@salutejs/plasma-new-hope 0.149.0-canary.1421.10946935893.0 → 0.149.0-canary.1421.10953636107.0

Sign up to get free protection for your applications and to get access to all the features.
@@ -1,5 +1,5 @@
1
1
  import { useForm as useReactHookForm, Controller } from 'react-hook-form';
2
- import React, { useRef } from 'react';
2
+ import React from 'react';
3
3
  import type { Meta, StoryObj } from '@storybook/react';
4
4
 
5
5
  import { WithTheme } from '../../../_helpers';
@@ -0,0 +1,245 @@
1
+ import { useForm as useReactHookForm, Controller } from 'react-hook-form';
2
+ import React from 'react';
3
+ import type { Meta, StoryObj } from '@storybook/react';
4
+
5
+ import { WithTheme } from '../../../_helpers';
6
+ import { Button } from '../Button/Button';
7
+ import { TextField } from '../TextField/TextField';
8
+ import { TextArea } from '../TextArea/TextArea';
9
+ import { Checkbox } from '../Checkbox/Checkbox';
10
+ import { Switch } from '../Switch/Switch';
11
+ import { Radiobox } from '../Radiobox/Radiobox';
12
+ import { RadioGroup } from '../../../../components/Radiobox';
13
+ import { Slider } from '../Slider/Slider';
14
+ import { useForm } from '../../../../hooks';
15
+ import { DatePicker, DatePickerRange } from '../DatePicker/DatePicker';
16
+
17
+ type StoryDropdownProps = {};
18
+
19
+ const langName = 'language';
20
+ const itemsRadiobox = [
21
+ { langName, value: 'c', label: 'C', disabled: false },
22
+ { langName, value: 'cpp', label: 'C++', disabled: false },
23
+ { langName, value: 'assembly', label: 'Assembly', disabled: false },
24
+ ];
25
+
26
+ const PlasmaForm = () => {
27
+ const onSubmit = (data) => {
28
+ console.log(data);
29
+ };
30
+
31
+ const { formRef, formData } = useForm(onSubmit, {
32
+ textfield: 'textfield',
33
+ textarea: 'textarea',
34
+ checkbox: 'checkobox',
35
+ switch: true,
36
+ radiobox: 'c',
37
+ slider: 10,
38
+ sliderd: [10, 20],
39
+ datepicker: '12.09.2024',
40
+ datepickerRange: ['09.09.2024', '12.09.2024'],
41
+ });
42
+
43
+ return (
44
+ <form onSubmit={formData} style={{ display: 'flex', flexDirection: 'column', gap: '20px' }} ref={formRef}>
45
+ <TextField name="textfield" placeholder="Textfield" required={false} />
46
+ <TextArea name="textarea" autoResize placeholder="Textarea" />
47
+ <Checkbox name="checkbox" label="Checkbox" />
48
+ <Switch name="switch" label="Switch" labelPosition="after" />
49
+ <RadioGroup aria-labelledby="radiogroup-title-id">
50
+ <div id="radiogroup-title-id" style={{ margin: '1rem 0', fontWeight: '600' }}>
51
+ Выберите язык программирования для изучения.
52
+ </div>
53
+ {itemsRadiobox.map((item) => (
54
+ <Radiobox
55
+ name="radiobox"
56
+ key={item.value}
57
+ value={item.value}
58
+ label={item.label}
59
+ disabled={item.disabled}
60
+ />
61
+ ))}
62
+ </RadioGroup>
63
+ <Slider name="slider" label="Slider" type="single" min={0} max={100} />
64
+ <Slider name="sliderd" label="Slider" type="double" min={0} max={100} />
65
+ <DatePicker label="DatePicker" name="datepicker" />
66
+ <DatePickerRange label="DatePicker" name="datepickerRange" />
67
+ <Button type="submit">Отправить</Button>
68
+ </form>
69
+ );
70
+ };
71
+
72
+ const meta: Meta<StoryDropdownProps> = {
73
+ title: 'plasma_web/Form',
74
+ decorators: [WithTheme],
75
+ component: PlasmaForm,
76
+ };
77
+
78
+ export default meta;
79
+
80
+ const StoryPlasmaForm = () => {
81
+ return <PlasmaForm />;
82
+ };
83
+
84
+ export const DefaultPlasmaForm: StoryObj<StoryDropdownProps> = {
85
+ render: () => <StoryPlasmaForm />,
86
+ };
87
+
88
+ const DefaultForm = () => {
89
+ const onSubmit = (event) => {
90
+ event.preventDefault();
91
+
92
+ const fData = new FormData(event.target);
93
+
94
+ for (const p of fData) {
95
+ const name = p[0];
96
+ const value = p[1];
97
+
98
+ console.log(name, value);
99
+ }
100
+ };
101
+ return (
102
+ <form onSubmit={onSubmit} style={{ display: 'flex', flexDirection: 'column', gap: '20px' }}>
103
+ <TextField name="textfield" placeholder="Textfield" required={false} />
104
+ <TextArea name="textarea" autoResize placeholder="Textarea" />
105
+ <Checkbox name="checkbox" label="Checkbox" />
106
+ <Switch name="switch" label="Switch" labelPosition="after" />
107
+ <RadioGroup aria-labelledby="radiogroup-title-id">
108
+ <div id="radiogroup-title-id" style={{ margin: '1rem 0', fontWeight: '600' }}>
109
+ Выберите язык программирования для изучения.
110
+ </div>
111
+ {itemsRadiobox.map((item) => (
112
+ <Radiobox
113
+ name="radiobox"
114
+ key={item.value}
115
+ value={item.value}
116
+ label={item.label}
117
+ disabled={item.disabled}
118
+ />
119
+ ))}
120
+ </RadioGroup>
121
+ <Slider name="slider" label="Slider" type="single" min={0} max={100} />
122
+ <Slider name="sliderd" label="Slider" type="double" min={0} max={100} />
123
+ <DatePicker label="DatePicker" name="datepicker" />
124
+ <DatePickerRange label="DatePicker" name="datepickerRange" />
125
+ <Button type="submit">Отправить</Button>
126
+ </form>
127
+ );
128
+ };
129
+
130
+ const StoryDefaultForm = () => {
131
+ return <DefaultForm />;
132
+ };
133
+
134
+ export const FormDefault: StoryObj<StoryDropdownProps> = {
135
+ render: () => <StoryDefaultForm />,
136
+ };
137
+
138
+ const DefaultUseForm = () => {
139
+ const { register, handleSubmit } = useReactHookForm({
140
+ defaultValues: {
141
+ textfield: 'John Doe',
142
+ textarea: 'Default description',
143
+ checkbox: true,
144
+ switch: true,
145
+ radiobox: 'c',
146
+ slider: 10,
147
+ },
148
+ });
149
+ const onSubmit = (data) => {
150
+ console.log(data);
151
+ };
152
+
153
+ return (
154
+ <form onSubmit={handleSubmit(onSubmit)} style={{ display: 'flex', flexDirection: 'column', gap: '20px' }}>
155
+ <TextField {...register('textfield')} placeholder="Textfield" required={false} />
156
+ <TextArea {...register('textarea')} autoResize placeholder="Textarea" />
157
+ <Checkbox {...register('checkbox')} label="Checkbox" />
158
+ <Switch {...register('switch')} label="Switch" labelPosition="after" />
159
+ <RadioGroup aria-labelledby="radiogroup-title-id">
160
+ <div id="radiogroup-title-id" style={{ margin: '1rem 0', fontWeight: '600' }}>
161
+ Выберите язык программирования для изучения.
162
+ </div>
163
+ {itemsRadiobox.map((item) => (
164
+ <Radiobox
165
+ {...register('radiobox')}
166
+ key={item.value}
167
+ value={item.value}
168
+ label={item.label}
169
+ disabled={item.disabled}
170
+ />
171
+ ))}
172
+ </RadioGroup>
173
+ <Button type="submit">Отправить</Button>
174
+ </form>
175
+ );
176
+ };
177
+
178
+ const StoryHookForm = () => {
179
+ return <DefaultUseForm />;
180
+ };
181
+
182
+ export const UseHookForm: StoryObj<StoryDropdownProps> = {
183
+ render: () => <StoryHookForm />,
184
+ };
185
+
186
+ const DefaultUseFormController = () => {
187
+ const { control, handleSubmit } = useReactHookForm({
188
+ defaultValues: {
189
+ textfield: 'John Doe',
190
+ textarea: 'Default description',
191
+ checkbox: true,
192
+ switch: true,
193
+ radiobox: 'c',
194
+ slider: 10,
195
+ sliderd: [10, 20],
196
+ },
197
+ });
198
+ const onSubmit = (data) => {
199
+ console.log(data);
200
+ };
201
+
202
+ return (
203
+ <form onSubmit={handleSubmit(onSubmit)} style={{ display: 'flex', flexDirection: 'column', gap: '20px' }}>
204
+ <Controller
205
+ name="textfield"
206
+ control={control}
207
+ render={({ field }) => <TextField {...field} label="TextField" />}
208
+ />
209
+ <Controller
210
+ name="textarea"
211
+ control={control}
212
+ render={({ field }) => <TextArea {...field} label="TextArea" />}
213
+ />
214
+ <Controller
215
+ name="checkbox"
216
+ control={control}
217
+ render={({ field }) => <Checkbox {...field} checked={field.value} label="Checkbox" />}
218
+ />
219
+ <Controller
220
+ name="switch"
221
+ control={control}
222
+ render={({ field }) => <Switch {...field} checked={field.value} labelPosition="after" label="Switch" />}
223
+ />
224
+ <Controller
225
+ name="slider"
226
+ control={control}
227
+ render={({ field }) => <Slider {...field} type="single" label="Slider" min={0} max={100} />}
228
+ />
229
+ <Controller
230
+ name="sliderd"
231
+ control={control}
232
+ render={({ field }) => <Slider {...field} type="double" label="Slider" min={0} max={100} />}
233
+ />
234
+ <Button type="submit">Отправить</Button>
235
+ </form>
236
+ );
237
+ };
238
+
239
+ const StoryHookFormController = () => {
240
+ return <DefaultUseFormController />;
241
+ };
242
+
243
+ export const UseHookFormController: StoryObj<StoryDropdownProps> = {
244
+ render: () => <StoryHookFormController />,
245
+ };
@@ -1,5 +1,5 @@
1
1
  import { useForm as useReactHookForm, Controller } from 'react-hook-form';
