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 7 commits into
base: main
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from 1 commit
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
34 changes: 20 additions & 14 deletions src/components/Label/Label.scss
Original file line number Diff line number Diff line change
Expand Up @@ -9,14 +9,15 @@ $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);

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));
transition-property: opacity, color, background-color;
transition-duration: $transition-duration;
transition-timing-function: $transition-timing-function;
Expand All @@ -25,12 +26,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);
margin: 0 var(--g-label-margin-inline, var(--_--margin-inline));
Copy link
Contributor

Choose a reason for hiding this comment

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

It can me named --g-label-padding like in Button's CSS API to be consistent, maybe also change prop from margin to padding

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 can me named --g-label-padding like in Button's CSS API to be consistent, maybe also change prop from margin to padding

should I definitely change margin to padding? with padding, margin will be larger due to collapse margins

Copy link
Contributor

Choose a reason for hiding this comment

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

No sure now, I see it conflicts with the addons space

Copy link
Contributor Author

Choose a reason for hiding this comment

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

No sure now, I see it conflicts with the addons space

Do I need to fix this as part of this PR?

Copy link
Contributor

Choose a reason for hiding this comment

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

@blasdfaa Hi, sorry for long response. Let's revert this to margin instead. --g-label-margin-inline name is ok

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 +70,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 +96,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 Down Expand Up @@ -189,7 +192,8 @@ $transition-timing-function: ease-in-out;
--_--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);
box-shadow: inset 0 0 0 var(--g-label-border-width, 1px)
var(--g-label-border-color, var(--g-color-line-generic));
}
}

Expand All @@ -204,12 +208,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-margin-inline` | Margin inline |
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 = {
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 theme="clear" type="close" {...args} />
</React.Fragment>
),
};
Loading