@@ -49,11 +49,11 @@ interface GenerateItemsArgs {
4949 variant ?: 'primary' | 'secondary' ;
5050 withHelper ?: boolean ;
5151 withIndicator ?: boolean ;
52- extraLongTitle ?: boolean ;
5352 tooltip ?: boolean ;
5453 colProps ?: ColProps ;
5554 layout ?: 'separated' | 'segmented' ;
5655 justifyContent ?: 'start' | 'center' | 'end' | 'between' | 'around' | 'evenly' ;
56+ withIcons ?: boolean ;
5757}
5858
5959const generateItems = ( {
@@ -66,36 +66,44 @@ const generateItems = ({
6666 colProps,
6767 layout,
6868 justifyContent,
69- } : GenerateItemsArgs ) : ExtendedChoiceGroupItemProps [ ] => [
70- {
71- id : `${ inputType } -${ variant } -value-${ index * 10 + 1 } -${ withHelper } -${ withIndicator } -${ layout } ` ,
72- label : 'Text' ,
73- value : `${ inputType } -${ variant } -value-${ index * 10 + 1 } -${ withHelper } -${ withIndicator } -${ layout } ` ,
74- ...( withHelper && { helper : { text : 'Description' } } ) ,
75- colProps,
76- tooltip : tooltip ? 'Tooltip' : undefined ,
77- justifyContent,
78- } ,
79- {
80- id : `${ inputType } -${ variant } -value-${ index * 10 + 2 } -${ withHelper } -${ withIndicator } -${ layout } ` ,
81- label : 'Text' ,
82- value : `${ inputType } -${ variant } -value-${ index * 10 + 2 } -${ withHelper } -${ withIndicator } -${ layout } ` ,
83- ...( withHelper && { helper : { text : 'Description' } } ) ,
84- colProps,
85- tooltip : tooltip ? 'Tooltip' : undefined ,
86- justifyContent,
87- } ,
88- {
89- id : `${ inputType } -${ variant } -value-${ index * 10 + 3 } -${ withHelper } -${ withIndicator } -${ layout } ` ,
90- label : 'Text' ,
91- value : `${ inputType } -${ variant } -value-${ index * 10 + 3 } -${ withHelper } -${ withIndicator } -${ layout } ` ,
92- ...( withHelper && { helper : { text : 'Description' , type : 'error' } } ) ,
93- disabled : true ,
94- colProps,
95- tooltip : tooltip ? 'Tooltip' : undefined ,
96- justifyContent,
97- } ,
98- ] ;
69+ withIcons = false ,
70+ } : GenerateItemsArgs ) : ExtendedChoiceGroupItemProps [ ] => {
71+ const baseId = withIcons ? `icon-${ inputType } -${ variant } ` : `${ inputType } -${ variant } ` ;
72+ const icons = withIcons ? [ 'train' , 'directions_walk' , 'directions_car' ] : [ ] ;
73+
74+ return [ 1 , 2 , 3 ] . map ( ( i ) => {
75+ const itemIndex = index * 10 + i ;
76+ const suffix = `${ withHelper } -${ withIndicator } -${ layout ?? 'default' } ` ;
77+
78+ let label : React . ReactNode = 'Text' ;
79+
80+ if ( withIcons ) {
81+ label = (
82+ < Text >
83+ < Icon name = { icons [ i - 1 ] } color = "inherit" display = "inline" />
84+ { ' Text' }
85+ </ Text >
86+ ) ;
87+ }
88+
89+ return {
90+ id : `${ baseId } -value-${ itemIndex } -${ suffix } ` ,
91+ label,
92+ value : `${ baseId } -value-${ itemIndex } ` ,
93+ ...( withHelper && {
94+ helper : {
95+ text : 'Description' ,
96+ ...( i === 3 && { type : 'error' } ) ,
97+ } ,
98+ } ) ,
99+ disabled : i === 3 ,
100+ colProps,
101+ tooltip : tooltip ? 'Tooltip' : undefined ,
102+ justifyContent,
103+ ...( withIcons && i === 1 && { defaultChecked : true } ) ,
104+ } ;
105+ } ) ;
106+ } ;
99107
100108const renderGroup = (
101109 inputType : 'radio' | 'checkbox' ,
@@ -104,13 +112,14 @@ const renderGroup = (
104112 withIndicator : boolean ,
105113 layout : 'segmented' | 'separated' ,
106114 index : number ,
107- justifyContent : 'start' | 'center' | 'end' | 'between' | 'around' | 'evenly'
115+ justifyContent : 'start' | 'center' | 'end' | 'between' | 'around' | 'evenly' = 'start' ,
116+ withIcons = false
108117) => (
109- < Row key = { `${ inputType } -${ variant } -${ layout } -${ index } ` } >
118+ < Row key = { `${ withIcons ? 'icon-' : '' } ${ inputType } -${ variant } -${ layout } -${ index } ` } >
110119 < Col lg = { 6 } md = { 12 } >
111120 < ChoiceGroup
112121 color = "primary"
113- id = { `${ inputType } -${ variant } -${ layout } -no-helper-${ index } ` }
122+ id = { `${ withIcons ? 'icon-' : '' } ${ inputType } -${ variant } -${ layout } -no-helper-${ index } ` }
114123 inputType = { inputType }
115124 items = { generateItems ( {
116125 index,
@@ -120,10 +129,11 @@ const renderGroup = (
120129 withIndicator,
121130 layout,
122131 justifyContent,
132+ withIcons,
123133 } ) }
124134 label = "Filter"
125135 hideLabel
126- name = { `${ inputType } -${ variant } -${ layout } -no-helper-${ index } ` }
136+ name = { `${ withIcons ? 'icon-' : '' } ${ inputType } -${ variant } -${ layout } -no-helper-${ index } ` }
127137 showIndicator = { withIndicator }
128138 variant = "card"
129139 layout = { layout }
@@ -132,7 +142,7 @@ const renderGroup = (
132142 < Col lg = { 6 } md = { 12 } >
133143 < ChoiceGroup
134144 color = "secondary"
135- id = { `${ inputType } -${ variant } -${ layout } -with-helper-${ index } ` }
145+ id = { `${ withIcons ? 'icon-' : '' } ${ inputType } -${ variant } -${ layout } -with-helper-${ index } ` }
136146 inputType = { inputType }
137147 items = { generateItems ( {
138148 index : index + 1 ,
@@ -142,10 +152,11 @@ const renderGroup = (
142152 withIndicator,
143153 layout,
144154 justifyContent,
155+ withIcons,
145156 } ) }
146157 label = "Filter"
147158 hideLabel
148- name = { `${ inputType } -${ variant } -${ layout } -with-helper-${ index } ` }
159+ name = { `${ withIcons ? 'icon-' : '' } ${ inputType } -${ variant } -${ layout } -with-helper-${ index } ` }
149160 showIndicator = { withIndicator }
150161 variant = "card"
151162 layout = { layout }
@@ -154,7 +165,7 @@ const renderGroup = (
154165 </ Row >
155166) ;
156167
157- const renderChoiceGroups = ( inputType : 'radio' | 'checkbox' , layout : 'segmented' | 'separated' ) => (
168+ const renderChoiceGroups = ( inputType : 'radio' | 'checkbox' , layout : 'segmented' | 'separated' , withIcons = false ) => (
158169 < VerticalSpacing >
159170 < Row >
160171 < Col lg = { 6 } md = { 12 } >
@@ -164,12 +175,12 @@ const renderChoiceGroups = (inputType: 'radio' | 'checkbox', layout: 'segmented'
164175 < Text modifiers = "bold" > Secondary</ Text >
165176 </ Col >
166177 </ Row >
167- { renderGroup ( inputType , 'primary' , false , true , layout , 1 , 'start' ) }
168- { renderGroup ( inputType , 'primary' , true , true , layout , 2 , 'start' ) }
178+ { renderGroup ( inputType , 'primary' , false , true , layout , 1 , 'start' , withIcons ) }
179+ { renderGroup ( inputType , 'primary' , true , true , layout , 2 , 'start' , withIcons ) }
169180 { inputType !== 'radio' ||
170- ( layout !== 'separated' && renderGroup ( inputType , 'primary' , false , false , layout , 3 , 'start' ) ) }
181+ ( layout !== 'separated' && renderGroup ( inputType , 'primary' , false , false , layout , 3 , 'start' , withIcons ) ) }
171182 { inputType !== 'radio' ||
172- ( layout !== 'separated' && renderGroup ( inputType , 'primary' , true , false , layout , 4 , 'start' ) ) }
183+ ( layout !== 'separated' && renderGroup ( inputType , 'primary' , true , false , layout , 4 , 'start' , withIcons ) ) }
173184 </ VerticalSpacing >
174185) ;
175186
@@ -223,6 +234,40 @@ export const RadioCardSegmented = () => <VerticalSpacing>{renderChoiceGroups('ra
223234export const RadioCardSeparated = ( ) => < VerticalSpacing > { renderChoiceGroups ( 'radio' , 'separated' ) } </ VerticalSpacing > ;
224235export const CheckboxCard = ( ) => < VerticalSpacing > { renderChoiceGroups ( 'checkbox' , 'separated' ) } </ VerticalSpacing > ;
225236
237+ export const RadioCardWithIcon : Story = {
238+ render : ( ) => (
239+ < VerticalSpacing >
240+ < Row >
241+ < Col lg = { 6 } md = { 12 } >
242+ < Text modifiers = "bold" > Primary</ Text >
243+ </ Col >
244+ < Col lg = { 6 } md = { 12 } >
245+ < Text modifiers = "bold" > Secondary</ Text >
246+ </ Col >
247+ </ Row >
248+ { renderGroup ( 'radio' , 'primary' , false , true , 'segmented' , 1 , 'start' , true ) }
249+ { renderGroup ( 'radio' , 'secondary' , true , true , 'segmented' , 2 , 'start' , true ) }
250+ </ VerticalSpacing >
251+ ) ,
252+ } ;
253+
254+ export const CheckboxCardWithIcon : Story = {
255+ render : ( ) => (
256+ < VerticalSpacing >
257+ < Row >
258+ < Col lg = { 6 } md = { 12 } >
259+ < Text modifiers = "bold" > Primary</ Text >
260+ </ Col >
261+ < Col lg = { 6 } md = { 12 } >
262+ < Text modifiers = "bold" > Secondary</ Text >
263+ </ Col >
264+ </ Row >
265+ { renderGroup ( 'checkbox' , 'primary' , false , true , 'separated' , 5 , 'start' , true ) }
266+ { renderGroup ( 'checkbox' , 'secondary' , true , true , 'separated' , 6 , 'start' , true ) }
267+ </ VerticalSpacing >
268+ ) ,
269+ } ;
270+
226271export const WithError : Story = {
227272 render : function Render ( args ) {
228273 const [ selectedValues , setSelectedValues ] = useState < ChoiceGroupValue > ( [ ] ) ;
0 commit comments