import type { ForwardedRef, ReactNode } from 'react'; import React, { useId, useMemo } from 'react'; import classNames from 'classnames'; import { omit, pick } from '@shoptet/utils'; import { forwardRef } from '../../../utils/forwardRef'; import type { FormRowProps } from '../../FormRow/FormRow'; import { FormRow } from '../../FormRow/FormRow'; import type { FormRowHelperTextOwnProps } from '../../FormRow/FormRowHelperText'; import { InputLoader } from '../../Inputs/InputLoader'; import type { SelectKey, SingleSelectProps } from '../../Inputs/SingleSelect/SingleSelect'; import { SingleSelect } from '../../Inputs/SingleSelect/SingleSelect'; /** * All props inherited from the `FormRow` component and the `SearchInput` component. * * Omitted props: * - 'as' field container cannot be used as a `HTMLLabelElement` due complexity of combobox * - `error` and `warning` simplified booleans of `SearchInput` component * @inheritdoc */ interface SingleSelectFieldInheritedProps extends Partial, Omit {} /** @inheritdoc */ export interface SingleSelectFieldProps extends Omit, 'error' | 'warning'>, SingleSelectFieldInheritedProps { /** * Addon to the right of the input. * * **INTERNAL USE ONLY:** It is unsafe to rely on this prop, as it may change or be removed in the future. * @internal */ UNSAFE_addon?: ReactNode; /** * Display loading indicator. */ loading?: boolean; } export const SingleSelectField = Object.assign( forwardRef(function SingleSelectField( { UNSAFE_addon: addon, emptyOptionsLabel, error, hint, id, justify, label, labelHidden, required, tooltip, warning, width, ...rest }: SingleSelectFieldProps, forwardedRef: ForwardedRef ) { const helperTextElement = useMemo( () => , [error, hint, warning] ); const internalId = useId(); const inputId = id ?? `singleSelect${internalId}`; return (
{helperTextElement}
{addon}
); }), { Option: SingleSelect.Option, } );