diff --git a/docs/examples/.eslintrc b/docs/examples/.eslintrc index ed5fd65183..86975f07e1 100644 --- a/docs/examples/.eslintrc +++ b/docs/examples/.eslintrc @@ -12,6 +12,7 @@ "Badge", "Button", "ButtonGroup", + "ButtonInput", "ButtonToolbar", "CollapsibleNav", "CollapsibleMixin", diff --git a/docs/examples/ButtonInput.js b/docs/examples/ButtonInput.js new file mode 100644 index 0000000000..90811ffef3 --- /dev/null +++ b/docs/examples/ButtonInput.js @@ -0,0 +1,44 @@ +const ButtonInputExample = React.createClass({ + getInitialState() { + return { + disabled: true, + style: '' + }; + }, + + resetValidation() { + this.setState({ + disabled: true, + style: '' + }); + }, + + validationState() { + let length = this.refs.input.getValue().length; + let style = 'danger'; + + if (length > 10) { style = 'success'; } + else if (length > 5) { style = 'warning'; } + + let disabled = style !== 'success'; + + return { style, disabled }; + }, + + handleChange() { + this.setState( this.validationState() ); + }, + + render() { + return ( +
+ + Child Text + + + + ); + } +}); + +React.render(, mountNode); diff --git a/docs/examples/InputTypes.js b/docs/examples/InputTypes.js index 965c6623c1..036f6d6199 100644 --- a/docs/examples/InputTypes.js +++ b/docs/examples/InputTypes.js @@ -16,7 +16,9 @@ const inputTypeInstance = ( - + + + ); diff --git a/docs/src/ComponentsPage.js b/docs/src/ComponentsPage.js index 4dc335759a..0353950113 100644 --- a/docs/src/ComponentsPage.js +++ b/docs/src/ComponentsPage.js @@ -551,6 +551,9 @@ const ComponentsPage = React.createClass({

Types

Supports select, textarea, static as well as standard HTML input types. getValue() returns an array for multiple select.

+

Button Input Types

+

Form buttons are encapsulated by ButtonInput. Pass in type="reset" or type="submit" to suit your needs. Styling is the same as Button.

+

Add-ons

Use addonBefore and addonAfter for normal addons, buttonBefore and buttonAfter for button addons. Exotic configurations may require some css on your side.

diff --git a/docs/src/ReactPlayground.js b/docs/src/ReactPlayground.js index 1d9152678b..7d2491aa9c 100644 --- a/docs/src/ReactPlayground.js +++ b/docs/src/ReactPlayground.js @@ -5,6 +5,7 @@ import * as modAlert from '../../src/Alert'; import * as modBadge from '../../src/Badge'; import * as modmodButton from '../../src/Button'; import * as modButtonGroup from '../../src/ButtonGroup'; +import * as modButtonInput from '../../src/ButtonInput'; import * as modmodButtonToolbar from '../../src/ButtonToolbar'; import * as modCollapsibleNav from '../../src/CollapsibleNav'; import * as modCollapsibleMixin from '../../src/CollapsibleMixin'; @@ -52,6 +53,7 @@ const Alert = modAlert.default; const Badge = modBadge.default; const Button = modmodButton.default; const ButtonGroup = modButtonGroup.default; +const ButtonInput = modButtonInput.default; const ButtonToolbar = modmodButtonToolbar.default; const CollapsibleNav = modCollapsibleNav.default; const CollapsibleMixin = modCollapsibleMixin.default; diff --git a/docs/src/Samples.js b/docs/src/Samples.js index d4821d9d10..82d9c40928 100644 --- a/docs/src/Samples.js +++ b/docs/src/Samples.js @@ -83,6 +83,7 @@ export default { TableResponsive: require('fs').readFileSync(__dirname + '/../examples/TableResponsive.js', 'utf8'), Input: require('fs').readFileSync(__dirname + '/../examples/Input.js', 'utf8'), InputTypes: require('fs').readFileSync(__dirname + '/../examples/InputTypes.js', 'utf8'), + ButtonInput: require('fs').readFileSync(__dirname + '/../examples/ButtonInput.js', 'utf8'), InputAddons: require('fs').readFileSync(__dirname + '/../examples/InputAddons.js', 'utf8'), InputSizes: require('fs').readFileSync(__dirname + '/../examples/InputSizes.js', 'utf8'), InputValidation: require('fs').readFileSync(__dirname + '/../examples/InputValidation.js', 'utf8'), diff --git a/src/ButtonInput.js b/src/ButtonInput.js new file mode 100644 index 0000000000..846d577ed4 --- /dev/null +++ b/src/ButtonInput.js @@ -0,0 +1,40 @@ +import React from 'react'; +import Button from './Button'; +import FormGroup from './FormGroup'; +import InputBase from './InputBase'; + +function valueValidation({children, value}, propName, componentName) { + if (children && value) { + return new Error('Both value and children cannot be passed to ButtonInput'); + } + return React.PropTypes.oneOfType([React.PropTypes.string, React.PropTypes.number]).call(null, {children, value}, propName, componentName); +} + +class ButtonInput extends InputBase { + renderFormGroup(children) { + let {bsStyle, value, ...other} = this.props; /* eslint no-unused-vars: 0 object-shorthand: 0 */ + return {children}; + } + + renderInput() { + let {children, value, ...other} = this.props; + let val = children ? children : value; + return