MCPcopy Create free account
hub / github.com/github/docs / Fields

Function Fields

components/ui/Picker/Fields.tsx:9–52  ·  view source on GitHub ↗
(fieldProps: {
  open: boolean
  setOpen: React.Dispatch<React.SetStateAction<boolean>>
  items: PickerItem[]
  onSelect?: (item: PickerItem) => void
  renderItem?: (item: PickerItem) => ReactNode | string
})

Source from the content-addressed store, hash-verified

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

Callers

nothing calls this directly

Calls

no outgoing calls

Tested by

no test coverage detected