Rating
Rating lets people score with stars; RatingDisplay shows a read-only score.
Import
Install from npm, copy the source into your project with @yugen-ui/cli or the shadcn CLI, or import directly when working in this repo.
// npm install yugen-uiimport { Rating, RatingDisplay } from "yugen-ui";Variants
Each tile is a standalone example: hover to copy, or press Code to see the source.
Color
neutral (default), brand, marigold.
Half stars (controlled)
step={0.5}: each star has two click targets.
RatingDisplay
Read-only display with the value and count; compact shows a single star.
Size
small (12px), medium (16px), large (20px), extra-large (28px, default).
Usage
- Always add an aria-label that names what is being rated.
- Show RatingDisplay with the count so people can judge how reliable the score is.
- Use one star color across the whole product.
- Don't use Rating for choices that aren't a scale. Use RadioGroup.
- Don't rely on star color alone. Show the numeric value as well.
Props
| Prop · Type | Default | Description |
|---|---|---|
| value / defaultValuenumber | Default: 0 | Current score (0 = not rated). |
| onValueChange(value: number) => void | Default: — | Called when a score is picked. |
| maxnumber | Default: 5 | Number of stars. |
| step1 | 0.5 | Default: 1 | Allows half stars. |
| color"neutral" | "brand" | "marigold" | Default: "neutral" | Star color. |
| size"small" | "medium" | "large" | "extra-large" | Default: "extra-large" | Star size 12 / 16 / 20 / 28px. |
| itemLabel(value: number) => string | Default: — | Screen reader label for each score. |
| RatingDisplay | Default: — | Number of ratings; show a single star. |
| RatingDisplay | Default: "medium" | Star and text size. |
| RatingDisplay | Default: true | Shows the value next to the stars. The old name hideValue (inverted) is deprecated (removed in 1.0). |
Messages
Text built into the component: labels, aria-labels, screen reader announcements.
English by default. Change it with the messages prop of YugenProvider, by the namespace below; messagesVi has the Vietnamese set. See Interface language.
messages.rating
| Key · Type | Default (English) | messagesVi |
|---|---|---|
| item(value: number, valueText: string) => string Nhãn đọc cho từng giá trị của Rating; | Default (English)(value, valueText) => (value === 1 ? `${valueText} star` : `${valueText} stars`) | messagesVi(_value, valueText) => `${valueText} sao` |
| summary(valueText: string, max: number) => string Nhãn đọc của RatingDisplay; | Default (English)(valueText, max) => `Rated ${valueText} out of ${max} stars` | messagesVi(valueText, max) => `Đánh giá ${valueText} trên ${max} sao` |
| count(count: number, countText: string) => string Số lượt đánh giá, nối sau | Default (English)(count, countText) => (count === 1 ? `${countText} rating` : `${countText} ratings`) | messagesVi(_count, countText) => `${countText} lượt` |