({
items,
iconButton,
ariaLabel,
pickerLabel,
dataTestId,
defaultText,
onSelect,
buttonBorder,
alignment,
renderItem,
}: Props)
| 30 | } |
| 31 | |
| 32 | export const Picker = ({ |
| 33 | items, |
| 34 | iconButton, |
| 35 | ariaLabel, |
| 36 | pickerLabel, |
| 37 | dataTestId, |
| 38 | defaultText, |
| 39 | onSelect, |
| 40 | buttonBorder, |
| 41 | alignment, |
| 42 | renderItem, |
| 43 | }: Props) => { |
| 44 | const [open, setOpen] = useState(false) |
| 45 | const selectedOption = items.find((item) => item.selected === true) |
| 46 | return ( |
| 47 | <ActionMenu open={open} onOpenChange={setOpen}> |
| 48 | {iconButton ? ( |
| 49 | <ActionMenu.Anchor> |
| 50 | <IconButton icon={iconButton} aria-label={ariaLabel} /> |
| 51 | </ActionMenu.Anchor> |
| 52 | ) : ( |
| 53 | <ActionMenu.Button |
| 54 | aria-label={ariaLabel} |
| 55 | variant={buttonBorder ? 'default' : 'invisible'} |
| 56 | sx={{ |
| 57 | color: `var(--color-fg-default)`, |
| 58 | width: '100%', |
| 59 | display: 'flex', |
| 60 | justifyContent: 'space-between', |
| 61 | }} |
| 62 | > |
| 63 | {pickerLabel && <span className="color-fg-muted text-normal">{`${pickerLabel}: `}</span>} |
| 64 | <span data-testid={dataTestId}>{selectedOption?.text || defaultText}</span> |
| 65 | </ActionMenu.Button> |
| 66 | )} |
| 67 | <ActionMenu.Overlay width="auto" align={alignment}> |
| 68 | <Fields |
| 69 | open={open} |
| 70 | setOpen={setOpen} |
| 71 | items={items} |
| 72 | onSelect={onSelect} |
| 73 | renderItem={renderItem} |
| 74 | /> |
| 75 | </ActionMenu.Overlay> |
| 76 | </ActionMenu> |
| 77 | ) |
| 78 | } |
nothing calls this directly
no outgoing calls
no test coverage detected