@@ -5,17 +5,23 @@ import {Button} from '../Button'
5
5
import type { ItemInput , GroupedListProps } from '../deprecated/ActionList/List'
6
6
import { SelectPanel , type SelectPanelProps } from './SelectPanel'
7
7
import {
8
+ AlertIcon ,
8
9
FilterIcon ,
9
10
GearIcon ,
11
+ InfoIcon ,
10
12
NoteIcon ,
11
13
ProjectIcon ,
12
14
SearchIcon ,
15
+ StopIcon ,
13
16
TriangleDownIcon ,
14
17
TypographyIcon ,
15
18
VersionsIcon ,
16
19
} from '@primer/octicons-react'
17
20
import useSafeTimeout from '../hooks/useSafeTimeout'
18
21
import FormControl from '../FormControl'
22
+ import Link from '../Link'
23
+ import { SegmentedControl } from '../SegmentedControl'
24
+ import { Stack } from '../Stack'
19
25
20
26
const meta = {
21
27
title : 'Components/SelectPanel/Features' ,
@@ -312,6 +318,92 @@ export const WithFooter = () => {
312
318
)
313
319
}
314
320
321
+ export const WithNotice = ( ) => {
322
+ const [ selected , setSelected ] = useState < ItemInput [ ] > ( items . slice ( 1 , 3 ) )
323
+ const [ filter , setFilter ] = useState ( '' )
324
+ const filteredItems = items . filter (
325
+ item =>
326
+ // design guidelines say to always show selected items in the list
327
+ selected . some ( selectedItem => selectedItem . text === item . text ) ||
328
+ // then filter the rest
329
+ item . text . toLowerCase ( ) . startsWith ( filter . toLowerCase ( ) ) ,
330
+ )
331
+ // design guidelines say to sort selected items first
332
+ const selectedItemsSortedFirst = filteredItems . sort ( ( a , b ) => {
333
+ const aIsSelected = selected . some ( selectedItem => selectedItem . text === a . text )
334
+ const bIsSelected = selected . some ( selectedItem => selectedItem . text === b . text )
335
+ if ( aIsSelected && ! bIsSelected ) return - 1
336
+ if ( ! aIsSelected && bIsSelected ) return 1
337
+ return 0
338
+ } )
339
+ const [ open , setOpen ] = useState ( false )
340
+ const [ noticeVariant , setNoticeVariant ] = useState ( 0 )
341
+
342
+ const noticeVariants : Array < { text : string | React . ReactElement ; variant : 'info' | 'warning' | 'error' } > = [
343
+ {
344
+ variant : 'info' ,
345
+ text : 'Try a different search term.' ,
346
+ } ,
347
+ {
348
+ variant : 'warning' ,
349
+ text : (
350
+ < >
351
+ You have reached the limit of assignees on your free account.{ ' ' }
352
+ < Link href = "/upgrade" > Upgrade your account.</ Link >
353
+ </ >
354
+ ) ,
355
+ } ,
356
+ {
357
+ variant : 'error' ,
358
+ text : (
359
+ < >
360
+ We couldn't load all collaborators. Try again or if the problem persists,{ ' ' }
361
+ < Link href = "/support" > contact support</ Link >
362
+ </ >
363
+ ) ,
364
+ } ,
365
+ ]
366
+
367
+ return (
368
+ < Stack align = "start" >
369
+ < FormControl >
370
+ < FormControl . Label > Notice variant</ FormControl . Label >
371
+ < SegmentedControl aria-label = "Notice variant" onChange = { setNoticeVariant } >
372
+ < SegmentedControl . Button defaultSelected aria-label = { 'Info' } leadingIcon = { InfoIcon } >
373
+ Info notice
374
+ </ SegmentedControl . Button >
375
+ < SegmentedControl . Button aria-label = { 'Warning' } leadingIcon = { AlertIcon } >
376
+ Warning notice
377
+ </ SegmentedControl . Button >
378
+ < SegmentedControl . Button aria-label = { 'Error' } leadingIcon = { StopIcon } >
379
+ Error notice
380
+ </ SegmentedControl . Button >
381
+ </ SegmentedControl >
382
+ </ FormControl >
383
+ < FormControl >
384
+ < FormControl . Label > SelectPanel with notice</ FormControl . Label >
385
+ < SelectPanel
386
+ renderAnchor = { ( { children, ...anchorProps } ) => (
387
+ < Button trailingAction = { TriangleDownIcon } { ...anchorProps } >
388
+ { children }
389
+ </ Button >
390
+ ) }
391
+ placeholder = "Select labels" // button text when no items are selected
392
+ open = { open }
393
+ onOpenChange = { setOpen }
394
+ items = { selectedItemsSortedFirst }
395
+ selected = { selected }
396
+ onSelectedChange = { setSelected }
397
+ onFilterChange = { setFilter }
398
+ overlayProps = { { width : 'small' , height : 'medium' } }
399
+ width = "medium"
400
+ notice = { noticeVariants [ noticeVariant ] }
401
+ />
402
+ </ FormControl >
403
+ </ Stack >
404
+ )
405
+ }
406
+
315
407
const listOfItems : Array < ItemInput > = [
316
408
{
317
409
id : '1' ,
0 commit comments