@fullkekw/popup 2.0.9 → 2.0.10

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.
@@ -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 PopupSettings {
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 PopupNode {
26
+ export interface IPopupNode {
26
27
  id: string;
27
28
  open: boolean;
28
29
  zIndex: number;
29
- settings: PopupSettings;
30
+ settings: IPopupSettings;
30
31
  }
31
- export interface PopupContextProps {
32
- nodes: PopupNode[];
33
- toggleNode(node: string | PopupNode, state?: boolean): void;
34
- registerNode(node: PopupNode): void;
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 PopupLayerProps extends React.HTMLAttributes<HTMLElement> {
38
+ export interface IPopupLayerProps extends React.HTMLAttributes<HTMLElement> {
38
39
  children: ReactNode | ReactNode[];
39
- settings?: PopupSettings;
40
+ settings?: IPopupSettings;
40
41
  }
41
- export interface PopupWindowProps extends React.HTMLAttributes<HTMLElement> {
42
+ export interface IPopupWindowProps extends React.HTMLAttributes<HTMLElement> {
42
43
  id: string;
43
44
  children?: ReactNode | ReactNode[];
44
45
  layerClassName?: string;
45
- settings?: PopupSettings;
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?(isOpen: boolean): void;
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 PopupButtonProps extends React.HTMLAttributes<HTMLElement> {
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 { PopupButtonProps, PopupLayerProps, PopupWindowProps } from './Interfaces';
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<PopupLayerProps>;
6
+ export declare const PopupLayer: FC<IPopupLayerProps>;
7
7
  /**
8
8
  * Popup window
9
9
  */
10
- export declare const PopupWindow: FC<PopupWindowProps>;
10
+ export declare const PopupWindow: FC<IPopupWindowProps>;
11
11
  /**
12
12
  * Popup trigger button
13
13
  */
14
- export declare const PopupButton: FC<PopupButtonProps>;
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,8 +1,8 @@
1
- import { jsxs as q, jsx as k, Fragment as F } from "react/jsx-runtime";
2
- import { createContext as R, useState as m, useEffect as O, useContext as z, useMemo as Z } from "react";
3
- import { createPortal as B } from "react-dom";
4
- function G(s) {
5
- return s && s.__esModule && Object.prototype.hasOwnProperty.call(s, "default") ? s.default : s;
1
+ import { jsx as k, jsxs as _ } from "react/jsx-runtime";
2
+ import { useState as x, createContext as L, useEffect as S, Suspense as M, useContext as P, useMemo as T } from "react";
3
+ import { createPortal as A } from "react-dom";
4
+ function q(o) {
5
+ return o && o.__esModule && Object.prototype.hasOwnProperty.call(o, "default") ? o.default : o;
6
6
  }
7
7
  var b = { exports: {} };
8
8
  /*!
@@ -10,15 +10,15 @@ var b = { exports: {} };
10
10
  Licensed under the MIT License (MIT), see
11
11
  http://jedwatson.github.io/classnames
12
12
  */
13
- var P;
14
- function K() {
15
- return P || (P = 1, function(s) {
13
+ var C;
14
+ function F() {
15
+ return C || (C = 1, function(o) {
16
16
  (function() {
17
- var x = {}.hasOwnProperty;
18
- function u() {
19
- for (var e = "", t = 0; t < arguments.length; t++) {
20
- var a = arguments[t];
21
- a && (e = r(e, c(a)));
17
+ var d = {}.hasOwnProperty;
18
+ function p() {
19
+ for (var e = "", n = 0; n < arguments.length; n++) {
20
+ var u = arguments[n];
21
+ u && (e = r(e, c(u)));
22
22
  }
23
23
  return e;
24
24
  }
@@ -28,133 +28,139 @@ function K() {
28
28
  if (typeof e != "object")
29
29
  return "";
30
30
  if (Array.isArray(e))
31
- return u.apply(null, e);
31
+ return p.apply(null, e);
32
32
  if (e.toString !== Object.prototype.toString && !e.toString.toString().includes("[native code]"))
33
33
  return e.toString();
34
- var t = "";
35
- for (var a in e)
36
- x.call(e, a) && e[a] && (t = r(t, a));
37
- return t;
34
+ var n = "";
35
+ for (var u in e)
36
+ d.call(e, u) && e[u] && (n = r(n, u));
37
+ return n;
38
38
  }
39
- function r(e, t) {
40
- return t ? e ? e + " " + t : e + t : e;
39
+ function r(e, n) {
40
+ return n ? e ? e + " " + n : e + n : e;
41
41
  }
42
- s.exports ? (u.default = u, s.exports = u) : window.classNames = u;
42
+ o.exports ? (p.default = p, o.exports = p) : window.classNames = p;
43
43
  })();
44
44
  }(b)), b.exports;
45
45
  }
46
- var U = K();
47
- const S = /* @__PURE__ */ G(U), D = {
46
+ var Z = F();
47
+ const O = /* @__PURE__ */ q(Z);
48
+ function B(o, d) {
49
+ const p = arguments.length === 2 && d !== void 0, [c, r] = x(o);
50
+ return p ? [
51
+ o,
52
+ d
53
+ ] : [c, r];
54
+ }
55
+ const N = {
48
56
  disableScroll: !0,
49
57
  exitOnDocument: !0,
50
58
  exitOnEscape: !0,
51
59
  preventStateChange: !1
52
- }, h = R({}), V = ({ className: s, settings: x, children: u, ...c }) => {
53
- const [r] = m(E(x ?? {}, D)), [e, t] = m([]), a = {
60
+ }, h = L({}), G = ({ className: o, settings: d, children: p, ...c }) => {
61
+ const [r] = x(z(d ?? {}, N)), [e, n] = x([]), u = {
54
62
  nodes: e,
55
- toggleNode: g,
56
- registerNode: y,
57
- toggleDocument: v
63
+ toggleNode: m,
64
+ registerNode: w,
65
+ toggleDocument: y
58
66
  };
59
- O(() => {
67
+ S(() => {
60
68
  if (typeof window > "u") return;
61
- window.addEventListener("keydown", i);
62
- function i(p) {
63
- if (p.key === "Escape") {
64
- const d = Math.max(...e.filter((l) => l.open).map((l) => l.zIndex)), o = e.find((l) => l.open && l.zIndex === d);
65
- if (!o || !o.settings.exitOnEscape || !(r != null && r.exitOnEscape)) return;
66
- g(o.id);
69
+ window.addEventListener("keydown", a);
70
+ function a(s) {
71
+ if (s.key === "Escape") {
72
+ const f = Math.max(...e.filter((l) => l.open).map((l) => l.zIndex)), i = e.find((l) => l.open && l.zIndex === f);
73
+ if (!i || !i.settings.exitOnEscape || !(r != null && r.exitOnEscape)) return;
74
+ m(i.id);
67
75
  }
68
76
  }
69
77
  return () => {
70
- window.removeEventListener("keydown", i);
78
+ window.removeEventListener("keydown", a);
71
79
  };
72
80
  }, [e]);
73
- function g(i, p) {
74
- let n;
75
- if (typeof i == "string" ? n = { ...e.find((o) => o.id === i) } : n = { ...i }, !n.id) return;
76
- if ((r.preventStateChange || n.settings.preventStateChange) && p === void 0) return console.warn("Popup action prevented");
77
- const d = p ?? !(n != null && n.open);
78
- n.open = d, n.zIndex = d ? Math.max(...e.map((o) => o.zIndex), 0) + 1 : 0, t((o) => [...o.filter((l) => l.id !== n.id), n]), r.disableScroll && n.settings.disableScroll && d && document.body.classList.add("fkw-popup--noScroll"), !d && !e.filter((o) => o.id !== n.id).some((o) => o.open) && document.body.classList.remove("fkw-popup--noScroll");
81
+ function m(a, s) {
82
+ let t;
83
+ if (typeof a == "string" ? t = { ...e.find((i) => i.id === a) } : t = { ...a }, !t.id) return;
84
+ if ((r.preventStateChange || t.settings.preventStateChange) && s === void 0) return console.warn("Popup action prevented");
85
+ const f = s ?? !(t != null && t.open);
86
+ t.open = f, t.zIndex = f ? Math.max(...e.map((i) => i.zIndex), 0) + 1 : 0, n((i) => [...i.filter((l) => l.id !== t.id), t]), r.disableScroll && t.settings.disableScroll && f && document.body.classList.add("fkw-popup--noScroll"), !f && !e.filter((i) => i.id !== t.id).some((i) => i.open) && document.body.classList.remove("fkw-popup--noScroll");
79
87
  }
80
- function y(i) {
81
- t((p) => [...p, i]), i.open && g(i, !0);
88
+ function w(a) {
89
+ n((s) => [...s, a]), a.open && m(a, !0);
82
90
  }
83
- function v(i, p) {
84
- const n = { ...e.find((o) => o.id === i) };
85
- !n.id || !n.settings.exitOnDocument || p.target.closest(".fkw-popup") || !n.settings.exitOnDocument || !r.exitOnDocument || g(n.id);
91
+ function y(a, s) {
92
+ const t = { ...e.find((i) => i.id === a) };
93
+ !t.id || !t.settings.exitOnDocument || s.target.closest(".fkw-popup") || !t.settings.exitOnDocument || !r.exitOnDocument || m(t.id);
86
94
  }
87
- return /* @__PURE__ */ q(h.Provider, { value: a, children: [
88
- u,
89
- /* @__PURE__ */ k("section", { className: S("fkw-popup-container", s), id: "fkw-popup-container", ...c })
90
- ] });
91
- }, W = ({ children: s, className: x, layerClassName: u, style: c, id: r, settings: e, isOpen: t, setIsOpen: a, animation: g, renderOnDemand: y, onExit: v, onOpen: i, ...p }) => {
92
- const n = z(h), [d] = m(g ?? "scale"), [o] = m(E(e ?? {}, D)), [l, j] = m(!1), [M, I] = m(!1), [C, _] = m(null), [f, L] = m(!1), [T, N] = m(0);
93
- return Z(() => {
94
- y ? f && I(!0) : I(!0), f && i && i(), !f && v && v();
95
- }, [f]), O(() => {
96
- _(document.querySelector("#fkw-popup-container")), j(!0), n.registerNode({
95
+ return /* @__PURE__ */ k(M, { children: /* @__PURE__ */ _(h.Provider, { value: u, children: [
96
+ p,
97
+ /* @__PURE__ */ k("section", { className: O("fkw-popup-container", o), id: "fkw-popup-container", ...c })
98
+ ] }) });
99
+ }, K = ({ children: o, className: d, layerClassName: p, style: c, id: r, settings: e, isOpen: n, setIsOpen: u, animation: m, onExit: w, onOpen: y, ...a }) => {
100
+ const s = P(h);
101
+ n = T(() => n ?? !1, []);
102
+ const [t] = x(m ?? "scale"), [f] = x(z(e ?? {}, N)), [i, l] = x(null), [v, D] = B(n, u), [E, I] = x(0);
103
+ return S(() => {
104
+ l(document.querySelector("#fkw-popup-container")), s.registerNode({
97
105
  id: r,
98
- open: !1,
106
+ open: n,
99
107
  zIndex: 0,
100
- settings: o
108
+ settings: f
101
109
  });
102
- }, []), O(() => {
103
- const w = n.nodes.find((A) => A.id === r);
104
- w && (L(w.open), w.zIndex !== 0 ? N(w.zIndex) : setTimeout(() => {
105
- N(w.zIndex);
110
+ }, []), S(() => {
111
+ v && y && y(), !v && w && w();
112
+ }, [v]), S(() => {
113
+ const g = s.nodes.find((j) => j.id === r);
114
+ g && (D(g.open), g.zIndex !== 0 ? I(g.zIndex) : setTimeout(() => {
115
+ I(g.zIndex);
106
116
  }, 200));
107
- }, [n]), O(() => {
108
- a === void 0 || t === f || a(f);
109
- }, [f]), O(() => {
110
- t === void 0 || t === f || n.toggleNode(r, t);
111
- }, [t]), !l || !C ? null : B(/* @__PURE__ */ k(F, { children: /* @__PURE__ */ k(
117
+ }, [s]), i ? A(/* @__PURE__ */ k(
112
118
  "section",
113
119
  {
114
120
  id: r,
115
- className: S("fkw-popup-layer", f && "fkw-popup-layer--open", u),
116
- style: { zIndex: 1e4 + T, cursor: o.exitOnDocument && !o.preventStateChange ? "pointer" : "auto", ...c },
117
- onClick: o.exitOnDocument && !o.preventStateChange ? (w) => n.toggleDocument(r, w) : void 0,
121
+ className: O("fkw-popup-layer", v && "fkw-popup-layer--open", p),
122
+ style: { zIndex: 1e4 + E, cursor: f.exitOnDocument && !f.preventStateChange ? "pointer" : "auto", ...c },
123
+ onClick: f.exitOnDocument && !f.preventStateChange ? (g) => s.toggleDocument(r, g) : void 0,
118
124
  children: /* @__PURE__ */ k(
119
125
  "article",
120
126
  {
121
- className: S("fkw-popup", f && "fkw-popup--open", d && `fkw-popup-animation--${d}`, x),
127
+ className: O("fkw-popup", v && "fkw-popup--open", t && `fkw-popup-animation--${t}`, d),
122
128
  role: "dialog",
123
129
  "aria-modal": !0,
124
- "aria-hidden": !f,
125
- ...p,
126
- children: M && s
130
+ "aria-hidden": !v,
131
+ ...a,
132
+ children: o
127
133
  }
128
134
  )
129
135
  }
130
- ) }), C);
131
- }, $ = ({ children: s, as: x, className: u, onClick: c, disabled: r, popupId: e, ...t }) => {
132
- const a = z(h), g = x ?? "button", [y, v] = m(!1);
133
- O(() => {
134
- const p = a.nodes.find((n) => n.id === e);
135
- p && v(p.open);
136
- }, [a]);
137
- function i(p) {
138
- a.toggleNode(e), c && c(p);
136
+ ), i) : null;
137
+ }, R = ({ children: o, as: d, className: p, onClick: c, disabled: r, popupId: e, ...n }) => {
138
+ const u = P(h), [m, w] = x(!1), y = d ?? "button";
139
+ S(() => {
140
+ const s = u.nodes.find((t) => t.id === e);
141
+ s && w(s.open);
142
+ }, [u]);
143
+ function a(s) {
144
+ u.toggleNode(e), c && c(s);
139
145
  }
140
- return /* @__PURE__ */ k(g, { className: S("fkw-popup-button", y && "fkw-popup-button--active", u), role: "button", onClick: i, "aria-haspopup": "dialog", tabIndex: 0, disabled: r, "aria-disabled": r, "data-fkw-popup-operator": e, "aria-label": y ? "Close Popup" : "Open Popup", ...t, children: s });
146
+ return /* @__PURE__ */ k(y, { className: O("fkw-popup-button", m && "fkw-popup-button--active", p), role: "button", onClick: a, "aria-haspopup": "dialog", tabIndex: 0, disabled: r, "aria-disabled": r, "data-fkw-popup-operator": e, "aria-label": m ? "Close Popup" : "Open Popup", ...n, children: o });
141
147
  };
142
- function E(s, x) {
143
- const u = { ...x };
144
- for (const c in s)
145
- u[c] = s[c];
146
- return u;
148
+ function z(o, d) {
149
+ const p = { ...d };
150
+ for (const c in o)
151
+ p[c] = o[c];
152
+ return p;
147
153
  }
148
- const X = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
154
+ const H = /* @__PURE__ */ Object.freeze(/* @__PURE__ */ Object.defineProperty({
149
155
  __proto__: null,
150
- PopupButton: $,
151
- PopupLayer: V,
152
- PopupWindow: W
156
+ PopupButton: R,
157
+ PopupLayer: G,
158
+ PopupWindow: K
153
159
  }, Symbol.toStringTag, { value: "Module" }));
154
160
  export {
155
- $ as PopupButton,
156
- V as PopupLayer,
157
- W as PopupWindow,
158
- X as default
161
+ R as PopupButton,
162
+ G as PopupLayer,
163
+ K as PopupWindow,
164
+ H as default
159
165
  };
160
166
  //# sourceMappingURL=index.es.js.map
@@ -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;A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BAAoBgC,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/useMixedState.ts","../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","'use client';\r\n\r\nimport { useState } from 'react';\r\nimport { StateSetter } from './Interfaces';\r\n\r\n\r\n\r\nexport default function useMixedState<S = undefined>(): [S | undefined, StateSetter<S | undefined>];\r\nexport default function useMixedState<S>(initialState: S | (() => S)): [S, StateSetter<S>];\r\nexport default function useMixedState<S>(state: S, setter?: StateSetter<S>): [S, StateSetter<S>];\r\n\r\n\r\n\r\n/** \r\n * Use mixed state hook\r\n * \r\n * @param initialStateOrValue Initial state, can be undefined, value or function. If externalSetter not specified, will return default state\r\n * @param externalSetter External state setter. If specified will return external state\r\n */\r\nexport default function useMixedState<S>(initialStateOrValue?: S | (() => S), externalSetter?: StateSetter<S>) {\r\n const isControlled = arguments.length === 2 && externalSetter !== undefined;\r\n\r\n const [defaultState, defaultSetter] = useState<S | undefined>(initialStateOrValue);\r\n\r\n\r\n\r\n if (isControlled) {\r\n return [\r\n initialStateOrValue as S,\r\n externalSetter as StateSetter<S>\r\n ];\r\n }\r\n\r\n return [defaultState, defaultSetter];\r\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 state = useMemo(() => state ?? false, []);\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] = useMixedState(state, stateSetter);\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: state,\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 }, [isOpen]);\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\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","useMixedState","initialStateOrValue","externalSetter","isControlled","defaultState","defaultSetter","useState","DEFAULT_SETTINGS","PopupContext","createContext","PopupLayer","className","initialSettings","children","props","settings","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","useMemo","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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AAWvE,KAAOsE;AACR,IAAAE,EAAAxE,CAAG,IAAIsE,EAAOtE,CAAG;AAGpB,SAAAwE;AACT;;;;;;;","x_google_ignoreList":[0]}
package/dist/index.umd.js CHANGED
@@ -1,6 +1,6 @@
1
- (function(c,d){typeof exports=="object"&&typeof module<"u"?d(exports,require("react/jsx-runtime"),require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","react-dom"],d):(c=typeof globalThis<"u"?globalThis:c||self,d(c["@fullkekw/fkw-popup"]={},c.ReactJsxRuntime,c.React,c.ReactDOM))})(this,function(c,d,s,T){"use strict";function _(r){return r&&r.__esModule&&Object.prototype.hasOwnProperty.call(r,"default")?r.default:r}var h={exports:{}};/*!
1
+ (function(l,x){typeof exports=="object"&&typeof module<"u"?x(exports,require("react/jsx-runtime"),require("react"),require("react-dom")):typeof define=="function"&&define.amd?define(["exports","react/jsx-runtime","react","react-dom"],x):(l=typeof globalThis<"u"?globalThis:l||self,x(l["@fullkekw/fkw-popup"]={},l.ReactJsxRuntime,l.React,l.ReactDOM))})(this,function(l,x,i,D){"use strict";function M(o){return o&&o.__esModule&&Object.prototype.hasOwnProperty.call(o,"default")?o.default:o}var O={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 I;function L(){return I||(I=1,function(r){(function(){var w={}.hasOwnProperty;function a(){for(var e="",n=0;n<arguments.length;n++){var p=arguments[n];p&&(e=i(e,l(p)))}return e}function l(e){if(typeof e=="string"||typeof e=="number")return e;if(typeof e!="object")return"";if(Array.isArray(e))return a.apply(null,e);if(e.toString!==Object.prototype.toString&&!e.toString.toString().includes("[native code]"))return e.toString();var n="";for(var p in e)w.call(e,p)&&e[p]&&(n=i(n,p));return n}function i(e,n){return n?e?e+" "+n:e+n:e}r.exports?(a.default=a,r.exports=a):window.classNames=a})()}(h)),h.exports}var q=L();const O=_(q),P={disableScroll:!0,exitOnDocument:!0,exitOnEscape:!0,preventStateChange:!1},b=s.createContext({}),E=({className:r,settings:w,children:a,...l})=>{const[i]=s.useState(j(w??{},P)),[e,n]=s.useState([]),p={nodes:e,toggleNode:y,registerNode:v,toggleDocument:k};s.useEffect(()=>{if(typeof window>"u")return;window.addEventListener("keydown",u);function u(f){if(f.key==="Escape"){const x=Math.max(...e.filter(g=>g.open).map(g=>g.zIndex)),o=e.find(g=>g.open&&g.zIndex===x);if(!o||!o.settings.exitOnEscape||!(i!=null&&i.exitOnEscape))return;y(o.id)}}return()=>{window.removeEventListener("keydown",u)}},[e]);function y(u,f){let t;if(typeof u=="string"?t={...e.find(o=>o.id===u)}:t={...u},!t.id)return;if((i.preventStateChange||t.settings.preventStateChange)&&f===void 0)return console.warn("Popup action prevented");const x=f??!(t!=null&&t.open);t.open=x,t.zIndex=x?Math.max(...e.map(o=>o.zIndex),0)+1:0,n(o=>[...o.filter(g=>g.id!==t.id),t]),i.disableScroll&&t.settings.disableScroll&&x&&document.body.classList.add("fkw-popup--noScroll"),!x&&!e.filter(o=>o.id!==t.id).some(o=>o.open)&&document.body.classList.remove("fkw-popup--noScroll")}function v(u){n(f=>[...f,u]),u.open&&y(u,!0)}function k(u,f){const t={...e.find(o=>o.id===u)};!t.id||!t.settings.exitOnDocument||f.target.closest(".fkw-popup")||!t.settings.exitOnDocument||!i.exitOnDocument||y(t.id)}return d.jsxs(b.Provider,{value:p,children:[a,d.jsx("section",{className:O("fkw-popup-container",r),id:"fkw-popup-container",...l})]})},C=({children:r,className:w,layerClassName:a,style:l,id:i,settings:e,isOpen:n,setIsOpen:p,animation:y,renderOnDemand:v,onExit:k,onOpen:u,...f})=>{const t=s.useContext(b),[x]=s.useState(y??"scale"),[o]=s.useState(j(e??{},P)),[g,F]=s.useState(!1),[B,z]=s.useState(!1),[D,W]=s.useState(null),[m,Z]=s.useState(!1),[G,M]=s.useState(0);return s.useMemo(()=>{v?m&&z(!0):z(!0),m&&u&&u(),!m&&k&&k()},[m]),s.useEffect(()=>{W(document.querySelector("#fkw-popup-container")),F(!0),t.registerNode({id:i,open:!1,zIndex:0,settings:o})},[]),s.useEffect(()=>{const S=t.nodes.find(J=>J.id===i);S&&(Z(S.open),S.zIndex!==0?M(S.zIndex):setTimeout(()=>{M(S.zIndex)},200))},[t]),s.useEffect(()=>{p===void 0||n===m||p(m)},[m]),s.useEffect(()=>{n===void 0||n===m||t.toggleNode(i,n)},[n]),!g||!D?null:T.createPortal(d.jsx(d.Fragment,{children:d.jsx("section",{id:i,className:O("fkw-popup-layer",m&&"fkw-popup-layer--open",a),style:{zIndex:1e4+G,cursor:o.exitOnDocument&&!o.preventStateChange?"pointer":"auto",...l},onClick:o.exitOnDocument&&!o.preventStateChange?S=>t.toggleDocument(i,S):void 0,children:d.jsx("article",{className:O("fkw-popup",m&&"fkw-popup--open",x&&`fkw-popup-animation--${x}`,w),role:"dialog","aria-modal":!0,"aria-hidden":!m,...f,children:B&&r})})}),D)},N=({children:r,as:w,className:a,onClick:l,disabled:i,popupId:e,...n})=>{const p=s.useContext(b),y=w??"button",[v,k]=s.useState(!1);s.useEffect(()=>{const f=p.nodes.find(t=>t.id===e);f&&k(f.open)},[p]);function u(f){p.toggleNode(e),l&&l(f)}return d.jsx(y,{className:O("fkw-popup-button",v&&"fkw-popup-button--active",a),role:"button",onClick:u,"aria-haspopup":"dialog",tabIndex:0,disabled:i,"aria-disabled":i,"data-fkw-popup-operator":e,"aria-label":v?"Close Popup":"Open Popup",...n,children:r})};function j(r,w){const a={...w};for(const l in r)a[l]=r[l];return a}const A=Object.freeze(Object.defineProperty({__proto__:null,PopupButton:N,PopupLayer:E,PopupWindow:C},Symbol.toStringTag,{value:"Module"}));c.PopupButton=N,c.PopupLayer=E,c.PopupWindow=C,c.default=A,Object.defineProperties(c,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
5
+ */var P;function T(){return P||(P=1,function(o){(function(){var m={}.hasOwnProperty;function p(){for(var e="",n=0;n<arguments.length;n++){var c=arguments[n];c&&(e=s(e,f(c)))}return e}function f(e){if(typeof e=="string"||typeof e=="number")return e;if(typeof e!="object")return"";if(Array.isArray(e))return p.apply(null,e);if(e.toString!==Object.prototype.toString&&!e.toString.toString().includes("[native code]"))return e.toString();var n="";for(var c in e)m.call(e,c)&&e[c]&&(n=s(n,c));return n}function s(e,n){return n?e?e+" "+n:e+n:e}o.exports?(p.default=p,o.exports=p):window.classNames=p})()}(O)),O.exports}var _=T();const h=M(_);function L(o,m){const p=arguments.length===2&&m!==void 0,[f,s]=i.useState(o);return p?[o,m]:[f,s]}const C={disableScroll:!0,exitOnDocument:!0,exitOnEscape:!0,preventStateChange:!1},b=i.createContext({}),I=({className:o,settings:m,children:p,...f})=>{const[s]=i.useState(N(m??{},C)),[e,n]=i.useState([]),c={nodes:e,toggleNode:g,registerNode:y,toggleDocument:v};i.useEffect(()=>{if(typeof window>"u")return;window.addEventListener("keydown",a);function a(r){if(r.key==="Escape"){const d=Math.max(...e.filter(S=>S.open).map(S=>S.zIndex)),u=e.find(S=>S.open&&S.zIndex===d);if(!u||!u.settings.exitOnEscape||!(s!=null&&s.exitOnEscape))return;g(u.id)}}return()=>{window.removeEventListener("keydown",a)}},[e]);function g(a,r){let t;if(typeof a=="string"?t={...e.find(u=>u.id===a)}:t={...a},!t.id)return;if((s.preventStateChange||t.settings.preventStateChange)&&r===void 0)return console.warn("Popup action prevented");const d=r??!(t!=null&&t.open);t.open=d,t.zIndex=d?Math.max(...e.map(u=>u.zIndex),0)+1:0,n(u=>[...u.filter(S=>S.id!==t.id),t]),s.disableScroll&&t.settings.disableScroll&&d&&document.body.classList.add("fkw-popup--noScroll"),!d&&!e.filter(u=>u.id!==t.id).some(u=>u.open)&&document.body.classList.remove("fkw-popup--noScroll")}function y(a){n(r=>[...r,a]),a.open&&g(a,!0)}function v(a,r){const t={...e.find(u=>u.id===a)};!t.id||!t.settings.exitOnDocument||r.target.closest(".fkw-popup")||!t.settings.exitOnDocument||!s.exitOnDocument||g(t.id)}return x.jsx(i.Suspense,{children:x.jsxs(b.Provider,{value:c,children:[p,x.jsx("section",{className:h("fkw-popup-container",o),id:"fkw-popup-container",...f})]})})},E=({children:o,className:m,layerClassName:p,style:f,id:s,settings:e,isOpen:n,setIsOpen:c,animation:g,onExit:y,onOpen:v,...a})=>{const r=i.useContext(b);n=i.useMemo(()=>n??!1,[]);const[t]=i.useState(g??"scale"),[d]=i.useState(N(e??{},C)),[u,S]=i.useState(null),[k,A]=L(n,c),[B,z]=i.useState(0);return i.useEffect(()=>{S(document.querySelector("#fkw-popup-container")),r.registerNode({id:s,open:n,zIndex:0,settings:d})},[]),i.useEffect(()=>{k&&v&&v(),!k&&y&&y()},[k]),i.useEffect(()=>{const w=r.nodes.find(F=>F.id===s);w&&(A(w.open),w.zIndex!==0?z(w.zIndex):setTimeout(()=>{z(w.zIndex)},200))},[r]),u?D.createPortal(x.jsx("section",{id:s,className:h("fkw-popup-layer",k&&"fkw-popup-layer--open",p),style:{zIndex:1e4+B,cursor:d.exitOnDocument&&!d.preventStateChange?"pointer":"auto",...f},onClick:d.exitOnDocument&&!d.preventStateChange?w=>r.toggleDocument(s,w):void 0,children:x.jsx("article",{className:h("fkw-popup",k&&"fkw-popup--open",t&&`fkw-popup-animation--${t}`,m),role:"dialog","aria-modal":!0,"aria-hidden":!k,...a,children:o})}),u):null},j=({children:o,as:m,className:p,onClick:f,disabled:s,popupId:e,...n})=>{const c=i.useContext(b),[g,y]=i.useState(!1),v=m??"button";i.useEffect(()=>{const r=c.nodes.find(t=>t.id===e);r&&y(r.open)},[c]);function a(r){c.toggleNode(e),f&&f(r)}return x.jsx(v,{className:h("fkw-popup-button",g&&"fkw-popup-button--active",p),role:"button",onClick:a,"aria-haspopup":"dialog",tabIndex:0,disabled:s,"aria-disabled":s,"data-fkw-popup-operator":e,"aria-label":g?"Close Popup":"Open Popup",...n,children:o})};function N(o,m){const p={...m};for(const f in o)p[f]=o[f];return p}const q=Object.freeze(Object.defineProperty({__proto__:null,PopupButton:j,PopupLayer:I,PopupWindow:E},Symbol.toStringTag,{value:"Module"}));l.PopupButton=j,l.PopupLayer=I,l.PopupWindow=E,l.default=q,Object.defineProperties(l,{__esModule:{value:!0},[Symbol.toStringTag]:{value:"Module"}})});
6
6
  //# sourceMappingURL=index.umd.js.map
@@ -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,WAAa,OAAO,UAAU,UAAY,CAACA,EAAI,SAAS,SAAQ,EAAG,SAAS,eAAe,EAClG,OAAOA,EAAI,SAAU,EAGtB,IAAIF,EAAU,GAEd,QAASK,KAAOH,EACXJ,EAAO,KAAKI,EAAKG,CAAG,GAAKH,EAAIG,CAAG,IACnCL,EAAUG,EAAYH,EAASK,CAAG,GAIpC,OAAOL,CACT,CAEC,SAASG,EAAaG,EAAOC,EAAU,CACtC,OAAKA,EAIDD,EACIA,EAAQ,IAAMC,EAGfD,EAAQC,EAPPD,CAQV,CAEsCE,EAAO,SAC3CT,EAAW,QAAUA,EACrBS,UAAiBT,GAOjB,OAAO,WAAa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oB,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/useMixedState.ts","../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","'use client';\r\n\r\nimport { useState } from 'react';\r\nimport { StateSetter } from './Interfaces';\r\n\r\n\r\n\r\nexport default function useMixedState<S = undefined>(): [S | undefined, StateSetter<S | undefined>];\r\nexport default function useMixedState<S>(initialState: S | (() => S)): [S, StateSetter<S>];\r\nexport default function useMixedState<S>(state: S, setter?: StateSetter<S>): [S, StateSetter<S>];\r\n\r\n\r\n\r\n/** \r\n * Use mixed state hook\r\n * \r\n * @param initialStateOrValue Initial state, can be undefined, value or function. If externalSetter not specified, will return default state\r\n * @param externalSetter External state setter. If specified will return external state\r\n */\r\nexport default function useMixedState<S>(initialStateOrValue?: S | (() => S), externalSetter?: StateSetter<S>) {\r\n const isControlled = arguments.length === 2 && externalSetter !== undefined;\r\n\r\n const [defaultState, defaultSetter] = useState<S | undefined>(initialStateOrValue);\r\n\r\n\r\n\r\n if (isControlled) {\r\n return [\r\n initialStateOrValue as S,\r\n externalSetter as StateSetter<S>\r\n ];\r\n }\r\n\r\n return [defaultState, defaultSetter];\r\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 state = useMemo(() => state ?? false, []);\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] = useMixedState(state, stateSetter);\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: state,\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 }, [isOpen]);\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\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","useMixedState","initialStateOrValue","externalSetter","isControlled","defaultState","defaultSetter","useState","DEFAULT_SETTINGS","PopupContext","createContext","PopupLayer","className","initialSettings","children","props","settings","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","useMemo","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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ACUqC,CAAS,EAjBE,IAkBzB,EAOaO,EAAqC,CAAC,CAAE,SAAA5C,EAAU,GAAA6C,EAAI,UAAA/C,EAAW,QAAAgD,EAAS,SAAAC,EAAU,QAAAC,EAAS,GAAG/C,KAAY,CACjH,MAAAgC,EAAMC,aAAWvC,CAAY,EAE7B,CAACsD,EAAUC,CAAW,EAAIzD,EAAAA,SAAkB,EAAK,EAEjD0D,EAAmCN,GAAM,SAK/CnC,EAAAA,UAAU,IAAM,CACd,MAAMK,EAAOkB,EAAI,MAAM,KAAWnB,GAAAA,EAAG,KAAOkC,CAAO,EAC9CjC,GAELmC,EAAYnC,EAAK,IAAI,CAAA,EACpB,CAACkB,CAAG,CAAC,EAIR,SAASmB,EAAOxC,EAAqB,CACnCqB,EAAI,WAAWe,CAAO,EACtBF,GAAWA,EAAQlC,CAAC,CAAA,CAKtB,OAAQW,EAAA,IAAA4B,EAAA,CAAI,UAAW3B,EAAG,mBAAoByB,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,SAASG,EAAekD,EAAgBC,EAAoB,CACpD,MAAAC,EAAU,CAAE,GAAGD,CAAW,EAEhC,UAAWvE,KAAOsE,EACRE,EAAAxE,CAAG,EAAIsE,EAAOtE,CAAG,EAGpB,OAAAwE,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>];
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@fullkekw/popup",
3
- "version": "2.0.9",
3
+ "version": "2.0.10",
4
4
  "description": "React Popup component written on Typescript. Compatible with NextJS & Vite!",
5
5
  "keywords": [
6
6
  "fkw",