17
17
18
18
import { action } from '@storybook/addon-actions' ;
19
19
import AlertNotice from '../spectrum-illustrations/linear/AlertNotice' ;
20
- import { createIcon , SelectBox , SelectBoxGroup , Text } from '../src' ;
20
+ import { Button , createIcon , SelectBox , SelectBoxGroup , Text } from '../src' ;
21
21
import type { Meta , StoryObj } from '@storybook/react' ;
22
22
import Paperairplane from '../spectrum-illustrations/linear/Paperairplane' ;
23
- import React from 'react' ;
23
+ import React , { useState } from 'react' ;
24
24
import Server from '../spectrum-illustrations/linear/Server' ;
25
25
import StarFilledSVG from '../s2wf-icons/S2_Icon_StarFilled_20_N.svg' ;
26
26
import StarSVG from '../s2wf-icons/S2_Icon_Star_20_N.svg' ;
@@ -29,7 +29,7 @@ const StarIcon = createIcon(StarSVG);
29
29
const StarFilledIcon = createIcon ( StarFilledSVG ) ;
30
30
31
31
const meta : Meta < typeof SelectBoxGroup > = {
32
- title : 'SelectBoxGroup (Collection) ' ,
32
+ title : 'SelectBoxGroup' ,
33
33
component : SelectBoxGroup ,
34
34
parameters : {
35
35
layout : 'centered'
@@ -42,7 +42,7 @@ const meta: Meta<typeof SelectBoxGroup> = {
42
42
} ,
43
43
size : {
44
44
control : 'select' ,
45
- options : [ 'XS' , ' S', 'M' , 'L' , 'XL' ]
45
+ options : [ 'S' , 'M' , 'L' , 'XL' ]
46
46
} ,
47
47
orientation : {
48
48
control : 'select' ,
@@ -63,7 +63,7 @@ const meta: Meta<typeof SelectBoxGroup> = {
63
63
numColumns : 2 ,
64
64
gutterWidth : 'default' ,
65
65
isRequired : false ,
66
- isDisabled : false ,
66
+ isDisabled : false
67
67
}
68
68
} ;
69
69
@@ -133,15 +133,13 @@ export const MultipleSelection: Story = {
133
133
// Grid Navigation Testing
134
134
export const GridNavigation : Story = {
135
135
args : {
136
- label : 'Test Grid Navigation (Use Arrow Keys) ' ,
136
+ label : 'Test Grid Navigation' ,
137
137
numColumns : 3
138
138
} ,
139
139
render : ( args ) => (
140
140
< div style = { { maxWidth : 600 } } >
141
141
< p style = { { marginBottom : 16 , fontSize : 14 , color : '#666' } } >
142
- Focus any item (best done by clicking to the left of the group and hitting the tab key) and use arrow keys to navigate:
143
- { /* <br />• ↑↓ moves vertically (same column)
144
- <br />• ←→ moves horizontally (same row) */ }
142
+ Focus any item (best done by clicking to the side of the group and hitting the tab key) and using arrow keys to navigate:
145
143
</ p >
146
144
< SelectBoxGroup { ...args } onSelectionChange = { action ( 'onSelectionChange' ) } >
147
145
< SelectBox value = "1" >
@@ -167,38 +165,6 @@ export const GridNavigation: Story = {
167
165
)
168
166
} ;
169
167
170
- // Form Integration
171
- export const FormIntegration : Story = {
172
- args : {
173
- label : 'Select your option' ,
174
- name : 'user_preference' ,
175
- isRequired : true
176
- } ,
177
- render : ( args ) => (
178
- < form
179
- onSubmit = { ( e ) => {
180
- e . preventDefault ( ) ;
181
- const formData = new FormData ( e . currentTarget ) ;
182
- action ( 'Form submitted' ) ( Object . fromEntries ( formData ) ) ;
183
- } } >
184
- < SelectBoxGroup { ...args } onSelectionChange = { action ( 'onSelectionChange' ) } >
185
- < SelectBox value = "option1" >
186
- < Text slot = "text" > Option 1</ Text >
187
- </ SelectBox >
188
- < SelectBox value = "option2" >
189
- < Text slot = "text" > Option 2</ Text >
190
- </ SelectBox >
191
- < SelectBox value = "option3" >
192
- < Text slot = "text" > Option 3</ Text >
193
- </ SelectBox >
194
- </ SelectBoxGroup >
195
- < button type = "submit" style = { { marginTop : 16 } } >
196
- Submit Form
197
- </ button >
198
- </ form >
199
- )
200
- } ;
201
-
202
168
export const FormValidation : Story = {
203
169
args : {
204
170
label : 'Required Selection' ,
@@ -222,7 +188,7 @@ export const FormValidation: Story = {
222
188
export const SizeVariations : Story = {
223
189
render : ( ) => (
224
190
< div style = { { display : 'flex' , flexDirection : 'column' , gap : 32 } } >
225
- { ( [ 'XS' , ' S', 'M' , 'L' , 'XL' ] as const ) . map ( ( size ) => (
191
+ { ( [ 'S' , 'M' , 'L' , 'XL' ] as const ) . map ( ( size ) => (
226
192
< SelectBoxGroup
227
193
key = { size }
228
194
size = { size }
@@ -311,9 +277,8 @@ export const IndividualDisabled: Story = {
311
277
)
312
278
} ;
313
279
314
- // Controlled Mode - Convert to proper component to use React hooks
315
280
function ControlledStory ( ) {
316
- const [ value , setValue ] = React . useState ( 'option2' ) ;
281
+ const [ value , setValue ] = useState ( 'option2' ) ;
317
282
318
283
return (
319
284
< div >
@@ -346,9 +311,8 @@ export const Controlled: Story = {
346
311
render : ( ) => < ControlledStory />
347
312
} ;
348
313
349
- // Dynamic Icons - Convert to proper component to use React hooks
350
314
function DynamicIconsStory ( ) {
351
- const [ selectedValues , setSelectedValues ] = React . useState < Set < string > > (
315
+ const [ selectedValues , setSelectedValues ] = useState < Set < string > > (
352
316
new Set ( )
353
317
) ;
354
318
@@ -379,7 +343,6 @@ export const DynamicIcons: Story = {
379
343
render : ( ) => < DynamicIconsStory />
380
344
} ;
381
345
382
- // Multiple Columns
383
346
export const MultipleColumns : Story = {
384
347
args : {
385
348
label : 'Choose options' ,
@@ -398,3 +361,55 @@ export const MultipleColumns: Story = {
398
361
</ div >
399
362
)
400
363
} ;
364
+
365
+ function FormSubmissionExample ( ) {
366
+ const [ selectedValues , setSelectedValues ] = useState < string [ ] > ( [ 'newsletter' ] ) ;
367
+ const [ submittedData , setSubmittedData ] = useState < string [ ] | null > ( null ) ;
368
+
369
+ const handleSubmit = ( e : React . FormEvent < HTMLFormElement > ) => {
370
+ e . preventDefault ( ) ;
371
+ const formData = new FormData ( e . currentTarget ) ;
372
+ const preferences = formData . getAll ( 'preferences' ) as string [ ] ;
373
+ setSubmittedData ( preferences ) ;
374
+ action ( 'form-submitted' ) ( preferences ) ;
375
+ } ;
376
+
377
+ return (
378
+ < div style = { { maxWidth : 400 } } >
379
+ < form onSubmit = { handleSubmit } >
380
+ < SelectBoxGroup
381
+ selectionMode = "multiple"
382
+ value = { selectedValues }
383
+ onSelectionChange = { ( val ) => setSelectedValues ( val as string [ ] ) }
384
+ name = "preferences"
385
+ label = "Email Preferences"
386
+ isRequired >
387
+ < SelectBox value = "newsletter" >
388
+ < Text slot = "text" > Newsletter</ Text >
389
+ </ SelectBox >
390
+ < SelectBox value = "marketing" >
391
+ < Text slot = "text" > Marketing Updates</ Text >
392
+ </ SelectBox >
393
+ < SelectBox value = "product" >
394
+ < Text slot = "text" > Product News</ Text >
395
+ </ SelectBox >
396
+ < SelectBox value = "security" >
397
+ < Text slot = "text" > Security Alerts</ Text >
398
+ </ SelectBox >
399
+ </ SelectBoxGroup >
400
+
401
+ < Button type = "submit" variant = "accent" >
402
+ Save Preferences
403
+ </ Button >
404
+ </ form >
405
+
406
+ { submittedData && (
407
+ < Text > Submitted: { submittedData . join ( ', ' ) } </ Text >
408
+ ) }
409
+ </ div >
410
+ ) ;
411
+ }
412
+
413
+ export const FormSubmission : Story = {
414
+ render : ( ) => < FormSubmissionExample />
415
+ } ;
0 commit comments