import { CustomOnChangeProps } from "../../common/types/components.js"; import { CheckboxProps, FormControlLabelProps, FormHelperTextProps } from "../../common/types/mui.js"; import "../../common/index.js"; import { ChangeEvent, JSX, ReactNode, Ref } from "react"; import { Control, FieldError, FieldValues, Path, RegisterOptions } from "react-hook-form"; import { CustomComponentIds } from "@nish1896/mui-components/types"; //#region src/mui/checkbox/index.d.ts type OnValueChangeProps = { newValue: boolean; event: ChangeEvent; }; type RHFCheckboxProps = { /** * Name/path of the React Hook Form field this component controls. */ fieldName: Path; /** * React Hook Form control object returned by `useForm`. */ control: Control; /** * Validation rules passed to React Hook Form for this field. */ registerOptions?: RegisterOptions>; /** * Overrides the default checkbox change handling. * Receives the next checked state and the original checkbox change event. * Call `rhfOnChange` with the boolean value that should be stored; else the form value will not be updated. * * @param rhfOnChange - React Hook Form field change handler for the checked value. * @param newValue - Next checked state. * @param event - Original checkbox change event. */ customOnChange?: ({ rhfOnChange, newValue, event }: CustomOnChangeProps) => void; /** * Called after the default checkbox handler stores the next checked state in React Hook Form. * * ⚠️ Important: * This callback is not called when `customOnChange` is used. * * @param newValue - Next checked state. * @param event - Original checkbox change event. */ onValueChange?: ({ newValue, event }: OnValueChangeProps) => void; /** * Label content shown for the field. Defaults to a label generated from `fieldName`. */ label?: ReactNode; /** * Props forwarded to the checkbox `FormControlLabel`. */ formControlLabelProps?: FormControlLabelProps; /** * When true, hides the rendered field label while preserving accessible labeling where possible. */ hideLabel?: boolean; /** * 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; /** * Custom ids for generated field, label, helper text, and error elements. */ customIds?: CustomComponentIds; } & CheckboxProps; /** * Controlled single Material UI `Checkbox`, wired to a React Hook Form field * via `control`. * * Use `RHFCheckboxGroup` instead for a set of checkboxes sharing one field. * * Docs: [RHFCheckbox](https://rhf-mui-components.vercel.app/components/mui/RHFCheckbox) * * API: [RHFCheckboxProps](https://rhf-mui-components.vercel.app/components/mui/RHFCheckbox#api) */ declare const RHFCheckbox: (props: RHFCheckboxProps & { ref?: Ref; }) => JSX.Element; //#endregion export { RHFCheckboxProps, RHFCheckbox as default };