Skip to content

Commit

Permalink
feat: RadioButton 스토리북 작성
Browse files Browse the repository at this point in the history
  • Loading branch information
hanyugeon committed Oct 14, 2023
1 parent 43c0600 commit 6e38608
Showing 1 changed file with 57 additions and 0 deletions.
57 changes: 57 additions & 0 deletions src/stories/Base/RadioButton.stories.tsx
Original file line number Diff line number Diff line change
@@ -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<typeof RadioButton> = {
title: 'Base/RadioButton',
component: RadioButton,
tags: ['autodocs'],
};

export default meta;

type Story = StoryObj<typeof RadioButton>;

type FormValues = {
Radio: string;
};

const RadioButtonWithUseForm = () => {
const { register, handleSubmit, watch } = useForm<FormValues>({
mode: 'all',
defaultValues: { Radio: '라디오 A' },
});

const handleSubmitForm: SubmitHandler<FormValues> = ({ Radio }) => {
alert(`Submit as: ${Radio}`);
};

return (
<>
<form
onSubmit={handleSubmit(handleSubmitForm)}
className="flex w-[43rem] flex-col gap-[1.6rem]"
>
<div className="flex justify-between">
<RadioButton {...register('Radio')} value="라디오 A" />
<RadioButton {...register('Radio')} value="라디오 B" />
<RadioButton {...register('Radio')} value="라디오 C" />
</div>
<Button size="large" type="submit">
Submit
</Button>
</form>
<pre>{JSON.stringify(watch(), null, 2)}</pre>
</>
);
};

export const Default: Story = {
render: args => <RadioButton {...args} value="라디오 버튼" />,
};

export const RadioButtonForm: Story = {
render: RadioButtonWithUseForm,
};

0 comments on commit 6e38608

Please sign in to comment.