aark-react-modalify 1.0.0 → 1.0.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 +1 -1
- package/dist/ModalProvider-BAlPeDjm.js +12 -0
- package/dist/ModalProvider-DA6KcJdZ.cjs +5 -0
- package/dist/aark-react-modalify.css +1 -1
- package/dist/index.cjs.js +20 -1
- package/dist/index.esm.js +390 -7
- package/package.json +14 -5
- package/src/assets/styles/aark-modal.css +183 -0
- package/dist/ModalProvider-ComHxfXZ.js +0 -9
- package/dist/ModalProvider-zcVXiybl.cjs +0 -1
- package/dist/index-CvIFkjib.cjs +0 -271
- package/dist/index-DIT0k89J.js +0 -25835
package/README.md
CHANGED
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import { jsx } from "react/jsx-runtime";
|
|
2
|
+
import { useModal, ModalRenderer } from "./index.esm.js";
|
|
3
|
+
const ModalProvider = () => {
|
|
4
|
+
const { isOpen, config, close } = useModal();
|
|
5
|
+
if (!isOpen || !config) {
|
|
6
|
+
return null;
|
|
7
|
+
}
|
|
8
|
+
return /* @__PURE__ */ jsx(ModalRenderer, { config, onClose: close });
|
|
9
|
+
};
|
|
10
|
+
export {
|
|
11
|
+
ModalProvider as default
|
|
12
|
+
};
|
|
@@ -0,0 +1,5 @@
|
|
|
1
|
+
"use strict"
|
|
2
|
+
Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"})
|
|
3
|
+
const e=require("react/jsx-runtime"),s=require("./index.cjs.js")
|
|
4
|
+
exports.default=()=>{const{isOpen:o,config:r,close:n}=s.useModal()
|
|
5
|
+
return o&&r?e.jsx(s.ModalRenderer,{config:r,onClose:n}):null}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
:root{--aark-modal-overlay-bg: rgba(0, 0, 0, .5);--aark-modal-
|
|
1
|
+
:root{--aark-modal-overlay-bg: rgba(0, 0, 0, .5);--aark-modal-bg: #fff;--aark-modal-radius: 8px;--aark-modal-shadow: 0 10px 25px rgba(0, 0, 0, .15);--aark-modal-pad: 16px;--aark-modal-z: 9999;--aark-close-color: #666;--aark-close-hover: #f5f5f5;--aark-anim: .2s}.aark-modal-container{position:fixed;inset:0;z-index:var(--aark-modal-z)}.aark-modal-container.notification{pointer-events:none}.aark-modal-overlay{position:absolute;inset:0;background:var(--aark-modal-overlay-bg);backdrop-filter:blur(2px)}.aark-modal-content{position:fixed;background:var(--aark-modal-bg);border-radius:var(--aark-modal-radius);box-shadow:var(--aark-modal-shadow);padding:var(--aark-modal-pad);z-index:calc(var(--aark-modal-z) + 1);max-width:90vw;max-height:90vh;overflow:auto}.aark-modal-content.notification{pointer-events:auto}.aark-modal-content.center{top:50%;left:50%;transform:translate(-50%,-50%)}.aark-modal-content.top-center{top:20px;left:50%;transform:translate(-50%)}.aark-modal-content.top-right{top:20px;right:20px}.aark-modal-content.bottom-right{bottom:20px;right:20px}.aark-modal-content.bottom-center{bottom:20px;left:50%;transform:translate(-50%)}.aark-modal-close{position:absolute;top:8px;right:8px;width:24px;height:24px;display:flex;align-items:center;justify-content:center;background:0;border:0;color:var(--aark-close-color);cursor:pointer;border-radius:50%;font-size:14px;line-height:1;transition:all var(--aark-anim)}.aark-modal-close:hover{background:var(--aark-close-hover);color:#333}.aark-modal-close:focus{outline:2px solid #007bff;outline-offset:2px}.aark-modal-body{padding-top:8px}.aark-modal-container{animation:f var(--aark-anim)}.aark-modal-content{animation:s var(--aark-anim)}@keyframes f{0%{opacity:0}to{opacity:1}}@keyframes s{0%{opacity:0;transform:translate(-50%,-50%) scale(.95)}to{opacity:1;transform:translate(-50%,-50%) scale(1)}}.aark-modal-content.top-center{animation:d var(--aark-anim)}.aark-modal-content.top-right,.aark-modal-content.bottom-right{animation:l var(--aark-anim)}.aark-modal-content.bottom-center{animation:u var(--aark-anim)}@keyframes d{0%{opacity:0;transform:translate(-50%) translateY(-10px)}to{opacity:1;transform:translate(-50%) translateY(0)}}@keyframes l{0%{opacity:0;transform:translate(10px)}to{opacity:1;transform:translate(0)}}@keyframes u{0%{opacity:0;transform:translate(-50%) translateY(10px)}to{opacity:1;transform:translate(-50%) translateY(0)}}@media (max-width: 768px){.aark-modal-content{margin:10px;max-width:calc(100vw - 20px)}.aark-modal-content.center{top:50%;left:50%;transform:translate(-50%,-50%)}.aark-modal-content.top-center,.aark-modal-content.bottom-center{left:50%;transform:translate(-50%)}.aark-modal-content.top-right{right:10px;left:auto;transform:none}.aark-modal-content.bottom-right{right:10px;bottom:10px;left:auto;transform:none}}
|
package/dist/index.cjs.js
CHANGED
|
@@ -1 +1,20 @@
|
|
|
1
|
-
"use strict"
|
|
1
|
+
"use strict"
|
|
2
|
+
function o(o,a){const e={type:o,config:a}
|
|
3
|
+
s.forEach(o=>o(e))}function a(){m&&(o("beforeClose",m),m=null,o("close"))}function e(o){const a=document.documentElement
|
|
4
|
+
o.overlayBackground&&a.style.setProperty("--aark-modal-overlay-bg",o.overlayBackground),o.overlayBlur&&a.style.setProperty("--aark-modal-overlay-blur",o.overlayBlur),o.modalBackground&&a.style.setProperty("--aark-modal-bg",o.modalBackground),o.modalBorderRadius&&a.style.setProperty("--aark-modal-border-radius",o.modalBorderRadius),o.modalShadow&&a.style.setProperty("--aark-modal-shadow",o.modalShadow),o.modalPadding&&a.style.setProperty("--aark-modal-padding",o.modalPadding),o.modalZIndex&&a.style.setProperty("--aark-modal-z-index",o.modalZIndex.toString()),o.modalContentZIndex&&a.style.setProperty("--aark-modal-content-z-index",o.modalContentZIndex.toString()),o.closeButtonColor&&a.style.setProperty("--aark-modal-close-color",o.closeButtonColor),o.closeButtonHoverBackground&&a.style.setProperty("--aark-modal-close-hover-bg",o.closeButtonHoverBackground),o.closeButtonHoverColor&&a.style.setProperty("--aark-modal-close-hover-color",o.closeButtonHoverColor),o.closeButtonFocusOutline&&a.style.setProperty("--aark-modal-close-focus-outline",o.closeButtonFocusOutline),o.animationDuration&&a.style.setProperty("--aark-modal-animation-duration",o.animationDuration),o.fadeDuration&&a.style.setProperty("--aark-modal-fade-duration",o.fadeDuration),o.customOverlayBackground&&a.style.setProperty("--aark-custom-overlay-bg",o.customOverlayBackground),o.customOverlayBlur&&a.style.setProperty("--aark-custom-overlay-blur",o.customOverlayBlur),o.customModalGradientStart&&a.style.setProperty("--aark-custom-modal-gradient-start",o.customModalGradientStart),o.customModalGradientEnd&&a.style.setProperty("--aark-custom-modal-gradient-end",o.customModalGradientEnd),o.customModalTextColor&&a.style.setProperty("--aark-custom-modal-text-color",o.customModalTextColor),o.customModalShadow&&a.style.setProperty("--aark-custom-modal-shadow",o.customModalShadow),o.customModalCloseColor&&a.style.setProperty("--aark-custom-modal-close-color",o.customModalCloseColor),o.customModalCloseHoverBackground&&a.style.setProperty("--aark-custom-modal-close-hover-bg",o.customModalCloseHoverBackground),o.customModalCloseHoverColor&&a.style.setProperty("--aark-custom-modal-close-hover-color",o.customModalCloseHoverColor)}function r(){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(a=>{o.style.removeProperty(a)})}function l(){const o=document.documentElement,a=getComputedStyle(o)
|
|
5
|
+
return{overlayBackground:a.getPropertyValue("--aark-modal-overlay-bg").trim(),overlayBlur:a.getPropertyValue("--aark-modal-overlay-blur").trim(),modalBackground:a.getPropertyValue("--aark-modal-bg").trim(),modalBorderRadius:a.getPropertyValue("--aark-modal-border-radius").trim(),modalShadow:a.getPropertyValue("--aark-modal-shadow").trim(),modalPadding:a.getPropertyValue("--aark-modal-padding").trim(),modalZIndex:parseInt(a.getPropertyValue("--aark-modal-z-index").trim())||void 0,modalContentZIndex:parseInt(a.getPropertyValue("--aark-modal-content-z-index").trim())||void 0,closeButtonColor:a.getPropertyValue("--aark-modal-close-color").trim(),closeButtonHoverBackground:a.getPropertyValue("--aark-modal-close-hover-bg").trim(),closeButtonHoverColor:a.getPropertyValue("--aark-modal-close-hover-color").trim(),closeButtonFocusOutline:a.getPropertyValue("--aark-modal-close-focus-outline").trim(),animationDuration:a.getPropertyValue("--aark-modal-animation-duration").trim(),fadeDuration:a.getPropertyValue("--aark-modal-fade-duration").trim(),customOverlayBackground:a.getPropertyValue("--aark-custom-overlay-bg").trim(),customOverlayBlur:a.getPropertyValue("--aark-custom-overlay-blur").trim(),customModalGradientStart:a.getPropertyValue("--aark-custom-modal-gradient-start").trim(),customModalGradientEnd:a.getPropertyValue("--aark-custom-modal-gradient-end").trim(),customModalTextColor:a.getPropertyValue("--aark-custom-modal-text-color").trim(),customModalShadow:a.getPropertyValue("--aark-custom-modal-shadow").trim(),customModalCloseColor:a.getPropertyValue("--aark-custom-modal-close-color").trim(),customModalCloseHoverBackground:a.getPropertyValue("--aark-custom-modal-close-hover-bg").trim(),customModalCloseHoverColor:a.getPropertyValue("--aark-custom-modal-close-hover-color").trim()}}Object.defineProperty(exports,Symbol.toStringTag,{value:"Module"})
|
|
6
|
+
const t=require("react"),n=require("react-dom/client"),d=require("react/jsx-runtime"),c=require("react-dom"),s=new Set
|
|
7
|
+
let m=null,u=null,i=null
|
|
8
|
+
const k={subscribe:function(o){return s.add(o),()=>s.delete(o)},fire:function(a,e){u||(u=document.createElement("div"),u.id="aark-react-modalify-root",u.style.position="relative",u.style.zIndex="9999",document.body.appendChild(u),Promise.resolve().then(()=>require("./ModalProvider-DA6KcJdZ.cjs")).then(({default:o})=>{u&&(i=n.createRoot(u),i.render(t.createElement(o)))}))
|
|
9
|
+
const r={content:a,options:Object.assign({position:"center",mode:"modal",showCloseIcon:!0,preventEscClose:!1,preventOverlayClose:!1},e)}
|
|
10
|
+
m=r,o("open",r)},close:a,isOpen:function(){return null!==m},getCurrentConfig:function(){return m},closeAll:function(){a()},cleanup:function(){u&&u.parentNode&&(u.parentNode.removeChild(u),u=null,i=null)}},v={fire:(o,a)=>k.fire(o,a),close:()=>k.close(),isOpen:()=>k.isOpen(),closeAll:()=>k.closeAll(),setTheme:o=>e(o),resetTheme:()=>r(),getTheme:()=>l()}
|
|
11
|
+
exports.ModalRenderer=({config:o,onClose:a})=>{const{content:e,options:r={}}=o,{position:l="center",mode:n="modal",showCloseIcon:s=!0,autoCloseTime:m,className:u="",overlayClassName:i="",preventEscClose:k=!1,preventOverlayClose:v=!1}=r
|
|
12
|
+
t.useEffect(()=>{if(m&&"notification"===n){const o=setTimeout(a,m)
|
|
13
|
+
return()=>clearTimeout(o)}},[m,n,a]),t.useEffect(()=>{const o=o=>{"Escape"!==o.key||k||a()}
|
|
14
|
+
if(!k)return document.addEventListener("keydown",o),()=>document.removeEventListener("keydown",o)},[a,k])
|
|
15
|
+
const g=t.useCallback(o=>{o.target!==o.currentTarget||v||a()},[a,v]),b=t.useCallback(o=>{o.stopPropagation(),a()},[a]),f="aark-modal-container "+("notification"===n?"notification":""),h=`aark-modal-content ${l} ${"notification"===n?"notification":""} ${u}`.trim(),p=("aark-modal-overlay "+i).trim()
|
|
16
|
+
return c.createPortal(d.jsxs("div",{className:f,children:["modal"===n&&d.jsx("div",{className:p,onClick:g,"aria-hidden":"true"}),d.jsxs("div",{className:h,role:"dialog","aria-modal":"true","aria-labelledby":"aark-modal-content",children:[s&&d.jsx("button",{onClick:b,className:"aark-modal-close","aria-label":"Close modal",type:"button",children:"×"}),d.jsx("div",{id:"aark-modal-content",className:"aark-modal-body",children:e})]})]}),document.body)},exports.aark=v,exports.getAarkModalTheme=l,exports.resetAarkModalTheme=r,exports.setAarkModalTheme=e,exports.useModal=function(){const[o,a]=t.useState(!1),[e,r]=t.useState(null),l=t.useCallback(()=>{k.close()},[])
|
|
17
|
+
return t.useEffect(()=>{const o=k.subscribe(o=>{switch(o.type){case"open":a(!0),r(o.config||null)
|
|
18
|
+
break
|
|
19
|
+
case"close":a(!1),r(null)}})
|
|
20
|
+
return a(k.isOpen()),r(k.getCurrentConfig()),o},[]),{isOpen:o,config:e,close:l}}
|
package/dist/index.esm.js
CHANGED
|
@@ -1,9 +1,392 @@
|
|
|
1
|
-
import {
|
|
1
|
+
import { createElement, useState, useCallback, useEffect } from "react";
|
|
2
|
+
import { createRoot } from "react-dom/client";
|
|
3
|
+
import { jsxs, jsx } from "react/jsx-runtime";
|
|
4
|
+
import { createPortal } from "react-dom";
|
|
5
|
+
const listeners = /* @__PURE__ */ new Set();
|
|
6
|
+
let currentConfig = null;
|
|
7
|
+
let container = null;
|
|
8
|
+
let root = null;
|
|
9
|
+
function init() {
|
|
10
|
+
if (container) return;
|
|
11
|
+
container = document.createElement("div");
|
|
12
|
+
container.id = "aark-react-modalify-root";
|
|
13
|
+
container.style.position = "relative";
|
|
14
|
+
container.style.zIndex = "9999";
|
|
15
|
+
document.body.appendChild(container);
|
|
16
|
+
import("./ModalProvider-BAlPeDjm.js").then(({ default: ModalProvider }) => {
|
|
17
|
+
if (container) {
|
|
18
|
+
root = createRoot(container);
|
|
19
|
+
root.render(createElement(ModalProvider));
|
|
20
|
+
}
|
|
21
|
+
});
|
|
22
|
+
}
|
|
23
|
+
function subscribe(listener) {
|
|
24
|
+
listeners.add(listener);
|
|
25
|
+
return () => listeners.delete(listener);
|
|
26
|
+
}
|
|
27
|
+
function emit(type, config) {
|
|
28
|
+
const event = { type, config };
|
|
29
|
+
listeners.forEach((listener) => listener(event));
|
|
30
|
+
}
|
|
31
|
+
function fire(content, options) {
|
|
32
|
+
init();
|
|
33
|
+
const config = {
|
|
34
|
+
content,
|
|
35
|
+
options: Object.assign(
|
|
36
|
+
{
|
|
37
|
+
position: "center",
|
|
38
|
+
mode: "modal",
|
|
39
|
+
showCloseIcon: true,
|
|
40
|
+
preventEscClose: false,
|
|
41
|
+
preventOverlayClose: false
|
|
42
|
+
},
|
|
43
|
+
options
|
|
44
|
+
)
|
|
45
|
+
};
|
|
46
|
+
currentConfig = config;
|
|
47
|
+
emit("open", config);
|
|
48
|
+
}
|
|
49
|
+
function close() {
|
|
50
|
+
if (currentConfig) {
|
|
51
|
+
emit("beforeClose", currentConfig);
|
|
52
|
+
currentConfig = null;
|
|
53
|
+
emit("close");
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
function isOpen() {
|
|
57
|
+
return currentConfig !== null;
|
|
58
|
+
}
|
|
59
|
+
function getCurrentConfig() {
|
|
60
|
+
return currentConfig;
|
|
61
|
+
}
|
|
62
|
+
function closeAll() {
|
|
63
|
+
close();
|
|
64
|
+
}
|
|
65
|
+
function cleanup() {
|
|
66
|
+
if (container && container.parentNode) {
|
|
67
|
+
container.parentNode.removeChild(container);
|
|
68
|
+
container = null;
|
|
69
|
+
root = null;
|
|
70
|
+
}
|
|
71
|
+
}
|
|
72
|
+
const modalManager = {
|
|
73
|
+
subscribe,
|
|
74
|
+
fire,
|
|
75
|
+
close,
|
|
76
|
+
isOpen,
|
|
77
|
+
getCurrentConfig,
|
|
78
|
+
closeAll,
|
|
79
|
+
cleanup
|
|
80
|
+
};
|
|
81
|
+
function setAarkModalTheme(theme) {
|
|
82
|
+
const root2 = document.documentElement;
|
|
83
|
+
if (theme.overlayBackground) {
|
|
84
|
+
root2.style.setProperty("--aark-modal-overlay-bg", theme.overlayBackground);
|
|
85
|
+
}
|
|
86
|
+
if (theme.overlayBlur) {
|
|
87
|
+
root2.style.setProperty("--aark-modal-overlay-blur", theme.overlayBlur);
|
|
88
|
+
}
|
|
89
|
+
if (theme.modalBackground) {
|
|
90
|
+
root2.style.setProperty("--aark-modal-bg", theme.modalBackground);
|
|
91
|
+
}
|
|
92
|
+
if (theme.modalBorderRadius) {
|
|
93
|
+
root2.style.setProperty(
|
|
94
|
+
"--aark-modal-border-radius",
|
|
95
|
+
theme.modalBorderRadius
|
|
96
|
+
);
|
|
97
|
+
}
|
|
98
|
+
if (theme.modalShadow) {
|
|
99
|
+
root2.style.setProperty("--aark-modal-shadow", theme.modalShadow);
|
|
100
|
+
}
|
|
101
|
+
if (theme.modalPadding) {
|
|
102
|
+
root2.style.setProperty("--aark-modal-padding", theme.modalPadding);
|
|
103
|
+
}
|
|
104
|
+
if (theme.modalZIndex) {
|
|
105
|
+
root2.style.setProperty(
|
|
106
|
+
"--aark-modal-z-index",
|
|
107
|
+
theme.modalZIndex.toString()
|
|
108
|
+
);
|
|
109
|
+
}
|
|
110
|
+
if (theme.modalContentZIndex) {
|
|
111
|
+
root2.style.setProperty(
|
|
112
|
+
"--aark-modal-content-z-index",
|
|
113
|
+
theme.modalContentZIndex.toString()
|
|
114
|
+
);
|
|
115
|
+
}
|
|
116
|
+
if (theme.closeButtonColor) {
|
|
117
|
+
root2.style.setProperty("--aark-modal-close-color", theme.closeButtonColor);
|
|
118
|
+
}
|
|
119
|
+
if (theme.closeButtonHoverBackground) {
|
|
120
|
+
root2.style.setProperty(
|
|
121
|
+
"--aark-modal-close-hover-bg",
|
|
122
|
+
theme.closeButtonHoverBackground
|
|
123
|
+
);
|
|
124
|
+
}
|
|
125
|
+
if (theme.closeButtonHoverColor) {
|
|
126
|
+
root2.style.setProperty(
|
|
127
|
+
"--aark-modal-close-hover-color",
|
|
128
|
+
theme.closeButtonHoverColor
|
|
129
|
+
);
|
|
130
|
+
}
|
|
131
|
+
if (theme.closeButtonFocusOutline) {
|
|
132
|
+
root2.style.setProperty(
|
|
133
|
+
"--aark-modal-close-focus-outline",
|
|
134
|
+
theme.closeButtonFocusOutline
|
|
135
|
+
);
|
|
136
|
+
}
|
|
137
|
+
if (theme.animationDuration) {
|
|
138
|
+
root2.style.setProperty(
|
|
139
|
+
"--aark-modal-animation-duration",
|
|
140
|
+
theme.animationDuration
|
|
141
|
+
);
|
|
142
|
+
}
|
|
143
|
+
if (theme.fadeDuration) {
|
|
144
|
+
root2.style.setProperty("--aark-modal-fade-duration", theme.fadeDuration);
|
|
145
|
+
}
|
|
146
|
+
if (theme.customOverlayBackground) {
|
|
147
|
+
root2.style.setProperty(
|
|
148
|
+
"--aark-custom-overlay-bg",
|
|
149
|
+
theme.customOverlayBackground
|
|
150
|
+
);
|
|
151
|
+
}
|
|
152
|
+
if (theme.customOverlayBlur) {
|
|
153
|
+
root2.style.setProperty(
|
|
154
|
+
"--aark-custom-overlay-blur",
|
|
155
|
+
theme.customOverlayBlur
|
|
156
|
+
);
|
|
157
|
+
}
|
|
158
|
+
if (theme.customModalGradientStart) {
|
|
159
|
+
root2.style.setProperty(
|
|
160
|
+
"--aark-custom-modal-gradient-start",
|
|
161
|
+
theme.customModalGradientStart
|
|
162
|
+
);
|
|
163
|
+
}
|
|
164
|
+
if (theme.customModalGradientEnd) {
|
|
165
|
+
root2.style.setProperty(
|
|
166
|
+
"--aark-custom-modal-gradient-end",
|
|
167
|
+
theme.customModalGradientEnd
|
|
168
|
+
);
|
|
169
|
+
}
|
|
170
|
+
if (theme.customModalTextColor) {
|
|
171
|
+
root2.style.setProperty(
|
|
172
|
+
"--aark-custom-modal-text-color",
|
|
173
|
+
theme.customModalTextColor
|
|
174
|
+
);
|
|
175
|
+
}
|
|
176
|
+
if (theme.customModalShadow) {
|
|
177
|
+
root2.style.setProperty(
|
|
178
|
+
"--aark-custom-modal-shadow",
|
|
179
|
+
theme.customModalShadow
|
|
180
|
+
);
|
|
181
|
+
}
|
|
182
|
+
if (theme.customModalCloseColor) {
|
|
183
|
+
root2.style.setProperty(
|
|
184
|
+
"--aark-custom-modal-close-color",
|
|
185
|
+
theme.customModalCloseColor
|
|
186
|
+
);
|
|
187
|
+
}
|
|
188
|
+
if (theme.customModalCloseHoverBackground) {
|
|
189
|
+
root2.style.setProperty(
|
|
190
|
+
"--aark-custom-modal-close-hover-bg",
|
|
191
|
+
theme.customModalCloseHoverBackground
|
|
192
|
+
);
|
|
193
|
+
}
|
|
194
|
+
if (theme.customModalCloseHoverColor) {
|
|
195
|
+
root2.style.setProperty(
|
|
196
|
+
"--aark-custom-modal-close-hover-color",
|
|
197
|
+
theme.customModalCloseHoverColor
|
|
198
|
+
);
|
|
199
|
+
}
|
|
200
|
+
}
|
|
201
|
+
function resetAarkModalTheme() {
|
|
202
|
+
const root2 = document.documentElement;
|
|
203
|
+
const properties = [
|
|
204
|
+
"--aark-modal-overlay-bg",
|
|
205
|
+
"--aark-modal-overlay-blur",
|
|
206
|
+
"--aark-modal-bg",
|
|
207
|
+
"--aark-modal-border-radius",
|
|
208
|
+
"--aark-modal-shadow",
|
|
209
|
+
"--aark-modal-padding",
|
|
210
|
+
"--aark-modal-z-index",
|
|
211
|
+
"--aark-modal-content-z-index",
|
|
212
|
+
"--aark-modal-close-color",
|
|
213
|
+
"--aark-modal-close-hover-bg",
|
|
214
|
+
"--aark-modal-close-hover-color",
|
|
215
|
+
"--aark-modal-close-focus-outline",
|
|
216
|
+
"--aark-modal-animation-duration",
|
|
217
|
+
"--aark-modal-fade-duration",
|
|
218
|
+
"--aark-custom-overlay-bg",
|
|
219
|
+
"--aark-custom-overlay-blur",
|
|
220
|
+
"--aark-custom-modal-gradient-start",
|
|
221
|
+
"--aark-custom-modal-gradient-end",
|
|
222
|
+
"--aark-custom-modal-text-color",
|
|
223
|
+
"--aark-custom-modal-shadow",
|
|
224
|
+
"--aark-custom-modal-close-color",
|
|
225
|
+
"--aark-custom-modal-close-hover-bg",
|
|
226
|
+
"--aark-custom-modal-close-hover-color"
|
|
227
|
+
];
|
|
228
|
+
properties.forEach((property) => {
|
|
229
|
+
root2.style.removeProperty(property);
|
|
230
|
+
});
|
|
231
|
+
}
|
|
232
|
+
function getAarkModalTheme() {
|
|
233
|
+
const root2 = document.documentElement;
|
|
234
|
+
const computedStyle = getComputedStyle(root2);
|
|
235
|
+
return {
|
|
236
|
+
overlayBackground: computedStyle.getPropertyValue("--aark-modal-overlay-bg").trim(),
|
|
237
|
+
overlayBlur: computedStyle.getPropertyValue("--aark-modal-overlay-blur").trim(),
|
|
238
|
+
modalBackground: computedStyle.getPropertyValue("--aark-modal-bg").trim(),
|
|
239
|
+
modalBorderRadius: computedStyle.getPropertyValue("--aark-modal-border-radius").trim(),
|
|
240
|
+
modalShadow: computedStyle.getPropertyValue("--aark-modal-shadow").trim(),
|
|
241
|
+
modalPadding: computedStyle.getPropertyValue("--aark-modal-padding").trim(),
|
|
242
|
+
modalZIndex: parseInt(computedStyle.getPropertyValue("--aark-modal-z-index").trim()) || void 0,
|
|
243
|
+
modalContentZIndex: parseInt(
|
|
244
|
+
computedStyle.getPropertyValue("--aark-modal-content-z-index").trim()
|
|
245
|
+
) || void 0,
|
|
246
|
+
closeButtonColor: computedStyle.getPropertyValue("--aark-modal-close-color").trim(),
|
|
247
|
+
closeButtonHoverBackground: computedStyle.getPropertyValue("--aark-modal-close-hover-bg").trim(),
|
|
248
|
+
closeButtonHoverColor: computedStyle.getPropertyValue("--aark-modal-close-hover-color").trim(),
|
|
249
|
+
closeButtonFocusOutline: computedStyle.getPropertyValue("--aark-modal-close-focus-outline").trim(),
|
|
250
|
+
animationDuration: computedStyle.getPropertyValue("--aark-modal-animation-duration").trim(),
|
|
251
|
+
fadeDuration: computedStyle.getPropertyValue("--aark-modal-fade-duration").trim(),
|
|
252
|
+
customOverlayBackground: computedStyle.getPropertyValue("--aark-custom-overlay-bg").trim(),
|
|
253
|
+
customOverlayBlur: computedStyle.getPropertyValue("--aark-custom-overlay-blur").trim(),
|
|
254
|
+
customModalGradientStart: computedStyle.getPropertyValue("--aark-custom-modal-gradient-start").trim(),
|
|
255
|
+
customModalGradientEnd: computedStyle.getPropertyValue("--aark-custom-modal-gradient-end").trim(),
|
|
256
|
+
customModalTextColor: computedStyle.getPropertyValue("--aark-custom-modal-text-color").trim(),
|
|
257
|
+
customModalShadow: computedStyle.getPropertyValue("--aark-custom-modal-shadow").trim(),
|
|
258
|
+
customModalCloseColor: computedStyle.getPropertyValue("--aark-custom-modal-close-color").trim(),
|
|
259
|
+
customModalCloseHoverBackground: computedStyle.getPropertyValue("--aark-custom-modal-close-hover-bg").trim(),
|
|
260
|
+
customModalCloseHoverColor: computedStyle.getPropertyValue("--aark-custom-modal-close-hover-color").trim()
|
|
261
|
+
};
|
|
262
|
+
}
|
|
263
|
+
const aark = {
|
|
264
|
+
fire: (content, options) => modalManager.fire(content, options),
|
|
265
|
+
close: () => modalManager.close(),
|
|
266
|
+
isOpen: () => modalManager.isOpen(),
|
|
267
|
+
closeAll: () => modalManager.closeAll(),
|
|
268
|
+
setTheme: (theme) => setAarkModalTheme(theme),
|
|
269
|
+
resetTheme: () => resetAarkModalTheme(),
|
|
270
|
+
getTheme: () => getAarkModalTheme()
|
|
271
|
+
};
|
|
272
|
+
function useModal() {
|
|
273
|
+
const [isOpen2, setIsOpen] = useState(false);
|
|
274
|
+
const [config, setConfig] = useState(null);
|
|
275
|
+
const close2 = useCallback(() => {
|
|
276
|
+
modalManager.close();
|
|
277
|
+
}, []);
|
|
278
|
+
useEffect(() => {
|
|
279
|
+
const handleModalEvent = (event) => {
|
|
280
|
+
switch (event.type) {
|
|
281
|
+
case "open":
|
|
282
|
+
setIsOpen(true);
|
|
283
|
+
setConfig(event.config || null);
|
|
284
|
+
break;
|
|
285
|
+
case "close":
|
|
286
|
+
setIsOpen(false);
|
|
287
|
+
setConfig(null);
|
|
288
|
+
break;
|
|
289
|
+
}
|
|
290
|
+
};
|
|
291
|
+
const unsubscribe = modalManager.subscribe(handleModalEvent);
|
|
292
|
+
setIsOpen(modalManager.isOpen());
|
|
293
|
+
setConfig(modalManager.getCurrentConfig());
|
|
294
|
+
return unsubscribe;
|
|
295
|
+
}, []);
|
|
296
|
+
return {
|
|
297
|
+
isOpen: isOpen2,
|
|
298
|
+
config,
|
|
299
|
+
close: close2
|
|
300
|
+
};
|
|
301
|
+
}
|
|
302
|
+
const ModalRenderer = ({ config, onClose }) => {
|
|
303
|
+
const { content, options = {} } = config;
|
|
304
|
+
const {
|
|
305
|
+
position = "center",
|
|
306
|
+
mode = "modal",
|
|
307
|
+
showCloseIcon = true,
|
|
308
|
+
autoCloseTime,
|
|
309
|
+
className = "",
|
|
310
|
+
overlayClassName = "",
|
|
311
|
+
preventEscClose = false,
|
|
312
|
+
preventOverlayClose = false
|
|
313
|
+
} = options;
|
|
314
|
+
useEffect(() => {
|
|
315
|
+
if (autoCloseTime && mode === "notification") {
|
|
316
|
+
const timer = setTimeout(onClose, autoCloseTime);
|
|
317
|
+
return () => clearTimeout(timer);
|
|
318
|
+
}
|
|
319
|
+
}, [autoCloseTime, mode, onClose]);
|
|
320
|
+
useEffect(() => {
|
|
321
|
+
const handleKeyDown = (event) => {
|
|
322
|
+
if (event.key === "Escape" && !preventEscClose) {
|
|
323
|
+
onClose();
|
|
324
|
+
}
|
|
325
|
+
};
|
|
326
|
+
if (!preventEscClose) {
|
|
327
|
+
document.addEventListener("keydown", handleKeyDown);
|
|
328
|
+
return () => document.removeEventListener("keydown", handleKeyDown);
|
|
329
|
+
}
|
|
330
|
+
}, [onClose, preventEscClose]);
|
|
331
|
+
const handleOverlayClick = useCallback(
|
|
332
|
+
(event) => {
|
|
333
|
+
if (event.target === event.currentTarget && !preventOverlayClose) {
|
|
334
|
+
onClose();
|
|
335
|
+
}
|
|
336
|
+
},
|
|
337
|
+
[onClose, preventOverlayClose]
|
|
338
|
+
);
|
|
339
|
+
const handleCloseClick = useCallback(
|
|
340
|
+
(event) => {
|
|
341
|
+
event.stopPropagation();
|
|
342
|
+
onClose();
|
|
343
|
+
},
|
|
344
|
+
[onClose]
|
|
345
|
+
);
|
|
346
|
+
const containerClasses = `aark-modal-container ${mode === "notification" ? "notification" : ""}`;
|
|
347
|
+
const contentClasses = `aark-modal-content ${position} ${mode === "notification" ? "notification" : ""} ${className}`.trim();
|
|
348
|
+
const overlayClasses = `aark-modal-overlay ${overlayClassName}`.trim();
|
|
349
|
+
return createPortal(
|
|
350
|
+
/* @__PURE__ */ jsxs("div", { className: containerClasses, children: [
|
|
351
|
+
mode === "modal" && /* @__PURE__ */ jsx(
|
|
352
|
+
"div",
|
|
353
|
+
{
|
|
354
|
+
className: overlayClasses,
|
|
355
|
+
onClick: handleOverlayClick,
|
|
356
|
+
"aria-hidden": "true"
|
|
357
|
+
}
|
|
358
|
+
),
|
|
359
|
+
/* @__PURE__ */ jsxs(
|
|
360
|
+
"div",
|
|
361
|
+
{
|
|
362
|
+
className: contentClasses,
|
|
363
|
+
role: "dialog",
|
|
364
|
+
"aria-modal": "true",
|
|
365
|
+
"aria-labelledby": "aark-modal-content",
|
|
366
|
+
children: [
|
|
367
|
+
showCloseIcon && /* @__PURE__ */ jsx(
|
|
368
|
+
"button",
|
|
369
|
+
{
|
|
370
|
+
onClick: handleCloseClick,
|
|
371
|
+
className: "aark-modal-close",
|
|
372
|
+
"aria-label": "Close modal",
|
|
373
|
+
type: "button",
|
|
374
|
+
children: "×"
|
|
375
|
+
}
|
|
376
|
+
),
|
|
377
|
+
/* @__PURE__ */ jsx("div", { id: "aark-modal-content", className: "aark-modal-body", children: content })
|
|
378
|
+
]
|
|
379
|
+
}
|
|
380
|
+
)
|
|
381
|
+
] }),
|
|
382
|
+
document.body
|
|
383
|
+
);
|
|
384
|
+
};
|
|
2
385
|
export {
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
386
|
+
ModalRenderer,
|
|
387
|
+
aark,
|
|
388
|
+
getAarkModalTheme,
|
|
389
|
+
resetAarkModalTheme,
|
|
390
|
+
setAarkModalTheme,
|
|
391
|
+
useModal
|
|
9
392
|
};
|
package/package.json
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "aark-react-modalify",
|
|
3
|
-
"version": "1.0.
|
|
4
|
-
"description": "A
|
|
3
|
+
"version": "1.0.2",
|
|
4
|
+
"description": "A lightweight, flexible React modal and notification library with TypeScript support. Features automatic DOM mounting, customizable styling, and a simple imperative API for displaying modals, alerts, confirmations, and toast notifications.",
|
|
5
5
|
"main": "dist/index.cjs.js",
|
|
6
6
|
"module": "dist/index.esm.js",
|
|
7
7
|
"types": "dist/index.d.ts",
|
|
@@ -15,7 +15,7 @@
|
|
|
15
15
|
},
|
|
16
16
|
"files": [
|
|
17
17
|
"dist",
|
|
18
|
-
"src/styles/aark-modal.css",
|
|
18
|
+
"src/assets/styles/aark-modal.css",
|
|
19
19
|
"README.md",
|
|
20
20
|
"LICENSE"
|
|
21
21
|
],
|
|
@@ -28,7 +28,8 @@
|
|
|
28
28
|
"prepare": "npm run build",
|
|
29
29
|
"lint": "eslint src --ext .ts,.tsx",
|
|
30
30
|
"lint:fix": "eslint src --ext .ts,.tsx --fix",
|
|
31
|
-
"typecheck": "tsc --noEmit"
|
|
31
|
+
"typecheck": "tsc --noEmit",
|
|
32
|
+
"analyze": "npm run build && npx bundlesize"
|
|
32
33
|
},
|
|
33
34
|
"keywords": [
|
|
34
35
|
"react",
|
|
@@ -37,8 +38,13 @@
|
|
|
37
38
|
"toast",
|
|
38
39
|
"popup",
|
|
39
40
|
"dialog",
|
|
41
|
+
"alert",
|
|
42
|
+
"confirm",
|
|
40
43
|
"typescript",
|
|
41
|
-
"
|
|
44
|
+
"imperative",
|
|
45
|
+
"lightweight",
|
|
46
|
+
"flexible",
|
|
47
|
+
"customizable"
|
|
42
48
|
],
|
|
43
49
|
"peerDependencies": {
|
|
44
50
|
"react": ">=16.8.0",
|
|
@@ -46,9 +52,11 @@
|
|
|
46
52
|
},
|
|
47
53
|
"devDependencies": {
|
|
48
54
|
"@eslint/js": "^9.32.0",
|
|
55
|
+
"@types/node": "^24.2.1",
|
|
49
56
|
"@types/react": "^19.1.9",
|
|
50
57
|
"@types/react-dom": "^19.1.7",
|
|
51
58
|
"@vitejs/plugin-react": "^4.7.0",
|
|
59
|
+
"cssnano": "^7.1.0",
|
|
52
60
|
"eslint": "^9.32.0",
|
|
53
61
|
"eslint-plugin-react-hooks": "^5.2.0",
|
|
54
62
|
"eslint-plugin-react-refresh": "^0.4.20",
|
|
@@ -56,6 +64,7 @@
|
|
|
56
64
|
"react": "^19.1.1",
|
|
57
65
|
"react-dom": "^19.1.1",
|
|
58
66
|
"rimraf": "^6.0.1",
|
|
67
|
+
"terser": "^5.43.1",
|
|
59
68
|
"typescript": "~5.8.3",
|
|
60
69
|
"typescript-eslint": "^8.39.0",
|
|
61
70
|
"vite": "^7.1.0"
|