tapcn
Components

Rating

An interactive star rating component.

Rating

An interactive star rating component that supports controlled values, multiple sizes, and a read-only display mode. Tapping a selected star toggles the rating back to zero.

Installation

npx @tapcn/cli add rating

Or using shadcn directly:

npx shadcn@latest add https://tapcn.vercel.app/r/rating.json

Usage

import { Rating } from '~/components/ui/rating';
import * as React from 'react';

export function RatingExample() {
  const [value, setValue] = React.useState(3);

  return (
    <Rating
      value={value}
      onValueChange={setValue}
      maxStars={5}
      size="default"
    />
  );
}

Props

PropTypeDefaultDescription
valuenumber0The current rating value.
onValueChange(value: number) => void-Callback fired when the rating changes.
maxStarsnumber5The total number of stars to display.
size'sm' | 'default' | 'lg''default'The size of the star icons (16px, 24px, or 32px).
readOnlybooleanfalseWhen true, the rating is display-only and cannot be changed.
classNamestring-Additional CSS classes for the container.

Dependencies

  • lucide-react-native

On this page