forked from github/docs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathFields.tsx
52 lines (48 loc) · 1.68 KB
/
Fields.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
import { ReactNode } from 'react'
import { ActionList } from '@primer/react'
import { PickerItem } from './Picker'
import { Link } from 'components/Link'
import styles from './Fields.module.scss'
export const Fields = (fieldProps: {
open: boolean
setOpen: React.Dispatch<React.SetStateAction<boolean>>
items: PickerItem[]
onSelect?: (item: PickerItem) => void
renderItem?: (item: PickerItem) => ReactNode | string
}) => {
const { open, setOpen, items, onSelect, renderItem } = fieldProps
return (
<ActionList selectionVariant="single">
{items.map((item, i) =>
item.divider ? (
<ActionList.Divider key={`divider${i}`} />
) : (
<ActionList.Item
as={Link}
key={item.text}
href={item.href}
selected={item.selected === true}
onClick={() => {
if (onSelect) onSelect(item)
setOpen(!open)
}}
// These extra links in the pickers are not a part of the selection variant
// in that they are generally external links, so we want to remove the selection
// variant span box in front of it. To date there isn't a possibility to have
// an ActionMenu in Primer that allow non-selection variant items with selection
// variant items
className={(item.extra?.arrow || item.extra?.info) && styles.extrasDisplay}
sx={{
':hover': {
textDecoration: 'none',
textAlign: 'left',
},
}}
>
{renderItem ? renderItem(item) : item.text}
</ActionList.Item>
),
)}
</ActionList>
)
}