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

rating-star

v1.1.0

Published

React rating star merely using SVG + CSS

Downloads

1,107

Readme

React Rating Star

Rating Star UI Component powered by ReactJS

npm

Installation

npm i rating-star
yarn add rating-star

Prerequisite

The version of React has to be 16.8.0 or above.

How To Use

Javascript / Typescript

import { RatingStar } from "rating-star";

export default function App() {
  const [rating, setRating] = React.useState(30);

  const onRatingChange = (score) => {
    setRating(score);
  };

  return (
    <div className="App">
      <h1>Rating Star</h1>
      <RatingStar
        clickable
        maxScore={100}
        id="123"
        rating={rating}
        onRatingChange={onRatingChange}
      />
    </div>
  );
}

For more details, can go to Demos.

Props

| Name | Description | | --------------------------- | ---------------------------------------------------- | | id | the element id | | clickable (optional) | enable click for the ratings, default is false | | noBorder (optional) | disable borders of the star icon, default is false | | size (optional) | icon size, default is 24 | | maxScore (optional) | the maximum score of the ratings, default is 5 | | rating (optional) | the current score, default is 0 | | numberOfStar (optional) | total number of star icons, default is 5 | | colors (optional) | colours of the star icon | | onRatingChange (optional) | a callback of rating changes |

Prop Types

interface ColourTheme {
  stroke: string;
  mask: string;
  rear: string;
}

interface RatingStarProps {
  id: string;
  clickable?: boolean;
  noBorder?: boolean;
  size?: number;
  maxScore?: number;
  rating?: number;
  numberOfStar?: number;
  colors?: Partial<ColourTheme>;
  onRatingChange?: (rating: number) => void;
}

Customise the Star Icon

You can customise the star icon with your needs.

Example:

import AcUnitIcon from "@material-ui/icons/AcUnit";
import { RatingStar } from "rating-star";

function App() {
  return (
    <RatingStar
      id="custom-icon-wow"
      rating={3}
      starIcon={AcUnitIcon}
      colors={{ mask: "#43a7e3" }}
      noBorder
    />
  );
}

Caveat

  • The custom icon must be a SVG React component which contains only one child element.

    The child element can be one of:

    • path
    • polygon
    • circle
    • rect
    • image

    e.g.

    function CustomIcon() {
      return (
        <svg>
          <path d="..." />
        </svg>
      );
    }

Customise the Styles

You can customise the styles of the rating-star container by CSS class name, "rating-star",

or use the id you have assigned to the rating-star component.

Use with Styled Components

For styled-components lover, you can modify the styles with the power of the styled-components.

import styled from "styled-components";

import { RatingStarContainer, RatingStarIconsWrapper } from "rating-star";

const YourStyledComponent = styled.div`
  ${RatingStarContainer} {
    margin: 10px 0;
  }
  ${RatingStarIconsWrapper} {
    > svg {
      margin: 3px 0;
    }
  }
`;

Demos