import React, { HTMLAttributes, PropsWithChildren, useEffect, useRef, useState, } from "react"; import { useCombobox, useSelect, UseSelectReturnValue, UseSelectStateChange, } from "downshift"; import classNames from "classnames"; import { useCunningham } from ":/components/Provider"; import { Field, FieldProps } from ":/components/Forms/Field"; import { LabelledBox } from ":/components/Forms/LabelledBox"; import { Button } from ":/components/Button"; interface Option { value?: string; label: string; disabled?: boolean; } type Props = PropsWithChildren & FieldProps & { label: string; hideLabel?: boolean; options: Option[]; searchable?: boolean; name?: string; defaultValue?: string | number; value?: string | number; onChange?: (event: { target: { value: string | number | undefined }; }) => void; disabled?: boolean; clearable?: boolean; }; function getOptionsFilter(inputValue?: string) { return (option: Option) => { return ( !inputValue || option.label.toLowerCase().includes(inputValue.toLowerCase()) || option.value?.toLowerCase().includes(inputValue.toLowerCase()) ); }; } const optionToString = (option: Option | null) => { return option ? option.label : ""; }; const optionToValue = (option: Option) => { return option.value ?? option.label; }; interface SubProps extends Props { defaultSelectedItem?: Option; downshiftProps: { initialSelectedItem?: Option; onSelectedItemChange?: any; }; } interface SelectAuxProps extends SubProps { options: Option[]; labelAsPlaceholder: boolean; downshiftReturn: { isOpen: boolean; wrapperProps?: HTMLAttributes; selectedItem?: Option | null; getLabelProps: any; toggleButtonProps: any; getMenuProps: any; getItemProps: any; highlightedIndex: number; selectItem: UseSelectReturnValue