/** * * The useRating manages the state and functionality of a rating component. * * [Live Demo](https://www.primereact.org/rating/) * * @module useRating * @group headless * */ import type { HeadlessInstance } from '@primereact/types/core'; /** * Event fired when the rating value changes. */ export interface UseRatingValueChangeEvent { /** * The original event that triggered the change. */ originalEvent: E; /** * The new rating value. */ value: number; } /** * Defines valid properties in useRating. */ export interface UseRatingProps { /** * Value of the rating. */ value?: number | undefined; /** * The default value of the rating. * @default 0 */ defaultValue?: number | undefined; /** * Whether to allow half stars. * @default true */ allowHalf?: boolean | undefined; /** * Name used for the hidden radio inputs. Auto-generated if not provided. */ name?: string | undefined; /** * The orientation of the rating. * @default 'horizontal' */ orientation?: 'horizontal' | 'vertical' | undefined; /** * When present, it specifies that the element should be disabled. * @default false */ disabled?: boolean | undefined; /** * When present, it specifies that component is read-only. * @default false */ readOnly?: boolean | undefined; /** * When present, it specifies that the component should have invalid state style. * @default false */ invalid?: boolean | undefined; /** * Callback fired when the value changes. */ onValueChange?: ((event: UseRatingValueChangeEvent) => void) | undefined; } /** * Defines valid state in useRating. */ export interface UseRatingState { /** * The current value of the rating. */ value: number; /** * Whether the rating is in a hover state. */ hovering: boolean; /** * The value currently being hovered over. */ hoveringValue: number; } /** * Data attribute props shared by Rating elements. */ export interface UseRatingRootProps { /** * Component scope identifier. */ 'data-scope': string; /** * Component part identifier. */ 'data-part': string; /** * Layout orientation. */ 'data-orientation': string; [key: string]: unknown; } /** * Defines the methods and properties exposed by useRating. */ export interface UseRatingExposes { /** * Current state of the rating. */ state: UseRatingState; /** * The computed name used for radio inputs (from props.name or auto-generated). * Named 'inputName' to avoid collision with withComponent's common.name. */ inputName: string; /** * Pre-built props for the root element (data attributes + event handlers). */ rootProps: UseRatingRootProps; /** * Update the rating value. */ updateValue: (event: React.SyntheticEvent, value: number) => void; /** * Set the hover value (called by On/Off on pointer move). */ setHoveringValue: (value: number) => void; /** * Resolves the value to set from a pointer event, taking allowHalf and element position into account. */ resolvePointerValue: (e: React.PointerEvent | React.MouseEvent, optionEl: Element | null, idx: number) => number; /** * Pre-built data attribute props for the option element. */ optionProps: UseRatingRootProps; /** * Pre-built data attribute props for the on-icon element. */ onProps: UseRatingRootProps; /** * Pre-built data attribute props for the off-icon element. */ offProps: UseRatingRootProps; } /** * Instance of useRating headless. */ export type UseRatingInstance = HeadlessInstance;