1.0.7 • Published 2 years ago

react-star-rating-element v1.0.7

Weekly downloads
-
License
BSD-3-Clause
Repository
github
Last release
2 years ago

React Star Rating Element

Customizable react star ratings. SVG stars that show aggregate star ratings to the hundreths decimal point.

Install

npm install --save react-star-rating-element

Demo Example Image

npm.io

Usage

import { StarRating } from 'react-star-rating-element';

function App() {
  const [rating, setRating] = useState(0);

  return (
    <div className="App">
      <div className="Wrapper">
        <StarRating
          ratingValue={rating}
          changeRating={setRating}
          starEmptyColor="#999999"
          starSpacing={10}
          starDimension={30}
        />
        <p className="Indicator">
          The rating is <span>{rating}</span>
        </p>
      </div>
    </div>
  );
}

export default App;

API

PropTypeDefaultDescriptionExample
ratingstring''Component's unique identification. Can be used when more than one star rating components are used'rating'
ratingValuenumber0The user's rating. Number of stars to highlight.3
changeRatingfunction()=>{}Callback that will be passed the new rating a user selects
numberOfStarsnumber5The max number of stars to choose from or to display6
starRatedColorstring'#ff8039'Color of stars that the user has ratedblack
starEmptyColorstring'#999999'Color of stars that the use hasn't ratedgrey
starDimensionnumber'13'The width and height of the star15 x 15
starSpacingnumber'2'The spacing between the stars10 :star: 10 :star:
svgIconPathstring'M6.5 1.61803L7.48381 4.6459L7.59607 4.99139H7.95934H11.143L8.56737 6.86271L8.27348 7.07624L8.38573 7.42173L9.36955 10.4496L6.79389 8.57827L6.5 8.36475L6.20611 8.57827L3.63045 10.4496L4.61426 7.42173L4.72652 7.07624L4.43263 6.86271L1.85697 4.99139H5.04066H5.40393L5.51619 4.6459L6.5 1.61803Z'Set a path that describes the svg shape'M6.5 1.61803L7.48381 4.6459L7.59607 4.99139H7.95934H11.143L8.56737 6.86271L8.27348 7.07624L8.38573 7.42173L9.36955 10.4496L6.79389 8.57827L6.5 8.36475L6.20611 8.57827L3.63045 10.4496L4.61426 7.42173L4.72652 7.07624L4.43263 6.86271L1.85697 4.99139H5.04066H5.40393L5.51619 4.6459L6.5 1.61803Z'

Browser Support

Supports Chrome, firefox, safari, edge, and ie 9+. The star is SVG, so this library fails for any browser that doesn't support svg.