@baseplate-dev/ui-components
Version:
Shared UI component library
30 lines • 2.51 kB
TypeScript
import type React from 'react';
import type { Control, FieldPath, FieldValues } from 'react-hook-form';
import type { AddOptionRequiredFields, FormFieldProps, SelectOptionProps } from '#src/types/form.js';
import type { ComboboxProps } from '../combobox/combobox.js';
type AsyncOptionLoader<OptionType> = (searchQuery: string) => Promise<OptionType[]>;
export interface AsyncComboboxFieldProps<OptionType> extends Omit<ComboboxProps, 'value' | 'onChange' | 'label' | 'children' | 'searchQuery' | 'onSearchQueryChange'>, Omit<SelectOptionProps<OptionType>, 'options'>, FormFieldProps {
className?: string;
noResultsText?: React.ReactNode;
loadingText?: React.ReactNode;
errorText?: React.ReactNode;
formatError?: (error: unknown) => string;
loadOptions: AsyncOptionLoader<OptionType>;
resolveValue?: (value: string | null) => Promise<OptionType | null>;
debounceMs?: number;
loadingDelay?: number;
minSearchLength?: number;
initialOptions?: OptionType[];
}
/**
* Field with label and error states that wraps a Combobox component with async option loading.
*/
declare function AsyncComboboxField<OptionType>({ label, description, error, value, placeholder, renderItemLabel, onChange, getOptionLabel, getOptionValue, className, noResultsText, loadingText, errorText, formatError, loadOptions, resolveValue, debounceMs, loadingDelay, minSearchLength, initialOptions, ...props }: AsyncComboboxFieldProps<OptionType> & AddOptionRequiredFields<OptionType>): React.ReactElement;
interface AsyncComboboxFieldControllerPropsBase<OptionType, TFieldValues extends FieldValues = FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> extends Omit<AsyncComboboxFieldProps<OptionType>, 'value'> {
control: Control<TFieldValues>;
name: TFieldName;
}
type AsyncComboboxFieldControllerProps<OptionType, TFieldValues extends FieldValues = FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>> = AsyncComboboxFieldControllerPropsBase<OptionType, TFieldValues, TFieldName>;
declare function AsyncComboboxFieldController<OptionType, TFieldValues extends FieldValues = FieldValues, TFieldName extends FieldPath<TFieldValues> = FieldPath<TFieldValues>>({ name, control, ...rest }: AsyncComboboxFieldControllerProps<OptionType, TFieldValues, TFieldName> & AddOptionRequiredFields<OptionType>): React.ReactElement;
export { AsyncComboboxField, AsyncComboboxFieldController };
//# sourceMappingURL=async-combobox-field.d.ts.map