1 line
2.6 KiB
JSON
1 line
2.6 KiB
JSON
{"ast":null,"code":"import _extends from \"@babel/runtime/helpers/esm/extends\";\nimport _objectWithoutPropertiesLoose from \"@babel/runtime/helpers/esm/objectWithoutPropertiesLoose\";\nimport _assertThisInitialized from \"@babel/runtime/helpers/esm/assertThisInitialized\";\nimport _inheritsLoose from \"@babel/runtime/helpers/esm/inheritsLoose\";\nimport React from \"react\";\nimport PropTypes from 'prop-types';\nimport Button from \"./Button\";\nimport classNames from 'classnames';\nimport { mapToCssModules } from './utils';\nvar propTypes = {\n onClick: PropTypes.func,\n onBlur: PropTypes.func,\n onFocus: PropTypes.func,\n defaultValue: PropTypes.bool\n};\nvar defaultProps = {\n defaultValue: false\n};\n\nvar ButtonToggle = /*#__PURE__*/function (_React$Component) {\n _inheritsLoose(ButtonToggle, _React$Component);\n\n function ButtonToggle(props) {\n var _this;\n\n _this = _React$Component.call(this, props) || this;\n _this.state = {\n toggled: props.defaultValue,\n focus: false\n };\n _this.onBlur = _this.onBlur.bind(_assertThisInitialized(_this));\n _this.onFocus = _this.onFocus.bind(_assertThisInitialized(_this));\n _this.onClick = _this.onClick.bind(_assertThisInitialized(_this));\n return _this;\n }\n\n var _proto = ButtonToggle.prototype;\n\n _proto.onBlur = function onBlur(e) {\n if (this.props.onBlur) {\n this.props.onBlur(e);\n }\n\n this.setState({\n focus: false\n });\n };\n\n _proto.onFocus = function onFocus(e) {\n if (this.props.onFocus) {\n this.props.onFocus(e);\n }\n\n this.setState({\n focus: true\n });\n };\n\n _proto.onClick = function onClick(e) {\n if (this.props.onClick) {\n this.props.onClick(e);\n }\n\n this.setState(function (_ref) {\n var toggled = _ref.toggled;\n return {\n toggled: !toggled\n };\n });\n };\n\n _proto.render = function render() {\n var _this$props = this.props,\n className = _this$props.className,\n attributes = _objectWithoutPropertiesLoose(_this$props, [\"className\"]);\n\n var classes = mapToCssModules(classNames(className, {\n focus: this.state.focus\n }), this.props.cssModule);\n return React.createElement(Button, _extends({\n active: this.state.toggled,\n onBlur: this.onBlur,\n onFocus: this.onFocus,\n onClick: this.onClick,\n className: classes\n }, attributes));\n };\n\n return ButtonToggle;\n}(React.Component);\n\nButtonToggle.propTypes = propTypes;\nButtonToggle.defaultProps = defaultProps;\nexport default ButtonToggle;","map":null,"metadata":{},"sourceType":"module"} |