import { forwardRef, type JSX } from "react"; import { SelectProps } from "react-stately"; import { AriaProps, DropdownProps, FieldInputProps, HasVariant, } from "../../../types"; import { useRenderProps } from "@hooks/useRenderProps"; import { useTranslations } from "@hooks/useTranslations"; import { Popover } from "../../Overlays/Popover"; import { ListBox } from "../ListBox"; import { SelectField } from "@components/Fields/SelectField"; import { FloatingFieldInputWrapper } from "@components/Internal/FloatingFieldInputWrapper"; import { StyledSelectField } from "./CustomSelect.styles"; import { Button } from "@components/Buttons/Button"; import { MaterialIcon } from "@components/Icons/MaterialIcon"; export type CustomSelectVariants = "default" | "floating" | "ghost"; export interface CustomSelectProps extends AriaProps>, FieldInputProps, HasVariant, DropdownProps {} const buttonVariantMap: Record = { default: "dropdown", ghost: "dropdown-ghost", }; /** A custom version of the builtin `select` component to * allow for consistent styling & an extended feature set */ export const CustomSelect = forwardRef(function CustomSelect( props: CustomSelectProps, ref: React.Ref ) { const { label, error, message, variant = "default", maxHeight = 300, dropdownPlacement = "bottom start", } = props; const t = useTranslations(); const placeholder = props.placeholder ?? t("select.placeholder"); const renderProps = useRenderProps({ componentClassName: "aje-select", variant, selectors: { "data-float": !!props.selectedKey && variant === "floating", }, }); const buttonVariant = buttonVariantMap[variant] ?? "dropdown"; return ( {props.children} ); }) as ( props: CustomSelectProps & React.RefAttributes ) => JSX.Element;