|
1 | | -import * as React from 'react'; |
2 | | - |
3 | 1 | import {Meta, StoryFn} from '@storybook/react'; |
4 | 2 | import {v4 as uuidv4} from 'uuid'; |
5 | 3 |
|
6 | | -import {yfmTransform} from '../../../../.storybook/utils'; |
7 | | -import {PageConstructor} from '../../../containers/PageConstructor'; |
8 | | -import {FormBlockDirection, FormBlockModel, isHubspotDataForm} from '../../../models'; |
| 4 | +import {blockTransform} from '../../../../.storybook/utils'; |
| 5 | +import {FormBlockDirection, FormBlockModel, FormBlockProps} from '../../../models'; |
9 | 6 | import FormBlock from '../Form'; |
10 | 7 |
|
11 | 8 | import data from './data.json'; |
12 | 9 |
|
13 | 10 | export default { |
14 | 11 | title: 'Blocks/Form', |
15 | 12 | component: FormBlock, |
16 | | - args: { |
17 | | - ...data.default, |
18 | | - textContent: { |
19 | | - ...data.default.textContent, |
20 | | - text: yfmTransform(data.default.textContent.text), |
21 | | - }, |
22 | | - }, |
23 | | - argTypes: { |
24 | | - type: {control: false}, |
25 | | - direction: {options: Object.values(FormBlockDirection), control: {type: 'select'}}, |
26 | | - }, |
27 | 13 | } as Meta; |
28 | 14 |
|
29 | | -const __getFormData = (formData: FormBlockModel['formData']): FormBlockModel['formData'] => { |
30 | | - const id = uuidv4(); |
31 | | - return isHubspotDataForm(formData) |
32 | | - ? ({hubspot: {...formData.hubspot, formInstanceId: id}} as FormBlockModel['formData']) |
33 | | - : {yandex: formData.yandex}; |
34 | | -}; |
| 15 | +const DIRECTIONS_VARIANTS = [ |
| 16 | + FormBlockDirection.FormContent, |
| 17 | + FormBlockDirection.ContentForm, |
| 18 | + FormBlockDirection.Center, |
| 19 | +].map((direction) => ({ |
| 20 | + ...data.default, |
| 21 | + direction, |
| 22 | + formData: {hubspot: {...data.default.formData.hubspot, formInstanceId: uuidv4()}}, |
| 23 | +})); |
35 | 24 |
|
36 | 25 | const DefaultTemplate: StoryFn<FormBlockModel> = (args) => ( |
37 | | - <PageConstructor |
38 | | - content={{ |
39 | | - blocks: [ |
40 | | - { |
41 | | - ...args, |
42 | | - formData: __getFormData(args.formData), |
43 | | - }, |
44 | | - ], |
45 | | - }} |
46 | | - /> |
| 26 | + <FormBlock {...(blockTransform(args) as FormBlockProps)} /> |
47 | 27 | ); |
48 | 28 |
|
49 | | -const ContentDirectionTemplate: StoryFn<FormBlockModel> = (args) => ( |
50 | | - <PageConstructor |
51 | | - content={{ |
52 | | - blocks: [ |
53 | | - { |
54 | | - ...args, |
55 | | - direction: FormBlockDirection.FormContent, |
56 | | - textContent: {...args.textContent, title: 'FormContent'}, |
57 | | - formData: __getFormData(args.formData), |
58 | | - }, |
59 | | - { |
60 | | - ...args, |
61 | | - direction: FormBlockDirection.ContentForm, |
62 | | - textContent: { |
63 | | - ...args.textContent, |
64 | | - title: 'ContentForm', |
65 | | - }, |
66 | | - formData: __getFormData(args.formData), |
67 | | - }, |
68 | | - { |
69 | | - ...args, |
70 | | - direction: FormBlockDirection.Center, |
71 | | - textContent: {...args.textContent, title: 'Center'}, |
72 | | - formData: __getFormData(args.formData), |
73 | | - }, |
74 | | - ], |
75 | | - }} |
76 | | - /> |
77 | | -); |
78 | | - |
79 | | -const FormDataTemplate: StoryFn<FormBlockModel> = (args) => ( |
80 | | - <React.Fragment> |
81 | | - <ContentDirectionTemplate {...args} /> |
82 | | - <ContentDirectionTemplate |
83 | | - {...args} |
84 | | - {...(data.default as FormBlockModel)} |
85 | | - {...data.withBackground} |
86 | | - /> |
87 | | - </React.Fragment> |
| 29 | +const VariantsTemplate: StoryFn<Record<number, FormBlockModel>> = (args) => ( |
| 30 | + <div> |
| 31 | + {Object.values(args).map((arg, index) => ( |
| 32 | + <div key={index} style={{marginBottom: '96px'}}> |
| 33 | + <FormBlock {...(blockTransform(arg) as FormBlockProps)} /> |
| 34 | + </div> |
| 35 | + ))} |
| 36 | + </div> |
88 | 37 | ); |
89 | 38 |
|
90 | 39 | export const Default = DefaultTemplate.bind({}); |
91 | | -export const ContentDirection = ContentDirectionTemplate.bind({}); |
92 | | -export const WithBackgroundColor = ContentDirectionTemplate.bind({}); |
93 | | -export const WithBackgroundImage = ContentDirectionTemplate.bind({}); |
94 | | -export const DarkTheme = ContentDirectionTemplate.bind({}); |
95 | | -export const FormData = FormDataTemplate.bind({}); |
| 40 | +export const ContentDirection = VariantsTemplate.bind([]); |
| 41 | +export const WithBackgroundColor = VariantsTemplate.bind([]); |
| 42 | +export const WithBackgroundImage = VariantsTemplate.bind([]); |
| 43 | +export const DarkTheme = VariantsTemplate.bind([]); |
| 44 | +export const FormData = VariantsTemplate.bind([]); |
| 45 | + |
| 46 | +Default.args = data.default as FormBlockModel; |
| 47 | + |
| 48 | +ContentDirection.args = DIRECTIONS_VARIANTS as FormBlockModel[]; |
| 49 | +ContentDirection.parameters = { |
| 50 | + controls: { |
| 51 | + include: Object.keys(DIRECTIONS_VARIANTS), |
| 52 | + }, |
| 53 | +}; |
96 | 54 |
|
97 | | -WithBackgroundColor.args = data.withBackground; |
| 55 | +WithBackgroundColor.args = DIRECTIONS_VARIANTS.map((variant) => ({ |
| 56 | + ...variant, |
| 57 | + ...data.withBackground, |
| 58 | +})) as FormBlockModel[]; |
| 59 | +WithBackgroundColor.parameters = { |
| 60 | + controls: { |
| 61 | + include: Object.keys(DIRECTIONS_VARIANTS), |
| 62 | + }, |
| 63 | +}; |
98 | 64 |
|
99 | | -WithBackgroundImage.args = data.withBackgroundImage; |
| 65 | +WithBackgroundImage.args = DIRECTIONS_VARIANTS.map((variant) => ({ |
| 66 | + ...variant, |
| 67 | + ...data.withBackgroundImage, |
| 68 | +})) as FormBlockModel[]; |
| 69 | +WithBackgroundImage.parameters = { |
| 70 | + controls: { |
| 71 | + include: Object.keys(DIRECTIONS_VARIANTS), |
| 72 | + }, |
| 73 | +}; |
100 | 74 |
|
101 | | -DarkTheme.args = data.darkTheme as FormBlockModel; |
| 75 | +DarkTheme.args = DIRECTIONS_VARIANTS.map((variant) => ({ |
| 76 | + ...variant, |
| 77 | + ...data.darkTheme, |
| 78 | +})) as FormBlockModel[]; |
| 79 | +DarkTheme.parameters = { |
| 80 | + controls: { |
| 81 | + include: Object.keys(DIRECTIONS_VARIANTS), |
| 82 | + }, |
| 83 | +}; |
102 | 84 |
|
103 | | -FormData.args = {...data.yandexForm, ...data.withBackgroundImage}; |
| 85 | +FormData.args = [data.default, data.yandexForm] as FormBlockModel[]; |
| 86 | +FormData.parameters = { |
| 87 | + controls: { |
| 88 | + include: Object.keys(FormData.args), |
| 89 | + }, |
| 90 | +}; |
0 commit comments