@fullkekw/popup 2.0.9 → 2.0.11
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/dist/Interfaces.d.ts +14 -15
- package/dist/Package.d.ts +4 -4
- package/dist/index.d.ts +1 -1
- package/dist/index.es.js +98 -98
- package/dist/index.es.js.map +1 -1
- package/dist/index.umd.js +2 -2
- package/dist/index.umd.js.map +1 -1
- package/dist/styles.css +1 -1
- package/dist/useMixedState.d.ts +4 -0
- package/package.json +1 -1
package/dist/Interfaces.d.ts
CHANGED
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import { default as React, ReactNode } from 'react';
|
|
2
|
+
export type StateSetter<S = any> = React.Dispatch<React.SetStateAction<S>>;
|
|
2
3
|
export type PopupWindowAnimationType = 'fade' | 'scale' | null;
|
|
3
|
-
export interface
|
|
4
|
+
export interface IPopupSettings {
|
|
4
5
|
/** Prevent state change due to user interactions (only synthetic) */
|
|
5
6
|
preventStateChange?: boolean;
|
|
6
7
|
/**
|
|
@@ -22,35 +23,33 @@ export interface PopupSettings {
|
|
|
22
23
|
*/
|
|
23
24
|
disableScroll?: boolean;
|
|
24
25
|
}
|
|
25
|
-
export interface
|
|
26
|
+
export interface IPopupNode {
|
|
26
27
|
id: string;
|
|
27
28
|
open: boolean;
|
|
28
29
|
zIndex: number;
|
|
29
|
-
settings:
|
|
30
|
+
settings: IPopupSettings;
|
|
30
31
|
}
|
|
31
|
-
export interface
|
|
32
|
-
nodes:
|
|
33
|
-
toggleNode(node: string |
|
|
34
|
-
registerNode(node:
|
|
32
|
+
export interface IPopupContextProps {
|
|
33
|
+
nodes: IPopupNode[];
|
|
34
|
+
toggleNode(node: string | IPopupNode, state?: boolean): void;
|
|
35
|
+
registerNode(node: IPopupNode): void;
|
|
35
36
|
toggleDocument(id: string, e: React.MouseEvent): void;
|
|
36
37
|
}
|
|
37
|
-
export interface
|
|
38
|
+
export interface IPopupLayerProps extends React.HTMLAttributes<HTMLElement> {
|
|
38
39
|
children: ReactNode | ReactNode[];
|
|
39
|
-
settings?:
|
|
40
|
+
settings?: IPopupSettings;
|
|
40
41
|
}
|
|
41
|
-
export interface
|
|
42
|
+
export interface IPopupWindowProps extends React.HTMLAttributes<HTMLElement> {
|
|
42
43
|
id: string;
|
|
43
44
|
children?: ReactNode | ReactNode[];
|
|
44
45
|
layerClassName?: string;
|
|
45
|
-
settings?:
|
|
46
|
+
settings?: IPopupSettings;
|
|
46
47
|
onOpen?(): void;
|
|
47
48
|
onExit?(): void;
|
|
48
|
-
/** Render popup in DOM only when user requested it */
|
|
49
|
-
renderOnDemand?: boolean;
|
|
50
49
|
/** Passed useState value */
|
|
51
50
|
isOpen?: boolean;
|
|
52
51
|
/** Passed useState setter */
|
|
53
|
-
setIsOpen
|
|
52
|
+
setIsOpen?: StateSetter<boolean>;
|
|
54
53
|
/**
|
|
55
54
|
* Popup animation
|
|
56
55
|
*
|
|
@@ -58,7 +57,7 @@ export interface PopupWindowProps extends React.HTMLAttributes<HTMLElement> {
|
|
|
58
57
|
*/
|
|
59
58
|
animation?: PopupWindowAnimationType;
|
|
60
59
|
}
|
|
61
|
-
export interface
|
|
60
|
+
export interface IPopupButtonProps extends React.HTMLAttributes<HTMLElement> {
|
|
62
61
|
popupId: string;
|
|
63
62
|
children?: ReactNode | ReactNode[];
|
|
64
63
|
onClick?(e: React.MouseEvent): void;
|
package/dist/Package.d.ts
CHANGED
|
@@ -1,14 +1,14 @@
|
|
|
1
1
|
import { FC } from 'react';
|
|
2
|
-
import {
|
|
2
|
+
import { IPopupButtonProps, IPopupLayerProps, IPopupWindowProps } from './Interfaces';
|
|
3
3
|
/**
|
|
4
4
|
* Popup context provider. Must be inside body tag and in client environment (NextJS)
|
|
5
5
|
*/
|
|
6
|
-
export declare const PopupLayer: FC<
|
|
6
|
+
export declare const PopupLayer: FC<IPopupLayerProps>;
|
|
7
7
|
/**
|
|
8
8
|
* Popup window
|
|
9
9
|
*/
|
|
10
|
-
export declare const PopupWindow: FC<
|
|
10
|
+
export declare const PopupWindow: FC<IPopupWindowProps>;
|
|
11
11
|
/**
|
|
12
12
|
* Popup trigger button
|
|
13
13
|
*/
|
|
14
|
-
export declare const PopupButton: FC<
|
|
14
|
+
export declare const PopupButton: FC<IPopupButtonProps>;
|
package/dist/index.d.ts
CHANGED
|
@@ -1,3 +1,3 @@
|
|
|
1
1
|
export * from './Package';
|
|
2
2
|
export * as default from './Package';
|
|
3
|
-
export type { PopupSettings, PopupWindowAnimationType, PopupLayerProps, PopupButtonProps, PopupWindowProps } from './Interfaces';
|
|
3
|
+
export type { IPopupSettings as PopupSettings, PopupWindowAnimationType, IPopupLayerProps as PopupLayerProps, IPopupButtonProps as PopupButtonProps, IPopupWindowProps as PopupWindowProps } from './Interfaces';
|
package/dist/index.es.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
|
-
import {
|
|
2
|
-
import { createContext as
|
|
3
|
-
import { createPortal as
|
|
4
|
-
function
|
|
1
|
+
import { jsx as S, jsxs as _ } from "react/jsx-runtime";
|
|
2
|
+
import { createContext as L, useState as g, useEffect as y, Suspense as T, useContext as N } from "react";
|
|
3
|
+
import { createPortal as A } from "react-dom";
|
|
4
|
+
function M(s) {
|
|
5
5
|
return s && s.__esModule && Object.prototype.hasOwnProperty.call(s, "default") ? s.default : s;
|
|
6
6
|
}
|
|
7
7
|
var b = { exports: {} };
|
|
@@ -10,151 +10,151 @@ var b = { exports: {} };
|
|
|
10
10
|
Licensed under the MIT License (MIT), see
|
|
11
11
|
http://jedwatson.github.io/classnames
|
|
12
12
|
*/
|
|
13
|
-
var
|
|
14
|
-
function
|
|
15
|
-
return
|
|
13
|
+
var C;
|
|
14
|
+
function q() {
|
|
15
|
+
return C || (C = 1, function(s) {
|
|
16
16
|
(function() {
|
|
17
|
-
var
|
|
18
|
-
function
|
|
19
|
-
for (var e = "",
|
|
20
|
-
var
|
|
21
|
-
|
|
17
|
+
var m = {}.hasOwnProperty;
|
|
18
|
+
function a() {
|
|
19
|
+
for (var e = "", n = 0; n < arguments.length; n++) {
|
|
20
|
+
var u = arguments[n];
|
|
21
|
+
u && (e = r(e, f(u)));
|
|
22
22
|
}
|
|
23
23
|
return e;
|
|
24
24
|
}
|
|
25
|
-
function
|
|
25
|
+
function f(e) {
|
|
26
26
|
if (typeof e == "string" || typeof e == "number")
|
|
27
27
|
return e;
|
|
28
28
|
if (typeof e != "object")
|
|
29
29
|
return "";
|
|
30
30
|
if (Array.isArray(e))
|
|
31
|
-
return
|
|
31
|
+
return a.apply(null, e);
|
|
32
32
|
if (e.toString !== Object.prototype.toString && !e.toString.toString().includes("[native code]"))
|
|
33
33
|
return e.toString();
|
|
34
|
-
var
|
|
35
|
-
for (var
|
|
36
|
-
|
|
37
|
-
return
|
|
34
|
+
var n = "";
|
|
35
|
+
for (var u in e)
|
|
36
|
+
m.call(e, u) && e[u] && (n = r(n, u));
|
|
37
|
+
return n;
|
|
38
38
|
}
|
|
39
|
-
function r(e,
|
|
40
|
-
return
|
|
39
|
+
function r(e, n) {
|
|
40
|
+
return n ? e ? e + " " + n : e + n : e;
|
|
41
41
|
}
|
|
42
|
-
s.exports ? (
|
|
42
|
+
s.exports ? (a.default = a, s.exports = a) : window.classNames = a;
|
|
43
43
|
})();
|
|
44
44
|
}(b)), b.exports;
|
|
45
45
|
}
|
|
46
|
-
var
|
|
47
|
-
const
|
|
46
|
+
var F = q();
|
|
47
|
+
const k = /* @__PURE__ */ M(F), P = {
|
|
48
48
|
disableScroll: !0,
|
|
49
49
|
exitOnDocument: !0,
|
|
50
50
|
exitOnEscape: !0,
|
|
51
51
|
preventStateChange: !1
|
|
52
|
-
}, h =
|
|
53
|
-
const [r] =
|
|
52
|
+
}, h = L({}), Z = ({ className: s, settings: m, children: a, ...f }) => {
|
|
53
|
+
const [r] = g(z(m ?? {}, P)), [e, n] = g([]), u = {
|
|
54
54
|
nodes: e,
|
|
55
|
-
toggleNode:
|
|
56
|
-
registerNode:
|
|
57
|
-
toggleDocument:
|
|
55
|
+
toggleNode: x,
|
|
56
|
+
registerNode: v,
|
|
57
|
+
toggleDocument: O
|
|
58
58
|
};
|
|
59
|
-
|
|
59
|
+
y(() => {
|
|
60
60
|
if (typeof window > "u") return;
|
|
61
|
-
window.addEventListener("keydown",
|
|
62
|
-
function
|
|
63
|
-
if (
|
|
64
|
-
const
|
|
65
|
-
if (!
|
|
66
|
-
|
|
61
|
+
window.addEventListener("keydown", p);
|
|
62
|
+
function p(o) {
|
|
63
|
+
if (o.key === "Escape") {
|
|
64
|
+
const c = Math.max(...e.filter((d) => d.open).map((d) => d.zIndex)), i = e.find((d) => d.open && d.zIndex === c);
|
|
65
|
+
if (!i || !i.settings.exitOnEscape || !(r != null && r.exitOnEscape)) return;
|
|
66
|
+
x(i.id);
|
|
67
67
|
}
|
|
68
68
|
}
|
|
69
69
|
return () => {
|
|
70
|
-
window.removeEventListener("keydown",
|
|
70
|
+
window.removeEventListener("keydown", p);
|
|
71
71
|
};
|
|
72
72
|
}, [e]);
|
|
73
|
-
function
|
|
74
|
-
let
|
|
75
|
-
if (typeof
|
|
76
|
-
if ((r.preventStateChange ||
|
|
77
|
-
const
|
|
78
|
-
|
|
73
|
+
function x(p, o) {
|
|
74
|
+
let t;
|
|
75
|
+
if (typeof p == "string" ? t = { ...e.find((i) => i.id === p) } : t = { ...p }, !t.id) return;
|
|
76
|
+
if ((r.preventStateChange || t.settings.preventStateChange) && o === void 0) return console.warn("Popup action prevented");
|
|
77
|
+
const c = o ?? !(t != null && t.open);
|
|
78
|
+
t.open = c, t.zIndex = c ? Math.max(...e.map((i) => i.zIndex), 0) + 1 : 0, n((i) => [...i.filter((d) => d.id !== t.id), t]), r.disableScroll && t.settings.disableScroll && c && document.body.classList.add("fkw-popup--noScroll"), !c && !e.filter((i) => i.id !== t.id).some((i) => i.open) && document.body.classList.remove("fkw-popup--noScroll");
|
|
79
79
|
}
|
|
80
|
-
function
|
|
81
|
-
|
|
80
|
+
function v(p) {
|
|
81
|
+
n((o) => [...o, p]), p.open && x(p, !0);
|
|
82
82
|
}
|
|
83
|
-
function
|
|
84
|
-
const
|
|
85
|
-
!
|
|
83
|
+
function O(p, o) {
|
|
84
|
+
const t = { ...e.find((i) => i.id === p) };
|
|
85
|
+
!t.id || !t.settings.exitOnDocument || o.target.closest(".fkw-popup") || !t.settings.exitOnDocument || !r.exitOnDocument || x(t.id);
|
|
86
86
|
}
|
|
87
|
-
return /* @__PURE__ */
|
|
88
|
-
|
|
89
|
-
/* @__PURE__ */
|
|
90
|
-
] });
|
|
91
|
-
},
|
|
92
|
-
const
|
|
93
|
-
return
|
|
94
|
-
|
|
95
|
-
}, [f]), O(() => {
|
|
96
|
-
_(document.querySelector("#fkw-popup-container")), j(!0), n.registerNode({
|
|
87
|
+
return /* @__PURE__ */ S(T, { children: /* @__PURE__ */ _(h.Provider, { value: u, children: [
|
|
88
|
+
a,
|
|
89
|
+
/* @__PURE__ */ S("section", { className: k("fkw-popup-container", s), id: "fkw-popup-container", ...f })
|
|
90
|
+
] }) });
|
|
91
|
+
}, B = ({ children: s, className: m, layerClassName: a, style: f, id: r, settings: e, isOpen: n, setIsOpen: u, animation: x, onExit: v, onOpen: O, ...p }) => {
|
|
92
|
+
const o = N(h), [t] = g(x ?? "scale"), [c] = g(z(e ?? {}, P)), [i, d] = g(null), [l, D] = g(n ?? !1), [E, I] = g(0);
|
|
93
|
+
return y(() => {
|
|
94
|
+
d(document.querySelector("#fkw-popup-container")), o.registerNode({
|
|
97
95
|
id: r,
|
|
98
|
-
open:
|
|
96
|
+
open: l,
|
|
99
97
|
zIndex: 0,
|
|
100
|
-
settings:
|
|
98
|
+
settings: c
|
|
101
99
|
});
|
|
102
|
-
}, []),
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
100
|
+
}, []), y(() => {
|
|
101
|
+
l && O && O(), !l && v && v();
|
|
102
|
+
}, [n]), y(() => {
|
|
103
|
+
const w = o.nodes.find((j) => j.id === r);
|
|
104
|
+
w && (D(w.open), w.zIndex !== 0 ? I(w.zIndex) : setTimeout(() => {
|
|
105
|
+
I(w.zIndex);
|
|
106
106
|
}, 200));
|
|
107
|
-
}, [
|
|
108
|
-
|
|
109
|
-
}, [
|
|
110
|
-
|
|
111
|
-
}, [
|
|
107
|
+
}, [o]), y(() => {
|
|
108
|
+
u === void 0 || n === l || u(l);
|
|
109
|
+
}, [l]), y(() => {
|
|
110
|
+
n === void 0 || n === l || o.toggleNode(r, n);
|
|
111
|
+
}, [n]), i ? A(/* @__PURE__ */ S(
|
|
112
112
|
"section",
|
|
113
113
|
{
|
|
114
114
|
id: r,
|
|
115
|
-
className:
|
|
116
|
-
style: { zIndex: 1e4 +
|
|
117
|
-
onClick:
|
|
118
|
-
children: /* @__PURE__ */
|
|
115
|
+
className: k("fkw-popup-layer", l && "fkw-popup-layer--open", a),
|
|
116
|
+
style: { zIndex: 1e4 + E, cursor: c.exitOnDocument && !c.preventStateChange ? "pointer" : "auto", ...f },
|
|
117
|
+
onClick: c.exitOnDocument && !c.preventStateChange ? (w) => o.toggleDocument(r, w) : void 0,
|
|
118
|
+
children: /* @__PURE__ */ S(
|
|
119
119
|
"article",
|
|
120
120
|
{
|
|
121
|
-
className:
|
|
121
|
+
className: k("fkw-popup", l && "fkw-popup--open", t && `fkw-popup-animation--${t}`, m),
|
|
122
122
|
role: "dialog",
|
|
123
123
|
"aria-modal": !0,
|
|
124
|
-
"aria-hidden": !
|
|
124
|
+
"aria-hidden": !l,
|
|
125
125
|
...p,
|
|
126
|
-
children:
|
|
126
|
+
children: s
|
|
127
127
|
}
|
|
128
128
|
)
|
|
129
129
|
}
|
|
130
|
-
)
|
|
131
|
-
},
|
|
132
|
-
const
|
|
133
|
-
|
|
134
|
-
const
|
|
135
|
-
|
|
136
|
-
}, [
|
|
137
|
-
function
|
|
138
|
-
|
|
130
|
+
), i) : null;
|
|
131
|
+
}, G = ({ children: s, as: m, className: a, onClick: f, disabled: r, popupId: e, ...n }) => {
|
|
132
|
+
const u = N(h), [x, v] = g(!1), O = m ?? "button";
|
|
133
|
+
y(() => {
|
|
134
|
+
const o = u.nodes.find((t) => t.id === e);
|
|
135
|
+
o && v(o.open);
|
|
136
|
+
}, [u]);
|
|
137
|
+
function p(o) {
|
|
138
|
+
u.toggleNode(e), f && f(o);
|
|
139
139
|
}
|
|
140
|
-
return /* @__PURE__ */
|
|
140
|
+
return /* @__PURE__ */ S(O, { className: k("fkw-popup-button", x && "fkw-popup-button--active", a), role: "button", onClick: p, "aria-haspopup": "dialog", tabIndex: 0, disabled: r, "aria-disabled": r, "data-fkw-popup-operator": e, "aria-label": x ? "Close Popup" : "Open Popup", ...n, children: s });
|
|
141
141
|
};
|
|
142
|
-
function
|
|
143
|
-
const
|
|
144
|
-
for (const
|
|
145
|
-
|
|
146
|
-
return
|
|
142
|
+
function z(s, m) {
|
|
143
|
+
const a = { ...m };
|
|
144
|
+
for (const f in s)
|
|
145
|
+
a[f] = s[f];
|
|
146
|
+
return a;
|
|
147
147
|
}
|
|
148
|
-
const
|
|
148
|
+
const V = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
|
|
149
149
|
__proto__: null,
|
|
150
|
-
PopupButton:
|
|
151
|
-
PopupLayer:
|
|
152
|
-
PopupWindow:
|
|
150
|
+
PopupButton: G,
|
|
151
|
+
PopupLayer: Z,
|
|
152
|
+
PopupWindow: B
|
|
153
153
|
}, Symbol.toStringTag, { value: "Module" }));
|
|
154
154
|
export {
|
|
155
|
-
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
155
|
+
G as PopupButton,
|
|
156
|
+
Z as PopupLayer,
|
|
157
|
+
B as PopupWindow,
|
|
158
|
+
V as default
|
|
159
159
|
};
|
|
160
160
|
//# sourceMappingURL=index.es.js.map
|
package/dist/index.es.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.es.js","sources":["../node_modules/classnames/index.js","../src/_package/Package.tsx"],"sourcesContent":["/*!\n\tCopyright (c) 2018 Jed Watson.\n\tLicensed under the MIT License (MIT), see\n\thttp://jedwatson.github.io/classnames\n*/\n/* global define */\n\n(function () {\n\t'use strict';\n\n\tvar hasOwn = {}.hasOwnProperty;\n\n\tfunction classNames () {\n\t\tvar classes = '';\n\n\t\tfor (var i = 0; i < arguments.length; i++) {\n\t\t\tvar arg = arguments[i];\n\t\t\tif (arg) {\n\t\t\t\tclasses = appendClass(classes, parseValue(arg));\n\t\t\t}\n\t\t}\n\n\t\treturn classes;\n\t}\n\n\tfunction parseValue (arg) {\n\t\tif (typeof arg === 'string' || typeof arg === 'number') {\n\t\t\treturn arg;\n\t\t}\n\n\t\tif (typeof arg !== 'object') {\n\t\t\treturn '';\n\t\t}\n\n\t\tif (Array.isArray(arg)) {\n\t\t\treturn classNames.apply(null, arg);\n\t\t}\n\n\t\tif (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes('[native code]')) {\n\t\t\treturn arg.toString();\n\t\t}\n\n\t\tvar classes = '';\n\n\t\tfor (var key in arg) {\n\t\t\tif (hasOwn.call(arg, key) && arg[key]) {\n\t\t\t\tclasses = appendClass(classes, key);\n\t\t\t}\n\t\t}\n\n\t\treturn classes;\n\t}\n\n\tfunction appendClass (value, newClass) {\n\t\tif (!newClass) {\n\t\t\treturn value;\n\t\t}\n\t\n\t\tif (value) {\n\t\t\treturn value + ' ' + newClass;\n\t\t}\n\t\n\t\treturn value + newClass;\n\t}\n\n\tif (typeof module !== 'undefined' && module.exports) {\n\t\tclassNames.default = classNames;\n\t\tmodule.exports = classNames;\n\t} else if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) {\n\t\t// register as 'classnames', consistent with npm package name\n\t\tdefine('classnames', [], function () {\n\t\t\treturn classNames;\n\t\t});\n\t} else {\n\t\twindow.classNames = classNames;\n\t}\n}());\n","import './styles.scss';\r\n\r\nimport React, { createContext, FC, JSX, useContext, useEffect, useMemo, useState } from \"react\";\r\nimport cn from 'classnames';\r\nimport { PopupButtonProps, PopupContextProps, PopupLayerProps, PopupNode, PopupSettings, PopupWindowAnimationType, PopupWindowProps } from './Interfaces';\r\nimport { createPortal } from 'react-dom';\r\n\r\n\r\n\r\nconst DEFAULT_SETTINGS: Required<PopupSettings> = {\r\n disableScroll: true,\r\n exitOnDocument: true,\r\n exitOnEscape: true,\r\n preventStateChange: false\r\n};\r\n\r\n// @ts-expect-error Need empty object\r\nconst PopupContext = createContext<PopupContextProps>({});\r\n\r\n\r\n\r\n/** \r\n * Popup context provider. Must be inside body tag and in client environment (NextJS)\r\n */\r\nexport const PopupLayer: FC<PopupLayerProps> = ({ className, settings: initialSettings, children, ...props }) => {\r\n const [settings] = useState<PopupSettings>(reassingObject(initialSettings ?? {}, DEFAULT_SETTINGS));\r\n const [nodes, setNodes] = useState<PopupNode[]>([]);\r\n\r\n const context: PopupContextProps = {\r\n nodes,\r\n toggleNode,\r\n registerNode,\r\n toggleDocument\r\n };\r\n\r\n\r\n\r\n // Handle exitOnEscape\r\n useEffect(() => {\r\n if (typeof window === 'undefined') return;\r\n\r\n window.addEventListener('keydown', handleKeydown);\r\n\r\n function handleKeydown(e: KeyboardEvent) {\r\n const key = e.key;\r\n\r\n if (key === 'Escape') {\r\n const maxZIndex = Math.max(...nodes.filter(el => el.open).map(el => el.zIndex));\r\n const node = nodes.find(el => el.open && el.zIndex === maxZIndex);\r\n if (!node || !node.settings.exitOnEscape || !settings?.exitOnEscape) return;\r\n\r\n toggleNode(node.id);\r\n }\r\n }\r\n\r\n return () => {\r\n window.removeEventListener('keydown', handleKeydown);\r\n };\r\n }, [nodes]);\r\n\r\n\r\n /** \r\n * @param state Forced state\r\n */\r\n function toggleNode(nod: string | PopupNode, force?: boolean) {\r\n let node: PopupNode;\r\n\r\n if (typeof nod === 'string') {\r\n node = { ...nodes.find(el => el.id === nod) } as PopupNode;\r\n } else {\r\n node = { ...nod };\r\n }\r\n\r\n if (!node.id) return;\r\n if ((settings.preventStateChange || node.settings.preventStateChange) && force === undefined) return console.warn(`Popup action prevented`);\r\n\r\n const open = force ?? !node?.open;\r\n\r\n node.open = open;\r\n node.zIndex = open ? Math.max(...nodes.map(el => el.zIndex), 0) + 1 : 0;\r\n\r\n setNodes(prev => [...prev.filter(el => el.id !== node.id), node]);\r\n\r\n // Hide scroll on open\r\n if (settings.disableScroll && node.settings.disableScroll && open) {\r\n document.body.classList.add('fkw-popup--noScroll');\r\n }\r\n\r\n // Show scroll if no popup open\r\n if (!open && !nodes.filter(el => el.id !== node.id).some(el => el.open)) {\r\n document.body.classList.remove('fkw-popup--noScroll');\r\n }\r\n }\r\n\r\n /** Register new node */\r\n function registerNode(node: PopupNode) {\r\n setNodes(prev => [...prev, node]);\r\n\r\n if (node.open) toggleNode(node, true);\r\n }\r\n\r\n function toggleDocument(id: string, e: React.MouseEvent) {\r\n const node: PopupNode = { ...nodes.find(el => el.id === id) } as PopupNode;\r\n if (!node.id) return;\r\n if (!node.settings.exitOnDocument) return;\r\n\r\n const popup = (e.target as HTMLElement).closest('.fkw-popup');\r\n if (popup || !node.settings.exitOnDocument || !settings.exitOnDocument) return;\r\n\r\n toggleNode(node.id);\r\n }\r\n\r\n\r\n\r\n return <PopupContext.Provider value={context}>\r\n {children}\r\n\r\n <section className={cn(`fkw-popup-container`, className)} id='fkw-popup-container' {...props}></section>\r\n </PopupContext.Provider>;\r\n};\r\n\r\n\r\n\r\n/** \r\n * Popup window\r\n */\r\nexport const PopupWindow: FC<PopupWindowProps> = ({ children, className, layerClassName, style, id, settings: initialSettings, isOpen: state, setIsOpen: stateSetter, animation: initialAnimation, renderOnDemand, onExit, onOpen, ...props }) => {\r\n const ctx = useContext(PopupContext) as PopupContextProps;\r\n\r\n const [animation] = useState<PopupWindowAnimationType>(initialAnimation ?? 'scale');\r\n const [settings] = useState<PopupSettings>(reassingObject(initialSettings ?? {}, DEFAULT_SETTINGS));\r\n const [isMounted, setIsMounted] = useState<boolean>(false);\r\n const [isRendered, setIsRendered] = useState<boolean>(false);\r\n const [container, setContainer] = useState<Element | null>(null);\r\n\r\n const [isOpen, setIsOpen] = useState<boolean>(false);\r\n const [zIndex, setZIndex] = useState<number>(0);\r\n\r\n\r\n\r\n // Handle isRendered & onOpen, onExit\r\n useMemo(() => {\r\n if (renderOnDemand) {\r\n if (isOpen) setIsRendered(true); // Render content only if window is open\r\n } else setIsRendered(true);\r\n\r\n if (isOpen && onOpen) onOpen();\r\n if (!isOpen && onExit) onExit();\r\n }, [isOpen]);\r\n\r\n // Mount\r\n useEffect(() => {\r\n setContainer(document.querySelector('#fkw-popup-container'));\r\n setIsMounted(true);\r\n\r\n ctx.registerNode({\r\n id,\r\n open: false,\r\n zIndex: 0,\r\n settings\r\n });\r\n }, []);\r\n\r\n // Listen context\r\n useEffect(() => {\r\n const node = ctx.nodes.find(el => el.id === id);\r\n if (!node) return;\r\n\r\n setIsOpen(node.open);\r\n\r\n if (node.zIndex !== 0) {\r\n // Instantly update zIndex\r\n setZIndex(node.zIndex);\r\n } else {\r\n // Timeout zIndex update\r\n setTimeout(() => {\r\n setZIndex(node.zIndex);\r\n }, 200);\r\n }\r\n }, [ctx]);\r\n\r\n // Sync out state on current change\r\n useEffect(() => {\r\n if (stateSetter === undefined || state === isOpen) return;\r\n\r\n stateSetter(isOpen);\r\n }, [isOpen]);\r\n\r\n // Sync current state on out change\r\n useEffect(() => {\r\n if (state === undefined || state === isOpen) return;\r\n\r\n ctx.toggleNode(id, state);\r\n }, [state]);\r\n\r\n\r\n\r\n if (!isMounted || !container) return null;\r\n\r\n return createPortal(<>\r\n <section\r\n id={id}\r\n className={cn(`fkw-popup-layer`, isOpen && 'fkw-popup-layer--open', layerClassName)}\r\n style={{ zIndex: 10000 + zIndex, cursor: settings.exitOnDocument && !settings.preventStateChange ? 'pointer' : 'auto', ...style }}\r\n onClick={settings.exitOnDocument && !settings.preventStateChange ? e => ctx.toggleDocument(id, e) : undefined}\r\n >\r\n <article\r\n className={cn(`fkw-popup`, isOpen && 'fkw-popup--open', animation && `fkw-popup-animation--${animation}`, className)}\r\n role='dialog'\r\n aria-modal\r\n aria-hidden={!isOpen}\r\n {...props}\r\n >\r\n {isRendered && children}\r\n </article>\r\n </section>\r\n </>, container);\r\n};\r\n\r\n\r\n\r\n/** \r\n * Popup trigger button\r\n */\r\nexport const PopupButton: FC<PopupButtonProps> = ({ children, as, className, onClick, disabled, popupId, ...props }) => {\r\n const ctx = useContext(PopupContext) as PopupContextProps;\r\n\r\n const Tag: keyof JSX.IntrinsicElements = as ?? 'button';\r\n\r\n const [isActive, setIsActive] = useState<boolean>(false);\r\n\r\n\r\n\r\n // Listen context\r\n useEffect(() => {\r\n const node = ctx.nodes.find(el => el.id === popupId);\r\n if (!node) return;\r\n\r\n setIsActive(node.open);\r\n }, [ctx]);\r\n\r\n\r\n\r\n function toggle(e: React.MouseEvent) {\r\n ctx.toggleNode(popupId);\r\n onClick && onClick(e);\r\n }\r\n\r\n\r\n\r\n return <Tag className={cn('fkw-popup-button', isActive && 'fkw-popup-button--active', className)} role='button' onClick={toggle} aria-haspopup=\"dialog\" tabIndex={0} disabled={disabled} aria-disabled={disabled} data-fkw-popup-operator={popupId} aria-label={isActive ? 'Close Popup' : 'Open Popup'} {...props}>\r\n {children}\r\n </Tag>;\r\n};\r\n\r\n\r\n\r\nfunction reassingObject(target: object, refference: object) {\r\n const payload = { ...refference };\r\n\r\n for (const key in target) {\r\n payload[key] = target[key];\r\n }\r\n\r\n return payload;\r\n}"],"names":["hasOwn","classNames","classes","i","arg","appendClass","parseValue","key","value","newClass","module","DEFAULT_SETTINGS","PopupContext","createContext","PopupLayer","className","initialSettings","children","props","settings","useState","reassingObject","nodes","setNodes","context","toggleNode","registerNode","toggleDocument","useEffect","handleKeydown","e","maxZIndex","el","node","nod","force","open","prev","id","jsxs","jsx","cn","PopupWindow","layerClassName","style","state","stateSetter","initialAnimation","renderOnDemand","onExit","onOpen","ctx","useContext","animation","isMounted","setIsMounted","isRendered","setIsRendered","container","setContainer","isOpen","setIsOpen","zIndex","setZIndex","useMemo","createPortal","Fragment","PopupButton","as","onClick","disabled","popupId","Tag","isActive","setIsActive","toggle","target","refference","payload"],"mappings":";;;;;;;;;;;;;;;AAOA,KAAC,WAAY;AAGZ,UAAIA,IAAS,CAAA,EAAG;AAEhB,eAASC,IAAc;AAGtB,iBAFIC,IAAU,IAELC,IAAI,GAAGA,IAAI,UAAU,QAAQA,KAAK;AAC1C,cAAIC,IAAM,UAAUD,CAAC;AACrB,UAAIC,MACHF,IAAUG,EAAYH,GAASI,EAAWF,CAAG,CAAC;AAAA,QAElD;AAEE,eAAOF;AAAA,MACT;AAEC,eAASI,EAAYF,GAAK;AACzB,YAAI,OAAOA,KAAQ,YAAY,OAAOA,KAAQ;AAC7C,iBAAOA;AAGR,YAAI,OAAOA,KAAQ;AAClB,iBAAO;AAGR,YAAI,MAAM,QAAQA,CAAG;AACpB,iBAAOH,EAAW,MAAM,MAAMG,CAAG;AAGlC,YAAIA,EAAI,aAAa,OAAO,UAAU,YAAY,CAACA,EAAI,SAAS,SAAQ,EAAG,SAAS,eAAe;AAClG,iBAAOA,EAAI,SAAU;AAGtB,YAAIF,IAAU;AAEd,iBAASK,KAAOH;AACf,UAAIJ,EAAO,KAAKI,GAAKG,CAAG,KAAKH,EAAIG,CAAG,MACnCL,IAAUG,EAAYH,GAASK,CAAG;AAIpC,eAAOL;AAAA,MACT;AAEC,eAASG,EAAaG,GAAOC,GAAU;AACtC,eAAKA,IAIDD,IACIA,IAAQ,MAAMC,IAGfD,IAAQC,IAPPD;AAAA,MAQV;AAEC,MAAqCE,EAAO,WAC3CT,EAAW,UAAUA,GACrBS,YAAiBT,KAOjB,OAAO,aAAaA;AAAA,IAEtB;;;;gCCnEMU,IAA4C;AAAA,EAChD,eAAe;AAAA,EACf,gBAAgB;AAAA,EAChB,cAAc;AAAA,EACd,oBAAoB;AACtB,GAGMC,IAAeC,EAAiC,EAAE,GAO3CC,IAAkC,CAAC,EAAE,WAAAC,GAAW,UAAUC,GAAiB,UAAAC,GAAU,GAAGC,QAAY;AAC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OuC,CAAO;AACnD,IAAKtC,KAELyC,EAAYzC,EAAK,IAAI;AAAA,EAAA,GACpB,CAACkB,CAAG,CAAC;AAIR,WAASwB,EAAO7C,GAAqB;AACnC,IAAAqB,EAAI,WAAWoB,CAAO,GACtBF,KAAWA,EAAQvC,CAAC;AAAA,EAAA;AAKtB,SAAQ,gBAAAU,EAAAgC,GAAA,EAAI,WAAW/B,EAAG,oBAAoBgC,KAAY,4BAA4B1D,CAAS,GAAG,MAAK,UAAS,SAAS4D,GAAQ,iBAAc,UAAS,UAAU,GAAG,UAAAL,GAAoB,iBAAeA,GAAU,2BAAyBC,GAAS,cAAYE,IAAW,gBAAgB,cAAe,GAAGvD,GAC1S,UAAAD,EACH,CAAA;AACF;AAIA,SAASI,EAAeuD,GAAgBC,GAAoB;AACpD,QAAAC,IAAU,EAAE,GAAGD,EAAW;AAEhC,aAAWtE,KAAOqE;AACR,IAAAE,EAAAvE,CAAG,IAAIqE,EAAOrE,CAAG;AAGpB,SAAAuE;AACT;;;;;;;","x_google_ignoreList":[0]}
|
|
1
|
+
{"version":3,"file":"index.es.js","sources":["../node_modules/classnames/index.js","../src/_package/Package.tsx"],"sourcesContent":["/*!\n\tCopyright (c) 2018 Jed Watson.\n\tLicensed under the MIT License (MIT), see\n\thttp://jedwatson.github.io/classnames\n*/\n/* global define */\n\n(function () {\n\t'use strict';\n\n\tvar hasOwn = {}.hasOwnProperty;\n\n\tfunction classNames () {\n\t\tvar classes = '';\n\n\t\tfor (var i = 0; i < arguments.length; i++) {\n\t\t\tvar arg = arguments[i];\n\t\t\tif (arg) {\n\t\t\t\tclasses = appendClass(classes, parseValue(arg));\n\t\t\t}\n\t\t}\n\n\t\treturn classes;\n\t}\n\n\tfunction parseValue (arg) {\n\t\tif (typeof arg === 'string' || typeof arg === 'number') {\n\t\t\treturn arg;\n\t\t}\n\n\t\tif (typeof arg !== 'object') {\n\t\t\treturn '';\n\t\t}\n\n\t\tif (Array.isArray(arg)) {\n\t\t\treturn classNames.apply(null, arg);\n\t\t}\n\n\t\tif (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes('[native code]')) {\n\t\t\treturn arg.toString();\n\t\t}\n\n\t\tvar classes = '';\n\n\t\tfor (var key in arg) {\n\t\t\tif (hasOwn.call(arg, key) && arg[key]) {\n\t\t\t\tclasses = appendClass(classes, key);\n\t\t\t}\n\t\t}\n\n\t\treturn classes;\n\t}\n\n\tfunction appendClass (value, newClass) {\n\t\tif (!newClass) {\n\t\t\treturn value;\n\t\t}\n\t\n\t\tif (value) {\n\t\t\treturn value + ' ' + newClass;\n\t\t}\n\t\n\t\treturn value + newClass;\n\t}\n\n\tif (typeof module !== 'undefined' && module.exports) {\n\t\tclassNames.default = classNames;\n\t\tmodule.exports = classNames;\n\t} else if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) {\n\t\t// register as 'classnames', consistent with npm package name\n\t\tdefine('classnames', [], function () {\n\t\t\treturn classNames;\n\t\t});\n\t} else {\n\t\twindow.classNames = classNames;\n\t}\n}());\n","import './styles.scss';\r\n\r\nimport React, { createContext, FC, JSX, Suspense, useContext, useEffect, useMemo, useState } from \"react\";\r\nimport cn from 'classnames';\r\nimport { IPopupButtonProps, IPopupContextProps, IPopupLayerProps, IPopupNode, IPopupSettings, PopupWindowAnimationType, IPopupWindowProps } from './Interfaces';\r\nimport { createPortal } from 'react-dom';\r\nimport useMixedState from './useMixedState';\r\n\r\n\r\n\r\nconst DEFAULT_SETTINGS: Required<IPopupSettings> = {\r\n disableScroll: true,\r\n exitOnDocument: true,\r\n exitOnEscape: true,\r\n preventStateChange: false\r\n};\r\n\r\nconst PopupContext = createContext<IPopupContextProps>({} as IPopupContextProps);\r\n\r\n\r\n\r\n/** \r\n * Popup context provider. Must be inside body tag and in client environment (NextJS)\r\n */\r\nexport const PopupLayer: FC<IPopupLayerProps> = ({ className, settings: initialSettings, children, ...props }) => {\r\n const [settings] = useState<IPopupSettings>(reassingObject(initialSettings ?? {}, DEFAULT_SETTINGS));\r\n const [nodes, setNodes] = useState<IPopupNode[]>([]);\r\n\r\n const context: IPopupContextProps = {\r\n nodes,\r\n toggleNode,\r\n registerNode,\r\n toggleDocument\r\n };\r\n\r\n\r\n\r\n // Handle exitOnEscape\r\n useEffect(() => {\r\n if (typeof window === 'undefined') return;\r\n\r\n window.addEventListener('keydown', handleKeydown);\r\n\r\n function handleKeydown(e: KeyboardEvent) {\r\n const key = e.key;\r\n\r\n if (key === 'Escape') {\r\n const maxZIndex = Math.max(...nodes.filter(el => el.open).map(el => el.zIndex));\r\n const node = nodes.find(el => el.open && el.zIndex === maxZIndex);\r\n if (!node || !node.settings.exitOnEscape || !settings?.exitOnEscape) return;\r\n\r\n toggleNode(node.id);\r\n }\r\n }\r\n\r\n return () => {\r\n window.removeEventListener('keydown', handleKeydown);\r\n };\r\n }, [nodes]);\r\n\r\n\r\n /** \r\n * @param state Forced state\r\n */\r\n function toggleNode(nod: string | IPopupNode, force?: boolean) {\r\n let node: IPopupNode;\r\n\r\n if (typeof nod === 'string') {\r\n node = { ...nodes.find(el => el.id === nod) } as IPopupNode;\r\n } else {\r\n node = { ...nod };\r\n }\r\n\r\n if (!node.id) return;\r\n if ((settings.preventStateChange || node.settings.preventStateChange) && force === undefined) return console.warn(`Popup action prevented`);\r\n\r\n const open = force ?? !node?.open;\r\n\r\n node.open = open;\r\n node.zIndex = open ? Math.max(...nodes.map(el => el.zIndex), 0) + 1 : 0;\r\n\r\n setNodes(prev => [...prev.filter(el => el.id !== node.id), node]);\r\n\r\n // Hide scroll on open\r\n if (settings.disableScroll && node.settings.disableScroll && open) {\r\n document.body.classList.add('fkw-popup--noScroll');\r\n }\r\n\r\n // Show scroll if no popup open\r\n if (!open && !nodes.filter(el => el.id !== node.id).some(el => el.open)) {\r\n document.body.classList.remove('fkw-popup--noScroll');\r\n }\r\n }\r\n\r\n /** Register new node */\r\n function registerNode(node: IPopupNode) {\r\n setNodes(prev => [...prev, node]);\r\n\r\n if (node.open) toggleNode(node, true);\r\n }\r\n\r\n function toggleDocument(id: string, e: React.MouseEvent) {\r\n const node: IPopupNode = { ...nodes.find(el => el.id === id) } as IPopupNode;\r\n if (!node.id) return;\r\n if (!node.settings.exitOnDocument) return;\r\n\r\n const popup = (e.target as HTMLElement).closest('.fkw-popup');\r\n if (popup || !node.settings.exitOnDocument || !settings.exitOnDocument) return;\r\n\r\n toggleNode(node.id);\r\n }\r\n\r\n\r\n\r\n return <Suspense>\r\n <PopupContext.Provider value={context}>\r\n {children}\r\n\r\n <section className={cn(`fkw-popup-container`, className)} id='fkw-popup-container' {...props}></section>\r\n </PopupContext.Provider>\r\n </Suspense>;\r\n};\r\n\r\n\r\n\r\n/** \r\n * Popup window\r\n */\r\nexport const PopupWindow: FC<IPopupWindowProps> = ({ children, className, layerClassName, style, id, settings: initialSettings, isOpen: state, setIsOpen: stateSetter, animation: initialAnimation, onExit, onOpen, ...props }) => {\r\n const ctx = useContext(PopupContext) as IPopupContextProps;\r\n\r\n const [animation] = useState<PopupWindowAnimationType>(initialAnimation ?? 'scale');\r\n const [settings] = useState<IPopupSettings>(reassingObject(initialSettings ?? {}, DEFAULT_SETTINGS));\r\n const [container, setContainer] = useState<Element | null>(null);\r\n\r\n const [isOpen, setIsOpen] = useState(state ?? false);\r\n const [zIndex, setZIndex] = useState<number>(0);\r\n\r\n\r\n\r\n // Mount\r\n useEffect(() => {\r\n setContainer(document.querySelector('#fkw-popup-container'));\r\n\r\n ctx.registerNode({\r\n id,\r\n open: isOpen,\r\n zIndex: 0,\r\n settings\r\n });\r\n }, []);\r\n\r\n // Handle onOpen, onExit\r\n useEffect(() => {\r\n if (isOpen && onOpen) onOpen();\r\n if (!isOpen && onExit) onExit();\r\n }, [state]);\r\n\r\n // Listen context\r\n useEffect(() => {\r\n const node = ctx.nodes.find(el => el.id === id);\r\n if (!node) return;\r\n\r\n setIsOpen(node.open);\r\n\r\n if (node.zIndex !== 0) {\r\n // Instantly update zIndex\r\n setZIndex(node.zIndex);\r\n } else {\r\n // Timeout zIndex update\r\n setTimeout(() => {\r\n setZIndex(node.zIndex);\r\n }, 200); // TODO: fix constant animation delay timeout\r\n }\r\n }, [ctx]);\r\n\r\n // Sync out state on current change\r\n useEffect(() => {\r\n if (stateSetter === undefined || state === isOpen) return;\r\n\r\n stateSetter(isOpen);\r\n }, [isOpen]);\r\n\r\n // Sync current state on out change\r\n useEffect(() => {\r\n if (state === undefined || state === isOpen) return;\r\n\r\n ctx.toggleNode(id, state);\r\n }, [state]);\r\n\r\n\r\n\r\n if (!container) return null;\r\n\r\n return createPortal(<section\r\n id={id}\r\n className={cn(`fkw-popup-layer`, isOpen && 'fkw-popup-layer--open', layerClassName)}\r\n style={{ zIndex: 10000 + zIndex, cursor: settings.exitOnDocument && !settings.preventStateChange ? 'pointer' : 'auto', ...style }}\r\n onClick={settings.exitOnDocument && !settings.preventStateChange ? e => ctx.toggleDocument(id, e) : undefined}\r\n >\r\n <article\r\n className={cn(`fkw-popup`, isOpen && 'fkw-popup--open', animation && `fkw-popup-animation--${animation}`, className)}\r\n role='dialog'\r\n aria-modal\r\n aria-hidden={!isOpen}\r\n {...props}\r\n >\r\n {children}\r\n </article>\r\n </section>, container);\r\n};\r\n\r\n\r\n\r\n/** \r\n * Popup trigger button\r\n */\r\nexport const PopupButton: FC<IPopupButtonProps> = ({ children, as, className, onClick, disabled, popupId, ...props }) => {\r\n const ctx = useContext(PopupContext) as IPopupContextProps;\r\n\r\n const [isActive, setIsActive] = useState<boolean>(false);\r\n\r\n const Tag: keyof JSX.IntrinsicElements = as ?? 'button';\r\n\r\n\r\n\r\n // Listen context\r\n useEffect(() => {\r\n const node = ctx.nodes.find(el => el.id === popupId);\r\n if (!node) return;\r\n\r\n setIsActive(node.open);\r\n }, [ctx]);\r\n\r\n\r\n\r\n function toggle(e: React.MouseEvent) {\r\n ctx.toggleNode(popupId);\r\n onClick && onClick(e);\r\n }\r\n\r\n\r\n\r\n return <Tag className={cn('fkw-popup-button', isActive && 'fkw-popup-button--active', className)} role='button' onClick={toggle} aria-haspopup=\"dialog\" tabIndex={0} disabled={disabled} aria-disabled={disabled} data-fkw-popup-operator={popupId} aria-label={isActive ? 'Close Popup' : 'Open Popup'} {...props}>\r\n {children}\r\n </Tag>;\r\n};\r\n\r\n\r\n\r\nfunction reassingObject(target: object, refference: object) {\r\n const payload = { ...refference };\r\n\r\n for (const key in target) {\r\n payload[key] = target[key];\r\n }\r\n\r\n return payload;\r\n}"],"names":["hasOwn","classNames","classes","i","arg","appendClass","parseValue","key","value","newClass","module","DEFAULT_SETTINGS","PopupContext","createContext","PopupLayer","className","initialSettings","children","props","settings","useState","reassingObject","nodes","setNodes","context","toggleNode","registerNode","toggleDocument","useEffect","handleKeydown","e","maxZIndex","el","node","nod","force","open","prev","id","Suspense","jsxs","jsx","cn","PopupWindow","layerClassName","style","state","stateSetter","initialAnimation","onExit","onOpen","ctx","useContext","animation","container","setContainer","isOpen","setIsOpen","zIndex","setZIndex","createPortal","PopupButton","as","onClick","disabled","popupId","isActive","setIsActive","Tag","toggle","target","refference","payload"],"mappings":";;;;;;;;;;;;;;;AAOA,KAAC,WAAY;AAGZ,UAAIA,IAAS,CAAA,EAAG;AAEhB,eAASC,IAAc;AAGtB,iBAFIC,IAAU,IAELC,IAAI,GAAGA,IAAI,UAAU,QAAQA,KAAK;AAC1C,cAAIC,IAAM,UAAUD,CAAC;AACrB,UAAIC,MACHF,IAAUG,EAAYH,GAASI,EAAWF,CAAG,CAAC;AAAA,QAElD;AAEE,eAAOF;AAAA,MACT;AAEC,eAASI,EAAYF,GAAK;AACzB,YAAI,OAAOA,KAAQ,YAAY,OAAOA,KAAQ;AAC7C,iBAAOA;AAGR,YAAI,OAAOA,KAAQ;AAClB,iBAAO;AAGR,YAAI,MAAM,QAAQA,CAAG;AACpB,iBAAOH,EAAW,MAAM,MAAMG,CAAG;AAGlC,YAAIA,EAAI,aAAa,OAAO,UAAU,YAAY,CAACA,EAAI,SAAS,SAAQ,EAAG,SAAS,eAAe;AAClG,iBAAO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AAAA,IACH;AAAA,KACUqC,CAAS,IAjBE;AAkBzB,GAOaO,IAAqC,CAAC,EAAE,UAAA5C,GAAU,IAAA6C,GAAI,WAAA/C,GAAW,SAAAgD,GAAS,UAAAC,GAAU,SAAAC,GAAS,GAAG/C,QAAY;AACjH,QAAAiC,IAAMC,EAAWxC,CAAY,GAE7B,CAACsD,GAAUC,CAAW,IAAI/C,EAAkB,EAAK,GAEjDgD,IAAmCN,KAAM;AAK/C,EAAAlC,EAAU,MAAM;AACd,UAAMK,IAAOkB,EAAI,MAAM,KAAK,CAAMnB,MAAAA,EAAG,OAAOiC,CAAO;AACnD,IAAKhC,KAELkC,EAAYlC,EAAK,IAAI;AAAA,EAAA,GACpB,CAACkB,CAAG,CAAC;AAIR,WAASkB,EAAOvC,GAAqB;AACnC,IAAAqB,EAAI,WAAWc,CAAO,GACtBF,KAAWA,EAAQjC,CAAC;AAAA,EAAA;AAKtB,SAAQ,gBAAAW,EAAA2B,GAAA,EAAI,WAAW1B,EAAG,oBAAoBwB,KAAY,4BAA4BnD,CAAS,GAAG,MAAK,UAAS,SAASsD,GAAQ,iBAAc,UAAS,UAAU,GAAG,UAAAL,GAAoB,iBAAeA,GAAU,2BAAyBC,GAAS,cAAYC,IAAW,gBAAgB,cAAe,GAAGhD,GAC1S,UAAAD,EACH,CAAA;AACF;AAIA,SAASI,EAAeiD,GAAgBC,GAAoB;AACpD,QAAAC,IAAU,EAAE,GAAGD,EAAW;AAEhC,aAAWhE,KAAO+D;AACR,IAAAE,EAAAjE,CAAG,IAAI+D,EAAO/D,CAAG;AAGpB,SAAAiE;AACT;;;;;;;","x_google_ignoreList":[0]}
|
package/dist/index.umd.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
|
-
(function(
|
|
1
|
+
(function(d,m){typeof exports=="object"&&typeof module<"u"?m(exports,require("react/jsx-runtime"),require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","react-dom"],m):(d=typeof globalThis<"u"?globalThis:d||self,m(d["@fullkekw/fkw-popup"]={},d.ReactJsxRuntime,d.React,d.ReactDOM))})(this,function(d,m,o,D){"use strict";function T(u){return u&&u.__esModule&&Object.prototype.hasOwnProperty.call(u,"default")?u.default:u}var h={exports:{}};/*!
|
|
2
2
|
Copyright (c) 2018 Jed Watson.
|
|
3
3
|
Licensed under the MIT License (MIT), see
|
|
4
4
|
http://jedwatson.github.io/classnames
|
|
5
|
-
*/var
|
|
5
|
+
*/var P;function _(){return P||(P=1,function(u){(function(){var w={}.hasOwnProperty;function c(){for(var e="",n=0;n<arguments.length;n++){var f=arguments[n];f&&(e=i(e,l(f)))}return e}function l(e){if(typeof e=="string"||typeof e=="number")return e;if(typeof e!="object")return"";if(Array.isArray(e))return c.apply(null,e);if(e.toString!==Object.prototype.toString&&!e.toString.toString().includes("[native code]"))return e.toString();var n="";for(var f in e)w.call(e,f)&&e[f]&&(n=i(n,f));return n}function i(e,n){return n?e?e+" "+n:e+n:e}u.exports?(c.default=c,u.exports=c):window.classNames=c})()}(h)),h.exports}var L=_();const O=T(L),E={disableScroll:!0,exitOnDocument:!0,exitOnEscape:!0,preventStateChange:!1},b=o.createContext({}),I=({className:u,settings:w,children:c,...l})=>{const[i]=o.useState(j(w??{},E)),[e,n]=o.useState([]),f={nodes:e,toggleNode:y,registerNode:v,toggleDocument:k};o.useEffect(()=>{if(typeof window>"u")return;window.addEventListener("keydown",p);function p(s){if(s.key==="Escape"){const a=Math.max(...e.filter(x=>x.open).map(x=>x.zIndex)),r=e.find(x=>x.open&&x.zIndex===a);if(!r||!r.settings.exitOnEscape||!(i!=null&&i.exitOnEscape))return;y(r.id)}}return()=>{window.removeEventListener("keydown",p)}},[e]);function y(p,s){let t;if(typeof p=="string"?t={...e.find(r=>r.id===p)}:t={...p},!t.id)return;if((i.preventStateChange||t.settings.preventStateChange)&&s===void 0)return console.warn("Popup action prevented");const a=s??!(t!=null&&t.open);t.open=a,t.zIndex=a?Math.max(...e.map(r=>r.zIndex),0)+1:0,n(r=>[...r.filter(x=>x.id!==t.id),t]),i.disableScroll&&t.settings.disableScroll&&a&&document.body.classList.add("fkw-popup--noScroll"),!a&&!e.filter(r=>r.id!==t.id).some(r=>r.open)&&document.body.classList.remove("fkw-popup--noScroll")}function v(p){n(s=>[...s,p]),p.open&&y(p,!0)}function k(p,s){const t={...e.find(r=>r.id===p)};!t.id||!t.settings.exitOnDocument||s.target.closest(".fkw-popup")||!t.settings.exitOnDocument||!i.exitOnDocument||y(t.id)}return m.jsx(o.Suspense,{children:m.jsxs(b.Provider,{value:f,children:[c,m.jsx("section",{className:O("fkw-popup-container",u),id:"fkw-popup-container",...l})]})})},C=({children:u,className:w,layerClassName:c,style:l,id:i,settings:e,isOpen:n,setIsOpen:f,animation:y,onExit:v,onOpen:k,...p})=>{const s=o.useContext(b),[t]=o.useState(y??"scale"),[a]=o.useState(j(e??{},E)),[r,x]=o.useState(null),[g,q]=o.useState(n??!1),[A,z]=o.useState(0);return o.useEffect(()=>{x(document.querySelector("#fkw-popup-container")),s.registerNode({id:i,open:g,zIndex:0,settings:a})},[]),o.useEffect(()=>{g&&k&&k(),!g&&v&&v()},[n]),o.useEffect(()=>{const S=s.nodes.find(B=>B.id===i);S&&(q(S.open),S.zIndex!==0?z(S.zIndex):setTimeout(()=>{z(S.zIndex)},200))},[s]),o.useEffect(()=>{f===void 0||n===g||f(g)},[g]),o.useEffect(()=>{n===void 0||n===g||s.toggleNode(i,n)},[n]),r?D.createPortal(m.jsx("section",{id:i,className:O("fkw-popup-layer",g&&"fkw-popup-layer--open",c),style:{zIndex:1e4+A,cursor:a.exitOnDocument&&!a.preventStateChange?"pointer":"auto",...l},onClick:a.exitOnDocument&&!a.preventStateChange?S=>s.toggleDocument(i,S):void 0,children:m.jsx("article",{className:O("fkw-popup",g&&"fkw-popup--open",t&&`fkw-popup-animation--${t}`,w),role:"dialog","aria-modal":!0,"aria-hidden":!g,...p,children:u})}),r):null},N=({children:u,as:w,className:c,onClick:l,disabled:i,popupId:e,...n})=>{const f=o.useContext(b),[y,v]=o.useState(!1),k=w??"button";o.useEffect(()=>{const s=f.nodes.find(t=>t.id===e);s&&v(s.open)},[f]);function p(s){f.toggleNode(e),l&&l(s)}return m.jsx(k,{className:O("fkw-popup-button",y&&"fkw-popup-button--active",c),role:"button",onClick:p,"aria-haspopup":"dialog",tabIndex:0,disabled:i,"aria-disabled":i,"data-fkw-popup-operator":e,"aria-label":y?"Close Popup":"Open Popup",...n,children:u})};function j(u,w){const c={...w};for(const l in u)c[l]=u[l];return c}const M=Object.freeze(Object.defineProperty({__proto__:null,PopupButton:N,PopupLayer:I,PopupWindow:C},Symbol.toStringTag,{value:"Module"}));d.PopupButton=N,d.PopupLayer=I,d.PopupWindow=C,d.default=M,Object.defineProperties(d,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
|
|
6
6
|
//# sourceMappingURL=index.umd.js.map
|
package/dist/index.umd.js.map
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.umd.js","sources":["../node_modules/classnames/index.js","../src/_package/Package.tsx"],"sourcesContent":["/*!\n\tCopyright (c) 2018 Jed Watson.\n\tLicensed under the MIT License (MIT), see\n\thttp://jedwatson.github.io/classnames\n*/\n/* global define */\n\n(function () {\n\t'use strict';\n\n\tvar hasOwn = {}.hasOwnProperty;\n\n\tfunction classNames () {\n\t\tvar classes = '';\n\n\t\tfor (var i = 0; i < arguments.length; i++) {\n\t\t\tvar arg = arguments[i];\n\t\t\tif (arg) {\n\t\t\t\tclasses = appendClass(classes, parseValue(arg));\n\t\t\t}\n\t\t}\n\n\t\treturn classes;\n\t}\n\n\tfunction parseValue (arg) {\n\t\tif (typeof arg === 'string' || typeof arg === 'number') {\n\t\t\treturn arg;\n\t\t}\n\n\t\tif (typeof arg !== 'object') {\n\t\t\treturn '';\n\t\t}\n\n\t\tif (Array.isArray(arg)) {\n\t\t\treturn classNames.apply(null, arg);\n\t\t}\n\n\t\tif (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes('[native code]')) {\n\t\t\treturn arg.toString();\n\t\t}\n\n\t\tvar classes = '';\n\n\t\tfor (var key in arg) {\n\t\t\tif (hasOwn.call(arg, key) && arg[key]) {\n\t\t\t\tclasses = appendClass(classes, key);\n\t\t\t}\n\t\t}\n\n\t\treturn classes;\n\t}\n\n\tfunction appendClass (value, newClass) {\n\t\tif (!newClass) {\n\t\t\treturn value;\n\t\t}\n\t\n\t\tif (value) {\n\t\t\treturn value + ' ' + newClass;\n\t\t}\n\t\n\t\treturn value + newClass;\n\t}\n\n\tif (typeof module !== 'undefined' && module.exports) {\n\t\tclassNames.default = classNames;\n\t\tmodule.exports = classNames;\n\t} else if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) {\n\t\t// register as 'classnames', consistent with npm package name\n\t\tdefine('classnames', [], function () {\n\t\t\treturn classNames;\n\t\t});\n\t} else {\n\t\twindow.classNames = classNames;\n\t}\n}());\n","import './styles.scss';\r\n\r\nimport React, { createContext, FC, JSX, useContext, useEffect, useMemo, useState } from \"react\";\r\nimport cn from 'classnames';\r\nimport { PopupButtonProps, PopupContextProps, PopupLayerProps, PopupNode, PopupSettings, PopupWindowAnimationType, PopupWindowProps } from './Interfaces';\r\nimport { createPortal } from 'react-dom';\r\n\r\n\r\n\r\nconst DEFAULT_SETTINGS: Required<PopupSettings> = {\r\n disableScroll: true,\r\n exitOnDocument: true,\r\n exitOnEscape: true,\r\n preventStateChange: false\r\n};\r\n\r\n// @ts-expect-error Need empty object\r\nconst PopupContext = createContext<PopupContextProps>({});\r\n\r\n\r\n\r\n/** \r\n * Popup context provider. Must be inside body tag and in client environment (NextJS)\r\n */\r\nexport const PopupLayer: FC<PopupLayerProps> = ({ className, settings: initialSettings, children, ...props }) => {\r\n const [settings] = useState<PopupSettings>(reassingObject(initialSettings ?? {}, DEFAULT_SETTINGS));\r\n const [nodes, setNodes] = useState<PopupNode[]>([]);\r\n\r\n const context: PopupContextProps = {\r\n nodes,\r\n toggleNode,\r\n registerNode,\r\n toggleDocument\r\n };\r\n\r\n\r\n\r\n // Handle exitOnEscape\r\n useEffect(() => {\r\n if (typeof window === 'undefined') return;\r\n\r\n window.addEventListener('keydown', handleKeydown);\r\n\r\n function handleKeydown(e: KeyboardEvent) {\r\n const key = e.key;\r\n\r\n if (key === 'Escape') {\r\n const maxZIndex = Math.max(...nodes.filter(el => el.open).map(el => el.zIndex));\r\n const node = nodes.find(el => el.open && el.zIndex === maxZIndex);\r\n if (!node || !node.settings.exitOnEscape || !settings?.exitOnEscape) return;\r\n\r\n toggleNode(node.id);\r\n }\r\n }\r\n\r\n return () => {\r\n window.removeEventListener('keydown', handleKeydown);\r\n };\r\n }, [nodes]);\r\n\r\n\r\n /** \r\n * @param state Forced state\r\n */\r\n function toggleNode(nod: string | PopupNode, force?: boolean) {\r\n let node: PopupNode;\r\n\r\n if (typeof nod === 'string') {\r\n node = { ...nodes.find(el => el.id === nod) } as PopupNode;\r\n } else {\r\n node = { ...nod };\r\n }\r\n\r\n if (!node.id) return;\r\n if ((settings.preventStateChange || node.settings.preventStateChange) && force === undefined) return console.warn(`Popup action prevented`);\r\n\r\n const open = force ?? !node?.open;\r\n\r\n node.open = open;\r\n node.zIndex = open ? Math.max(...nodes.map(el => el.zIndex), 0) + 1 : 0;\r\n\r\n setNodes(prev => [...prev.filter(el => el.id !== node.id), node]);\r\n\r\n // Hide scroll on open\r\n if (settings.disableScroll && node.settings.disableScroll && open) {\r\n document.body.classList.add('fkw-popup--noScroll');\r\n }\r\n\r\n // Show scroll if no popup open\r\n if (!open && !nodes.filter(el => el.id !== node.id).some(el => el.open)) {\r\n document.body.classList.remove('fkw-popup--noScroll');\r\n }\r\n }\r\n\r\n /** Register new node */\r\n function registerNode(node: PopupNode) {\r\n setNodes(prev => [...prev, node]);\r\n\r\n if (node.open) toggleNode(node, true);\r\n }\r\n\r\n function toggleDocument(id: string, e: React.MouseEvent) {\r\n const node: PopupNode = { ...nodes.find(el => el.id === id) } as PopupNode;\r\n if (!node.id) return;\r\n if (!node.settings.exitOnDocument) return;\r\n\r\n const popup = (e.target as HTMLElement).closest('.fkw-popup');\r\n if (popup || !node.settings.exitOnDocument || !settings.exitOnDocument) return;\r\n\r\n toggleNode(node.id);\r\n }\r\n\r\n\r\n\r\n return <PopupContext.Provider value={context}>\r\n {children}\r\n\r\n <section className={cn(`fkw-popup-container`, className)} id='fkw-popup-container' {...props}></section>\r\n </PopupContext.Provider>;\r\n};\r\n\r\n\r\n\r\n/** \r\n * Popup window\r\n */\r\nexport const PopupWindow: FC<PopupWindowProps> = ({ children, className, layerClassName, style, id, settings: initialSettings, isOpen: state, setIsOpen: stateSetter, animation: initialAnimation, renderOnDemand, onExit, onOpen, ...props }) => {\r\n const ctx = useContext(PopupContext) as PopupContextProps;\r\n\r\n const [animation] = useState<PopupWindowAnimationType>(initialAnimation ?? 'scale');\r\n const [settings] = useState<PopupSettings>(reassingObject(initialSettings ?? {}, DEFAULT_SETTINGS));\r\n const [isMounted, setIsMounted] = useState<boolean>(false);\r\n const [isRendered, setIsRendered] = useState<boolean>(false);\r\n const [container, setContainer] = useState<Element | null>(null);\r\n\r\n const [isOpen, setIsOpen] = useState<boolean>(false);\r\n const [zIndex, setZIndex] = useState<number>(0);\r\n\r\n\r\n\r\n // Handle isRendered & onOpen, onExit\r\n useMemo(() => {\r\n if (renderOnDemand) {\r\n if (isOpen) setIsRendered(true); // Render content only if window is open\r\n } else setIsRendered(true);\r\n\r\n if (isOpen && onOpen) onOpen();\r\n if (!isOpen && onExit) onExit();\r\n }, [isOpen]);\r\n\r\n // Mount\r\n useEffect(() => {\r\n setContainer(document.querySelector('#fkw-popup-container'));\r\n setIsMounted(true);\r\n\r\n ctx.registerNode({\r\n id,\r\n open: false,\r\n zIndex: 0,\r\n settings\r\n });\r\n }, []);\r\n\r\n // Listen context\r\n useEffect(() => {\r\n const node = ctx.nodes.find(el => el.id === id);\r\n if (!node) return;\r\n\r\n setIsOpen(node.open);\r\n\r\n if (node.zIndex !== 0) {\r\n // Instantly update zIndex\r\n setZIndex(node.zIndex);\r\n } else {\r\n // Timeout zIndex update\r\n setTimeout(() => {\r\n setZIndex(node.zIndex);\r\n }, 200);\r\n }\r\n }, [ctx]);\r\n\r\n // Sync out state on current change\r\n useEffect(() => {\r\n if (stateSetter === undefined || state === isOpen) return;\r\n\r\n stateSetter(isOpen);\r\n }, [isOpen]);\r\n\r\n // Sync current state on out change\r\n useEffect(() => {\r\n if (state === undefined || state === isOpen) return;\r\n\r\n ctx.toggleNode(id, state);\r\n }, [state]);\r\n\r\n\r\n\r\n if (!isMounted || !container) return null;\r\n\r\n return createPortal(<>\r\n <section\r\n id={id}\r\n className={cn(`fkw-popup-layer`, isOpen && 'fkw-popup-layer--open', layerClassName)}\r\n style={{ zIndex: 10000 + zIndex, cursor: settings.exitOnDocument && !settings.preventStateChange ? 'pointer' : 'auto', ...style }}\r\n onClick={settings.exitOnDocument && !settings.preventStateChange ? e => ctx.toggleDocument(id, e) : undefined}\r\n >\r\n <article\r\n className={cn(`fkw-popup`, isOpen && 'fkw-popup--open', animation && `fkw-popup-animation--${animation}`, className)}\r\n role='dialog'\r\n aria-modal\r\n aria-hidden={!isOpen}\r\n {...props}\r\n >\r\n {isRendered && children}\r\n </article>\r\n </section>\r\n </>, container);\r\n};\r\n\r\n\r\n\r\n/** \r\n * Popup trigger button\r\n */\r\nexport const PopupButton: FC<PopupButtonProps> = ({ children, as, className, onClick, disabled, popupId, ...props }) => {\r\n const ctx = useContext(PopupContext) as PopupContextProps;\r\n\r\n const Tag: keyof JSX.IntrinsicElements = as ?? 'button';\r\n\r\n const [isActive, setIsActive] = useState<boolean>(false);\r\n\r\n\r\n\r\n // Listen context\r\n useEffect(() => {\r\n const node = ctx.nodes.find(el => el.id === popupId);\r\n if (!node) return;\r\n\r\n setIsActive(node.open);\r\n }, [ctx]);\r\n\r\n\r\n\r\n function toggle(e: React.MouseEvent) {\r\n ctx.toggleNode(popupId);\r\n onClick && onClick(e);\r\n }\r\n\r\n\r\n\r\n return <Tag className={cn('fkw-popup-button', isActive && 'fkw-popup-button--active', className)} role='button' onClick={toggle} aria-haspopup=\"dialog\" tabIndex={0} disabled={disabled} aria-disabled={disabled} data-fkw-popup-operator={popupId} aria-label={isActive ? 'Close Popup' : 'Open Popup'} {...props}>\r\n {children}\r\n </Tag>;\r\n};\r\n\r\n\r\n\r\nfunction reassingObject(target: object, refference: object) {\r\n const payload = { ...refference };\r\n\r\n for (const key in target) {\r\n payload[key] = target[key];\r\n }\r\n\r\n return payload;\r\n}"],"names":["hasOwn","classNames","classes","i","arg","appendClass","parseValue","key","value","newClass","module","DEFAULT_SETTINGS","PopupContext","createContext","PopupLayer","className","initialSettings","children","props","settings","useState","reassingObject","nodes","setNodes","context","toggleNode","registerNode","toggleDocument","useEffect","handleKeydown","e","maxZIndex","el","node","nod","force","open","prev","id","jsxs","jsx","cn","PopupWindow","layerClassName","style","state","stateSetter","initialAnimation","renderOnDemand","onExit","onOpen","ctx","useContext","animation","isMounted","setIsMounted","isRendered","setIsRendered","container","setContainer","isOpen","setIsOpen","zIndex","setZIndex","useMemo","createPortal","Fragment","PopupButton","as","onClick","disabled","popupId","Tag","isActive","setIsActive","toggle","target","refference","payload"],"mappings":";;;;iDAOC,UAAY,CAGZ,IAAIA,EAAS,CAAA,EAAG,eAEhB,SAASC,GAAc,CAGtB,QAFIC,EAAU,GAELC,EAAI,EAAGA,EAAI,UAAU,OAAQA,IAAK,CAC1C,IAAIC,EAAM,UAAUD,CAAC,EACjBC,IACHF,EAAUG,EAAYH,EAASI,EAAWF,CAAG,CAAC,EAElD,CAEE,OAAOF,CACT,CAEC,SAASI,EAAYF,EAAK,CACzB,GAAI,OAAOA,GAAQ,UAAY,OAAOA,GAAQ,SAC7C,OAAOA,EAGR,GAAI,OAAOA,GAAQ,SAClB,MAAO,GAGR,GAAI,MAAM,QAAQA,CAAG,EACpB,OAAOH,EAAW,MAAM,KAAMG,CAAG,EAGlC,GAAIA,EAAI,WAA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D,EAAI,UAAArD,EAAW,QAAAsD,EAAS,SAAAC,EAAU,QAAAC,EAAS,GAAGrD,KAAY,CAChH,MAAAiC,EAAMC,aAAWxC,CAAY,EAE7B4D,EAAmCJ,GAAM,SAEzC,CAACK,EAAUC,CAAW,EAAItD,EAAAA,SAAkB,EAAK,EAKvDQ,EAAAA,UAAU,IAAM,CACd,MAAMK,EAAOkB,EAAI,MAAM,KAAWnB,GAAAA,EAAG,KAAOuC,CAAO,EAC9CtC,GAELyC,EAAYzC,EAAK,IAAI,CAAA,EACpB,CAACkB,CAAG,CAAC,EAIR,SAASwB,EAAO7C,EAAqB,CACnCqB,EAAI,WAAWoB,CAAO,EACtBF,GAAWA,EAAQvC,CAAC,CAAA,CAKtB,OAAQU,EAAA,IAAAgC,EAAA,CAAI,UAAW/B,EAAG,mBAAoBgC,GAAY,2BAA4B1D,CAAS,EAAG,KAAK,SAAS,QAAS4D,EAAQ,gBAAc,SAAS,SAAU,EAAG,SAAAL,EAAoB,gBAAeA,EAAU,0BAAyBC,EAAS,aAAYE,EAAW,cAAgB,aAAe,GAAGvD,EAC1S,SAAAD,CACH,CAAA,CACF,EAIA,SAASI,EAAeuD,EAAgBC,EAAoB,CACpD,MAAAC,EAAU,CAAE,GAAGD,CAAW,EAEhC,UAAWtE,KAAOqE,EACRE,EAAAvE,CAAG,EAAIqE,EAAOrE,CAAG,EAGpB,OAAAuE,CACT","x_google_ignoreList":[0]}
|
|
1
|
+
{"version":3,"file":"index.umd.js","sources":["../node_modules/classnames/index.js","../src/_package/Package.tsx"],"sourcesContent":["/*!\n\tCopyright (c) 2018 Jed Watson.\n\tLicensed under the MIT License (MIT), see\n\thttp://jedwatson.github.io/classnames\n*/\n/* global define */\n\n(function () {\n\t'use strict';\n\n\tvar hasOwn = {}.hasOwnProperty;\n\n\tfunction classNames () {\n\t\tvar classes = '';\n\n\t\tfor (var i = 0; i < arguments.length; i++) {\n\t\t\tvar arg = arguments[i];\n\t\t\tif (arg) {\n\t\t\t\tclasses = appendClass(classes, parseValue(arg));\n\t\t\t}\n\t\t}\n\n\t\treturn classes;\n\t}\n\n\tfunction parseValue (arg) {\n\t\tif (typeof arg === 'string' || typeof arg === 'number') {\n\t\t\treturn arg;\n\t\t}\n\n\t\tif (typeof arg !== 'object') {\n\t\t\treturn '';\n\t\t}\n\n\t\tif (Array.isArray(arg)) {\n\t\t\treturn classNames.apply(null, arg);\n\t\t}\n\n\t\tif (arg.toString !== Object.prototype.toString && !arg.toString.toString().includes('[native code]')) {\n\t\t\treturn arg.toString();\n\t\t}\n\n\t\tvar classes = '';\n\n\t\tfor (var key in arg) {\n\t\t\tif (hasOwn.call(arg, key) && arg[key]) {\n\t\t\t\tclasses = appendClass(classes, key);\n\t\t\t}\n\t\t}\n\n\t\treturn classes;\n\t}\n\n\tfunction appendClass (value, newClass) {\n\t\tif (!newClass) {\n\t\t\treturn value;\n\t\t}\n\t\n\t\tif (value) {\n\t\t\treturn value + ' ' + newClass;\n\t\t}\n\t\n\t\treturn value + newClass;\n\t}\n\n\tif (typeof module !== 'undefined' && module.exports) {\n\t\tclassNames.default = classNames;\n\t\tmodule.exports = classNames;\n\t} else if (typeof define === 'function' && typeof define.amd === 'object' && define.amd) {\n\t\t// register as 'classnames', consistent with npm package name\n\t\tdefine('classnames', [], function () {\n\t\t\treturn classNames;\n\t\t});\n\t} else {\n\t\twindow.classNames = classNames;\n\t}\n}());\n","import './styles.scss';\r\n\r\nimport React, { createContext, FC, JSX, Suspense, useContext, useEffect, useMemo, useState } from \"react\";\r\nimport cn from 'classnames';\r\nimport { IPopupButtonProps, IPopupContextProps, IPopupLayerProps, IPopupNode, IPopupSettings, PopupWindowAnimationType, IPopupWindowProps } from './Interfaces';\r\nimport { createPortal } from 'react-dom';\r\nimport useMixedState from './useMixedState';\r\n\r\n\r\n\r\nconst DEFAULT_SETTINGS: Required<IPopupSettings> = {\r\n disableScroll: true,\r\n exitOnDocument: true,\r\n exitOnEscape: true,\r\n preventStateChange: false\r\n};\r\n\r\nconst PopupContext = createContext<IPopupContextProps>({} as IPopupContextProps);\r\n\r\n\r\n\r\n/** \r\n * Popup context provider. Must be inside body tag and in client environment (NextJS)\r\n */\r\nexport const PopupLayer: FC<IPopupLayerProps> = ({ className, settings: initialSettings, children, ...props }) => {\r\n const [settings] = useState<IPopupSettings>(reassingObject(initialSettings ?? {}, DEFAULT_SETTINGS));\r\n const [nodes, setNodes] = useState<IPopupNode[]>([]);\r\n\r\n const context: IPopupContextProps = {\r\n nodes,\r\n toggleNode,\r\n registerNode,\r\n toggleDocument\r\n };\r\n\r\n\r\n\r\n // Handle exitOnEscape\r\n useEffect(() => {\r\n if (typeof window === 'undefined') return;\r\n\r\n window.addEventListener('keydown', handleKeydown);\r\n\r\n function handleKeydown(e: KeyboardEvent) {\r\n const key = e.key;\r\n\r\n if (key === 'Escape') {\r\n const maxZIndex = Math.max(...nodes.filter(el => el.open).map(el => el.zIndex));\r\n const node = nodes.find(el => el.open && el.zIndex === maxZIndex);\r\n if (!node || !node.settings.exitOnEscape || !settings?.exitOnEscape) return;\r\n\r\n toggleNode(node.id);\r\n }\r\n }\r\n\r\n return () => {\r\n window.removeEventListener('keydown', handleKeydown);\r\n };\r\n }, [nodes]);\r\n\r\n\r\n /** \r\n * @param state Forced state\r\n */\r\n function toggleNode(nod: string | IPopupNode, force?: boolean) {\r\n let node: IPopupNode;\r\n\r\n if (typeof nod === 'string') {\r\n node = { ...nodes.find(el => el.id === nod) } as IPopupNode;\r\n } else {\r\n node = { ...nod };\r\n }\r\n\r\n if (!node.id) return;\r\n if ((settings.preventStateChange || node.settings.preventStateChange) && force === undefined) return console.warn(`Popup action prevented`);\r\n\r\n const open = force ?? !node?.open;\r\n\r\n node.open = open;\r\n node.zIndex = open ? Math.max(...nodes.map(el => el.zIndex), 0) + 1 : 0;\r\n\r\n setNodes(prev => [...prev.filter(el => el.id !== node.id), node]);\r\n\r\n // Hide scroll on open\r\n if (settings.disableScroll && node.settings.disableScroll && open) {\r\n document.body.classList.add('fkw-popup--noScroll');\r\n }\r\n\r\n // Show scroll if no popup open\r\n if (!open && !nodes.filter(el => el.id !== node.id).some(el => el.open)) {\r\n document.body.classList.remove('fkw-popup--noScroll');\r\n }\r\n }\r\n\r\n /** Register new node */\r\n function registerNode(node: IPopupNode) {\r\n setNodes(prev => [...prev, node]);\r\n\r\n if (node.open) toggleNode(node, true);\r\n }\r\n\r\n function toggleDocument(id: string, e: React.MouseEvent) {\r\n const node: IPopupNode = { ...nodes.find(el => el.id === id) } as IPopupNode;\r\n if (!node.id) return;\r\n if (!node.settings.exitOnDocument) return;\r\n\r\n const popup = (e.target as HTMLElement).closest('.fkw-popup');\r\n if (popup || !node.settings.exitOnDocument || !settings.exitOnDocument) return;\r\n\r\n toggleNode(node.id);\r\n }\r\n\r\n\r\n\r\n return <Suspense>\r\n <PopupContext.Provider value={context}>\r\n {children}\r\n\r\n <section className={cn(`fkw-popup-container`, className)} id='fkw-popup-container' {...props}></section>\r\n </PopupContext.Provider>\r\n </Suspense>;\r\n};\r\n\r\n\r\n\r\n/** \r\n * Popup window\r\n */\r\nexport const PopupWindow: FC<IPopupWindowProps> = ({ children, className, layerClassName, style, id, settings: initialSettings, isOpen: state, setIsOpen: stateSetter, animation: initialAnimation, onExit, onOpen, ...props }) => {\r\n const ctx = useContext(PopupContext) as IPopupContextProps;\r\n\r\n const [animation] = useState<PopupWindowAnimationType>(initialAnimation ?? 'scale');\r\n const [settings] = useState<IPopupSettings>(reassingObject(initialSettings ?? {}, DEFAULT_SETTINGS));\r\n const [container, setContainer] = useState<Element | null>(null);\r\n\r\n const [isOpen, setIsOpen] = useState(state ?? false);\r\n const [zIndex, setZIndex] = useState<number>(0);\r\n\r\n\r\n\r\n // Mount\r\n useEffect(() => {\r\n setContainer(document.querySelector('#fkw-popup-container'));\r\n\r\n ctx.registerNode({\r\n id,\r\n open: isOpen,\r\n zIndex: 0,\r\n settings\r\n });\r\n }, []);\r\n\r\n // Handle onOpen, onExit\r\n useEffect(() => {\r\n if (isOpen && onOpen) onOpen();\r\n if (!isOpen && onExit) onExit();\r\n }, [state]);\r\n\r\n // Listen context\r\n useEffect(() => {\r\n const node = ctx.nodes.find(el => el.id === id);\r\n if (!node) return;\r\n\r\n setIsOpen(node.open);\r\n\r\n if (node.zIndex !== 0) {\r\n // Instantly update zIndex\r\n setZIndex(node.zIndex);\r\n } else {\r\n // Timeout zIndex update\r\n setTimeout(() => {\r\n setZIndex(node.zIndex);\r\n }, 200); // TODO: fix constant animation delay timeout\r\n }\r\n }, [ctx]);\r\n\r\n // Sync out state on current change\r\n useEffect(() => {\r\n if (stateSetter === undefined || state === isOpen) return;\r\n\r\n stateSetter(isOpen);\r\n }, [isOpen]);\r\n\r\n // Sync current state on out change\r\n useEffect(() => {\r\n if (state === undefined || state === isOpen) return;\r\n\r\n ctx.toggleNode(id, state);\r\n }, [state]);\r\n\r\n\r\n\r\n if (!container) return null;\r\n\r\n return createPortal(<section\r\n id={id}\r\n className={cn(`fkw-popup-layer`, isOpen && 'fkw-popup-layer--open', layerClassName)}\r\n style={{ zIndex: 10000 + zIndex, cursor: settings.exitOnDocument && !settings.preventStateChange ? 'pointer' : 'auto', ...style }}\r\n onClick={settings.exitOnDocument && !settings.preventStateChange ? e => ctx.toggleDocument(id, e) : undefined}\r\n >\r\n <article\r\n className={cn(`fkw-popup`, isOpen && 'fkw-popup--open', animation && `fkw-popup-animation--${animation}`, className)}\r\n role='dialog'\r\n aria-modal\r\n aria-hidden={!isOpen}\r\n {...props}\r\n >\r\n {children}\r\n </article>\r\n </section>, container);\r\n};\r\n\r\n\r\n\r\n/** \r\n * Popup trigger button\r\n */\r\nexport const PopupButton: FC<IPopupButtonProps> = ({ children, as, className, onClick, disabled, popupId, ...props }) => {\r\n const ctx = useContext(PopupContext) as IPopupContextProps;\r\n\r\n const [isActive, setIsActive] = useState<boolean>(false);\r\n\r\n const Tag: keyof JSX.IntrinsicElements = as ?? 'button';\r\n\r\n\r\n\r\n // Listen context\r\n useEffect(() => {\r\n const node = ctx.nodes.find(el => el.id === popupId);\r\n if (!node) return;\r\n\r\n setIsActive(node.open);\r\n }, [ctx]);\r\n\r\n\r\n\r\n function toggle(e: React.MouseEvent) {\r\n ctx.toggleNode(popupId);\r\n onClick && onClick(e);\r\n }\r\n\r\n\r\n\r\n return <Tag className={cn('fkw-popup-button', isActive && 'fkw-popup-button--active', className)} role='button' onClick={toggle} aria-haspopup=\"dialog\" tabIndex={0} disabled={disabled} aria-disabled={disabled} data-fkw-popup-operator={popupId} aria-label={isActive ? 'Close Popup' : 'Open Popup'} {...props}>\r\n {children}\r\n </Tag>;\r\n};\r\n\r\n\r\n\r\nfunction reassingObject(target: object, refference: object) {\r\n const payload = { ...refference };\r\n\r\n for (const key in target) {\r\n payload[key] = target[key];\r\n }\r\n\r\n return payload;\r\n}"],"names":["hasOwn","classNames","classes","i","arg","appendClass","parseValue","key","value","newClass","module","DEFAULT_SETTINGS","PopupContext","createContext","PopupLayer","className","initialSettings","children","props","settings","useState","reassingObject","nodes","setNodes","context","toggleNode","registerNode","toggleDocument","useEffect","handleKeydown","e","maxZIndex","el","node","nod","force","open","prev","id","Suspense","jsxs","jsx","cn","PopupWindow","layerClassName","style","state","stateSetter","initialAnimation","onExit","onOpen","ctx","useContext","animation","container","setContainer","isOpen","setIsOpen","zIndex","setZIndex","createPortal","PopupButton","as","onClick","disabled","popupId","isActive","setIsActive","Tag","toggle","target","refference","payload"],"mappings":";;;;iDAOC,UAAY,CAGZ,IAAIA,EAAS,CAAA,EAAG,eAEhB,SAASC,GAAc,CAGtB,QAFIC,EAAU,GAELC,EAAI,EAAGA,EAAI,UAAU,OAAQA,IAAK,CAC1C,IAAIC,EAAM,UAAUD,CAAC,EACjBC,IACHF,EAAUG,EAAYH,EAASI,EAAWF,CAAG,CAAC,EAElD,CAEE,OAAOF,CACT,CAEC,SAASI,EAAYF,EAAK,CACzB,GAAI,OAAOA,GAAQ,UAAY,OAAOA,GAAQ,SAC7C,OAAOA,EAGR,GAA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,EAAMC,aAAWxC,CAAY,EAE7B,CAACsD,EAAUC,CAAW,EAAI/C,EAAAA,SAAkB,EAAK,EAEjDgD,EAAmCN,GAAM,SAK/ClC,EAAAA,UAAU,IAAM,CACd,MAAMK,EAAOkB,EAAI,MAAM,KAAWnB,GAAAA,EAAG,KAAOiC,CAAO,EAC9ChC,GAELkC,EAAYlC,EAAK,IAAI,CAAA,EACpB,CAACkB,CAAG,CAAC,EAIR,SAASkB,EAAOvC,EAAqB,CACnCqB,EAAI,WAAWc,CAAO,EACtBF,GAAWA,EAAQjC,CAAC,CAAA,CAKtB,OAAQW,EAAA,IAAA2B,EAAA,CAAI,UAAW1B,EAAG,mBAAoBwB,GAAY,2BAA4BnD,CAAS,EAAG,KAAK,SAAS,QAASsD,EAAQ,gBAAc,SAAS,SAAU,EAAG,SAAAL,EAAoB,gBAAeA,EAAU,0BAAyBC,EAAS,aAAYC,EAAW,cAAgB,aAAe,GAAGhD,EAC1S,SAAAD,CACH,CAAA,CACF,EAIA,SAASI,EAAeiD,EAAgBC,EAAoB,CACpD,MAAAC,EAAU,CAAE,GAAGD,CAAW,EAEhC,UAAWhE,KAAO+D,EACRE,EAAAjE,CAAG,EAAI+D,EAAO/D,CAAG,EAGpB,OAAAiE,CACT","x_google_ignoreList":[0]}
|
package/dist/styles.css
CHANGED
|
@@ -1 +1 @@
|
|
|
1
|
-
.fkw-popup{cursor:auto;transition:.2s ease-in-out}.fkw-popup--noScroll{overflow:hidden;scrollbar-gutter:stable}.fkw-popup-animation--fade{opacity:1}.fkw-popup-animation--fade:not(.fkw-popup--open){opacity:0}.fkw-popup-animation--scale{scale:1}.fkw-popup-animation--scale:not(.fkw-popup--open){scale:.8}.fkw-popup-layer{position:fixed;top:0;left:0;width:100%;height:100%;max-height:100%;z-index:9999;background:#0003;-webkit-tap-highlight-color:transparent;contain:paint;opacity:0;visibility:hidden;touch-action:none;pointer-events:none;transition:.2s ease-in-out;display:flex;align-items:center;justify-content:center}.fkw-popup-layer--open{opacity:1;visibility:visible;touch-action:auto;pointer-events:auto}.fkw-popup-button{cursor:pointer}
|
|
1
|
+
.fkw-popup{cursor:auto;transition:.2s ease-in-out;max-height:100%;overflow-y:auto}.fkw-popup--noScroll{overflow:hidden;scrollbar-gutter:stable}.fkw-popup-animation--fade{opacity:1}.fkw-popup-animation--fade:not(.fkw-popup--open){opacity:0}.fkw-popup-animation--scale{scale:1}.fkw-popup-animation--scale:not(.fkw-popup--open){scale:.8}.fkw-popup-layer{position:fixed;top:0;right:0;bottom:0;left:0;width:100%;height:100%;max-height:100%;z-index:9999;background:#0003;-webkit-tap-highlight-color:transparent;contain:paint;opacity:0;visibility:hidden;touch-action:none;pointer-events:none;transition:.2s ease-in-out;display:flex;align-items:center;justify-content:center}.fkw-popup-layer--open{opacity:1;visibility:visible;touch-action:auto;pointer-events:auto}.fkw-popup-button{cursor:pointer}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import { StateSetter } from './Interfaces';
|
|
2
|
+
export default function useMixedState<S = undefined>(): [S | undefined, StateSetter<S | undefined>];
|
|
3
|
+
export default function useMixedState<S>(initialState: S | (() => S)): [S, StateSetter<S>];
|
|
4
|
+
export default function useMixedState<S>(state: S, setter?: StateSetter<S>): [S, StateSetter<S>];
|