mahaplatform/reframe

View on GitHub
src/controls/moneyfield/index.js

Summary

Maintainability
B
4 hrs
Test Coverage
import React from 'react'
import PropTypes from 'prop-types'
import TextField from '../textfield'

class MoneyField extends React.Component {

  static propTypes = {
    maxLength: PropTypes.number,
    disabled: PropTypes.bool,
    placeholder: PropTypes.string,
    defaultValue: PropTypes.string,
    tabIndex: PropTypes.number,
    onBusy: PropTypes.func,
    onChange: PropTypes.func,
    onFocus: PropTypes.func,
    onBlur: PropTypes.func,
    onReady: PropTypes.func,
    onKeyPress: PropTypes.func,
    onKeyUp: PropTypes.func,
    onKeyDown: PropTypes.func
  }

  static defaultProps = {
    tabIndex: 0
  }

  render() {
    return <TextField { ...this._getTextField() } />
  }

  _getTextField() {
    return {
      ...this.props,
      sanitize: (value) => value.replace(/[\$,]/g,''),
      validate: (value) => value.match(/^-?\d*\.?\d{0,2}$/) !== null
    }
  }

}

export default MoneyField