import React, { useId, useRef } from 'react' import { useSelectState } from '@react-stately/select' import classNames from 'classnames' import { useSelect } from 'react-aria' import { FieldMessage, Label } from '~components/index' import { SingleSelectContext } from '../../context' import { type SelectItem, type SelectProps } from '../../types' import { List } from '../List' import { Popover } from '../Popover' import { SelectTrigger } from '../SelectTrigger' import styles from './Select.module.css' export const Select = (props: SelectProps): JSX.Element => { const { label, description, labelHidden, labelPosition = 'top', isDisabled, isReadOnly, size = 'medium', variant = 'primary', } = props const state = useSelectState({ ...props, items: props.items, children: props.children, }) const popoverRef = useRef(null) const listBoxRef = useRef(null) const triggerRef = useRef(null) const { labelProps, descriptionProps, menuProps, triggerProps, valueProps } = useSelect( { ...props, 'aria-label': labelHidden ? label : undefined, }, state, triggerRef, ) const uniqueId = useId() const anchorName = `--trigger-${uniqueId}` return (
{!labelHidden && (
)}
{description && (
)}
) }