npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

react-simple-star-rating

v5.1.7

Published

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

Downloads

129,507

Readme

React Simple Rating

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

NPM JavaScript Style Guidenpm bundle sizeGitHub

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