-
Notifications
You must be signed in to change notification settings - Fork 98
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat(Link)!: the "href" property is required #1270
Conversation
Preview is ready. |
361654d
to
8426404
Compare
href?: undefined; | ||
} & BaseBreadcrumbsItem; | ||
|
||
export type BreadcrumbsItem = LinkBreadcrumbsItem | ButtonBreadcrumbsItem; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Isn't the same as before?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It was types product, became types sum. Its more powerful way for union declaration.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean there is no difference, href
is optional anyway. What's the point of this change?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I mean there is no difference,
href
is optional anyway. What's the point of this change?
Oh, I figure out, why it wasn't obvious to use this kind of approach. Lost it while rebasing, it should have been:
type BaseBreadcrumbsItem = {
text: string;
items?: BreadcrumbsItem[];
title?: string;
};
type LinkBreadcrumbsItem = {
href: string;
action?: (event: React.MouseEvent<HTMLElement, MouseEvent> | KeyboardEvent) => void;
} & BaseBreadcrumbsItem;
type ButtonBreadcrumbsItem = {
href?: undefined;
action: (event: React.MouseEvent<HTMLElement, MouseEvent> | KeyboardEvent) => void;
} & BaseBreadcrumbsItem;
So, we describe 2 categories of breadcrumb items: the one is like regular anchor(and should have the href prop), the two is like button, that should have some action(action prop).
So, if user want to create Breadcrumb, that is not like regular link, he will be forced(by typescript) to specify the action prop.
And if the developer(of uikit) needs to add a new behavior for only one of the types of breadcrumb item(e.g. the target attribute for anchor), then he modifies only LinkBreadcrumbsItem and any time in the code he will know, that he works with certain type of item(due to the href prop check).
onClick: React.MouseEventHandler<HTMLElement>; | ||
children: React.ReactNode; | ||
}) { | ||
return <button {...props} className={b('switcher', {more: true})} />; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
button must have the type
attribute with the "button"
value
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And add please focus styling to the button
| :--------- | :----------------------------------------- | :-------------------------------------------------------: | :--------: | | ||
| view | Link appearance | `"normal" \| "primary" \| "secondary"` | `"normal"` | | ||
| visitable | Display `:visitable` CSS state | `boolean \| undefined` | | ||
| href | HTML `href` attribute | `string \| undefined` | |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
table formatting broke
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@@ -2,7 +2,7 @@ import React from 'react'; | |||
|
|||
import type {Meta, StoryFn} from '@storybook/react'; | |||
|
|||
import {Link} from '../Link'; | |||
import {Link, type LinkProps} from '../Link'; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We're not using this TS syntax
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Well, then it should be regulated by the linter. The language provides me with tools, and I use them. In addition, this constuction is used in other components(e.g. ActionTooltip).
I can set up an appropriate rule to ban inline type imports. But at first glance it looks strange. Why did you decide to not use it?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I remember the main reason was that it requires to use TS 4.5+
8426404
to
df8cbe2
Compare
df8cbe2
to
5763523
Compare
UXRFC-1