@@ -190,6 +190,16 @@ export const WithoutCheckbox: StoryObj<DualListBoxProps> = {
190
190
{
191
191
id : "2" ,
192
192
content : "bar" ,
193
+ items : [
194
+ {
195
+ id : "21" ,
196
+ content : "bar1" ,
197
+ } ,
198
+ {
199
+ id : "22" ,
200
+ content : "bar2" ,
201
+ } ,
202
+ ] ,
193
203
} ,
194
204
{
195
205
id : "3" ,
@@ -235,42 +245,100 @@ export const WithoutCheckbox: StoryObj<DualListBoxProps> = {
235
245
items
236
246
. filter (
237
247
( item ) =>
238
- ! allowedIds . includes ( item . id ) && ! disallowedIds . includes ( item . id ) ,
248
+ ( ! item . items &&
249
+ ! allowedIds . includes ( item . id ) &&
250
+ ! disallowedIds . includes ( item . id ) ) ||
251
+ item . items ?. some (
252
+ ( nestedItem ) =>
253
+ ! allowedIds . includes ( nestedItem . id ) &&
254
+ ! disallowedIds . includes ( nestedItem . id ) ,
255
+ ) ,
239
256
)
240
- . map ( ( item ) => ( {
241
- id : item . id ,
242
- content : (
243
- < Flex alignItems = "center" display = "flex" flex = { 1 } gap = { 1 } >
244
- < Typography > { item . content } </ Typography >
245
- < Flex
246
- alignItems = "center"
247
- display = "flex"
248
- flex = { 1 }
249
- justifyContent = "flex-end"
250
- gap = { 1 }
251
- >
252
- < ActionButton
253
- color = "primary"
254
- onClick = { ( ) => handleAllow ( item . id ) }
255
- >
256
- < Icon color = "active" name = "check_thin" />
257
- </ ActionButton >
258
- < ActionButton
259
- color = "warning"
260
- onClick = { ( ) => handleDisallow ( item . id ) }
261
- >
262
- < Icon color = { theme . palette . danger . main } name = "forbid" />
263
- </ ActionButton >
264
- </ Flex >
265
- </ Flex >
266
- ) ,
267
- } ) ) ,
257
+ . map ( ( item ) => {
258
+ if ( item . items ) {
259
+ return {
260
+ id : item . id ,
261
+ content : item . content ,
262
+ items : item . items
263
+ . filter (
264
+ ( nestedItem ) =>
265
+ ! allowedIds . includes ( nestedItem . id ) &&
266
+ ! disallowedIds . includes ( nestedItem . id ) ,
267
+ )
268
+ . map ( ( nestedItem ) => ( {
269
+ id : nestedItem . id ,
270
+ content : (
271
+ < Flex alignItems = "center" display = "flex" flex = { 1 } gap = { 1 } >
272
+ < Typography > { nestedItem . content } </ Typography >
273
+ < Flex
274
+ alignItems = "center"
275
+ display = "flex"
276
+ flex = { 1 }
277
+ justifyContent = "flex-end"
278
+ gap = { 1 }
279
+ >
280
+ < ActionButton
281
+ color = "primary"
282
+ onClick = { ( ) => handleAllow ( nestedItem . id ) }
283
+ >
284
+ < Icon color = "active" name = "check_thin" />
285
+ </ ActionButton >
286
+ < ActionButton
287
+ color = "warning"
288
+ onClick = { ( ) => handleDisallow ( nestedItem . id ) }
289
+ >
290
+ < Icon
291
+ color = { theme . palette . danger . main }
292
+ name = "forbid"
293
+ />
294
+ </ ActionButton >
295
+ </ Flex >
296
+ </ Flex >
297
+ ) ,
298
+ } ) ) ,
299
+ } ;
300
+ } else {
301
+ return {
302
+ id : item . id ,
303
+ content : (
304
+ < Flex alignItems = "center" display = "flex" flex = { 1 } gap = { 1 } >
305
+ < Typography > { item . content } </ Typography >
306
+ < Flex
307
+ alignItems = "center"
308
+ display = "flex"
309
+ flex = { 1 }
310
+ justifyContent = "flex-end"
311
+ gap = { 1 }
312
+ >
313
+ < ActionButton
314
+ color = "primary"
315
+ onClick = { ( ) => handleAllow ( item . id ) }
316
+ >
317
+ < Icon color = "active" name = "check_thin" />
318
+ </ ActionButton >
319
+ < ActionButton
320
+ color = "warning"
321
+ onClick = { ( ) => handleDisallow ( item . id ) }
322
+ >
323
+ < Icon color = { theme . palette . danger . main } name = "forbid" />
324
+ </ ActionButton >
325
+ </ Flex >
326
+ </ Flex >
327
+ ) ,
328
+ } ;
329
+ }
330
+ } ) ,
268
331
[ allowedIds , disallowedIds , items , theme . palette . danger . main ] ,
269
332
) ;
270
333
271
334
const selectedItems = React . useMemo (
272
335
( ) =>
273
336
items
337
+ . reduce (
338
+ ( prev : DualListBoxItem [ ] , item ) =>
339
+ item . items ? [ ...prev , ...item . items ] : [ ...prev , item ] ,
340
+ [ ] ,
341
+ )
274
342
. filter (
275
343
( item ) =>
276
344
allowedIds . includes ( item . id ) || disallowedIds . includes ( item . id ) ,
0 commit comments