Components
Star Rating
Rate from one to five stars.
<StarRating legend="Your rating" />Installation
npx shadcn@latest add https://ui.zjkm.tech/r/star-rating.jsonimport { StarRating } from "@/components/star-rating"Using JavaScript? Set tsx: false in components.json and the CLI converts it.
New to shadcn? Run npx shadcn@latest init first. The CLI needs components.json and the @/ import alias.
Usage
Rate from one to five stars. Hovering previews the rating. The stars are native radios named "1 star" to "5 stars", so arrow keys work and screen readers say the rating.
import { StarRating } from "@/components/star-rating";
export function Review() {
return <StarRating legend="Your rating" name="rating" onChange={(n) => console.log(n)} />;
}Props
| Prop | Type | Default | Description |
|---|---|---|---|
legend | string | Names the group. | |
max | number | 5 | Number of stars. |
name | string | Form field name. | |
defaultValue | number | 0 | Starting rating. 0 is none. |
onChange | (value: number) => void | Called when the rating changes. | |
color | string | "#f59e0b" | Lit star colour. |
className | string | Classes for the wrapper. |
With reduced motion, stars don't grow on hover.