import * as React from 'react'; import { Props as BaseFieldProps } from '../BaseField/useBaseField'; import { FormElementProps, SizeRangeReduced } from '../utils/types'; export type SelectOption = { id?: string; value: string; disabled?: boolean; label: string; }; export type SelectOptionGroup = { id?: string; label: string; options: SelectOption[]; }; type MultipleProps = FormElementProps & { /** * Enables selection of multiple values. */ multiple: true; /** * Value for the select element. * An array of values is required for `multiple`. */ value: string[]; onChange: ( value: string[], extra?: { event: React.ChangeEvent }, ) => void; }; type SingluarProps = FormElementProps & { /** * Enables selection of multiple values. */ multiple: false | undefined; /** * Value for the select element. * An array of values is required for `multiple`. */ value: string; onChange: ( value: string, extra?: { event: React.ChangeEvent }, ) => void; }; export type Props = Omit & (MultipleProps | SingluarProps) & { /** * @example * ```jsx * import { Select, Text } from `@wp-g2/components` * * function Example() { * return * } * ``` */ isSubtle?: boolean; /** * Options to render within `Select`. * * @example * ```jsx * import { Select } from `@wp-g2/components` * * function Example() { * const options = [ * { id: 'elsa', value: 'elsa', label: 'Elsa' }, * { id: 'ana', value: 'ana', label: 'Ana' }, * ] * * return * } * ``` */ options?: (SelectOption | SelectOptionGroup)[]; /** * Example text to display as placeholder. */ placeholder?: string; /** * Renders prefix content within `Select`. * * @example * ```jsx * import { Select, Text } from `@wp-g2/components` * * function Example() { * return * } * ``` */ size?: SizeRangeReduced; /** * Renders prefix content within `Select`. * * @example * ```jsx * import { Select, Text } from `@wp-g2/components` * * function Example() { * return