import * as React from 'react'; import classNames from 'classnames'; import { classNameModifier } from '../shared/utils'; import { ComponentClassNames } from '../shared/constants'; import { FieldErrorMessage, FieldDescription } from '../Field'; import { Flex } from '../Flex'; import { Label } from '../Label'; import { Select } from '../Select'; import { BaseSelectFieldProps, SelectFieldProps, ForwardRefPrimitive, Primitive, } from '../types'; import { splitPrimitiveProps } from '../utils/splitPrimitiveProps'; import { useStableId } from '../utils/useStableId'; interface SelectFieldChildrenProps { children?: React.ReactNode; options?: SelectFieldProps['options']; } const selectFieldChildren = ({ children, options, }: SelectFieldChildrenProps) => { if (children) { if (options?.length) { // eslint-disable-next-line no-console console.warn( 'Amplify UI: component defaults to rendering children over `options`. When using the `options` prop, omit children.' ); } return children; } return options?.map((option, index) => ( )); }; const SelectFieldPrimitive: Primitive = ( props, ref ) => { const { children, className, descriptiveText, errorMessage, hasError = false, id, label, labelHidden = false, options, size, testId, inputStyles, ..._rest } = props; const fieldId = useStableId(id); const descriptionId = useStableId(); const ariaDescribedBy = descriptiveText ? descriptionId : undefined; const { styleProps, rest } = splitPrimitiveProps(_rest); return ( ); }; /** * [📖 Docs](https://ui.docs.amplify.aws/react/components/selectfield) */ export const SelectField: ForwardRefPrimitive = React.forwardRef(SelectFieldPrimitive); SelectField.displayName = 'SelectField';