@kne/react-modal 0.1.1
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 +2050 -0
- package/dist/index.css +514 -0
- package/dist/index.css.map +1 -0
- package/dist/index.js +595 -0
- package/dist/index.js.map +1 -0
- package/dist/index.modern.js +602 -0
- package/dist/index.modern.js.map +1 -0
- package/dist/locale/en-US.js +7 -0
- package/dist/locale/en-US.js.map +1 -0
- package/dist/locale/en-US.modern.js +7 -0
- package/dist/locale/en-US.modern.js.map +1 -0
- package/dist/locale/zh-CN.js +7 -0
- package/dist/locale/zh-CN.js.map +1 -0
- package/dist/locale/zh-CN.modern.js +7 -0
- package/dist/locale/zh-CN.modern.js.map +1 -0
- package/package.json +113 -0
|
@@ -0,0 +1,602 @@
|
|
|
1
|
+
import { useRef, useEffect, Children } from 'react';
|
|
2
|
+
import { Modal as Modal$1, App, Button, Tabs } from 'antd';
|
|
3
|
+
import { CloseOutlined } from '@ant-design/icons';
|
|
4
|
+
import classnames from 'classnames';
|
|
5
|
+
import { useMobilePopupMount, useScrollElement } from '@kne/responsive-utils';
|
|
6
|
+
import { createWithIntlProvider, useIntl } from '@kne/react-intl';
|
|
7
|
+
import ButtonGroup from '@kne/button-group';
|
|
8
|
+
import { jsxs, jsx, Fragment } from 'react/jsx-runtime';
|
|
9
|
+
import SimpleBar from 'simplebar-react';
|
|
10
|
+
import 'simplebar-react/dist/simplebar.min.css';
|
|
11
|
+
|
|
12
|
+
var styles = {"modal-tabs-layout":"kne-react-modal_nfGH7","modal-columns-layout":"kne-react-modal_ZjINn","modal-columns-layout__col":"kne-react-modal_KJmX4","modal-scroll-region":"kne-react-modal_86VYa","modal-scroll-region-inner":"kne-react-modal_K9DGN","is-inset":"kne-react-modal_HTvLy"};
|
|
13
|
+
|
|
14
|
+
function _extends() {
|
|
15
|
+
return _extends = Object.assign ? Object.assign.bind() : function (n) {
|
|
16
|
+
for (var e = 1; e < arguments.length; e++) {
|
|
17
|
+
var t = arguments[e];
|
|
18
|
+
for (var r in t) ({}).hasOwnProperty.call(t, r) && (n[r] = t[r]);
|
|
19
|
+
}
|
|
20
|
+
return n;
|
|
21
|
+
}, _extends.apply(null, arguments);
|
|
22
|
+
}
|
|
23
|
+
function _objectWithoutPropertiesLoose(r, e) {
|
|
24
|
+
if (null == r) return {};
|
|
25
|
+
var t = {};
|
|
26
|
+
for (var n in r) if ({}.hasOwnProperty.call(r, n)) {
|
|
27
|
+
if (-1 !== e.indexOf(n)) continue;
|
|
28
|
+
t[n] = r[n];
|
|
29
|
+
}
|
|
30
|
+
return t;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const locale$1 = {
|
|
34
|
+
Cancel: '取消',
|
|
35
|
+
Confirm: '确定'
|
|
36
|
+
};
|
|
37
|
+
|
|
38
|
+
const locale = {
|
|
39
|
+
Cancel: 'Cancel',
|
|
40
|
+
Confirm: 'Confirm'
|
|
41
|
+
};
|
|
42
|
+
|
|
43
|
+
const withLocale = createWithIntlProvider({
|
|
44
|
+
defaultLocale: 'zh-CN',
|
|
45
|
+
messages: {
|
|
46
|
+
'zh-CN': locale$1,
|
|
47
|
+
'en-US': locale
|
|
48
|
+
},
|
|
49
|
+
namespace: 'react-modal'
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
var style = {"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-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"};
|
|
53
|
+
|
|
54
|
+
const _excluded$4 = ["ButtonComponent", "onClick", "autoClose", "display"];
|
|
55
|
+
const Footer = ({
|
|
56
|
+
footer,
|
|
57
|
+
footerButtons,
|
|
58
|
+
onConfirm,
|
|
59
|
+
onCancel,
|
|
60
|
+
cancelText,
|
|
61
|
+
confirmText,
|
|
62
|
+
onClose,
|
|
63
|
+
targetProps,
|
|
64
|
+
isMobile
|
|
65
|
+
}) => {
|
|
66
|
+
const {
|
|
67
|
+
formatMessage
|
|
68
|
+
} = useIntl();
|
|
69
|
+
const defaultButtons = [{
|
|
70
|
+
children: cancelText || formatMessage({
|
|
71
|
+
id: 'Cancel'
|
|
72
|
+
}),
|
|
73
|
+
onClick: onCancel
|
|
74
|
+
}, {
|
|
75
|
+
type: 'primary',
|
|
76
|
+
children: confirmText || formatMessage({
|
|
77
|
+
id: 'Confirm'
|
|
78
|
+
}),
|
|
79
|
+
onClick: onConfirm
|
|
80
|
+
}];
|
|
81
|
+
const rawList = footerButtons === undefined ? defaultButtons : footerButtons;
|
|
82
|
+
const list = (Array.isArray(rawList) ? rawList : []).filter(item => {
|
|
83
|
+
if (typeof (item == null ? void 0 : item.display) === 'function') {
|
|
84
|
+
return item.display();
|
|
85
|
+
}
|
|
86
|
+
return (item == null ? void 0 : item.display) !== false;
|
|
87
|
+
}).map(_ref => {
|
|
88
|
+
let {
|
|
89
|
+
ButtonComponent,
|
|
90
|
+
onClick,
|
|
91
|
+
autoClose = true
|
|
92
|
+
} = _ref,
|
|
93
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded$4);
|
|
94
|
+
return _extends({}, props, {
|
|
95
|
+
buttonComponent: ButtonComponent,
|
|
96
|
+
onClick: async (...args) => {
|
|
97
|
+
const res = await Promise.resolve(onClick && onClick(...args, targetProps));
|
|
98
|
+
autoClose && res !== false && onClose && onClose();
|
|
99
|
+
return res;
|
|
100
|
+
}
|
|
101
|
+
});
|
|
102
|
+
});
|
|
103
|
+
const showButtons = !(Array.isArray(footerButtons) && footerButtons.length === 0) && list.length > 0;
|
|
104
|
+
const embeddedFooterOnly = Array.isArray(footerButtons) && footerButtons.length === 0 && footer != null;
|
|
105
|
+
const showFooterSlot = !isMobile || footer;
|
|
106
|
+
if (!showFooterSlot && !showButtons) {
|
|
107
|
+
return null;
|
|
108
|
+
}
|
|
109
|
+
return /*#__PURE__*/jsxs("div", {
|
|
110
|
+
className: classnames(style['modal-footer'], 'modal-footer', {
|
|
111
|
+
[style['is-mobile']]: isMobile,
|
|
112
|
+
[style['is-embedded-footer']]: embeddedFooterOnly
|
|
113
|
+
}),
|
|
114
|
+
children: [showFooterSlot ? /*#__PURE__*/jsx("div", {
|
|
115
|
+
className: style['modal-footer-extra'],
|
|
116
|
+
children: footer
|
|
117
|
+
}) : null, showButtons ? /*#__PURE__*/jsx("div", {
|
|
118
|
+
className: style['modal-footer-actions'],
|
|
119
|
+
children: /*#__PURE__*/jsx(ButtonGroup, {
|
|
120
|
+
list: list,
|
|
121
|
+
showLength: list.length,
|
|
122
|
+
place: isMobile ? 'center' : 'end'
|
|
123
|
+
})
|
|
124
|
+
}) : null]
|
|
125
|
+
});
|
|
126
|
+
};
|
|
127
|
+
|
|
128
|
+
const _excluded$3 = ["children", "footer", "footerButtons", "className", "size", "title", "onClose", "onConfirm", "confirmText", "onCancel", "cancelText", "closable", "noPadding", "bodyScroll", "isMobile", "mobileFullscreen", "fixedModeClass", "wrapClassName", "classNames", "styles", "style"],
|
|
129
|
+
_excluded2 = ["width"],
|
|
130
|
+
_excluded3 = ["size", "getContainer", "open", "mobileFullscreen", "bodyScroll"],
|
|
131
|
+
_excluded4 = ["afterClose", "getContainer"],
|
|
132
|
+
_excluded5 = ["children", "getContainer", "afterClose"];
|
|
133
|
+
const ModalLocaleRoot = withLocale(({
|
|
134
|
+
children
|
|
135
|
+
}) => children);
|
|
136
|
+
const renderWithOptions = (value, options) => {
|
|
137
|
+
if (typeof value === 'function') {
|
|
138
|
+
return value(options);
|
|
139
|
+
}
|
|
140
|
+
return value;
|
|
141
|
+
};
|
|
142
|
+
const wrapCustomGetContainer = customGetContainer => {
|
|
143
|
+
if (!customGetContainer) {
|
|
144
|
+
return undefined;
|
|
145
|
+
}
|
|
146
|
+
if (typeof customGetContainer === 'function') {
|
|
147
|
+
return triggerNode => customGetContainer(triggerNode) || null;
|
|
148
|
+
}
|
|
149
|
+
return () => customGetContainer;
|
|
150
|
+
};
|
|
151
|
+
const VIEWPORT_EXAMPLE_SELECTORS = ['.example-driver-device-scroll'];
|
|
152
|
+
const viewportPopupMountOptions = {
|
|
153
|
+
cover: 'viewport',
|
|
154
|
+
exampleSelectors: VIEWPORT_EXAMPLE_SELECTORS
|
|
155
|
+
};
|
|
156
|
+
const findParentModalMountHost = node => {
|
|
157
|
+
if (!node || typeof node.closest !== 'function') {
|
|
158
|
+
return null;
|
|
159
|
+
}
|
|
160
|
+
const parentRoot = node.closest('.ant-modal-root');
|
|
161
|
+
if (!parentRoot) {
|
|
162
|
+
return null;
|
|
163
|
+
}
|
|
164
|
+
return parentRoot.parentElement || (typeof document !== 'undefined' ? document.body : null);
|
|
165
|
+
};
|
|
166
|
+
const resolveModalGetContainer = ({
|
|
167
|
+
customGetContainer,
|
|
168
|
+
getPopupContainer,
|
|
169
|
+
getHostNode
|
|
170
|
+
}) => {
|
|
171
|
+
const wrappedCustom = wrapCustomGetContainer(customGetContainer);
|
|
172
|
+
return triggerNode => {
|
|
173
|
+
if (wrappedCustom) {
|
|
174
|
+
const custom = wrappedCustom(triggerNode);
|
|
175
|
+
if (custom) {
|
|
176
|
+
return custom;
|
|
177
|
+
}
|
|
178
|
+
}
|
|
179
|
+
const from = triggerNode || (typeof getHostNode === 'function' ? getHostNode() : null);
|
|
180
|
+
const nestedHost = findParentModalMountHost(from);
|
|
181
|
+
if (nestedHost) {
|
|
182
|
+
return nestedHost;
|
|
183
|
+
}
|
|
184
|
+
return getPopupContainer(triggerNode);
|
|
185
|
+
};
|
|
186
|
+
};
|
|
187
|
+
let parentScrollLockCount = 0;
|
|
188
|
+
let parentScrollLocked = [];
|
|
189
|
+
const lockParentScroll = getScrollElement => {
|
|
190
|
+
parentScrollLockCount += 1;
|
|
191
|
+
if (parentScrollLockCount === 1) {
|
|
192
|
+
const targets = [document.body];
|
|
193
|
+
const scrollEl = typeof getScrollElement === 'function' ? getScrollElement() : null;
|
|
194
|
+
if (scrollEl && scrollEl !== document.body && !targets.includes(scrollEl)) {
|
|
195
|
+
targets.push(scrollEl);
|
|
196
|
+
}
|
|
197
|
+
parentScrollLocked = targets.map(el => {
|
|
198
|
+
const prev = {
|
|
199
|
+
overflow: el.style.overflow,
|
|
200
|
+
overscrollBehavior: el.style.overscrollBehavior
|
|
201
|
+
};
|
|
202
|
+
el.style.overflow = 'hidden';
|
|
203
|
+
el.style.overscrollBehavior = 'none';
|
|
204
|
+
return {
|
|
205
|
+
el,
|
|
206
|
+
prev
|
|
207
|
+
};
|
|
208
|
+
});
|
|
209
|
+
}
|
|
210
|
+
return () => {
|
|
211
|
+
parentScrollLockCount = Math.max(0, parentScrollLockCount - 1);
|
|
212
|
+
if (parentScrollLockCount === 0) {
|
|
213
|
+
parentScrollLocked.forEach(({
|
|
214
|
+
el,
|
|
215
|
+
prev
|
|
216
|
+
}) => {
|
|
217
|
+
el.style.overflow = prev.overflow;
|
|
218
|
+
el.style.overscrollBehavior = prev.overscrollBehavior;
|
|
219
|
+
});
|
|
220
|
+
parentScrollLocked = [];
|
|
221
|
+
}
|
|
222
|
+
};
|
|
223
|
+
};
|
|
224
|
+
const useLockParentScroll = (enabled, getScrollElement) => {
|
|
225
|
+
useEffect(() => {
|
|
226
|
+
if (!enabled) {
|
|
227
|
+
return undefined;
|
|
228
|
+
}
|
|
229
|
+
return lockParentScroll(getScrollElement);
|
|
230
|
+
}, [enabled, getScrollElement]);
|
|
231
|
+
};
|
|
232
|
+
const sizeStyleVars = (size, hasFooter) => {
|
|
233
|
+
const minBase = size === 'small' ? 300 : 500;
|
|
234
|
+
const chrome = 48 + (hasFooter ? 58 : 0);
|
|
235
|
+
const minHeight = `${Math.max(0, minBase - chrome)}px`;
|
|
236
|
+
if (size === 'large') {
|
|
237
|
+
return {
|
|
238
|
+
width: typeof window !== 'undefined' ? `${Math.min(window.innerWidth - 64, 1500)}px` : '1500px',
|
|
239
|
+
'--kne-modal-body-min-height': minHeight
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
if (size === 'small') {
|
|
243
|
+
return {
|
|
244
|
+
width: '600px',
|
|
245
|
+
'--kne-modal-body-min-height': minHeight
|
|
246
|
+
};
|
|
247
|
+
}
|
|
248
|
+
return {
|
|
249
|
+
width: '1000px',
|
|
250
|
+
'--kne-modal-body-min-height': minHeight
|
|
251
|
+
};
|
|
252
|
+
};
|
|
253
|
+
const ModalOuter = ({
|
|
254
|
+
title,
|
|
255
|
+
footer,
|
|
256
|
+
footerButtons,
|
|
257
|
+
noPadding,
|
|
258
|
+
onClose,
|
|
259
|
+
closable,
|
|
260
|
+
onConfirm,
|
|
261
|
+
onCancel,
|
|
262
|
+
children,
|
|
263
|
+
targetProps,
|
|
264
|
+
cancelText,
|
|
265
|
+
confirmText,
|
|
266
|
+
isMobile,
|
|
267
|
+
bodyScroll
|
|
268
|
+
}) => {
|
|
269
|
+
const effectiveNoPadding = noPadding != null ? noPadding : bodyScroll === false;
|
|
270
|
+
const bodyInner = /*#__PURE__*/jsx("div", {
|
|
271
|
+
className: classnames(style['modal-body-inner'], 'modal-body-inner', {
|
|
272
|
+
[style['no-padding']]: effectiveNoPadding
|
|
273
|
+
}),
|
|
274
|
+
children: children
|
|
275
|
+
});
|
|
276
|
+
const bodyClassName = classnames(style['modal-body'], 'modal-body');
|
|
277
|
+
return /*#__PURE__*/jsxs("div", {
|
|
278
|
+
className: classnames(style['modal-outer'], 'modal-container', {
|
|
279
|
+
[style['is-mobile']]: isMobile,
|
|
280
|
+
[style['no-title']]: !title,
|
|
281
|
+
[style['no-footer']]: footer === null && footerButtons === undefined,
|
|
282
|
+
[style['no-padding']]: effectiveNoPadding
|
|
283
|
+
}),
|
|
284
|
+
"data-testid": "react-modal",
|
|
285
|
+
children: [closable === false ? null : /*#__PURE__*/jsx(Button, {
|
|
286
|
+
"data-testid": "react-modal-close-btn",
|
|
287
|
+
className: classnames(style['modal-close'], 'modal-close'),
|
|
288
|
+
type: "text",
|
|
289
|
+
icon: /*#__PURE__*/jsx(CloseOutlined, {}),
|
|
290
|
+
onClick: e => {
|
|
291
|
+
e.stopPropagation();
|
|
292
|
+
onClose && onClose();
|
|
293
|
+
}
|
|
294
|
+
}), title ? /*#__PURE__*/jsx("div", {
|
|
295
|
+
className: classnames(style['modal-title'], 'modal-title'),
|
|
296
|
+
children: title
|
|
297
|
+
}) : null, bodyScroll !== false ? /*#__PURE__*/jsx(SimpleBar, {
|
|
298
|
+
className: bodyClassName,
|
|
299
|
+
style: {
|
|
300
|
+
height: 'var(--kne-modal-body-height)'
|
|
301
|
+
},
|
|
302
|
+
children: bodyInner
|
|
303
|
+
}) : /*#__PURE__*/jsx("div", {
|
|
304
|
+
className: classnames(bodyClassName, style['body-scroll-off']),
|
|
305
|
+
children: bodyInner
|
|
306
|
+
}), footer === null && footerButtons === undefined ? null : /*#__PURE__*/jsx(Footer, {
|
|
307
|
+
footer: footer,
|
|
308
|
+
footerButtons: footerButtons,
|
|
309
|
+
onConfirm: onConfirm,
|
|
310
|
+
confirmText: confirmText,
|
|
311
|
+
onCancel: onCancel,
|
|
312
|
+
cancelText: cancelText,
|
|
313
|
+
onClose: onClose,
|
|
314
|
+
targetProps: targetProps,
|
|
315
|
+
isMobile: isMobile
|
|
316
|
+
})]
|
|
317
|
+
});
|
|
318
|
+
};
|
|
319
|
+
const computedCommonProps = _ref => {
|
|
320
|
+
var _props$width;
|
|
321
|
+
let {
|
|
322
|
+
children,
|
|
323
|
+
footer,
|
|
324
|
+
footerButtons,
|
|
325
|
+
className,
|
|
326
|
+
size = 'default',
|
|
327
|
+
title,
|
|
328
|
+
onClose,
|
|
329
|
+
onConfirm,
|
|
330
|
+
confirmText,
|
|
331
|
+
onCancel,
|
|
332
|
+
cancelText,
|
|
333
|
+
closable,
|
|
334
|
+
noPadding,
|
|
335
|
+
bodyScroll = true,
|
|
336
|
+
isMobile,
|
|
337
|
+
mobileFullscreen = true,
|
|
338
|
+
fixedModeClass,
|
|
339
|
+
wrapClassName,
|
|
340
|
+
classNames: propsClassNames,
|
|
341
|
+
styles: propsStyles,
|
|
342
|
+
style: propsStyle
|
|
343
|
+
} = _ref,
|
|
344
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded$3);
|
|
345
|
+
const useMobileLayout = isMobile && mobileFullscreen !== false;
|
|
346
|
+
const hasFooter = !(footer === null && footerButtons === undefined);
|
|
347
|
+
const sizeVars = sizeStyleVars(size, hasFooter);
|
|
348
|
+
const {
|
|
349
|
+
width
|
|
350
|
+
} = sizeVars,
|
|
351
|
+
cssVars = _objectWithoutPropertiesLoose(sizeVars, _excluded2);
|
|
352
|
+
const runChildren = options => {
|
|
353
|
+
const opts = Object.assign({}, options, {
|
|
354
|
+
close: onClose
|
|
355
|
+
});
|
|
356
|
+
return /*#__PURE__*/jsx(ModalOuter, {
|
|
357
|
+
title: renderWithOptions(title, opts),
|
|
358
|
+
closable: closable,
|
|
359
|
+
onClose: onClose,
|
|
360
|
+
onConfirm: onConfirm,
|
|
361
|
+
confirmText: confirmText,
|
|
362
|
+
onCancel: onCancel,
|
|
363
|
+
cancelText: cancelText,
|
|
364
|
+
footerButtons: renderWithOptions(footerButtons, opts),
|
|
365
|
+
noPadding: noPadding,
|
|
366
|
+
footer: renderWithOptions(footer, opts),
|
|
367
|
+
targetProps: opts,
|
|
368
|
+
isMobile: useMobileLayout,
|
|
369
|
+
bodyScroll: bodyScroll,
|
|
370
|
+
children: renderWithOptions(children, opts)
|
|
371
|
+
});
|
|
372
|
+
};
|
|
373
|
+
return _extends({}, props, {
|
|
374
|
+
icon: null,
|
|
375
|
+
centered: !useMobileLayout,
|
|
376
|
+
width: (_props$width = props.width) != null ? _props$width : useMobileLayout ? 'var(--kne-modal-viewport-width, 100vw)' : width,
|
|
377
|
+
wrapClassName: classnames(wrapClassName, style['modal-wrap'], useMobileLayout ? style['modal-wrap-fullscreen'] : style['modal-wrap-centered'], useMobileLayout && fixedModeClass),
|
|
378
|
+
classNames: Object.assign({}, propsClassNames, {
|
|
379
|
+
mask: classnames(propsClassNames == null ? void 0 : propsClassNames.mask, useMobileLayout && style['modal-mask-fullscreen'], useMobileLayout && fixedModeClass),
|
|
380
|
+
container: classnames(style['modal-container'], useMobileLayout && style['is-mobile'], propsClassNames == null ? void 0 : propsClassNames.container),
|
|
381
|
+
body: classnames(style['modal-antd-body'], useMobileLayout && style['is-mobile'], propsClassNames == null ? void 0 : propsClassNames.body),
|
|
382
|
+
footer: classnames(style['modal-antd-footer'], propsClassNames == null ? void 0 : propsClassNames.footer),
|
|
383
|
+
header: classnames(style['modal-antd-header'], propsClassNames == null ? void 0 : propsClassNames.header),
|
|
384
|
+
content: classnames(style['modal-container'], useMobileLayout && style['is-mobile'], propsClassNames == null ? void 0 : propsClassNames.content)
|
|
385
|
+
}),
|
|
386
|
+
title: null,
|
|
387
|
+
maskClosable: Object.prototype.hasOwnProperty.call(props, 'maskClosable') ? props.maskClosable : false,
|
|
388
|
+
destroyOnHidden: true,
|
|
389
|
+
footer: null,
|
|
390
|
+
closable: false,
|
|
391
|
+
onCancel: onClose,
|
|
392
|
+
className: classnames(className, style['modal'], style[size], {
|
|
393
|
+
[style['is-mobile']]: useMobileLayout
|
|
394
|
+
}),
|
|
395
|
+
style: Object.assign({}, cssVars, propsStyle, useMobileLayout ? {
|
|
396
|
+
'--kne-modal-viewport-gutter': '0px',
|
|
397
|
+
maxWidth: '100%',
|
|
398
|
+
width: '100%',
|
|
399
|
+
height: 'var(--kne-modal-viewport-height, 100vh)',
|
|
400
|
+
maxHeight: 'var(--kne-modal-viewport-height, 100vh)',
|
|
401
|
+
top: 0,
|
|
402
|
+
margin: 0,
|
|
403
|
+
paddingBottom: 0
|
|
404
|
+
} : null),
|
|
405
|
+
styles: _extends({}, propsStyles, {
|
|
406
|
+
container: _extends({
|
|
407
|
+
padding: 0
|
|
408
|
+
}, propsStyles == null ? void 0 : propsStyles.container, useMobileLayout ? {
|
|
409
|
+
borderRadius: 0,
|
|
410
|
+
height: '100%',
|
|
411
|
+
maxHeight: '100%',
|
|
412
|
+
overflow: 'hidden'
|
|
413
|
+
} : null),
|
|
414
|
+
content: _extends({
|
|
415
|
+
padding: 0
|
|
416
|
+
}, propsStyles == null ? void 0 : propsStyles.content),
|
|
417
|
+
body: _extends({
|
|
418
|
+
padding: 0
|
|
419
|
+
}, propsStyles == null ? void 0 : propsStyles.body, useMobileLayout ? {
|
|
420
|
+
height: '100%',
|
|
421
|
+
maxHeight: '100%',
|
|
422
|
+
overflow: 'hidden'
|
|
423
|
+
} : null)
|
|
424
|
+
}),
|
|
425
|
+
children: /*#__PURE__*/jsx(ModalLocaleRoot, {
|
|
426
|
+
children: runChildren({})
|
|
427
|
+
})
|
|
428
|
+
});
|
|
429
|
+
};
|
|
430
|
+
const Modal = withLocale(_ref2 => {
|
|
431
|
+
let {
|
|
432
|
+
size = 'default',
|
|
433
|
+
getContainer,
|
|
434
|
+
open,
|
|
435
|
+
mobileFullscreen = true,
|
|
436
|
+
bodyScroll = true
|
|
437
|
+
} = _ref2,
|
|
438
|
+
props = _objectWithoutPropertiesLoose(_ref2, _excluded3);
|
|
439
|
+
const hostRef = useRef(null);
|
|
440
|
+
const {
|
|
441
|
+
isMobile,
|
|
442
|
+
fixedModeClass,
|
|
443
|
+
getPopupContainer,
|
|
444
|
+
anchorRef
|
|
445
|
+
} = useMobilePopupMount(_extends({}, viewportPopupMountOptions, {
|
|
446
|
+
getPopupContainer: wrapCustomGetContainer(getContainer)
|
|
447
|
+
}));
|
|
448
|
+
const getScrollElement = useScrollElement();
|
|
449
|
+
useLockParentScroll(!!open, getScrollElement);
|
|
450
|
+
const setAnchorRef = node => {
|
|
451
|
+
hostRef.current = node;
|
|
452
|
+
anchorRef(node);
|
|
453
|
+
};
|
|
454
|
+
const getModalContainer = resolveModalGetContainer({
|
|
455
|
+
customGetContainer: getContainer,
|
|
456
|
+
getPopupContainer,
|
|
457
|
+
getHostNode: () => hostRef.current
|
|
458
|
+
});
|
|
459
|
+
return /*#__PURE__*/jsxs(Fragment, {
|
|
460
|
+
children: [/*#__PURE__*/jsx("span", {
|
|
461
|
+
ref: setAnchorRef,
|
|
462
|
+
className: style['modal-host'],
|
|
463
|
+
"aria-hidden": "true"
|
|
464
|
+
}), /*#__PURE__*/jsx(Modal$1, _extends({}, computedCommonProps(Object.assign({}, props, {
|
|
465
|
+
size,
|
|
466
|
+
isMobile,
|
|
467
|
+
open,
|
|
468
|
+
fixedModeClass,
|
|
469
|
+
mobileFullscreen,
|
|
470
|
+
bodyScroll
|
|
471
|
+
})), {
|
|
472
|
+
open: open,
|
|
473
|
+
getContainer: getModalContainer
|
|
474
|
+
}))]
|
|
475
|
+
});
|
|
476
|
+
});
|
|
477
|
+
const useModal = () => {
|
|
478
|
+
const {
|
|
479
|
+
modal
|
|
480
|
+
} = App.useApp();
|
|
481
|
+
const {
|
|
482
|
+
resolveMount,
|
|
483
|
+
getPopupContainer
|
|
484
|
+
} = useMobilePopupMount(viewportPopupMountOptions);
|
|
485
|
+
const getScrollElement = useScrollElement();
|
|
486
|
+
return props => {
|
|
487
|
+
const anchor = typeof document !== 'undefined' ? document.activeElement : null;
|
|
488
|
+
const {
|
|
489
|
+
isMobile,
|
|
490
|
+
fixedModeClass
|
|
491
|
+
} = resolveMount(anchor);
|
|
492
|
+
const unlock = lockParentScroll(getScrollElement);
|
|
493
|
+
const api = {};
|
|
494
|
+
const {
|
|
495
|
+
afterClose: userAfterClose,
|
|
496
|
+
getContainer: customGetContainer
|
|
497
|
+
} = props,
|
|
498
|
+
restProps = _objectWithoutPropertiesLoose(props, _excluded4);
|
|
499
|
+
const _computedCommonProps = computedCommonProps(_extends({
|
|
500
|
+
onClose: () => api.close(),
|
|
501
|
+
isMobile,
|
|
502
|
+
fixedModeClass,
|
|
503
|
+
afterClose: (...args) => {
|
|
504
|
+
unlock();
|
|
505
|
+
userAfterClose && userAfterClose(...args);
|
|
506
|
+
}
|
|
507
|
+
}, restProps)),
|
|
508
|
+
{
|
|
509
|
+
children,
|
|
510
|
+
getContainer,
|
|
511
|
+
afterClose
|
|
512
|
+
} = _computedCommonProps,
|
|
513
|
+
otherProps = _objectWithoutPropertiesLoose(_computedCommonProps, _excluded5);
|
|
514
|
+
const {
|
|
515
|
+
destroy
|
|
516
|
+
} = modal.info(_extends({}, otherProps, {
|
|
517
|
+
afterClose,
|
|
518
|
+
content: children,
|
|
519
|
+
getContainer: resolveModalGetContainer({
|
|
520
|
+
customGetContainer: customGetContainer != null ? customGetContainer : getContainer,
|
|
521
|
+
getPopupContainer,
|
|
522
|
+
getHostNode: () => anchor
|
|
523
|
+
})
|
|
524
|
+
}));
|
|
525
|
+
api.close = destroy;
|
|
526
|
+
return api;
|
|
527
|
+
};
|
|
528
|
+
};
|
|
529
|
+
|
|
530
|
+
const _excluded$2 = ["className", "inset", "children"];
|
|
531
|
+
const ModalScrollRegion = _ref => {
|
|
532
|
+
let {
|
|
533
|
+
className,
|
|
534
|
+
inset = false,
|
|
535
|
+
children
|
|
536
|
+
} = _ref,
|
|
537
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded$2);
|
|
538
|
+
return /*#__PURE__*/jsx(SimpleBar, _extends({
|
|
539
|
+
className: classnames(styles['modal-scroll-region'], 'modal-scroll-region', inset && styles['is-inset'], className)
|
|
540
|
+
}, props, {
|
|
541
|
+
children: /*#__PURE__*/jsx("div", {
|
|
542
|
+
className: styles['modal-scroll-region-inner'],
|
|
543
|
+
children: children
|
|
544
|
+
})
|
|
545
|
+
}));
|
|
546
|
+
};
|
|
547
|
+
|
|
548
|
+
const _excluded$1 = ["className", "destroyOnHidden"];
|
|
549
|
+
const ModalTabsLayout = _ref => {
|
|
550
|
+
let {
|
|
551
|
+
className,
|
|
552
|
+
destroyOnHidden = true
|
|
553
|
+
} = _ref,
|
|
554
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded$1);
|
|
555
|
+
return /*#__PURE__*/jsx(Tabs, _extends({
|
|
556
|
+
className: classnames(styles['modal-tabs-layout'], className),
|
|
557
|
+
destroyOnHidden: destroyOnHidden
|
|
558
|
+
}, props));
|
|
559
|
+
};
|
|
560
|
+
|
|
561
|
+
const _excluded = ["widths", "className", "children"];
|
|
562
|
+
const resolveColStyle = width => {
|
|
563
|
+
if (width == null || width === '1fr') {
|
|
564
|
+
return {
|
|
565
|
+
flex: '1 1 0%',
|
|
566
|
+
minWidth: 0
|
|
567
|
+
};
|
|
568
|
+
}
|
|
569
|
+
return {
|
|
570
|
+
flex: 'none',
|
|
571
|
+
width,
|
|
572
|
+
minWidth: 0
|
|
573
|
+
};
|
|
574
|
+
};
|
|
575
|
+
const ModalColumnsLayout = _ref => {
|
|
576
|
+
let {
|
|
577
|
+
widths,
|
|
578
|
+
className,
|
|
579
|
+
children
|
|
580
|
+
} = _ref,
|
|
581
|
+
props = _objectWithoutPropertiesLoose(_ref, _excluded);
|
|
582
|
+
const cols = Children.toArray(children);
|
|
583
|
+
return /*#__PURE__*/jsx("div", _extends({
|
|
584
|
+
className: classnames(styles['modal-columns-layout'], className)
|
|
585
|
+
}, props, {
|
|
586
|
+
children: cols.map((child, index) => /*#__PURE__*/jsx("div", {
|
|
587
|
+
className: styles['modal-columns-layout__col'],
|
|
588
|
+
style: widths ? resolveColStyle(widths[index]) : undefined,
|
|
589
|
+
children: child
|
|
590
|
+
}, index))
|
|
591
|
+
}));
|
|
592
|
+
};
|
|
593
|
+
|
|
594
|
+
const createModalRender = modalDefaults => hostProps => /*#__PURE__*/jsx(Modal, _extends({}, modalDefaults, hostProps));
|
|
595
|
+
|
|
596
|
+
const modalClassNames = {
|
|
597
|
+
stepsForm: 'react-modal-steps-form',
|
|
598
|
+
splitter: 'react-modal-splitter'
|
|
599
|
+
};
|
|
600
|
+
|
|
601
|
+
export { ModalColumnsLayout, ModalScrollRegion, ModalTabsLayout, createModalRender, Modal as default, modalClassNames, useModal };
|
|
602
|
+
//# sourceMappingURL=index.modern.js.map
|