Socket
Socket
Sign inDemoInstall

react-custom-rating-component

Package Overview
Dependencies
3
Maintainers
1
Versions
7
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-custom-rating-component

A fully customizable rating component for react and next.js


Version published
Maintainers
1
Created

Readme

Source

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 --save react-custom-rating-component

Or

yarn add -D 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

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

Demo Example Image

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. It uses SVG and CSS3 to render the icons and hence the browser support is the same as that of SVG and CSS3.

Try Example And Contribute

Clone the repo and run yarn install and then yarn run start to run the example. Run yarn run test to run the tests and ensure that everything is working as expected before submitting a PR.

If you want to contribute: Make changes in the src folder. And then run yarn run build. And of course test by running yarn run test. Then submit a PR.

Keywords

FAQs

Last updated on 14 Aug 2023

Did you know?

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

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc