@kne/react-modal 0.1.1 → 0.1.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +763 -334
- package/dist/index.css +599 -0
- package/dist/index.css.map +1 -1
- package/dist/index.js +867 -63
- package/dist/index.js.map +1 -1
- package/dist/index.modern.js +862 -73
- package/dist/index.modern.js.map +1 -1
- package/package.json +5 -2
package/dist/index.js
CHANGED
|
@@ -36,7 +36,7 @@ const withLocale = reactIntl.createWithIntlProvider({
|
|
|
36
36
|
namespace: 'react-modal'
|
|
37
37
|
});
|
|
38
38
|
|
|
39
|
-
var
|
|
39
|
+
var modalStyle = {"kne-responsive-boundary":"kne-react-modal_gh14z","kne-responsive-scroll":"kne-react-modal_Kfn6L","modal":"kne-react-modal_Bk7-B","small":"kne-react-modal_DZGD6","large":"kne-react-modal_9sz-n","modal-body-inner":"kne-react-modal_fFnva","is-mobile":"kne-react-modal_LtgJz","modal-container":"kne-react-modal_aEoZq","modal-antd-header":"kne-react-modal_54n8W","modal-antd-footer":"kne-react-modal_AJ9pV","modal-antd-body":"kne-react-modal_u2IjN","modal-outer":"kne-react-modal_kkILR","no-title":"kne-react-modal_8Iysr","no-footer":"kne-react-modal_VMxik","no-padding":"kne-react-modal_Fof-N","modal-title":"kne-react-modal_tG9MF","modal-body":"kne-react-modal_W-QFz","modal-footer":"kne-react-modal_meVfy","body-scroll-off":"kne-react-modal_l627I","is-embedded-footer":"kne-react-modal_17Eih","modal-footer-extra":"kne-react-modal_Fx8Z-","modal-footer-actions":"kne-react-modal_V3ZrX","modal-close":"kne-react-modal_-EK8N","modal-host":"kne-react-modal_eNb-h","modal-form-host":"kne-react-modal_Js8cf","modal-wrap":"kne-react-modal_3Sju5","modal-wrap-centered":"kne-react-modal_-qCIk","modal-wrap-fullscreen":"kne-react-modal_8lS2G","modal-mask-fullscreen":"kne-react-modal_XfLOC"};
|
|
40
40
|
|
|
41
41
|
const Footer = ({
|
|
42
42
|
footer,
|
|
@@ -98,15 +98,15 @@ const Footer = ({
|
|
|
98
98
|
return null;
|
|
99
99
|
}
|
|
100
100
|
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
101
|
-
className: classnames__default["default"](
|
|
102
|
-
[
|
|
103
|
-
[
|
|
101
|
+
className: classnames__default["default"](modalStyle['modal-footer'], 'modal-footer', {
|
|
102
|
+
[modalStyle['is-mobile']]: isMobile,
|
|
103
|
+
[modalStyle['is-embedded-footer']]: embeddedFooterOnly
|
|
104
104
|
}),
|
|
105
105
|
children: [showFooterSlot ? /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
106
|
-
className:
|
|
106
|
+
className: modalStyle['modal-footer-extra'],
|
|
107
107
|
children: footer
|
|
108
108
|
}) : null, showButtons ? /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
109
|
-
className:
|
|
109
|
+
className: modalStyle['modal-footer-actions'],
|
|
110
110
|
children: /*#__PURE__*/jsxRuntime.jsx(ButtonGroup__default["default"], {
|
|
111
111
|
list: list,
|
|
112
112
|
showLength: list.length,
|
|
@@ -119,13 +119,13 @@ const Footer = ({
|
|
|
119
119
|
const ModalLocaleRoot = withLocale(({
|
|
120
120
|
children
|
|
121
121
|
}) => children);
|
|
122
|
-
const renderWithOptions = (value, options) => {
|
|
122
|
+
const renderWithOptions$1 = (value, options) => {
|
|
123
123
|
if (typeof value === 'function') {
|
|
124
124
|
return value(options);
|
|
125
125
|
}
|
|
126
126
|
return value;
|
|
127
127
|
};
|
|
128
|
-
const wrapCustomGetContainer = customGetContainer => {
|
|
128
|
+
const wrapCustomGetContainer$2 = customGetContainer => {
|
|
129
129
|
if (!customGetContainer) {
|
|
130
130
|
return undefined;
|
|
131
131
|
}
|
|
@@ -134,10 +134,10 @@ const wrapCustomGetContainer = customGetContainer => {
|
|
|
134
134
|
}
|
|
135
135
|
return () => customGetContainer;
|
|
136
136
|
};
|
|
137
|
-
const VIEWPORT_EXAMPLE_SELECTORS = ['.example-driver-device-scroll'];
|
|
138
|
-
const viewportPopupMountOptions = {
|
|
137
|
+
const VIEWPORT_EXAMPLE_SELECTORS$3 = ['.example-driver-device-scroll'];
|
|
138
|
+
const viewportPopupMountOptions$1 = {
|
|
139
139
|
cover: 'viewport',
|
|
140
|
-
exampleSelectors: VIEWPORT_EXAMPLE_SELECTORS
|
|
140
|
+
exampleSelectors: VIEWPORT_EXAMPLE_SELECTORS$3
|
|
141
141
|
};
|
|
142
142
|
const findParentModalMountHost = node => {
|
|
143
143
|
if (!node || typeof node.closest !== 'function') {
|
|
@@ -154,7 +154,7 @@ const resolveModalGetContainer = ({
|
|
|
154
154
|
getPopupContainer,
|
|
155
155
|
getHostNode
|
|
156
156
|
}) => {
|
|
157
|
-
const wrappedCustom = wrapCustomGetContainer(customGetContainer);
|
|
157
|
+
const wrappedCustom = wrapCustomGetContainer$2(customGetContainer);
|
|
158
158
|
return triggerNode => {
|
|
159
159
|
if (wrappedCustom) {
|
|
160
160
|
const custom = wrappedCustom(triggerNode);
|
|
@@ -170,17 +170,17 @@ const resolveModalGetContainer = ({
|
|
|
170
170
|
return getPopupContainer(triggerNode);
|
|
171
171
|
};
|
|
172
172
|
};
|
|
173
|
-
let parentScrollLockCount = 0;
|
|
174
|
-
let parentScrollLocked = [];
|
|
175
|
-
const lockParentScroll = getScrollElement => {
|
|
176
|
-
parentScrollLockCount += 1;
|
|
177
|
-
if (parentScrollLockCount === 1) {
|
|
173
|
+
let parentScrollLockCount$1 = 0;
|
|
174
|
+
let parentScrollLocked$1 = [];
|
|
175
|
+
const lockParentScroll$1 = getScrollElement => {
|
|
176
|
+
parentScrollLockCount$1 += 1;
|
|
177
|
+
if (parentScrollLockCount$1 === 1) {
|
|
178
178
|
const targets = [document.body];
|
|
179
179
|
const scrollEl = typeof getScrollElement === 'function' ? getScrollElement() : null;
|
|
180
180
|
if (scrollEl && scrollEl !== document.body && !targets.includes(scrollEl)) {
|
|
181
181
|
targets.push(scrollEl);
|
|
182
182
|
}
|
|
183
|
-
parentScrollLocked = targets.map(el => {
|
|
183
|
+
parentScrollLocked$1 = targets.map(el => {
|
|
184
184
|
const prev = {
|
|
185
185
|
overflow: el.style.overflow,
|
|
186
186
|
overscrollBehavior: el.style.overscrollBehavior
|
|
@@ -194,28 +194,28 @@ const lockParentScroll = getScrollElement => {
|
|
|
194
194
|
});
|
|
195
195
|
}
|
|
196
196
|
return () => {
|
|
197
|
-
parentScrollLockCount = Math.max(0, parentScrollLockCount - 1);
|
|
198
|
-
if (parentScrollLockCount === 0) {
|
|
199
|
-
parentScrollLocked.forEach(({
|
|
197
|
+
parentScrollLockCount$1 = Math.max(0, parentScrollLockCount$1 - 1);
|
|
198
|
+
if (parentScrollLockCount$1 === 0) {
|
|
199
|
+
parentScrollLocked$1.forEach(({
|
|
200
200
|
el,
|
|
201
201
|
prev
|
|
202
202
|
}) => {
|
|
203
203
|
el.style.overflow = prev.overflow;
|
|
204
204
|
el.style.overscrollBehavior = prev.overscrollBehavior;
|
|
205
205
|
});
|
|
206
|
-
parentScrollLocked = [];
|
|
206
|
+
parentScrollLocked$1 = [];
|
|
207
207
|
}
|
|
208
208
|
};
|
|
209
209
|
};
|
|
210
|
-
const useLockParentScroll = (enabled, getScrollElement) => {
|
|
210
|
+
const useLockParentScroll$1 = (enabled, getScrollElement) => {
|
|
211
211
|
react.useEffect(() => {
|
|
212
212
|
if (!enabled) {
|
|
213
213
|
return undefined;
|
|
214
214
|
}
|
|
215
|
-
return lockParentScroll(getScrollElement);
|
|
215
|
+
return lockParentScroll$1(getScrollElement);
|
|
216
216
|
}, [enabled, getScrollElement]);
|
|
217
217
|
};
|
|
218
|
-
const sizeStyleVars = (size, hasFooter) => {
|
|
218
|
+
const sizeStyleVars$1 = (size, hasFooter) => {
|
|
219
219
|
const minBase = size === 'small' ? 300 : 500;
|
|
220
220
|
const chrome = 48 + (hasFooter ? 58 : 0);
|
|
221
221
|
const minHeight = `${Math.max(0, minBase - chrome)}px`;
|
|
@@ -254,23 +254,23 @@ const ModalOuter = ({
|
|
|
254
254
|
}) => {
|
|
255
255
|
const effectiveNoPadding = noPadding ?? bodyScroll === false;
|
|
256
256
|
const bodyInner = /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
257
|
-
className: classnames__default["default"](
|
|
258
|
-
[
|
|
257
|
+
className: classnames__default["default"](modalStyle['modal-body-inner'], 'modal-body-inner', {
|
|
258
|
+
[modalStyle['no-padding']]: effectiveNoPadding
|
|
259
259
|
}),
|
|
260
260
|
children: children
|
|
261
261
|
});
|
|
262
|
-
const bodyClassName = classnames__default["default"](
|
|
262
|
+
const bodyClassName = classnames__default["default"](modalStyle['modal-body'], 'modal-body');
|
|
263
263
|
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
264
|
-
className: classnames__default["default"](
|
|
265
|
-
[
|
|
266
|
-
[
|
|
267
|
-
[
|
|
268
|
-
[
|
|
264
|
+
className: classnames__default["default"](modalStyle['modal-outer'], 'modal-container', {
|
|
265
|
+
[modalStyle['is-mobile']]: isMobile,
|
|
266
|
+
[modalStyle['no-title']]: !title,
|
|
267
|
+
[modalStyle['no-footer']]: footer === null && footerButtons === undefined,
|
|
268
|
+
[modalStyle['no-padding']]: effectiveNoPadding
|
|
269
269
|
}),
|
|
270
270
|
"data-testid": "react-modal",
|
|
271
271
|
children: [closable === false ? null : /*#__PURE__*/jsxRuntime.jsx(antd.Button, {
|
|
272
272
|
"data-testid": "react-modal-close-btn",
|
|
273
|
-
className: classnames__default["default"](
|
|
273
|
+
className: classnames__default["default"](modalStyle['modal-close'], 'modal-close'),
|
|
274
274
|
type: "text",
|
|
275
275
|
icon: /*#__PURE__*/jsxRuntime.jsx(icons.CloseOutlined, {}),
|
|
276
276
|
onClick: e => {
|
|
@@ -278,7 +278,7 @@ const ModalOuter = ({
|
|
|
278
278
|
onClose && onClose();
|
|
279
279
|
}
|
|
280
280
|
}), title ? /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
281
|
-
className: classnames__default["default"](
|
|
281
|
+
className: classnames__default["default"](modalStyle['modal-title'], 'modal-title'),
|
|
282
282
|
children: title
|
|
283
283
|
}) : null, bodyScroll !== false ? /*#__PURE__*/jsxRuntime.jsx(SimpleBar__default["default"], {
|
|
284
284
|
className: bodyClassName,
|
|
@@ -287,7 +287,7 @@ const ModalOuter = ({
|
|
|
287
287
|
},
|
|
288
288
|
children: bodyInner
|
|
289
289
|
}) : /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
290
|
-
className: classnames__default["default"](bodyClassName,
|
|
290
|
+
className: classnames__default["default"](bodyClassName, modalStyle['body-scroll-off']),
|
|
291
291
|
children: bodyInner
|
|
292
292
|
}), footer === null && footerButtons === undefined ? null : /*#__PURE__*/jsxRuntime.jsx(Footer, {
|
|
293
293
|
footer: footer,
|
|
@@ -324,11 +324,12 @@ const computedCommonProps = ({
|
|
|
324
324
|
classNames: propsClassNames,
|
|
325
325
|
styles: propsStyles,
|
|
326
326
|
style: propsStyle,
|
|
327
|
+
modalRender,
|
|
327
328
|
...props
|
|
328
329
|
}) => {
|
|
329
330
|
const useMobileLayout = isMobile && mobileFullscreen !== false;
|
|
330
331
|
const hasFooter = !(footer === null && footerButtons === undefined);
|
|
331
|
-
const sizeVars = sizeStyleVars(size, hasFooter);
|
|
332
|
+
const sizeVars = sizeStyleVars$1(size, hasFooter);
|
|
332
333
|
const {
|
|
333
334
|
width,
|
|
334
335
|
...cssVars
|
|
@@ -337,36 +338,37 @@ const computedCommonProps = ({
|
|
|
337
338
|
const opts = Object.assign({}, options, {
|
|
338
339
|
close: onClose
|
|
339
340
|
});
|
|
340
|
-
|
|
341
|
-
title: renderWithOptions(title, opts),
|
|
341
|
+
const modalPanel = /*#__PURE__*/jsxRuntime.jsx(ModalOuter, {
|
|
342
|
+
title: renderWithOptions$1(title, opts),
|
|
342
343
|
closable: closable,
|
|
343
344
|
onClose: onClose,
|
|
344
345
|
onConfirm: onConfirm,
|
|
345
346
|
confirmText: confirmText,
|
|
346
347
|
onCancel: onCancel,
|
|
347
348
|
cancelText: cancelText,
|
|
348
|
-
footerButtons: renderWithOptions(footerButtons, opts),
|
|
349
|
+
footerButtons: renderWithOptions$1(footerButtons, opts),
|
|
349
350
|
noPadding: noPadding,
|
|
350
|
-
footer: renderWithOptions(footer, opts),
|
|
351
|
+
footer: renderWithOptions$1(footer, opts),
|
|
351
352
|
targetProps: opts,
|
|
352
353
|
isMobile: useMobileLayout,
|
|
353
354
|
bodyScroll: bodyScroll,
|
|
354
|
-
children: renderWithOptions(children, opts)
|
|
355
|
+
children: renderWithOptions$1(children, opts)
|
|
355
356
|
});
|
|
357
|
+
return typeof modalRender === 'function' ? modalRender(modalPanel) : modalPanel;
|
|
356
358
|
};
|
|
357
359
|
return {
|
|
358
360
|
...props,
|
|
359
361
|
icon: null,
|
|
360
362
|
centered: !useMobileLayout,
|
|
361
363
|
width: props.width ?? (useMobileLayout ? 'var(--kne-modal-viewport-width, 100vw)' : width),
|
|
362
|
-
wrapClassName: classnames__default["default"](wrapClassName,
|
|
364
|
+
wrapClassName: classnames__default["default"](wrapClassName, modalStyle['modal-wrap'], useMobileLayout ? modalStyle['modal-wrap-fullscreen'] : modalStyle['modal-wrap-centered'], useMobileLayout && fixedModeClass, modalRender && modalStyle['modal-form-host']),
|
|
363
365
|
classNames: Object.assign({}, propsClassNames, {
|
|
364
|
-
mask: classnames__default["default"](propsClassNames?.mask, useMobileLayout &&
|
|
365
|
-
container: classnames__default["default"](
|
|
366
|
-
body: classnames__default["default"](
|
|
367
|
-
footer: classnames__default["default"](
|
|
368
|
-
header: classnames__default["default"](
|
|
369
|
-
content: classnames__default["default"](
|
|
366
|
+
mask: classnames__default["default"](propsClassNames?.mask, useMobileLayout && modalStyle['modal-mask-fullscreen'], useMobileLayout && fixedModeClass),
|
|
367
|
+
container: classnames__default["default"](modalStyle['modal-container'], useMobileLayout && modalStyle['is-mobile'], propsClassNames?.container),
|
|
368
|
+
body: classnames__default["default"](modalStyle['modal-antd-body'], useMobileLayout && modalStyle['is-mobile'], propsClassNames?.body),
|
|
369
|
+
footer: classnames__default["default"](modalStyle['modal-antd-footer'], propsClassNames?.footer),
|
|
370
|
+
header: classnames__default["default"](modalStyle['modal-antd-header'], propsClassNames?.header),
|
|
371
|
+
content: classnames__default["default"](modalStyle['modal-container'], useMobileLayout && modalStyle['is-mobile'], propsClassNames?.content)
|
|
370
372
|
}),
|
|
371
373
|
title: null,
|
|
372
374
|
maskClosable: Object.prototype.hasOwnProperty.call(props, 'maskClosable') ? props.maskClosable : false,
|
|
@@ -374,8 +376,8 @@ const computedCommonProps = ({
|
|
|
374
376
|
footer: null,
|
|
375
377
|
closable: false,
|
|
376
378
|
onCancel: onClose,
|
|
377
|
-
className: classnames__default["default"](className,
|
|
378
|
-
[
|
|
379
|
+
className: classnames__default["default"](className, modalStyle['modal'], modalStyle[size], {
|
|
380
|
+
[modalStyle['is-mobile']]: useMobileLayout
|
|
379
381
|
}),
|
|
380
382
|
style: Object.assign({}, cssVars, propsStyle, useMobileLayout ? {
|
|
381
383
|
'--kne-modal-viewport-gutter': '0px',
|
|
@@ -433,11 +435,11 @@ const Modal = withLocale(({
|
|
|
433
435
|
getPopupContainer,
|
|
434
436
|
anchorRef
|
|
435
437
|
} = responsiveUtils.useMobilePopupMount({
|
|
436
|
-
...viewportPopupMountOptions,
|
|
437
|
-
getPopupContainer: wrapCustomGetContainer(getContainer)
|
|
438
|
+
...viewportPopupMountOptions$1,
|
|
439
|
+
getPopupContainer: wrapCustomGetContainer$2(getContainer)
|
|
438
440
|
});
|
|
439
441
|
const getScrollElement = responsiveUtils.useScrollElement();
|
|
440
|
-
useLockParentScroll(!!open, getScrollElement);
|
|
442
|
+
useLockParentScroll$1(!!open, getScrollElement);
|
|
441
443
|
const setAnchorRef = node => {
|
|
442
444
|
hostRef.current = node;
|
|
443
445
|
anchorRef(node);
|
|
@@ -450,7 +452,7 @@ const Modal = withLocale(({
|
|
|
450
452
|
return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
451
453
|
children: [/*#__PURE__*/jsxRuntime.jsx("span", {
|
|
452
454
|
ref: setAnchorRef,
|
|
453
|
-
className:
|
|
455
|
+
className: modalStyle['modal-host'],
|
|
454
456
|
"aria-hidden": "true"
|
|
455
457
|
}), /*#__PURE__*/jsxRuntime.jsx(antd.Modal, {
|
|
456
458
|
...computedCommonProps(Object.assign({}, props, {
|
|
@@ -473,7 +475,7 @@ const useModal = () => {
|
|
|
473
475
|
const {
|
|
474
476
|
resolveMount,
|
|
475
477
|
getPopupContainer
|
|
476
|
-
} = responsiveUtils.useMobilePopupMount(viewportPopupMountOptions);
|
|
478
|
+
} = responsiveUtils.useMobilePopupMount(viewportPopupMountOptions$1);
|
|
477
479
|
const getScrollElement = responsiveUtils.useScrollElement();
|
|
478
480
|
return props => {
|
|
479
481
|
const anchor = typeof document !== 'undefined' ? document.activeElement : null;
|
|
@@ -481,7 +483,7 @@ const useModal = () => {
|
|
|
481
483
|
isMobile,
|
|
482
484
|
fixedModeClass
|
|
483
485
|
} = resolveMount(anchor);
|
|
484
|
-
const unlock = lockParentScroll(getScrollElement);
|
|
486
|
+
const unlock = lockParentScroll$1(getScrollElement);
|
|
485
487
|
const api = {};
|
|
486
488
|
const {
|
|
487
489
|
afterClose: userAfterClose,
|
|
@@ -520,7 +522,799 @@ const useModal = () => {
|
|
|
520
522
|
};
|
|
521
523
|
};
|
|
522
524
|
|
|
523
|
-
|
|
525
|
+
var style = {"kne-responsive-boundary":"kne-react-modal_qwqLr","kne-responsive-scroll":"kne-react-modal_vmry7","drawer":"kne-react-modal_cDsbq","small":"kne-react-modal_3QgK-","is-mobile":"kne-react-modal_FFf73","large":"kne-react-modal_8lell","drawer-body-inner":"kne-react-modal_xgX4D","drawer-antd-header":"kne-react-modal_3EUxr","drawer-antd-footer":"kne-react-modal_2G81L","drawer-antd-body":"kne-react-modal_eKVMu","drawer-outer":"kne-react-modal_P3Cw8","no-title":"kne-react-modal_upRot","no-footer":"kne-react-modal_j4sGu","no-padding":"kne-react-modal_pg37M","drawer-title":"kne-react-modal_-hw5V","drawer-body":"kne-react-modal_nJj7Y","body-scroll-off":"kne-react-modal_2Wh1H","modal-footer-extra":"kne-react-modal_M4hy9","drawer-close":"kne-react-modal_dVh38","drawer-host":"kne-react-modal_Nsxi9","drawer-host-render":"kne-react-modal_iGDWP","drawer-panel-host":"kne-react-modal_A0h-2","drawer-panel-body":"kne-react-modal_E4tcc","drawer-form-host":"kne-react-modal_vKkQW","drawer-wrapper-mobile":"kne-react-modal_vsxOs","drawer-wrapper-mobile-vertical":"kne-react-modal_HG8Vz","drawer-root-mobile":"kne-react-modal_G-qXe"};
|
|
526
|
+
|
|
527
|
+
const DrawerLocaleRoot = withLocale(({
|
|
528
|
+
children
|
|
529
|
+
}) => children);
|
|
530
|
+
const VIEWPORT_EXAMPLE_SELECTORS$2 = ['.example-driver-device-scroll'];
|
|
531
|
+
const boundaryPopupMountOptions$1 = {
|
|
532
|
+
cover: 'boundary',
|
|
533
|
+
exampleSelectors: VIEWPORT_EXAMPLE_SELECTORS$2
|
|
534
|
+
};
|
|
535
|
+
const renderWithOptions = (value, options) => {
|
|
536
|
+
if (typeof value === 'function') {
|
|
537
|
+
return value(options);
|
|
538
|
+
}
|
|
539
|
+
return value;
|
|
540
|
+
};
|
|
541
|
+
const wrapCustomGetContainer$1 = customGetContainer => {
|
|
542
|
+
if (!customGetContainer) {
|
|
543
|
+
return undefined;
|
|
544
|
+
}
|
|
545
|
+
if (typeof customGetContainer === 'function') {
|
|
546
|
+
return triggerNode => customGetContainer(triggerNode) || null;
|
|
547
|
+
}
|
|
548
|
+
return () => customGetContainer;
|
|
549
|
+
};
|
|
550
|
+
const isVerticalPlacement = placement => placement === 'top' || placement === 'bottom';
|
|
551
|
+
const findParentDrawerMountHost = node => {
|
|
552
|
+
if (!node || typeof node.closest !== 'function') {
|
|
553
|
+
return null;
|
|
554
|
+
}
|
|
555
|
+
const parentRoot = node.closest('.ant-drawer-root');
|
|
556
|
+
if (!parentRoot) {
|
|
557
|
+
return null;
|
|
558
|
+
}
|
|
559
|
+
return parentRoot.parentElement || (typeof document !== 'undefined' ? document.body : null);
|
|
560
|
+
};
|
|
561
|
+
const resolveDrawerGetContainer = ({
|
|
562
|
+
customGetContainer,
|
|
563
|
+
getPopupContainer,
|
|
564
|
+
getHostNode
|
|
565
|
+
}) => {
|
|
566
|
+
const wrappedCustom = wrapCustomGetContainer$1(customGetContainer);
|
|
567
|
+
return triggerNode => {
|
|
568
|
+
if (wrappedCustom) {
|
|
569
|
+
const custom = wrappedCustom(triggerNode);
|
|
570
|
+
if (custom) {
|
|
571
|
+
return custom;
|
|
572
|
+
}
|
|
573
|
+
}
|
|
574
|
+
const from = triggerNode || (typeof getHostNode === 'function' ? getHostNode() : null);
|
|
575
|
+
const nestedHost = findParentDrawerMountHost(from);
|
|
576
|
+
if (nestedHost) {
|
|
577
|
+
return nestedHost;
|
|
578
|
+
}
|
|
579
|
+
return getPopupContainer(triggerNode);
|
|
580
|
+
};
|
|
581
|
+
};
|
|
582
|
+
let parentScrollLockCount = 0;
|
|
583
|
+
let parentScrollLocked = [];
|
|
584
|
+
const lockParentScroll = getScrollElement => {
|
|
585
|
+
parentScrollLockCount += 1;
|
|
586
|
+
if (parentScrollLockCount === 1) {
|
|
587
|
+
const targets = [document.body];
|
|
588
|
+
const scrollEl = typeof getScrollElement === 'function' ? getScrollElement() : null;
|
|
589
|
+
if (scrollEl && scrollEl !== document.body && !targets.includes(scrollEl)) {
|
|
590
|
+
targets.push(scrollEl);
|
|
591
|
+
}
|
|
592
|
+
parentScrollLocked = targets.map(el => {
|
|
593
|
+
const prev = {
|
|
594
|
+
overflow: el.style.overflow,
|
|
595
|
+
overscrollBehavior: el.style.overscrollBehavior
|
|
596
|
+
};
|
|
597
|
+
el.style.overflow = 'hidden';
|
|
598
|
+
el.style.overscrollBehavior = 'none';
|
|
599
|
+
return {
|
|
600
|
+
el,
|
|
601
|
+
prev
|
|
602
|
+
};
|
|
603
|
+
});
|
|
604
|
+
}
|
|
605
|
+
return () => {
|
|
606
|
+
parentScrollLockCount = Math.max(0, parentScrollLockCount - 1);
|
|
607
|
+
if (parentScrollLockCount === 0) {
|
|
608
|
+
parentScrollLocked.forEach(({
|
|
609
|
+
el,
|
|
610
|
+
prev
|
|
611
|
+
}) => {
|
|
612
|
+
el.style.overflow = prev.overflow;
|
|
613
|
+
el.style.overscrollBehavior = prev.overscrollBehavior;
|
|
614
|
+
});
|
|
615
|
+
parentScrollLocked = [];
|
|
616
|
+
}
|
|
617
|
+
};
|
|
618
|
+
};
|
|
619
|
+
const useLockParentScroll = (enabled, getScrollElement) => {
|
|
620
|
+
react.useEffect(() => {
|
|
621
|
+
if (!enabled) {
|
|
622
|
+
return undefined;
|
|
623
|
+
}
|
|
624
|
+
return lockParentScroll(getScrollElement);
|
|
625
|
+
}, [enabled, getScrollElement]);
|
|
626
|
+
};
|
|
627
|
+
const sizeStyleVars = (size, hasFooter) => {
|
|
628
|
+
const minBase = size === 'small' ? 300 : 500;
|
|
629
|
+
const chrome = 48 + (hasFooter ? 69 : 0);
|
|
630
|
+
const minHeight = `${Math.max(0, minBase - chrome)}px`;
|
|
631
|
+
const largeDim = typeof window !== 'undefined' ? `${Math.min(window.innerWidth - 64, 1500)}px` : '1500px';
|
|
632
|
+
if (size === 'large') {
|
|
633
|
+
return {
|
|
634
|
+
dimension: largeDim,
|
|
635
|
+
'--kne-drawer-body-min-height': minHeight
|
|
636
|
+
};
|
|
637
|
+
}
|
|
638
|
+
if (size === 'small') {
|
|
639
|
+
return {
|
|
640
|
+
dimension: '600px',
|
|
641
|
+
'--kne-drawer-body-min-height': minHeight
|
|
642
|
+
};
|
|
643
|
+
}
|
|
644
|
+
return {
|
|
645
|
+
dimension: '1000px',
|
|
646
|
+
'--kne-drawer-body-min-height': minHeight
|
|
647
|
+
};
|
|
648
|
+
};
|
|
649
|
+
const DrawerOuter = ({
|
|
650
|
+
title,
|
|
651
|
+
footer,
|
|
652
|
+
footerButtons,
|
|
653
|
+
noPadding,
|
|
654
|
+
onClose,
|
|
655
|
+
closable,
|
|
656
|
+
onConfirm,
|
|
657
|
+
onCancel,
|
|
658
|
+
children,
|
|
659
|
+
targetProps,
|
|
660
|
+
cancelText,
|
|
661
|
+
confirmText,
|
|
662
|
+
isMobile,
|
|
663
|
+
bodyScroll
|
|
664
|
+
}) => {
|
|
665
|
+
const effectiveNoPadding = noPadding ?? bodyScroll === false;
|
|
666
|
+
const bodyInner = /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
667
|
+
className: classnames__default["default"](style['drawer-body-inner'], 'drawer-body-inner', 'modal-body-inner', {
|
|
668
|
+
[style['no-padding']]: effectiveNoPadding
|
|
669
|
+
}),
|
|
670
|
+
children: children
|
|
671
|
+
});
|
|
672
|
+
const bodyClassName = classnames__default["default"](style['drawer-body'], 'drawer-body', 'modal-body');
|
|
673
|
+
return /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
674
|
+
className: classnames__default["default"](style['drawer-outer'], 'drawer-container', {
|
|
675
|
+
[style['is-mobile']]: isMobile,
|
|
676
|
+
[style['no-title']]: !title,
|
|
677
|
+
[style['no-footer']]: footer === null && footerButtons === undefined,
|
|
678
|
+
[style['no-padding']]: effectiveNoPadding
|
|
679
|
+
}),
|
|
680
|
+
"data-testid": "react-drawer",
|
|
681
|
+
children: [closable === false ? null : /*#__PURE__*/jsxRuntime.jsx(antd.Button, {
|
|
682
|
+
"data-testid": "react-drawer-close-btn",
|
|
683
|
+
className: classnames__default["default"](style['drawer-close'], 'drawer-close'),
|
|
684
|
+
type: "text",
|
|
685
|
+
icon: /*#__PURE__*/jsxRuntime.jsx(icons.CloseOutlined, {}),
|
|
686
|
+
onClick: e => {
|
|
687
|
+
e.stopPropagation();
|
|
688
|
+
onClose && onClose();
|
|
689
|
+
}
|
|
690
|
+
}), title ? /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
691
|
+
className: classnames__default["default"](style['drawer-title'], 'drawer-title', 'modal-title'),
|
|
692
|
+
children: title
|
|
693
|
+
}) : null, bodyScroll !== false ? /*#__PURE__*/jsxRuntime.jsx(SimpleBar__default["default"], {
|
|
694
|
+
className: bodyClassName,
|
|
695
|
+
style: {
|
|
696
|
+
height: 'var(--kne-drawer-body-height)'
|
|
697
|
+
},
|
|
698
|
+
children: bodyInner
|
|
699
|
+
}) : /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
700
|
+
className: classnames__default["default"](bodyClassName, style['body-scroll-off']),
|
|
701
|
+
children: bodyInner
|
|
702
|
+
}), footer === null && footerButtons === undefined ? null : /*#__PURE__*/jsxRuntime.jsx(Footer, {
|
|
703
|
+
footer: footer,
|
|
704
|
+
footerButtons: footerButtons,
|
|
705
|
+
onConfirm: onConfirm,
|
|
706
|
+
confirmText: confirmText,
|
|
707
|
+
onCancel: onCancel,
|
|
708
|
+
cancelText: cancelText,
|
|
709
|
+
onClose: onClose,
|
|
710
|
+
targetProps: targetProps,
|
|
711
|
+
isMobile: isMobile
|
|
712
|
+
})]
|
|
713
|
+
});
|
|
714
|
+
};
|
|
715
|
+
const computedDrawerProps = ({
|
|
716
|
+
children,
|
|
717
|
+
footer,
|
|
718
|
+
footerButtons,
|
|
719
|
+
className,
|
|
720
|
+
size = 'default',
|
|
721
|
+
placement = 'right',
|
|
722
|
+
title,
|
|
723
|
+
onClose,
|
|
724
|
+
onConfirm,
|
|
725
|
+
confirmText,
|
|
726
|
+
onCancel,
|
|
727
|
+
cancelText,
|
|
728
|
+
closable,
|
|
729
|
+
noPadding,
|
|
730
|
+
bodyScroll = true,
|
|
731
|
+
isMobile,
|
|
732
|
+
fixedModeClass,
|
|
733
|
+
rootClassName,
|
|
734
|
+
classNames: propsClassNames,
|
|
735
|
+
styles: propsStyles,
|
|
736
|
+
style: propsStyle,
|
|
737
|
+
width: propsWidth,
|
|
738
|
+
height: propsHeight,
|
|
739
|
+
modalRender,
|
|
740
|
+
drawerRender,
|
|
741
|
+
...props
|
|
742
|
+
}) => {
|
|
743
|
+
const vertical = isVerticalPlacement(placement);
|
|
744
|
+
const hasFooter = !(footer === null && footerButtons === undefined);
|
|
745
|
+
const {
|
|
746
|
+
dimension,
|
|
747
|
+
...cssVars
|
|
748
|
+
} = sizeStyleVars(size, hasFooter);
|
|
749
|
+
const sizeProp = vertical ? {
|
|
750
|
+
height: propsHeight ?? dimension
|
|
751
|
+
} : {
|
|
752
|
+
width: propsWidth ?? dimension
|
|
753
|
+
};
|
|
754
|
+
const runChildren = options => {
|
|
755
|
+
const opts = Object.assign({}, options, {
|
|
756
|
+
close: onClose
|
|
757
|
+
});
|
|
758
|
+
const drawerPanel = /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
759
|
+
className: classnames__default["default"](style['drawer-panel-host'], 'drawer-panel-host'),
|
|
760
|
+
children: /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
761
|
+
className: classnames__default["default"](style['drawer-panel-body'], 'drawer-panel-body'),
|
|
762
|
+
children: /*#__PURE__*/jsxRuntime.jsx(DrawerOuter, {
|
|
763
|
+
title: renderWithOptions(title, opts),
|
|
764
|
+
closable: closable,
|
|
765
|
+
onClose: onClose,
|
|
766
|
+
onConfirm: onConfirm,
|
|
767
|
+
confirmText: confirmText,
|
|
768
|
+
onCancel: onCancel,
|
|
769
|
+
cancelText: cancelText,
|
|
770
|
+
footerButtons: renderWithOptions(footerButtons, opts),
|
|
771
|
+
noPadding: noPadding,
|
|
772
|
+
footer: renderWithOptions(footer, opts),
|
|
773
|
+
targetProps: opts,
|
|
774
|
+
isMobile: isMobile,
|
|
775
|
+
bodyScroll: bodyScroll,
|
|
776
|
+
children: renderWithOptions(children, opts)
|
|
777
|
+
})
|
|
778
|
+
})
|
|
779
|
+
});
|
|
780
|
+
return typeof modalRender === 'function' ? modalRender(drawerPanel) : drawerPanel;
|
|
781
|
+
};
|
|
782
|
+
const mobileWrapperClass = isMobile ? vertical ? style['drawer-wrapper-mobile-vertical'] : style['drawer-wrapper-mobile'] : null;
|
|
783
|
+
const panelLayoutStyles = {
|
|
784
|
+
height: '100%',
|
|
785
|
+
display: 'flex',
|
|
786
|
+
flexDirection: 'column',
|
|
787
|
+
padding: 0
|
|
788
|
+
};
|
|
789
|
+
return {
|
|
790
|
+
...props,
|
|
791
|
+
...(drawerRender ? {
|
|
792
|
+
drawerRender
|
|
793
|
+
} : null),
|
|
794
|
+
placement,
|
|
795
|
+
...sizeProp,
|
|
796
|
+
title: null,
|
|
797
|
+
maskClosable: Object.prototype.hasOwnProperty.call(props, 'maskClosable') ? props.maskClosable : false,
|
|
798
|
+
destroyOnHidden: true,
|
|
799
|
+
footer: null,
|
|
800
|
+
closable: false,
|
|
801
|
+
onClose,
|
|
802
|
+
rootClassName: classnames__default["default"](rootClassName, isMobile && style['drawer-root-mobile'], isMobile && fixedModeClass, modalRender && style['drawer-form-host'], drawerRender && style['drawer-host-render']),
|
|
803
|
+
classNames: Object.assign({}, propsClassNames, {
|
|
804
|
+
header: classnames__default["default"](style['drawer-antd-header'], propsClassNames?.header),
|
|
805
|
+
footer: classnames__default["default"](style['drawer-antd-footer'], propsClassNames?.footer),
|
|
806
|
+
body: classnames__default["default"](style['drawer-antd-body'], isMobile && style['is-mobile'], propsClassNames?.body),
|
|
807
|
+
wrapper: classnames__default["default"](propsClassNames?.wrapper, mobileWrapperClass),
|
|
808
|
+
mask: classnames__default["default"](propsClassNames?.mask, isMobile && fixedModeClass)
|
|
809
|
+
}),
|
|
810
|
+
className: classnames__default["default"](className, style['drawer'], style[size], {
|
|
811
|
+
[style['is-mobile']]: isMobile
|
|
812
|
+
}),
|
|
813
|
+
style: Object.assign({}, cssVars, propsStyle, vertical ? {
|
|
814
|
+
'--kne-drawer-viewport-height': dimension
|
|
815
|
+
} : null),
|
|
816
|
+
styles: {
|
|
817
|
+
...propsStyles,
|
|
818
|
+
body: {
|
|
819
|
+
padding: 0,
|
|
820
|
+
...propsStyles?.body,
|
|
821
|
+
flex: '1 1 auto',
|
|
822
|
+
minHeight: 0,
|
|
823
|
+
display: 'flex',
|
|
824
|
+
flexDirection: 'column',
|
|
825
|
+
overflow: 'hidden',
|
|
826
|
+
...(isMobile ? {
|
|
827
|
+
height: '100%',
|
|
828
|
+
maxHeight: '100%'
|
|
829
|
+
} : null)
|
|
830
|
+
},
|
|
831
|
+
section: {
|
|
832
|
+
...panelLayoutStyles,
|
|
833
|
+
...propsStyles?.section,
|
|
834
|
+
...propsStyles?.content
|
|
835
|
+
},
|
|
836
|
+
wrapper: {
|
|
837
|
+
...propsStyles?.wrapper,
|
|
838
|
+
...(vertical ? {
|
|
839
|
+
height: 'var(--kne-drawer-viewport-height, 100vh)',
|
|
840
|
+
maxHeight: '100%'
|
|
841
|
+
} : {
|
|
842
|
+
height: '100%'
|
|
843
|
+
}),
|
|
844
|
+
...(isMobile && !vertical ? {
|
|
845
|
+
width: 'var(--kne-viewport-width, 100vw)',
|
|
846
|
+
maxWidth: '100%'
|
|
847
|
+
} : null),
|
|
848
|
+
...(isMobile && vertical ? {
|
|
849
|
+
height: 'var(--kne-viewport-height, 100vh)',
|
|
850
|
+
maxHeight: '100%'
|
|
851
|
+
} : null)
|
|
852
|
+
}
|
|
853
|
+
},
|
|
854
|
+
children: /*#__PURE__*/jsxRuntime.jsx(DrawerLocaleRoot, {
|
|
855
|
+
children: runChildren({})
|
|
856
|
+
})
|
|
857
|
+
};
|
|
858
|
+
};
|
|
859
|
+
const Drawer = withLocale(({
|
|
860
|
+
size = 'default',
|
|
861
|
+
placement = 'right',
|
|
862
|
+
getContainer,
|
|
863
|
+
open,
|
|
864
|
+
bodyScroll = true,
|
|
865
|
+
...props
|
|
866
|
+
}) => {
|
|
867
|
+
const hostRef = react.useRef(null);
|
|
868
|
+
const {
|
|
869
|
+
isMobile,
|
|
870
|
+
fixedModeClass,
|
|
871
|
+
getPopupContainer,
|
|
872
|
+
anchorRef
|
|
873
|
+
} = responsiveUtils.useMobilePopupMount({
|
|
874
|
+
...boundaryPopupMountOptions$1,
|
|
875
|
+
getPopupContainer: wrapCustomGetContainer$1(getContainer)
|
|
876
|
+
});
|
|
877
|
+
const getScrollElement = responsiveUtils.useScrollElement();
|
|
878
|
+
useLockParentScroll(!!open, getScrollElement);
|
|
879
|
+
const setAnchorRef = node => {
|
|
880
|
+
hostRef.current = node;
|
|
881
|
+
anchorRef(node);
|
|
882
|
+
};
|
|
883
|
+
const getDrawerContainer = resolveDrawerGetContainer({
|
|
884
|
+
customGetContainer: getContainer,
|
|
885
|
+
getPopupContainer,
|
|
886
|
+
getHostNode: () => hostRef.current
|
|
887
|
+
});
|
|
888
|
+
return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
889
|
+
children: [/*#__PURE__*/jsxRuntime.jsx("span", {
|
|
890
|
+
ref: setAnchorRef,
|
|
891
|
+
className: style['drawer-host'],
|
|
892
|
+
"aria-hidden": "true"
|
|
893
|
+
}), /*#__PURE__*/jsxRuntime.jsx(antd.Drawer, {
|
|
894
|
+
...computedDrawerProps(Object.assign({}, props, {
|
|
895
|
+
size,
|
|
896
|
+
placement,
|
|
897
|
+
isMobile,
|
|
898
|
+
open,
|
|
899
|
+
fixedModeClass,
|
|
900
|
+
bodyScroll
|
|
901
|
+
})),
|
|
902
|
+
open: open,
|
|
903
|
+
getContainer: getDrawerContainer
|
|
904
|
+
})]
|
|
905
|
+
});
|
|
906
|
+
});
|
|
907
|
+
|
|
908
|
+
const usePatchElement = () => {
|
|
909
|
+
const [elements, setElements] = react.useState([]);
|
|
910
|
+
const patchElement = react.useCallback(element => {
|
|
911
|
+
setElements(originElements => [...originElements, element]);
|
|
912
|
+
return () => {
|
|
913
|
+
setElements(originElements => originElements.filter(ele => ele !== element));
|
|
914
|
+
};
|
|
915
|
+
}, []);
|
|
916
|
+
return [elements, patchElement];
|
|
917
|
+
};
|
|
918
|
+
|
|
919
|
+
const VIEWPORT_EXAMPLE_SELECTORS$1 = ['.example-driver-device-scroll'];
|
|
920
|
+
const boundaryPopupMountOptions = {
|
|
921
|
+
cover: 'boundary',
|
|
922
|
+
exampleSelectors: VIEWPORT_EXAMPLE_SELECTORS$1
|
|
923
|
+
};
|
|
924
|
+
const wrapCustomGetContainer = customGetContainer => {
|
|
925
|
+
if (!customGetContainer) {
|
|
926
|
+
return undefined;
|
|
927
|
+
}
|
|
928
|
+
if (typeof customGetContainer === 'function') {
|
|
929
|
+
return triggerNode => customGetContainer(triggerNode) || null;
|
|
930
|
+
}
|
|
931
|
+
return () => customGetContainer;
|
|
932
|
+
};
|
|
933
|
+
const drawerApiRef = {
|
|
934
|
+
current: null
|
|
935
|
+
};
|
|
936
|
+
let hookDrawerUuid = 0;
|
|
937
|
+
const HookDrawer = /*#__PURE__*/react.forwardRef(({
|
|
938
|
+
config,
|
|
939
|
+
afterClose: hookAfterClose
|
|
940
|
+
}, ref) => {
|
|
941
|
+
const [open, setOpen] = react.useState(true);
|
|
942
|
+
const [innerConfig, setInnerConfig] = react.useState(config);
|
|
943
|
+
const hostRef = react.useRef(null);
|
|
944
|
+
const {
|
|
945
|
+
getPopupContainer,
|
|
946
|
+
anchorRef
|
|
947
|
+
} = responsiveUtils.useMobilePopupMount({
|
|
948
|
+
...boundaryPopupMountOptions,
|
|
949
|
+
getPopupContainer: wrapCustomGetContainer(innerConfig.getContainer)
|
|
950
|
+
});
|
|
951
|
+
const close = () => {
|
|
952
|
+
setOpen(false);
|
|
953
|
+
};
|
|
954
|
+
react.useImperativeHandle(ref, () => ({
|
|
955
|
+
destroy: close,
|
|
956
|
+
update: newConfig => {
|
|
957
|
+
setInnerConfig(origin => Object.assign({}, origin, typeof newConfig === 'function' ? newConfig(origin) : newConfig));
|
|
958
|
+
}
|
|
959
|
+
}));
|
|
960
|
+
const {
|
|
961
|
+
getContainer,
|
|
962
|
+
afterClose: userAfterClose,
|
|
963
|
+
...restConfig
|
|
964
|
+
} = innerConfig;
|
|
965
|
+
const mergedAfterClose = function () {
|
|
966
|
+
var args = [].slice.call(arguments);
|
|
967
|
+
hookAfterClose && hookAfterClose(...args);
|
|
968
|
+
userAfterClose && userAfterClose(...args);
|
|
969
|
+
};
|
|
970
|
+
const drawerProps = computedDrawerProps({
|
|
971
|
+
...restConfig,
|
|
972
|
+
onClose: close,
|
|
973
|
+
afterClose: mergedAfterClose
|
|
974
|
+
});
|
|
975
|
+
const getDrawerContainer = resolveDrawerGetContainer({
|
|
976
|
+
customGetContainer: getContainer,
|
|
977
|
+
getPopupContainer,
|
|
978
|
+
getHostNode: () => hostRef.current
|
|
979
|
+
});
|
|
980
|
+
return /*#__PURE__*/jsxRuntime.jsxs(jsxRuntime.Fragment, {
|
|
981
|
+
children: [/*#__PURE__*/jsxRuntime.jsx("span", {
|
|
982
|
+
ref: node => {
|
|
983
|
+
hostRef.current = node;
|
|
984
|
+
anchorRef(node);
|
|
985
|
+
},
|
|
986
|
+
"aria-hidden": "true",
|
|
987
|
+
style: {
|
|
988
|
+
position: 'absolute',
|
|
989
|
+
width: 0,
|
|
990
|
+
height: 0,
|
|
991
|
+
overflow: 'hidden'
|
|
992
|
+
}
|
|
993
|
+
}), /*#__PURE__*/jsxRuntime.jsx(antd.Drawer, {
|
|
994
|
+
...drawerProps,
|
|
995
|
+
open: open,
|
|
996
|
+
getContainer: getDrawerContainer
|
|
997
|
+
})]
|
|
998
|
+
});
|
|
999
|
+
});
|
|
1000
|
+
const ElementsHolder = /*#__PURE__*/react.memo(/*#__PURE__*/react.forwardRef((_props, ref) => {
|
|
1001
|
+
const [elements, patchElement] = usePatchElement();
|
|
1002
|
+
react.useImperativeHandle(ref, () => ({
|
|
1003
|
+
patchElement
|
|
1004
|
+
}), [patchElement]);
|
|
1005
|
+
return /*#__PURE__*/jsxRuntime.jsx(jsxRuntime.Fragment, {
|
|
1006
|
+
children: elements
|
|
1007
|
+
});
|
|
1008
|
+
}));
|
|
1009
|
+
const useDrawerHolder = () => {
|
|
1010
|
+
const holderRef = react.useRef(null);
|
|
1011
|
+
const [actionQueue, setActionQueue] = react.useState([]);
|
|
1012
|
+
const {
|
|
1013
|
+
resolveMount,
|
|
1014
|
+
getPopupContainer
|
|
1015
|
+
} = responsiveUtils.useMobilePopupMount(boundaryPopupMountOptions);
|
|
1016
|
+
const getScrollElement = responsiveUtils.useScrollElement();
|
|
1017
|
+
react.useEffect(() => {
|
|
1018
|
+
if (actionQueue.length) {
|
|
1019
|
+
const cloneQueue = [...actionQueue];
|
|
1020
|
+
cloneQueue.forEach(action => action());
|
|
1021
|
+
setActionQueue([]);
|
|
1022
|
+
}
|
|
1023
|
+
}, [actionQueue]);
|
|
1024
|
+
const drawer = react.useCallback(props => {
|
|
1025
|
+
hookDrawerUuid += 1;
|
|
1026
|
+
const drawerRef = /*#__PURE__*/react.createRef();
|
|
1027
|
+
const api = {};
|
|
1028
|
+
let closeFunc;
|
|
1029
|
+
let unlock = () => {};
|
|
1030
|
+
const runOpen = () => {
|
|
1031
|
+
const anchor = typeof document !== 'undefined' ? document.activeElement : null;
|
|
1032
|
+
const {
|
|
1033
|
+
isMobile,
|
|
1034
|
+
fixedModeClass
|
|
1035
|
+
} = resolveMount(anchor);
|
|
1036
|
+
unlock = lockParentScroll(getScrollElement);
|
|
1037
|
+
const {
|
|
1038
|
+
afterClose: userAfterClose,
|
|
1039
|
+
getContainer: customGetContainer,
|
|
1040
|
+
...restProps
|
|
1041
|
+
} = props;
|
|
1042
|
+
const drawerEl = /*#__PURE__*/jsxRuntime.jsx(HookDrawer, {
|
|
1043
|
+
ref: drawerRef,
|
|
1044
|
+
config: {
|
|
1045
|
+
...restProps,
|
|
1046
|
+
isMobile,
|
|
1047
|
+
fixedModeClass,
|
|
1048
|
+
getContainer: customGetContainer,
|
|
1049
|
+
onClose: () => api.close(),
|
|
1050
|
+
afterClose: function () {
|
|
1051
|
+
unlock();
|
|
1052
|
+
userAfterClose && userAfterClose(...[].slice.call(arguments));
|
|
1053
|
+
}
|
|
1054
|
+
},
|
|
1055
|
+
afterClose: () => {
|
|
1056
|
+
closeFunc && closeFunc();
|
|
1057
|
+
}
|
|
1058
|
+
}, `react-drawer-${hookDrawerUuid}`);
|
|
1059
|
+
closeFunc = holderRef.current?.patchElement(drawerEl);
|
|
1060
|
+
};
|
|
1061
|
+
if (holderRef.current?.patchElement) {
|
|
1062
|
+
runOpen();
|
|
1063
|
+
} else {
|
|
1064
|
+
setActionQueue(prev => [...prev, runOpen]);
|
|
1065
|
+
}
|
|
1066
|
+
api.close = () => {
|
|
1067
|
+
if (drawerRef.current) {
|
|
1068
|
+
drawerRef.current.destroy();
|
|
1069
|
+
} else {
|
|
1070
|
+
setActionQueue(prev => [...prev, () => drawerRef.current?.destroy()]);
|
|
1071
|
+
}
|
|
1072
|
+
};
|
|
1073
|
+
return api;
|
|
1074
|
+
}, [getScrollElement, resolveMount]);
|
|
1075
|
+
return [drawer, /*#__PURE__*/jsxRuntime.jsx(ElementsHolder, {
|
|
1076
|
+
ref: holderRef
|
|
1077
|
+
}, "drawer-elements-holder")];
|
|
1078
|
+
};
|
|
1079
|
+
const DrawerContextHolder = () => {
|
|
1080
|
+
const [drawer, contextHolder] = useDrawerHolder();
|
|
1081
|
+
drawerApiRef.current = drawer;
|
|
1082
|
+
return contextHolder;
|
|
1083
|
+
};
|
|
1084
|
+
const useDrawer = () => {
|
|
1085
|
+
if (!drawerApiRef.current) {
|
|
1086
|
+
throw new Error('useDrawer requires <DrawerContextHolder /> mounted inside <App> before calling useDrawer()');
|
|
1087
|
+
}
|
|
1088
|
+
return drawerApiRef.current;
|
|
1089
|
+
};
|
|
1090
|
+
|
|
1091
|
+
var confirmStyle = {"kne-responsive-boundary":"kne-react-modal_6tGX5","kne-responsive-scroll":"kne-react-modal_DOfki","confirm-modal-wrap":"kne-react-modal_NZArM","is-mobile":"kne-react-modal_PJp65","is-danger":"kne-react-modal_LUqb9","title-icon":"kne-react-modal_WAuWk","titleRow":"kne-react-modal_oEIMf","contentRow":"kne-react-modal_VFlnj","titleIcon":"kne-react-modal_UDO1-","title-icon-confirm":"kne-react-modal_w4spp","title-icon-info":"kne-react-modal_9DX59","title-icon-success":"kne-react-modal_pFvwL","title-icon-warning":"kne-react-modal_Wv7-o","title-icon-error":"kne-react-modal_0cNi0","titleText":"kne-react-modal_vDt06","contentText":"kne-react-modal_i15SX","has-title":"kne-react-modal_reDXC","has-icon":"kne-react-modal_Mpjjc","is-mobile-block":"kne-react-modal_C7-hV"};
|
|
1092
|
+
|
|
1093
|
+
const ConfirmLocaleRoot = withLocale(({
|
|
1094
|
+
children
|
|
1095
|
+
}) => children);
|
|
1096
|
+
const VIEWPORT_EXAMPLE_SELECTORS = ['.example-driver-device-scroll'];
|
|
1097
|
+
const viewportPopupMountOptions = {
|
|
1098
|
+
cover: 'viewport',
|
|
1099
|
+
exampleSelectors: VIEWPORT_EXAMPLE_SELECTORS
|
|
1100
|
+
};
|
|
1101
|
+
const ICON_BY_TYPE = {
|
|
1102
|
+
info: icons.InfoCircleFilled,
|
|
1103
|
+
confirm: icons.ExclamationCircleFilled,
|
|
1104
|
+
warning: icons.ExclamationCircleFilled,
|
|
1105
|
+
error: icons.CloseCircleFilled,
|
|
1106
|
+
success: icons.CheckCircleFilled
|
|
1107
|
+
};
|
|
1108
|
+
const getIconKind = (type, confirmType) => type === 'confirm' ? confirmType : type;
|
|
1109
|
+
const shouldShowDefaultIcon = ({
|
|
1110
|
+
type,
|
|
1111
|
+
danger,
|
|
1112
|
+
icon
|
|
1113
|
+
}) => {
|
|
1114
|
+
if (icon === false || icon === null) {
|
|
1115
|
+
return false;
|
|
1116
|
+
}
|
|
1117
|
+
if (type === 'confirm') {
|
|
1118
|
+
return !!danger;
|
|
1119
|
+
}
|
|
1120
|
+
return ['info', 'success', 'warning', 'error'].includes(type);
|
|
1121
|
+
};
|
|
1122
|
+
const getConfirmIconNode = ({
|
|
1123
|
+
type,
|
|
1124
|
+
confirmType = 'info',
|
|
1125
|
+
danger,
|
|
1126
|
+
icon
|
|
1127
|
+
}) => {
|
|
1128
|
+
if (icon) {
|
|
1129
|
+
return icon;
|
|
1130
|
+
}
|
|
1131
|
+
if (!shouldShowDefaultIcon({
|
|
1132
|
+
type,
|
|
1133
|
+
danger,
|
|
1134
|
+
icon
|
|
1135
|
+
})) {
|
|
1136
|
+
return null;
|
|
1137
|
+
}
|
|
1138
|
+
const kind = getIconKind(type, confirmType);
|
|
1139
|
+
const IconComponent = ICON_BY_TYPE[kind] || ICON_BY_TYPE.info;
|
|
1140
|
+
return /*#__PURE__*/jsxRuntime.jsx(IconComponent, {
|
|
1141
|
+
className: classnames__default["default"](confirmStyle['title-icon'], confirmStyle[`title-icon-${kind}`])
|
|
1142
|
+
});
|
|
1143
|
+
};
|
|
1144
|
+
const buildConfirmContent = ({
|
|
1145
|
+
type,
|
|
1146
|
+
confirmType,
|
|
1147
|
+
title,
|
|
1148
|
+
message,
|
|
1149
|
+
danger,
|
|
1150
|
+
icon,
|
|
1151
|
+
isMobile
|
|
1152
|
+
}) => {
|
|
1153
|
+
const iconNode = getConfirmIconNode({
|
|
1154
|
+
type,
|
|
1155
|
+
confirmType,
|
|
1156
|
+
danger,
|
|
1157
|
+
icon
|
|
1158
|
+
});
|
|
1159
|
+
const mobileClass = isMobile ? confirmStyle['is-mobile-block'] : null;
|
|
1160
|
+
return {
|
|
1161
|
+
title: title ? /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
1162
|
+
className: classnames__default["default"](confirmStyle.titleRow, mobileClass),
|
|
1163
|
+
onClick: e => {
|
|
1164
|
+
e.stopPropagation();
|
|
1165
|
+
},
|
|
1166
|
+
children: [iconNode ? /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
1167
|
+
className: confirmStyle.titleIcon,
|
|
1168
|
+
children: iconNode
|
|
1169
|
+
}) : null, /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
1170
|
+
className: confirmStyle.titleText,
|
|
1171
|
+
children: title
|
|
1172
|
+
})]
|
|
1173
|
+
}) : null,
|
|
1174
|
+
content: /*#__PURE__*/jsxRuntime.jsxs("div", {
|
|
1175
|
+
className: classnames__default["default"](confirmStyle.contentRow, mobileClass, {
|
|
1176
|
+
[confirmStyle['has-title']]: title,
|
|
1177
|
+
[confirmStyle['has-icon']]: !!iconNode && title
|
|
1178
|
+
}),
|
|
1179
|
+
children: [!title && iconNode ? /*#__PURE__*/jsxRuntime.jsx("span", {
|
|
1180
|
+
className: confirmStyle.titleIcon,
|
|
1181
|
+
children: iconNode
|
|
1182
|
+
}) : null, /*#__PURE__*/jsxRuntime.jsx("div", {
|
|
1183
|
+
className: confirmStyle.contentText,
|
|
1184
|
+
children: message
|
|
1185
|
+
})]
|
|
1186
|
+
})
|
|
1187
|
+
};
|
|
1188
|
+
};
|
|
1189
|
+
const mapConfirmProps = (props, {
|
|
1190
|
+
isMobile,
|
|
1191
|
+
fixedModeClass,
|
|
1192
|
+
getPopupContainer,
|
|
1193
|
+
anchor,
|
|
1194
|
+
unlock,
|
|
1195
|
+
userAfterClose
|
|
1196
|
+
}) => {
|
|
1197
|
+
const {
|
|
1198
|
+
type = 'confirm',
|
|
1199
|
+
icon,
|
|
1200
|
+
title,
|
|
1201
|
+
danger,
|
|
1202
|
+
wrapClassName,
|
|
1203
|
+
message,
|
|
1204
|
+
confirmType = 'info',
|
|
1205
|
+
getContainer: customGetContainer,
|
|
1206
|
+
onConfirm,
|
|
1207
|
+
onCancel,
|
|
1208
|
+
confirmText,
|
|
1209
|
+
cancelText,
|
|
1210
|
+
afterClose,
|
|
1211
|
+
zIndex,
|
|
1212
|
+
...otherProps
|
|
1213
|
+
} = {
|
|
1214
|
+
maskClosable: false,
|
|
1215
|
+
...props
|
|
1216
|
+
};
|
|
1217
|
+
const {
|
|
1218
|
+
title: confirmTitle,
|
|
1219
|
+
content
|
|
1220
|
+
} = buildConfirmContent({
|
|
1221
|
+
type,
|
|
1222
|
+
confirmType,
|
|
1223
|
+
title,
|
|
1224
|
+
message,
|
|
1225
|
+
danger,
|
|
1226
|
+
icon,
|
|
1227
|
+
isMobile
|
|
1228
|
+
});
|
|
1229
|
+
return {
|
|
1230
|
+
modalMethod: type,
|
|
1231
|
+
config: {
|
|
1232
|
+
...otherProps,
|
|
1233
|
+
zIndex: zIndex ?? 1100,
|
|
1234
|
+
okText: confirmText ?? otherProps.okText,
|
|
1235
|
+
cancelText: cancelText ?? otherProps.cancelText,
|
|
1236
|
+
onOk: onConfirm ?? otherProps.onOk,
|
|
1237
|
+
onCancel: onCancel ?? otherProps.onCancel,
|
|
1238
|
+
getContainer: resolveModalGetContainer({
|
|
1239
|
+
customGetContainer,
|
|
1240
|
+
getPopupContainer,
|
|
1241
|
+
getHostNode: () => anchor
|
|
1242
|
+
}),
|
|
1243
|
+
centered: true,
|
|
1244
|
+
afterClose: function () {
|
|
1245
|
+
var args = [].slice.call(arguments);
|
|
1246
|
+
unlock();
|
|
1247
|
+
userAfterClose && userAfterClose(...args);
|
|
1248
|
+
afterClose && afterClose(...args);
|
|
1249
|
+
},
|
|
1250
|
+
icon: null,
|
|
1251
|
+
classNames: {
|
|
1252
|
+
mask: classnames__default["default"](isMobile && modalStyle['modal-mask-fullscreen'], isMobile && fixedModeClass, otherProps.classNames?.mask)
|
|
1253
|
+
},
|
|
1254
|
+
wrapClassName: classnames__default["default"](modalStyle['modal-wrap'], confirmStyle['confirm-modal-wrap'], wrapClassName, {
|
|
1255
|
+
[confirmStyle['is-danger']]: danger,
|
|
1256
|
+
[confirmStyle['is-mobile']]: isMobile,
|
|
1257
|
+
[modalStyle['modal-wrap-centered']]: isMobile,
|
|
1258
|
+
[fixedModeClass]: isMobile
|
|
1259
|
+
}),
|
|
1260
|
+
title: confirmTitle ? /*#__PURE__*/jsxRuntime.jsx(ConfirmLocaleRoot, {
|
|
1261
|
+
children: confirmTitle
|
|
1262
|
+
}) : null,
|
|
1263
|
+
content: /*#__PURE__*/jsxRuntime.jsx(ConfirmLocaleRoot, {
|
|
1264
|
+
children: content
|
|
1265
|
+
})
|
|
1266
|
+
}
|
|
1267
|
+
};
|
|
1268
|
+
};
|
|
1269
|
+
const useConfirmModal = () => {
|
|
1270
|
+
const {
|
|
1271
|
+
modal
|
|
1272
|
+
} = antd.App.useApp();
|
|
1273
|
+
const {
|
|
1274
|
+
resolveMount,
|
|
1275
|
+
getPopupContainer
|
|
1276
|
+
} = responsiveUtils.useMobilePopupMount(viewportPopupMountOptions);
|
|
1277
|
+
const getScrollElement = responsiveUtils.useScrollElement();
|
|
1278
|
+
return props => {
|
|
1279
|
+
const anchor = typeof document !== 'undefined' ? document.activeElement : null;
|
|
1280
|
+
const {
|
|
1281
|
+
isMobile,
|
|
1282
|
+
fixedModeClass
|
|
1283
|
+
} = resolveMount(anchor);
|
|
1284
|
+
const unlock = lockParentScroll$1(getScrollElement);
|
|
1285
|
+
const api = {};
|
|
1286
|
+
const {
|
|
1287
|
+
afterClose: userAfterClose,
|
|
1288
|
+
...restProps
|
|
1289
|
+
} = props;
|
|
1290
|
+
const {
|
|
1291
|
+
modalMethod,
|
|
1292
|
+
config
|
|
1293
|
+
} = mapConfirmProps({
|
|
1294
|
+
...restProps,
|
|
1295
|
+
onClose: () => api.close()
|
|
1296
|
+
}, {
|
|
1297
|
+
isMobile,
|
|
1298
|
+
fixedModeClass,
|
|
1299
|
+
getPopupContainer,
|
|
1300
|
+
anchor,
|
|
1301
|
+
unlock,
|
|
1302
|
+
userAfterClose
|
|
1303
|
+
});
|
|
1304
|
+
if (typeof modal[modalMethod] === 'function') {
|
|
1305
|
+
const {
|
|
1306
|
+
destroy
|
|
1307
|
+
} = modal[modalMethod](config);
|
|
1308
|
+
api.close = destroy;
|
|
1309
|
+
} else {
|
|
1310
|
+
unlock();
|
|
1311
|
+
api.close = () => {};
|
|
1312
|
+
}
|
|
1313
|
+
return api;
|
|
1314
|
+
};
|
|
1315
|
+
};
|
|
1316
|
+
|
|
1317
|
+
const ScrollRegion = ({
|
|
524
1318
|
className,
|
|
525
1319
|
inset = false,
|
|
526
1320
|
children,
|
|
@@ -534,7 +1328,7 @@ const ModalScrollRegion = ({
|
|
|
534
1328
|
})
|
|
535
1329
|
});
|
|
536
1330
|
|
|
537
|
-
const
|
|
1331
|
+
const TabsLayout = ({
|
|
538
1332
|
className,
|
|
539
1333
|
destroyOnHidden = true,
|
|
540
1334
|
...props
|
|
@@ -557,7 +1351,7 @@ const resolveColStyle = width => {
|
|
|
557
1351
|
minWidth: 0
|
|
558
1352
|
};
|
|
559
1353
|
};
|
|
560
|
-
const
|
|
1354
|
+
const ColumnsLayout = ({
|
|
561
1355
|
widths,
|
|
562
1356
|
className,
|
|
563
1357
|
children,
|
|
@@ -580,16 +1374,26 @@ const createModalRender = modalDefaults => hostProps => /*#__PURE__*/jsxRuntime.
|
|
|
580
1374
|
...hostProps
|
|
581
1375
|
});
|
|
582
1376
|
|
|
1377
|
+
const createDrawerRender = drawerDefaults => hostProps => /*#__PURE__*/jsxRuntime.jsx(Drawer, {
|
|
1378
|
+
...drawerDefaults,
|
|
1379
|
+
...hostProps
|
|
1380
|
+
});
|
|
1381
|
+
|
|
583
1382
|
const modalClassNames = {
|
|
584
1383
|
stepsForm: 'react-modal-steps-form',
|
|
585
1384
|
splitter: 'react-modal-splitter'
|
|
586
1385
|
};
|
|
587
1386
|
|
|
588
|
-
exports.
|
|
589
|
-
exports.
|
|
590
|
-
exports.
|
|
1387
|
+
exports.ColumnsLayout = ColumnsLayout;
|
|
1388
|
+
exports.Drawer = Drawer;
|
|
1389
|
+
exports.DrawerContextHolder = DrawerContextHolder;
|
|
1390
|
+
exports.ScrollRegion = ScrollRegion;
|
|
1391
|
+
exports.TabsLayout = TabsLayout;
|
|
1392
|
+
exports.createDrawerRender = createDrawerRender;
|
|
591
1393
|
exports.createModalRender = createModalRender;
|
|
592
1394
|
exports["default"] = Modal;
|
|
593
1395
|
exports.modalClassNames = modalClassNames;
|
|
1396
|
+
exports.useConfirmModal = useConfirmModal;
|
|
1397
|
+
exports.useDrawer = useDrawer;
|
|
594
1398
|
exports.useModal = useModal;
|
|
595
1399
|
//# sourceMappingURL=index.js.map
|