Socket
Socket
Sign inDemoInstall

react-simple-star-rating

Package Overview
Dependencies
5
Maintainers
1
Versions
22
Alerts
File Explorer

Advanced tools

Install Socket

Detect and block malicious and high-risk dependencies

Install

    react-simple-star-rating

A simple react component for adding a star rating to your project.


Version published
Weekly downloads
31K
decreased by-5.59%
Maintainers
1
Install size
43.8 kB
Created
Weekly downloads
 

Readme

Source

React Simple Rating

A simple react component for adding a star rating to your project.

NPM JavaScript Style Guidenpm bundle sizeGitHub

screenshot

Install

npm
npm i react-simple-star-rating
Yarn
yarn add react-simple-star-rating

Usage

import React, { useState } from 'react'
import { Rating } from 'react-simple-star-rating'

export function MyComponent() {
  const [rating, setRating] = useState(0)

  // Catch Rating value
  const handleRating = (rate: number) => {
    setRating(rate)

    // other logic
  }
  // Optinal callback functions
  const onPointerEnter = () => console.log('Enter')
  const onPointerLeave = () => console.log('Leave')
  const onPointerMove = (value: number, index: number) => console.log(value, index)

  return (
    <div className='App'>
      <Rating
        onClick={handleRating}
        onPointerEnter={onPointerEnter}
        onPointerLeave={onPointerLeave}
        onPointerMove={onPointerMove}
        /* Available Props */
      />
    </div>
  )
}

Reset Rating Value

import React, { useState } from 'react'
import { Rating } from 'react-simple-star-rating'

export function MyComponent() {
  const [rating, setRating] = useState(0)

  // Catch Rating value
  const handleRating = (rate: number) => {
    setRating(rate)
  }

  const handleReset = () => {
    // Set the initial value
    setRating(0)
  }

  return (
    <div className='App'>
      {/* set initial value */}
      <Rating onClick={handleRating} initialValue={rating} />

      <button onClick={handleReset}>reset</button>
    </div>
  )
}

Available Props

PropTypeOptionsDescriptionDefault
onClickfunctionOptionalcallback with hover, index and event values passed-
onPointerMovefunctionOptionalcallback with hover, index and event values passed-
onPointerEnterfunctionOptionalcallback with event passed-
onPointerLeavefunctionOptionalcallback with event passed-
initialValuenumberOptionalSet initial value0
iconsCountnumberOptionalNumber of the icons5
readonlybooleanOptionalReadonly modefalse
rtlbooleanOptionalRTL modefalse
transitionbooleanOptionalAdds a smooth transition effect on mouse hoverfalse
allowFractionbooleanOptionalEnable a fractional icon (half icon)false
classNamestringOptionalApplied to the main spanreact-simple-star-rating
styleCSSPropertiesOptionalInline style applied to the main spanbasic style
sizenumberOptionalSVG Icon width / height in px25
SVGstrokeColorstringOptionalSVG Icon stroke colorcurrentColor
SVGstorkeWidthstring | numberOptionalSVG Icon storke width0
SVGclassNamestringOptionalSVG Icon css classstar-svg
SVGstyleCSSPropertiesOptionalSVG inline style-
fillIconReactNodeOptionalCustom fill icon SVGnull
fillColorstringOptionalFill icons color#f1a545
fillColorArrayarrayOptionalArray of string to add color range[]
fillStyleCSSPropertiesOptionalInline style applied to filled icon spanbasic style
fillClassNamestringOptionalApplied to the filled icon spanfilled-icons
emptyIconReactNodeOptionalCustom empty icon SVGnull
emptyColorstringOptionalEmpty icons color#cccccc
emptyStyleCSSPropertiesOptionalInline style applied to empty icon spanbasic style
emptyClassNamestringOptionalApplied to the empty icon spanempty-icons
customIconsarray of objectOptionalAdd a group of icons[]
allowHoverbooleanOptionalEnable / Disable hover effecttrue
disableFillHoverbooleanOptionalEnable / Disable hover effect on filled starsfalse
showTooltipstringOptionalShow a tooltip with live valuesfalse
tooltipDefaultTextstringOptionalInitial tooltip text if no rating valueYour Rate
tooltipArrayarrayOptionalArray of strings to show inside tooltip[]
tooltipClassNamestringOptionalTooltip CSS classrating-tooltip
tooltipStyleCSSPropertiesOptionalInline style applied to the tooltip spanbasic style
titleSeparatorstringOptionalSeparator word in a title of a rating star (1 out of 5)out of


BREAKING CHANGES: version 4.1.0 (2022-10-03)

oldnewchanges
allowHalfIconallowFractionRenamed
fullIconfillIconRenamed
fullStylefillStyleRenamed
fullClassNamefillClassNameRenamed
ratingValue-Removed

Demos

See all demos and usage examples in action.


Edit react-simple-rating-ts

License

MIT © awran5

Keywords

FAQs

Last updated on 22 Nov 2022

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