๐Ÿš€ Big News: Socket Acquires Coana to Bring Reachability Analysis to Every Appsec Team.Learn more โ†’
Socket
Sign inDemoInstall
Socket

reactjs-star-rating

Package Overview
Dependencies
Maintainers
1
Versions
5
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

reactjs-star-rating

This is a simple star rating component for ReactJS.

0.4.1
latest
Source
npm
Version published
Maintainers
1
Created
Source

React Star Rating Component

ReactJS Star Rating is a flexible and customizable star rating component that supports both full and half-star ratings. It comes with features like custom labels, read-only mode, hover effects, and custom styling, making it perfect for any React project.

Demo

GIF

Installation

Using npm:

npm install reactjs-star-rating

Using yarn:

yarn add reactjs-star-rating

Features

  • โญ Full and half-star ratings
  • ๐ŸŽจ Customizable colors and sizes
  • ๐Ÿท๏ธ Custom labels support
  • ๐Ÿ”’ Read-only mode
  • ๐Ÿ“ฑ Responsive design
  • ๐ŸŽฏ Callback functions
  • ๐Ÿ’… Custom styling support

Basic Usage

import StarRating from "reactjs-star-rating";

function App() {
  return <StarRating defaultRating={3} maxRating={5} />;
}

Props

PropTypeDefaultDescription
maxRatingnumber5Maximum rating value
colorstring"#fcc419"Color of the stars
sizenumber48Size of stars in pixels
classNamestring""Custom CSS class name
defaultRatingnumber0Initial rating value
readOnlybooleanfalseMakes the rating read-only
showLabelbooleantrueShows/hides the rating label
labelsstring[][]Custom labels for ratings
onSetRatingfunctionundefinedCallback when rating changes
allowHalfbooleanfalseEnables half-star ratings

Examples

Basic Star Rating

<StarRating defaultRating={3} maxRating={5} />

Half Star Rating

<StarRating
  allowHalf
  defaultRating={2.5}
  maxRating={5}
  color="purple"
  onSetRating={(rating) => console.log(rating)}
/>

Custom Labels

<StarRating
  maxRating={5}
  showLabel={true}
  labels={["Poor", "Fair", "Good", "Very Good", "Excellent"]}
  defaultRating={3}
  color="green"
/>

Read-only Rating

<StarRating defaultRating={4} maxRating={5} readOnly color="blue" />

With Callback Function

<StarRating
  maxRating={5}
  onSetRating={(rating) => {
    console.log(`Selected rating: ${rating}`);
  }}
/>

Custom Styling

<StarRating
  maxRating={5}
  className="custom-star-rating"
  size={32}
  color="#ff9800"
/>

Styling

You can customize the appearance using CSS by targeting the provided className:

.custom-star-rating {
  /* Your custom styles */
  background: #f5f5f5;
  padding: 10px;
  border-radius: 8px;
}

Contributing

Contributions are welcome! Please feel free to submit a Pull Request.

License

MIT ยฉ Varshil Shah

Made with โค by Varshil Shah from ๐Ÿ‡ฎ๐Ÿ‡ณ

Keywords

react

FAQs

Package last updated on 10 Nov 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts