@nish1896/rhf-mui-components
Version:
A suite of 20+ reusable Material UI components for React Hook Form to minimize your time and effort in creating and styling forms
27 lines (26 loc) • 2.02 kB
TypeScript
import { type ReactNode, type SyntheticEvent } from 'react';
import { type FieldValues, type Path, type Control, type RegisterOptions } from 'react-hook-form';
import { type AutocompleteProps, type AutocompleteChangeDetails, type AutocompleteChangeReason } from '@mui/material/Autocomplete';
import type { FormLabelProps, FormHelperTextProps, TrueOrFalse, StrObjOption, AutoCompleteTextFieldProps, MuiChipProps } from '../../types';
type OmittedAutocompleteProps = Omit<AutocompleteProps<StrObjOption, TrueOrFalse, TrueOrFalse, TrueOrFalse>, 'freeSolo' | 'fullWidth' | 'renderInput' | 'renderOption' | 'options' | 'value' | 'defaultValue' | 'onChange' | 'getOptionKey' | 'getOptionLabel' | 'isOptionEqualToValue' | 'autoHighlight' | 'blurOnSelect' | 'disableCloseOnSelect' | 'ChipProps'>;
export type RHFAutocompleteProps<T extends FieldValues> = {
fieldName: Path<T>;
control: Control<T>;
registerOptions?: RegisterOptions<T, Path<T>>;
options: StrObjOption[];
labelKey?: string;
valueKey?: string;
onValueChange?: (fieldValue: string | string[] | null, event: SyntheticEvent<Element, Event>, reason: AutocompleteChangeReason, details?: AutocompleteChangeDetails<StrObjOption>) => void;
label?: ReactNode;
showLabelAboveFormField?: boolean;
formLabelProps?: FormLabelProps;
required?: boolean;
helperText?: ReactNode;
errorMessage?: ReactNode;
hideErrorMessage?: boolean;
formHelperTextProps?: FormHelperTextProps;
textFieldProps?: AutoCompleteTextFieldProps;
ChipProps?: MuiChipProps;
} & OmittedAutocompleteProps;
declare const RHFAutocomplete: <T extends FieldValues>({ fieldName, control, registerOptions, options, multiple, labelKey, valueKey, onValueChange, label, showLabelAboveFormField, formLabelProps, required, helperText, errorMessage, hideErrorMessage, formHelperTextProps, textFieldProps, slotProps, ChipProps, ...otherAutoCompleteProps }: RHFAutocompleteProps<T>) => import("react/jsx-runtime").JSX.Element;
export default RHFAutocomplete;