Genesis
@beta

Rating

Rating — a row of stars, read-only or interactive. Read-only (no `onChange`): one `img` role whose label reads "3 of 5 stars", so a screen reader hears the value once instead of five icons. Interactive: Radix's `RadioGroup` (G1: the radiogroup pattern is Radix's, roving focus, arrow keys and right-to-left included), one radio per star named "N of M stars". The arrows move between stars and choose as they go; re-clicking the chosen star clears it to 0 (`nextRating`), and the arrows never clear. The stars up to the chosen one are filled, `text-warning`; empty ones `text-muted-foreground`; no raw colours. `readOnly` forces the read-only rendering while keeping `onChange` wired for later.

packages/ui/src/components/patterns/rating.tsx

Import
Subpath export: @marktiderman/genesis-ui/patterns
import { Rating } from "@marktiderman/genesis-ui/patterns";
Components
Auto-generated from TypeScript source via react-docgen-typescript.

nextRating

The value a click on `star` produces: that star, or 0 when it is already the current value, so the one gesture also clears the rating.

No declared props.

Rating

Rating — a row of stars, read-only or interactive. Read-only (no `onChange`): one `img` role whose label reads "3 of 5 stars", so a screen reader hears the value once instead of five icons. Interactive: Radix's `RadioGroup` (G1: the radiogroup pattern is Radix's, roving focus, arrow keys and right-to-left included), one radio per star named "N of M stars". The arrows move between stars and choose as they go; re-clicking the chosen star clears it to 0 (`nextRating`), and the arrows never clear. The stars up to the chosen one are filled, `text-warning`; empty ones `text-muted-foreground`; no raw colours. `readOnly` forces the read-only rendering while keeping `onChange` wired for later.

PropTypeDefaultDescription
value*number—Current value, 0..`max`. Fractions are rounded for display.
classNamestring—
clearablebooleantrueRe-clicking the chosen star clears it to 0. Default true; false for a required answer.
disabledbooleanfalseThe stars can't be chosen, and read as disabled.
getItemProps((value: number) => { "aria-describedby"?: string; onClick?: (() => void); }) | undefined—More on a star's radio: its `aria-describedby`, a click of your own.
getLabel((value: number, max: number) => string)—Replaces the default "N of M stars" value text used in aria labels.
labelstring—Accessible name for the control (or the image, when read-only).
maxnumber5Number of stars. Default 5.
onChange((value: number) => void)—Called with the new value when a star is chosen. Absent, the rating is read-only and renders as a single `img` named "N of M stars".
readOnlybooleanfalseRead-only even with `onChange` present (e.g. while saving).
sizeenummdStar size. Default `md`. `touch` is a 44px target around a large star, for a form.
toneenumwarningThe chosen stars' colour. Default `warning`.
Storybook
Storybook hosts the canonical visual reference with controls for every variant.