Dashboard sipadu mbip
You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.default = void 0;
  4. var _matches = _interopRequireDefault(require("dom-helpers/query/matches"));
  5. var _querySelectorAll = _interopRequireDefault(require("dom-helpers/query/querySelectorAll"));
  6. var _react = _interopRequireDefault(require("react"));
  7. var _reactDom = _interopRequireDefault(require("react-dom"));
  8. var _propTypes = _interopRequireDefault(require("prop-types"));
  9. var _uncontrollable = _interopRequireDefault(require("uncontrollable"));
  10. var Popper = _interopRequireWildcard(require("react-popper"));
  11. var _DropdownContext = _interopRequireDefault(require("./DropdownContext"));
  12. var _DropdownMenu = _interopRequireDefault(require("./DropdownMenu"));
  13. var _DropdownToggle = _interopRequireDefault(require("./DropdownToggle"));
  14. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } else { var newObj = {}; if (obj != null) { for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {}; if (desc.get || desc.set) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } } newObj.default = obj; return newObj; } }
  15. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  16. 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; }
  17. function _extends() { _extends = Object.assign || 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); }
  18. function _inheritsLoose(subClass, superClass) { subClass.prototype = Object.create(superClass.prototype); subClass.prototype.constructor = subClass; subClass.__proto__ = superClass; }
  19. var propTypes = {
  20. /**
  21. * A render prop that returns the root dropdown element. The `props`
  22. * argument should spread through to an element containing _both_ the
  23. * menu and toggle in order to handle keyboard events for focus management.
  24. *
  25. * @type {Function ({
  26. * props: {
  27. * onKeyDown: (SyntheticEvent) => void,
  28. * },
  29. * }) => React.Element}
  30. */
  31. children: _propTypes.default.func.isRequired,
  32. /**
  33. * Determines the direction and location of the Menu in relation to it's Toggle.
  34. */
  35. drop: _propTypes.default.oneOf(['up', 'left', 'right', 'down']),
  36. /**
  37. * Controls the focus behavior for when the Dropdown is opened. Set to
  38. * `true` to always focus the first menu item, `keyboard` to focus only when
  39. * navigating via the keyboard, or `false` to disable completely
  40. *
  41. * The Default behavior is `false` **unless** the Menu has a `role="menu"`
  42. * where it will default to `keyboard` to match the recommended [ARIA Authoring practices](https://www.w3.org/TR/wai-aria-practices-1.1/#menubutton).
  43. */
  44. focusFirstItemOnShow: _propTypes.default.oneOf([false, true, 'keyboard']),
  45. /**
  46. * A css slector string that will return __focusable__ menu items.
  47. * Selectors should be relative to the menu component:
  48. * e.g. ` > li:not('.disabled')`
  49. */
  50. itemSelector: _propTypes.default.string.isRequired,
  51. /**
  52. * Align the menu to the 'end' side of the placement side of the Dropdown toggle. The default placement is `top-start` or `bottom-start`.
  53. */
  54. alignEnd: _propTypes.default.bool,
  55. /**
  56. * Whether or not the Dropdown is visible.
  57. *
  58. * @controllable onToggle
  59. */
  60. show: _propTypes.default.bool,
  61. /**
  62. * A callback fired when the Dropdown wishes to change visibility. Called with the requested
  63. * `show` value, the DOM event, and the source that fired it: `'click'`,`'keydown'`,`'rootClose'`, or `'select'`.
  64. *
  65. * ```js
  66. * function(
  67. * isOpen: boolean,
  68. * event: SyntheticEvent,
  69. * ): void
  70. * ```
  71. *
  72. * @controllable show
  73. */
  74. onToggle: _propTypes.default.func
  75. };
  76. var defaultProps = {
  77. itemSelector: '* > *'
  78. };
  79. /**
  80. * `Dropdown` is set of structural components for building, accessible dropdown menus with close-on-click,
  81. * keyboard navigation, and correct focus handling. As with all the react-overlay's
  82. * components its BYOS (bring your own styles). Dropdown is primarily
  83. * built from three base components, you should compose to build your Dropdowns.
  84. *
  85. * - `Dropdown`, which wraps the menu and toggle, and handles keyboard navigation
  86. * - `Dropdown.Toggle` generally a button that triggers the menu opening
  87. * - `Dropdown.Menu` The overlaid, menu, positioned to the toggle with PopperJs
  88. */
  89. var Dropdown =
  90. /*#__PURE__*/
  91. function (_React$Component) {
  92. _inheritsLoose(Dropdown, _React$Component);
  93. Dropdown.getDerivedStateFromProps = function getDerivedStateFromProps(_ref, prevState) {
  94. var drop = _ref.drop,
  95. alignEnd = _ref.alignEnd,
  96. show = _ref.show;
  97. var lastShow = prevState.context.show;
  98. return {
  99. lastShow: lastShow,
  100. context: _extends({}, prevState.context, {
  101. drop: drop,
  102. show: show,
  103. alignEnd: alignEnd
  104. })
  105. };
  106. };
  107. function Dropdown(props, context) {
  108. var _this;
  109. _this = _React$Component.call(this, props, context) || this;
  110. _this.handleClick = function (event) {
  111. _this.toggleOpen(event);
  112. };
  113. _this.handleKeyDown = function (event) {
  114. var key = event.key,
  115. target = event.target; // Second only to https://github.com/twbs/bootstrap/blob/8cfbf6933b8a0146ac3fbc369f19e520bd1ebdac/js/src/dropdown.js#L400
  116. // in inscrutability
  117. var isInput = /input|textarea/i.test(target.tagName);
  118. if (isInput && (key === ' ' || key !== 'Escape' && _this.menu.contains(target))) {
  119. return;
  120. }
  121. _this._lastSourceEvent = event.type;
  122. switch (key) {
  123. case 'ArrowUp':
  124. {
  125. var next = _this.getNextFocusedChild(target, -1);
  126. if (next && next.focus) next.focus();
  127. event.preventDefault();
  128. return;
  129. }
  130. case 'ArrowDown':
  131. event.preventDefault();
  132. if (!_this.props.show) {
  133. _this.toggleOpen(event);
  134. } else {
  135. var _next = _this.getNextFocusedChild(target, 1);
  136. if (_next && _next.focus) _next.focus();
  137. }
  138. return;
  139. case 'Escape':
  140. case 'Tab':
  141. _this.props.onToggle(false, event);
  142. break;
  143. default:
  144. }
  145. };
  146. _this._focusInDropdown = false;
  147. _this.menu = null;
  148. _this.state = {
  149. context: {
  150. close: _this.handleClose,
  151. toggle: _this.handleClick,
  152. menuRef: function menuRef(r) {
  153. _this.menu = r;
  154. },
  155. toggleRef: function toggleRef(r) {
  156. var toggleNode = r && _reactDom.default.findDOMNode(r);
  157. _this.setState(function (_ref2) {
  158. var context = _ref2.context;
  159. return {
  160. context: _extends({}, context, {
  161. toggleNode: toggleNode
  162. })
  163. };
  164. });
  165. }
  166. }
  167. };
  168. return _this;
  169. }
  170. var _proto = Dropdown.prototype;
  171. _proto.componentDidUpdate = function componentDidUpdate(prevProps) {
  172. var show = this.props.show;
  173. var prevOpen = prevProps.show;
  174. if (show && !prevOpen) {
  175. this.maybeFocusFirst();
  176. }
  177. this._lastSourceEvent = null;
  178. if (!show && prevOpen) {
  179. // if focus hasn't already moved from the menu let's return it
  180. // to the toggle
  181. if (this._focusInDropdown) {
  182. this._focusInDropdown = false;
  183. this.focus();
  184. }
  185. }
  186. };
  187. _proto.getNextFocusedChild = function getNextFocusedChild(current, offset) {
  188. if (!this.menu) return null;
  189. var itemSelector = this.props.itemSelector;
  190. var items = (0, _querySelectorAll.default)(this.menu, itemSelector);
  191. var index = items.indexOf(current) + offset;
  192. index = Math.max(0, Math.min(index, items.length));
  193. return items[index];
  194. };
  195. _proto.hasMenuRole = function hasMenuRole() {
  196. return this.menu && (0, _matches.default)(this.menu, '[role=menu]');
  197. };
  198. _proto.focus = function focus() {
  199. var toggleNode = this.state.context.toggleNode;
  200. if (toggleNode && toggleNode.focus) {
  201. toggleNode.focus();
  202. }
  203. };
  204. _proto.maybeFocusFirst = function maybeFocusFirst() {
  205. var type = this._lastSourceEvent;
  206. var focusFirstItemOnShow = this.props.focusFirstItemOnShow;
  207. if (focusFirstItemOnShow == null) {
  208. focusFirstItemOnShow = this.hasMenuRole() ? 'keyboard' : false;
  209. }
  210. if (focusFirstItemOnShow === false || focusFirstItemOnShow === 'keyboard' && !/^key.+$/.test(type)) {
  211. return;
  212. }
  213. var itemSelector = this.props.itemSelector;
  214. var first = (0, _querySelectorAll.default)(this.menu, itemSelector)[0];
  215. if (first && first.focus) first.focus();
  216. };
  217. _proto.toggleOpen = function toggleOpen(event) {
  218. var show = !this.props.show;
  219. this.props.onToggle(show, event);
  220. };
  221. _proto.render = function render() {
  222. var _this$props = this.props,
  223. children = _this$props.children,
  224. props = _objectWithoutPropertiesLoose(_this$props, ["children"]);
  225. delete props.onToggle;
  226. if (this.menu && this.state.lastShow && !this.props.show) {
  227. this._focusInDropdown = this.menu.contains(document.activeElement);
  228. }
  229. return _react.default.createElement(_DropdownContext.default.Provider, {
  230. value: this.state.context
  231. }, _react.default.createElement(Popper.Manager, null, children({
  232. props: {
  233. onKeyDown: this.handleKeyDown
  234. }
  235. })));
  236. };
  237. return Dropdown;
  238. }(_react.default.Component);
  239. Dropdown.displayName = 'ReactOverlaysDropdown';
  240. Dropdown.propTypes = propTypes;
  241. Dropdown.defaultProps = defaultProps;
  242. var UncontrolledDropdown = (0, _uncontrollable.default)(Dropdown, {
  243. show: 'onToggle'
  244. });
  245. UncontrolledDropdown.Menu = _DropdownMenu.default;
  246. UncontrolledDropdown.Toggle = _DropdownToggle.default;
  247. var _default = UncontrolledDropdown;
  248. exports.default = _default;
  249. module.exports = exports.default;