UNPKG

@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.

113 lines (112 loc) 4.43 kB
import { CustomComponentIds } from "../../types/common.js"; import { FormHelperTextProps, FormLabelProps } from "../../common/types/mui.js"; import { JSX, ReactNode, Ref } from "react"; import { Control, FieldError, FieldValues, Path, RegisterOptions } from "react-hook-form"; import { PickerChangeHandlerContext, PickerValidDate, StaticTimePickerProps, TimeValidationError } from "@mui/x-date-pickers"; //#region src/mui-pickers/time/RHFStaticTimePicker.d.ts type StaticTimePickerInputProps = Omit<StaticTimePickerProps, 'value' | 'ref'>; type PickerOnValueChangeProps<ValidationError> = { newValue: PickerValidDate; context: PickerChangeHandlerContext<ValidationError>; }; type PickerCustomOnChangeProps<ValidationError> = PickerOnValueChangeProps<ValidationError> & { rhfOnChange: (value: PickerValidDate) => void; }; type RHFStaticTimePickerProps<T extends FieldValues> = { /** * Name/path of the React Hook Form field this component controls. */ fieldName: Path<T>; /** * React Hook Form control object returned by `useForm`. */ control: Control<T>; /** * Validation rules passed to React Hook Form for this field. */ registerOptions?: RegisterOptions<T, Path<T>>; /** * When true, marks the field as required in the UI and accessibility attributes. */ required?: boolean; /** * Overrides the default time picker change handling. * Receives every picker change, including time values that currently have validation errors. * Call `rhfOnChange` with the picker value that should be stored; else the form value will not be updated. * The default handler stores the value only when `context.validationError` is `null`. * * @param rhfOnChange - React Hook Form field change handler for the selected time value. * @param newValue - New time value emitted by MUI X. * @param context - MUI X picker change context, including validation status. */ customOnChange?: ({ rhfOnChange, newValue, context }: PickerCustomOnChangeProps<TimeValidationError>) => void; /** * Called after the default time picker handler stores a valid time value in React Hook Form. * * ⚠️ Important: * This callback is not called when `customOnChange` is used. * * @param newValue - New time value emitted by MUI X. * @param context - MUI X picker change context, including validation status. */ onValueChange?: ({ newValue, context }: PickerOnValueChangeProps<TimeValidationError>) => void; /** * Label content shown for the field. Defaults to a label generated from `fieldName`. */ label?: ReactNode; /** * When `true`, renders the label above the component instead of within the field layout. */ showLabelAboveFormField?: boolean; /** * Props forwarded to the internal `FormLabel`. The `id` is managed by the component. */ formLabelProps?: Omit<FormLabelProps, 'id'>; /** * When true, hides the rendered field label while preserving accessible labeling where possible. */ hideLabel?: boolean; /** * @deprecated * Field error message is now automatically derived from form state. * Passing this prop is no longer necessary and it will be removed in the next major version. * * Use `renderError` to customize how the field error is rendered. */ errorMessage?: ReactNode; /** * Custom renderer for the React Hook Form field error. * Receives the current field error and must return renderable content, such as `error.message` or a custom element. * * @param error - React Hook Form field error for this field. */ renderError?: (error: FieldError) => ReactNode; /** * If true, hides the error message text while keeping the field in an error state. */ hideErrorMessage?: boolean; /** * Helper text shown below the field when there is no visible validation error. */ helperText?: ReactNode; /** * Props forwarded to the internal `FormHelperText`. The `id` is managed by the component. */ formHelperTextProps?: Omit<FormHelperTextProps, 'id'>; /** * Custom ids for generated field, label, helper text, and error elements. */ customIds?: CustomComponentIds; } & StaticTimePickerInputProps; declare const RHFStaticTimePicker: <T extends FieldValues>(props: RHFStaticTimePickerProps<T> & { ref?: Ref<HTMLDivElement>; }) => JSX.Element; //#endregion export { RHFStaticTimePicker, RHFStaticTimePickerProps };