0.1.6 • Published 8 months ago

react-custom-rating-component v0.1.6

Weekly downloads
-
License
MIT
Repository
github
Last release
8 months ago

A fully customizable custom react rating component

Customizable react star ratings. It allows use of different precisions and supports custom icon like heart icon

npm install react-custom-rating-component

Or

yarn add react-custom-rating-component

Motivation

I wanted a star rating component that was highly customizable and could do half stars, and I wanted it to be declarative. I couldn't find one that I liked, so I made one.

Demo

Check out the playground with different use cases Play Ground

Take a look at react-custom-rating-component live example

Demo Example Image

npm.io

Usage

import { Rating } from 'react-custom-rating-component'

const App = () => {
  return (
    <div
      style={{
        display: 'flex',
        justifyContent: 'center',
        alignItems: 'center',
        margin: '40px 20px',
      }}
    >
      <Rating
        defaultValue={2.5}
        size='30px'
        spacing='10px'
        activeColor='red'
        onChange={(newRating) => console.log('newRating', newRating)}
        onHover={(hoveredRating) => console.log('hoveredRating', hoveredRating)}
      />
    </div>
  )
}

All Props

PropTypeDefaultDescription
defaultValuestring0Required. This is the value of the rating displayed by default. Supply this if your rating is also a readOnly
precisionnumber1The value to increment rating when hovered or clicked
countnumber5The number of Icons to display
shapestar or heartstarThis is the shape displayed as icon
onChangefunction-This is the function that is called when the rating value changes
onHoverfunction-This is the function that is called when the rating Icon is hovered
classNamestring''classes passed to the parent component
readOnlybooleanfalseThis sets the component to be non editable
sizestring24pxThis defines the size of the Icons used
spacingstring5pxThis defines the fap between the Icons used
activeColorstringorangeThis is the color of the icon in the active state
defaultColorstringgrayThis is the color of the icon in the inactive state
titleArraystring[]'Poor', 'Good', 'Very Good', 'Best', 'Excellent'These are displayed as titles when icons are hovered
showTitlebooleanfalseThis defines whether to display the titles or not

Browser Support

This library is supported by all the major browsers. If you find any issues please raise an issue on the repo and I will attend to it as soon as possible.

Contribute

If you have any ideas on how to make this library better, please feel free to contribute by raising a PR or an issue. I will be happy to review and merge.