Skip to content
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

Merged
merged 2 commits into from
Jan 31, 2024

Conversation

LakeVostok
Copy link
Contributor

UXRFC-1

@gravity-ui-bot
Copy link
Contributor

Preview is ready.

href?: undefined;
} & BaseBreadcrumbsItem;

export type BreadcrumbsItem = LinkBreadcrumbsItem | ButtonBreadcrumbsItem;
Copy link
Contributor

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?

Copy link
Contributor Author

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.

Copy link
Contributor

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?

Copy link
Contributor Author

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})} />;
Copy link
Contributor

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

Copy link
Contributor

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` |
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

table formatting broke

Copy link
Contributor Author

@LakeVostok LakeVostok Jan 30, 2024

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

what exactly is broken and what tool to check it with? Github doesn't show any problems.
йцук

@@ -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';
Copy link
Contributor

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

Copy link
Contributor Author

@LakeVostok LakeVostok Jan 28, 2024

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?

Copy link
Contributor

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+

@amje amje changed the title chore(Link)!: the "href" property is required feat(Link)!: the "href" property is required Jan 31, 2024
@amje amje merged commit 8bbedf4 into gravity-ui:next Jan 31, 2024
3 of 4 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants