This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export default App |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
import inputIsValid from '../lib/validate' | |
export default class RatingInputs extends Component { | |
constructor(props) { | |
super() | |
this.handleRating = this.handleRating.bind(this) | |
this.state = { | |
...props | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
.App { | |
display: grid; | |
grid-template-columns: 1fr; | |
grid-auto-rows: 8em; | |
grid-template-areas: "title" "rating" "input"; | |
max-width: 100%; | |
margin: auto; | |
grid-gap: 1em; | |
text-align: center; | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from "react" | |
import FontAwesomeIcon from "@fortawesome/react-fontawesome" | |
import inputIsValid from '../lib/validate' | |
export default class StarRating extends Component { | |
// ... | |
componentWillMount() { | |
let { rating, minRating, maxRating, starRatio, limit } = this.props | |
if (!inputIsValid(rating, minRating, maxRating, starRatio, limit)) { |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import React, { Component } from 'react' | |
import inputIsValid from '../lib/validate' | |
export default class RatingInputs extends Component { | |
// ... | |
handleRating() { | |
let rating = Number(this.refs.rating.value) | |
let minRating = Number(this.refs.minRating.value) | |
let maxRating = Number(this.refs.maxRating.value) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
export let ratingIsValid = function(rating, minRating, maxRating) { | |
if (rating >= minRating && rating <= maxRating) return true | |
return false | |
} | |
export let valuesNotZeroOrLess = function(...values) { | |
let filteredValues = values.filter(value => value > 0) | |
return values.length === filteredValues.length | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// ... | |
class App extends Component { | |
constructor () { | |
super() | |
this.state = { | |
rating: 5, | |
minRating: 0, | |
maxRating: 10, | |
starRatio: 2, |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
render() { | |
let { rating, minRating, maxRating } = this.props | |
return ( | |
<div className="rating-inputs"> | |
<label htmlFor="rating">Rating</label> | |
<input type="number" ref="rating" name="rating" value={rating} min={minRating} max={maxRating} onChange={this.handleRating} /> | |
</div> | |
) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
render() { | |
let { rating } = this.state | |
return ( | |
<div className="App"> | |
<header className="App-header"> | |
<img src={logo} className="App-logo" alt="logo" /> | |
<h1 className="App-title">Welcome to React</h1> | |
</header> | |
<p className="App-intro"> | |
To get started, edit <code>src/App.js</code> and save to reload. |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
handleStarRatingsUpdate(data) { | |
this.setState({ | |
...this.state, | |
...data | |
}) | |
} |