2017-08-25 18:18:52 +02:00
|
|
|
const Component = require('react').Component
|
|
|
|
const h = require('react-hyperscript')
|
|
|
|
const inherits = require('util').inherits
|
2017-10-13 22:19:22 +02:00
|
|
|
const { addCurrencies } = require('../conversion-util')
|
2017-08-25 18:18:52 +02:00
|
|
|
|
|
|
|
module.exports = InputNumber
|
|
|
|
|
|
|
|
inherits(InputNumber, Component)
|
|
|
|
function InputNumber () {
|
|
|
|
Component.call(this)
|
|
|
|
|
2017-08-29 16:50:48 +02:00
|
|
|
this.setValue = this.setValue.bind(this)
|
2017-08-25 18:18:52 +02:00
|
|
|
}
|
|
|
|
|
|
|
|
InputNumber.prototype.setValue = function (newValue) {
|
2017-10-13 22:19:22 +02:00
|
|
|
const { fixed, min = -1, max = Infinity, onChange } = this.props
|
2017-08-25 18:18:52 +02:00
|
|
|
|
2017-10-13 22:19:22 +02:00
|
|
|
newValue = Number(fixed ? newValue.toFixed(4) : newValue)
|
2017-08-25 18:18:52 +02:00
|
|
|
|
2017-10-13 22:19:22 +02:00
|
|
|
if (newValue >= min && newValue <= max) {
|
2017-08-25 18:18:52 +02:00
|
|
|
onChange(newValue)
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
InputNumber.prototype.render = function () {
|
2017-10-13 22:19:22 +02:00
|
|
|
const { unitLabel, step = 1, placeholder, value = 0 } = this.props
|
2017-08-29 16:50:48 +02:00
|
|
|
|
2017-08-25 18:18:52 +02:00
|
|
|
return h('div.customize-gas-input-wrapper', {}, [
|
|
|
|
h('input.customize-gas-input', {
|
|
|
|
placeholder,
|
|
|
|
type: 'number',
|
2017-10-13 22:19:22 +02:00
|
|
|
value: value,
|
|
|
|
onChange: (e) => this.setValue(e.target.value),
|
2017-08-25 18:18:52 +02:00
|
|
|
}),
|
|
|
|
h('span.gas-tooltip-input-detail', {}, [unitLabel]),
|
|
|
|
h('div.gas-tooltip-input-arrows', {}, [
|
|
|
|
h('i.fa.fa-angle-up', {
|
2017-10-13 22:19:22 +02:00
|
|
|
onClick: () => this.setValue(addCurrencies(value, step)),
|
2017-08-25 18:18:52 +02:00
|
|
|
}),
|
|
|
|
h('i.fa.fa-angle-down', {
|
2017-09-11 09:45:06 +02:00
|
|
|
style: { cursor: 'pointer' },
|
2017-10-13 22:19:22 +02:00
|
|
|
onClick: () => this.setValue(addCurrencies(value, step * -1)),
|
2017-08-25 18:18:52 +02:00
|
|
|
}),
|
|
|
|
]),
|
|
|
|
])
|
|
|
|
}
|