Giter VIP home page Giter VIP logo

react-material-ui-rating's People

Contributors

lawrentiy avatar tylerbuchea avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar

react-material-ui-rating's Issues

Call stack exceeded. Better way to import the star SVGs

@lawrentiy thanks so much for making this module! Came across a nasty bug when building this with Cordova for iOS that took a long time to hunt down and solve, thought I'd share the findings

The error was that the the maximum call stack size is exceeded, but only on iOS 10 devices.

Turns out, it was import {ToggleStarBorder, ToggleStar} from 'material-ui/svg-icons';

I switched to a different way of importing, and it works again:

import Star from 'material-ui/svg-icons/toggle/star'
import StarBorder from 'material-ui/svg-icons/toggle/star-border'

Full code (modified + streamlined):

import * as React from 'react'
import FlatButton from 'material-ui/FlatButton'
import {colors} from 'material-ui/styles'
import Star from 'material-ui/svg-icons/toggle/star'
import StarBorder from 'material-ui/svg-icons/toggle/star-border'

export interface StarRatingProps {
  hintText?: boolean;
  onChange: (rating: number) => any;
  readOnly?: boolean;
  style?: any;
  value?: number;
}

export default class StarRating extends React.Component<StarRatingProps, {}> {
  render() {
    const ratings = [null, 'Hated it', 'Disliked it', 'It\'s OK', 'Liked it', 'Loved it'];
    const stars = [1,2,3,4,5].map((i: number): JSX.Element => {
      const onClick = this.props.readOnly ? undefined : this.props.onChange.bind(this, i);
      const checked = (i <= this.props.value);
      let classes = 'star';
      if (!this.props.readOnly) classes += ' editable';
      if (checked) { classes += ' filled'; }
      else { classes += ' outline'; }

      return <div className={classes}>
        <FlatButton key={i} onTouchTap={() => { this.props.onChange(i) }}>
          {checked && <Star  color={colors.grey900} />}
          {!checked && <StarBorder color={colors.grey600} />}
        </FlatButton>
      </div>;
    });
    return (<div className="starContainer" style={this.props.style}>
      {stars}
      {this.props.hintText && <div className="hint">{ratings[this.props.value]}</div>}
    </div>);
  }
}

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.