mirror of
https://github.com/idanoo/GoScrobble.git
synced 2024-11-23 00:45:16 +00:00
137 lines
5.0 KiB
JavaScript
137 lines
5.0 KiB
JavaScript
|
import _extends from "@babel/runtime/helpers/esm/extends";
|
||
|
import _defineProperty from "@babel/runtime/helpers/esm/defineProperty";
|
||
|
import _objectWithoutPropertiesLoose from "@babel/runtime/helpers/esm/objectWithoutPropertiesLoose";
|
||
|
import _inheritsLoose from "@babel/runtime/helpers/esm/inheritsLoose";
|
||
|
|
||
|
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 from 'react';
|
||
|
import PropTypes from 'prop-types';
|
||
|
import ReactDOM from 'react-dom';
|
||
|
import classNames from 'classnames';
|
||
|
import { Popper } from 'react-popper';
|
||
|
import { DropdownContext } from './DropdownContext';
|
||
|
import { mapToCssModules, tagPropType, targetPropType, getTarget } from './utils';
|
||
|
var propTypes = {
|
||
|
tag: tagPropType,
|
||
|
children: PropTypes.node.isRequired,
|
||
|
right: PropTypes.bool,
|
||
|
flip: PropTypes.bool,
|
||
|
modifiers: PropTypes.object,
|
||
|
className: PropTypes.string,
|
||
|
cssModule: PropTypes.object,
|
||
|
persist: PropTypes.bool,
|
||
|
positionFixed: PropTypes.bool,
|
||
|
container: 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) {
|
||
|
_inheritsLoose(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 = _objectWithoutPropertiesLoose(_this$props, ["className", "cssModule", "right", "tag", "flip", "modifiers", "persist", "positionFixed", "container"]);
|
||
|
|
||
|
var classes = mapToCssModules(classNames(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.createElement(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.createElement(Tag, _extends({
|
||
|
tabIndex: "-1",
|
||
|
role: "menu",
|
||
|
ref: handleRef
|
||
|
}, attrs, {
|
||
|
style: combinedStyle,
|
||
|
"aria-hidden": !_this.context.isOpen,
|
||
|
className: classes,
|
||
|
"x-placement": placement
|
||
|
}));
|
||
|
});
|
||
|
|
||
|
if (container) {
|
||
|
return /*#__PURE__*/ReactDOM.createPortal(popper, getTarget(container));
|
||
|
} else {
|
||
|
return popper;
|
||
|
}
|
||
|
}
|
||
|
|
||
|
return /*#__PURE__*/React.createElement(Tag, _extends({
|
||
|
tabIndex: "-1",
|
||
|
role: "menu"
|
||
|
}, attrs, {
|
||
|
"aria-hidden": !this.context.isOpen,
|
||
|
className: classes,
|
||
|
"x-placement": attrs.placement
|
||
|
}));
|
||
|
};
|
||
|
|
||
|
return DropdownMenu;
|
||
|
}(React.Component);
|
||
|
|
||
|
;
|
||
|
DropdownMenu.propTypes = propTypes;
|
||
|
DropdownMenu.defaultProps = defaultProps;
|
||
|
DropdownMenu.contextType = DropdownContext;
|
||
|
export default DropdownMenu;
|