1 | import _extends from 'babel-runtime/helpers/extends';
|
2 | import _objectWithoutProperties from 'babel-runtime/helpers/objectWithoutProperties';
|
3 | import _classCallCheck from 'babel-runtime/helpers/classCallCheck';
|
4 | import _possibleConstructorReturn from 'babel-runtime/helpers/possibleConstructorReturn';
|
5 | import _inherits from 'babel-runtime/helpers/inherits';
|
6 | import PropTypes from 'prop-types';
|
7 | import React from 'react';
|
8 |
|
9 | import Button from './Button';
|
10 |
|
11 | var propTypes = {
|
12 | |
13 |
|
14 |
|
15 |
|
16 | type: PropTypes.oneOf(['checkbox', 'radio']),
|
17 |
|
18 | |
19 |
|
20 |
|
21 |
|
22 | name: PropTypes.string,
|
23 |
|
24 | |
25 |
|
26 |
|
27 | checked: PropTypes.bool,
|
28 |
|
29 | |
30 |
|
31 |
|
32 | disabled: PropTypes.bool,
|
33 |
|
34 | |
35 |
|
36 |
|
37 | onChange: PropTypes.func,
|
38 | |
39 |
|
40 |
|
41 | value: PropTypes.any.isRequired
|
42 | };
|
43 |
|
44 | var 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 |
|
84 | ToggleButton.propTypes = propTypes;
|
85 |
|
86 | export default ToggleButton; |
\ | No newline at end of file |