diff options
author | Dan <danjm.com@gmail.com> | 2017-08-26 00:18:52 +0800 |
---|---|---|
committer | Dan <danjm.com@gmail.com> | 2017-08-26 03:34:23 +0800 |
commit | e56b8c5055a19ccfb88ef71f4cef13fb6d05a54a (patch) | |
tree | 11350939241b964775f5a1a46e08e171a303c3ab /ui/app/components/input-number.js | |
parent | 5677fdaf68ff28b9d9b4b27be1737101489f3861 (diff) | |
download | tangerine-wallet-browser-e56b8c5055a19ccfb88ef71f4cef13fb6d05a54a.tar.gz tangerine-wallet-browser-e56b8c5055a19ccfb88ef71f4cef13fb6d05a54a.tar.zst tangerine-wallet-browser-e56b8c5055a19ccfb88ef71f4cef13fb6d05a54a.zip |
Refactor tooltip to remove external lib; tooltip now updating gas fee in parent.
Diffstat (limited to 'ui/app/components/input-number.js')
-rw-r--r-- | ui/app/components/input-number.js | 57 |
1 files changed, 57 insertions, 0 deletions
diff --git a/ui/app/components/input-number.js b/ui/app/components/input-number.js new file mode 100644 index 000000000..5b4265459 --- /dev/null +++ b/ui/app/components/input-number.js @@ -0,0 +1,57 @@ +const Component = require('react').Component +const h = require('react-hyperscript') +const inherits = require('util').inherits +const findDOMNode = require('react-dom').findDOMNode + +module.exports = InputNumber + +inherits(InputNumber, Component) +function InputNumber () { + Component.call(this) + + this.state = { + value: 0, + } + + this.setValue = this.setValue.bind(this); +} + +InputNumber.prototype.componentWillMount == function () { + const { initValue = 0 } = this.props + + this.setState({ value: initValue }); +} + +InputNumber.prototype.setValue = function (newValue) { + const { fixed, min, onChange } = this.props + + if (fixed) newValue = Number(newValue.toFixed(4)) + + if (newValue >= min) { + this.setState({ value: newValue }) + onChange(newValue) + } +} + +InputNumber.prototype.render = function () { + const { unitLabel, step = 1, min, placeholder } = this.props + const { value } = this.state + + return h('div.customize-gas-input-wrapper', {}, [ + h('input.customize-gas-input', { + placeholder, + type: 'number', + value, + onChange: (e) => this.setValue(Number(e.target.value)) + }), + h('span.gas-tooltip-input-detail', {}, [unitLabel]), + h('div.gas-tooltip-input-arrows', {}, [ + h('i.fa.fa-angle-up', { + onClick: () => this.setValue(value + step) + }), + h('i.fa.fa-angle-down', { + onClick: () => this.setValue(value - step) + }), + ]), + ]) +} |