diff options
author | fragosti <francesco.agosti93@gmail.com> | 2018-10-27 02:41:09 +0800 |
---|---|---|
committer | fragosti <francesco.agosti93@gmail.com> | 2018-10-27 02:41:09 +0800 |
commit | a414dc9b83c14b277af90ce8397db3736a51a4d3 (patch) | |
tree | e9814de850892932b539c88e1798d44b00db563a /packages/instant/src/components/scaling_amount_input.tsx | |
parent | 951a5271e15cebb010281de3b8cbfb3972ecec83 (diff) | |
parent | 0f6307169604f36b0316f236eb96d6001b788f50 (diff) | |
download | dexon-0x-contracts-a414dc9b83c14b277af90ce8397db3736a51a4d3.tar dexon-0x-contracts-a414dc9b83c14b277af90ce8397db3736a51a4d3.tar.gz dexon-0x-contracts-a414dc9b83c14b277af90ce8397db3736a51a4d3.tar.bz2 dexon-0x-contracts-a414dc9b83c14b277af90ce8397db3736a51a4d3.tar.lz dexon-0x-contracts-a414dc9b83c14b277af90ce8397db3736a51a4d3.tar.xz dexon-0x-contracts-a414dc9b83c14b277af90ce8397db3736a51a4d3.tar.zst dexon-0x-contracts-a414dc9b83c14b277af90ce8397db3736a51a4d3.zip |
Merge branch 'development' of https://github.com/0xProject/0x-monorepo into feature/instant/fixed-orders-in-render-method
Diffstat (limited to 'packages/instant/src/components/scaling_amount_input.tsx')
-rw-r--r-- | packages/instant/src/components/scaling_amount_input.tsx | 52 |
1 files changed, 52 insertions, 0 deletions
diff --git a/packages/instant/src/components/scaling_amount_input.tsx b/packages/instant/src/components/scaling_amount_input.tsx new file mode 100644 index 000000000..655ae2b74 --- /dev/null +++ b/packages/instant/src/components/scaling_amount_input.tsx @@ -0,0 +1,52 @@ +import * as _ from 'lodash'; +import * as React from 'react'; + +import { ColorOption } from '../style/theme'; +import { BigNumberInput } from '../util/big_number_input'; +import { util } from '../util/util'; + +import { ScalingInput } from './scaling_input'; + +export interface ScalingAmountInputProps { + maxFontSizePx: number; + textLengthThreshold: number; + fontColor?: ColorOption; + value?: BigNumberInput; + onChange: (value?: BigNumberInput) => void; + onFontSizeChange: (fontSizePx: number) => void; +} + +export class ScalingAmountInput extends React.Component<ScalingAmountInputProps> { + public static defaultProps = { + onChange: util.boundNoop, + onFontSizeChange: util.boundNoop, + }; + public render(): React.ReactNode { + const { textLengthThreshold, fontColor, maxFontSizePx, value, onFontSizeChange } = this.props; + return ( + <ScalingInput + maxFontSizePx={maxFontSizePx} + textLengthThreshold={textLengthThreshold} + onFontSizeChange={onFontSizeChange} + fontColor={fontColor} + onChange={this._handleChange} + value={!_.isUndefined(value) ? value.toDisplayString() : ''} + placeholder="0.00" + emptyInputWidthCh={3.5} + /> + ); + } + private readonly _handleChange = (event: React.ChangeEvent<HTMLInputElement>): void => { + const value = event.target.value; + let bigNumberValue; + if (!_.isEmpty(value)) { + try { + bigNumberValue = new BigNumberInput(value); + } catch { + // We don't want to allow values that can't be a BigNumber, so don't even call onChange. + return; + } + } + this.props.onChange(bigNumberValue); + }; +} |