import { Check } from "@phosphor-icons/react/dist/ssr/Check"; import clsx from "clsx"; import type { ComponentProps, ReactNode } from "react"; import { type PopoverProps, type Button as BaseButton, Label, Select as BaseSelect, Popover, Header, Collection, SelectValue, } from "react-aria-components"; import styles from "./index.module.scss"; import { type Props as ButtonProps, Button } from "../Button/index.js"; import { DropdownCaretDown } from "../DropdownCaretDown/index.js"; import { ListBox, ListBoxItem, ListBoxSection, } from "../unstyled/ListBox/index.js"; type Props = Omit< ComponentProps, "defaultSelectedKey" | "selectedKey" | "onSelectionChange" > & Pick< ButtonProps, "variant" | "size" | "rounded" | "hideText" | "isPending" > & Pick & { show?: (value: T) => string; icon?: ComponentProps["beforeIcon"]; label: ReactNode; hideLabel?: boolean | undefined; buttonLabel?: ReactNode; } & ( | { defaultSelectedKey?: T | undefined; } | { selectedKey: T; onSelectionChange: (newValue: T) => void; } ) & ( | { options: readonly T[]; } | { hideGroupLabel?: boolean | undefined; optionGroups: { name: string; options: readonly T[] }[]; } ); export const Select = ({ className, show, variant, size, rounded, hideText, icon, label, hideLabel, placement, isPending, buttonLabel, ...props }: Props) => ( // @ts-expect-error react-aria coerces everything to Key for some reason... {label} {"options" in props ? ( ({ id }))} > {({ id }) => {id}} ) : ( {({ name, options }) => (
{name}
({ id }))}> {({ id }) => {id}}
)}
)}
); type ItemProps = { children: T; show: ((value: T) => string) | undefined; }; const Item = ({ children, show }: ItemProps) => ( {show?.(children) ?? children} );