Skip to content

Commit

Permalink
feat: Button disabled style 추가
Browse files Browse the repository at this point in the history
  • Loading branch information
gxxrxn committed Jun 8, 2024
1 parent 0a4dc5b commit 5bb9eb6
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 4 deletions.
16 changes: 16 additions & 0 deletions src/stories/base/Button.stories.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,22 @@ export const Kakao: Story = {
render: args => <Button {...args}>버튼</Button>,
};

export const Disabled: Story = {
args: {
disabled: true,
},
render: args => (
<div className="flex gap-[0.5rem]">
<Button {...args} fill={true}>
버튼
</Button>
<Button {...args} fill={false}>
버튼
</Button>
</div>
),
};

export const RecentSearch: Story = {
args: {
...MainLight.args,
Expand Down
23 changes: 19 additions & 4 deletions src/v1/base/Button.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,20 @@ const getSizeClasses = (size: Size) => {
}
};

const getSchemeClasses = (theme: ColorScheme, isFill: boolean) => {
const getSchemeClasses = (
theme: ColorScheme,
isFill: boolean,
disabled?: boolean
) => {
if (disabled) {
return (
'cursor-default ' +
(isFill
? 'border-transparent bg-black-900/[0.12] text-black-900/[0.26]'
: 'border-black-900/[0.12] bg-white text-black-900/[0.26]')
);
}

switch (theme) {
case 'main': {
return isFill
Expand Down Expand Up @@ -68,21 +81,23 @@ const Button = ({
fill = true,
fullRadius = false,
className,
disabled,
children,
...props
}: ButtonProps) => {
const computedClasses = useMemo(() => {
const sizeClass = getSizeClasses(size);
const schemeClass = getSchemeClasses(colorScheme, fill);
const schemeClass = getSchemeClasses(colorScheme, fill, disabled);
const roundedClass = fullRadius ? 'rounded-full' : 'rounded-[5px]';

return [sizeClass, schemeClass, roundedClass].join(' ');
}, [size, colorScheme, fill, fullRadius]);
}, [size, colorScheme, fill, fullRadius, disabled]);

return (
<button
type="button"
className={`${BASE_BUTTON_CLASSES} ${computedClasses} ` + className}
className={`${BASE_BUTTON_CLASSES} ${computedClasses} ${className}`}
disabled={disabled}
{...props}
>
{children}
Expand Down

0 comments on commit 5bb9eb6

Please sign in to comment.