A read-only row of five stars that fills to match a numeric rating, including fractional values. Use it for review scores on product cards and testimonials.
Install
pnpm dlx shadcn@latest add https://sitex.full.dev/r/rating.jsonUsage
import { Rating } from "@/components/ui/rating"
export function ReviewScore() {
return (
<p className="flex items-center gap-2">
<Rating value={4.5} />
<span className="text-sm text-muted-foreground">4.5 out of 5</span>
</p>
)
}Key points:
Ratingis the only export; it renders adivand accepts all standarddivprops.value(default5) sets how many of the five stars are filled; fractions like4.5render a partially filled star.- The stars scale with the surrounding font size (they are sized in
em), so setclassName="text-sm"or similar to resize them; filled stars use theprimarycolor and empty stars a muted track.
It is purely presentational with no state or handlers, so no client directive is needed.