lawrentiy / react-material-ui-rating Goto Github PK
View Code? Open in Web Editor NEWRating component for react material-ui package
Rating component for react material-ui package
@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>);
}
}
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.