-
Notifications
You must be signed in to change notification settings - Fork 2
CSS Value
brandonk1234 edited this page Dec 5, 2016
·
5 revisions
The CSS Value component consists of 2 button elements, one that increases the value and one that decreases the value. This component also gives you the option to choose the unit you want to work in... just pass in the desired unit as a prop. An example of this component in good use would be if you had were building out an editor app, you could use the cssValue to increment and decrement things like height, width, border width etc etc.
The props needed for this component are listed and explained below:
-
unit
- This prop must be astring
. Pass in your desired unit here, here a few you could use pt, px, vh or vw. -
value
- This prop must be anumber
. -
onChange
- This prop must be afunction
. -
onIncrease
- This prop must be afunction
. -
onDecrease
- This prop must be afunction
. -
isSmall
- This prop must be aboolean
. Use this to have a smaller version of the component
<CssValue
unit={this.state.unit}
value={this.state.width}
onChange={this.onWidthChanged}
onIncrease={this.onWidthIncrease}
onDecrease={this.onWidthDecrease}
/>
// ...React Component
getInitialState: function() {
return {
unit: "px",
width: "100"
}
},
onWidthChanged: function(value) {
this.setState({
width: value
})
}
onWidthIncrease: function(increaseBy) {
this.setState({
width: this.state.width + (1 * increaseBy)
})
},
onWidthDecrease: function(decreaseBy) {
this.setState({
width: this.state.width - (1 * decreaseBy)
})
},