diff --git a/src/stories/Base/RadioButton.stories.tsx b/src/stories/Base/RadioButton.stories.tsx new file mode 100644 index 00000000..bc6a2402 --- /dev/null +++ b/src/stories/Base/RadioButton.stories.tsx @@ -0,0 +1,57 @@ +import { Meta, StoryObj } from '@storybook/react'; +import { SubmitHandler, useForm } from 'react-hook-form'; + +import RadioButton from '@/ui/Base/RadioButton'; +import Button from '@/ui/Base/Button'; + +const meta: Meta = { + title: 'Base/RadioButton', + component: RadioButton, + tags: ['autodocs'], +}; + +export default meta; + +type Story = StoryObj; + +type FormValues = { + radio: string; +}; + +const RadioButtonWithUseForm = () => { + const { register, handleSubmit, watch } = useForm({ + mode: 'all', + defaultValues: { radio: '라디오 A' }, + }); + + const handleSubmitForm: SubmitHandler = ({ radio }) => { + alert(`Submit as: ${radio}`); + }; + + return ( + <> +
+
+ + + +
+ +
+
{JSON.stringify(watch(), null, 2)}
+ + ); +}; + +export const Default: Story = { + render: args => , +}; + +export const RadioButtonForm: Story = { + render: RadioButtonWithUseForm, +}; diff --git a/src/ui/Base/RadioButton.tsx b/src/ui/Base/RadioButton.tsx new file mode 100644 index 00000000..2072b61d --- /dev/null +++ b/src/ui/Base/RadioButton.tsx @@ -0,0 +1,30 @@ +import { ComponentPropsWithoutRef, forwardRef, Ref } from 'react'; + +const BASE_RADIO_BUTTON_CLASSES = + 'px-[1.2rem] py-[0.5rem] bg-main-600/[0.18] text-main-900 text-sm font-normal rounded-[2rem] cursor-pointer w-full h-full peer-checked:bg-main-900 peer-checked:text-white'; + +const RadioButton = ( + { + name, + value, + ...props + }: Omit, 'id' | 'type' | 'className'>, + ref: Ref +) => { + return ( + + ); +}; + +export default forwardRef(RadioButton);