mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-25 09:55:15 +00:00
146 lines
5.5 KiB
JavaScript
146 lines
5.5 KiB
JavaScript
import _extends from "@babel/runtime/helpers/esm/extends";
|
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
|
import _assertThisInitialized from "@babel/runtime/helpers/esm/assertThisInitialized";
|
|
import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
|
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
|
|
|
var _transitionStatusToCl;
|
|
|
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); keys.push.apply(keys, symbols); } return keys; }
|
|
|
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
|
|
import React, { Component } from 'react';
|
|
import PropTypes from 'prop-types';
|
|
import classNames from 'classnames';
|
|
import { Transition } from 'react-transition-group';
|
|
import { mapToCssModules, omit, pick, TransitionTimeouts, TransitionPropTypeKeys, TransitionStatuses, tagPropType } from './utils';
|
|
|
|
var propTypes = _objectSpread(_objectSpread({}, Transition.propTypes), {}, {
|
|
isOpen: PropTypes.bool,
|
|
children: PropTypes.oneOfType([PropTypes.arrayOf(PropTypes.node), PropTypes.node]),
|
|
tag: tagPropType,
|
|
className: PropTypes.node,
|
|
navbar: PropTypes.bool,
|
|
cssModule: PropTypes.object,
|
|
innerRef: PropTypes.oneOfType([PropTypes.func, PropTypes.string, PropTypes.object])
|
|
});
|
|
|
|
var defaultProps = _objectSpread(_objectSpread({}, Transition.defaultProps), {}, {
|
|
isOpen: false,
|
|
appear: false,
|
|
enter: true,
|
|
exit: true,
|
|
tag: 'div',
|
|
timeout: TransitionTimeouts.Collapse
|
|
});
|
|
|
|
var transitionStatusToClassHash = (_transitionStatusToCl = {}, _transitionStatusToCl[TransitionStatuses.ENTERING] = 'collapsing', _transitionStatusToCl[TransitionStatuses.ENTERED] = 'collapse show', _transitionStatusToCl[TransitionStatuses.EXITING] = 'collapsing', _transitionStatusToCl[TransitionStatuses.EXITED] = 'collapse', _transitionStatusToCl);
|
|
|
|
function getTransitionClass(status) {
|
|
return transitionStatusToClassHash[status] || 'collapse';
|
|
}
|
|
|
|
function getHeight(node) {
|
|
return node.scrollHeight;
|
|
}
|
|
|
|
var Collapse = /*#__PURE__*/function (_Component) {
|
|
_inheritsLoose(Collapse, _Component);
|
|
|
|
function Collapse(props) {
|
|
var _this;
|
|
|
|
_this = _Component.call(this, props) || this;
|
|
_this.state = {
|
|
height: null
|
|
};
|
|
['onEntering', 'onEntered', 'onExit', 'onExiting', 'onExited'].forEach(function (name) {
|
|
_this[name] = _this[name].bind(_assertThisInitialized(_this));
|
|
});
|
|
return _this;
|
|
}
|
|
|
|
var _proto = Collapse.prototype;
|
|
|
|
_proto.onEntering = function onEntering(node, isAppearing) {
|
|
this.setState({
|
|
height: getHeight(node)
|
|
});
|
|
this.props.onEntering(node, isAppearing);
|
|
};
|
|
|
|
_proto.onEntered = function onEntered(node, isAppearing) {
|
|
this.setState({
|
|
height: null
|
|
});
|
|
this.props.onEntered(node, isAppearing);
|
|
};
|
|
|
|
_proto.onExit = function onExit(node) {
|
|
this.setState({
|
|
height: getHeight(node)
|
|
});
|
|
this.props.onExit(node);
|
|
};
|
|
|
|
_proto.onExiting = function onExiting(node) {
|
|
// getting this variable triggers a reflow
|
|
var _unused = node.offsetHeight; // eslint-disable-line no-unused-vars
|
|
|
|
this.setState({
|
|
height: 0
|
|
});
|
|
this.props.onExiting(node);
|
|
};
|
|
|
|
_proto.onExited = function onExited(node) {
|
|
this.setState({
|
|
height: null
|
|
});
|
|
this.props.onExited(node);
|
|
};
|
|
|
|
_proto.render = function render() {
|
|
var _this2 = this;
|
|
|
|
var _this$props = this.props,
|
|
Tag = _this$props.tag,
|
|
isOpen = _this$props.isOpen,
|
|
className = _this$props.className,
|
|
navbar = _this$props.navbar,
|
|
cssModule = _this$props.cssModule,
|
|
children = _this$props.children,
|
|
innerRef = _this$props.innerRef,
|
|
otherProps = _objectWithoutPropertiesLoose(_this$props, ["tag", "isOpen", "className", "navbar", "cssModule", "children", "innerRef"]);
|
|
|
|
var height = this.state.height;
|
|
var transitionProps = pick(otherProps, TransitionPropTypeKeys);
|
|
var childProps = omit(otherProps, TransitionPropTypeKeys);
|
|
return /*#__PURE__*/React.createElement(Transition, _extends({}, transitionProps, {
|
|
in: isOpen,
|
|
onEntering: this.onEntering,
|
|
onEntered: this.onEntered,
|
|
onExit: this.onExit,
|
|
onExiting: this.onExiting,
|
|
onExited: this.onExited
|
|
}), function (status) {
|
|
var collapseClass = getTransitionClass(status);
|
|
var classes = mapToCssModules(classNames(className, collapseClass, navbar && 'navbar-collapse'), cssModule);
|
|
var style = height === null ? null : {
|
|
height: height
|
|
};
|
|
return /*#__PURE__*/React.createElement(Tag, _extends({}, childProps, {
|
|
style: _objectSpread(_objectSpread({}, childProps.style), style),
|
|
className: classes,
|
|
ref: _this2.props.innerRef
|
|
}), children);
|
|
});
|
|
};
|
|
|
|
return Collapse;
|
|
}(Component);
|
|
|
|
Collapse.propTypes = propTypes;
|
|
Collapse.defaultProps = defaultProps;
|
|
export default Collapse; |