-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'develop' into feature/modal
- Loading branch information
Showing
8 changed files
with
1,299 additions
and
1,384 deletions.
There are no files selected for viewing
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
import { useEffect } from 'react'; | ||
import { Controller, type UseFormReturn } from 'react-hook-form'; | ||
|
||
import { ReactComponent as CheckMark } from '@/assets/check-mark.svg'; | ||
import { ReactComponent as FatHorizontalIcon } from '@/assets/fat-horizontal.svg'; | ||
import { ReactComponent as FatVerticalIcon } from '@/assets/fat-vertical.svg'; | ||
import { ReactComponent as ThinVerticalIcon } from '@/assets/thin-vertical.svg'; | ||
|
||
interface CheckboxProps { | ||
type: 'fatHorizontal' | 'fatVertical' | 'thinVertical'; | ||
control?: UseFormReturn<any>['control']; | ||
} | ||
|
||
const DataByType = { | ||
fatHorizontal: { | ||
text: '뚱뚱 가로', | ||
iconComponent: FatHorizontalIcon, | ||
}, | ||
fatVertical: { | ||
text: '뚱뚱 세로', | ||
iconComponent: FatVerticalIcon, | ||
}, | ||
thinVertical: { | ||
text: '길쭉 세로', | ||
iconComponent: ThinVerticalIcon, | ||
}, | ||
}; | ||
|
||
export function Checkbox({ type, control }: CheckboxProps) { | ||
const Icon = DataByType[type].iconComponent; | ||
|
||
useEffect(() => {}, []); | ||
|
||
return ( | ||
<Controller | ||
name="checkbox" | ||
control={control} | ||
render={({ field }) => { | ||
const isSelected = field.value === type; | ||
|
||
return ( | ||
<button | ||
className={`w-[336px] h-[101px] border-2 rounded-xl flex justify-start items-center font-bold text-[24px] p-3 ${ | ||
isSelected | ||
? 'text-white bg-primary-default border-primary-default' | ||
: 'text-grey-placeholder border-grey-placeholder' | ||
}`} | ||
onClick={() => { | ||
field.onChange(type); | ||
}} | ||
> | ||
<Icon className={`w-12 h-12 pr-2 ${isSelected ? '[&>*]:stroke-primary-default' : ''}`} /> | ||
<span className="font-bold text-[24px] flex-1 text-left">{DataByType[type].text}</span> | ||
{isSelected ? <CheckMark className="right-3 w-[20px] h-[20px] [&>*]:fill-white" /> : null} | ||
</button> | ||
); | ||
}} | ||
/> | ||
); | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
import type { Meta, StoryObj } from '@storybook/react'; | ||
|
||
import { Checkbox } from '@/domain/_common/components'; | ||
import { useForm } from '@/hooks'; | ||
import { yupSchema } from '@/utils/validation'; | ||
|
||
const meta: Meta<typeof Checkbox> = { | ||
title: 'Components/Checkbox', | ||
component: Checkbox, | ||
parameters: { | ||
layout: 'centered', | ||
}, | ||
tags: [], | ||
} satisfies Meta<typeof Checkbox>; | ||
|
||
export default meta; | ||
type Story = StoryObj<typeof meta>; | ||
|
||
export const CheckboxForm: Story = { | ||
render: () => { | ||
const { control } = useForm({ | ||
defaultValues: { | ||
checkbox: '', | ||
}, | ||
schema: { | ||
checkbox: yupSchema.requiredString, | ||
}, | ||
mode: 'onChange', | ||
}); | ||
|
||
return ( | ||
<ul className="flex flex-col gap-3"> | ||
<li> | ||
<Checkbox type="fatHorizontal" control={control} /> | ||
</li> | ||
<li> | ||
<Checkbox type="fatVertical" control={control} /> | ||
</li> | ||
<li> | ||
<Checkbox type="thinVertical" control={control} /> | ||
</li> | ||
</ul> | ||
); | ||
}, | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.