Skip to content

Commit aeb2132

Browse files
author
berdysheva
committed
feat: add utils to storybook
1 parent 73675a7 commit aeb2132

File tree

12 files changed

+39
-87
lines changed

12 files changed

+39
-87
lines changed

.storybook/utils.ts

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
import yfm from '@doc-tools/transform';
2+
3+
export const yfmTransform = (content: string) => yfm(content).result.html;

src/blocks/CardLayout/__stories__/CardLayout.stories.tsx

Lines changed: 1 addition & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -12,14 +12,7 @@ export default {
1212
component: CardLayout,
1313
} as Meta;
1414

15-
const createCardArray = (count: number, card: any) => {
16-
const cardArray = [];
17-
for (let i = 0; i < count; i++) {
18-
cardArray.push(card);
19-
}
20-
21-
return cardArray;
22-
};
15+
const createCardArray = (count: number, card: any) => new Array(count).fill(card);
2316

2417
const DefaultTemplate: Story<CardLayoutBlockModel> = (args) => (
2518
<PageConstructor content={{blocks: [args]}} />

src/blocks/ContentLayout/__stories__/ContentLayout.stories.tsx

Lines changed: 14 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
import React from 'react';
2-
import yfm from '@doc-tools/transform';
32
import {Meta, Story} from '@storybook/react/types-6-0';
43
import {
54
ContentLayoutBlockModel,
@@ -10,6 +9,7 @@ import {
109
} from '../../../models';
1110
import Content from '../ContentLayout';
1211
import {PageConstructor} from '../../../containers/PageConstructor/PageConstructor';
12+
import {yfmTransform} from '../../../../.storybook/utils';
1313

1414
import data from './data.json';
1515

@@ -31,7 +31,7 @@ const DefaultTemplate: Story<ContentLayoutBlockModel> = (args) => (
3131
...args,
3232
textContent: {
3333
...args.textContent,
34-
additionalInfo: yfm(data.common.additionalInfo).result.html,
34+
additionalInfo: yfmTransform(data.common.additionalInfo),
3535
},
3636
},
3737
{
@@ -113,6 +113,7 @@ const ThemesTemplate: Story<ContentLayoutBlockModel> = (args) => (
113113
...args,
114114
properties: {
115115
...args.properties,
116+
...data.theme.lightProperties.properties,
116117
theme: data.theme.lightProperties.properties.theme as ContentTheme,
117118
},
118119
textContent: {
@@ -158,26 +159,29 @@ export const WithBackgroundImageAndColor = BackgroundTemplate.bind({});
158159
export const TextAlignCenter = BackgroundTemplate.bind({});
159160
export const Theme = ThemesTemplate.bind([]);
160161
export const TextWidth = TextWidthTemplate.bind([]);
162+
163+
const transformedText = yfmTransform(data.common.text);
164+
161165
Default.args = {
162166
...data.default.content,
163167
textContent: {
164168
title: data.common.title,
165-
text: yfm(data.common.text).result.html,
169+
text: transformedText,
166170
},
167171
} as ContentLayoutBlockProps;
168172

169173
WithFiles.args = {
170174
...data.default.content,
171175
textContent: {
172-
text: yfm(data.common.text).result.html,
176+
text: transformedText,
173177
},
174178
fileContent: data.common.fileContent,
175179
} as ContentLayoutBlockProps;
176180

177181
Size.args = {
178182
...data.size.content,
179183
textContent: {
180-
text: yfm(data.common.text).result.html,
184+
text: transformedText,
181185
buttons: data.common.buttons,
182186
},
183187
} as ContentLayoutBlockProps;
@@ -186,7 +190,7 @@ WithBackgroundColor.args = {
186190
...data.withBackgroundColor.content,
187191
textContent: {
188192
title: data.common.title,
189-
text: yfm(data.common.text).result.html,
193+
text: transformedText,
190194
buttons: data.common.buttons,
191195
},
192196
} as ContentLayoutBlockProps;
@@ -195,7 +199,7 @@ WithBackgroundImageAndColor.args = {
195199
...data.withImageAndBackgroundColor.content,
196200
textContent: {
197201
title: data.common.title,
198-
text: yfm(data.common.text).result.html,
202+
text: transformedText,
199203
buttons: data.common.buttons,
200204
},
201205
} as ContentLayoutBlockProps;
@@ -204,22 +208,22 @@ TextAlignCenter.args = {
204208
...data.textAlignCenter.content,
205209
textContent: {
206210
title: data.common.title,
207-
text: yfm(data.common.text).result.html,
211+
text: transformedText,
208212
buttons: data.common.buttons,
209213
},
210214
} as ContentLayoutBlockProps;
211215

212216
Theme.args = {
213217
...data.theme.content,
214218
textContent: {
215-
text: yfm(data.common.text).result.html,
219+
text: transformedText,
216220
},
217221
} as ContentLayoutBlockProps;
218222

219223
TextWidth.args = {
220224
...data.textWidth.content,
221225
textContent: {
222-
text: yfm(data.common.text).result.html,
226+
text: transformedText,
223227
buttons: data.common.buttons,
224228
},
225229
} as ContentLayoutBlockProps;

src/blocks/ContentLayout/__stories__/data.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -130,7 +130,7 @@
130130
"theme": "light",
131131
"background": {
132132
"style": {
133-
"backgroundColor": "#CCF0D2"
133+
"backgroundColor": "#ccf0d2"
134134
}
135135
}
136136
},

src/blocks/Header/__stories__/Header.stories.tsx

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,9 @@
11
import React, {Fragment} from 'react';
2-
import yfm from '@doc-tools/transform';
32
import {Meta, Story} from '@storybook/react/types-6-0';
43
import {ButtonProps, HeaderBlockModel, HeaderBlockProps} from '../../../models';
54
import Header from '../Header';
65
import {PageConstructor} from '../../../containers/PageConstructor';
6+
import {yfmTransform} from '../../../../.storybook/utils';
77

88
import data from './data.json';
99

@@ -34,7 +34,7 @@ export default {
3434

3535
const DefaultArgs = {
3636
...data.default.content,
37-
description: yfm(data.default.content.description).result.html,
37+
description: yfmTransform(data.default.content.description),
3838
};
3939

4040
const DefaultTemplate: Story<HeaderBlockModel> = (args) => (

src/blocks/Info/__stories__/Info.stories.tsx

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import React from 'react';
2-
import yfm from '@doc-tools/transform';
32
import {Meta, Story} from '@storybook/react/types-6-0';
43
import {InfoBlockModel, InfoBlockProps} from '../../../models';
4+
import {yfmTransform} from '../../../../.storybook/utils';
55
import Info from '../Info';
66
import {PageConstructor} from '../../../containers/PageConstructor/PageConstructor';
77

@@ -19,17 +19,19 @@ const DefaultTemplate: Story<InfoBlockModel> = (args) => (
1919
export const Default = DefaultTemplate.bind({});
2020
export const LightTheme = DefaultTemplate.bind({});
2121

22+
const transformedText = yfmTransform(data.common.text);
23+
2224
Default.args = {
2325
...data.dark.content,
2426
leftContent: {
2527
...data.dark.content.leftContent,
2628
title: data.common.title,
27-
text: yfm(data.common.text).result.html,
29+
text: transformedText,
2830
},
2931
rightContent: {
3032
title: data.common.title,
3133
links: data.common.links,
32-
text: yfm(data.common.text).result.html,
34+
text: transformedText,
3335
},
3436
} as InfoBlockProps;
3537

@@ -38,11 +40,11 @@ LightTheme.args = {
3840
leftContent: {
3941
...data.light.content.leftContent,
4042
title: data.common.title,
41-
text: yfm(data.common.text).result.html,
43+
text: transformedText,
4244
},
4345
rightContent: {
4446
title: data.common.title,
4547
links: data.common.links,
46-
text: yfm(data.common.text).result.html,
48+
text: transformedText,
4749
},
4850
} as InfoBlockProps;

src/blocks/Media/__stories__/Media.stories.tsx

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
import React from 'react';
22
import {Meta, Story} from '@storybook/react/types-6-0';
3+
import {yfmTransform} from '../../../../.storybook/utils';
34
import {
45
ButtonProps,
56
LinkProps,
@@ -11,7 +12,6 @@ import Media from '../Media';
1112
import {PageConstructor} from '../../../containers/PageConstructor/PageConstructor';
1213

1314
import data from './data.json';
14-
import yfm from '@doc-tools/transform';
1515

1616
export default {
1717
title: 'Blocks/Media',
@@ -29,7 +29,7 @@ const DefaultTemplate: Story<MediaBlockModel> = (args) => (
2929
blocks: [
3030
{
3131
...args,
32-
additionalInfo: yfm(data.common.additionalInfo).result.html,
32+
additionalInfo: yfmTransform(data.common.additionalInfo),
3333
},
3434
{
3535
...args,
@@ -129,7 +129,7 @@ export const WithoutShadow = ImageSliderTemplate.bind({});
129129
const DefaultArgs = {
130130
...data.default.content,
131131
title: data.common.title,
132-
description: yfm(data.common.description).result.html,
132+
description: yfmTransform(data.common.description),
133133
};
134134

135135
Default.args = DefaultArgs as MediaBlockProps;

src/blocks/PromoFeaturesBlock/__stories__/PromoFeaturesBlock.stories.tsx

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import {Meta, Story} from '@storybook/react/types-6-0';
22
import React from 'react';
3-
import yfm from '@doc-tools/transform';
3+
import {yfmTransform} from '../../../../.storybook/utils';
44

55
import PromoFeaturesBlock from '../PromoFeaturesBlock';
66
import {PromoFeaturesBlockModel, PromoFeaturesProps} from '../../../models';
@@ -25,7 +25,7 @@ export const GreyTheme = DefaultTemplate.bind({});
2525

2626
const DefaultArgs = {
2727
...data.common,
28-
description: yfm(data.common.description).result.html,
28+
description: yfmTransform(data.common.description),
2929
};
3030

3131
DefaultTheme.args = {
@@ -34,7 +34,7 @@ DefaultTheme.args = {
3434
items: data.defaultTheme.content.items.map((item) => {
3535
return {
3636
...item,
37-
text: yfm(item.text).result.html,
37+
text: yfmTransform(item.text),
3838
};
3939
}),
4040
} as PromoFeaturesProps;
@@ -44,7 +44,7 @@ GreyTheme.args = {
4444
items: data.greyTheme.content.items.map((item) => {
4545
return {
4646
...item,
47-
text: yfm(item.text).result.html,
47+
text: yfmTransform(item.text),
4848
};
4949
}),
5050
} as PromoFeaturesProps;

src/blocks/Simple/__stories__/Simple.stories.tsx

Lines changed: 0 additions & 25 deletions
This file was deleted.

src/blocks/Simple/__stories__/data.json

Lines changed: 0 additions & 25 deletions
This file was deleted.

0 commit comments

Comments
 (0)