Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.
componentWillReceiveProps (nextProps, nextContext) {
if (!this._input.value) return
// If the locale or precision props change, update the input value accordingly
const currentLocale = this.getLocale(this.props, this.context)
const nextLocale = this.getLocale(nextProps, nextContext)
const currentPrecision = this.getPrecision(this.props)
const nextPrecision = this.getPrecision(nextProps)
if (currentLocale === nextLocale && deepEqual(currentPrecision, nextPrecision)) return
const decimalValue = Decimal.parse(this._input.value, currentLocale)
if (decimalValue.isNaN()) return
const formattedString = this.formatValue(decimalValue, nextLocale, nextPrecision)
this.setState({ value: formattedString })
nextProps.onChange(null, formattedString, this.normalizeValue(decimalValue, nextPrecision))
}
applyStep = (dir) => {
let d = Decimal.parse(this._input.value || '0', this.locale)
if (this.step.isNaN()) return d
if (!d.mod(this.step).equals(0)) {
// case when value is between steps, so we snap to the next step
const steps = d.div(this.step)
if (dir > 0) {
d = steps.floor().times(this.step)
} else {
d = steps.ceil().times(this.step)
}
}
// then we add the step
if (dir > 0) {
d = d.plus(this.step)
getDecimalValue (value) {
return Decimal.parse(value, this.locale)
}