mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-24 09:25:15 +00:00
155 lines
5.6 KiB
JavaScript
155 lines
5.6 KiB
JavaScript
"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 _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
|
|
var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
|
|
|
var _inheritsLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/inheritsLoose"));
|
|
|
|
var _react = _interopRequireDefault(require("react"));
|
|
|
|
var _propTypes = _interopRequireDefault(require("prop-types"));
|
|
|
|
var _reactDom = _interopRequireDefault(require("react-dom"));
|
|
|
|
var _classnames = _interopRequireDefault(require("classnames"));
|
|
|
|
var _reactPopper = require("react-popper");
|
|
|
|
var _DropdownContext = require("./DropdownContext");
|
|
|
|
var _utils = require("./utils");
|
|
|
|
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) { (0, _defineProperty2.default)(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; }
|
|
|
|
var propTypes = {
|
|
tag: _utils.tagPropType,
|
|
children: _propTypes.default.node.isRequired,
|
|
right: _propTypes.default.bool,
|
|
flip: _propTypes.default.bool,
|
|
modifiers: _propTypes.default.object,
|
|
className: _propTypes.default.string,
|
|
cssModule: _propTypes.default.object,
|
|
persist: _propTypes.default.bool,
|
|
positionFixed: _propTypes.default.bool,
|
|
container: _utils.targetPropType
|
|
};
|
|
var defaultProps = {
|
|
tag: 'div',
|
|
flip: true
|
|
};
|
|
var noFlipModifier = {
|
|
flip: {
|
|
enabled: false
|
|
}
|
|
};
|
|
var directionPositionMap = {
|
|
up: 'top',
|
|
left: 'left',
|
|
right: 'right',
|
|
down: 'bottom'
|
|
};
|
|
|
|
var DropdownMenu = /*#__PURE__*/function (_React$Component) {
|
|
(0, _inheritsLoose2.default)(DropdownMenu, _React$Component);
|
|
|
|
function DropdownMenu() {
|
|
return _React$Component.apply(this, arguments) || this;
|
|
}
|
|
|
|
var _proto = DropdownMenu.prototype;
|
|
|
|
_proto.render = function render() {
|
|
var _this = this;
|
|
|
|
var _this$props = this.props,
|
|
className = _this$props.className,
|
|
cssModule = _this$props.cssModule,
|
|
right = _this$props.right,
|
|
tag = _this$props.tag,
|
|
flip = _this$props.flip,
|
|
modifiers = _this$props.modifiers,
|
|
persist = _this$props.persist,
|
|
positionFixed = _this$props.positionFixed,
|
|
container = _this$props.container,
|
|
attrs = (0, _objectWithoutPropertiesLoose2.default)(_this$props, ["className", "cssModule", "right", "tag", "flip", "modifiers", "persist", "positionFixed", "container"]);
|
|
var classes = (0, _utils.mapToCssModules)((0, _classnames.default)(className, 'dropdown-menu', {
|
|
'dropdown-menu-right': right,
|
|
show: this.context.isOpen
|
|
}), cssModule);
|
|
var Tag = tag;
|
|
|
|
if (persist || this.context.isOpen && !this.context.inNavbar) {
|
|
var position1 = directionPositionMap[this.context.direction] || 'bottom';
|
|
var position2 = right ? 'end' : 'start';
|
|
var poperPlacement = position1 + "-" + position2;
|
|
var poperModifiers = !flip ? _objectSpread(_objectSpread({}, modifiers), noFlipModifier) : modifiers;
|
|
var popperPositionFixed = !!positionFixed;
|
|
|
|
var popper = /*#__PURE__*/_react.default.createElement(_reactPopper.Popper, {
|
|
placement: poperPlacement,
|
|
modifiers: poperModifiers,
|
|
positionFixed: popperPositionFixed
|
|
}, function (_ref) {
|
|
var ref = _ref.ref,
|
|
style = _ref.style,
|
|
placement = _ref.placement;
|
|
|
|
var combinedStyle = _objectSpread(_objectSpread({}, _this.props.style), style);
|
|
|
|
var handleRef = function handleRef(tagRef) {
|
|
// Send the ref to `react-popper`
|
|
ref(tagRef); // Send the ref to the parent Dropdown so that clicks outside
|
|
// it will cause it to close
|
|
|
|
var onMenuRef = _this.context.onMenuRef;
|
|
if (onMenuRef) onMenuRef(tagRef);
|
|
};
|
|
|
|
return /*#__PURE__*/_react.default.createElement(Tag, (0, _extends2.default)({
|
|
tabIndex: "-1",
|
|
role: "menu",
|
|
ref: handleRef
|
|
}, attrs, {
|
|
style: combinedStyle,
|
|
"aria-hidden": !_this.context.isOpen,
|
|
className: classes,
|
|
"x-placement": placement
|
|
}));
|
|
});
|
|
|
|
if (container) {
|
|
return /*#__PURE__*/_reactDom.default.createPortal(popper, (0, _utils.getTarget)(container));
|
|
} else {
|
|
return popper;
|
|
}
|
|
}
|
|
|
|
return /*#__PURE__*/_react.default.createElement(Tag, (0, _extends2.default)({
|
|
tabIndex: "-1",
|
|
role: "menu"
|
|
}, attrs, {
|
|
"aria-hidden": !this.context.isOpen,
|
|
className: classes,
|
|
"x-placement": attrs.placement
|
|
}));
|
|
};
|
|
|
|
return DropdownMenu;
|
|
}(_react.default.Component);
|
|
|
|
;
|
|
DropdownMenu.propTypes = propTypes;
|
|
DropdownMenu.defaultProps = defaultProps;
|
|
DropdownMenu.contextType = _DropdownContext.DropdownContext;
|
|
var _default = DropdownMenu;
|
|
exports.default = _default; |