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
The current rating value.
The maximum rating value (number of stars).
Callback when rating changes (editable mode).
Whether the rating can be changed by clicking.
Whether to display the numeric rating value.
size
'xs' | 'sm' | 'md' | 'lg' | 'xl'
default:"'md'"
The size of the rating stars.
Additional CSS classes to apply to each star.
Additional CSS classes to apply to the container.
Examples
Read-Only Rating
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>
);
}