diff options
Diffstat (limited to 'app/components/AccountInput.js')
| -rw-r--r-- | app/components/AccountInput.js | 66 |
1 files changed, 65 insertions, 1 deletions
diff --git a/app/components/AccountInput.js b/app/components/AccountInput.js index eba498fb95..3d321a605a 100644 --- a/app/components/AccountInput.js +++ b/app/components/AccountInput.js @@ -1,6 +1,13 @@ import React, { Component, PropTypes } from 'react'; import { formatAccount } from '../lib/formatters'; +/** + * Account input field with automatic formatting + * + * @export + * @class AccountInput + * @extends {Component} + */ export default class AccountInput extends Component { /** @@ -27,6 +34,12 @@ export default class AccountInput extends Component { // selection range holds selection converted from DOM selection range to // internal unformatted representation of account number const val = this.sanitize(props.value); + + /** + * @type {object} + * @property {string} value - raw text value + * @property {number[]} selectionRange - raw text mapped selection range [start, end] + */ this.state = { value: val, selectionRange: [val.length, val.length] @@ -44,6 +57,9 @@ export default class AccountInput extends Component { } } + /** + * @override + */ shouldComponentUpdate(nextProps, nextState) { return (this.props.value !== nextProps.value || this.props.onEnter !== nextProps.onEnter || @@ -52,7 +68,10 @@ export default class AccountInput extends Component { this.state.selectionRange[0] !== nextState.selectionRange[0] || this.state.selectionRange[1] !== nextState.selectionRange[1]); } - + + /** + * @override + */ render() { const displayString = formatAccount(this.state.value || ''); const props = Object.assign({}, this.props); @@ -83,6 +102,7 @@ export default class AccountInput extends Component { /** * Modify original string inserting substring using selection range * + * @private * @param {String?} val string * @returns String * @@ -95,6 +115,7 @@ export default class AccountInput extends Component { /** * Modify original string inserting substring using selection range * + * @private * @param {String} val original string * @param {String} insert insertion string * @param {Array} selRange selection range ([x,y]) @@ -115,6 +136,7 @@ export default class AccountInput extends Component { /** * Modify string by removing single character or range of characters based on selection range. * + * @private * @param {String} val original string * @param {Array} selRange selection range ([x,y]) * @returns Object @@ -144,6 +166,7 @@ export default class AccountInput extends Component { /** * Convert DOM selection range to internal selection range * + * @private * @param {String} val original string * @param {Array} domRange selection range from DOM * @returns Object @@ -171,6 +194,7 @@ export default class AccountInput extends Component { /** * Convert internal selection range to DOM selection range * + * @private * @param {String} val original string * @param {Array} selRange selection range * @returns Object @@ -196,6 +220,12 @@ export default class AccountInput extends Component { // Events + /** + * Key down handler + * @private + * @param {event} e + * @memberOf AccountInput + */ onKeyDown(e) { const { value, selectionRange } = this.state; @@ -224,6 +254,12 @@ export default class AccountInput extends Component { } } + /** + * Key up handler + * @private + * @param {event} e + * @memberOf AccountInput + */ onKeyUp(e) { this._ignoreSelect = false; @@ -232,6 +268,12 @@ export default class AccountInput extends Component { } } + /** + * Select handler + * @private + * @param {event} e + * @memberOf AccountInput + */ onSelect(e) { const ref = e.target; @@ -245,6 +287,12 @@ export default class AccountInput extends Component { this.setState({ selectionRange: selRange }); } + /** + * Paste handler + * @private + * @param {event} e + * @memberOf AccountInput + */ onPaste(e) { const { value, selectionRange } = this.state; const pastedData = e.clipboardData.getData('text'); @@ -258,6 +306,12 @@ export default class AccountInput extends Component { }); } + /** + * Cut handler + * @private + * @param {event} e + * @memberOf AccountInput + */ onCut(e) { const { value, selectionRange } = this.state; @@ -279,6 +333,12 @@ export default class AccountInput extends Component { } } + /** + * Reference handler + * @private + * @param {DOMElement} ref + * @memberOf AccountInput + */ onRef(ref) { this._ref = ref; if(!ref) { return; } @@ -290,6 +350,10 @@ export default class AccountInput extends Component { ref.selectionEnd = domRange[1]; } + /** + * Focus on text field + * @memberOf AccountInput + */ focus() { if(this._ref) { this._ref.focus(); |