2
- import React, { useRef } from 'react';
2
+ import React from 'react';
3
3
  import type { Meta, StoryObj } from '@storybook/react';
4
4
 
5
5
  import { WithTheme } from '../../../_helpers';
@@ -0,0 +1,245 @@
1
+ import { useForm as useReactHookForm, Controller } from 'react-hook-form';
2
+ import React from 'react';
3
+ import type { Meta, StoryObj } from '@storybook/react';
4
+
5
+ import { WithTheme } from '../../../_helpers';
6
+ import { Button } from '../Button/Button';
7
+ import { TextField } from '../TextField/TextField';
8
+ import { TextArea } from '../TextArea/TextArea';
9
+ import { Checkbox } from '../Checkbox/Checkbox';
10
+ import { Switch } from '../Switch/Switch';
11
+ import { Radiobox } from '../Radiobox/Radiobox';
12
+ import { RadioGroup } from '../../../../components/Radiobox';
13
+ import { Slider } from '../Slider/Slider';
14
+ import { useForm } from '../../../../hooks';
15
+ import { DatePicker, DatePickerRange } from '../DatePicker/DatePicker';
16
+
17
+ type StoryDropdownProps = {};
18
+
19
+ const langName = 'language';
20
+ const itemsRadiobox = [
21
+ { langName, value: 'c', label: 'C', disabled: false },
22
+ { langName, value: 'cpp', label: 'C++', disabled: false },
23
+ { langName, value: 'assembly', label: 'Assembly', disabled: false },
24
+ ];
25
+
26
+ const PlasmaForm = () => {
27
+ const onSubmit = (data) => {
28
+ console.log(data);
29
+ };
30
+
31
+ const { formRef, formData } = useForm(onSubmit, {
32
+ textfield: 'textfield',
33
+ textarea: 'textarea',
34
+ checkbox: 'checkobox',
35
+ switch: true,
36
+ radiobox: 'c',
37
+ slider: 10,
38
+ sliderd: [10, 20],
39
+ datepicker: '12.09.2024',
40
+ datepickerRange: ['09.09.2024', '12.09.2024'],
41
+ });
42
+
43
+ return (
44
+ <form onSubmit={formData} style={{ display: 'flex', flexDirection: 'column', gap: '20px' }} ref={formRef}>
45
+ <TextField name="textfield" placeholder="Textfield" required={false} />
46
+ <TextArea name="textarea" autoResize placeholder="Textarea" />
47
+ <Checkbox name="checkbox" label="Checkbox" />
48
+ <Switch name="switch" label="Switch" labelPosition="after" />
49
+ <RadioGroup aria-labelledby="radiogroup-title-id">
50
+ <div id="radiogroup-title-id" style={{ margin: '1rem 0', fontWeight: '600' }}>
51
+ Выберите язык программирования для изучения.
52
+ </div>
53
+ {itemsRadiobox.map((item) => (
54
+ <Radiobox
55
+ name="radiobox"
56
+ key={item.value}
57
+ value={item.value}
58
+ label={item.label}
59
+ disabled={item.disabled}
60
+ />
61
+ ))}
62
+ </RadioGroup>
63
+ <Slider name="slider" label="Slider" type="single" min={0} max={100} />
64
+ <Slider name="sliderd" label="Slider" type="double" min={0} max={100} />
65
+ <DatePicker label="DatePicker" name="datepicker" />
66
+ <DatePickerRange label="DatePicker" name="datepickerRange" />
67
+ <Button type="submit">Отправить</Button>
68
+ </form>
69
+ );
70
+ };
71
+
72
+ const meta: Meta<StoryDropdownProps> = {
73
+ title: 'plasma_web/Form',
74
+ decorators: [WithTheme],
75
+ component: PlasmaForm,
76
+ };
77
+
78
+ export default meta;
79
+
80
+ const StoryPlasmaForm = () => {
81
+ return <PlasmaForm />;
82
+ };
83
+
84
+ export const DefaultPlasmaForm: StoryObj<StoryDropdownProps> = {
85
+ render: () => <StoryPlasmaForm />,
86
+ };
87
+
88
+ const DefaultForm = () => {
89
+ const onSubmit = (event) => {
90
+ event.preventDefault();
91
+
92
+ const fData = new FormData(event.target);
93
+
94
+ for (const p of fData) {
95
+ const name = p[0];
96
+ const value = p[1];
97
+
98
+ console.log(name, value);
99
+ }
100
+ };
101
+ return (
102
+ <form onSubmit={onSubmit} style={{ display: 'flex', flexDirection: 'column', gap: '20px' }}>
103
+ <TextField name="textfield" placeholder="Textfield" required={false} />
104
+ <TextArea name="textarea" autoResize placeholder="Textarea" />
105
+ <Checkbox name="checkbox" label="Checkbox" />
106
+ <Switch name="switch" label="Switch" labelPosition="after" />
107
+ <RadioGroup aria-labelledby="radiogroup-title-id">
108
+ <div id="radiogroup-title-id" style={{ margin: '1rem 0', fontWeight: '600' }}>
109
+ Выберите язык программирования для изучения.
110
+ </div>
111
+ {itemsRadiobox.map((item) => (
112
+ <Radiobox
113
+ name="radiobox"
114
+ key={item.value}
115
+ value={item.value}
116
+ label={item.label}
117
+ disabled={item.disabled}
118
+ />
119
+ ))}
120
+ </RadioGroup>
121
+ <Slider name="slider" label="Slider" type="single" min={0} max={100} />
122
+ <Slider name="sliderd" label="Slider" type="double" min={0} max={100} />
123
+ <DatePicker label="DatePicker" name="datepicker" />
124
+ <DatePickerRange label="DatePicker" name="datepickerRange" />
125
+ <Button type="submit">Отправить</Button>
126
+ </form>
127
+ );
128
+ };
129
+
130
+ const StoryDefaultForm = () => {
131
+ return <DefaultForm />;
132
+ };
133
+
134
+ export const FormDefault: StoryObj<StoryDropdownProps> = {
135
+ render: () => <StoryDefaultForm />,
136
+ };
137
+
138
+ const DefaultUseForm = () => {
139
+ const { register, handleSubmit } = useReactHookForm({
140
+ defaultValues: {
141
+ textfield: 'John Doe',
142
+ textarea: 'Default description',
143
+ checkbox: true,
144
+ switch: true,
145
+ radiobox: 'c',
146
+ slider: 10,
147
+ },
148
+ });
149
+ const onSubmit = (data) => {
150
+ console.log(data);
151
+ };
152
+
153
+ return (
154
+ <form onSubmit={handleSubmit(onSubmit)} style={{ display: 'flex', flexDirection: 'column', gap: '20px' }}>
155
+ <TextField {...register('textfield')} placeholder="Textfield" required={false} />
156
+ <TextArea {...register('textarea')} autoResize placeholder="Textarea" />
157
+ <Checkbox {...register('checkbox')} label="Checkbox" />
158
+ <Switch {...register('switch')} label="Switch" labelPosition="after" />
159
+ <RadioGroup aria-labelledby="radiogroup-title-id">
160
+ <div id="radiogroup-title-id" style={{ margin: '1rem 0', fontWeight: '600' }}>
161
+ Выберите язык программирования для изучения.
162
+ </div>
163
+ {itemsRadiobox.map((item) => (
164
+ <Radiobox
165
+ {...register('radiobox')}
166
+ key={item.value}
167
+ value={item.value}
168
+ label={item.label}
169
+ disabled={item.disabled}
170
+ />
171
+ ))}
172
+ </RadioGroup>
173
+ <Button type="submit">Отправить</Button>
174
+ </form>
175
+ );
176
+ };
177
+
178
+ const StoryHookForm = () => {
179
+ return <DefaultUseForm />;
180
+ };
181
+
182
+ export const UseHookForm: StoryObj<StoryDropdownProps> = {
183
+ render: () => <StoryHookForm />,
184
+ };
185
+
186
+ const DefaultUseFormController = () => {
187
+ const { control, handleSubmit } = useReactHookForm({
188
+ defaultValues: {
189
+ textfield: 'John Doe',
190
+ textarea: 'Default description',
191
+ checkbox: true,
192
+ switch: true,
193
+ radiobox: 'c',
194
+ slider: 10,
195
+ sliderd: [10, 20],
196
+ },
197
+ });
198
+ const onSubmit = (data) => {
199
+ console.log(data);
200
+ };
201
+
202
+ return (
203
+ <form onSubmit={handleSubmit(onSubmit)} style={{ display: 'flex', flexDirection: 'column', gap: '20px' }}>
204
+ <Controller
205
+ name="textfield"
206
+ control={control}
207
+ render={({ field }) => <TextField {...field} label="TextField" />}
208
+ />
209
+ <Controller
210
+ name="textarea"
211
+ control={control}
212
+ render={({ field }) => <TextArea {...field} label="TextArea" />}
213
+ />
214
+ <Controller
215
+ name="checkbox"
216
+ control={control}
217
+ render={({ field }) => <Checkbox {...field} checked={field.value} label="Checkbox" />}
218
+ />
219
+ <Controller
220
+ name="switch"
221
+ control={control}
222
+ render={({ field }) => <Switch {...field} checked={field.value} labelPosition="after" label="Switch" />}
223
+ />
224
+ <Controller
225
+ name="slider"
226
+ control={control}
227
+ render={({ field }) => <Slider {...field} type="single" label="Slider" min={0} max={100} />}
228
+ />
229
+ <Controller
230
+ name="sliderd"
231
+ control={control}
232
+ render={({ field }) => <Slider {...field} type="double" label="Slider" min={0} max={100} />}
233
+ />
234
+ <Button type="submit">Отправить</Button>
235
+ </form>
236
+ );
237
+ };
238
+
239
+ const StoryHookFormController = () => {
240
+ return <DefaultUseFormController />;
241
+ };
242
+
243
+ export const UseHookFormController: StoryObj<StoryDropdownProps> = {
244
+ render: () => <StoryHookFormController />,
245
+ };
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@salutejs/plasma-new-hope",
3
- "version": "0.149.0-canary.1421.10946935893.0",
3
+ "version": "0.149.0-canary.1421.10953636107.0",
4
4
  "description": "Salute Design System blueprint",
