-
Notifications
You must be signed in to change notification settings - Fork 68.3k
Expand file tree
/
Copy pathFields.tsx
More file actions
50 lines (46 loc) · 1.69 KB
/
Copy pathFields.tsx
File metadata and controls
50 lines (46 loc) · 1.69 KB
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
import { ActionList } from '@primer/react'
import React, { ReactNode } from 'react'
import cx from 'classnames'
import { PickerItem } from './Picker'
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" role="menu">
{items.map((item, i) =>
item.divider ? (
<ActionList.Divider key={`divider${i}`} />
) : (
<ActionList.LinkItem
as="a"
key={item.text}
href={item.href}
active={item.selected === true}
onSelect={() => {
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={cx(
(item.extra?.arrow || item.extra?.info) && styles.extrasDisplay,
styles.linkItem,
)}
role={item.extra?.arrow || item.extra?.info ? 'menuitem' : 'menuitemradio'}
>
{renderItem ? renderItem(item) : item.text}
</ActionList.LinkItem>
),
)}
</ActionList>
)
}