@@ -8,6 +8,8 @@ import type {OverlayProps} from '../Overlay'
8
8
import { TriangleDownIcon } from '@primer/octicons-react'
9
9
import { ActionList } from '../deprecated/ActionList'
10
10
import FormControl from '../FormControl'
11
+ import { Stack } from '../Stack'
12
+ import { Dialog } from '../experimental'
11
13
12
14
const meta = {
13
15
title : 'Components/SelectPanel/Examples' ,
@@ -442,3 +444,96 @@ export const ItemsInScope = () => {
442
444
</ FormControl >
443
445
)
444
446
}
447
+
448
+ export const RepositionAfterLoading = ( ) => {
449
+ const [ selected , setSelected ] = React . useState < ItemInput [ ] > ( [ items [ 0 ] , items [ 1 ] ] )
450
+ const [ open , setOpen ] = useState ( false )
451
+ const [ filter , setFilter ] = React . useState ( '' )
452
+ const [ filteredItems , setFilteredItems ] = React . useState < typeof items > ( [ ] )
453
+
454
+ const [ loading , setLoading ] = useState ( true )
455
+
456
+ React . useEffect ( ( ) => {
457
+ if ( ! open ) setLoading ( true )
458
+ window . setTimeout ( ( ) => {
459
+ if ( open ) {
460
+ setFilteredItems ( items . filter ( item => item . text . toLowerCase ( ) . startsWith ( filter . toLowerCase ( ) ) ) )
461
+ setLoading ( false )
462
+ }
463
+ } , 2000 )
464
+ // eslint-disable-next-line react-hooks/exhaustive-deps
465
+ } , [ open ] )
466
+
467
+ React . useEffect ( ( ) => {
468
+ if ( ! loading ) {
469
+ setFilteredItems ( items . filter ( item => item . text . toLowerCase ( ) . startsWith ( filter . toLowerCase ( ) ) ) )
470
+ }
471
+ // eslint-disable-next-line react-hooks/exhaustive-deps
472
+ } , [ filter ] )
473
+
474
+ return (
475
+ < >
476
+ < Stack direction = "vertical" justify = "space-between" style = { { height : 'calc(100vh - 300px)' , width : 'fit-content' } } >
477
+ < h1 > Reposition panel after loading</ h1 >
478
+ < SelectPanel
479
+ loading = { loading }
480
+ title = "Select labels"
481
+ placeholderText = "Filter Labels"
482
+ open = { open }
483
+ onOpenChange = { setOpen }
484
+ items = { filteredItems }
485
+ selected = { selected }
486
+ onSelectedChange = { setSelected }
487
+ onFilterChange = { setFilter }
488
+ />
489
+ </ Stack >
490
+ </ >
491
+ )
492
+ }
493
+
494
+ export const SelectPanelRepositionInsideDialog = ( ) => {
495
+ const [ selected , setSelected ] = React . useState < ItemInput [ ] > ( [ items [ 0 ] , items [ 1 ] ] )
496
+ const [ open , setOpen ] = useState ( false )
497
+ const [ filter , setFilter ] = React . useState ( '' )
498
+ const [ filteredItems , setFilteredItems ] = React . useState < typeof items > ( [ ] )
499
+
500
+ const [ loading , setLoading ] = useState ( true )
501
+
502
+ React . useEffect ( ( ) => {
503
+ if ( ! open ) setLoading ( true )
504
+ window . setTimeout ( ( ) => {
505
+ if ( open ) {
506
+ setFilteredItems ( items . filter ( item => item . text . toLowerCase ( ) . startsWith ( filter . toLowerCase ( ) ) ) )
507
+ setLoading ( false )
508
+ }
509
+ } , 2000 )
510
+ // eslint-disable-next-line react-hooks/exhaustive-deps
511
+ } , [ open ] )
512
+
513
+ React . useEffect ( ( ) => {
514
+ if ( ! loading ) {
515
+ setFilteredItems ( items . filter ( item => item . text . toLowerCase ( ) . startsWith ( filter . toLowerCase ( ) ) ) )
516
+ }
517
+ // eslint-disable-next-line react-hooks/exhaustive-deps
518
+ } , [ filter ] )
519
+
520
+ return (
521
+ < Dialog title = "SelectPanel reposition after loading inside Dialog" onClose = { ( ) => { } } >
522
+ < Stack direction = "vertical" justify = "space-between" style = { { height : 'calc(100vh - 500px)' , width : 'fit-content' } } >
523
+ < p > other content</ p >
524
+ < SelectPanel
525
+ loading = { loading }
526
+ title = "Select labels"
527
+ placeholderText = "Filter Labels"
528
+ open = { open }
529
+ onOpenChange = { setOpen }
530
+ items = { filteredItems }
531
+ selected = { selected }
532
+ onSelectedChange = { setSelected }
533
+ onFilterChange = { setFilter }
534
+ overlayProps = { { anchorSide : 'outside-top' } }
535
+ />
536
+ </ Stack >
537
+ </ Dialog >
538
+ )
539
+ }
0 commit comments