envoc-form
Version:
Envoc form components
29 lines (28 loc) • 1.44 kB
TypeScript
/// <reference types="react" />
import { InjectedFieldProps } from '../Field/InjectedFieldProps';
import { GroupProps } from '../Group';
export interface SelectOption<TValue> {
/** Value for the select. This will be sent to the API. */
value: (TValue extends Array<infer P> ? P : TValue) | undefined;
/** Label for the select. This is displayed to the user. */
label: string;
}
interface OptionsApiResult<TValue> {
result?: Partial<SelectOption<TValue>>[];
}
interface OptionsUseServiceResult<TValue> {
loading?: boolean;
resp?: Partial<SelectOption<TValue>>[] | OptionsApiResult<TValue> | null;
error?: any;
}
export interface SelectGroupProps<TValue> extends InjectedFieldProps<TValue | undefined | null>, Omit<GroupProps, 'input' | 'meta' | 'children'> {
/** Options for the dropdown. Includes the label and value. */
options: SelectOption<TValue>[] | OptionsUseServiceResult<TValue>;
/** Whether the user should be able to have multiple values selected. */
multiple: TValue extends Array<any> ? true : false;
/** Text diplayed when no value is selected. */
placeholder?: string;
}
/** Generic select dropdown. Uses [react-select](https://react-select.com/home). */
export default function SelectGroup<TValue>({ input, meta, className, required, disabled, options, multiple, placeholder, ...rest }: SelectGroupProps<TValue>): JSX.Element;
export {};