1 line
8.0 KiB
JSON
1 line
8.0 KiB
JSON
|
{"ast":null,"code":"import matches from 'dom-helpers/matches';\nimport qsa from 'dom-helpers/querySelectorAll';\nimport React, { useCallback, useRef, useEffect, useMemo } from 'react';\nimport PropTypes from 'prop-types';\nimport { useUncontrolled } from 'uncontrollable';\nimport usePrevious from '@restart/hooks/usePrevious';\nimport useCallbackRef from '@restart/hooks/useCallbackRef';\nimport useForceUpdate from '@restart/hooks/useForceUpdate';\nimport useEventCallback from '@restart/hooks/useEventCallback';\nimport DropdownContext from './DropdownContext';\nimport DropdownMenu from './DropdownMenu';\nimport DropdownToggle from './DropdownToggle';\nvar propTypes = {\n /**\n * A render prop that returns the root dropdown element. The `props`\n * argument should spread through to an element containing _both_ the\n * menu and toggle in order to handle keyboard events for focus management.\n *\n * @type {Function ({\n * props: {\n * onKeyDown: (SyntheticEvent) => void,\n * },\n * }) => React.Element}\n */\n children: PropTypes.func.isRequired,\n\n /**\n * Determines the direction and location of the Menu in relation to it's Toggle.\n */\n drop: PropTypes.oneOf(['up', 'left', 'right', 'down']),\n\n /**\n * Controls the focus behavior for when the Dropdown is opened. Set to\n * `true` to always focus the first menu item, `keyboard` to focus only when\n * navigating via the keyboard, or `false` to disable completely\n *\n * The Default behavior is `false` **unless** the Menu has a `role=\"menu\"`\n * where it will default to `keyboard` to match the recommended [ARIA Authoring practices](https://www.w3.org/TR/wai-aria-practices-1.1/#menubutton).\n */\n focusFirstItemOnShow: PropTypes.oneOf([false, true, 'keyboard']),\n\n /**\n * A css slector string that will return __focusable__ menu items.\n * Selectors should be relative to the menu component:\n * e.g. ` > li:not('.disabled')`\n */\n itemSelector: PropTypes.string.isRequired,\n\n /**\n * Align the menu to the 'end' side of the placement side of the Dropdown toggle. The default placement is `top-start` or `bottom-start`.\n */\n alignEnd: PropTypes.bool,\n\n /**\n * Whether or not the Dropdown is visible.\n *\n * @controllable onToggle\n */\n show: PropTypes.bool,\n\n /**\n * Sets the initial show position of the Dropdown.\n */\n defaultShow: PropTypes.bool,\n\n /**\n * A callback fired when the Dropdown wishes to change visibility. Called with the requested\n * `show` value, the DOM event, and the source that fired it: `'click'`,`'keydown'`,`'rootClose'`, or `'select'`.\n *\n * ```js\n * function(\n * isOpen: boolean,\n * event: SyntheticEvent,\n * ): void\n * ```\n *\n * @controllable show\n */\n onToggle: PropTypes.func\n};\nvar defaultProps = {\n itemSelector: '* > *'\n};\n/**\n * `Dropdown` is set of structural components for building, accessible dropdown menus with close-on-click,\n * keyboard navigation, and correct focus handling. As with all the react-overlay's\n * components its BYOS (bring your own styles). Dropdown is primarily\n * built from three base components, you should compose to build your Dropdowns.\n *\n * - `Dropdown`, which wraps the menu and toggle, and handles keyboard navigation\n * - `Dropdown.Toggle` generally a button that triggers the menu opening\n * - `Dropdown.Menu` The overlaid, menu, positioned to the toggle with PopperJs\n */\n\nfunction Dropdown(_ref) {\n var drop = _ref.drop,\n alignEnd = _ref.alignEnd,\n defaultShow = _ref.defaultShow,\n rawShow = _ref.show,\n rawOnToggle = _ref.onToggle,\n itemSelector = _ref.itemSelector,\n focusFirstItemOnShow = _ref.focusFirstItemOnShow,\n children = _ref.children;\n var forceUpdate = useForceUpdate();\n\n var _useUncontrolled = useUncontrolled({\n defaultShow: defaultShow,\n show: rawShow,\n onToggle: rawOnToggle\n }, {\n show: 'onToggle'\n }),\n show = _useUncontrolled.show,\n onToggle = _useUncontrolled.onToggle;\n\n var
|