Important: This documentation covers Yarn 1 (Classic).
For Yarn 2+ docs and migration guide, see yarnpkg.com.

Package detail

react-simple-star-rating

awran5132.8kMIT5.1.7TypeScript support: included

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

react, star rating, react component, react rating

readme

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

Prop Type Options Description Default
onClick function Optional callback with hover, index and event values passed -
onPointerMove function Optional callback with hover, index and event values passed -
onPointerEnter function Optional callback with event passed -
onPointerLeave function Optional callback with event passed -
initialValue number Optional Set initial value 0
iconsCount number Optional Number of the icons 5
readonly boolean Optional Readonly mode false
rtl boolean Optional RTL mode false
transition boolean Optional Adds a smooth transition effect on mouse hover false
allowFraction boolean Optional Enable a fractional icon (half icon) false
className string Optional Applied to the main span react-simple-star-rating
style CSSProperties Optional Inline style applied to the main span basic style
size number Optional SVG Icon width / height in px 25
SVGstrokeColor string Optional SVG Icon stroke color currentColor
SVGstorkeWidth string | number Optional SVG Icon storke width 0
SVGclassName string Optional SVG Icon css class star-svg
SVGstyle CSSProperties Optional SVG inline style -
fillIcon ReactNode Optional Custom fill icon SVG null
fillColor string Optional Fill icons color #f1a545
fillColorArray array Optional Array of string to add color range []
fillStyle CSSProperties Optional Inline style applied to filled icon span basic style
fillClassName string Optional Applied to the filled icon span filled-icons
emptyIcon ReactNode Optional Custom empty icon SVG null
emptyColor string Optional Empty icons color #cccccc
emptyStyle CSSProperties Optional Inline style applied to empty icon span basic style
emptyClassName string Optional Applied to the empty icon span empty-icons
customIcons array of object Optional Add a group of icons []
allowHover boolean Optional Enable / Disable hover effect true
disableFillHover boolean Optional Enable / Disable hover effect on filled stars false
showTooltip string Optional Show a tooltip with live values false
tooltipDefaultText string Optional Initial tooltip text if no rating value Your Rate
tooltipArray array Optional Array of strings to show inside tooltip []
tooltipClassName string Optional Tooltip CSS class rating-tooltip
tooltipStyle CSSProperties Optional Inline style applied to the tooltip span basic style
titleSeparator string Optional Separator word in a title of a rating star (1 out of 5) out of


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

old new changes
allowHalfIcon allowFraction Renamed
fullIcon fillIcon Renamed
fullStyle fillStyle Renamed
fullClassName fillClassName Renamed
ratingValue - Removed

Demos

See all demos and usage examples in action.


Edit react-simple-rating-ts

License

MIT © awran5

changelog

Changelog

All notable changes to this project will be documented in this file.

The format is based on Keep a Changelog and this project adheres to Semantic Versioning.

Generated by auto-changelog.

v5.1.7

v5.1.7 - 2022-11-22

Commits

  • fix: incorrent value when use even icons #32
  • feat: new allowTitleTag prop to disable HTML title tag
  • build: safe upgrade de3584d
  • build: remove deprecated standard-version 1b108bf
  • docs: add preset-create-react-app 3c108ec

v5.1.6 - 2022-10-28

Commits

  • chore(release): 5.1.6 c763647
  • docs: correct spelling of CHANGELOG fbe5fcc

v5.1.5 - 2022-10-28

Commits

v5.1.4 - 2022-10-28

Commits

v5.1.3 - 2022-10-11

Fixed

  • fix: window is not defined error while using Next.js #28

Commits

  • build: update dependencies 861a357
  • chore(release): 5.1.3 4c34a26
  • fix: window is undefined" and "navigator is undefined" when using in Next.js abb3c5b

v5.1.2 - 2022-10-07

Commits

v5.1.1 - 2022-10-07

Merged

  • resolve next js window and navigator undefined issue #27

v5.1.0 - 2022-10-03

Commits

v5.0.0 - 2022-10-03

Commits

v4.1.1 - 2022-10-03

Commits

v4.1.0 - 2022-10-03

Merged

  • feat: add allowHoverOnDefault prop & update docs #19
  • fix: issue #10 #16
  • fix: adds default styling for starsvg #14
  • Export Types Again (This was removed in V4) #8

Commits

v4.0.5 - 2021-12-13

Commits

v4.0.4 - 2021-12-13

Commits

v4.0.3 - 2021-12-11

Commits

v4.0.2 - 2021-12-10

Fixed

  • fix: fix #6 not working on mobile browsers #6 #6

Commits

  • switch to standard-version 1114086
  • fix(responsive issue): add missing CSS to fix responsive 5e20f1e
  • docs: log changes 2d1d6e1

v4.0.0 - 2021-11-28

Commits

v3.0.0 - 2021-07-06

Commits

v2.1.0 - 2021-07-06

Commits

  • feat: moved to semantic-release 8ff381d
  • fix(github action setup): edit release.yml to setup github action ea0e87d
  • edit readme dcb75a6

v2.0.0 - 2021-07-05

Merged

  • Version Packages #4

Commits