aark-react-modalify 1.2.0 → 1.2.2
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 +73 -603
- package/dist/aark-react-modalify.css +1 -1
- package/dist/index-no-styles.esm.js +14 -898
- package/dist/index.cjs.js +51 -0
- package/dist/index.esm.js +62 -0
- package/package.json +18 -18
|
@@ -1,898 +1,14 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
setIsOpen(true);
|
|
16
|
-
setConfig(event.config || null);
|
|
17
|
-
break;
|
|
18
|
-
case "close":
|
|
19
|
-
setIsOpen(false);
|
|
20
|
-
setConfig(null);
|
|
21
|
-
break;
|
|
22
|
-
}
|
|
23
|
-
};
|
|
24
|
-
const unsubscribe = modalManager.subscribe(handleModalEvent);
|
|
25
|
-
setIsOpen(modalManager.isOpen());
|
|
26
|
-
setConfig(modalManager.getCurrentConfig());
|
|
27
|
-
return unsubscribe;
|
|
28
|
-
}, []);
|
|
29
|
-
return {
|
|
30
|
-
isOpen: isOpen2,
|
|
31
|
-
config,
|
|
32
|
-
close: close2
|
|
33
|
-
};
|
|
34
|
-
}
|
|
35
|
-
const colors = {
|
|
36
|
-
white: "#FFFFFF",
|
|
37
|
-
black: "#0B071A"
|
|
38
|
-
};
|
|
39
|
-
const Icon = memo(
|
|
40
|
-
({
|
|
41
|
-
name,
|
|
42
|
-
color = "black",
|
|
43
|
-
style,
|
|
44
|
-
className = "",
|
|
45
|
-
noHoverEffect = false,
|
|
46
|
-
onClick,
|
|
47
|
-
size = 24,
|
|
48
|
-
"aria-label": ariaLabel,
|
|
49
|
-
title
|
|
50
|
-
}) => {
|
|
51
|
-
const resolvedSize = useMemo(() => {
|
|
52
|
-
return String(size);
|
|
53
|
-
}, [size]);
|
|
54
|
-
const resolvedColor = useMemo(() => {
|
|
55
|
-
if (colors[color]) {
|
|
56
|
-
return colors[color];
|
|
57
|
-
}
|
|
58
|
-
if (color.startsWith("#")) {
|
|
59
|
-
return color;
|
|
60
|
-
}
|
|
61
|
-
return color;
|
|
62
|
-
}, [color]);
|
|
63
|
-
const iconElement = useMemo(() => {
|
|
64
|
-
const fill = resolvedColor;
|
|
65
|
-
switch (name) {
|
|
66
|
-
case "close":
|
|
67
|
-
return /* @__PURE__ */ jsx("svg", { xmlns: "http://www.w3.org/2000/svg", width: resolvedSize, height: resolvedSize, viewBox: "0 0 16 16", fill: "none", children: /* @__PURE__ */ jsx("path", { d: "M15.281 14.2198C15.3507 14.2895 15.406 14.3722 15.4437 14.4632C15.4814 14.5543 15.5008 14.6519 15.5008 14.7504C15.5008 14.849 15.4814 14.9465 15.4437 15.0376C15.406 15.1286 15.3507 15.2114 15.281 15.281C15.2114 15.3507 15.1286 15.406 15.0376 15.4437C14.9465 15.4814 14.849 15.5008 14.7504 15.5008C14.6519 15.5008 14.5543 15.4814 14.4632 15.4437C14.3722 15.406 14.2895 15.3507 14.2198 15.281L8.00042 9.06073L1.78104 15.281C1.64031 15.4218 1.44944 15.5008 1.25042 15.5008C1.05139 15.5008 0.860523 15.4218 0.719792 15.281C0.579062 15.1403 0.5 14.9494 0.5 14.7504C0.5 14.5514 0.579062 14.3605 0.719792 14.2198L6.9401 8.00042L0.719792 1.78104C0.579062 1.64031 0.5 1.44944 0.5 1.25042C0.5 1.05139 0.579062 0.860523 0.719792 0.719792C0.860523 0.579062 1.05139 0.5 1.25042 0.5C1.44944 0.5 1.64031 0.579062 1.78104 0.719792L8.00042 6.9401L14.2198 0.719792C14.3605 0.579062 14.5514 0.5 14.7504 0.5C14.9494 0.5 15.1403 0.579062 15.281 0.719792C15.4218 0.860523 15.5008 1.05139 15.5008 1.25042C15.5008 1.44944 15.4218 1.64031 15.281 1.78104L9.06073 8.00042L15.281 14.2198Z", fill }) });
|
|
68
|
-
default:
|
|
69
|
-
return null;
|
|
70
|
-
}
|
|
71
|
-
}, [name, resolvedColor, resolvedSize]);
|
|
72
|
-
const accessibilityProps = useMemo(() => {
|
|
73
|
-
const props = {};
|
|
74
|
-
if (ariaLabel) {
|
|
75
|
-
props["aria-label"] = ariaLabel;
|
|
76
|
-
} else {
|
|
77
|
-
props["aria-label"] = `${name} icon`;
|
|
78
|
-
}
|
|
79
|
-
if (title) {
|
|
80
|
-
props.title = title;
|
|
81
|
-
}
|
|
82
|
-
props.role = onClick ? "button" : "img";
|
|
83
|
-
return props;
|
|
84
|
-
}, [ariaLabel, title, name, onClick]);
|
|
85
|
-
const handleKeyDown = useMemo(() => {
|
|
86
|
-
if (!onClick) return void 0;
|
|
87
|
-
return (event) => {
|
|
88
|
-
if (event.key === "Enter" || event.key === " ") {
|
|
89
|
-
event.preventDefault();
|
|
90
|
-
onClick();
|
|
91
|
-
}
|
|
92
|
-
};
|
|
93
|
-
}, [onClick]);
|
|
94
|
-
return /* @__PURE__ */ jsx(
|
|
95
|
-
"i",
|
|
96
|
-
{
|
|
97
|
-
className: `
|
|
98
|
-
inline-flex items-center justify-center bg-transparent outline-none border-none
|
|
99
|
-
${!noHoverEffect && onClick && "hover:opacity-80 cursor-pointer transition-opacity duration-200"}
|
|
100
|
-
${onClick && "focus:outline-2 focus:outline-blue-500 focus:outline-offset-2"}
|
|
101
|
-
${className}
|
|
102
|
-
`.trim(),
|
|
103
|
-
style,
|
|
104
|
-
onClick,
|
|
105
|
-
onKeyDown: handleKeyDown,
|
|
106
|
-
tabIndex: onClick ? 0 : void 0,
|
|
107
|
-
...accessibilityProps,
|
|
108
|
-
children: iconElement
|
|
109
|
-
}
|
|
110
|
-
);
|
|
111
|
-
}
|
|
112
|
-
);
|
|
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
|
-
};
|
|
238
|
-
const Modal = ({ config, onClose }) => {
|
|
239
|
-
const { content, props, options = {} } = config;
|
|
240
|
-
const {
|
|
241
|
-
position = "center",
|
|
242
|
-
showCloseIcon = true,
|
|
243
|
-
className = "",
|
|
244
|
-
overlayClassName = "",
|
|
245
|
-
preventEscClose = false,
|
|
246
|
-
preventOverlayClose = false
|
|
247
|
-
} = options;
|
|
248
|
-
useEffect(() => {
|
|
249
|
-
const handleKeyDown = (event) => {
|
|
250
|
-
if (event.key === "Escape" && !preventEscClose) {
|
|
251
|
-
onClose();
|
|
252
|
-
}
|
|
253
|
-
};
|
|
254
|
-
if (!preventEscClose) {
|
|
255
|
-
document.addEventListener("keydown", handleKeyDown);
|
|
256
|
-
return () => document.removeEventListener("keydown", handleKeyDown);
|
|
257
|
-
}
|
|
258
|
-
}, [onClose, preventEscClose]);
|
|
259
|
-
const handleOverlayClick = useCallback(
|
|
260
|
-
(event) => {
|
|
261
|
-
if (event.target === event.currentTarget && !preventOverlayClose) {
|
|
262
|
-
onClose();
|
|
263
|
-
}
|
|
264
|
-
},
|
|
265
|
-
[onClose, preventOverlayClose]
|
|
266
|
-
);
|
|
267
|
-
const handleCloseClick = useCallback(
|
|
268
|
-
(event) => {
|
|
269
|
-
event.stopPropagation();
|
|
270
|
-
onClose();
|
|
271
|
-
},
|
|
272
|
-
[onClose]
|
|
273
|
-
);
|
|
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
|
-
};
|
|
326
|
-
return createPortal(
|
|
327
|
-
/* @__PURE__ */ jsx(
|
|
328
|
-
"div",
|
|
329
|
-
{
|
|
330
|
-
className: `aark-modal-overlay ${overlayClassName}`.trim(),
|
|
331
|
-
onClick: handleOverlayClick,
|
|
332
|
-
"aria-hidden": "true",
|
|
333
|
-
style: {
|
|
334
|
-
position: "fixed",
|
|
335
|
-
inset: 0,
|
|
336
|
-
zIndex: 9999,
|
|
337
|
-
background: "var(--aark-modal-overlay-bg)",
|
|
338
|
-
backdropFilter: "blur(2px)",
|
|
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"
|
|
344
|
-
},
|
|
345
|
-
children: renderContent()
|
|
346
|
-
}
|
|
347
|
-
),
|
|
348
|
-
modalContainer
|
|
349
|
-
);
|
|
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
|
-
};
|
|
481
|
-
const Notification = ({ config, onClose }) => {
|
|
482
|
-
const { content, props, options = {} } = config;
|
|
483
|
-
const {
|
|
484
|
-
position = "top-right",
|
|
485
|
-
showCloseIcon = true,
|
|
486
|
-
autoCloseTime = 5e3,
|
|
487
|
-
className = "",
|
|
488
|
-
preventEscClose = false
|
|
489
|
-
} = options;
|
|
490
|
-
useEffect(() => {
|
|
491
|
-
if (autoCloseTime && !props) {
|
|
492
|
-
const timer = setTimeout(onClose, autoCloseTime);
|
|
493
|
-
return () => clearTimeout(timer);
|
|
494
|
-
}
|
|
495
|
-
}, [autoCloseTime, onClose, props]);
|
|
496
|
-
useEffect(() => {
|
|
497
|
-
const handleKeyDown = (event) => {
|
|
498
|
-
if (event.key === "Escape" && !preventEscClose) {
|
|
499
|
-
onClose();
|
|
500
|
-
}
|
|
501
|
-
};
|
|
502
|
-
if (!preventEscClose) {
|
|
503
|
-
document.addEventListener("keydown", handleKeyDown);
|
|
504
|
-
return () => document.removeEventListener("keydown", handleKeyDown);
|
|
505
|
-
}
|
|
506
|
-
}, [onClose, preventEscClose]);
|
|
507
|
-
const handleCloseClick = useCallback(
|
|
508
|
-
(event) => {
|
|
509
|
-
event.stopPropagation();
|
|
510
|
-
onClose();
|
|
511
|
-
},
|
|
512
|
-
[onClose]
|
|
513
|
-
);
|
|
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
|
-
};
|
|
568
|
-
return createPortal(
|
|
569
|
-
/* @__PURE__ */ jsx("div", { style: getPositionStyles(), children: renderContent() }),
|
|
570
|
-
modalContainer
|
|
571
|
-
);
|
|
572
|
-
};
|
|
573
|
-
const ModalProvider = () => {
|
|
574
|
-
const { isOpen: isOpen2, config, close: close2 } = useModal();
|
|
575
|
-
if (!isOpen2 || !config) {
|
|
576
|
-
return null;
|
|
577
|
-
}
|
|
578
|
-
if (config.mode === "modal") {
|
|
579
|
-
return /* @__PURE__ */ jsx(Modal, { config, onClose: close2 });
|
|
580
|
-
}
|
|
581
|
-
if (config.mode === "notification") {
|
|
582
|
-
return /* @__PURE__ */ jsx(Notification, { config, onClose: close2 });
|
|
583
|
-
}
|
|
584
|
-
return null;
|
|
585
|
-
};
|
|
586
|
-
const listeners = /* @__PURE__ */ new Set();
|
|
587
|
-
let currentConfig = null;
|
|
588
|
-
let root = null;
|
|
589
|
-
function init() {
|
|
590
|
-
if (root) return;
|
|
591
|
-
const container = getModalRoot();
|
|
592
|
-
root = createRoot(container);
|
|
593
|
-
root.render(createElement(ModalProvider));
|
|
594
|
-
}
|
|
595
|
-
function subscribe(listener) {
|
|
596
|
-
listeners.add(listener);
|
|
597
|
-
return () => listeners.delete(listener);
|
|
598
|
-
}
|
|
599
|
-
function emit(type, config) {
|
|
600
|
-
const event = { type, config };
|
|
601
|
-
listeners.forEach((listener) => listener(event));
|
|
602
|
-
}
|
|
603
|
-
function fireModal(contentOrProps, options) {
|
|
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
|
-
}
|
|
614
|
-
const config = {
|
|
615
|
-
content,
|
|
616
|
-
props,
|
|
617
|
-
mode: "modal",
|
|
618
|
-
options: Object.assign(
|
|
619
|
-
{
|
|
620
|
-
position: "center",
|
|
621
|
-
showCloseIcon: true,
|
|
622
|
-
preventEscClose: false,
|
|
623
|
-
preventOverlayClose: false
|
|
624
|
-
},
|
|
625
|
-
options
|
|
626
|
-
)
|
|
627
|
-
};
|
|
628
|
-
currentConfig = config;
|
|
629
|
-
emit("open", config);
|
|
630
|
-
}
|
|
631
|
-
function fireNotification(contentOrProps, options) {
|
|
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
|
-
}
|
|
642
|
-
const config = {
|
|
643
|
-
content,
|
|
644
|
-
props,
|
|
645
|
-
mode: "notification",
|
|
646
|
-
options: Object.assign(
|
|
647
|
-
{
|
|
648
|
-
position: "top-right",
|
|
649
|
-
showCloseIcon: true,
|
|
650
|
-
autoCloseTime: 5e3,
|
|
651
|
-
preventEscClose: false
|
|
652
|
-
},
|
|
653
|
-
options
|
|
654
|
-
)
|
|
655
|
-
};
|
|
656
|
-
currentConfig = config;
|
|
657
|
-
emit("open", config);
|
|
658
|
-
}
|
|
659
|
-
function fire(contentOrProps, options) {
|
|
660
|
-
fireModal(contentOrProps, options);
|
|
661
|
-
}
|
|
662
|
-
function close() {
|
|
663
|
-
if (currentConfig) {
|
|
664
|
-
emit("beforeClose", currentConfig);
|
|
665
|
-
currentConfig = null;
|
|
666
|
-
emit("close");
|
|
667
|
-
}
|
|
668
|
-
}
|
|
669
|
-
function isOpen() {
|
|
670
|
-
return currentConfig !== null;
|
|
671
|
-
}
|
|
672
|
-
function getCurrentConfig() {
|
|
673
|
-
return currentConfig;
|
|
674
|
-
}
|
|
675
|
-
function closeAll() {
|
|
676
|
-
close();
|
|
677
|
-
}
|
|
678
|
-
function cleanup() {
|
|
679
|
-
if (root) {
|
|
680
|
-
root.unmount();
|
|
681
|
-
root = null;
|
|
682
|
-
}
|
|
683
|
-
cleanupModalRoot();
|
|
684
|
-
}
|
|
685
|
-
const modalManager = {
|
|
686
|
-
subscribe,
|
|
687
|
-
fire,
|
|
688
|
-
fireModal,
|
|
689
|
-
fireNotification,
|
|
690
|
-
close,
|
|
691
|
-
isOpen,
|
|
692
|
-
getCurrentConfig,
|
|
693
|
-
closeAll,
|
|
694
|
-
cleanup
|
|
695
|
-
};
|
|
696
|
-
function setAarkModalTheme(theme) {
|
|
697
|
-
const root2 = document.documentElement;
|
|
698
|
-
if (theme.overlayBackground) {
|
|
699
|
-
root2.style.setProperty("--aark-modal-overlay-bg", theme.overlayBackground);
|
|
700
|
-
}
|
|
701
|
-
if (theme.overlayBlur) {
|
|
702
|
-
root2.style.setProperty("--aark-modal-overlay-blur", theme.overlayBlur);
|
|
703
|
-
}
|
|
704
|
-
if (theme.modalBackground) {
|
|
705
|
-
root2.style.setProperty("--aark-modal-bg", theme.modalBackground);
|
|
706
|
-
}
|
|
707
|
-
if (theme.modalBorderRadius) {
|
|
708
|
-
root2.style.setProperty(
|
|
709
|
-
"--aark-modal-border-radius",
|
|
710
|
-
theme.modalBorderRadius
|
|
711
|
-
);
|
|
712
|
-
}
|
|
713
|
-
if (theme.modalShadow) {
|
|
714
|
-
root2.style.setProperty("--aark-modal-shadow", theme.modalShadow);
|
|
715
|
-
}
|
|
716
|
-
if (theme.modalPadding) {
|
|
717
|
-
root2.style.setProperty("--aark-modal-padding", theme.modalPadding);
|
|
718
|
-
}
|
|
719
|
-
if (theme.modalZIndex) {
|
|
720
|
-
root2.style.setProperty(
|
|
721
|
-
"--aark-modal-z-index",
|
|
722
|
-
theme.modalZIndex.toString()
|
|
723
|
-
);
|
|
724
|
-
}
|
|
725
|
-
if (theme.modalContentZIndex) {
|
|
726
|
-
root2.style.setProperty(
|
|
727
|
-
"--aark-modal-content-z-index",
|
|
728
|
-
theme.modalContentZIndex.toString()
|
|
729
|
-
);
|
|
730
|
-
}
|
|
731
|
-
if (theme.closeButtonColor) {
|
|
732
|
-
root2.style.setProperty("--aark-modal-close-color", theme.closeButtonColor);
|
|
733
|
-
}
|
|
734
|
-
if (theme.closeButtonHoverBackground) {
|
|
735
|
-
root2.style.setProperty(
|
|
736
|
-
"--aark-modal-close-hover-bg",
|
|
737
|
-
theme.closeButtonHoverBackground
|
|
738
|
-
);
|
|
739
|
-
}
|
|
740
|
-
if (theme.closeButtonHoverColor) {
|
|
741
|
-
root2.style.setProperty(
|
|
742
|
-
"--aark-modal-close-hover-color",
|
|
743
|
-
theme.closeButtonHoverColor
|
|
744
|
-
);
|
|
745
|
-
}
|
|
746
|
-
if (theme.closeButtonFocusOutline) {
|
|
747
|
-
root2.style.setProperty(
|
|
748
|
-
"--aark-modal-close-focus-outline",
|
|
749
|
-
theme.closeButtonFocusOutline
|
|
750
|
-
);
|
|
751
|
-
}
|
|
752
|
-
if (theme.animationDuration) {
|
|
753
|
-
root2.style.setProperty(
|
|
754
|
-
"--aark-modal-animation-duration",
|
|
755
|
-
theme.animationDuration
|
|
756
|
-
);
|
|
757
|
-
}
|
|
758
|
-
if (theme.fadeDuration) {
|
|
759
|
-
root2.style.setProperty("--aark-modal-fade-duration", theme.fadeDuration);
|
|
760
|
-
}
|
|
761
|
-
if (theme.customOverlayBackground) {
|
|
762
|
-
root2.style.setProperty(
|
|
763
|
-
"--aark-custom-overlay-bg",
|
|
764
|
-
theme.customOverlayBackground
|
|
765
|
-
);
|
|
766
|
-
}
|
|
767
|
-
if (theme.customOverlayBlur) {
|
|
768
|
-
root2.style.setProperty(
|
|
769
|
-
"--aark-custom-overlay-blur",
|
|
770
|
-
theme.customOverlayBlur
|
|
771
|
-
);
|
|
772
|
-
}
|
|
773
|
-
if (theme.customModalGradientStart) {
|
|
774
|
-
root2.style.setProperty(
|
|
775
|
-
"--aark-custom-modal-gradient-start",
|
|
776
|
-
theme.customModalGradientStart
|
|
777
|
-
);
|
|
778
|
-
}
|
|
779
|
-
if (theme.customModalGradientEnd) {
|
|
780
|
-
root2.style.setProperty(
|
|
781
|
-
"--aark-custom-modal-gradient-end",
|
|
782
|
-
theme.customModalGradientEnd
|
|
783
|
-
);
|
|
784
|
-
}
|
|
785
|
-
if (theme.customModalTextColor) {
|
|
786
|
-
root2.style.setProperty(
|
|
787
|
-
"--aark-custom-modal-text-color",
|
|
788
|
-
theme.customModalTextColor
|
|
789
|
-
);
|
|
790
|
-
}
|
|
791
|
-
if (theme.customModalShadow) {
|
|
792
|
-
root2.style.setProperty(
|
|
793
|
-
"--aark-custom-modal-shadow",
|
|
794
|
-
theme.customModalShadow
|
|
795
|
-
);
|
|
796
|
-
}
|
|
797
|
-
if (theme.customModalCloseColor) {
|
|
798
|
-
root2.style.setProperty(
|
|
799
|
-
"--aark-custom-modal-close-color",
|
|
800
|
-
theme.customModalCloseColor
|
|
801
|
-
);
|
|
802
|
-
}
|
|
803
|
-
if (theme.customModalCloseHoverBackground) {
|
|
804
|
-
root2.style.setProperty(
|
|
805
|
-
"--aark-custom-modal-close-hover-bg",
|
|
806
|
-
theme.customModalCloseHoverBackground
|
|
807
|
-
);
|
|
808
|
-
}
|
|
809
|
-
if (theme.customModalCloseHoverColor) {
|
|
810
|
-
root2.style.setProperty(
|
|
811
|
-
"--aark-custom-modal-close-hover-color",
|
|
812
|
-
theme.customModalCloseHoverColor
|
|
813
|
-
);
|
|
814
|
-
}
|
|
815
|
-
}
|
|
816
|
-
function resetAarkModalTheme() {
|
|
817
|
-
const root2 = document.documentElement;
|
|
818
|
-
const properties = [
|
|
819
|
-
"--aark-modal-overlay-bg",
|
|
820
|
-
"--aark-modal-overlay-blur",
|
|
821
|
-
"--aark-modal-bg",
|
|
822
|
-
"--aark-modal-border-radius",
|
|
823
|
-
"--aark-modal-shadow",
|
|
824
|
-
"--aark-modal-padding",
|
|
825
|
-
"--aark-modal-z-index",
|
|
826
|
-
"--aark-modal-content-z-index",
|
|
827
|
-
"--aark-modal-close-color",
|
|
828
|
-
"--aark-modal-close-hover-bg",
|
|
829
|
-
"--aark-modal-close-hover-color",
|
|
830
|
-
"--aark-modal-close-focus-outline",
|
|
831
|
-
"--aark-modal-animation-duration",
|
|
832
|
-
"--aark-modal-fade-duration",
|
|
833
|
-
"--aark-custom-overlay-bg",
|
|
834
|
-
"--aark-custom-overlay-blur",
|
|
835
|
-
"--aark-custom-modal-gradient-start",
|
|
836
|
-
"--aark-custom-modal-gradient-end",
|
|
837
|
-
"--aark-custom-modal-text-color",
|
|
838
|
-
"--aark-custom-modal-shadow",
|
|
839
|
-
"--aark-custom-modal-close-color",
|
|
840
|
-
"--aark-custom-modal-close-hover-bg",
|
|
841
|
-
"--aark-custom-modal-close-hover-color"
|
|
842
|
-
];
|
|
843
|
-
properties.forEach((property) => {
|
|
844
|
-
root2.style.removeProperty(property);
|
|
845
|
-
});
|
|
846
|
-
}
|
|
847
|
-
function getAarkModalTheme() {
|
|
848
|
-
const root2 = document.documentElement;
|
|
849
|
-
const computedStyle = getComputedStyle(root2);
|
|
850
|
-
return {
|
|
851
|
-
overlayBackground: computedStyle.getPropertyValue("--aark-modal-overlay-bg").trim(),
|
|
852
|
-
overlayBlur: computedStyle.getPropertyValue("--aark-modal-overlay-blur").trim(),
|
|
853
|
-
modalBackground: computedStyle.getPropertyValue("--aark-modal-bg").trim(),
|
|
854
|
-
modalBorderRadius: computedStyle.getPropertyValue("--aark-modal-border-radius").trim(),
|
|
855
|
-
modalShadow: computedStyle.getPropertyValue("--aark-modal-shadow").trim(),
|
|
856
|
-
modalPadding: computedStyle.getPropertyValue("--aark-modal-padding").trim(),
|
|
857
|
-
modalZIndex: parseInt(computedStyle.getPropertyValue("--aark-modal-z-index").trim()) || void 0,
|
|
858
|
-
modalContentZIndex: parseInt(
|
|
859
|
-
computedStyle.getPropertyValue("--aark-modal-content-z-index").trim()
|
|
860
|
-
) || void 0,
|
|
861
|
-
closeButtonColor: computedStyle.getPropertyValue("--aark-modal-close-color").trim(),
|
|
862
|
-
closeButtonHoverBackground: computedStyle.getPropertyValue("--aark-modal-close-hover-bg").trim(),
|
|
863
|
-
closeButtonHoverColor: computedStyle.getPropertyValue("--aark-modal-close-hover-color").trim(),
|
|
864
|
-
closeButtonFocusOutline: computedStyle.getPropertyValue("--aark-modal-close-focus-outline").trim(),
|
|
865
|
-
animationDuration: computedStyle.getPropertyValue("--aark-modal-animation-duration").trim(),
|
|
866
|
-
fadeDuration: computedStyle.getPropertyValue("--aark-modal-fade-duration").trim(),
|
|
867
|
-
customOverlayBackground: computedStyle.getPropertyValue("--aark-custom-overlay-bg").trim(),
|
|
868
|
-
customOverlayBlur: computedStyle.getPropertyValue("--aark-custom-overlay-blur").trim(),
|
|
869
|
-
customModalGradientStart: computedStyle.getPropertyValue("--aark-custom-modal-gradient-start").trim(),
|
|
870
|
-
customModalGradientEnd: computedStyle.getPropertyValue("--aark-custom-modal-gradient-end").trim(),
|
|
871
|
-
customModalTextColor: computedStyle.getPropertyValue("--aark-custom-modal-text-color").trim(),
|
|
872
|
-
customModalShadow: computedStyle.getPropertyValue("--aark-custom-modal-shadow").trim(),
|
|
873
|
-
customModalCloseColor: computedStyle.getPropertyValue("--aark-custom-modal-close-color").trim(),
|
|
874
|
-
customModalCloseHoverBackground: computedStyle.getPropertyValue("--aark-custom-modal-close-hover-bg").trim(),
|
|
875
|
-
customModalCloseHoverColor: computedStyle.getPropertyValue("--aark-custom-modal-close-hover-color").trim()
|
|
876
|
-
};
|
|
877
|
-
}
|
|
878
|
-
const aark = {
|
|
879
|
-
fire: (contentOrProps, options) => modalManager.fire(contentOrProps, options),
|
|
880
|
-
modal: (contentOrProps, options) => modalManager.fireModal(contentOrProps, options),
|
|
881
|
-
notification: (contentOrProps, options) => modalManager.fireNotification(contentOrProps, options),
|
|
882
|
-
close: () => modalManager.close(),
|
|
883
|
-
isOpen: () => modalManager.isOpen(),
|
|
884
|
-
closeAll: () => modalManager.closeAll(),
|
|
885
|
-
setTheme: (theme) => setAarkModalTheme(theme),
|
|
886
|
-
resetTheme: () => resetAarkModalTheme(),
|
|
887
|
-
getTheme: () => getAarkModalTheme()
|
|
888
|
-
};
|
|
889
|
-
export {
|
|
890
|
-
Modal,
|
|
891
|
-
ModalProvider,
|
|
892
|
-
Notification,
|
|
893
|
-
aark,
|
|
894
|
-
getAarkModalTheme,
|
|
895
|
-
resetAarkModalTheme,
|
|
896
|
-
setAarkModalTheme,
|
|
897
|
-
useModal
|
|
898
|
-
};
|
|
1
|
+
import{useState as o,useCallback as e,useEffect as t,memo as a,useMemo as r,createElement as n}from"react";import{createRoot as l}from"react-dom/client";import{jsx as i,jsxs as s}from"react/jsx-runtime";import{createPortal as c}from"react-dom";function d(){const[a,r]=o(!1),[n,l]=o(null),i=e(()=>{E.close()},[]);return t(()=>{const o=E.subscribe(o=>{switch(o.type){case"open":r(!0),l(o.config||null);break;case"close":r(!1),l(null)}});return r(E.isOpen()),l(E.getCurrentConfig()),o},[]),{isOpen:a,config:n,close:i}}const m={white:"#FFFFFF",black:"#0B071A"},u=a(({name:o,color:e="black",style:t,className:a="",noHoverEffect:n=!1,onClick:l,size:s=24,"aria-label":c,title:d})=>{const u=r(()=>String(s),[s]),p=r(()=>m[e]?m[e]:(e.startsWith("#"),e),[e]),f=r(()=>"close"===o?/* @__PURE__ */i("svg",{xmlns:"http://www.w3.org/2000/svg",width:u,height:u,viewBox:"0 0 16 16",fill:"none",children:/* @__PURE__ */i("path",{d:"M15.281 14.2198C15.3507 14.2895 15.406 14.3722 15.4437 14.4632C15.4814 14.5543 15.5008 14.6519 15.5008 14.7504C15.5008 14.849 15.4814 14.9465 15.4437 15.0376C15.406 15.1286 15.3507 15.2114 15.281 15.281C15.2114 15.3507 15.1286 15.406 15.0376 15.4437C14.9465 15.4814 14.849 15.5008 14.7504 15.5008C14.6519 15.5008 14.5543 15.4814 14.4632 15.4437C14.3722 15.406 14.2895 15.3507 14.2198 15.281L8.00042 9.06073L1.78104 15.281C1.64031 15.4218 1.44944 15.5008 1.25042 15.5008C1.05139 15.5008 0.860523 15.4218 0.719792 15.281C0.579062 15.1403 0.5 14.9494 0.5 14.7504C0.5 14.5514 0.579062 14.3605 0.719792 14.2198L6.9401 8.00042L0.719792 1.78104C0.579062 1.64031 0.5 1.44944 0.5 1.25042C0.5 1.05139 0.579062 0.860523 0.719792 0.719792C0.860523 0.579062 1.05139 0.5 1.25042 0.5C1.44944 0.5 1.64031 0.579062 1.78104 0.719792L8.00042 6.9401L14.2198 0.719792C14.3605 0.579062 14.5514 0.5 14.7504 0.5C14.9494 0.5 15.1403 0.579062 15.281 0.719792C15.4218 0.860523 15.5008 1.05139 15.5008 1.25042C15.5008 1.44944 15.4218 1.64031 15.281 1.78104L9.06073 8.00042L15.281 14.2198Z",fill:p})}):null,[o,p,u]),y=r(()=>{const e={};return e["aria-label"]=c||`${o} icon`,d&&(e.title=d),e.role=l?"button":"img",e},[c,d,o,l]),k=r(()=>{if(l)return o=>{"Enter"!==o.key&&" "!==o.key||(o.preventDefault(),l())}},[l]);/* @__PURE__ */
|
|
2
|
+
return i("i",{className:`\n inline-flex items-center justify-center bg-transparent outline-none border-none\n ${!n&&l&&"hover:opacity-80 cursor-pointer transition-opacity duration-200"}\n ${l&&"focus:outline-2 focus:outline-blue-500 focus:outline-offset-2"}\n ${a}\n `.trim(),style:t,onClick:l,onKeyDown:k,tabIndex:l?0:void 0,...y,children:f})});u.displayName="Icon";const p={success:"✓",error:"✕",warning:"⚠",info:"ⓘ",question:"?"},f={success:"#4ade80",error:"#ef4444",warning:"#f59e0b",info:"#3b82f6",question:"#8b5cf6"},y=({props:o,onClose:e})=>{const{title:t,text:a,type:n="info",cancelText:l="Cancel",confirmText:c="OK",onCancel:d,onConfirm:m,icon:u,html:y,showCancelButton:k=!1,showConfirmButton:g=!0,reverseButtons:h=!1,width:v="auto",fullWidth:C=!1,customClass:b={}}=o,x=()=>{d?.(),e()},P=()=>{m?.(),e()},w=r(()=>u?"string"==typeof u?/* @__PURE__ */i("span",{children:u}):u:/* @__PURE__ */i("span",{style:{color:f[n]},children:p[n]}),[u,n]),B=h?["confirm","cancel"]:["cancel","confirm"],N=r(()=>{const o={};return C?(o.width="calc(100vw - 20px)",o.maxWidth="calc(100vw - 20px)"):o.width="number"==typeof v?`${v}px`:v,o},[v,C]);/* @__PURE__ */
|
|
3
|
+
return s("div",{className:`aark-standard-modal ${b.popup||""}`,style:N,children:[
|
|
4
|
+
/* @__PURE__ */s("div",{className:`aark-modal-content ${b.content||""}`,children:[w&&/* @__PURE__ */i("div",{className:`aark-modal-icon ${b.icon||""}`,children:w}),t&&/* @__PURE__ */i("div",{className:`aark-modal-header ${b.header||""}`,children:/* @__PURE__ */i("h2",{className:`aark-modal-title ${b.title||""}`,children:t})}),y?/* @__PURE__ */i("div",{dangerouslySetInnerHTML:{__html:"string"==typeof y?y:""}}):a?/* @__PURE__ */i("p",{children:a}):null]}),(k||g)&&/* @__PURE__ */i("div",{className:`aark-modal-footer ${b.actions||""}`,children:B.map(o=>"cancel"===o&&k?/* @__PURE__ */i("button",{onClick:x,className:`aark-modal-cancel-button ${b.cancelButton||""}`,children:l},"cancel"):"confirm"===o&&g?/* @__PURE__ */i("button",{onClick:P,className:`aark-modal-confirm-button ${b.confirmButton||""}`,style:{background:f[n]},children:c},"confirm"):null)})]})};let k=null;const g=()=>(k||(k=document.getElementById("aark-react-modalify-root"),k||(k=document.createElement("div"),k.id="aark-react-modalify-root",k.style.cssText="\n position: fixed;\n top: 0;\n left: 0;\n width: 100%;\n height: 100%;\n pointer-events: none;\n z-index: 9998;\n ",document.body.appendChild(k))),k),h=({config:o,onClose:a})=>{const{content:r,props:n,options:l={}}=o,{position:d="center",showCloseIcon:m=!0,className:p="",overlayClassName:f="",preventEscClose:k=!1,preventOverlayClose:h=!1}=l;t(()=>{const o=o=>{"Escape"!==o.key||k||a()};if(!k)return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[a,k]);const v=e(o=>{o.target!==o.currentTarget||h||a()},[a,h]),C=e(o=>{o.stopPropagation(),a()},[a]),b=`aark-modal-container ${d} ${p}`.trim(),x=g();return c(
|
|
5
|
+
/* @__PURE__ */i("div",{className:`aark-modal-overlay ${f}`.trim(),onClick:v,"aria-hidden":"true",style:{position:"fixed",inset:0,zIndex:9999,background:"var(--aark-modal-overlay-bg)",backdropFilter:"blur(2px)",animation:"fade-in var(--aark-anim)",display:"flex",alignItems:d.includes("center")?"center":d.includes("top")?"flex-start":"flex-end",justifyContent:d.includes("center")?"center":d.includes("right")?"flex-end":"flex-start",padding:"1rem"},children:n?/* @__PURE__ */s("div",{className:b,role:"dialog","aria-modal":"true",onClick:o=>o.stopPropagation(),children:[m&&/* @__PURE__ */i("button",{onClick:C,className:"aark-modal-close","aria-label":"Close Modal",type:"button",children:/* @__PURE__ */i(u,{name:"close",size:12})}),
|
|
6
|
+
/* @__PURE__ */i("div",{className:"aark-modal-wrapper",children:/* @__PURE__ */i(y,{props:n,onClose:a})})]}):r?/* @__PURE__ */s("div",{className:b,role:"dialog","aria-modal":"true",onClick:o=>o.stopPropagation(),children:[m&&/* @__PURE__ */i("button",{onClick:C,className:"aark-modal-close","aria-label":"Close Modal",type:"button",children:/* @__PURE__ */i(u,{name:"close",size:12})}),
|
|
7
|
+
/* @__PURE__ */i("div",{className:"aark-modal-body",children:r})]}):null}),x)},v={success:"✓",error:"✕",warning:"⚠",info:"ⓘ",question:"?"},C={success:"#4ade80",error:"#ef4444",warning:"#f59e0b",info:"#3b82f6",question:"#8b5cf6"},b=({props:o,onClose:e})=>{const{title:a,text:n,type:l="info",icon:c,html:d,timer:m=5e3,showCloseButton:u=!0,clickToClose:p=!0,width:f="300px",fullWidth:y=!1,padding:k="1rem",background:g="#ffffff",customClass:h={}}=o;t(()=>{if(m&&m>0){const o=setTimeout(e,m);return()=>clearTimeout(o)}},[m,e]);const b=r(()=>c?"string"==typeof c?/* @__PURE__ */i("span",{children:c}):c:/* @__PURE__ */i("span",{style:{color:C[l]},children:v[l]}),[c,l]),x=r(()=>{const o={padding:k,background:g,borderRadius:"8px",boxShadow:"0 4px 12px rgba(0, 0, 0, 0.1)",border:`1px solid ${C[l]}`,cursor:p?"pointer":"default",position:"relative",overflow:"hidden"};return y?(o.width="calc(100vw - 40px)",o.maxWidth="calc(100vw - 40px)"):o.width="number"==typeof f?`${f}px`:f,o},[f,y,k,g,l,p]);/* @__PURE__ */
|
|
8
|
+
return s("div",{className:`aark-standard-notification ${h.popup||""}`,style:x,onClick:()=>{p&&e()},children:[m&&m>0&&/* @__PURE__ */i("div",{style:{position:"absolute",bottom:0,left:0,height:"3px",background:C[l],animation:`aark-notification-progress ${m}ms linear forwards`,transformOrigin:"left"}}),
|
|
9
|
+
/* @__PURE__ */s("div",{style:{display:"flex",alignItems:"flex-start",gap:"0.75rem"},children:[b&&/* @__PURE__ */i("div",{className:`aark-notification-icon ${h.icon||""}`,style:{fontSize:"1.25rem",flexShrink:0,marginTop:"0.125rem"},children:b}),
|
|
10
|
+
/* @__PURE__ */s("div",{style:{flex:1,minWidth:0},children:[a&&/* @__PURE__ */i("div",{className:`aark-notification-header ${h.header||""}`,children:/* @__PURE__ */i("h4",{className:`aark-notification-title ${h.title||""}`,style:{margin:0,fontSize:"0.875rem",fontWeight:"600",color:"#1f2937"},children:a})}),
|
|
11
|
+
/* @__PURE__ */i("div",{className:`aark-notification-content ${h.content||""}`,style:{marginTop:a?"0.25rem":0},children:d?/* @__PURE__ */i("div",{dangerouslySetInnerHTML:{__html:"string"==typeof d?d:""}}):n?/* @__PURE__ */i("p",{style:{margin:0,fontSize:"0.75rem",color:"#6b7280",lineHeight:"1.4"},children:n}):null})]}),u&&/* @__PURE__ */i("button",{onClick:o=>{o.stopPropagation(),e()},className:`aark-notification-close ${h.closeButton||""}`,style:{background:"none",border:"none",fontSize:"1rem",color:"#9ca3af",cursor:"pointer",padding:0,lineHeight:1,flexShrink:0},"aria-label":"Close notification",children:"×"})]}),
|
|
12
|
+
/* @__PURE__ */i("style",{children:"\n @keyframes aark-notification-progress {\n from {\n transform: scaleX(1);\n }\n to {\n transform: scaleX(0);\n }\n }\n "})]})},x=({config:o,onClose:a})=>{const{content:r,props:n,options:l={}}=o,{position:d="top-right",showCloseIcon:m=!0,autoCloseTime:u=5e3,className:p="",preventEscClose:f=!1}=l;t(()=>{if(u&&!n){const o=setTimeout(a,u);return()=>clearTimeout(o)}},[u,a,n]),t(()=>{const o=o=>{"Escape"!==o.key||f||a()};if(!f)return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[a,f]);const y=e(o=>{o.stopPropagation(),a()},[a]),k=`aark-notification-container ${d} ${p}`.trim(),h=g();return c(
|
|
13
|
+
/* @__PURE__ */i("div",{style:(()=>{const o={position:"fixed",zIndex:1e4,margin:"1rem"};switch(d){case"top-left":return{...o,top:0,left:0};case"top-center":return{...o,top:0,left:"50%",transform:"translateX(-50%)"};case"top-right":default:return{...o,top:0,right:0};case"bottom-left":return{...o,bottom:0,left:0};case"bottom-center":return{...o,bottom:0,left:"50%",transform:"translateX(-50%)"};case"bottom-right":return{...o,bottom:0,right:0}}})(),children:n?/* @__PURE__ */i("div",{className:"aark-notification-wrapper",children:/* @__PURE__ */i(b,{props:n,onClose:a})}):r?/* @__PURE__ */s("div",{className:k,role:"alert","aria-live":"polite","aria-labelledby":"aark-notification-content",children:[m&&/* @__PURE__ */i("button",{onClick:y,className:"aark-notification-close","aria-label":"Close notification",type:"button",children:"×"}),
|
|
14
|
+
/* @__PURE__ */i("div",{id:"aark-notification-body",className:"aark-notification-body",children:r})]}):null}),h)},P=()=>{const{isOpen:o,config:e,close:t}=d();return o&&e?"modal"===e.mode?/* @__PURE__ */i(h,{config:e,onClose:t}):"notification"===e.mode?/* @__PURE__ */i(x,{config:e,onClose:t}):null:null},w=/* @__PURE__ */new Set;let B=null,N=null;function $(){if(N)return;const o=g();N=l(o),N.render(n(P))}function M(o,e){const t={type:o,config:e};w.forEach(o=>o(t))}function S(o,e){let t,a;$(),!o||"object"!=typeof o||"$$typeof"in o||Array.isArray(o)?(t=o,a=void 0):(a=o,t=void 0);const r={content:t,props:a,mode:"modal",options:Object.assign({position:"center",showCloseIcon:!0,preventEscClose:!1,preventOverlayClose:!1},e)};B=r,M("open",r)}function V(){B&&(M("beforeClose",B),B=null,M("close"))}const E={subscribe:function(o){return w.add(o),()=>w.delete(o)},fire:function(o,e){S(o,e)},fireModal:S,fireNotification:function(o,e){let t,a;$(),!o||"object"!=typeof o||"$$typeof"in o||Array.isArray(o)?(t=o,a=void 0):(a=o,t=void 0);const r={content:t,props:a,mode:"notification",options:Object.assign({position:"top-right",showCloseIcon:!0,autoCloseTime:5e3,preventEscClose:!1},e)};B=r,M("open",r)},close:V,isOpen:function(){return null!==B},getCurrentConfig:function(){return B},closeAll:function(){V()},cleanup:function(){N&&(N.unmount(),N=null),k&&0===k.children.length&&(k.remove(),k=null)}};function I(o){const e=document.documentElement;o.overlayBackground&&e.style.setProperty("--aark-modal-overlay-bg",o.overlayBackground),o.overlayBlur&&e.style.setProperty("--aark-modal-overlay-blur",o.overlayBlur),o.modalBackground&&e.style.setProperty("--aark-modal-bg",o.modalBackground),o.modalBorderRadius&&e.style.setProperty("--aark-modal-border-radius",o.modalBorderRadius),o.modalShadow&&e.style.setProperty("--aark-modal-shadow",o.modalShadow),o.modalPadding&&e.style.setProperty("--aark-modal-padding",o.modalPadding),o.modalZIndex&&e.style.setProperty("--aark-modal-z-index",o.modalZIndex.toString()),o.modalContentZIndex&&e.style.setProperty("--aark-modal-content-z-index",o.modalContentZIndex.toString()),o.closeButtonColor&&e.style.setProperty("--aark-modal-close-color",o.closeButtonColor),o.closeButtonHoverBackground&&e.style.setProperty("--aark-modal-close-hover-bg",o.closeButtonHoverBackground),o.closeButtonHoverColor&&e.style.setProperty("--aark-modal-close-hover-color",o.closeButtonHoverColor),o.closeButtonFocusOutline&&e.style.setProperty("--aark-modal-close-focus-outline",o.closeButtonFocusOutline),o.animationDuration&&e.style.setProperty("--aark-modal-animation-duration",o.animationDuration),o.fadeDuration&&e.style.setProperty("--aark-modal-fade-duration",o.fadeDuration),o.customOverlayBackground&&e.style.setProperty("--aark-custom-overlay-bg",o.customOverlayBackground),o.customOverlayBlur&&e.style.setProperty("--aark-custom-overlay-blur",o.customOverlayBlur),o.customModalGradientStart&&e.style.setProperty("--aark-custom-modal-gradient-start",o.customModalGradientStart),o.customModalGradientEnd&&e.style.setProperty("--aark-custom-modal-gradient-end",o.customModalGradientEnd),o.customModalTextColor&&e.style.setProperty("--aark-custom-modal-text-color",o.customModalTextColor),o.customModalShadow&&e.style.setProperty("--aark-custom-modal-shadow",o.customModalShadow),o.customModalCloseColor&&e.style.setProperty("--aark-custom-modal-close-color",o.customModalCloseColor),o.customModalCloseHoverBackground&&e.style.setProperty("--aark-custom-modal-close-hover-bg",o.customModalCloseHoverBackground),o.customModalCloseHoverColor&&e.style.setProperty("--aark-custom-modal-close-hover-color",o.customModalCloseHoverColor)}function O(){const o=document.documentElement;["--aark-modal-overlay-bg","--aark-modal-overlay-blur","--aark-modal-bg","--aark-modal-border-radius","--aark-modal-shadow","--aark-modal-padding","--aark-modal-z-index","--aark-modal-content-z-index","--aark-modal-close-color","--aark-modal-close-hover-bg","--aark-modal-close-hover-color","--aark-modal-close-focus-outline","--aark-modal-animation-duration","--aark-modal-fade-duration","--aark-custom-overlay-bg","--aark-custom-overlay-blur","--aark-custom-modal-gradient-start","--aark-custom-modal-gradient-end","--aark-custom-modal-text-color","--aark-custom-modal-shadow","--aark-custom-modal-close-color","--aark-custom-modal-close-hover-bg","--aark-custom-modal-close-hover-color"].forEach(e=>{o.style.removeProperty(e)})}function T(){const o=document.documentElement,e=getComputedStyle(o);return{overlayBackground:e.getPropertyValue("--aark-modal-overlay-bg").trim(),overlayBlur:e.getPropertyValue("--aark-modal-overlay-blur").trim(),modalBackground:e.getPropertyValue("--aark-modal-bg").trim(),modalBorderRadius:e.getPropertyValue("--aark-modal-border-radius").trim(),modalShadow:e.getPropertyValue("--aark-modal-shadow").trim(),modalPadding:e.getPropertyValue("--aark-modal-padding").trim(),modalZIndex:parseInt(e.getPropertyValue("--aark-modal-z-index").trim())||void 0,modalContentZIndex:parseInt(e.getPropertyValue("--aark-modal-content-z-index").trim())||void 0,closeButtonColor:e.getPropertyValue("--aark-modal-close-color").trim(),closeButtonHoverBackground:e.getPropertyValue("--aark-modal-close-hover-bg").trim(),closeButtonHoverColor:e.getPropertyValue("--aark-modal-close-hover-color").trim(),closeButtonFocusOutline:e.getPropertyValue("--aark-modal-close-focus-outline").trim(),animationDuration:e.getPropertyValue("--aark-modal-animation-duration").trim(),fadeDuration:e.getPropertyValue("--aark-modal-fade-duration").trim(),customOverlayBackground:e.getPropertyValue("--aark-custom-overlay-bg").trim(),customOverlayBlur:e.getPropertyValue("--aark-custom-overlay-blur").trim(),customModalGradientStart:e.getPropertyValue("--aark-custom-modal-gradient-start").trim(),customModalGradientEnd:e.getPropertyValue("--aark-custom-modal-gradient-end").trim(),customModalTextColor:e.getPropertyValue("--aark-custom-modal-text-color").trim(),customModalShadow:e.getPropertyValue("--aark-custom-modal-shadow").trim(),customModalCloseColor:e.getPropertyValue("--aark-custom-modal-close-color").trim(),customModalCloseHoverBackground:e.getPropertyValue("--aark-custom-modal-close-hover-bg").trim(),customModalCloseHoverColor:e.getPropertyValue("--aark-custom-modal-close-hover-color").trim()}}const H={fire:(o,e)=>E.fire(o,e),modal:(o,e)=>E.fireModal(o,e),notification:(o,e)=>E.fireNotification(o,e),close:()=>E.close(),isOpen:()=>E.isOpen(),closeAll:()=>E.closeAll(),setTheme:o=>I(o),resetTheme:()=>O(),getTheme:()=>T()};export{h as Modal,P as ModalProvider,x as Notification,H as aark,T as getAarkModalTheme,O as resetAarkModalTheme,I as setAarkModalTheme,d as useModal};
|