About
An accessible star-rating control with keyboard support, half-star precision, and a hidden form input, for collecting a 1-to-N rating from a user.
Built with React and Tailwind. Copy the prompt and paste it into Claude Code, Cursor or Lovable: your agent adds Rating Group to your project and fits it to your theme.
Code
How Rating Group is used: the demo's code. The component's own source comes with a free account.
Usage.tsx
"use client";
import RatingGroup from "@/components/ui/rating-group";
import { useState } from "react";
function Star() {
return (
<svg
viewBox="0 0 24 24"
width={16}
height={16}
fill="currentColor"
aria-hidden="true"
>
<path d="M12 2.5l2.9 6.1 6.7.9-4.9 4.6 1.2 6.6-5.9-3.2-5.9 3.2 1.2-6.6L2.4 9.5l6.7-.9z" />
</svg>
);
}
export default function RatingGroupControlledDemo() {
const [value, setValue] = useState(0);
return (
<div className="flex items-center justify-center p-10">
<div style={{ display: "grid", gap: "0.5rem", justifyItems: "start" }}>
<RatingGroup.Root
count={5}
value={value}
onValueChange={(e: { value: number }) => setValue(e.value)}
>
<RatingGroup.Label>Controlled</RatingGroup.Label>
<RatingGroup.Control>
<RatingGroup.Context>
{({ items }: { items: number[] }) =>
items.map((item) => (
<RatingGroup.Item key={item} index={item}>
<Star />
</RatingGroup.Item>
))
}
</RatingGroup.Context>
<RatingGroup.HiddenInput />
</RatingGroup.Control>
</RatingGroup.Root>
<p className="text-sm text-muted-foreground">Value: {value}</p>
</div>
</div>
);
}















