Skip to content

Instantly share code, notes, and snippets.

View Jantho1990's full-sized avatar
💭
Game devvin'

Josh Anthony Jantho1990

💭
Game devvin'
View GitHub Profile
@Jantho1990
Jantho1990 / App.1d.js
Created June 12, 2018 03:32
StarRating React -- 1d
export default App
@Jantho1990
Jantho1990 / RatingInputs.8.jsx
Last active June 12, 2018 04:59
StarRating React -- 8
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
}
@Jantho1990
Jantho1990 / App.7.css
Created June 10, 2018 08:30
StarRating React -- 7
.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;
}
@Jantho1990
Jantho1990 / StarRating.6c.jsx
Created June 10, 2018 08:12
StarRating React -- 6c
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)) {
@Jantho1990
Jantho1990 / RatingInputs.6b.jsx
Created June 10, 2018 08:07
StarRating React -- 6b
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)
@Jantho1990
Jantho1990 / validate.6a.js
Created June 10, 2018 07:47
StarRating React -- 6a
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
}
@Jantho1990
Jantho1990 / App.5d.js
Created June 10, 2018 07:35
StarRating React -- 5d
// ...
class App extends Component {
constructor () {
super()
this.state = {
rating: 5,
minRating: 0,
maxRating: 10,
starRatio: 2,
@Jantho1990
Jantho1990 / RatingInputs.5c.jsx
Last active June 10, 2018 07:26
StarRating React -- 5c
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>
)
}
@Jantho1990
Jantho1990 / App.5b3.js
Created June 10, 2018 07:02
StarRating React -- 5b3
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.
@Jantho1990
Jantho1990 / App.5b2.js
Created June 10, 2018 06:53
StarRating React -- 5b2
handleStarRatingsUpdate(data) {
this.setState({
...this.state,
...data
})
}