import * as React from "react"; import * as $ from "@radix-ui/react-select"; import { match, P } from "ts-pattern"; import { FaCheck, FaChevronDown, FaChevronUp } from "react-icons/fa"; import * as T from "./Select.types"; import * as styles from "./Select.styles"; import { cx } from "../../utils"; import { Box } from "../Box"; import { Label, HelpText } from "../Common"; const Select = React.forwardRef( ( { label, hideLabel = false, helpText, fullWidth, hasError, children, className, ...props }, ref ) => { const classes = cx( [styles.selectStyles({ fullWidth, hasError })], className ); return ( <$.Root> <$.Trigger id="select" {...props} className={classes} ref={ref}> <$.Value placeholder={props.placeholder} /> <$.Icon className={cx(["ml-2"])} asChild> <$.Portal> <$.Content className={cx([styles.content])} position="popper"> <$.ScrollUpButton className={cx([styles.scroll])}> <$.Viewport className={cx([styles.viewport])}> {children} <$.ScrollDownButton className={cx([styles.scroll])}> <$.Arrow /> {match(helpText) .with(P.not(P.nullish), (helpText) => ( {helpText} )) .otherwise(() => null)} ); } ); const SelectItem = React.forwardRef( ({ children, className, ...props }, forwardedRef) => { const classes = cx([styles.itemStyles()], className); return ( <$.Item {...props} className={classes} ref={forwardedRef}> <$.ItemText>{children} <$.ItemIndicator className={cx([styles.indicator])}> {" "} ); } ); export { Select, SelectItem };