|
1 | | -import React from 'react'; |
| 1 | +import React, {Fragment} from 'react'; |
2 | 2 | import {Meta, Story} from '@storybook/react/types-6-0'; |
3 | 3 |
|
4 | 4 | import CardLayout from '../CardLayout'; |
5 | | -import {CardLayoutBlockModel, CardLayoutBlockProps} from '../../../models'; |
6 | | -import {PageConstructor} from '../../../containers/PageConstructor/PageConstructor'; |
| 5 | +import {CardLayoutBlockModel, CardLayoutBlockProps, SubBlockModels} from '../../../models'; |
| 6 | +import {PageConstructor} from '../../../containers/PageConstructor'; |
7 | 7 |
|
8 | 8 | import data from './data.json'; |
9 | 9 |
|
10 | | -const getPaddingsStoryName = (size: string) => { |
11 | | - return data.cardsPaddings.storyName.replace('{{size}}', size); |
12 | | -}; |
13 | | - |
14 | 10 | export default { |
15 | 11 | title: 'Blocks/CardLayout', |
16 | 12 | component: CardLayout, |
17 | 13 | } as Meta; |
18 | 14 |
|
| 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 | +}; |
| 23 | + |
19 | 24 | const DefaultTemplate: Story<CardLayoutBlockModel> = (args) => ( |
20 | 25 | <PageConstructor content={{blocks: [args]}} /> |
21 | 26 | ); |
22 | 27 |
|
23 | | -const PaddingsTemplate: Story<CardLayoutBlockModel> = (args) => ( |
24 | | - <PageConstructor |
25 | | - content={{ |
26 | | - blocks: [ |
27 | | - { |
28 | | - ...args, |
29 | | - title: getPaddingsStoryName('s'), |
30 | | - children: args.children?.map((child) => ({...child, paddingBottom: 's'})), |
31 | | - }, |
32 | | - { |
33 | | - ...args, |
34 | | - title: getPaddingsStoryName('m'), |
35 | | - children: args.children?.map((child) => ({...child, paddingBottom: 'm'})), |
36 | | - }, |
37 | | - { |
38 | | - ...args, |
39 | | - title: getPaddingsStoryName('l'), |
40 | | - children: args.children?.map((child) => ({...child, paddingBottom: 'l'})), |
41 | | - }, |
42 | | - { |
43 | | - ...args, |
44 | | - title: getPaddingsStoryName('xl'), |
45 | | - children: args.children?.map((child) => ({...child, paddingBottom: 'xl'})), |
46 | | - }, |
47 | | - ], |
48 | | - }} |
49 | | - /> |
| 28 | +const ColSizeTemplate: Story<CardLayoutBlockModel> = (args) => ( |
| 29 | + <Fragment> |
| 30 | + <PageConstructor |
| 31 | + content={{ |
| 32 | + blocks: [ |
| 33 | + { |
| 34 | + ...args, |
| 35 | + description: data.colSizes.four.description, |
| 36 | + colSizes: data.colSizes.four.colSizes, |
| 37 | + }, |
| 38 | + { |
| 39 | + ...args, |
| 40 | + description: data.colSizes.two.description, |
| 41 | + colSizes: data.colSizes.two.colSizes, |
| 42 | + children: createCardArray(8, data.colSizes.two.card) as SubBlockModels[], |
| 43 | + }, |
| 44 | + ], |
| 45 | + }} |
| 46 | + /> |
| 47 | + </Fragment> |
50 | 48 | ); |
51 | 49 |
|
52 | | -export const CardsWithImage = DefaultTemplate.bind([]); |
53 | | -export const CardsWithImageFullScreen = DefaultTemplate.bind([]); |
54 | | -export const CardsWithImageAllProps = DefaultTemplate.bind([]); |
55 | | -export const BackgroundCardsPaddings = PaddingsTemplate.bind([]); |
56 | | -export const BackgroundCardsBackgroundColor = DefaultTemplate.bind([]); |
57 | | -export const BackgroundCardsContentSizes = DefaultTemplate.bind([]); |
58 | | -export const BackgroundCardsThemes = DefaultTemplate.bind([]); |
59 | | - |
60 | | -CardsWithImage.args = data.cardsWithImage.content as CardLayoutBlockProps; |
61 | | -CardsWithImage.storyName = data.cardsWithImage.storyName; |
62 | | - |
63 | | -CardsWithImageFullScreen.args = data.cardsWithImageFullScreen.content as CardLayoutBlockProps; |
64 | | -CardsWithImageFullScreen.storyName = data.cardsWithImageFullScreen.storyName; |
65 | | - |
66 | | -CardsWithImageAllProps.args = data.cardsWithImageAllProps.content as CardLayoutBlockProps; |
67 | | -CardsWithImageAllProps.storyName = data.cardsWithImageAllProps.storyName; |
68 | | - |
69 | | -BackgroundCardsPaddings.args = data.cardsPaddings.content as CardLayoutBlockProps; |
70 | | - |
71 | | -BackgroundCardsBackgroundColor.args = data.cardsBackgroundColor.content as CardLayoutBlockProps; |
72 | | -BackgroundCardsBackgroundColor.storyName = data.cardsBackgroundColor.storyName; |
| 50 | +export const Default = DefaultTemplate.bind({}); |
| 51 | +export const ColSize = ColSizeTemplate.bind({}); |
73 | 52 |
|
74 | | -BackgroundCardsContentSizes.args = data.cardsContentSizes.content as CardLayoutBlockProps; |
75 | | -BackgroundCardsContentSizes.storyName = data.cardsContentSizes.storyName; |
| 53 | +Default.args = { |
| 54 | + ...data.default.content, |
| 55 | + children: createCardArray(6, data.default.card), |
| 56 | +} as CardLayoutBlockProps; |
76 | 57 |
|
77 | | -BackgroundCardsThemes.args = data.backgroundCardThemes.content as CardLayoutBlockProps; |
78 | | -BackgroundCardsThemes.storyName = data.backgroundCardThemes.storyName; |
| 58 | +ColSize.args = { |
| 59 | + ...data.default.content, |
| 60 | + children: createCardArray(8, data.colSizes.four.card), |
| 61 | +} as CardLayoutBlockProps; |
0 commit comments