1 | function _typeof(obj) { "@babel/helpers - typeof"; return _typeof = "function" == typeof Symbol && "symbol" == typeof Symbol.iterator ? function (obj) { return typeof obj; } : function (obj) { return obj && "function" == typeof Symbol && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }, _typeof(obj); }
|
2 | var _excluded = ["className", "cssModule", "dark", "end", "right", "tag", "flip", "modifiers", "persist", "strategy", "container", "updateOnSelect"];
|
3 | function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
4 | function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
5 | function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
6 | function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
7 | function _toConsumableArray(arr) { return _arrayWithoutHoles(arr) || _iterableToArray(arr) || _unsupportedIterableToArray(arr) || _nonIterableSpread(); }
|
8 | function _nonIterableSpread() { throw new TypeError("Invalid attempt to spread non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
|
9 | function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
|
10 | function _iterableToArray(iter) { if (typeof Symbol !== "undefined" && iter[Symbol.iterator] != null || iter["@@iterator"] != null) return Array.from(iter); }
|
11 | function _arrayWithoutHoles(arr) { if (Array.isArray(arr)) return _arrayLikeToArray(arr); }
|
12 | function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
|
13 | function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
14 | function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
15 | function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
16 | function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
17 | function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); Object.defineProperty(Constructor, "prototype", { writable: false }); return Constructor; }
|
18 | function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); Object.defineProperty(subClass, "prototype", { writable: false }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
19 | function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
20 | function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
21 | function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } else if (call !== void 0) { throw new TypeError("Derived constructors may only return object or undefined"); } return _assertThisInitialized(self); }
|
22 | function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
23 | function _isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Boolean.prototype.valueOf.call(Reflect.construct(Boolean, [], function () {})); return true; } catch (e) { return false; } }
|
24 | function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf.bind() : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
|
25 | import React from 'react';
|
26 | import PropTypes from 'prop-types';
|
27 | import ReactDOM from 'react-dom';
|
28 | import classNames from 'classnames';
|
29 | import { Popper } from 'react-popper';
|
30 | import { DropdownContext } from './DropdownContext';
|
31 | import { mapToCssModules, tagPropType, targetPropType, getTarget, deprecated } from './utils';
|
32 | var propTypes = {
|
33 | tag: tagPropType,
|
34 | children: PropTypes.node.isRequired,
|
35 | dark: PropTypes.bool,
|
36 | end: PropTypes.bool,
|
37 |
|
38 | flip: PropTypes.bool,
|
39 | modifiers: PropTypes.array,
|
40 | className: PropTypes.string,
|
41 | cssModule: PropTypes.object,
|
42 | style: PropTypes.object,
|
43 | persist: PropTypes.bool,
|
44 | strategy: PropTypes.string,
|
45 | container: targetPropType,
|
46 |
|
47 | updateOnSelect: PropTypes.bool,
|
48 | right: deprecated(PropTypes.bool, 'Please use "end" instead.')
|
49 | };
|
50 | var directionPositionMap = {
|
51 | up: 'top',
|
52 | left: 'left',
|
53 | right: 'right',
|
54 | start: 'left',
|
55 | end: 'right',
|
56 | down: 'bottom'
|
57 | };
|
58 | var DropdownMenu = function (_React$Component) {
|
59 | _inherits(DropdownMenu, _React$Component);
|
60 | var _super = _createSuper(DropdownMenu);
|
61 | function DropdownMenu() {
|
62 | _classCallCheck(this, DropdownMenu);
|
63 | return _super.apply(this, arguments);
|
64 | }
|
65 | _createClass(DropdownMenu, [{
|
66 | key: "getRole",
|
67 | value: function getRole() {
|
68 | if (this.context.menuRole === 'listbox') {
|
69 | return 'listbox';
|
70 | }
|
71 | return 'menu';
|
72 | }
|
73 | }, {
|
74 | key: "render",
|
75 | value: function render() {
|
76 | var _this = this;
|
77 | var _this$props = this.props,
|
78 | className = _this$props.className,
|
79 | cssModule = _this$props.cssModule,
|
80 | dark = _this$props.dark,
|
81 | end = _this$props.end,
|
82 | right = _this$props.right,
|
83 | _this$props$tag = _this$props.tag,
|
84 | tag = _this$props$tag === void 0 ? 'div' : _this$props$tag,
|
85 | _this$props$flip = _this$props.flip,
|
86 | flip = _this$props$flip === void 0 ? true : _this$props$flip,
|
87 | _this$props$modifiers = _this$props.modifiers,
|
88 | modifiers = _this$props$modifiers === void 0 ? [] : _this$props$modifiers,
|
89 | persist = _this$props.persist,
|
90 | strategy = _this$props.strategy,
|
91 | container = _this$props.container,
|
92 | updateOnSelect = _this$props.updateOnSelect,
|
93 | attrs = _objectWithoutProperties(_this$props, _excluded);
|
94 | var classes = mapToCssModules(classNames(className, 'dropdown-menu', {
|
95 | 'dropdown-menu-dark': dark,
|
96 | 'dropdown-menu-end': end || right,
|
97 | show: this.context.isOpen
|
98 | }), cssModule);
|
99 | var Tag = tag;
|
100 | if (persist || this.context.isOpen && !this.context.inNavbar) {
|
101 | var position1 = directionPositionMap[this.context.direction] || 'bottom';
|
102 | var position2 = end || right ? 'end' : 'start';
|
103 | var poperPlacement = "".concat(position1, "-").concat(position2);
|
104 | var poperModifiers = [].concat(_toConsumableArray(modifiers), [{
|
105 | name: 'flip',
|
106 | enabled: !!flip
|
107 | }]);
|
108 | var persistStyles = {};
|
109 | if (persist) {
|
110 | persistStyles.display = 'block';
|
111 | persistStyles.visibility = this.context.isOpen ? 'visible' : 'hidden';
|
112 | }
|
113 | var popper = React.createElement(Popper, {
|
114 | placement: poperPlacement,
|
115 | modifiers: poperModifiers,
|
116 | strategy: strategy
|
117 | }, function (_ref) {
|
118 | var ref = _ref.ref,
|
119 | style = _ref.style,
|
120 | placement = _ref.placement,
|
121 | update = _ref.update;
|
122 | var combinedStyle = _objectSpread(_objectSpread(_objectSpread({}, _this.props.style), persistStyles), style);
|
123 | var handleRef = function handleRef(tagRef) {
|
124 |
|
125 | ref(tagRef);
|
126 |
|
127 |
|
128 | var onMenuRef = _this.context.onMenuRef;
|
129 | if (onMenuRef) onMenuRef(tagRef);
|
130 | };
|
131 | return React.createElement(Tag, _extends({
|
132 | tabIndex: "-1",
|
133 | role: _this.getRole(),
|
134 | ref: handleRef
|
135 | }, attrs, {
|
136 | style: combinedStyle,
|
137 | "aria-hidden": !_this.context.isOpen,
|
138 | className: classes,
|
139 | "data-popper-placement": placement,
|
140 | onClick: function onClick() {
|
141 | return updateOnSelect && update();
|
142 | }
|
143 | }));
|
144 | });
|
145 | if (container) {
|
146 | return ReactDOM.createPortal(popper, getTarget(container));
|
147 | }
|
148 | return popper;
|
149 | }
|
150 | var onMenuRef = this.context.onMenuRef;
|
151 | return React.createElement(Tag, _extends({
|
152 | tabIndex: "-1",
|
153 | role: this.getRole()
|
154 | }, attrs, {
|
155 | ref: onMenuRef,
|
156 | "aria-hidden": !this.context.isOpen,
|
157 | className: classes,
|
158 | "data-popper-placement": attrs.placement,
|
159 | "data-bs-popper": "static"
|
160 | }));
|
161 | }
|
162 | }]);
|
163 | return DropdownMenu;
|
164 | }(React.Component);
|
165 | DropdownMenu.propTypes = propTypes;
|
166 | DropdownMenu.contextType = DropdownContext;
|
167 | export default DropdownMenu; |
\ | No newline at end of file |