11import { Meta , Story } from '@storybook/react/types-6-0' ;
22import React from 'react' ;
3+ import yfm from '@doc-tools/transform' ;
34
45import BackgroundCard from '../BackgroundCard' ;
5- import { BackgroundCardModel , BackgroundCardProps } from '../../../models' ;
6+ import { BackgroundCardProps } from '../../../models' ;
67import { CARDS , COMPONENTS } from '../../../demo/constants' ;
78
89import data from './data.json' ;
910
11+ const getPaddingBottomTitle = ( padding : string ) =>
12+ data . paddings . title . replace ( '{{padding}}' , padding ) ;
13+
1014export default {
1115 component : BackgroundCard ,
1216 title : `${ COMPONENTS } /${ CARDS } /BackgroundCard` ,
@@ -26,46 +30,77 @@ const DefaultTemplate: Story<BackgroundCardProps> = (args) => (
2630const PaddingsTemplate : Story < BackgroundCardProps > = ( args ) => (
2731 < div style = { { display : 'flex' } } >
2832 < div style = { { display : 'inline-table' , maxWidth : '400px' , padding : '0 8px' } } >
29- < BackgroundCard { ...args } title = "paddingBottom = s" paddingBottom = "s" />
33+ < BackgroundCard { ...args } title = { getPaddingBottomTitle ( 'S' ) } paddingBottom = "s" />
3034 </ div >
3135 < div style = { { display : 'inline-table' , maxWidth : '400px' , padding : '0 8px' } } >
32- < BackgroundCard { ...args } title = "paddingBottom = m" paddingBottom = "m" />
36+ < BackgroundCard { ...args } title = { getPaddingBottomTitle ( 'M' ) } paddingBottom = "m" />
3337 </ div >
3438 < div style = { { display : 'inline-table' , maxWidth : '400px' , padding : '0 8px' } } >
35- < BackgroundCard { ...args } title = "paddingBottom = l" paddingBottom = "l" />
39+ < BackgroundCard { ...args } title = { getPaddingBottomTitle ( 'L' ) } paddingBottom = "l" />
3640 </ div >
3741 < div style = { { display : 'inline-table' , maxWidth : '400px' , padding : '0 8px' } } >
38- < BackgroundCard { ...args } title = "paddingBottom = xl" paddingBottom = "xl" />
42+ < BackgroundCard { ...args } title = { getPaddingBottomTitle ( 'XL' ) } paddingBottom = "xl" />
3943 </ div >
4044 </ div >
4145) ;
4246
43- const CardThemesTemplate : Story < BackgroundCardProps > = ( args ) => (
44- < div style = { { display : 'flex' } } >
45- < div style = { { maxWidth : '400px' , padding : '0 8px' } } >
46- < BackgroundCard { ...args } title = "Тема по умолчанию = s" theme = "default" />
47- </ div >
48- < div style = { { maxWidth : '400px' , padding : '0 8px' } } >
49- < BackgroundCard { ...args } title = "Темная тема = m" theme = "dark" />
50- </ div >
51- < div style = { { maxWidth : '400px' , padding : '0 8px' } } >
52- < BackgroundCard { ...args } title = "Светлая тема = l" theme = "light" />
47+ const CardThemesTemplate : Story < BackgroundCardProps [ ] > = ( args ) => {
48+ return (
49+ < div style = { { display : 'flex' } } >
50+ { Object . values ( args ) . map ( ( item , i ) => (
51+ < div style = { { maxWidth : '400px' , padding : '0 8px' } } key = { i } >
52+ < BackgroundCard { ...item } />
53+ </ div >
54+ ) ) }
5355 </ div >
54- </ div >
55- ) ;
56+ ) ;
57+ } ;
5658
5759export const Default = DefaultTemplate . bind ( { } ) ;
5860export const WithBackgroundImage = DefaultTemplate . bind ( { } ) ;
5961export const Paddings = PaddingsTemplate . bind ( { } ) ;
60- export const CardThemes = CardThemesTemplate . bind ( { } ) ;
62+ export const CardThemes = CardThemesTemplate . bind ( [ ] ) ;
6163export const BorderLine = DefaultTemplate . bind ( { } ) ;
6264export const BackgroundColor = DefaultTemplate . bind ( { } ) ;
6365export const WithTheme = DefaultTemplate . bind ( { } ) ;
6466
65- Default . args = data . default . content as BackgroundCardModel ;
66- WithBackgroundImage . args = data . withBackgroundImage . content as BackgroundCardModel ;
67- Paddings . args = data . paddings . content as BackgroundCardModel ;
68- CardThemes . args = data . cardThemes . content as BackgroundCardModel ;
69- BorderLine . args = data . borderLine . content as BackgroundCardModel ;
70- BackgroundColor . args = data . backgroundColor . content as BackgroundCardModel ;
71- WithTheme . args = data . withTheme . content as BackgroundCardModel ;
67+ const DefaultArgs = {
68+ ...data . default . content ,
69+ text : yfm ( data . default . content . text ) . result . html ,
70+ additionalInfo : yfm ( data . default . content . additionalInfo ) . result . html ,
71+ } ;
72+
73+ Default . args = {
74+ ...DefaultArgs ,
75+ } as BackgroundCardProps ;
76+
77+ WithBackgroundImage . args = {
78+ ...DefaultArgs ,
79+ ...data . withBackgroundImage . content ,
80+ } as BackgroundCardProps ;
81+
82+ Paddings . args = {
83+ ...DefaultArgs ,
84+ ...data . withBackgroundImage . content ,
85+ } as BackgroundCardProps ;
86+
87+ CardThemes . args = [ ...data . cardThemes . content ] . map ( ( item ) => ( {
88+ ...DefaultArgs ,
89+ ...item ,
90+ } ) ) as BackgroundCardProps [ ] ;
91+
92+ BorderLine . args = {
93+ ...DefaultArgs ,
94+ ...data . borderLine . content ,
95+ ...data . withBackgroundImage . content ,
96+ } as BackgroundCardProps ;
97+
98+ BackgroundColor . args = {
99+ ...DefaultArgs ,
100+ ...data . backgroundColor . content ,
101+ } as BackgroundCardProps ;
102+
103+ WithTheme . args = {
104+ ...DefaultArgs ,
105+ ...data . withTheme . content ,
106+ } as BackgroundCardProps ;
0 commit comments