NK

Search

Search pages, posts, and components

All components

Star Rating

Inputs

A star rating you can click, with hover preview.

Installation

Add it with the shadcn CLI:

$pnpm dlx shadcn@latest add https://nawalkattel.com.np/r/star-rating.json
Or install manually
  1. 1. Install dependencies

    pnpm add motion clsx tailwind-merge lucide-react
  2. 2. Copy the component source into components/library/star-rating.tsx

Props

PropTypeDefaultDescription
valuenumber4Initial rating.
maxnumber5Number of stars.
onChange(value: number) => void - Called with the new rating.

Accessibility

  • role=radiogroup with aria-checked on the selected star.
  • Each star has an aria-label giving its numeric value.
  • Hover preview never commits until you click.

Dependencies

motionclsxtailwind-mergelucide-react