@@ -43,6 +43,8 @@ const dummySections = Array(5)
43
43
export const Primary = ( ) => {
44
44
const [ sections , setSections ] = useState < ISection [ ] > ( [ ] ) ;
45
45
const [ expandedSections , setExpandedSections ] = useState < number [ ] > ( [ 1 ] ) ;
46
+ const [ selectedSection , setSelectedSection ] = useState < number | null > ( null ) ;
47
+ const [ selectedItem , setSelectedItem ] = useState < number | null > ( null ) ;
46
48
47
49
useEffect ( ( ) => {
48
50
if ( sections . length ) {
@@ -61,6 +63,16 @@ export const Primary = () => {
61
63
< Accordion
62
64
className = 'yl:w-[500px]'
63
65
sections = { sections }
66
+ selected = { {
67
+ sectionId : selectedSection ?? 0 ,
68
+ itemId : selectedItem ?? 0
69
+ } }
70
+ setSelectedSection = { sectionId => {
71
+ setSelectedSection ( sectionId ) ;
72
+ } }
73
+ setSelectedItem = { itemId => {
74
+ setSelectedItem ( itemId ) ;
75
+ } }
64
76
onSorted = { ( _ , data ) => {
65
77
setSections ( data ) ;
66
78
} }
@@ -84,7 +96,8 @@ export const Primary = () => {
84
96
export const Interactive = ( ) => {
85
97
const [ sections , setSections ] = useState < ISection [ ] > ( [ ] ) ;
86
98
const [ expandedSections , setExpandedSections ] = useState < number [ ] > ( [ 1 ] ) ;
87
- const [ selectedSection , setSelectedSection ] = useState < number > ( 2 ) ;
99
+ const [ selectedSection , setSelectedSection ] = useState < number | null > ( null ) ;
100
+ const [ selectedItem , setSelectedItem ] = useState < number | null > ( null ) ;
88
101
89
102
useEffect ( ( ) => {
90
103
if ( sections . length ) {
@@ -104,7 +117,16 @@ export const Interactive = () => {
104
117
className = 'yl:w-[500px]'
105
118
sections = { sections }
106
119
expanded = { expandedSections }
107
- selectedId = { selectedSection }
120
+ selected = { {
121
+ sectionId : selectedSection ?? 0 ,
122
+ itemId : selectedItem ?? 0
123
+ } }
124
+ setSelectedSection = { sectionId => {
125
+ setSelectedSection ( sectionId ) ;
126
+ } }
127
+ setSelectedItem = { itemId => {
128
+ setSelectedItem ( itemId ) ;
129
+ } }
108
130
setExpanded = { ( expanded : number [ ] ) => {
109
131
setExpandedSections ( expanded ) ;
110
132
} }
@@ -124,6 +146,8 @@ export const Interactive = () => {
124
146
export const NonInteractiveItems = ( ) => {
125
147
const [ sections , setSections ] = useState < ISection [ ] > ( [ ] ) ;
126
148
const [ expandedSections , setExpandedSections ] = useState < number [ ] > ( [ 1 ] ) ;
149
+ const [ selectedSection , setSelectedSection ] = useState < number | null > ( null ) ;
150
+ const [ selectedItem , setSelectedItem ] = useState < number | null > ( null ) ;
127
151
128
152
useEffect ( ( ) => {
129
153
if ( sections . length ) {
@@ -141,7 +165,16 @@ export const NonInteractiveItems = () => {
141
165
< div >
142
166
< Accordion
143
167
className = 'yl:w-[500px]'
144
- selectedId = { 2 }
168
+ selected = { {
169
+ sectionId : selectedSection ?? 0 ,
170
+ itemId : selectedItem ?? 0
171
+ } }
172
+ setSelectedSection = { sectionId => {
173
+ setSelectedSection ( sectionId ) ;
174
+ } }
175
+ setSelectedItem = { itemId => {
176
+ setSelectedItem ( itemId ) ;
177
+ } }
145
178
sections = { sections }
146
179
onSorted = { ( _ , sections ) => {
147
180
setSections ( sections ) ;
@@ -161,6 +194,8 @@ export const NonInteractiveItems = () => {
161
194
export const WithoutDragAndDrop = ( ) => {
162
195
const [ sections , setSections ] = useState < ISection [ ] > ( [ ] ) ;
163
196
const [ expandedSections , setExpandedSections ] = useState < number [ ] > ( [ 1 ] ) ;
197
+ const [ selectedSection , setSelectedSection ] = useState < number | null > ( null ) ;
198
+ const [ selectedItem , setSelectedItem ] = useState < number | null > ( null ) ;
164
199
165
200
useEffect ( ( ) => {
166
201
if ( sections . length ) {
@@ -178,7 +213,16 @@ export const WithoutDragAndDrop = () => {
178
213
< div >
179
214
< Accordion
180
215
className = 'yl:w-[500px]'
181
- selectedId = { 2 }
216
+ selected = { {
217
+ sectionId : selectedSection ?? 0 ,
218
+ itemId : selectedItem ?? 0
219
+ } }
220
+ setSelectedSection = { sectionId => {
221
+ setSelectedSection ( sectionId ) ;
222
+ } }
223
+ setSelectedItem = { itemId => {
224
+ setSelectedItem ( itemId ) ;
225
+ } }
182
226
sections = { sections }
183
227
onSorted = { ( _ , sections ) => {
184
228
setSections ( sections ) ;
@@ -214,6 +258,8 @@ export const AddSectionAndSectionItem = () => {
214
258
] ) ;
215
259
216
260
const [ expandedSections , setExpandedSections ] = useState < number [ ] > ( [ 1 ] ) ;
261
+ const [ selectedSection , setSelectedSection ] = useState < number | null > ( null ) ;
262
+ const [ selectedItem , setSelectedItem ] = useState < number | null > ( null ) ;
217
263
218
264
if ( ! sections . length ) {
219
265
return < div > Loading...</ div > ;
@@ -239,7 +285,16 @@ export const AddSectionAndSectionItem = () => {
239
285
</ Button >
240
286
< Accordion
241
287
className = 'yl:w-[500px]'
242
- selectedId = { 2 }
288
+ selected = { {
289
+ sectionId : selectedSection ?? 0 ,
290
+ itemId : selectedItem ?? 0
291
+ } }
292
+ setSelectedSection = { sectionId => {
293
+ setSelectedSection ( sectionId ) ;
294
+ } }
295
+ setSelectedItem = { itemId => {
296
+ setSelectedItem ( itemId ) ;
297
+ } }
243
298
sections = { sections }
244
299
expanded = { expandedSections }
245
300
hasDraggableSectionItems = { true }
@@ -277,6 +332,8 @@ export const AddSectionAndSectionItem = () => {
277
332
export const WithAddLabels = ( ) => {
278
333
const [ sections , setSections ] = useState < ISection [ ] > ( [ ] ) ;
279
334
const [ expandedSections , setExpandedSections ] = useState < number [ ] > ( [ 1 ] ) ;
335
+ const [ selectedSection , setSelectedSection ] = useState < number | null > ( null ) ;
336
+ const [ selectedItem , setSelectedItem ] = useState < number | null > ( null ) ;
280
337
281
338
useEffect ( ( ) => {
282
339
if ( sections . length ) {
@@ -294,7 +351,16 @@ export const WithAddLabels = () => {
294
351
< div >
295
352
< Accordion
296
353
className = 'yl:w-[500px]'
297
- selectedId = { 2 }
354
+ selected = { {
355
+ sectionId : selectedSection ?? 0 ,
356
+ itemId : selectedItem ?? 0
357
+ } }
358
+ setSelectedSection = { sectionId => {
359
+ setSelectedSection ( sectionId ) ;
360
+ } }
361
+ setSelectedItem = { itemId => {
362
+ setSelectedItem ( itemId ) ;
363
+ } }
298
364
sections = { sections }
299
365
expanded = { expandedSections }
300
366
onSorted = { ( _ , sections ) => {
@@ -321,7 +387,7 @@ export const WithAddLabels = () => {
321
387
} ;
322
388
323
389
export const WithNoItems = ( ) => {
324
- const [ sections , setSections ] = useState < ISection [ ] > ( [
390
+ const [ sections ] = useState < ISection [ ] > ( [
325
391
{
326
392
id : 1 ,
327
393
title : "velum constans brevis canis corrumpo magni attollo" ,
@@ -331,6 +397,8 @@ export const WithNoItems = () => {
331
397
}
332
398
] ) ;
333
399
const [ expandedSections , setExpandedSections ] = useState < number [ ] > ( [ ] ) ;
400
+ const [ selectedSection , setSelectedSection ] = useState < number | null > ( null ) ;
401
+ const [ selectedItem , setSelectedItem ] = useState < number | null > ( null ) ;
334
402
335
403
if ( ! sections . length ) {
336
404
return < div > Loading...</ div > ;
@@ -340,11 +408,18 @@ export const WithNoItems = () => {
340
408
< div >
341
409
< Accordion
342
410
className = 'yl:w-[500px]'
343
- sections = { sections }
344
411
expanded = { expandedSections }
345
- onSorted = { ( _ , sections ) => {
346
- setSections ( sections ) ;
412
+ selected = { {
413
+ sectionId : selectedSection ?? 0 ,
414
+ itemId : selectedItem ?? 0
415
+ } }
416
+ setSelectedSection = { sectionId => {
417
+ setSelectedSection ( sectionId ) ;
347
418
} }
419
+ setSelectedItem = { itemId => {
420
+ setSelectedItem ( itemId ) ;
421
+ } }
422
+ sections = { sections }
348
423
onAddSection = { ( ) => {
349
424
action ( "onAddSection" ) ( ) ;
350
425
} }
@@ -368,6 +443,8 @@ export const WithNoItems = () => {
368
443
export const DefaultExpanded = ( ) => {
369
444
const [ sections , setSections ] = useState < ISection [ ] > ( [ ] ) ;
370
445
const [ expandedSections , setExpandedSections ] = useState < number [ ] > ( [ ] ) ;
446
+ const [ selectedSection , setSelectedSection ] = useState < number | null > ( null ) ;
447
+ const [ selectedItem , setSelectedItem ] = useState < number | null > ( null ) ;
371
448
372
449
useEffect ( ( ) => {
373
450
if ( sections . length ) {
@@ -385,10 +462,18 @@ export const DefaultExpanded = () => {
385
462
< div >
386
463
< Accordion
387
464
className = 'yl:w-[500px]'
388
- selectedId = { 2 }
465
+ selected = { {
466
+ sectionId : selectedSection ?? 0 ,
467
+ itemId : selectedItem ?? 0
468
+ } }
469
+ setSelectedSection = { sectionId => {
470
+ setSelectedSection ( sectionId ) ;
471
+ } }
472
+ setSelectedItem = { itemId => {
473
+ setSelectedItem ( itemId ) ;
474
+ } }
389
475
sections = { sections }
390
476
expanded = { expandedSections }
391
- defaultExpanded = { true }
392
477
onSorted = { ( _ , sections ) => {
393
478
setSections ( sections ) ;
394
479
} }
0 commit comments