import { CustomOnChangeProps } from "../../common/types/components.js"; import { FormHelperTextProps, FormLabelProps } from "../../common/types/mui.js"; import "../../common/index.js"; import { JSX, ReactNode, Ref, SyntheticEvent } from "react"; import { Control, FieldError, FieldValues, Path, RegisterOptions } from "react-hook-form"; import { RatingProps } from "@mui/material/Rating"; import { CustomComponentIds } from "@nish1896/mui-components/types"; //#region src/mui/rating/index.d.ts type OnValueChangeProps = { newValue: number | null; event: SyntheticEvent; }; type InputRatingProps = Omit; type RHFRatingProps = { /** * 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>; /** * When true, marks the field as required in the UI and accessibility attributes. */ required?: boolean; /** * Overrides the default rating change handling. * Receives the next rating value and the original rating change event. * Call `rhfOnChange` with the number or `null` value that should be stored; else the form value will not be updated. * * @param rhfOnChange - React Hook Form field change handler for the rating value. * @param newValue - Next rating value, or `null` when cleared. * @param event - Original rating change event. */ customOnChange?: ({ rhfOnChange, newValue, event }: CustomOnChangeProps) => void; /** * Called after the default rating handler stores the next rating value in React Hook Form. * * ⚠️ Important: * This callback is not called when `customOnChange` is used. * * @param newValue - Next rating value, or `null` when cleared. * @param event - Original rating change event. */ onValueChange?: ({ newValue, event }: OnValueChangeProps) => void; /** * Label content shown for the field. Defaults to a label generated from `fieldName`. */ label?: ReactNode; /** * Renders the label above the component. * @default true */ showLabelAboveFormField?: boolean; /** * Props forwarded to the internal `FormLabel`. The `id` is managed by the component. */ formLabelProps?: Omit; /** * 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; } & InputRatingProps; /** * Controlled Material UI `Rating` (star) input, wired to a React Hook Form * field via `control`. * * Docs: [RHFRating](https://rhf-mui-components.vercel.app/components/mui/RHFRating) * * API: [RHFRatingProps](https://rhf-mui-components.vercel.app/components/mui/RHFRating#api) */ declare const RHFRating: (props: RHFRatingProps & { ref?: Ref; }) => JSX.Element; //#endregion export { RHFRatingProps, RHFRating as default };