Rating
Star rating that works as both a fractional display and an interactive input. Fractional values (e.g. 3.75) render partial stars with no rounding. Provide onValueChange or defaultValue to switch to interactive input mode.
Install
Pull Rating from the barrel for everyday use, or the granular path when you want a tighter bundle.
import { Rating } from "@brika/clay";import { Rating } from "@brika/clay/components/rating";A minimal example
Drop this into a page. Native HTML attributes pass through to the underlying primitive.
import { Rating } from '@brika/clay/components/rating';
/** Default five-star rating at 3.75: the fourth star is 75% filled, no rounding. */
export default function RatingDefaultDemo() {
return <Rating value={3.75} aria-label="3.75 out of 5 stars" />;
}Rating, every way
Colors
Four ratings side by side each using a different `color` prop value, from the default `--warning` token to a custom hex.
Fractional
Three read-only ratings at different fractional values (3.75, 2.3, 0.5) shown across all three size variants, demonstrating sub-star fill with no rounding.
Interactive
Whole-star selection via hover and click, shown in uncontrolled, controlled, and disabled modes with Arrow-key keyboard support.
Sizes
All three size variants (`sm`, `default`, `lg`) shown at the same 3.75 value for easy comparison.
Accessibility
- Display mode (no handler /
readOnlyset): usesrole="img"with anaria-labeldefaulting to "Rated {value} out of {max}". Override with thearia-labelprop. - Interactive mode: uses
role="radiogroup"on the row; each star is a<button role="radio">witharia-checkedandaria-label("N out of max"). The committed star (or star 1 when unset) is the roving tab stop. - Keyboard in interactive mode: ArrowRight/ArrowUp moves to the next star and commits it; ArrowLeft/ArrowDown moves to the previous star and commits it.
- Each
<FractionalStar>isaria-hidden; only the button label carries the accessible name. - Pass
disabledto render the visual without interaction; buttons are absent and opacity is reduced.
Theme tokens
Every CSS variable Rating reads, with its default and the
dotted path you'd write in a ThemeConfig JSON
to override it. Set any of these in your theme to retune Rating
without touching component code.
Rating tokens
5 tokens--rating-filled-colorcolorvar(--warning)components.rating.filledColorFill and stroke color for stars at or below the rounded value. Defaults to `--warning` (amber) so the hue follows the theme without a hard-coded color.
--rating-empty-colorcolorcolor-mix(in oklch, var(--muted-foreground) 30%, transparent)components.rating.emptyColorStroke color for stars above the rounded value. A 30% mix of `--muted-foreground` against transparent gives a faint ghost that reads on both light and dark surfaces.
--rating-star-size-smsize0.75remcomponents.rating.starSizeSmStar icon diameter at the `sm` size variant.
--rating-star-sizesize0.875remcomponents.rating.starSizeStar icon diameter at the `default` size variant.
--rating-star-size-lgsize1.25remcomponents.rating.starSizeLgStar icon diameter at the `lg` size variant.
Override in a theme
Authoring a theme is plain JSON. Drop overrides under
components.rating, the names
are camelCase versions of the variable suffix.
{
"id": "my-theme",
"name": "My Theme",
"description": "...",
"accentSwatches": ["#000"],
"components": {
"rating": {
"filledColor": "var(--warning)"
}
}
}
Then apply with applyTheme(myTheme)
(see the theming guide),
scope it to a subtree with themeToCssVars(myTheme, mode),
or consume any token directly in your own JSX with the matching Tailwind utility
(e.g. bg-rating-…) — see the
chips on each token row.
API reference
Props specific to Rating. Native HTML attributes pass through to the underlying primitive, see the component source on GitHub for the full type signature.
<Rating />
passthroughNo wrapper-specific props, all attributes pass through to the underlying primitive.
<FractionalStar />
1 prop- number
No description.