@@ -10,10 +10,6 @@ import BackgroundCard from '../BackgroundCard';
10
10
11
11
import data from './data.json' ;
12
12
13
- interface BackgroundCardStoryProps {
14
- items : BackgroundCardProps [ ] ;
15
- }
16
-
17
13
const transformContentList = ( list : ContentItemProps [ ] ) =>
18
14
list . map ( ( item ) => {
19
15
return {
@@ -25,28 +21,6 @@ const transformContentList = (list: ContentItemProps[]) =>
25
21
const getPaddingBottomTitle = ( padding : string ) =>
26
22
data . paddings . title . replace ( '{{padding}}' , padding ) ;
27
23
28
- const getStoryArgs = (
29
- count : number ,
30
- args : BackgroundCardProps ,
31
- getExtra : ( index : number ) => Partial < BackgroundCardProps > ,
32
- ) : BackgroundCardStoryProps => ( {
33
- items : new Array ( count ) . fill ( null ) . map ( ( _ , index ) => ( { ...args , ...getExtra ( index ) } ) ) ,
34
- } ) ;
35
-
36
- const getDefaultExtraArgs : Parameters < typeof getStoryArgs > [ 2 ] = ( index ) => {
37
- switch ( index ) {
38
- case 0 :
39
- return { additionalInfo : yfmTransform ( data . common . additionalInfo ) } ;
40
- case 1 :
41
- return { links : data . common . links as LinkProps [ ] } ;
42
- case 2 :
43
- return { buttons : data . common . buttons as ButtonProps [ ] } ;
44
- case 3 :
45
- default :
46
- return { list : transformContentList ( data . common . list ) } ;
47
- }
48
- } ;
49
-
50
24
export default {
51
25
component : BackgroundCard ,
52
26
title : 'Components/Cards/BackgroundCard' ,
@@ -65,20 +39,41 @@ export default {
65
39
} ,
66
40
} as Meta ;
67
41
68
- const DefaultTemplate : StoryFn < BackgroundCardStoryProps & BackgroundCardProps > = ( {
69
- items,
70
- ...props
71
- } ) => (
42
+ const DefaultTemplate : StoryFn < BackgroundCardProps > = ( args ) => (
72
43
< div style = { { display : 'flex' } } >
73
- { items . map ( ( item , index ) => (
74
- < div key = { index } style = { { display : 'inline-table' , maxWidth : '400px' , padding : '0 8px' } } >
75
- < BackgroundCard { ...item } { ...props } />
76
- </ div >
77
- ) ) }
44
+ < div style = { { display : 'inline-table' , maxWidth : '400px' , padding : '0 8px' } } >
45
+ < BackgroundCard { ...args } additionalInfo = { yfmTransform ( data . common . additionalInfo ) } />
46
+ </ div >
47
+ < div style = { { display : 'inline-table' , maxWidth : '400px' , padding : '0 8px' } } >
48
+ < BackgroundCard { ...args } links = { data . common . links as LinkProps [ ] } />
49
+ </ div >
50
+ < div style = { { display : 'inline-table' , maxWidth : '400px' , padding : '0 8px' } } >
51
+ < BackgroundCard { ...args } buttons = { data . common . buttons as ButtonProps [ ] } />
52
+ </ div >
53
+ < div style = { { display : 'inline-table' , maxWidth : '400px' , padding : '0 8px' } } >
54
+ < BackgroundCard { ...args } list = { transformContentList ( data . common . list ) } />
55
+ </ div >
56
+ </ div >
57
+ ) ;
58
+
59
+ const PaddingsTemplate : StoryFn < BackgroundCardProps > = ( args ) => (
60
+ < div style = { { display : 'flex' } } >
61
+ < div style = { { display : 'inline-table' , maxWidth : '400px' , padding : '0 8px' } } >
62
+ < BackgroundCard { ...args } title = { getPaddingBottomTitle ( 'S' ) } paddingBottom = "s" />
63
+ </ div >
64
+ < div style = { { display : 'inline-table' , maxWidth : '400px' , padding : '0 8px' } } >
65
+ < BackgroundCard { ...args } title = { getPaddingBottomTitle ( 'M' ) } paddingBottom = "m" />
66
+ </ div >
67
+ < div style = { { display : 'inline-table' , maxWidth : '400px' , padding : '0 8px' } } >
68
+ < BackgroundCard { ...args } title = { getPaddingBottomTitle ( 'L' ) } paddingBottom = "l" />
69
+ </ div >
70
+ < div style = { { display : 'inline-table' , maxWidth : '400px' , padding : '0 8px' } } >
71
+ < BackgroundCard { ...args } title = { getPaddingBottomTitle ( 'XL' ) } paddingBottom = "xl" />
72
+ </ div >
78
73
</ div >
79
74
) ;
80
75
81
- const CardThemesTemplate : StoryFn < BackgroundCardStoryProps > = ( args ) => (
76
+ const CardThemesTemplate : StoryFn < { items : BackgroundCardProps [ ] } > = ( args ) => (
82
77
< div style = { { display : 'flex' } } >
83
78
{ args . items . map ( ( item , i ) => (
84
79
< div style = { { maxWidth : '400px' , padding : '0 8px' } } key = { i } >
@@ -95,6 +90,33 @@ const CardThemesTemplate: StoryFn<BackgroundCardStoryProps> = (args) => (
95
90
</ div >
96
91
) ;
97
92
93
+ const BackgroundColorTemplate : StoryFn < BackgroundCardProps > = ( args ) => (
94
+ < div style = { { display : 'flex' } } >
95
+ < div style = { { display : 'inline-table' , maxWidth : '400px' , padding : '0 8px' } } >
96
+ < BackgroundCard { ...args } additionalInfo = { yfmTransform ( data . common . additionalInfo ) } />
97
+ </ div >
98
+ < div style = { { display : 'inline-table' , maxWidth : '400px' , padding : '0 8px' } } >
99
+ < BackgroundCard { ...args } links = { data . common . links as LinkProps [ ] } />
100
+ </ div >
101
+ < div style = { { display : 'inline-table' , maxWidth : '400px' , padding : '0 8px' } } >
102
+ < BackgroundCard
103
+ { ...args }
104
+ buttons = { data . cardThemes . content [ 1 ] . buttons as ButtonProps [ ] }
105
+ />
106
+ </ div >
107
+ </ div >
108
+ ) ;
109
+
110
+ const WithUrlTemplate : StoryFn < { items : BackgroundCardProps [ ] } > = ( args ) => (
111
+ < div style = { { display : 'flex' } } >
112
+ { args . items . map ( ( item , i ) => (
113
+ < div style = { { maxWidth : '400px' , padding : '0 8px' } } key = { i } >
114
+ < BackgroundCard { ...item } />
115
+ </ div >
116
+ ) ) }
117
+ </ div >
118
+ ) ;
119
+
98
120
const ControlPositionTemplate : StoryFn < BackgroundCardProps > = ( args ) => (
99
121
< Grid >
100
122
< ConstructorRow >
@@ -132,49 +154,31 @@ const ControlPositionTemplate: StoryFn<BackgroundCardProps> = (args) => (
132
154
133
155
export const Default = DefaultTemplate . bind ( { } ) ;
134
156
export const WithBackgroundImage = DefaultTemplate . bind ( { } ) ;
135
- export const Paddings = DefaultTemplate . bind ( { } ) ;
157
+ export const Paddings = PaddingsTemplate . bind ( { } ) ;
136
158
export const CardThemes = CardThemesTemplate . bind ( [ ] ) ;
137
159
export const BorderLine = DefaultTemplate . bind ( { } ) ;
138
- export const BackgroundColor = DefaultTemplate . bind ( { } ) ;
139
- export const WithUrl = DefaultTemplate . bind ( { } ) ;
160
+ export const BackgroundColor = BackgroundColorTemplate . bind ( { } ) ;
161
+ export const WithUrl = WithUrlTemplate . bind ( { } ) ;
140
162
export const ControlPosition = ControlPositionTemplate . bind ( { } ) ;
141
163
142
164
const DefaultArgs = {
143
165
title : data . common . title ,
144
166
text : yfmTransform ( data . common . text ) ,
145
167
} ;
146
168
147
- Default . args = getStoryArgs ( 4 , DefaultArgs , getDefaultExtraArgs ) ;
169
+ Default . args = {
170
+ ...DefaultArgs ,
171
+ } as BackgroundCardProps ;
148
172
149
- WithBackgroundImage . args = getStoryArgs (
150
- 4 ,
151
- {
152
- ...DefaultArgs ,
153
- ...data . withBackgroundImage . content ,
154
- } ,
155
- getDefaultExtraArgs ,
156
- ) ;
173
+ WithBackgroundImage . args = {
174
+ ...DefaultArgs ,
175
+ ...data . withBackgroundImage . content ,
176
+ } as BackgroundCardProps ;
157
177
158
- Paddings . args = getStoryArgs (
159
- 4 ,
160
- {
161
- ...DefaultArgs ,
162
- ...data . withBackgroundImage . content ,
163
- } ,
164
- ( index ) => {
165
- switch ( index ) {
166
- case 0 :
167
- return { title : getPaddingBottomTitle ( 'S' ) , paddingBottom : 's' } ;
168
- case 1 :
169
- return { title : getPaddingBottomTitle ( 'M' ) , paddingBottom : 'm' } ;
170
- case 2 :
171
- return { title : getPaddingBottomTitle ( 'L' ) , paddingBottom : 'l' } ;
172
- case 3 :
173
- default :
174
- return { title : getPaddingBottomTitle ( 'XL' ) , paddingBottom : 'xl' } ;
175
- }
176
- } ,
177
- ) ;
178
+ Paddings . args = {
179
+ ...DefaultArgs ,
180
+ ...data . withBackgroundImage . content ,
181
+ } as BackgroundCardProps ;
178
182
179
183
CardThemes . args = {
180
184
items : [ ...data . cardThemes . content ] . map ( ( item ) => ( {
@@ -183,34 +187,16 @@ CardThemes.args = {
183
187
} ) ) as BackgroundCardProps [ ] ,
184
188
} ;
185
189
186
- BorderLine . args = getStoryArgs (
187
- 4 ,
188
- {
189
- ...DefaultArgs ,
190
- ...data . borderLine . content ,
191
- ...data . withBackgroundImage . content ,
192
- } as BackgroundCardProps ,
193
- getDefaultExtraArgs ,
194
- ) ;
190
+ BorderLine . args = {
191
+ ...DefaultArgs ,
192
+ ...data . borderLine . content ,
193
+ ...data . withBackgroundImage . content ,
194
+ } as BackgroundCardProps ;
195
195
196
- BackgroundColor . args = getStoryArgs (
197
- 3 ,
198
- {
199
- ...DefaultArgs ,
200
- ...data . backgroundColor . content ,
201
- } as BackgroundCardProps ,
202
- ( index ) => {
203
- switch ( index ) {
204
- case 0 :
205
- return { additionalInfo : yfmTransform ( data . common . additionalInfo ) } ;
206
- case 1 :
207
- return { links : data . common . links as LinkProps [ ] } ;
208
- case 2 :
209
- default :
210
- return { buttons : data . cardThemes . content [ 1 ] . buttons as ButtonProps [ ] } ;
211
- }
212
- } ,
213
- ) ;
196
+ BackgroundColor . args = {
197
+ ...DefaultArgs ,
198
+ ...data . backgroundColor . content ,
199
+ } as BackgroundCardProps ;
214
200
215
201
WithUrl . args = {
216
202
items : [
0 commit comments