1 | "use strict";
|
2 |
|
3 | var _interopRequireWildcard = require("@babel/runtime/helpers/interopRequireWildcard");
|
4 |
|
5 | var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
6 |
|
7 | exports.__esModule = true;
|
8 | exports.useDropdownToggle = useDropdownToggle;
|
9 | exports["default"] = void 0;
|
10 |
|
11 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
12 |
|
13 | var _react = _interopRequireWildcard(require("react"));
|
14 |
|
15 | var _DropdownContext = _interopRequireDefault(require("./DropdownContext"));
|
16 |
|
17 | var noop = function noop() {};
|
18 |
|
19 |
|
20 |
|
21 |
|
22 |
|
23 |
|
24 |
|
25 |
|
26 | function useDropdownToggle() {
|
27 | var _ref = (0, _react.useContext)(_DropdownContext["default"]) || {},
|
28 | _ref$show = _ref.show,
|
29 | show = _ref$show === void 0 ? false : _ref$show,
|
30 | _ref$toggle = _ref.toggle,
|
31 | toggle = _ref$toggle === void 0 ? noop : _ref$toggle,
|
32 | setToggle = _ref.setToggle;
|
33 |
|
34 | var handleClick = (0, _react.useCallback)(function (e) {
|
35 | toggle(!show, e);
|
36 | }, [show, toggle]);
|
37 | return [{
|
38 | ref: setToggle || noop,
|
39 | onClick: handleClick,
|
40 | 'aria-haspopup': true,
|
41 | 'aria-expanded': !!show
|
42 | }, {
|
43 | show: show,
|
44 | toggle: toggle
|
45 | }];
|
46 | }
|
47 |
|
48 | var propTypes = {
|
49 | |
50 |
|
51 |
|
52 |
|
53 |
|
54 |
|
55 |
|
56 |
|
57 |
|
58 |
|
59 |
|
60 |
|
61 |
|
62 |
|
63 |
|
64 | children: _propTypes["default"].func.isRequired
|
65 | };
|
66 |
|
67 |
|
68 |
|
69 |
|
70 |
|
71 |
|
72 |
|
73 | function DropdownToggle(_ref2) {
|
74 | var children = _ref2.children;
|
75 |
|
76 | var _useDropdownToggle = useDropdownToggle(),
|
77 | props = _useDropdownToggle[0],
|
78 | meta = _useDropdownToggle[1];
|
79 |
|
80 | return _react["default"].createElement(_react["default"].Fragment, null, children(props, meta));
|
81 | }
|
82 |
|
83 | DropdownToggle.displayName = 'ReactOverlaysDropdownToggle';
|
84 | DropdownToggle.propTypes = propTypes;
|
85 |
|
86 |
|
87 | var _default = DropdownToggle;
|
88 | exports["default"] = _default; |
\ | No newline at end of file |