Skip to main content

Installation

npm install @kuzenbo/core

Usage

import { Rating } from "@kuzenbo/core";
import { useState } from "react";

function Example() {
  const [rating, setRating] = useState(3.5);

  return (
    <Rating
      rating={rating}
      onRatingChange={setRating}
      editable
      showValue
    />
  );
}

Props

rating
number
required
The current rating value.
maxRating
number
default:"5"
The maximum rating value (number of stars).
onRatingChange
(rating: number) => void
Callback when rating changes (editable mode).
editable
boolean
default:"false"
Whether the rating can be changed by clicking.
showValue
boolean
default:"false"
Whether to display the numeric rating value.
size
'xs' | 'sm' | 'md' | 'lg' | 'xl'
default:"'md'"
The size of the rating stars.
starClassName
string
Additional CSS classes to apply to each star.
className
string
Additional CSS classes to apply to the container.

Examples

Read-Only Rating

<Rating rating={4} />

Editable Rating

const [rating, setRating] = useState(0);

<Rating
  rating={rating}
  onRatingChange={setRating}
  editable
/>

With Value Display

<Rating rating={4.5} showValue />

Custom Max Rating

<Rating rating={7} maxRating={10} showValue />

Different Sizes

<div className="space-y-4">
  <Rating rating={4} size="xs" />
  <Rating rating={4} size="sm" />
  <Rating rating={4} size="md" />
  <Rating rating={4} size="lg" />
  <Rating rating={4} size="xl" />
</div>

Half Star Ratings

<Rating rating={3.5} showValue />

Product Rating

function ProductRating() {
  return (
    <div className="flex items-center gap-2">
      <Rating rating={4.3} />
      <span className="text-sm text-muted-foreground">
        (128 reviews)
      </span>
    </div>
  );
}

Build docs developers (and LLMs) love