|
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'; |
4 | 2 | 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> = { |
6 | 19 | title: 'Radio', |
| 20 | + component: RadioGroup, |
| 21 | + subcomponents: { Radio }, |
| 22 | + argTypes: { |
| 23 | + onChange: { action: 'change' }, |
| 24 | + }, |
7 | 25 | }; |
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} /> |
28 | 36 | </RadioGroup> |
29 | 37 | ), |
30 | 38 | 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 | + }, |
31 | 50 | parameters: { |
32 | | - info: 'Radio Group controlled with knobs', |
| 51 | + docs: { |
| 52 | + description: { |
| 53 | + story: 'Radio Group controlled with knobs', |
| 54 | + }, |
| 55 | + }, |
33 | 56 | }, |
34 | 57 | }; |
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}> |
38 | 65 | <Radio label='Radio Label One' value='1' checked /> |
39 | 66 | <Radio label='Radio Label Two' value='2' /> |
40 | 67 | </RadioGroup> |
41 | 68 | ), |
| 69 | + args: { |
| 70 | + label: 'Radio Group Label', |
| 71 | + }, |
42 | 72 | parameters: { |
43 | | - info: 'Default Radio Group control', |
| 73 | + docs: { |
| 74 | + description: { |
| 75 | + story: 'Default Radio Group control', |
| 76 | + }, |
| 77 | + }, |
44 | 78 | }, |
45 | 79 | }; |
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 | + }, |
53 | 90 | parameters: { |
54 | | - info: 'Radio Group control with required attribute', |
| 91 | + docs: { |
| 92 | + description: { |
| 93 | + story: 'Radio Group control with required attribute', |
| 94 | + }, |
| 95 | + }, |
55 | 96 | }, |
56 | 97 | }; |
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 | + }, |
68 | 109 | parameters: { |
69 | | - info: 'Radio Group control with error message', |
| 110 | + docs: { |
| 111 | + description: { |
| 112 | + story: 'Radio Group control with error message', |
| 113 | + }, |
| 114 | + }, |
70 | 115 | }, |
71 | 116 | }; |
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}> |
75 | 124 | <Radio label='Radio Label One' value='1' disabled /> |
76 | 125 | <Radio label='Radio Label Two' value='2' disabled /> |
77 | 126 | </RadioGroup> |
78 | 127 | ), |
| 128 | + args: { |
| 129 | + label: 'Radio Group Label', |
| 130 | + }, |
79 | 131 | parameters: { |
80 | | - info: 'Radio Group control with disabled status', |
| 132 | + docs: { |
| 133 | + description: { |
| 134 | + story: 'Radio Group control with disabled status', |
| 135 | + }, |
| 136 | + }, |
81 | 137 | }, |
82 | 138 | }; |
83 | | -export const ColsTotalCols = { |
84 | | - render: () => ( |
| 139 | + |
| 140 | +/** |
| 141 | + * |
| 142 | + */ |
| 143 | +export const ColsTotalCols: StoryObj<StoryProps> = { |
| 144 | + render: ({ radiogroup1, radiogroup2 }) => ( |
85 | 145 | <> |
86 | | - <RadioGroup totalCols={3} cols={2} label='Radio Group Label 1'> |
| 146 | + <RadioGroup {...radiogroup1}> |
87 | 147 | <Radio label='Radio Label One' value='1' checked /> |
88 | 148 | <Radio label='Radio Label Two' value='2' /> |
89 | 149 | </RadioGroup> |
90 | | - <RadioGroup totalCols={3} cols={1} label='Radio Group Label 2'> |
| 150 | + <RadioGroup {...radiogroup2}> |
91 | 151 | <Radio label='Radio Label One' value='1' checked /> |
92 | 152 | <Radio label='Radio Label Two' value='2' /> |
93 | 153 | </RadioGroup> |
94 | 154 | </> |
95 | 155 | ), |
96 | 156 | 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 | + }, |
97 | 169 | 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 | + }, |
99 | 175 | }, |
100 | 176 | }; |
0 commit comments