GoScrobble/web/node_modules/reactstrap/lib/ButtonToggle.js

110 lines
3.0 KiB
JavaScript
Raw Normal View History

2022-04-25 02:47:15 +00:00
"use strict";
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
exports.__esModule = true;
exports.default = void 0;
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
var _assertThisInitialized2 = _interopRequireDefault(require("@babel/runtime/helpers/assertThisInitialized"));
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
var _react = _interopRequireDefault(require("react"));
var _propTypes = _interopRequireDefault(require("prop-types"));
var _Button = _interopRequireDefault(require("./Button"));
var _classnames = _interopRequireDefault(require("classnames"));
var _utils = require("./utils");
var propTypes = {
onClick: _propTypes.default.func,
onBlur: _propTypes.default.func,
onFocus: _propTypes.default.func,
defaultValue: _propTypes.default.bool
};
var defaultProps = {
defaultValue: false
};
var ButtonToggle = /*#__PURE__*/function (_React$Component) {
(0, _inheritsLoose2.default)(ButtonToggle, _React$Component);
function ButtonToggle(props) {
var _this;
_this = _React$Component.call(this, props) || this;
_this.state = {
toggled: props.defaultValue,
focus: false
};
_this.onBlur = _this.onBlur.bind((0, _assertThisInitialized2.default)(_this));
_this.onFocus = _this.onFocus.bind((0, _assertThisInitialized2.default)(_this));
_this.onClick = _this.onClick.bind((0, _assertThisInitialized2.default)(_this));
return _this;
}
var _proto = ButtonToggle.prototype;
_proto.onBlur = function onBlur(e) {
if (this.props.onBlur) {
this.props.onBlur(e);
}
this.setState({
focus: false
});
};
_proto.onFocus = function onFocus(e) {
if (this.props.onFocus) {
this.props.onFocus(e);
}
this.setState({
focus: true
});
};
_proto.onClick = function onClick(e) {
if (this.props.onClick) {
this.props.onClick(e);
}
this.setState(function (_ref) {
var toggled = _ref.toggled;
return {
toggled: !toggled
};
});
};
_proto.render = function render() {
var _this$props = this.props,
className = _this$props.className,
attributes = (0, _objectWithoutPropertiesLoose2.default)(_this$props, ["className"]);
var classes = (0, _utils.mapToCssModules)((0, _classnames.default)(className, {
focus: this.state.focus
}), this.props.cssModule);
return /*#__PURE__*/_react.default.createElement(_Button.default, (0, _extends2.default)({
active: this.state.toggled,
onBlur: this.onBlur,
onFocus: this.onFocus,
onClick: this.onClick,
className: classes
}, attributes));
};
return ButtonToggle;
}(_react.default.Component);
ButtonToggle.propTypes = propTypes;
ButtonToggle.defaultProps = defaultProps;
var _default = ButtonToggle;
exports.default = _default;