Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

react-ratings-declarative

Package Overview
Dependencies
Maintainers
1
Versions
14
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

react-ratings-declarative

A customizable rating component for selecting x widgets or visualizing x widgets

  • 3.4.1
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
2.8K
decreased by-1.33%
Maintainers
1
Weekly downloads
 
Created
Source

React Ratings Declarative

A customizable rating component for selecting x widgets or visualizing x widgets. SVG stars that show aggregate star ratings to the hundreths decimal point.

Install

npm install --save react-ratings-declarative

Demo

codepen playground

Demo Example Image

Usage

import Ratings from 'react-ratings-declarative';

class Foo extends Component {
    changeRating( newRating ) {
      this.setState({
        rating: newRating
      });
    }

    render() {
      return (
          <Ratings
            rating={this.state.rating}
            widgetRatedColors="blue"
            changeRating={this.changeRating}
          >
            <Ratings.Widget />
            <Ratings.Widget />
            <Ratings.Widget
              widgetDimension="60px"
              svgIconViewBox="0 0 5 5"
              svgIconPath="M2 1 h1 v1 h1 v1 h-1 v1 h-1 v-1 h-1 v-1 h1 z"
            />
            <Ratings.Widget widgetHoverColor="black" />
            <Ratings.Widget />
          </Ratings>
      );
    }
}


class Bar extends Component {
  render() {
    return (
      <Ratings
        rating={3.403}
        widgetDimensions="40px"
        widgetSpacings="15px"
      >
        <Ratings.Widget widgetRatedColor="green" />
        <Ratings.Widget widgetSpacing="30px" widgetDimension="15px" />
        <Ratings.Widget widgetRatedColor="black" />
        <Ratings.Widget widgetRatedColor="rebeccapurple" />
        <Ratings.Widget />
      </Ratings>
    );
  }
}

API

Ratings

PropTypeDefaultDescriptionExample
ratingnumber0The user's rating. Number of widgets to highlight.3
typeOfWidgetstring'Star'The type of widget used as a rating meterPoint
changeRatingfunction()=>{}Callback that will be passed the new rating a user selectsconst setNewRating = (rating) => this.props.dispatch( fooActions.setRating(rating) )
gradientPathNamestring''gradientPathname needed if app's path is not at the root/app/
ignoreInlineStylesbooleanfalseignore all the inline styles and write your own css using the provided classestrue
svgIconPathsstring'm25,1 6,17h18l-14,11 5,17-15-10-15,10 5-17-14-11h18z'Set a path that describes the svg shape for all the children'm25,1 6,17h18l-14,11 5,17-15-10-15,10 5-17-14-11h18z'
svgIconViewBoxesstring'0 0 51 48'Set the view box for a custom svg path you might have for all the children'0 0 51 48'
svgsnodenoneUse a custom svg or react element for all the children<svg><circle /></svg>
widgetRatedColorsstring'rgb(109, 122, 130)'Color of widgets that the user has rated, applied to all the childrenblack
widgetEmptyColorsstring'rgb(203, 211, 227)'Color of widgets that the use hasn't rated, applied to all the childrengrey
widgetHoverColorsstring'rgb(230, 67, 47)'Color of widget when hovering over it in selection mode, applied to all the childrenyellow
widgetDimensionsstring'50px'The width and height of the star, applied to all the children15px
widgetSpacingsstring'7px'The spacing between the widgets, applied to all the children0

Widget

PropTypeDefaultDescriptionExample
svgIconPathstring'm25,1 6,17h18l-14,11 5,17-15-10-15,10 5-17-14-11h18z'Set a path that describes the svg shape'm25,1 6,17h18l-14,11 5,17-15-10-15,10 5-17-14-11h18z'
svgIconViewBoxstring'0 0 51 48'Set the view box for a custom svg path you might have'0 0 51 48'
svgnodenoneUse a custom svg or react element<svg><circle /></svg>
widgetRatedColorstring'rgb(109, 122, 130)'Color of widgets that the user has ratedblack
widgetEmptyColorstring'rgb(203, 211, 227)'Color of widgets that the use hasn't ratedgrey
widgetHoverColorstring'rgb(230, 67, 47)'Color of star when hovering over it in selection modeyellow
widgetDimensionstring'50px'The width and height of the widget15px
widgetSpacingstring'7px'The spacing between the widgets0

Browser Support

Supports Chrome, safari, firefox, edge, and ie 9+. The widget is SVG, so this library fails for any browser that doesn't support svg.

Potential Gradient Path Name Issue

I use the css property fill: 'url(#starGrad<randomNum>)'; to fill in just a percentage of a star. It has some weird bugs depending on the pathname of the app. Normally SPA's have window.location.pathname === '/', but if you append window.location.origin with the pathname of say app, so that window.location.pathname === '/app/', then you need a gradientPathName of '/app/'.

Here is a stackoverflow post that I found that was related to this issue: http://stackoverflow.com/questions/36774188/svg-internal-url-links-and-iframes-on-wirecloud

Contribute

If you want to contribute: Make changes in the src folder. And then run make build. The make build command compiles react and es6 stuff using babel from src/ into build/.

Keywords

FAQs

Package last updated on 03 Mar 2018

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc