({
name,
options,
placeholder,
icon,
buttonProps,
onSelect,
}: SelectProps)
| 21 | }; |
| 22 | |
| 23 | const Select = ({ |
| 24 | name, |
| 25 | options, |
| 26 | placeholder, |
| 27 | icon, |
| 28 | buttonProps, |
| 29 | onSelect, |
| 30 | }: SelectProps) => { |
| 31 | const { control, setValue } = useFormContext(); |
| 32 | |
| 33 | const menuItems: MenuItemProps[] = options.map((opt) => { |
| 34 | return { |
| 35 | label: opt.label, |
| 36 | action: () => { |
| 37 | setValue(name, opt.value); |
| 38 | onSelect?.(opt.value); |
| 39 | }, |
| 40 | }; |
| 41 | }); |
| 42 | |
| 43 | return ( |
| 44 | <Controller |
| 45 | name={name} |
| 46 | control={control} |
| 47 | render={({ field }) => ( |
| 48 | <> |
| 49 | <input type="hidden" {...field} /> |
| 50 | <DropdownMenu> |
| 51 | <DropdownMenuTrigger className="w-full" asChild> |
| 52 | <Button |
| 53 | icon={icon} |
| 54 | variant={ButtonVariant.Float} |
| 55 | {...buttonProps} |
| 56 | > |
| 57 | {options.find((opt) => opt.value === field.value?.toString()) |
| 58 | ?.label || placeholder} |
| 59 | <ArrowIcon className="ml-auto rotate-180" secondary /> |
| 60 | </Button> |
| 61 | </DropdownMenuTrigger> |
| 62 | <DropdownMenuContent |
| 63 | variant="field" |
| 64 | align="start" |
| 65 | sideOffset={10} |
| 66 | className="flex flex-col gap-1 !p-0" |
| 67 | > |
| 68 | <DropdownMenuOptions options={menuItems} /> |
| 69 | </DropdownMenuContent> |
| 70 | </DropdownMenu> |
| 71 | </> |
| 72 | )} |
| 73 | /> |
| 74 | ); |
| 75 | }; |
| 76 | |
| 77 | export default Select; |
nothing calls this directly
no test coverage detected