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
@marktiderman/genesis-ui/patternsimport { Rating } from "@marktiderman/genesis-ui/patterns";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.
| Prop | Type | Default | Description |
|---|---|---|---|
| value* | number | — | Current value, 0..`max`. Fractions are rounded for display. |
| className | string | — | |
| clearable | boolean | true | Re-clicking the chosen star clears it to 0. Default true; false for a required answer. |
| disabled | boolean | false | The 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. |
| label | string | — | Accessible name for the control (or the image, when read-only). |
| max | number | 5 | Number 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". |
| readOnly | boolean | false | Read-only even with `onChange` present (e.g. while saving). |
| size | enum | md | Star size. Default `md`. `touch` is a 44px target around a large star, for a form. |
| tone | enum | warning | The chosen stars' colour. Default `warning`. |