UNPKG

2.29 kBJavaScriptView Raw
1import _extends from 'babel-runtime/helpers/extends';
2import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
3import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
4import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
5import _inherits from 'babel-runtime/helpers/inherits';
6import PropTypes from 'prop-types';
7import React from 'react';
8
9import Button from './Button';
10
11var propTypes = {
12 /**
13 * The `<input>` `type`
14 * @type {[type]}
15 */
16 type: PropTypes.oneOf(['checkbox', 'radio']),
17
18 /**
19 * The HTML input name, used to group like checkboxes or radio buttons together
20 * semantically
21 */
22 name: PropTypes.string,
23
24 /**
25 * The checked state of the input, managed by `<ToggleButtonGroup>`` automatically
26 */
27 checked: PropTypes.bool,
28
29 /**
30 * The disabled state of both the label and input
31 */
32 disabled: PropTypes.bool,
33
34 /**
35 * [onChange description]
36 */
37 onChange: PropTypes.func,
38 /**
39 * The value of the input, and unique identifier in the ToggleButtonGroup
40 */
41 value: PropTypes.any.isRequired
42};
43
44var ToggleButton = function (_React$Component) {
45 _inherits(ToggleButton, _React$Component);
46
47 function ToggleButton() {
48 _classCallCheck(this, ToggleButton);
49
50 return _possibleConstructorReturn(this, _React$Component.apply(this, arguments));
51 }
52
53 ToggleButton.prototype.render = function render() {
54 var _props = this.props,
55 children = _props.children,
56 name = _props.name,
57 checked = _props.checked,
58 type = _props.type,
59 onChange = _props.onChange,
60 value = _props.value,
61 props = _objectWithoutProperties(_props, ['children', 'name', 'checked', 'type', 'onChange', 'value']);
62
63 var disabled = props.disabled;
64
65 return React.createElement(
66 Button,
67 _extends({}, props, { active: !!checked, componentClass: 'label' }),
68 React.createElement('input', {
69 name: name,
70 type: type,
71 autoComplete: 'off',
72 value: value,
73 checked: !!checked,
74 disabled: !!disabled,
75 onChange: onChange
76 }),
77 children
78 );
79 };
80
81 return ToggleButton;
82}(React.Component);
83
84ToggleButton.propTypes = propTypes;
85
86export default ToggleButton;
\No newline at end of file