5
5
  "main": "cjs/index.js",
6
6
  "module": "es/index.js",
@@ -122,5 +122,5 @@
122
122
  "react-popper": "2.3.0",
123
123
  "storeon": "3.1.5"
124
124
  },
125
- "gitHead": "762c59891c495e85fc2129bcae4ca10739edf897"
125
+ "gitHead": "eb284ced3851f94f3c0b58b5e2a5662921991b4d"
126
126
  }
@@ -1,5 +1,5 @@
1
1
  import { useForm as useReactHookForm, Controller } from 'react-hook-form';
2
- import React, { useRef } from 'react';
2
+ import React from 'react';
3
3
  import type { Meta, StoryObj } from '@storybook/react';
4
4
 
5
5
  import { WithTheme } from '../../../_helpers';
@@ -0,0 +1,245 @@
1
+ import { useForm as useReactHookForm, Controller } from 'react-hook-form';
2
+ import React from 'react';
3
+ import type { Meta, StoryObj } from '@storybook/react';
4
+
5
+ import { WithTheme } from '../../../_helpers';
6
+ import { Button } from '../Button/Button';
7
+ import { TextField } from '../TextField/TextField';
8
+ import { TextArea } from '../TextArea/TextArea';
9
+ import { Checkbox } from '../Checkbox/Checkbox';
10
+ import { Switch } from '../Switch/Switch';
11
+ import { Radiobox } from '../Radiobox/Radiobox';
12
+ import { RadioGroup } from '../../../../components/Radiobox';
13
+ import { Slider } from '../Slider/Slider';
14
+ import { useForm } from '../../../../hooks';
15
+ import { DatePicker, DatePickerRange } from '../DatePicker/DatePicker';
16
+
17
+ type StoryDropdownProps = {};
18
+
19
+ const langName = 'language';
20
+ const itemsRadiobox = [
21
+ { langName, value: 'c', label: 'C', disabled: false },
22
+ { langName, value: 'cpp', label: 'C++', disabled: false },
23
+ { langName, value: 'assembly', label: 'Assembly', disabled: false },
24
+ ];
25
+
26
+ const PlasmaForm = () => {
27
+ const onSubmit = (data) => {
28
+ console.log(data);
29
+ };
30
+
31
+ const { formRef, formData } = useForm(onSubmit, {
32
+ textfield: 'textfield',
33
+ textarea: 'textarea',
34
+ checkbox: 'checkobox',
35
+ switch: true,
36
+ radiobox: 'c',
37
+ slider: 10,
38
+ sliderd: [10, 20],
39
+ datepicker: '12.09.2024',
40
+ datepickerRange: ['09.09.2024', '12.09.2024'],
41
+ });
42
+
43
+ return (
44
+ <form onSubmit={formData} style={{ display: 'flex', flexDirection: 'column', gap: '20px' }} ref={formRef}>
45
+ <TextField name="textfield" placeholder="Textfield" required={false} />
46
+ <TextArea name="textarea" autoResize placeholder="Textarea" />
47
+ <Checkbox name="checkbox" label="Checkbox" />
48
+ <Switch name="switch" label="Switch" labelPosition="after" />
49
+ <RadioGroup aria-labelledby="radiogroup-title-id">
50
+ <div id="radiogroup-title-id" style={{ margin: '1rem 0', fontWeight: '600' }}>
51
+ Выберите язык программирования для изучения.
52
+ </div>
53
+ {itemsRadiobox.map((item) => (
54
+ <Radiobox
55
+ name="radiobox"
56
+ key={item.value}
57
+ value={item.value}
58
+ label={item.label}
59
+ disabled={item.disabled}
60
+ />
61
+ ))}
62
+ </RadioGroup>
63
+ <Slider name="slider" label="Slider" type="single" min={0} max={100} />
64
+ <Slider name="sliderd" label="Slider" type="double" min={0} max={100} />
65
+ <DatePicker label="DatePicker" name="datepicker" />
66
+ <DatePickerRange label="DatePicker" name="datepickerRange" />
67
+ <Button type="submit">Отправить</Button>
68
+ </form>
69
+ );
70
+ };
71
+
72
+ const meta: Meta<StoryDropdownProps> = {
73
+ title: 'plasma_web/Form',
74
+ decorators: [WithTheme],
75
+ component: PlasmaForm,
76
+ };
77
+
78
+ export default meta;
79
+
80
+ const StoryPlasmaForm = () => {
81
+ return <PlasmaForm />;
82
+ };
83
+
84
+ export const DefaultPlasmaForm: StoryObj<StoryDropdownProps> = {
85
+ render: () => <StoryPlasmaForm />,
86
+ };
87
+
88
+ const DefaultForm = () => {
89
+ const onSubmit = (event) => {
90
+ event.preventDefault();
91
+
92
+ const fData = new FormData(event.target);
93
+
94
+ for (const p of fData) {
95
+ const name = p[0];
96
+ const value = p[1];
97
+
98
+ console.log(name, value);
99
+ }
100
+ };
101
+ return (
102
+ <form onSubmit={onSubmit} style={{ display: 'flex', flexDirection: 'column', gap: '20px' }}>
103
+ <TextField name="textfield" placeholder="Textfield" required={false} />
104
+ <TextArea name="textarea" autoResize placeholder="Textarea" />
105
+ <Checkbox name="checkbox" label="Checkbox" />
106
+ <Switch name="switch" label="Switch" labelPosition="after" />
107
+ <RadioGroup aria-labelledby="radiogroup-title-id">
108
+ <div id="radiogroup-title-id" style={{ margin: '1rem 0', fontWeight: '600' }}>
109
+ Выберите язык программирования для изучения.
110
+ </div>
111
+ {itemsRadiobox.map((item) => (
112
+ <Radiobox
113
+ name="radiobox"
114
+ key={item.value}
115
+ value={item.value}
116
+ label={item.label}
117
+ disabled={item.disabled}
118
+ />
119
+ ))}
120
+ </RadioGroup>
121
+ <Slider name="slider" label="Slider" type="single" min={0} max={100} />
122
+ <Slider name="sliderd" label="Slider" type="double" min={0} max={100} />
123
+ <DatePicker label="DatePicker" name="datepicker" />
124
+ <DatePickerRange label="DatePicker" name="datepickerRange" />
125
+ <Button type="submit">Отправить</Button>
126
+ </form>
127
+ );
128
+ };
129
+
130
+ const StoryDefaultForm = () => {
131
+ return <DefaultForm />;
132
+ };
133
+
134
+ export const FormDefault: StoryObj<StoryDropdownProps> = {
135
+ render: () => <StoryDefaultForm />,
136
+ };
137
+
138
+ const DefaultUseForm = () => {
139
+ const { register, handleSubmit } = useReactHookForm({
140
+ defaultValues: {
141
+ textfield: 'John Doe',
142
+ textarea: 'Default description',
143
+ checkbox: true,
144
+ switch: true,
145
+ radiobox: 'c',
146
+ slider: 10,
147
+ },
148
+ });
149
+ const onSubmit = (data) => {
150
+ console.log(data);
151
+ };
152
+
153
+ return (
154
+ <form onSubmit={handleSubmit(onSubmit)} style={{ display: 'flex', flexDirection: 'column', gap: '20px' }}>
155
+ <TextField {...register('textfield')} placeholder="Textfield" required={false} />
156
+ <TextArea {...register('textarea')} autoResize placeholder="Textarea" />
157
+ <Checkbox {...register('checkbox')} label="Checkbox" />
158
+ <Switch {...register('switch')} label="Switch" labelPosition="after" />
159
+ <RadioGroup aria-labelledby="radiogroup-title-id">
160
+ <div id="radiogroup-title-id" style={{ margin: '1rem 0', fontWeight: '600' }}>
161
+ Выберите язык программирования для изучения.
162
+ </div>
163
+ {itemsRadiobox.map((item) => (
164
+ <Radiobox
165
+ {...register('radiobox')}
166
+ key={item.value}
167
+ value={item.value}
168
+ label={item.label}
169
+ disabled={item.disabled}
170
+ />
171
+ ))}
172
+ </RadioGroup>
173
+ <Button type="submit">Отправить</Button>
174
+ </form>
175
+ );
176
+ };
177
+
178
+ const StoryHookForm = () => {
179
+ return <DefaultUseForm />;
180
+ };
181
+
182
+ export const UseHookForm: StoryObj<StoryDropdownProps> = {
183
+ render: () => <StoryHookForm />,
184
+ };
185
+
186
+ const DefaultUseFormController = () => {
187
+ const { control, handleSubmit } = useReactHookForm({
188
+ defaultValues: {
189
+ textfield: 'John Doe',
190
+ textarea: 'Default description',
191
+ checkbox: true,
192
+ switch: true,
193
+ radiobox: 'c',
194
+ slider: 10,
195
+ sliderd: [10, 20],
196
+ },
197
+ });
198
+ const onSubmit = (data) => {
199
+ console.log(data);
200
+ };
201
+
202
+ return (
203
+ <form onSubmit={handleSubmit(onSubmit)} style={{ display: 'flex', flexDirection: 'column', gap: '20px' }}>
204
+ <Controller
205
+ name="textfield"
206
+ control={control}
207
+ render={({ field }) => <TextField {...field} label="TextField" />}
208
+ />
209
+ <Controller
210
+ name="textarea"
211
+ control={control}
212
+ render={({ field }) => <TextArea {...field} label="TextArea" />}
213
+ />
214
+ <Controller
215
+ name="checkbox"
216
+ control={control}
217
+ render={({ field }) => <Checkbox {...field} checked={field.value} label="Checkbox" />}
218
+ />
219
+ <Controller
220
+ name="switch"
221
+ control={control}
222
+ render={({ field }) => <Switch {...field} checked={field.value} labelPosition="after" label="Switch" />}
223
+ />
224
+ <Controller
225
+ name="slider"
226
+ control={control}
227
+ render={({ field }) => <Slider {...field} type="single" label="Slider" min={0} max={100} />}
228
+ />
229
+ <Controller
230
+ name="sliderd"
231
+ control={control}
232
+ render={({ field }) => <Slider {...field} type="double" label="Slider" min={0} max={100} />}
233
+ />
234
+ <Button type="submit">Отправить</Button>
235
+ </form>
236
+ );
237
+ };
238
+
239
+ const StoryHookFormController = () => {
240
+ return <DefaultUseFormController />;
241
+ };
242
+
243
+ export const UseHookFormController: StoryObj<StoryDropdownProps> = {
244
+ render: () => <StoryHookFormController />,
245
+ };
@@ -1,5 +1,5 @@
1
1
  import { useForm as useReactHookForm, Controller } from 'react-hook-form';
