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-star-rate

v0.2.0

Published

Lightweight, customizable star ratings component for React

Downloads

3,616

Readme

Features

  • 🔩 Easily Customizable
  • 🕊 Lightweight - less than 4kb including styles
  • Accessible

Table of contents

Example

You can visit the example here: View on CodeSandbox

Installation

With yarn

yarn add react-star-rate

With NPM

npm install react-star-rate

Getting Started

You can add React Stars Rating to your project using the <StarsRating /> component.

import { useState } from 'react';

import StarsRating from 'react-star-rate';

const App = () => {
  const [value, setValue] = useState(0);
  return (
    <div>
      <StarsRating
        value={value}
        onChange={value => {
          setValue(value);
        }}
      />
    </div>
  );
};

Props

| Name | Type | Default | Description | | ----------------- | -------- | ------------------- | ---------------------------------------------------------------------------------- | | allowClear | boolean | true | Allow the value to be reset when clicked again | | allowHalf | boolean | true | Allow half of the star to be selected | | autoFocus | boolean | - | Automatically focus the element | | classNamePrefix | string | "react-star-rate" | The components will have classNames with the given prefix | | count | number | 5 | Number of stars | | defaultValue | number | 0 | The default value of the stars. Should be the same as the default useState value | | direction | string | "ltr" | The direction of the selected stars. Either "ltr" or "rtl" | | disabled | boolean | false | Disable the rating element | | onBlur | function | - | Will be triggered on blur | | onChange | function | (value) => {} | Will be triggered on change of value | | onFocus | function | - | Will be triggered on focus | | onHoverChange | function | (value) => {} | Will be triggered on hover | | style | object | {} | Custom styles. See styling | | symbol | string | "★" | The symbol to be displayed | | tabIndex | number | 0 | The tab index of the stars container | | value | number | - | Controlled value of the component |

Styling

Style Object

Each component inside the StarsRating component is keyed and ships with default styles. You can apply custom styles by accessing the key on the style prop.

Style Keys

  • style.style - The main wrapper ul element.
  • style.full - Styles for when the star is fully active.
    • style.full.star - The wrapper li element every star.
    • style.full.first - The first half star, on top.
    • style.full.second - The second full star, in the background.
  • style.half - Styles for when the star is half active.
    • style.half.star - The wrapper li element every star.
    • style.half.first - The first half star, on top.
    • style.half.second - The second full star, in the background.
  • style.zero - Styles for when the star is not active.
    • style.zero.star - The wrapper li element every star.
    • style.zero.first - The first half star, on top.
    • style.zero.second - The second full star, in the background.
  • style.hover - Styles for when the element is hovered over. You can use access of the keys listed above in the hover object.

With CSS

You can also apply custom styles using CSS Stylesheets. The classnames are determined with the classNamePrefix prop (defaults to "react-star-rate").

Classnames

  • ${classNamePrefix} - The main ul element.
  • ${classNamePrefix}--ltr | - ${classNamePrefix}--rtl - If the rating component is from left-to-right or right-to-left respectively.
  • ${classNamePrefix}__star - The star li element.
  • ${classNamePrefix}__star--zero | ${classNamePrefix}__star--half | ${classNamePrefix}__star--full - When the star is inactive, half, or completely full.
  • ${classNamePrefix}__star__first - The first half star, on top.
  • ${classNamePrefix}__star__second - The second full star, in the background.

License

MIT Licensed. Copyright (c) 2021-present, Raymon Zhang.