GoScrobble/web/node_modules/reactstrap/es/UncontrolledCollapse.js

71 lines
2.1 KiB
JavaScript

import _extends from "@babel/runtime/helpers/esm/extends";
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
import React, { Component } from 'react';
import PropTypes from 'prop-types';
import Collapse from './Collapse';
import { omit, findDOMElements, defaultToggleEvents, addMultipleEventListeners } from './utils';
var omitKeys = ['toggleEvents', 'defaultOpen'];
var propTypes = {
defaultOpen: PropTypes.bool,
toggler: PropTypes.string.isRequired,
toggleEvents: PropTypes.arrayOf(PropTypes.string)
};
var defaultProps = {
toggleEvents: defaultToggleEvents
};
var UncontrolledCollapse = /*#__PURE__*/function (_Component) {
_inheritsLoose(UncontrolledCollapse, _Component);
function UncontrolledCollapse(props) {
var _this;
_this = _Component.call(this, props) || this;
_this.togglers = null;
_this.removeEventListeners = null;
_this.toggle = _this.toggle.bind(_assertThisInitialized(_this));
_this.state = {
isOpen: props.defaultOpen || false
};
return _this;
}
var _proto = UncontrolledCollapse.prototype;
_proto.componentDidMount = function componentDidMount() {
this.togglers = findDOMElements(this.props.toggler);
if (this.togglers.length) {
this.removeEventListeners = addMultipleEventListeners(this.togglers, this.toggle, this.props.toggleEvents);
}
};
_proto.componentWillUnmount = function componentWillUnmount() {
if (this.togglers.length && this.removeEventListeners) {
this.removeEventListeners();
}
};
_proto.toggle = function toggle(e) {
this.setState(function (_ref) {
var isOpen = _ref.isOpen;
return {
isOpen: !isOpen
};
});
e.preventDefault();
};
_proto.render = function render() {
return /*#__PURE__*/React.createElement(Collapse, _extends({
isOpen: this.state.isOpen
}, omit(this.props, omitKeys)));
};
return UncontrolledCollapse;
}(Component);
UncontrolledCollapse.propTypes = propTypes;
UncontrolledCollapse.defaultProps = defaultProps;
export default UncontrolledCollapse;