@@ -11,19 +11,23 @@ import {
11
11
GearIcon ,
12
12
InfoIcon ,
13
13
NoteIcon ,
14
+ PlusIcon ,
14
15
ProjectIcon ,
15
16
SearchIcon ,
16
17
StopIcon ,
18
+ TagIcon ,
17
19
TriangleDownIcon ,
18
20
TypographyIcon ,
19
21
VersionsIcon ,
22
+ type IconProps ,
20
23
} from '@primer/octicons-react'
21
24
import useSafeTimeout from '../hooks/useSafeTimeout'
22
25
import ToggleSwitch from '../ToggleSwitch'
23
26
import Text from '../Text'
24
27
import FormControl from '../FormControl'
25
28
import { SegmentedControl } from '../SegmentedControl'
26
29
import { Stack } from '../Stack'
30
+ import { FeatureFlags } from '../FeatureFlags'
27
31
28
32
const meta : Meta < typeof SelectPanel > = {
29
33
title : 'Components/SelectPanel/Features' ,
@@ -909,6 +913,103 @@ export const WithInactiveItems = () => {
909
913
)
910
914
}
911
915
916
+ export const WithMessage = ( ) => {
917
+ const [ selected , setSelected ] = useState < ItemInput [ ] > ( [ ] )
918
+ const [ filter , setFilter ] = useState ( '' )
919
+ const [ open , setOpen ] = useState ( false )
920
+ const [ messageVariant , setMessageVariant ] = useState ( 0 )
921
+
922
+ const messageVariants : Array <
923
+ | undefined
924
+ | {
925
+ title : string
926
+ body : string | React . ReactElement
927
+ variant : 'empty' | 'error' | 'warning'
928
+ icon ?: React . ComponentType < IconProps >
929
+ action ?: React . ReactElement
930
+ }
931
+ > = [
932
+ undefined , // Default message
933
+ {
934
+ variant : 'empty' ,
935
+ title : 'No labels found' ,
936
+ body : 'Try adjusting your search or create a new label' ,
937
+ icon : TagIcon ,
938
+ action : (
939
+ < Button variant = "default" size = "small" leadingVisual = { PlusIcon } onClick = { ( ) => { } } >
940
+ Create new label
941
+ </ Button >
942
+ ) ,
943
+ } ,
944
+ {
945
+ variant : 'error' ,
946
+ title : 'Failed to load labels' ,
947
+ body : (
948
+ < >
949
+ Check your network connection and try again or < Link href = "/support" > contact support</ Link >
950
+ </ >
951
+ ) ,
952
+ } ,
953
+ {
954
+ variant : 'warning' ,
955
+ title : 'Some labels may be outdated' ,
956
+ body : 'Consider refreshing to get the latest data' ,
957
+ } ,
958
+ ]
959
+
960
+ const itemsToShow = messageVariant === 0 ? items . slice ( 0 , 3 ) : [ ]
961
+ const filteredItems = itemsToShow . filter ( item => item . text . toLowerCase ( ) . startsWith ( filter . toLowerCase ( ) ) )
962
+
963
+ useEffect ( ( ) => {
964
+ setFilter ( '' )
965
+ } , [ messageVariant ] )
966
+
967
+ return (
968
+ < FeatureFlags flags = { { primer_react_select_panel_with_modern_action_list : true } } >
969
+ < Stack align = "start" >
970
+ < FormControl >
971
+ < FormControl . Label > Message variant</ FormControl . Label >
972
+ < SegmentedControl aria-label = "Message variant" onChange = { setMessageVariant } >
973
+ < SegmentedControl . Button defaultSelected aria-label = "Default message" >
974
+ Default message
975
+ </ SegmentedControl . Button >
976
+ < SegmentedControl . Button aria-label = "Empty" leadingIcon = { SearchIcon } >
977
+ Empty
978
+ </ SegmentedControl . Button >
979
+ < SegmentedControl . Button aria-label = "Error" leadingIcon = { StopIcon } >
980
+ Error
981
+ </ SegmentedControl . Button >
982
+ < SegmentedControl . Button aria-label = "Warning" leadingIcon = { AlertIcon } >
983
+ Warning
984
+ </ SegmentedControl . Button >
985
+ </ SegmentedControl >
986
+ </ FormControl >
987
+ < FormControl >
988
+ < FormControl . Label > SelectPanel with message</ FormControl . Label >
989
+ < SelectPanel
990
+ renderAnchor = { ( { children, ...anchorProps } ) => (
991
+ < Button trailingAction = { TriangleDownIcon } { ...anchorProps } >
992
+ { children }
993
+ </ Button >
994
+ ) }
995
+ placeholder = "Select labels"
996
+ open = { open }
997
+ onOpenChange = { setOpen }
998
+ items = { filteredItems }
999
+ selected = { selected }
1000
+ onSelectedChange = { setSelected }
1001
+ onFilterChange = { setFilter }
1002
+ overlayProps = { { width : 'small' , height : 'medium' } }
1003
+ width = "medium"
1004
+ message = { messageVariants [ messageVariant ] }
1005
+ filterValue = { filter }
1006
+ />
1007
+ </ FormControl >
1008
+ </ Stack >
1009
+ </ FeatureFlags >
1010
+ )
1011
+ }
1012
+
912
1013
export const WithSelectAll = ( ) => {
913
1014
const [ selected , setSelected ] = useState < ItemInput [ ] > ( [ ] )
914
1015
const [ filter , setFilter ] = useState ( '' )
0 commit comments