aboutsummaryrefslogtreecommitdiffstats
path: root/src/components/molecules/forms/labelled-boolean-field.stories.tsx
blob: b1f819425a319eb395b94802c9c8b952ce9dfb78 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
import { ComponentMeta, ComponentStory } from '@storybook/react';
import { useState } from 'react';
import { LabelledBooleanField } from './labelled-boolean-field';
import { label } from './labelled-boolean-field.fixture';

/**
 * LabelledBooleanField - Storybook Meta
 */
export default {
  title: 'Molecules/Forms/Boolean',
  component: LabelledBooleanField,
  args: {
    checked: false,
    hidden: false,
    label,
    labelSize: 'small',
  },
  argTypes: {
    checked: {
      control: {
        type: null,
      },
      description: 'Should the option be checked?',
      type: {
        name: 'boolean',
        required: true,
      },
    },
    className: {
      control: {
        type: 'text',
      },
      description: 'Set additional classnames to the labelled field wrapper.',
      table: {
        category: 'Styles',
      },
      type: {
        name: 'string',
        required: false,
      },
    },
    fieldClassName: {
      control: {
        type: 'text',
      },
      description: 'Set additional classnames to the field.',
      table: {
        category: 'Styles',
      },
      type: {
        name: 'string',
        required: false,
      },
    },
    hidden: {
      control: {
        type: 'boolean',
      },
      description: 'Define if the field should be visually hidden.',
      table: {
        category: 'Options',
        defaultValue: { summary: false },
      },
      type: {
        name: 'boolean',
        required: false,
      },
    },
    id: {
      control: {
        type: 'text',
      },
      description: 'The option id.',
      type: {
        name: 'string',
        required: true,
      },
    },
    label: {
      control: {
        type: 'text',
      },
      description: 'The radio label.',
      type: {
        name: 'string',
        required: true,
      },
    },
    labelClassName: {
      control: {
        type: 'text',
      },
      description: 'Set additional classnames to the label.',
      table: {
        category: 'Styles',
      },
      type: {
        name: 'string',
        required: false,
      },
    },
    labelPosition: {
      control: {
        type: 'select',
      },
      description: 'Determine the label position.',
      options: ['left', 'right'],
      table: {
        category: 'Options',
        defaultValue: { summary: 'left' },
      },
      type: {
        name: 'string',
        required: false,
      },
    },
    labelSize: {
      control: {
        type: 'select',
      },
      description: 'The label size.',
      options: ['medium', 'small'],
      table: {
        category: 'Options',
      },
      type: {
        name: 'string',
        required: false,
      },
    },
    name: {
      control: {
        type: 'text',
      },
      description: 'The field name.',
      type: {
        name: 'string',
        required: true,
      },
    },
    onChange: {
      control: {
        type: null,
      },
      description: 'A callback function to handle field state change.',
      table: {
        category: 'Events',
      },
      type: {
        name: 'function',
        required: true,
      },
    },
    onClick: {
      control: {
        type: null,
      },
      description: 'A callback function to handle click on field.',
      table: {
        category: 'Events',
      },
      type: {
        name: 'function',
        required: false,
      },
    },
    type: {
      control: {
        type: 'select',
      },
      description: 'The field type. Either checkbox or radio.',
      options: ['checkbox', 'radio'],
      type: {
        name: 'string',
        required: true,
      },
    },
    value: {
      control: {
        type: 'text',
      },
      description: 'The field value.',
      type: {
        name: 'string',
        required: true,
      },
    },
  },
} as ComponentMeta<typeof LabelledBooleanField>;

const Template: ComponentStory<typeof LabelledBooleanField> = ({
  checked,
  onChange: _onChange,
  ...args
}) => {
  const [isChecked, setIsChecked] = useState<boolean>(checked);

  return (
    <LabelledBooleanField
      checked={isChecked}
      onChange={() => {
        setIsChecked(!isChecked);
      }}
      {...args}
    />
  );
};

/**
 * Labelled Boolean Field Stories - Checkbox with left label
 */
export const CheckboxLeftLabel = Template.bind({});
CheckboxLeftLabel.args = {
  id: 'checkbox',
  labelPosition: 'left',
  name: 'checkbox-left-label',
  type: 'checkbox',
  value: 'checkbox',
};

/**
 * Labelled Boolean Field Stories - Checkbox with right label
 */
export const CheckboxRightLabel = Template.bind({});
CheckboxRightLabel.args = {
  id: 'checkbox',
  labelPosition: 'right',
  name: 'checkbox-right-label',
  type: 'checkbox',
};

/**
 * Labelled Boolean Field Stories - Radio button with left label
 */
export const RadioButtonLeftLabel = Template.bind({});
RadioButtonLeftLabel.args = {
  id: 'radio',
  labelPosition: 'left',
  name: 'radio-left-label',
  type: 'radio',
  value: 'radio',
};

/**
 * Labelled Boolean Field Stories - Radio button with right label
 */
export const RadioButtonRightLabel = Template.bind({});
RadioButtonRightLabel.args = {
  id: 'radio',
  labelPosition: 'right',
  name: 'radio-right-label',
  type: 'radio',
  value: 'radio',
};