StarForge
Display

Stars Rating

Interactive star rating components for user feedback and evaluation

Note

All presented components are responsive and compatible with Tailwind CSS. Make sure Tailwind is configured in your project to use them.

Stars Rating 1

Stars Rating 2

Props Reference

PropTypeDefaultDescription
ratingnumber0Current rating value (0 to maxRating)
maxRatingnumber5Maximum number of stars
size'sm' | 'md' | 'lg''md'Size of the stars
readonlybooleanfalseWhether the rating is interactive
onChange(rating: number) => voidundefinedCallback when rating changes
classNamestringundefinedAdditional CSS classes
showValuebooleantrue (Stars Rating 2 only)Whether to display numeric value

Usage Examples

Basic Interactive Rating

import { useState } from 'react';
import StarsRating1 from '@/components/star-forge/others/stars-rating-1';

export default function Example() {
  const [rating, setRating] = useState(3);

  return (
    <StarsRating1
      rating={rating}
      onChange={setRating}
      size="md"
    />
  );
}

Read-only Display

import StarsRating2 from '@/components/star-forge/others/stars-rating-2';

export default function Example() {
  return (
    <StarsRating2
      rating={4.5}
      readonly
      size="lg"
      showValue
    />
  );
}

Custom Styling

import StarsRating1 from '@/components/star-forge/others/stars-rating-1';

export default function Example() {
  return (
    <StarsRating1
      rating={2.5}
      onChange={(rating) => console.log('New rating:', rating)}
      size="sm"
      className="my-custom-class"
    />
  );
}

Features

  • Interactive Mode: Click to set rating, hover for preview
  • Read-only Mode: Display rating without interaction
  • Multiple Sizes: Small, medium, and large star sizes
  • Smooth Animations: Hover effects and transitions
  • Accessibility: Proper focus management and keyboard support
  • TypeScript: Full type safety with IntelliSense support
  • Customizable: Additional CSS classes and callbacks