asafefe.dev

Rating Input

New

A star rating with hover preview, optional half steps and a quick pop wave on select. Arrow keys change it, and read only mode shows partial fills.

motionlucide-reactutils@soultel/use-reduced-motion-safe

How was your delivery?

Order #4812 from Acme Bakery

Average, read only
4.6
From 1,284 reviews
Half steps
Custom icon

Installation

$ pnpm dlx shadcn@latest add @soultel/rating-input

No namespace set up? npx shadcn@latest add https://asafefe.dev/r/rating-input.json works too.

Manual installation
  1. 1. Install the dependencies.
    terminal1 lines
    npm install motion lucide-react
  2. 2. Copy the source from the Code tab into components/rating-input.tsx.

Usage

example.tsx11 lines
import { RatingInput } from "@/components/rating-input"

export function Review() {
  return (
    <RatingInput
      label="How was your order?"
      labels={["Terrible", "Bad", "Okay", "Good", "Great"]}
      onValueChange={(stars) => saveRating(stars)}
    />
  )
}

Props

PropTypeDefaultDescription
value / defaultValuenumber0Controlled or initial rating. 0 means none.
onValueChange(value: number) => void-Called when the rating changes.
maxnumber5Number of icons.
allowHalfbooleanfalseHalf steps, picked from the left or right half of an icon.
readOnlybooleanfalseDisplay only. Fractions like 4.3 fill partially.
clearablebooleantrueClicking the current value clears it.
iconLucideIconStarAny lucide icon, like Heart.
labelsstring[]-One word per step, shown beside the icons.
sizenumber24Icon size in px.