@nish1896/rhf-mui-components
Version:
A suite of 20+ production-ready react-hook-form components built with material-ui. Fully typed, tree-shakable, and optimized for enterprise-grade forms.
55 lines (54 loc) • 2.65 kB
TypeScript
import { KeyValueOption, TrueOrFalse } from "../../types/common.js";
import { AutoCompleteTextFieldProps, FormHelperTextProps, FormLabelProps, MuiChipProps } from "../../types/mui.js";
import { ReactNode, SyntheticEvent } from "react";
import * as react_jsx_runtime0 from "react/jsx-runtime";
import { Control, FieldValues, Path, RegisterOptions } from "react-hook-form";
import { AutocompleteChangeDetails, AutocompleteChangeReason, AutocompleteProps } from "@mui/material/Autocomplete";
//#region src/mui/autocomplete-object/index.d.ts
type OmittedAutocompleteProps<Option> = Omit<AutocompleteProps<Option, TrueOrFalse, TrueOrFalse, TrueOrFalse>, 'freeSolo' | 'fullWidth' | 'renderInput' | 'options' | 'value' | 'defaultValue' | 'onChange' | 'getOptionKey' | 'getOptionLabel' | 'isOptionEqualToValue' | 'autoHighlight' | 'blurOnSelect' | 'disableCloseOnSelect' | 'ChipProps'>;
type RHFAutocompleteObjectProps<T extends FieldValues, Option extends KeyValueOption = KeyValueOption, LabelKey extends Extract<keyof Option, string> = Extract<keyof Option, string>, ValueKey extends Extract<keyof Option, string> = Extract<keyof Option, string>> = {
fieldName: Path<T>;
control: Control<T>;
registerOptions?: RegisterOptions<T, Path<T>>;
options: Option[];
labelKey: LabelKey;
valueKey: ValueKey;
onValueChange?: (fieldValue: Option | Option[] | null, event: SyntheticEvent<Element, Event>, reason: AutocompleteChangeReason, details?: AutocompleteChangeDetails<Option>) => void;
label?: ReactNode;
showLabelAboveFormField?: boolean;
formLabelProps?: FormLabelProps;
required?: boolean;
helperText?: ReactNode;
errorMessage?: ReactNode;
hideErrorMessage?: boolean;
formHelperTextProps?: FormHelperTextProps;
textFieldProps?: AutoCompleteTextFieldProps;
ChipProps?: MuiChipProps;
} & OmittedAutocompleteProps<Option>;
declare const RHFAutocompleteObject: <T extends FieldValues, Option extends KeyValueOption, LabelKey extends Extract<keyof Option, string> = Extract<keyof Option, string>, ValueKey extends Extract<keyof Option, string> = Extract<keyof Option, string>>({
fieldName,
control,
registerOptions,
options,
multiple,
labelKey,
valueKey,
onValueChange,
disabled: muiDisabled,
label,
showLabelAboveFormField,
formLabelProps,
required,
helperText,
errorMessage,
hideErrorMessage,
formHelperTextProps,
textFieldProps,
slotProps,
ChipProps,
onBlur,
loading,
...otherAutoCompleteProps
}: RHFAutocompleteObjectProps<T, Option, LabelKey, ValueKey>) => react_jsx_runtime0.JSX.Element;
//#endregion
export { RHFAutocompleteObjectProps, RHFAutocompleteObject as default };