2
- import React, { useRef } from 'react';
2
+ import React from 'react';
3
3
  import type { Meta, StoryObj } from '@storybook/react';
4
4
 
5
5
  import { WithTheme } from '../../../_helpers';
@@ -0,0 +1,245 @@
1
+ import { useForm as useReactHookForm, Controller } from 'react-hook-form';
2
+ import React from 'react';
3
+ import type { Meta, StoryObj } from '@storybook/react';
4
+
5
+ import { WithTheme } from '../../../_helpers';
6
+ import { Button } from '../Button/Button';
7
+ import { TextField } from '../TextField/TextField';
8
+ import { TextArea } from '../TextArea/TextArea';
9
+ import { Checkbox } from '../Checkbox/Checkbox';
10
+ import { Switch } from '../Switch/Switch';
11
+ import { Radiobox } from '../Radiobox/Radiobox';
12
+ import { RadioGroup } from '../../../../components/Radiobox';
13
+ import { Slider } from '../Slider/Slider';
14
+ import { useForm } from '../../../../hooks';
15
+ import { DatePicker, DatePickerRange } from '../DatePicker/DatePicker';
16
+
17
+ type StoryDropdownProps = {};
18
+
19
+ const langName = 'language';
20
+ const itemsRadiobox = [
21
+ { langName, value: 'c', label: 'C', disabled: false },
22
+ { langName, value: 'cpp', label: 'C++', disabled: false },
23
+ { langName, value: 'assembly', label: 'Assembly', disabled: false },
24
+ ];
25
+
26
+ const PlasmaForm = () => {
27
+ const onSubmit = (data) => {
28
+ console.log(data);
29
+ };
30
+
31
+ const { formRef, formData } = useForm(onSubmit, {
32
+ textfield: 'textfield',
33
+ textarea: 'textarea',
34
+ checkbox: 'checkobox',
35
+ switch: true,
36
+ radiobox: 'c',
37
+ slider: 10,
38
+ sliderd: [10, 20],
39
+ datepicker: '12.09.2024',
40
+ datepickerRange: ['09.09.2024', '12.09.2024'],
41
+ });
42
+
43
+ return (
44
+ <form onSubmit={formData} style={{ display: 'flex', flexDirection: 'column', gap: '20px' }} ref={formRef}>
45
+ <TextField name="textfield" placeholder="Textfield" required={false} />
46
+ <TextArea name="textarea" autoResize placeholder="Textarea" />
47
+ <Checkbox name="checkbox" label="Checkbox" />
48
+ <Switch name="switch" label="Switch" labelPosition="after" />
49
+ <RadioGroup aria-labelledby="radiogroup-title-id">
50
+ <div id="radiogroup-title-id" style={{ margin: '1rem 0', fontWeight: '600' }}>
51
+ Выберите язык программирования для изучения.
52
+ </div>
53
+ {itemsRadiobox.map((item) => (
54
+ <Radiobox
55
+ name="radiobox"
56
+ key={item.value}
57
+ value={item.value}
58
+ label={item.label}
59
+ disabled={item.disabled}
60
+ />
61
+ ))}
62
+ </RadioGroup>
63
+ <Slider name="slider" label="Slider" type="single" min={0} max={100} />
64
+ <Slider name="sliderd" label="Slider" type="double" min={0} max={100} />
65
+ <DatePicker label="DatePicker" name="datepicker" />
66
+ <DatePickerRange label="DatePicker" name="datepickerRange" />
67
+ <Button type="submit">Отправить</Button>
68
+ </form>
69
+ );
70
+ };
71
+
72
+ const meta: Meta<StoryDropdownProps> = {
73
+ title: 'plasma_web/Form',
74
+ decorators: [WithTheme],
75
+ component: PlasmaForm,
76
+ };
77
+
78
+ export default meta;
79
+
80
+ const StoryPlasmaForm = () => {
81
+ return <PlasmaForm />;
82
+ };
83
+
84
+ export const DefaultPlasmaForm: StoryObj<StoryDropdownProps> = {
85
+ render: () => <StoryPlasmaForm />,
86
+ };
87
+
88
+ const DefaultForm = () => {
89
+ const onSubmit = (event) => {
90
+ event.preventDefault();
91
+
92
+ const fData = new FormData(event.target);
93
+
94
+ for (const p of fData) {
95
+ const name = p[0];
96
+ const value = p[1];
97
+
98
+ console.log(name, value);
99
+ }
100
+ };
101
+ return (
102
+ <form onSubmit={onSubmit} style={{ display: 'flex', flexDirection: 'column', gap: '20px' }}>
103
+ <TextField name="textfield" placeholder="Textfield" required={false} />
104
+ <TextArea name="textarea" autoResize placeholder="Textarea" />
105
+ <Checkbox name="checkbox" label="Checkbox" />
106
+ <Switch name="switch" label="Switch" labelPosition="after" />
107
+ <RadioGroup aria-labelledby="radiogroup-title-id">
108
+ <div id="radiogroup-title-id" style={{ margin: '1rem 0', fontWeight: '600' }}>
109
+ Выберите язык программирования для изучения.
110
+ </div>
111
+ {itemsRadiobox.map((item) => (
112
+ <Radiobox
113
+ name="radiobox"
114
+ key={item.value}
115
+ value={item.value}
116
+ label={item.label}
117
+ disabled={item.disabled}
118
+ />
119
+ ))}
120
+ </RadioGroup>
121
+ <Slider name="slider" label="Slider" type="single" min={0} max={100} />
122
+ <Slider name="sliderd" label="Slider" type="double" min={0} max={100} />
123
+ <DatePicker label="DatePicker" name="datepicker" />
124
+ <DatePickerRange label="DatePicker" name="datepickerRange" />
125
+ <Button type="submit">Отправить</Button>
126
+ </form>
127
+ );
128
+ };
129
+
130
+ const StoryDefaultForm = () => {
131
+ return <DefaultForm />;
132
+ };
133
+
134
+ export const FormDefault: StoryObj<StoryDropdownProps> = {
135
+ render: () => <StoryDefaultForm />,
136
+ };
137
+
138
+ const DefaultUseForm = () => {
139
+ const { register, handleSubmit } = useReactHookForm({
140
+ defaultValues: {
141
+ textfield: 'John Doe',
142
+ textarea: 'Default description',
143
+ checkbox: true,
144
+ switch: true,
145
+ radiobox: 'c',
146
+ slider: 10,
147
+ },
148
+ });
149
+ const onSubmit = (data) => {
150
+ console.log(data);
151
+ };
152
+
153
+ return (
154
+ <form onSubmit={handleSubmit(onSubmit)} style={{ display: 'flex', flexDirection: 'column', gap: '20px' }}>
155
+ <TextField {...register('textfield')} placeholder="Textfield" required={false} />
156
+ <TextArea {...register('textarea')} autoResize placeholder="Textarea" />
157
+ <Checkbox {...register('checkbox')} label="Checkbox" />
158
+ <Switch {...register('switch')} label="Switch" labelPosition="after" />
159
+ <RadioGroup aria-labelledby="radiogroup-title-id">
160
+ <div id="radiogroup-title-id" style={{ margin: '1rem 0', fontWeight: '600' }}>
161
+ Выберите язык программирования для изучения.
162
+ </div>
163
+ {itemsRadiobox.map((item) => (
164
+ <Radiobox
165
+ {...register('radiobox')}
166
+ key={item.value}
167
+ value={item.value}
168
+ label={item.label}
169
+ disabled={item.disabled}
170
+ />
171
+ ))}
172
+ </RadioGroup>
173
+ <Button type="submit">Отправить</Button>
174
+ </form>
175
+ );
176
+ };
177
+
178
+ const StoryHookForm = () => {
179
+ return <DefaultUseForm />;
180
+ };
181
+
182
+ export const UseHookForm: StoryObj<StoryDropdownProps> = {
183
+ render: () => <StoryHookForm />,
184
+ };
185
+
186
+ const DefaultUseFormController = () => {
187
+ const { control, handleSubmit } = useReactHookForm({
188
+ defaultValues: {
189
+ textfield: 'John Doe',
190
+ textarea: 'Default description',
191
+ checkbox: true,
192
+ switch: true,
193
+ radiobox: 'c',
194
+ slider: 10,
195
+ sliderd: [10, 20],
196
+ },
197
+ });
198
+ const onSubmit = (data) => {
199
+ console.log(data);
200
+ };
201
+
202
+ return (
203
+ <form onSubmit={handleSubmit(onSubmit)} style={{ display: 'flex', flexDirection: 'column', gap: '20px' }}>
204
+ <Controller
205
+ name="textfield"
206
+ control={control}
207
+ render={({ field }) => <TextField {...field} label="TextField" />}
208
+ />
209
+ <Controller
210
+ name="textarea"
211
+ control={control}
212
+ render={({ field }) => <TextArea {...field} label="TextArea" />}
213
+ />
214
+ <Controller
215
+ name="checkbox"
216
+ control={control}
217
+ render={({ field }) => <Checkbox {...field} checked={field.value} label="Checkbox" />}
218
+ />
219
+ <Controller
220
+ name="switch"
221
+ control={control}
222
+ render={({ field }) => <Switch {...field} checked={field.value} labelPosition="after" label="Switch" />}
223
+ />
224
+ <Controller
225
+ name="slider"
226
+ control={control}
227
+ render={({ field }) => <Slider {...field} type="single" label="Slider" min={0} max={100} />}
228
+ />
229
+ <Controller
230
+ name="sliderd"
231
+ control={control}
232
+ render={({ field }) => <Slider {...field} type="double" label="Slider" min={0} max={100} />}
233
+ />
234
+ <Button type="submit">Отправить</Button>
235
+ </form>
236
+ );
237
+ };
238
+
239
+ const StoryHookFormController = () => {
240
+ return <DefaultUseFormController />;
241
+ };
242
+
243
+ export const UseHookFormController: StoryObj<StoryDropdownProps> = {
244
+ render: () => <StoryHookFormController />,
245
+ };