aark-react-modalify 1.1.0 → 1.2.0
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 +683 -46
- package/dist/aark-react-modalify.css +1 -1
- package/dist/components/modals/StandardModal.d.ts +8 -0
- package/dist/components/modals/index.d.ts +1 -0
- package/dist/components/notifications/StandardNotification.d.ts +8 -0
- package/dist/components/notifications/index.d.ts +1 -0
- package/dist/index-no-styles.cjs.js +1 -0
- package/dist/{index.esm.js → index-no-styles.esm.js} +406 -76
- package/dist/index.d.ts +2 -1
- package/dist/logic/ModalManager.d.ts +4 -4
- package/dist/logic/aark.d.ts +4 -4
- package/dist/types/index.d.ts +66 -2
- package/dist/utils/inject-styles.d.ts +3 -0
- package/dist/utils/modal-root.d.ts +18 -0
- package/package.json +10 -8
- package/dist/index.cjs.js +0 -32
|
@@ -111,8 +111,132 @@ const Icon = memo(
|
|
|
111
111
|
}
|
|
112
112
|
);
|
|
113
113
|
Icon.displayName = "Icon";
|
|
114
|
+
const typeIcons$1 = {
|
|
115
|
+
success: "✓",
|
|
116
|
+
error: "✕",
|
|
117
|
+
warning: "⚠",
|
|
118
|
+
info: "ⓘ",
|
|
119
|
+
question: "?"
|
|
120
|
+
};
|
|
121
|
+
const typeColors$1 = {
|
|
122
|
+
success: "#4ade80",
|
|
123
|
+
error: "#ef4444",
|
|
124
|
+
warning: "#f59e0b",
|
|
125
|
+
info: "#3b82f6",
|
|
126
|
+
question: "#8b5cf6"
|
|
127
|
+
};
|
|
128
|
+
const StandardModal = ({ props, onClose }) => {
|
|
129
|
+
const {
|
|
130
|
+
title,
|
|
131
|
+
text,
|
|
132
|
+
type = "info",
|
|
133
|
+
cancelText = "Cancel",
|
|
134
|
+
confirmText = "OK",
|
|
135
|
+
onCancel,
|
|
136
|
+
onConfirm,
|
|
137
|
+
icon,
|
|
138
|
+
html,
|
|
139
|
+
showCancelButton = false,
|
|
140
|
+
showConfirmButton = true,
|
|
141
|
+
reverseButtons = false,
|
|
142
|
+
width = "auto",
|
|
143
|
+
fullWidth = false,
|
|
144
|
+
customClass = {}
|
|
145
|
+
} = props;
|
|
146
|
+
const handleCancel = () => {
|
|
147
|
+
onCancel?.();
|
|
148
|
+
onClose();
|
|
149
|
+
};
|
|
150
|
+
const handleConfirm = () => {
|
|
151
|
+
onConfirm?.();
|
|
152
|
+
onClose();
|
|
153
|
+
};
|
|
154
|
+
const iconElement = useMemo(() => {
|
|
155
|
+
if (icon) {
|
|
156
|
+
return typeof icon === "string" ? /* @__PURE__ */ jsx("span", { children: icon }) : icon;
|
|
157
|
+
}
|
|
158
|
+
return /* @__PURE__ */ jsx("span", { style: { color: typeColors$1[type] }, children: typeIcons$1[type] });
|
|
159
|
+
}, [icon, type]);
|
|
160
|
+
const buttonOrder = reverseButtons ? ["confirm", "cancel"] : ["cancel", "confirm"];
|
|
161
|
+
const modalStyle = useMemo(() => {
|
|
162
|
+
const baseStyle = {};
|
|
163
|
+
if (fullWidth) {
|
|
164
|
+
baseStyle.width = "calc(100vw - 20px)";
|
|
165
|
+
baseStyle.maxWidth = "calc(100vw - 20px)";
|
|
166
|
+
} else {
|
|
167
|
+
if (typeof width === "number") {
|
|
168
|
+
baseStyle.width = `${width}px`;
|
|
169
|
+
} else {
|
|
170
|
+
baseStyle.width = width;
|
|
171
|
+
}
|
|
172
|
+
}
|
|
173
|
+
return baseStyle;
|
|
174
|
+
}, [width, fullWidth]);
|
|
175
|
+
return /* @__PURE__ */ jsxs("div", { className: `aark-standard-modal ${customClass.popup || ""}`, style: modalStyle, children: [
|
|
176
|
+
/* @__PURE__ */ jsxs("div", { className: `aark-modal-content ${customClass.content || ""}`, children: [
|
|
177
|
+
iconElement && /* @__PURE__ */ jsx("div", { className: `aark-modal-icon ${customClass.icon || ""}`, children: iconElement }),
|
|
178
|
+
title && /* @__PURE__ */ jsx("div", { className: `aark-modal-header ${customClass.header || ""}`, children: /* @__PURE__ */ jsx("h2", { className: `aark-modal-title ${customClass.title || ""}`, children: title }) }),
|
|
179
|
+
html ? /* @__PURE__ */ jsx("div", { dangerouslySetInnerHTML: { __html: typeof html === "string" ? html : "" } }) : text ? /* @__PURE__ */ jsx("p", { children: text }) : null
|
|
180
|
+
] }),
|
|
181
|
+
(showCancelButton || showConfirmButton) && /* @__PURE__ */ jsx("div", { className: `aark-modal-footer ${customClass.actions || ""}`, children: buttonOrder.map((buttonType) => {
|
|
182
|
+
if (buttonType === "cancel" && showCancelButton) {
|
|
183
|
+
return /* @__PURE__ */ jsx(
|
|
184
|
+
"button",
|
|
185
|
+
{
|
|
186
|
+
onClick: handleCancel,
|
|
187
|
+
className: `aark-modal-cancel-button ${customClass.cancelButton || ""}`,
|
|
188
|
+
children: cancelText
|
|
189
|
+
},
|
|
190
|
+
"cancel"
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
if (buttonType === "confirm" && showConfirmButton) {
|
|
194
|
+
return /* @__PURE__ */ jsx(
|
|
195
|
+
"button",
|
|
196
|
+
{
|
|
197
|
+
onClick: handleConfirm,
|
|
198
|
+
className: `aark-modal-confirm-button ${customClass.confirmButton || ""}`,
|
|
199
|
+
style: {
|
|
200
|
+
background: typeColors$1[type]
|
|
201
|
+
},
|
|
202
|
+
children: confirmText
|
|
203
|
+
},
|
|
204
|
+
"confirm"
|
|
205
|
+
);
|
|
206
|
+
}
|
|
207
|
+
return null;
|
|
208
|
+
}) })
|
|
209
|
+
] });
|
|
210
|
+
};
|
|
211
|
+
let modalRoot = null;
|
|
212
|
+
const getModalRoot = () => {
|
|
213
|
+
if (!modalRoot) {
|
|
214
|
+
modalRoot = document.getElementById("aark-react-modalify-root");
|
|
215
|
+
if (!modalRoot) {
|
|
216
|
+
modalRoot = document.createElement("div");
|
|
217
|
+
modalRoot.id = "aark-react-modalify-root";
|
|
218
|
+
modalRoot.style.cssText = `
|
|
219
|
+
position: fixed;
|
|
220
|
+
top: 0;
|
|
221
|
+
left: 0;
|
|
222
|
+
width: 100%;
|
|
223
|
+
height: 100%;
|
|
224
|
+
pointer-events: none;
|
|
225
|
+
z-index: 9998;
|
|
226
|
+
`;
|
|
227
|
+
document.body.appendChild(modalRoot);
|
|
228
|
+
}
|
|
229
|
+
}
|
|
230
|
+
return modalRoot;
|
|
231
|
+
};
|
|
232
|
+
const cleanupModalRoot = () => {
|
|
233
|
+
if (modalRoot && modalRoot.children.length === 0) {
|
|
234
|
+
modalRoot.remove();
|
|
235
|
+
modalRoot = null;
|
|
236
|
+
}
|
|
237
|
+
};
|
|
114
238
|
const Modal = ({ config, onClose }) => {
|
|
115
|
-
const { content, options = {} } = config;
|
|
239
|
+
const { content, props, options = {} } = config;
|
|
116
240
|
const {
|
|
117
241
|
position = "center",
|
|
118
242
|
showCloseIcon = true,
|
|
@@ -147,8 +271,58 @@ const Modal = ({ config, onClose }) => {
|
|
|
147
271
|
},
|
|
148
272
|
[onClose]
|
|
149
273
|
);
|
|
150
|
-
const contentClasses = `aark-modal-
|
|
151
|
-
const modalContainer =
|
|
274
|
+
const contentClasses = `aark-modal-container ${position} ${className}`.trim();
|
|
275
|
+
const modalContainer = getModalRoot();
|
|
276
|
+
const renderContent = () => {
|
|
277
|
+
if (props) {
|
|
278
|
+
return /* @__PURE__ */ jsxs(
|
|
279
|
+
"div",
|
|
280
|
+
{
|
|
281
|
+
className: contentClasses,
|
|
282
|
+
role: "dialog",
|
|
283
|
+
"aria-modal": "true",
|
|
284
|
+
onClick: (e) => e.stopPropagation(),
|
|
285
|
+
children: [
|
|
286
|
+
showCloseIcon && /* @__PURE__ */ jsx(
|
|
287
|
+
"button",
|
|
288
|
+
{
|
|
289
|
+
onClick: handleCloseClick,
|
|
290
|
+
className: "aark-modal-close",
|
|
291
|
+
"aria-label": "Close Modal",
|
|
292
|
+
type: "button",
|
|
293
|
+
children: /* @__PURE__ */ jsx(Icon, { name: "close", size: 12 })
|
|
294
|
+
}
|
|
295
|
+
),
|
|
296
|
+
/* @__PURE__ */ jsx("div", { className: "aark-modal-wrapper", children: /* @__PURE__ */ jsx(StandardModal, { props, onClose }) })
|
|
297
|
+
]
|
|
298
|
+
}
|
|
299
|
+
);
|
|
300
|
+
} else if (content) {
|
|
301
|
+
return /* @__PURE__ */ jsxs(
|
|
302
|
+
"div",
|
|
303
|
+
{
|
|
304
|
+
className: contentClasses,
|
|
305
|
+
role: "dialog",
|
|
306
|
+
"aria-modal": "true",
|
|
307
|
+
onClick: (e) => e.stopPropagation(),
|
|
308
|
+
children: [
|
|
309
|
+
showCloseIcon && /* @__PURE__ */ jsx(
|
|
310
|
+
"button",
|
|
311
|
+
{
|
|
312
|
+
onClick: handleCloseClick,
|
|
313
|
+
className: "aark-modal-close",
|
|
314
|
+
"aria-label": "Close Modal",
|
|
315
|
+
type: "button",
|
|
316
|
+
children: /* @__PURE__ */ jsx(Icon, { name: "close", size: 12 })
|
|
317
|
+
}
|
|
318
|
+
),
|
|
319
|
+
/* @__PURE__ */ jsx("div", { className: "aark-modal-body", children: content })
|
|
320
|
+
]
|
|
321
|
+
}
|
|
322
|
+
);
|
|
323
|
+
}
|
|
324
|
+
return null;
|
|
325
|
+
};
|
|
152
326
|
return createPortal(
|
|
153
327
|
/* @__PURE__ */ jsx(
|
|
154
328
|
"div",
|
|
@@ -159,41 +333,153 @@ const Modal = ({ config, onClose }) => {
|
|
|
159
333
|
style: {
|
|
160
334
|
position: "fixed",
|
|
161
335
|
inset: 0,
|
|
162
|
-
zIndex:
|
|
336
|
+
zIndex: 9999,
|
|
163
337
|
background: "var(--aark-modal-overlay-bg)",
|
|
164
338
|
backdropFilter: "blur(2px)",
|
|
165
|
-
animation: "fade-in var(--aark-anim)"
|
|
339
|
+
animation: "fade-in var(--aark-anim)",
|
|
340
|
+
display: "flex",
|
|
341
|
+
alignItems: position.includes("center") ? "center" : position.includes("top") ? "flex-start" : "flex-end",
|
|
342
|
+
justifyContent: position.includes("center") ? "center" : position.includes("right") ? "flex-end" : "flex-start",
|
|
343
|
+
padding: "1rem"
|
|
166
344
|
},
|
|
167
|
-
children:
|
|
168
|
-
"div",
|
|
169
|
-
{
|
|
170
|
-
className: contentClasses,
|
|
171
|
-
role: "dialog",
|
|
172
|
-
"aria-modal": "true",
|
|
173
|
-
"aria-labelledby": "aark-modal-content",
|
|
174
|
-
onClick: (e) => e.stopPropagation(),
|
|
175
|
-
children: [
|
|
176
|
-
showCloseIcon && /* @__PURE__ */ jsx("header", { className: "aark-modal-header", children: /* @__PURE__ */ jsx(
|
|
177
|
-
"button",
|
|
178
|
-
{
|
|
179
|
-
onClick: handleCloseClick,
|
|
180
|
-
className: "aark-modal-close",
|
|
181
|
-
"aria-label": "Close modal",
|
|
182
|
-
type: "button",
|
|
183
|
-
children: /* @__PURE__ */ jsx(Icon, { name: "close", size: 12 })
|
|
184
|
-
}
|
|
185
|
-
) }),
|
|
186
|
-
/* @__PURE__ */ jsx("div", { id: "aark-modal-content", className: "aark-modal-body", children: content })
|
|
187
|
-
]
|
|
188
|
-
}
|
|
189
|
-
)
|
|
345
|
+
children: renderContent()
|
|
190
346
|
}
|
|
191
347
|
),
|
|
192
348
|
modalContainer
|
|
193
349
|
);
|
|
194
350
|
};
|
|
351
|
+
const typeIcons = {
|
|
352
|
+
success: "✓",
|
|
353
|
+
error: "✕",
|
|
354
|
+
warning: "⚠",
|
|
355
|
+
info: "ⓘ",
|
|
356
|
+
question: "?"
|
|
357
|
+
};
|
|
358
|
+
const typeColors = {
|
|
359
|
+
success: "#4ade80",
|
|
360
|
+
error: "#ef4444",
|
|
361
|
+
warning: "#f59e0b",
|
|
362
|
+
info: "#3b82f6",
|
|
363
|
+
question: "#8b5cf6"
|
|
364
|
+
};
|
|
365
|
+
const StandardNotification = ({ props, onClose }) => {
|
|
366
|
+
const {
|
|
367
|
+
title,
|
|
368
|
+
text,
|
|
369
|
+
type = "info",
|
|
370
|
+
icon,
|
|
371
|
+
html,
|
|
372
|
+
timer = 5e3,
|
|
373
|
+
showCloseButton = true,
|
|
374
|
+
clickToClose = true,
|
|
375
|
+
width = "300px",
|
|
376
|
+
fullWidth = false,
|
|
377
|
+
padding = "1rem",
|
|
378
|
+
background = "#ffffff",
|
|
379
|
+
customClass = {}
|
|
380
|
+
} = props;
|
|
381
|
+
useEffect(() => {
|
|
382
|
+
if (timer && timer > 0) {
|
|
383
|
+
const timeoutId = setTimeout(onClose, timer);
|
|
384
|
+
return () => clearTimeout(timeoutId);
|
|
385
|
+
}
|
|
386
|
+
}, [timer, onClose]);
|
|
387
|
+
const handleClick = () => {
|
|
388
|
+
if (clickToClose) {
|
|
389
|
+
onClose();
|
|
390
|
+
}
|
|
391
|
+
};
|
|
392
|
+
const iconElement = useMemo(() => {
|
|
393
|
+
if (icon) {
|
|
394
|
+
return typeof icon === "string" ? /* @__PURE__ */ jsx("span", { children: icon }) : icon;
|
|
395
|
+
}
|
|
396
|
+
return /* @__PURE__ */ jsx("span", { style: { color: typeColors[type] }, children: typeIcons[type] });
|
|
397
|
+
}, [icon, type]);
|
|
398
|
+
const notificationStyle = useMemo(() => {
|
|
399
|
+
const baseStyle = {
|
|
400
|
+
padding,
|
|
401
|
+
background,
|
|
402
|
+
borderRadius: "8px",
|
|
403
|
+
boxShadow: "0 4px 12px rgba(0, 0, 0, 0.1)",
|
|
404
|
+
border: `1px solid ${typeColors[type]}`,
|
|
405
|
+
cursor: clickToClose ? "pointer" : "default",
|
|
406
|
+
position: "relative",
|
|
407
|
+
overflow: "hidden"
|
|
408
|
+
};
|
|
409
|
+
if (fullWidth) {
|
|
410
|
+
baseStyle.width = "calc(100vw - 40px)";
|
|
411
|
+
baseStyle.maxWidth = "calc(100vw - 40px)";
|
|
412
|
+
} else {
|
|
413
|
+
baseStyle.width = typeof width === "number" ? `${width}px` : width;
|
|
414
|
+
}
|
|
415
|
+
return baseStyle;
|
|
416
|
+
}, [width, fullWidth, padding, background, type, clickToClose]);
|
|
417
|
+
return /* @__PURE__ */ jsxs(
|
|
418
|
+
"div",
|
|
419
|
+
{
|
|
420
|
+
className: `aark-standard-notification ${customClass.popup || ""}`,
|
|
421
|
+
style: notificationStyle,
|
|
422
|
+
onClick: handleClick,
|
|
423
|
+
children: [
|
|
424
|
+
timer && timer > 0 && /* @__PURE__ */ jsx(
|
|
425
|
+
"div",
|
|
426
|
+
{
|
|
427
|
+
style: {
|
|
428
|
+
position: "absolute",
|
|
429
|
+
bottom: 0,
|
|
430
|
+
left: 0,
|
|
431
|
+
height: "3px",
|
|
432
|
+
background: typeColors[type],
|
|
433
|
+
animation: `aark-notification-progress ${timer}ms linear forwards`,
|
|
434
|
+
transformOrigin: "left"
|
|
435
|
+
}
|
|
436
|
+
}
|
|
437
|
+
),
|
|
438
|
+
/* @__PURE__ */ jsxs("div", { style: { display: "flex", alignItems: "flex-start", gap: "0.75rem" }, children: [
|
|
439
|
+
iconElement && /* @__PURE__ */ jsx("div", { className: `aark-notification-icon ${customClass.icon || ""}`, style: { fontSize: "1.25rem", flexShrink: 0, marginTop: "0.125rem" }, children: iconElement }),
|
|
440
|
+
/* @__PURE__ */ jsxs("div", { style: { flex: 1, minWidth: 0 }, children: [
|
|
441
|
+
title && /* @__PURE__ */ jsx("div", { className: `aark-notification-header ${customClass.header || ""}`, children: /* @__PURE__ */ jsx("h4", { className: `aark-notification-title ${customClass.title || ""}`, style: { margin: 0, fontSize: "0.875rem", fontWeight: "600", color: "#1f2937" }, children: title }) }),
|
|
442
|
+
/* @__PURE__ */ jsx("div", { className: `aark-notification-content ${customClass.content || ""}`, style: { marginTop: title ? "0.25rem" : 0 }, children: html ? /* @__PURE__ */ jsx("div", { dangerouslySetInnerHTML: { __html: typeof html === "string" ? html : "" } }) : text ? /* @__PURE__ */ jsx("p", { style: { margin: 0, fontSize: "0.75rem", color: "#6b7280", lineHeight: "1.4" }, children: text }) : null })
|
|
443
|
+
] }),
|
|
444
|
+
showCloseButton && /* @__PURE__ */ jsx(
|
|
445
|
+
"button",
|
|
446
|
+
{
|
|
447
|
+
onClick: (e) => {
|
|
448
|
+
e.stopPropagation();
|
|
449
|
+
onClose();
|
|
450
|
+
},
|
|
451
|
+
className: `aark-notification-close ${customClass.closeButton || ""}`,
|
|
452
|
+
style: {
|
|
453
|
+
background: "none",
|
|
454
|
+
border: "none",
|
|
455
|
+
fontSize: "1rem",
|
|
456
|
+
color: "#9ca3af",
|
|
457
|
+
cursor: "pointer",
|
|
458
|
+
padding: 0,
|
|
459
|
+
lineHeight: 1,
|
|
460
|
+
flexShrink: 0
|
|
461
|
+
},
|
|
462
|
+
"aria-label": "Close notification",
|
|
463
|
+
children: "×"
|
|
464
|
+
}
|
|
465
|
+
)
|
|
466
|
+
] }),
|
|
467
|
+
/* @__PURE__ */ jsx("style", { children: `
|
|
468
|
+
@keyframes aark-notification-progress {
|
|
469
|
+
from {
|
|
470
|
+
transform: scaleX(1);
|
|
471
|
+
}
|
|
472
|
+
to {
|
|
473
|
+
transform: scaleX(0);
|
|
474
|
+
}
|
|
475
|
+
}
|
|
476
|
+
` })
|
|
477
|
+
]
|
|
478
|
+
}
|
|
479
|
+
);
|
|
480
|
+
};
|
|
195
481
|
const Notification = ({ config, onClose }) => {
|
|
196
|
-
const { content, options = {} } = config;
|
|
482
|
+
const { content, props, options = {} } = config;
|
|
197
483
|
const {
|
|
198
484
|
position = "top-right",
|
|
199
485
|
showCloseIcon = true,
|
|
@@ -202,11 +488,11 @@ const Notification = ({ config, onClose }) => {
|
|
|
202
488
|
preventEscClose = false
|
|
203
489
|
} = options;
|
|
204
490
|
useEffect(() => {
|
|
205
|
-
if (autoCloseTime) {
|
|
491
|
+
if (autoCloseTime && !props) {
|
|
206
492
|
const timer = setTimeout(onClose, autoCloseTime);
|
|
207
493
|
return () => clearTimeout(timer);
|
|
208
494
|
}
|
|
209
|
-
}, [autoCloseTime, onClose]);
|
|
495
|
+
}, [autoCloseTime, onClose, props]);
|
|
210
496
|
useEffect(() => {
|
|
211
497
|
const handleKeyDown = (event) => {
|
|
212
498
|
if (event.key === "Escape" && !preventEscClose) {
|
|
@@ -225,31 +511,62 @@ const Notification = ({ config, onClose }) => {
|
|
|
225
511
|
},
|
|
226
512
|
[onClose]
|
|
227
513
|
);
|
|
228
|
-
const contentClasses = `aark-
|
|
229
|
-
const modalContainer =
|
|
514
|
+
const contentClasses = `aark-notification-container ${position} ${className}`.trim();
|
|
515
|
+
const modalContainer = getModalRoot();
|
|
516
|
+
const getPositionStyles = () => {
|
|
517
|
+
const baseStyles = {
|
|
518
|
+
position: "fixed",
|
|
519
|
+
zIndex: 1e4,
|
|
520
|
+
margin: "1rem"
|
|
521
|
+
};
|
|
522
|
+
switch (position) {
|
|
523
|
+
case "top-left":
|
|
524
|
+
return { ...baseStyles, top: 0, left: 0 };
|
|
525
|
+
case "top-center":
|
|
526
|
+
return { ...baseStyles, top: 0, left: "50%", transform: "translateX(-50%)" };
|
|
527
|
+
case "top-right":
|
|
528
|
+
return { ...baseStyles, top: 0, right: 0 };
|
|
529
|
+
case "bottom-left":
|
|
530
|
+
return { ...baseStyles, bottom: 0, left: 0 };
|
|
531
|
+
case "bottom-center":
|
|
532
|
+
return { ...baseStyles, bottom: 0, left: "50%", transform: "translateX(-50%)" };
|
|
533
|
+
case "bottom-right":
|
|
534
|
+
return { ...baseStyles, bottom: 0, right: 0 };
|
|
535
|
+
default:
|
|
536
|
+
return { ...baseStyles, top: 0, right: 0 };
|
|
537
|
+
}
|
|
538
|
+
};
|
|
539
|
+
const renderContent = () => {
|
|
540
|
+
if (props) {
|
|
541
|
+
return /* @__PURE__ */ jsx("div", { className: "aark-notification-wrapper", children: /* @__PURE__ */ jsx(StandardNotification, { props, onClose }) });
|
|
542
|
+
} else if (content) {
|
|
543
|
+
return /* @__PURE__ */ jsxs(
|
|
544
|
+
"div",
|
|
545
|
+
{
|
|
546
|
+
className: contentClasses,
|
|
547
|
+
role: "alert",
|
|
548
|
+
"aria-live": "polite",
|
|
549
|
+
"aria-labelledby": "aark-notification-content",
|
|
550
|
+
children: [
|
|
551
|
+
showCloseIcon && /* @__PURE__ */ jsx(
|
|
552
|
+
"button",
|
|
553
|
+
{
|
|
554
|
+
onClick: handleCloseClick,
|
|
555
|
+
className: "aark-notification-close",
|
|
556
|
+
"aria-label": "Close notification",
|
|
557
|
+
type: "button",
|
|
558
|
+
children: "×"
|
|
559
|
+
}
|
|
560
|
+
),
|
|
561
|
+
/* @__PURE__ */ jsx("div", { id: "aark-notification-body", className: "aark-notification-body", children: content })
|
|
562
|
+
]
|
|
563
|
+
}
|
|
564
|
+
);
|
|
565
|
+
}
|
|
566
|
+
return null;
|
|
567
|
+
};
|
|
230
568
|
return createPortal(
|
|
231
|
-
/* @__PURE__ */
|
|
232
|
-
"div",
|
|
233
|
-
{
|
|
234
|
-
className: contentClasses,
|
|
235
|
-
role: "alert",
|
|
236
|
-
"aria-live": "polite",
|
|
237
|
-
"aria-labelledby": "aark-notification-content",
|
|
238
|
-
children: [
|
|
239
|
-
showCloseIcon && /* @__PURE__ */ jsx(
|
|
240
|
-
"button",
|
|
241
|
-
{
|
|
242
|
-
onClick: handleCloseClick,
|
|
243
|
-
className: "aark-modal-close",
|
|
244
|
-
"aria-label": "Close notification",
|
|
245
|
-
type: "button",
|
|
246
|
-
children: "×"
|
|
247
|
-
}
|
|
248
|
-
),
|
|
249
|
-
/* @__PURE__ */ jsx("div", { id: "aark-notification-content", className: "aark-modal-body", children: content })
|
|
250
|
-
]
|
|
251
|
-
}
|
|
252
|
-
),
|
|
569
|
+
/* @__PURE__ */ jsx("div", { style: getPositionStyles(), children: renderContent() }),
|
|
253
570
|
modalContainer
|
|
254
571
|
);
|
|
255
572
|
};
|
|
@@ -268,19 +585,12 @@ const ModalProvider = () => {
|
|
|
268
585
|
};
|
|
269
586
|
const listeners = /* @__PURE__ */ new Set();
|
|
270
587
|
let currentConfig = null;
|
|
271
|
-
let container = null;
|
|
272
588
|
let root = null;
|
|
273
589
|
function init() {
|
|
274
|
-
if (
|
|
275
|
-
container =
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
container.style.zIndex = "9999";
|
|
279
|
-
document.body.appendChild(container);
|
|
280
|
-
if (container) {
|
|
281
|
-
root = createRoot(container);
|
|
282
|
-
root.render(createElement(ModalProvider));
|
|
283
|
-
}
|
|
590
|
+
if (root) return;
|
|
591
|
+
const container = getModalRoot();
|
|
592
|
+
root = createRoot(container);
|
|
593
|
+
root.render(createElement(ModalProvider));
|
|
284
594
|
}
|
|
285
595
|
function subscribe(listener) {
|
|
286
596
|
listeners.add(listener);
|
|
@@ -290,10 +600,20 @@ function emit(type, config) {
|
|
|
290
600
|
const event = { type, config };
|
|
291
601
|
listeners.forEach((listener) => listener(event));
|
|
292
602
|
}
|
|
293
|
-
function fireModal(
|
|
603
|
+
function fireModal(contentOrProps, options) {
|
|
294
604
|
init();
|
|
605
|
+
let content;
|
|
606
|
+
let props;
|
|
607
|
+
if (contentOrProps && typeof contentOrProps === "object" && !("$$typeof" in contentOrProps) && !Array.isArray(contentOrProps)) {
|
|
608
|
+
props = contentOrProps;
|
|
609
|
+
content = void 0;
|
|
610
|
+
} else {
|
|
611
|
+
content = contentOrProps;
|
|
612
|
+
props = void 0;
|
|
613
|
+
}
|
|
295
614
|
const config = {
|
|
296
615
|
content,
|
|
616
|
+
props,
|
|
297
617
|
mode: "modal",
|
|
298
618
|
options: Object.assign(
|
|
299
619
|
{
|
|
@@ -308,10 +628,20 @@ function fireModal(content, options) {
|
|
|
308
628
|
currentConfig = config;
|
|
309
629
|
emit("open", config);
|
|
310
630
|
}
|
|
311
|
-
function fireNotification(
|
|
631
|
+
function fireNotification(contentOrProps, options) {
|
|
312
632
|
init();
|
|
633
|
+
let content;
|
|
634
|
+
let props;
|
|
635
|
+
if (contentOrProps && typeof contentOrProps === "object" && !("$$typeof" in contentOrProps) && !Array.isArray(contentOrProps)) {
|
|
636
|
+
props = contentOrProps;
|
|
637
|
+
content = void 0;
|
|
638
|
+
} else {
|
|
639
|
+
content = contentOrProps;
|
|
640
|
+
props = void 0;
|
|
641
|
+
}
|
|
313
642
|
const config = {
|
|
314
643
|
content,
|
|
644
|
+
props,
|
|
315
645
|
mode: "notification",
|
|
316
646
|
options: Object.assign(
|
|
317
647
|
{
|
|
@@ -326,8 +656,8 @@ function fireNotification(content, options) {
|
|
|
326
656
|
currentConfig = config;
|
|
327
657
|
emit("open", config);
|
|
328
658
|
}
|
|
329
|
-
function fire(
|
|
330
|
-
fireModal(
|
|
659
|
+
function fire(contentOrProps, options) {
|
|
660
|
+
fireModal(contentOrProps, options);
|
|
331
661
|
}
|
|
332
662
|
function close() {
|
|
333
663
|
if (currentConfig) {
|
|
@@ -346,11 +676,11 @@ function closeAll() {
|
|
|
346
676
|
close();
|
|
347
677
|
}
|
|
348
678
|
function cleanup() {
|
|
349
|
-
if (
|
|
350
|
-
|
|
351
|
-
container = null;
|
|
679
|
+
if (root) {
|
|
680
|
+
root.unmount();
|
|
352
681
|
root = null;
|
|
353
682
|
}
|
|
683
|
+
cleanupModalRoot();
|
|
354
684
|
}
|
|
355
685
|
const modalManager = {
|
|
356
686
|
subscribe,
|
|
@@ -546,9 +876,9 @@ function getAarkModalTheme() {
|
|
|
546
876
|
};
|
|
547
877
|
}
|
|
548
878
|
const aark = {
|
|
549
|
-
fire: (
|
|
550
|
-
modal: (
|
|
551
|
-
notification: (
|
|
879
|
+
fire: (contentOrProps, options) => modalManager.fire(contentOrProps, options),
|
|
880
|
+
modal: (contentOrProps, options) => modalManager.fireModal(contentOrProps, options),
|
|
881
|
+
notification: (contentOrProps, options) => modalManager.fireNotification(contentOrProps, options),
|
|
552
882
|
close: () => modalManager.close(),
|
|
553
883
|
isOpen: () => modalManager.isOpen(),
|
|
554
884
|
closeAll: () => modalManager.closeAll(),
|
package/dist/index.d.ts
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
|
+
import "./assets/styles/aark-modal.css";
|
|
1
2
|
export { default as aark } from "./logic/aark";
|
|
2
|
-
export type { ModalOptions, NotificationOptions, ModalPosition, NotificationPosition, ModalMode, ModalConfig, NotificationConfig, ComponentConfig, ModalState, ModalEvent, ModalEventType, } from "./types";
|
|
3
|
+
export type { ModalOptions, NotificationOptions, ModalPosition, NotificationPosition, ModalMode, ModalType, ModalProps, NotificationProps, ModalConfig, NotificationConfig, ComponentConfig, ModalState, ModalEvent, ModalEventType, } from "./types";
|
|
3
4
|
export type { AarkModalTheme } from "./utils/theme";
|
|
4
5
|
export { setAarkModalTheme, resetAarkModalTheme, getAarkModalTheme, } from "./utils/theme";
|
|
5
6
|
export { useModal } from "./hooks/useModal";
|
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
-
import type { ComponentConfig, ModalOptions, NotificationOptions, ModalEvent } from "../types";
|
|
2
|
+
import type { ComponentConfig, ModalOptions, NotificationOptions, ModalEvent, ModalProps, NotificationProps } from "../types";
|
|
3
3
|
type ModalListener = (event: ModalEvent) => void;
|
|
4
4
|
declare function subscribe(listener: ModalListener): () => void;
|
|
5
|
-
declare function fireModal(
|
|
6
|
-
declare function fireNotification(
|
|
7
|
-
declare function fire(
|
|
5
|
+
declare function fireModal(contentOrProps: ReactNode | ModalProps, options?: ModalOptions): void;
|
|
6
|
+
declare function fireNotification(contentOrProps: ReactNode | NotificationProps, options?: NotificationOptions): void;
|
|
7
|
+
declare function fire(contentOrProps: ReactNode | ModalProps, options?: ModalOptions): void;
|
|
8
8
|
declare function close(): void;
|
|
9
9
|
declare function isOpen(): boolean;
|
|
10
10
|
declare function getCurrentConfig(): ComponentConfig | null;
|
package/dist/logic/aark.d.ts
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type { ReactNode } from "react";
|
|
2
|
-
import type { ModalOptions, NotificationOptions } from "../types";
|
|
2
|
+
import type { ModalOptions, NotificationOptions, ModalProps, NotificationProps } from "../types";
|
|
3
3
|
import type { AarkModalTheme } from "../utils/theme";
|
|
4
4
|
declare const aark: {
|
|
5
|
-
fire: (
|
|
6
|
-
modal: (
|
|
7
|
-
notification: (
|
|
5
|
+
fire: (contentOrProps: ReactNode | ModalProps, options?: ModalOptions) => void;
|
|
6
|
+
modal: (contentOrProps: ReactNode | ModalProps, options?: ModalOptions) => void;
|
|
7
|
+
notification: (contentOrProps: ReactNode | NotificationProps, options?: NotificationOptions) => void;
|
|
8
8
|
close: () => void;
|
|
9
9
|
isOpen: () => boolean;
|
|
10
10
|
closeAll: () => void;
|