@nish1896/rhf-mui-components
Version:
A suite of 25+ production-ready react-hook-form components built with material-ui. Fully typed, tree-shakable, and optimized for enterprise-grade forms.
30 lines • 1.57 kB
TypeScript
//#region src/types/common.d.ts
type StringOrNumber = string | number;
type StrNumArray = StringOrNumber[];
type KeyValueOption = Record<string, any>;
type StrNumObjOption = StringOrNumber | KeyValueOption;
type SelectValueType = StrNumObjOption | StrNumObjOption[];
type StrObjOption = string | KeyValueOption;
type OptionPrimitive = string | number;
/**
* Generic type representing the possible value types for options
* used in form components like select, radio group, checkbox group, etc.
*/
type OptionValue<Option, ValueKey extends string | undefined> = Option extends OptionPrimitive ? Option : ValueKey extends keyof Option ? Option[ValueKey] extends OptionPrimitive ? Option[ValueKey] : never : never;
type CustomComponentIds = Partial<{
field: string;
label: string;
helperText: string;
error: string;
}>;
type CustomOnChangeProps<T, V> = T & {
rhfOnChange: (value: V) => void;
};
/**
* RHF field value for Autocomplete components mirrors
* MUI `AutocompleteValue<string, Multiple, DisableClearable, false>` for primitives.
* Tuple checks avoid distributive `boolean` breaking the conditional.
*/
type AutocompleteNewValue<Multiple extends boolean, DisableClearable extends boolean> = [Multiple] extends [true] ? [DisableClearable] extends [true] ? string[] : string[] | null : [DisableClearable] extends [true] ? string : string | null;
//#endregion
export { AutocompleteNewValue, CustomComponentIds, CustomOnChangeProps, KeyValueOption, OptionPrimitive, OptionValue, SelectValueType, StrNumArray, StrNumObjOption, StrObjOption, StringOrNumber };