A star rating on Vercel's UI SDK with whole or half stars, a hover preview, read-only averages and form support.
Install
Add it to your project
Run this in a project set up for shadcn/ui. It writes the files and installs the npm packages.
First time: connect the Infinity UI registry
- Create a personal token on your Tokens page.
- Put it in
.env.localasINFINITYUI_TOKEN. - Add the registry to
components.json:
{
"registries": {
"@infinityui": {
"url": "https://infinityui.io/r/{name}.json",
"headers": {
"Authorization": "Bearer ${INFINITYUI_TOKEN}"
}
}
}
}Using Claude Code, Codex, Cursor, Lovable or v0? See CLI & MCP for a setup prompt.
npm packages it adds
- cn
- @ui-sdk/core
- @ui-sdk/react
- @tabler/icons-react
- class-variance-authority
Code
"use client"
import * as React from "react"
import { Rating, RatingItem } from "@/components/ui/ui-sdk-rating"
const labels = ["Terrible", "Poor", "Okay", "Good", "Great"]
function UiSdkRatingDemo() {
const [value, setValue] = React.useState<number | null>(4)
return (
<div className="flex flex-col items-center gap-2">
<Rating
aria-label="How was your stay?"
size="lg"
value={value}
onValueChange={setValue}
getValueLabel={(score, max) =>
labels[score - 1] + ", " + score + " of " + max
}
>
<RatingItem />
</Rating>
<p
aria-hidden="true"
className="min-h-5 text-sm text-muted-foreground tabular-nums"
>
{value ? labels[value - 1] : "Not rated yet"}
</p>
</div>
)
}
export { UiSdkRatingDemo }
































