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["default"] = void 0;
|
9 |
|
10 | var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
11 |
|
12 | var _objectWithoutPropertiesLoose2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutPropertiesLoose"));
|
13 |
|
14 | var _propTypes = _interopRequireDefault(require("prop-types"));
|
15 |
|
16 | var _react = _interopRequireWildcard(require("react"));
|
17 |
|
18 | var _reactDom = _interopRequireDefault(require("react-dom"));
|
19 |
|
20 | var _useCallbackRef3 = _interopRequireDefault(require("@restart/hooks/useCallbackRef"));
|
21 |
|
22 | var _useMergedRefs = _interopRequireDefault(require("@restart/hooks/useMergedRefs"));
|
23 |
|
24 | var _popper = require("./popper");
|
25 |
|
26 | var _usePopper2 = _interopRequireDefault(require("./usePopper"));
|
27 |
|
28 | var _useRootClose = _interopRequireDefault(require("./useRootClose"));
|
29 |
|
30 | var _useWaitForDOMRef = _interopRequireDefault(require("./useWaitForDOMRef"));
|
31 |
|
32 | var _mergeOptionsWithPopperConfig = _interopRequireDefault(require("./mergeOptionsWithPopperConfig"));
|
33 |
|
34 |
|
35 |
|
36 |
|
37 |
|
38 | var Overlay = _react["default"].forwardRef(function (props, outerRef) {
|
39 | var flip = props.flip,
|
40 | offset = props.offset,
|
41 | placement = props.placement,
|
42 | _props$containerPaddi = props.containerPadding,
|
43 | containerPadding = _props$containerPaddi === void 0 ? 5 : _props$containerPaddi,
|
44 | _props$popperConfig = props.popperConfig,
|
45 | popperConfig = _props$popperConfig === void 0 ? {} : _props$popperConfig,
|
46 | Transition = props.transition;
|
47 |
|
48 | var _useCallbackRef = (0, _useCallbackRef3["default"])(),
|
49 | rootElement = _useCallbackRef[0],
|
50 | attachRef = _useCallbackRef[1];
|
51 |
|
52 | var _useCallbackRef2 = (0, _useCallbackRef3["default"])(),
|
53 | arrowElement = _useCallbackRef2[0],
|
54 | attachArrowRef = _useCallbackRef2[1];
|
55 |
|
56 | var mergedRef = (0, _useMergedRefs["default"])(attachRef, outerRef);
|
57 | var container = (0, _useWaitForDOMRef["default"])(props.container);
|
58 | var target = (0, _useWaitForDOMRef["default"])(props.target);
|
59 |
|
60 | var _useState = (0, _react.useState)(!props.show),
|
61 | exited = _useState[0],
|
62 | setExited = _useState[1];
|
63 |
|
64 | var _usePopper = (0, _usePopper2["default"])(target, rootElement, (0, _mergeOptionsWithPopperConfig["default"])({
|
65 | placement: placement,
|
66 | enableEvents: !!props.show,
|
67 | containerPadding: containerPadding || 5,
|
68 | flip: flip,
|
69 | offset: offset,
|
70 | arrowElement: arrowElement,
|
71 | popperConfig: popperConfig
|
72 | })),
|
73 | styles = _usePopper.styles,
|
74 | attributes = _usePopper.attributes,
|
75 | popper = (0, _objectWithoutPropertiesLoose2["default"])(_usePopper, ["styles", "attributes"]);
|
76 |
|
77 | if (props.show) {
|
78 | if (exited) setExited(false);
|
79 | } else if (!props.transition && !exited) {
|
80 | setExited(true);
|
81 | }
|
82 |
|
83 | var handleHidden = function handleHidden() {
|
84 | setExited(true);
|
85 |
|
86 | if (props.onExited) {
|
87 | props.onExited.apply(props, arguments);
|
88 | }
|
89 | };
|
90 |
|
91 |
|
92 | var mountOverlay = props.show || Transition && !exited;
|
93 | (0, _useRootClose["default"])(rootElement, props.onHide, {
|
94 | disabled: !props.rootClose || props.rootCloseDisabled,
|
95 | clickTrigger: props.rootCloseEvent
|
96 | });
|
97 |
|
98 | if (!mountOverlay) {
|
99 |
|
100 | return null;
|
101 | }
|
102 |
|
103 | var child = props.children((0, _extends2["default"])({}, popper, {
|
104 | show: !!props.show,
|
105 | props: (0, _extends2["default"])({}, attributes.popper, {
|
106 | style: styles.popper,
|
107 | ref: mergedRef
|
108 | }),
|
109 | arrowProps: (0, _extends2["default"])({}, attributes.arrow, {
|
110 | style: styles.arrow,
|
111 | ref: attachArrowRef
|
112 | })
|
113 | }));
|
114 |
|
115 | if (Transition) {
|
116 | var onExit = props.onExit,
|
117 | onExiting = props.onExiting,
|
118 | onEnter = props.onEnter,
|
119 | onEntering = props.onEntering,
|
120 | onEntered = props.onEntered;
|
121 | child = _react["default"].createElement(Transition, {
|
122 | "in": props.show,
|
123 | appear: true,
|
124 | onExit: onExit,
|
125 | onExiting: onExiting,
|
126 | onExited: handleHidden,
|
127 | onEnter: onEnter,
|
128 | onEntering: onEntering,
|
129 | onEntered: onEntered
|
130 | }, child);
|
131 | }
|
132 |
|
133 | return container ? _reactDom["default"].createPortal(child, container) : null;
|
134 | });
|
135 |
|
136 | Overlay.displayName = 'Overlay';
|
137 | Overlay.propTypes = {
|
138 | |
139 |
|
140 |
|
141 | show: _propTypes["default"].bool,
|
142 |
|
143 |
|
144 | placement: _propTypes["default"].oneOf(_popper.placements),
|
145 |
|
146 | |
147 |
|
148 |
|
149 |
|
150 | target: _propTypes["default"].any,
|
151 |
|
152 | |
153 |
|
154 |
|
155 |
|
156 | container: _propTypes["default"].any,
|
157 |
|
158 | |
159 |
|
160 |
|
161 |
|
162 |
|
163 | flip: _propTypes["default"].bool,
|
164 |
|
165 | |
166 |
|
167 |
|
168 |
|
169 |
|
170 |
|
171 |
|
172 |
|
173 |
|
174 |
|
175 |
|
176 |
|
177 |
|
178 |
|
179 |
|
180 |
|
181 |
|
182 |
|
183 |
|
184 |
|
185 |
|
186 |
|
187 | children: _propTypes["default"].func.isRequired,
|
188 |
|
189 | |
190 |
|
191 |
|
192 |
|
193 | containerPadding: _propTypes["default"].number,
|
194 |
|
195 | |
196 |
|
197 |
|
198 | popperConfig: _propTypes["default"].object,
|
199 |
|
200 | |
201 |
|
202 |
|
203 | rootClose: _propTypes["default"].bool,
|
204 |
|
205 | |
206 |
|
207 |
|
208 | rootCloseEvent: _propTypes["default"].oneOf(['click', 'mousedown']),
|
209 |
|
210 | |
211 |
|
212 |
|
213 | rootCloseDisabled: _propTypes["default"].bool,
|
214 |
|
215 | |
216 |
|
217 |
|
218 |
|
219 |
|
220 |
|
221 |
|
222 | onHide: function onHide(props) {
|
223 | for (var _len = arguments.length, args = new Array(_len > 1 ? _len - 1 : 0), _key = 1; _key < _len; _key++) {
|
224 | args[_key - 1] = arguments[_key];
|
225 | }
|
226 |
|
227 | if (props.rootClose) {
|
228 | var _PropTypes$func;
|
229 |
|
230 | return (_PropTypes$func = _propTypes["default"].func).isRequired.apply(_PropTypes$func, [props].concat(args));
|
231 | }
|
232 |
|
233 | return _propTypes["default"].func.apply(_propTypes["default"], [props].concat(args));
|
234 | },
|
235 |
|
236 | |
237 |
|
238 |
|
239 |
|
240 |
|
241 | transition: _propTypes["default"].elementType,
|
242 |
|
243 | |
244 |
|
245 |
|
246 | onEnter: _propTypes["default"].func,
|
247 |
|
248 | |
249 |
|
250 |
|
251 | onEntering: _propTypes["default"].func,
|
252 |
|
253 | |
254 |
|
255 |
|
256 | onEntered: _propTypes["default"].func,
|
257 |
|
258 | |
259 |
|
260 |
|
261 | onExit: _propTypes["default"].func,
|
262 |
|
263 | |
264 |
|
265 |
|
266 | onExiting: _propTypes["default"].func,
|
267 |
|
268 | |
269 |
|
270 |
|
271 | onExited: _propTypes["default"].func
|
272 | };
|
273 | var _default = Overlay;
|
274 | exports["default"] = _default;
|
275 | module.exports = exports.default; |
\ | No newline at end of file |