Back to Reui

Rating

content/docs/components/base/rating.mdx

2.0.02.6 KB
Original Source
<ComponentPreview styleName="base-nova" name="c-rating-1" />

Installation

<CodeTabs> <TabsList> <TabsTrigger value="cli">CLI</TabsTrigger> <TabsTrigger value="manual">Manual</TabsTrigger> </TabsList> <TabsContent value="cli">
bash
npx shadcn@latest add @reui/rating
</TabsContent> <TabsContent value="manual"> <Steps>

<Step>Install the following dependencies:</Step>

bash
npm install @base-ui/react

<Step>Copy and paste the following code into your project.</Step>

<ComponentSource styleName="base-nova" name="rating" title="components/reui/rating.tsx" />

</Steps> </TabsContent> </CodeTabs>

Usage

tsx
import { Rating } from "@/components/reui/rating"
tsx
<Rating rating={4.5} showValue editable />

Examples

Decimal

<ComponentPreview styleName="base-nova" name="c-rating-2" />

Show Value

<ComponentPreview styleName="base-nova" name="c-rating-3" />

Editable

<ComponentPreview styleName="base-nova" name="c-rating-4" />

Size

<ComponentPreview styleName="base-nova" name="c-rating-5" />

API Reference

Rating

The main component for displaying and editing star ratings.

PropTypeDefaultDescription
ratingnumber-Required. The current rating value. Supports decimal values for partial stars.
maxRatingnumber5Total number of stars to display.
size"sm" | "default" | "lg""md"The size of the stars and spacing.
showValuebooleanfalseWhether to show the numeric rating value next to the stars.
editablebooleanfalseWhether the rating can be changed by clicking on stars.
onRatingChange(rating: number) => void-Callback fired when a star is clicked (if editable is true).
starClassNamestring-Additional CSS classes for the numeric value container.
classNamestring-Additional CSS classes for the root container.