Rating
Star rating. 6 values × 2 sizes.
4 of 5 for Sylhet green
import * as React from "react";
import { Rating } from "@/components/ui/rating";
export default function Example() {
const [stars, setStars] = React.useState(4);
return (
<div style={{ display: "grid", gap: 6, justifyItems: "center" }}>
<Rating aria-label="Rate Sylhet green" value={stars} onValueChange={setStars} />
<span className="text-body-small text-fg-secondary">{stars} of 5 for Sylhet green</span>
</div>
);
}
Installation
$ npx uix-ui@latest add ratingThis copies the file into components/ui/rating.tsx in your project. npx shadcn@latest add @uix/rating works too.
Usage
import { Rating } from "@/components/ui/rating";
<div style={{ display: "grid", gap: 6, justifyItems: "center" }}>
<Rating aria-label="Rate Sylhet green" value={stars} onValueChange={setStars} />
<span className="text-body-small text-fg-secondary">{stars} of 5 for Sylhet green</span>
</div>
Props
| Prop | Type | Default | Description |
|---|---|---|---|
size | sm | md | "md" | |
value | number | 0 | Stars filled, 0 to max. |
max | number | 5 | Number of stars. |
onValueChange | (value: number) => void | – | Makes the stars buttons and calls this with the star that was pressed. |
Everything else is passed to the root element, so className, aria-* and event handlers work as usual.
Dependencies
Installed for you by the CLI.
class-variance-authorityclsxtailwind-merge
lib/utils.tscomponents/ui/icons.tsx