From e694e00ccec6128c7a70a8225f31cedd1dd80a82 Mon Sep 17 00:00:00 2001 From: Alex Abenoja Date: Sun, 26 Apr 2015 08:55:46 -0600 Subject: [PATCH] Convert Input to es6 class --- src/Input.js | 216 +++++++++++++++++++++------------------------- test/InputSpec.js | 8 +- 2 files changed, 103 insertions(+), 121 deletions(-) diff --git a/src/Input.js b/src/Input.js index 52dc202ee8..ef48dffe10 100644 --- a/src/Input.js +++ b/src/Input.js @@ -3,122 +3,51 @@ import classNames from 'classnames'; import Button from './Button'; import FormGroup from './FormGroup'; -const Input = React.createClass({ - - propTypes: { - type: React.PropTypes.string, - label: React.PropTypes.node, - help: React.PropTypes.node, - addonBefore: React.PropTypes.node, - addonAfter: React.PropTypes.node, - buttonBefore: React.PropTypes.node, - buttonAfter: React.PropTypes.node, - bsSize: React.PropTypes.oneOf(['small', 'medium', 'large']), - bsStyle(props) { - if (props.type === 'submit') { - // Return early if `type=submit` as the `Button` component - // it transfers these props to has its own propType checks. - return null; - } - - return React.PropTypes.oneOf(['success', 'warning', 'error']).apply(null, arguments); - }, - hasFeedback: React.PropTypes.bool, - id: React.PropTypes.string, - groupClassName: React.PropTypes.string, - wrapperClassName: React.PropTypes.string, - labelClassName: React.PropTypes.string, - multiple: React.PropTypes.bool, - disabled: React.PropTypes.bool, - value: React.PropTypes.any - }, - +class Input extends React.Component { getInputDOMNode() { return React.findDOMNode(this.refs.input); - }, + } getValue() { if (this.props.type === 'static') { return this.props.value; - } - else if (this.props.type) { + } else if (this.props.type) { if (this.props.type === 'select' && this.props.multiple) { return this.getSelectedOptions(); } else { return this.getInputDOMNode().value; } - } - else { + } else { throw 'Cannot use getValue without specifying input type.'; } - }, + } getChecked() { return this.getInputDOMNode().checked; - }, + } getSelectedOptions() { let values = []; Array.prototype.forEach.call( this.getInputDOMNode().getElementsByTagName('option'), - function (option) { + (option) => { if (option.selected) { - let value = option.getAttribute('value') || option.innerHTML; - + let value = option.getAttribute('value') || option.innerHtml; values.push(value); } - } - ); + }); return values; - }, + } isCheckboxOrRadio() { - return this.props.type === 'radio' || this.props.type === 'checkbox'; - }, + return this.props.type === 'checkbox' || this.props.type === 'radio'; + } isFile() { return this.props.type === 'file'; - }, - - renderInput() { - let input = null; - - if (!this.props.type) { - return this.props.children; - } - - switch (this.props.type) { - case 'select': - input = ( - - ); - break; - case 'textarea': - input =