Skip to content

Commit

Permalink
feat(Button): add xs Button size
Browse files Browse the repository at this point in the history
  • Loading branch information
Marginy605 committed May 15, 2023
1 parent fe05925 commit ac2b5d2
Show file tree
Hide file tree
Showing 8 changed files with 58 additions and 8 deletions.
40 changes: 40 additions & 0 deletions src/components/Button/Button.scss
Original file line number Diff line number Diff line change
Expand Up @@ -85,6 +85,46 @@ $block: '.#{variables.$ns}button';
}

&_size {
&_xs {
--yc-button-height: 20px;
--yc-button-icon-size: 12px;

font-size: 13px;

#{$block}__text {
margin: 0 6px;
}

#{$block}__icon {
width: var(--yc-button-height);

&_side_left {
margin-left: 6px;
width: var(--yc-button-icon-size);
}

&_side_left ~ #{$block}__text {
margin-left: 22px;
}

&_side_right {
margin-right: 6px;
width: var(--yc-button-icon-size);
}

&_side_right ~ #{$block}__text {
margin-right: 22px;
}

#{$block}__icon-inner > * {
max-height: var(--yc-button-icon-size);
max-width: var(--yc-button-icon-size);
}
}

--yc-button-border-radius: var(--yc-border-radius-xs);
}

&_s {
--yc-button-height: 24px;

Expand Down
2 changes: 1 addition & 1 deletion src/components/Button/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export type ButtonView =
| 'outlined-contrast' // outlined button appearance with contrast background
| 'flat-contrast'; // flat button appearance with contrast background

export type ButtonSize = 's' | 'm' | 'l' | 'xl';
export type ButtonSize = 'xs' | 's' | 'm' | 'l' | 'xl';

export type ButtonPin =
| 'round-round'
Expand Down
2 changes: 1 addition & 1 deletion src/components/Button/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -82,7 +82,7 @@ type ButtonView =
| 'outlined-contrast'
| 'flat-contrast';

type ButtonSize = 's' | 'm' | 'l' | 'xl';
type ButtonSize = 'xs' | 's' | 'm' | 'l' | 'xl';

type ButtonPin =
| 'round-round'
Expand Down
2 changes: 1 addition & 1 deletion src/components/Button/__stories__/Button.new.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,7 @@ export default {
defaultValue: 'normal',
},
size: {
options: ['s', 'm', 'l', 'xl'],
options: ['xs', 's', 'm', 'l', 'xl'],
control: {type: 'radio'},
defaultValue: 'm',
},
Expand Down
4 changes: 4 additions & 0 deletions src/components/Button/__stories__/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,10 @@ export const Default = DefaultTemplate.bind({});

const SizeTemplate: Story<ButtonProps> = (args) => (
<>
<Button {...args} size="xs">
Size xs
</Button>
<span style={{margin: '16px'}} />
<Button {...args} size="s">
Size s
</Button>
Expand Down
2 changes: 2 additions & 0 deletions src/components/Button/__stories__/ButtonShowcase.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,8 @@ export function ButtonShowcase() {
{renderViewGrid()}
<ShowcaseItem title="size">
<p>
<Button size="xs">Size xs</Button>
<span style={{margin: '8px'}} />
<Button size="s">Size s</Button>
<span style={{margin: '8px'}} />
<Button size="m">Size m</Button>
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -238,6 +238,7 @@ export function ButtonExampleState() {
export function ButtonExampleSize() {
return (
<DocsExample gap="l" space="l">
<Button size="xs">XS-size</Button>
<Button size="s">S-size</Button>
<Button size="m">M-size</Button>
<Button size="l">L-size</Button>
Expand Down
13 changes: 8 additions & 5 deletions src/components/Button/__tests__/Button.test.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,15 @@ describe('Button', () => {
expect(button).not.toBeDisabled();
});

test.each(new Array<ButtonSize>('s', 'm', 'l', 'xl'))('render with given "%s" size', (size) => {
render(<Button size={size} qa={qaId} />);
const button = screen.getByTestId(qaId);
test.each(new Array<ButtonSize>('xs', 's', 'm', 'l', 'xl'))(
'render with given "%s" size',
(size) => {
render(<Button size={size} qa={qaId} />);
const button = screen.getByTestId(qaId);

expect(button).toHaveClass(`yc-button_size_${size}`);
});
expect(button).toHaveClass(`yc-button_size_${size}`);
},
);

test.each(new Array<ButtonView>(...buttonViews))('render with given "%s" view', (view) => {
render(<Button view={view} qa={qaId} />);
Expand Down

0 comments on commit ac2b5d2

Please sign in to comment.