Rating Component
Star rating component for displaying and collecting user ratings. Supports full stars, half stars, and interactive mode.
Display Mode
Non-interactive ratings for displaying existing ratings.
Full Stars
0 stars:
1 star:
2 stars:
3 stars:
4 stars:
5 stars:
Half Stars
0.5 stars:
1.5 stars:
2.5 stars:
3.5 stars:
4.5 stars:
Sizes
Three size variants: small, medium (default), and large.
Small:
Medium:
Large:
Interactive Mode
Allow users to select a rating by clicking on stars. Hover to preview.
Click to Rate
Your rating:Not rated
Click on a star to set your rating
Pre-filled:3 / 5
Starts with a default value
With half stars:4.5 / 5
Supports half-star ratings
Different Sizes
Small:
Medium:
Large:
Usage Example
Example code for implementing Rating component
import { Rating } from '@monorepo/ui/DesignSystem';
import { useState } from 'react';
// Display rating
<Rating value={4.5} />
// Interactive rating
const [rating, setRating] = useState(0);
<Rating
value={rating}
interactive
onChange={(value) => setRating(value)}
/>
// Custom size
<Rating value={3} size="lg" />
// Without half stars
<Rating value={4} showHalfStars={false} />
// Custom max stars
<Rating value={7} max={10} />Props
| Prop | Type | Default | Description |
|---|---|---|---|
| value | number | 0 | Current rating value (0 to max) |
| max | number | 5 | Maximum rating value |
| size | 'sm' | 'md' | 'lg' | 'md' | Size of stars |
| interactive | boolean | false | Whether the rating is interactive |
| onChange | (value: number) => void | - | Callback when rating changes (interactive mode only) |
| showHalfStars | boolean | true | Whether to show half stars |
Design Specifications
- Star Size:
- • Small: 16x16px
- • Medium: 24x24px (default, from Figma)
- • Large: 32x32px
- Gap Between Stars:
- • Small: 6px
- • Medium: 8px (close to 9px from Figma)
- • Large: 10px
- Colors (from Figma):
- • Filled: #F2E127 (yellow-600)
- • Empty: #E9EBED (gray-200)
- • Stroke Width: 1.5px
- States:
- • Empty: Stroke only, no fill
- • Half: 50% filled (left half)
- • Filled: Full fill with stroke
- Interactive Mode:
- • Hover effect shows preview
- • Click to set rating
- • Keyboard accessible