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(Label): implement css api #1953

Open
wants to merge 3 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 28 additions & 18 deletions src/components/Label/Label.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,20 @@ $transition-timing-function: ease-in-out;
--_--bg-color: none;
--_--bg-color-hover: none;
--_--text-color: none;
--_--font-size: var(--g-text-body-1-font-size);
--_--border-color: var(--g-color-line-generic);
--_--border-width: 0;
--_--border-color: currentColor;

display: inline-flex;
align-items: center;
position: relative;
height: var(--_--height);
border-radius: var(--_--border-radius);
color: var(--_--text-color);
background-color: var(--_--bg-color);
height: var(--g-label-height, var(--_--height));
border-radius: var(--g-label-border-radius, var(--_--border-radius));
color: var(--g-label-text-color, var(--_--text-color));
background-color: var(--g-label-background-color, var(--_--bg-color));
box-shadow: inset 0 0 0 var(--g-label-border-width, var(--_--border-width))
var(--g-label-border-color, var(--_--border-color));
transition-property: opacity, color, background-color;
transition-duration: $transition-duration;
transition-timing-function: $transition-timing-function;
Expand All @@ -25,12 +31,14 @@ $transition-timing-function: ease-in-out;
isolation: isolate;

&__text {
@include mixins.text-body-1();
display: flex;
align-items: baseline;
margin: 0 var(--_--margin-inline);
padding: 0 var(--g-label-padding, var(--_--padding-inline));
width: 100%;
line-height: var(--_--height);
font-family: var(--g-text-body-font-family);
font-weight: var(--g-text-body-font-weight);
font-size: var(--g-label-font-size, var(--_--font-size));
line-height: var(--g-label-height, var(--_--height));
text-align: center;
white-space: nowrap;
overflow: hidden;
Expand Down Expand Up @@ -67,9 +75,9 @@ $transition-timing-function: ease-in-out;
display: flex;
align-items: center;
justify-content: center;
width: var(--_--height);
height: var(--_--height);
border-radius: var(--_--border-radius);
width: var(--g-label-height, var(--_--height));
height: var(--g-label-height, var(--_--height));
border-radius: var(--g-label-border-radius, var(--_--border-radius));

&_side_start,
&_side_end {
Expand All @@ -93,7 +101,7 @@ $transition-timing-function: ease-in-out;
@include mixins.button-reset();
z-index: 2;
cursor: pointer;
color: var(--_--text-color);
color: var(--g-label-text-color, var(--_--text-color));
background-color: transparent;
transition:
color $transition-duration $transition-timing-function,
Expand All @@ -110,23 +118,23 @@ $transition-timing-function: ease-in-out;
&_xs {
--_--height: 20px;
--_--border-radius: var(--g-border-radius-xs);
--_--margin-inline: 8px;
--_--padding-inline: 8px;
--_--margin-addon-start: 24px;
--_--margin-addon-end: 22px;
}

&_s {
--_--height: 24px;
--_--border-radius: var(--g-border-radius-s);
--_--margin-inline: 10px;
--_--padding-inline: 10px;
--_--margin-addon-start: 28px;
--_--margin-addon-end: 26px;
}

&_m {
--_--height: 28px;
--_--border-radius: var(--g-border-radius-m);
--_--margin-inline: 12px;
--_--padding-inline: 12px;
--_--margin-addon-start: 32px;
--_--margin-addon-end: 32px;
}
Expand Down Expand Up @@ -188,8 +196,8 @@ $transition-timing-function: ease-in-out;
--_--bg-color: transparent;
--_--bg-color-hover: var(--g-color-base-simple-hover);
--_--text-color: var(--g-color-text-complementary);

box-shadow: inset 0 0 0 1px var(--g-color-line-generic);
--_--border-width: 1px;
--_--border-color: var(--g-color-line-generic);
}
}

Expand All @@ -204,12 +212,14 @@ $transition-timing-function: ease-in-out;
// hover styles
&_interactive:hover:not(:has(#{$block}__addon_type_button:hover)),
&__addon_type_button:hover {
background-color: var(--_--bg-color-hover);
background-color: var(--g-label-background-color-hover, var(--_--bg-color-hover));
}

// focus styles
&__main-button:focus-visible,
&__addon_type_button:focus-visible {
outline: 2px solid var(--g-color-line-focus);
outline: var(--g-label-focus-outline-width, 2px) var(--g-label-focus-outline-style, solid)
var(--g-label-focus-outline-color, var(--g-color-line-focus));
outline-offset: var(--g-label-focus-outline-offset, 0);
}
}
18 changes: 18 additions & 0 deletions src/components/Label/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -270,3 +270,21 @@ LANDING_BLOCK-->
| value | Label value (displayed as "children : value") | `string` | |
| title | HTML `title` attribute | `string` | |
| qa | HTML `data-qa` attribute, used in tests | `string` | |

## CSS API

| Name | Description |
| :--------------------------------- | :------------------------ |
| `--g-label-text-color` | Text color |
| `--g-label-background-color` | Background color |
| `--g-label-background-color-hover` | Background color on hover |
| `--g-label-border-width` | Border width |
| `--g-label-border-color` | Border color |
| `--g-label-focus-outline-width` | Focus outline color |
| `--g-label-focus-outline-color` | Focus outline color |
| `--g-label-focus-outline-style` | Focus outline style |
| `--g-label-focus-outline-offset` | Focus outline offset |
| `--g-label-height` | Height, line-height |
| `--g-label-border-radius` | Border radius |
| `--g-label-font-size` | Text font size |
| `--g-label-padding` | Side paddings |
27 changes: 27 additions & 0 deletions src/components/Label/__stories__/Label.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -159,3 +159,30 @@ export const ShowcaseStory: Story = {
render: () => <LabelShowcase />,
name: 'Showcase',
};

export const Custom: Story = {
Copy link
Contributor

Choose a reason for hiding this comment

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

Custom story is visually broken now

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Custom story is visually broken now

please tell me in more detail what needs to be fixed in this story?

Copy link
Contributor

Choose a reason for hiding this comment

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

"close" addon seems to be ignoring text's padding
Снимок экрана 2024-12-25 в 18 43 47

args: {
children: 'Custom label',
},
render: (args) => (
<React.Fragment>
<style>
{`.g-root {
--g-label-text-color: #fff;
--g-label-text-color-hover: #fff;
--g-label-background-color: #9a2eff;
--g-label-background-color-hover: #8526de;
--g-label-border-width: 5px;
--g-label-border-color: #8526de;
--g-label-height: 60px;
--g-label-padding: 36px;
--g-label-font-size: 20px;
--g-label-border-radius: 40px 20px;
--g-label-focus-outline-color: #9a2eff;
--g-label-focus-outline-offset: 4px;
}`}
</style>
<Label interactive type="close" {...args} />
</React.Fragment>
),
};
Loading