Skip to content

Commit c1272b4

Browse files
committed
adjust radio story as csf3
1 parent 3d9e352 commit c1272b4

File tree

1 file changed

+134
-58
lines changed

1 file changed

+134
-58
lines changed

stories/Radio.stories.tsx

Lines changed: 134 additions & 58 deletions
Original file line numberDiff line numberDiff line change
@@ -1,100 +1,176 @@
1-
import React from 'react';
2-
import { action } from '@storybook/addon-actions';
3-
import { text, boolean } from '@storybook/addon-knobs';
1+
import React, { ComponentProps } from 'react';
42
import { RadioGroup, Radio } from '../src/scripts';
5-
export default {
3+
import { Meta, StoryObj } from '@storybook/react';
4+
5+
/**
6+
*
7+
*/
8+
type StoryProps = ComponentProps<typeof RadioGroup> & {
9+
radiogroup1?: ComponentProps<typeof RadioGroup>;
10+
radiogroup2?: ComponentProps<typeof RadioGroup>;
11+
radio1?: ComponentProps<typeof Radio>;
12+
radio2?: ComponentProps<typeof Radio>;
13+
};
14+
15+
/**
16+
*
17+
*/
18+
const meta: Meta<StoryProps> = {
619
title: 'Radio',
20+
component: RadioGroup,
21+
subcomponents: { Radio },
22+
argTypes: {
23+
onChange: { action: 'change' },
24+
},
725
};
8-
export const ControlledWithKnobs = {
9-
render: () => (
10-
<RadioGroup
11-
label={text('label', 'Radio Group Label')}
12-
error={text('error', '')}
13-
required={boolean('required', false)}
14-
onChange={action('change')}
15-
>
16-
<Radio
17-
label='Radio Label One'
18-
value='1'
19-
disabled={boolean('disabled #1', false)}
20-
checked={text('value', '') === '1'}
21-
/>
22-
<Radio
23-
label='Radio Label Two'
24-
value='2'
25-
disabled={boolean('disabled #2', false)}
26-
checked={text('value', '') === '2'}
27-
/>
26+
export default meta;
27+
28+
/**
29+
*
30+
*/
31+
export const ControlledWithKnobs: StoryObj<StoryProps> = {
32+
render: ({ radio1, radio2, ...args }) => (
33+
<RadioGroup {...args}>
34+
<Radio {...radio1} />
35+
<Radio {...radio2} />
2836
</RadioGroup>
2937
),
3038
name: 'Controlled with knobs',
39+
args: {
40+
radio1: {
41+
label: 'Radio Label One',
42+
value: '1',
43+
},
44+
radio2: {
45+
label: 'Radio Label Two',
46+
value: '2',
47+
},
48+
label: 'Radio Group Label',
49+
},
3150
parameters: {
32-
info: 'Radio Group controlled with knobs',
51+
docs: {
52+
description: {
53+
story: 'Radio Group controlled with knobs',
54+
},
55+
},
3356
},
3457
};
35-
export const Default = {
36-
render: () => (
37-
<RadioGroup label='Radio Group Label'>
58+
59+
/**
60+
*
61+
*/
62+
export const Default: StoryObj<StoryProps> = {
63+
render: (args) => (
64+
<RadioGroup {...args}>
3865
<Radio label='Radio Label One' value='1' checked />
3966
<Radio label='Radio Label Two' value='2' />
4067
</RadioGroup>
4168
),
69+
args: {
70+
label: 'Radio Group Label',
71+
},
4272
parameters: {
43-
info: 'Default Radio Group control',
73+
docs: {
74+
description: {
75+
story: 'Default Radio Group control',
76+
},
77+
},
4478
},
4579
};
46-
export const Required = {
47-
render: () => (
48-
<RadioGroup label='Radio Group Label' required>
49-
<Radio label='Radio Label One' value='1' checked />
50-
<Radio label='Radio Label Two' value='2' />
51-
</RadioGroup>
52-
),
80+
81+
/**
82+
*
83+
*/
84+
export const Required: StoryObj<StoryProps> = {
85+
...Default,
86+
args: {
87+
label: 'Radio Group Label',
88+
required: true,
89+
},
5390
parameters: {
54-
info: 'Radio Group control with required attribute',
91+
docs: {
92+
description: {
93+
story: 'Radio Group control with required attribute',
94+
},
95+
},
5596
},
5697
};
57-
export const Error = {
58-
render: () => (
59-
<RadioGroup
60-
label='Radio Group Label'
61-
required
62-
error='This field is required'
63-
>
64-
<Radio label='Radio Label One' value='1' checked />
65-
<Radio label='Radio Label Two' value='2' />
66-
</RadioGroup>
67-
),
98+
99+
/**
100+
*
101+
*/
102+
export const Error: StoryObj<StoryProps> = {
103+
...Default,
104+
args: {
105+
label: 'Radio Group Label',
106+
required: true,
107+
error: 'This field is required',
108+
},
68109
parameters: {
69-
info: 'Radio Group control with error message',
110+
docs: {
111+
description: {
112+
story: 'Radio Group control with error message',
113+
},
114+
},
70115
},
71116
};
72-
export const Disabled = {
73-
render: () => (
74-
<RadioGroup label='Radio Group Label'>
117+
118+
/**
119+
*
120+
*/
121+
export const Disabled: StoryObj<StoryProps> = {
122+
render: (args) => (
123+
<RadioGroup {...args}>
75124
<Radio label='Radio Label One' value='1' disabled />
76125
<Radio label='Radio Label Two' value='2' disabled />
77126
</RadioGroup>
78127
),
128+
args: {
129+
label: 'Radio Group Label',
130+
},
79131
parameters: {
80-
info: 'Radio Group control with disabled status',
132+
docs: {
133+
description: {
134+
story: 'Radio Group control with disabled status',
135+
},
136+
},
81137
},
82138
};
83-
export const ColsTotalCols = {
84-
render: () => (
139+
140+
/**
141+
*
142+
*/
143+
export const ColsTotalCols: StoryObj<StoryProps> = {
144+
render: ({ radiogroup1, radiogroup2 }) => (
85145
<>
86-
<RadioGroup totalCols={3} cols={2} label='Radio Group Label 1'>
146+
<RadioGroup {...radiogroup1}>
87147
<Radio label='Radio Label One' value='1' checked />
88148
<Radio label='Radio Label Two' value='2' />
89149
</RadioGroup>
90-
<RadioGroup totalCols={3} cols={1} label='Radio Group Label 2'>
150+
<RadioGroup {...radiogroup2}>
91151
<Radio label='Radio Label One' value='1' checked />
92152
<Radio label='Radio Label Two' value='2' />
93153
</RadioGroup>
94154
</>
95155
),
96156
name: 'Cols & totalCols',
157+
args: {
158+
radiogroup1: {
159+
totalCols: 3,
160+
cols: 2,
161+
label: 'Radio Group Label 1',
162+
},
163+
radiogroup2: {
164+
totalCols: 3,
165+
cols: 1,
166+
label: 'Radio Group Label 2',
167+
},
168+
},
97169
parameters: {
98-
info: 'Radio Group control with `cols` and `totalCols`',
170+
docs: {
171+
description: {
172+
story: 'Radio Group control with `cols` and `totalCols`',
173+
},
174+
},
99175
},
100176
};

0 commit comments

Comments
 (0)