Skip to content

Commit

Permalink
feat(button): introduce size variant
Browse files Browse the repository at this point in the history
  • Loading branch information
AugustinMauroy committed Dec 22, 2024
1 parent d687927 commit 273eb1a
Show file tree
Hide file tree
Showing 3 changed files with 28 additions and 2 deletions.
6 changes: 6 additions & 0 deletions apps/site/components/Common/Button/index.module.css
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,12 @@
@apply cursor-not-allowed;
}

&.small {
@apply px-3
py-2
text-sm;
}

&.neutral {
@apply rounded
bg-neutral-900
Expand Down
15 changes: 14 additions & 1 deletion apps/site/components/Common/Button/index.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,7 @@ export const Neutral: Story = {
kind: 'neutral',
children: 'Download Node (LTS)',
disabled: false,
size: 'default',
},
};

Expand All @@ -19,6 +20,7 @@ export const Primary: Story = {
kind: 'primary',
children: 'Download Node (LTS)',
disabled: false,
size: 'default',
},
};

Expand All @@ -27,6 +29,7 @@ export const Secondary: Story = {
kind: 'secondary',
children: 'Download Node (LTS)',
disabled: false,
size: 'default',
},
};

Expand All @@ -35,6 +38,7 @@ export const Special: Story = {
kind: 'special',
children: 'Download Node (LTS)',
disabled: false,
size: 'default',
},
};

Expand All @@ -48,7 +52,16 @@ export const WithIcon: Story = {
</>
),
disabled: false,
size: 'default',
},
};

export default { component: Button } as Meta;
export default {
component: Button,
argTypes: {
size: {
options: ['default', 'small'],
control: { type: 'radio' },
},
},
} as Meta;
9 changes: 8 additions & 1 deletion apps/site/components/Common/Button/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -14,11 +14,13 @@ import styles from './index.module.css';

type ButtonProps = AnchorHTMLAttributes<HTMLAnchorElement> & {
kind?: 'neutral' | 'primary' | 'secondary' | 'special';
size?: 'default' | 'small';
disabled?: boolean;
};

const Button: FC<ButtonProps> = ({
kind = 'primary',
size = 'default',
disabled = false,
href = undefined,
children,
Expand Down Expand Up @@ -56,7 +58,12 @@ const Button: FC<ButtonProps> = ({
role="button"
href={disabled ? undefined : href}
aria-disabled={disabled}
className={classNames(styles.button, styles[kind], className)}
className={classNames(
styles.button,
styles[kind],
styles[size],
className
)}
tabIndex={disabled ? -1 : 0} // Ensure focusable if not disabled
onClick={onClickHandler}
onKeyDown={onKeyDownHandler}
Expand Down

0 comments on commit 273eb1a

Please sign in to comment.