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

star-rating-react-ts

v1.1.4

Published

A super simple, customizable star rating React component built with Typescript

Downloads

102

Readme

React Star Rating Component

A super simple, tiny, customizable star rating React component that installs no additional dependencies, has a total size of 11KB and has Typescript support.

Working examples can be found here Star Rating Examples

How to use

Requirements:

React >= 16.8.0

Install:

On the command line navigate to the project root and enter

npm install star-rating-react-ts

Import:

import {StarRating} from 'star-rating-react-ts'

JSX:

<YourComponent>
    <StarRating/>
</YourComponent>

Props

| prop name | type | default | optional | description | |---------------|-------------|-----------|----------|------------------------------------------------------------------------------------------| | numStars | number | 5 | true | number of stars to display | | initialRating | number | 0 | true | initial rating value | | readOnly | boolean | false | true | ignore user interaction | | theme | object | see below | true | styling options | | onClick | function | undefined | true | called when the user clicks a star, receives the new star rating as an argument (number) | | icon | JSX.Element | undefined | true | a custom SVG icon imported as a React Component |

Theming

Schema and default values for the theme prop object (all properties are optional):

{
    colors: {
        backgroundDefault: 'lightgray',
        backgroundColorActive: '#D8A127',
        backgroundColorHover: '#275ed8'
        }
    },
    size: 50
}

Custom Icons

By default the star rating component displays a star icon SVG. To use a custom icon in the star rating:

  1. The SVG needs to be imported as a React Component. The easiest option is to use SVGR. Create React App includes SVGR under the hood. Vite publishes a simple SVGR plugin that can be installed in your project. In the following example it is assumed that the SVG icon file is in an assets folder in the src folder within the project root:

App.tsx

// Using Create React App
import { ReactComponent as BoneIcon } from './assets/bone.svg';

// Using the SVGR plugin for Vite
import BoneIcon from "./assets/bone.svg?react";

function App () {
    ...
    return <StarRating icon={<BoneIcon/>}/> // <-- pass custom icon as a component!
}
  1. In the SVG image file, add the following fill & width attributes to the opening <svg> tag to ensure the theme colors and size props are inherited.

bone.svg

<svg xmlns="http://www.w3.org/2000/svg"
     fill="currentColor"
     width="100%"
...
</svg>

Accessibility

In addition to standard mouse and touch events this component is designed to be compatible with assistive technology (ie screen readers) and keyboard navigation. We use Axe Dev Tools to test for accessibility.