Skip to content

Commit 0425223

Browse files
committed
[#556] 버튼 컴포넌트 disabled style 작성 (#615)
* feat: Button disabled style 추가 * feat: 모임 생성 퍼널 버튼에 form이 유효하지 않으면 disabled 적용
1 parent badcf8e commit 0425223

File tree

5 files changed

+51
-8
lines changed

5 files changed

+51
-8
lines changed

src/stories/base/Button.stories.tsx

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -59,6 +59,22 @@ export const Kakao: Story = {
5959
render: args => <Button {...args}>버튼</Button>,
6060
};
6161

62+
export const Disabled: Story = {
63+
args: {
64+
disabled: true,
65+
},
66+
render: args => (
67+
<div className="flex gap-[0.5rem]">
68+
<Button {...args} fill={true}>
69+
버튼
70+
</Button>
71+
<Button {...args} fill={false}>
72+
버튼
73+
</Button>
74+
</div>
75+
),
76+
};
77+
6278
export const RecentSearch: Story = {
6379
args: {
6480
...MainLight.args,

src/v1/base/Button.tsx

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,20 @@ const getSizeClasses = (size: Size) => {
3333
}
3434
};
3535

36-
const getSchemeClasses = (theme: ColorScheme, isFill: boolean) => {
36+
const getSchemeClasses = (
37+
theme: ColorScheme,
38+
isFill: boolean,
39+
disabled?: boolean
40+
) => {
41+
if (disabled) {
42+
return (
43+
'cursor-default ' +
44+
(isFill
45+
? 'border-transparent bg-black-900/[0.12] text-black-900/[0.26]'
46+
: 'border-black-900/[0.12] bg-white text-black-900/[0.26]')
47+
);
48+
}
49+
3750
switch (theme) {
3851
case 'main': {
3952
return isFill
@@ -68,21 +81,23 @@ const Button = ({
6881
fill = true,
6982
fullRadius = false,
7083
className,
84+
disabled,
7185
children,
7286
...props
7387
}: ButtonProps) => {
7488
const computedClasses = useMemo(() => {
7589
const sizeClass = getSizeClasses(size);
76-
const schemeClass = getSchemeClasses(colorScheme, fill);
90+
const schemeClass = getSchemeClasses(colorScheme, fill, disabled);
7791
const roundedClass = fullRadius ? 'rounded-full' : 'rounded-[5px]';
7892

7993
return [sizeClass, schemeClass, roundedClass].join(' ');
80-
}, [size, colorScheme, fill, fullRadius]);
94+
}, [size, colorScheme, fill, fullRadius, disabled]);
8195

8296
return (
8397
<button
8498
type="button"
85-
className={`${BASE_BUTTON_CLASSES} ${computedClasses} ` + className}
99+
className={`${BASE_BUTTON_CLASSES} ${computedClasses} ${className}`}
100+
disabled={disabled}
86101
{...props}
87102
>
88103
{children}

src/v1/bookGroup/create/steps/EnterTitleStep/EnterTitleStep.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,10 @@ import BottomActionButton from '@/v1/base/BottomActionButton';
99
import { TitleField } from './fields';
1010

1111
const EnterTitleStep = ({ onNextStep }: MoveFunnelStepProps) => {
12-
const { handleSubmit } = useFormContext<EnterTitleStepFormValues>();
12+
const {
13+
handleSubmit,
14+
formState: { isValid },
15+
} = useFormContext<EnterTitleStepFormValues>();
1316

1417
useRemoveVerticalScroll();
1518

@@ -24,6 +27,7 @@ const EnterTitleStep = ({ onNextStep }: MoveFunnelStepProps) => {
2427

2528
<BottomActionButton
2629
type="submit"
30+
disabled={!isValid}
2731
onClick={handleSubmit(() => onNextStep?.())}
2832
>
2933
다음

src/v1/bookGroup/create/steps/SelectJoinTypeStep/SelectJoinTypeStep.tsx

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@ export type JoinTypeStepFieldName = keyof SelectJoinTypeStepFormValues;
1010
export type JoinTypeStepFieldProp = { name: JoinTypeStepFieldName };
1111

1212
const SelectJoinTypeStep = ({ onSubmit }: MoveFunnelStepProps) => {
13-
const { handleSubmit } = useFormContext<SelectJoinTypeStepFormValues>();
13+
const {
14+
handleSubmit,
15+
formState: { isValid },
16+
} = useFormContext<SelectJoinTypeStepFormValues>();
1417

1518
return (
1619
<article>
@@ -31,6 +34,7 @@ const SelectJoinTypeStep = ({ onSubmit }: MoveFunnelStepProps) => {
3134

3235
<BottomActionButton
3336
type="submit"
37+
disabled={!isValid}
3438
onClick={onSubmit && handleSubmit(onSubmit)}
3539
>
3640
독서모임 만들기

src/v1/bookGroup/create/steps/SetUpDetailStep/SetUpDetailStep.tsx

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -30,8 +30,11 @@ const SetUpDetailStep = ({
3030
goToSelectBookStep,
3131
onNextStep,
3232
}: SetUpDetailStepProps) => {
33-
const { handleSubmit, getValues } =
34-
useFormContext<SetUpDetailStepFormValues>();
33+
const {
34+
handleSubmit,
35+
getValues,
36+
formState: { isValid },
37+
} = useFormContext<SetUpDetailStepFormValues>();
3538

3639
return (
3740
<article className="flex flex-col gap-[2.5rem] overflow-y-scroll pb-[7rem]">
@@ -55,6 +58,7 @@ const SetUpDetailStep = ({
5558

5659
<BottomActionButton
5760
type="submit"
61+
disabled={!isValid}
5862
onClick={handleSubmit(() => onNextStep?.())}
5963
>
6064
다음

0 commit comments

Comments
 (0)