@alphakits/ui 2.5.5 → 2.5.7
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,16 +1,16 @@
|
|
|
1
1
|
import { jsxs as E, jsx as l } from "react/jsx-runtime";
|
|
2
2
|
import O from "@alphakits/icons/dist/CloseM";
|
|
3
3
|
import C from "classnames";
|
|
4
|
-
import { useState as L, useRef as w, useLayoutEffect as N, useEffect as
|
|
4
|
+
import { useState as L, useRef as w, useLayoutEffect as N, useEffect as S, useCallback as k } from "react";
|
|
5
5
|
import { Button as z } from "../../../button/component.js";
|
|
6
6
|
import { showConfirm as j } from "../../../confirm-popup/component.js";
|
|
7
|
-
import { useMatchMedia as
|
|
7
|
+
import { useMatchMedia as q } from "../../../mq/use-match-media.js";
|
|
8
8
|
import s from "./index.module.css.js";
|
|
9
|
-
const
|
|
9
|
+
const T = {
|
|
10
10
|
s: 488,
|
|
11
11
|
m: 888,
|
|
12
12
|
full: "96%"
|
|
13
|
-
},
|
|
13
|
+
}, A = 102, B = "(max-width: 823px)", D = (t) => t === "full" ? `calc(-96vw - ${A}px)` : -T[t] - A, K = [
|
|
14
14
|
'a[href]:not([tabindex="-1"])',
|
|
15
15
|
'area[href]:not([tabindex="-1"])',
|
|
16
16
|
'button:not([disabled]):not([tabindex="-1"])',
|
|
@@ -25,76 +25,84 @@ const R = {
|
|
|
25
25
|
'audio[controls]:not([tabindex="-1"])',
|
|
26
26
|
'video[controls]:not([tabindex="-1"])',
|
|
27
27
|
'details > summary:first-of-type:not([tabindex="-1"])'
|
|
28
|
-
].join(","), F = (
|
|
28
|
+
].join(","), F = (t) => t ? Array.from(t.querySelectorAll(K)).filter((r) => {
|
|
29
29
|
if (r.hidden || r.getAttribute("aria-hidden") === "true") return !1;
|
|
30
30
|
const a = window.getComputedStyle(r);
|
|
31
31
|
return a.visibility === "hidden" || a.display === "none" ? !1 : r.offsetWidth > 0 || r.offsetHeight > 0 || r.getClientRects().length > 0;
|
|
32
|
-
}) : [],
|
|
33
|
-
|
|
32
|
+
}) : [], P = (t) => {
|
|
33
|
+
if (t.hasAttribute("data-modal-no-autofocus") || t.hasAttribute("aria-haspopup") || t.hasAttribute("aria-autocomplete")) return !0;
|
|
34
|
+
const n = t.getAttribute("role");
|
|
35
|
+
return !!(n === "combobox" || n === "listbox" || t.querySelector('[role="combobox"],[aria-haspopup],[aria-autocomplete]'));
|
|
36
|
+
}, _ = (t) => {
|
|
37
|
+
if (!t) return null;
|
|
38
|
+
const n = t.querySelector("[data-modal-autofocus]");
|
|
39
|
+
return n || F(t).find((d) => !P(d)) || t;
|
|
40
|
+
}, J = ({ modal: t, t: n, index: r, dirtyModals: a, closeModal: d, currentModalId: u }) => {
|
|
41
|
+
const R = D(t.props.size), [m] = q(B), [p, h] = L(!1), c = w(null), x = w(null);
|
|
34
42
|
N(() => {
|
|
35
|
-
const o = requestAnimationFrame(() =>
|
|
43
|
+
const o = requestAnimationFrame(() => h(!0));
|
|
36
44
|
return () => cancelAnimationFrame(o);
|
|
37
|
-
}, [
|
|
38
|
-
if (
|
|
45
|
+
}, [t.id]), S(() => {
|
|
46
|
+
if (t.id !== u) return;
|
|
39
47
|
x.current = document.activeElement || null;
|
|
40
48
|
const o = setTimeout(() => {
|
|
41
|
-
const
|
|
42
|
-
|
|
49
|
+
const e = _(c.current);
|
|
50
|
+
e && typeof e.focus == "function" && e.focus({ preventScroll: !0 });
|
|
43
51
|
}, 50);
|
|
44
52
|
return () => {
|
|
45
53
|
clearTimeout(o);
|
|
46
|
-
const
|
|
47
|
-
if (!
|
|
48
|
-
const
|
|
49
|
-
if (
|
|
54
|
+
const e = document.activeElement;
|
|
55
|
+
if (!e || !c.current?.contains(e)) return;
|
|
56
|
+
const i = x.current;
|
|
57
|
+
if (i && typeof i.focus == "function" && document.body.contains(i))
|
|
50
58
|
try {
|
|
51
|
-
|
|
59
|
+
i.focus({ preventScroll: !0 });
|
|
52
60
|
} catch {
|
|
53
61
|
document.body.focus();
|
|
54
62
|
}
|
|
55
63
|
};
|
|
56
|
-
}, [
|
|
57
|
-
const
|
|
64
|
+
}, [t.id, u]);
|
|
65
|
+
const y = k(
|
|
58
66
|
(o) => a[o] ? j({
|
|
59
|
-
title:
|
|
60
|
-
confirmText:
|
|
61
|
-
cancelText:
|
|
67
|
+
title: n("common:exitConfirm"),
|
|
68
|
+
confirmText: n("common:Да"),
|
|
69
|
+
cancelText: n("common:Нет"),
|
|
62
70
|
confirmView: "negative"
|
|
63
71
|
}) : Promise.resolve(!0),
|
|
64
72
|
// eslint-disable-next-line react-hooks/exhaustive-deps
|
|
65
|
-
[a,
|
|
66
|
-
), f =
|
|
73
|
+
[a, n]
|
|
74
|
+
), f = k(
|
|
67
75
|
async (o) => {
|
|
68
|
-
const { id:
|
|
69
|
-
await
|
|
70
|
-
|
|
76
|
+
const { id: e } = t;
|
|
77
|
+
await y(o || e) && (h(!1), setTimeout(() => {
|
|
78
|
+
t.props.closeCallback && t.props.closeCallback(), d(o || e);
|
|
71
79
|
}, 250));
|
|
72
80
|
},
|
|
73
|
-
[
|
|
81
|
+
[d, y, t]
|
|
74
82
|
);
|
|
75
|
-
return
|
|
76
|
-
const o = (
|
|
77
|
-
if (
|
|
83
|
+
return S(() => {
|
|
84
|
+
const o = (e) => {
|
|
85
|
+
if (e.key === "27" || e.key === "Escape") {
|
|
78
86
|
f(u);
|
|
79
87
|
return;
|
|
80
88
|
}
|
|
81
|
-
if (
|
|
82
|
-
const
|
|
83
|
-
if (!
|
|
84
|
-
|
|
89
|
+
if (e.key !== "Tab") return;
|
|
90
|
+
const i = F(c.current);
|
|
91
|
+
if (!i.length) {
|
|
92
|
+
e.preventDefault(), c.current && c.current.focus({ preventScroll: !0 });
|
|
85
93
|
return;
|
|
86
94
|
}
|
|
87
|
-
const
|
|
88
|
-
if (
|
|
89
|
-
|
|
95
|
+
const g = i[0], v = i[i.length - 1], b = document.activeElement;
|
|
96
|
+
if (e.shiftKey && (b === g || !c.current?.contains(b))) {
|
|
97
|
+
e.preventDefault(), v.focus({ preventScroll: !0 });
|
|
90
98
|
return;
|
|
91
99
|
}
|
|
92
|
-
!
|
|
100
|
+
!e.shiftKey && (b === v || !c.current?.contains(b)) && (e.preventDefault(), g.focus({ preventScroll: !0 }));
|
|
93
101
|
};
|
|
94
|
-
return
|
|
102
|
+
return t.id === u && window?.addEventListener("keydown", o), () => {
|
|
95
103
|
window?.removeEventListener("keydown", o);
|
|
96
104
|
};
|
|
97
|
-
}, [f, u,
|
|
105
|
+
}, [f, u, t.id]), /* @__PURE__ */ E(
|
|
98
106
|
"div",
|
|
99
107
|
{
|
|
100
108
|
className: s.container,
|
|
@@ -105,30 +113,30 @@ const R = {
|
|
|
105
113
|
/* @__PURE__ */ l(
|
|
106
114
|
"div",
|
|
107
115
|
{
|
|
108
|
-
ref:
|
|
116
|
+
ref: c,
|
|
109
117
|
className: C(s.right, s.content, {
|
|
110
118
|
[s.open]: p,
|
|
111
|
-
[s.bottomSheet]:
|
|
119
|
+
[s.bottomSheet]: m
|
|
112
120
|
}),
|
|
113
121
|
style: {
|
|
114
122
|
zIndex: 9999999 + r,
|
|
115
|
-
width:
|
|
123
|
+
width: T[t.props.size],
|
|
116
124
|
// На десктопе right-slide управляется JS-ом (старая
|
|
117
125
|
// схема — анимация ширины и right'а синхронны). На
|
|
118
126
|
// мобиле right=0 всегда, а появление контролируется
|
|
119
127
|
// CSS (.bottomSheet.open → top: 0).
|
|
120
|
-
right:
|
|
128
|
+
right: m || p ? 0 : R
|
|
121
129
|
},
|
|
122
130
|
role: "dialog",
|
|
123
131
|
"aria-modal": "true",
|
|
124
|
-
"aria-labelledby": `modal-title-${
|
|
132
|
+
"aria-labelledby": `modal-title-${t.id}`,
|
|
125
133
|
tabIndex: -1,
|
|
126
134
|
children: /* @__PURE__ */ E("div", { className: s.inner, children: [
|
|
127
135
|
/* @__PURE__ */ l(
|
|
128
|
-
|
|
136
|
+
t.modal,
|
|
129
137
|
{
|
|
130
|
-
...
|
|
131
|
-
modalId:
|
|
138
|
+
...t.props,
|
|
139
|
+
modalId: t.id,
|
|
132
140
|
close: () => f()
|
|
133
141
|
}
|
|
134
142
|
),
|
|
@@ -136,7 +144,7 @@ const R = {
|
|
|
136
144
|
z,
|
|
137
145
|
{
|
|
138
146
|
className: C(s.button, {
|
|
139
|
-
[s.doubleModal]:
|
|
147
|
+
[s.doubleModal]: t.props.isDouble
|
|
140
148
|
}),
|
|
141
149
|
view: "secondary",
|
|
142
150
|
size: "xs",
|
|
@@ -161,5 +169,5 @@ const R = {
|
|
|
161
169
|
);
|
|
162
170
|
};
|
|
163
171
|
export {
|
|
164
|
-
|
|
172
|
+
J as Modal
|
|
165
173
|
};
|
|
@@ -1,68 +1,70 @@
|
|
|
1
|
-
import { jsx as
|
|
2
|
-
import
|
|
3
|
-
import { createRoot as
|
|
4
|
-
import { ToastPlate as
|
|
5
|
-
import
|
|
6
|
-
import { createTimer as
|
|
7
|
-
let
|
|
8
|
-
typeof window < "u" && (
|
|
9
|
-
const
|
|
10
|
-
className:
|
|
11
|
-
children:
|
|
1
|
+
import { jsx as y } from "react/jsx-runtime";
|
|
2
|
+
import w from "classnames";
|
|
3
|
+
import { createRoot as E } from "react-dom/client";
|
|
4
|
+
import { ToastPlate as $ } from "../toast-plate/component.js";
|
|
5
|
+
import t from "./index.module.css.js";
|
|
6
|
+
import { createTimer as A } from "./use-timer.js";
|
|
7
|
+
let o;
|
|
8
|
+
typeof window < "u" && (o = document.createElement("div"), o.setAttribute("id", "toast_manager"), document.body.appendChild(o));
|
|
9
|
+
const R = ({
|
|
10
|
+
className: d,
|
|
11
|
+
children: L,
|
|
12
12
|
offset: n = 108,
|
|
13
|
-
hasCloser:
|
|
14
|
-
onClose:
|
|
15
|
-
text:
|
|
16
|
-
onMouseEnter:
|
|
17
|
-
onMouseLeave:
|
|
18
|
-
style:
|
|
19
|
-
position:
|
|
20
|
-
delay:
|
|
21
|
-
...
|
|
13
|
+
hasCloser: u = !0,
|
|
14
|
+
onClose: M,
|
|
15
|
+
text: c,
|
|
16
|
+
onMouseEnter: T,
|
|
17
|
+
onMouseLeave: N,
|
|
18
|
+
style: p,
|
|
19
|
+
position: f = "bottom",
|
|
20
|
+
delay: v = 3e3,
|
|
21
|
+
...x
|
|
22
22
|
}) => {
|
|
23
23
|
if (typeof window > "u") return null;
|
|
24
|
-
const r = window.innerWidth > 600,
|
|
25
|
-
const
|
|
26
|
-
return r ? `${
|
|
24
|
+
const r = window.innerWidth > 600, b = () => {
|
|
25
|
+
const m = "position: fixed; z-index: 999999999;";
|
|
26
|
+
return r ? `${m} ${f}: ${n}px; right: 30px` : `${m} top: ${n}px; right: 30px; left: 30px`;
|
|
27
27
|
};
|
|
28
|
-
|
|
29
|
-
const
|
|
30
|
-
|
|
31
|
-
const
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
}),
|
|
41
|
-
|
|
42
|
-
|
|
28
|
+
o.setAttribute("style", b());
|
|
29
|
+
const e = document.createElement("div");
|
|
30
|
+
e.classList.remove(t.isClosing), e.setAttribute("id", `toast_wrap-${Math.random()}`), e.setAttribute("style", "margin-bottom: 18px"), o.appendChild(e);
|
|
31
|
+
const s = E(e);
|
|
32
|
+
let i = !1, a;
|
|
33
|
+
const l = () => {
|
|
34
|
+
i || (i = !0, a?.(), e.classList.add(t.isClosing), setTimeout(() => {
|
|
35
|
+
s.unmount(), e.remove();
|
|
36
|
+
}, 300));
|
|
37
|
+
}, { pause: h, resume: C, cancel: g } = A(l, v);
|
|
38
|
+
return a = g, e.addEventListener("mouseenter", () => {
|
|
39
|
+
h();
|
|
40
|
+
}), e.addEventListener("mouseleave", () => {
|
|
41
|
+
C();
|
|
42
|
+
}), s.render(
|
|
43
|
+
/* @__PURE__ */ y(
|
|
44
|
+
$,
|
|
43
45
|
{
|
|
44
|
-
hasCloser:
|
|
45
|
-
className:
|
|
46
|
+
hasCloser: u,
|
|
47
|
+
className: w(
|
|
46
48
|
{
|
|
47
|
-
[
|
|
48
|
-
[
|
|
49
|
+
[t.isVisible]: !0,
|
|
50
|
+
[t.mobile]: !r
|
|
49
51
|
},
|
|
50
|
-
|
|
52
|
+
d
|
|
51
53
|
),
|
|
52
|
-
contentClassName:
|
|
54
|
+
contentClassName: t.toastContent,
|
|
53
55
|
style: {
|
|
54
56
|
right: 0,
|
|
55
57
|
position: "relative",
|
|
56
|
-
...
|
|
58
|
+
...p
|
|
57
59
|
},
|
|
58
60
|
role: "alert",
|
|
59
|
-
onClose:
|
|
60
|
-
...
|
|
61
|
-
children:
|
|
61
|
+
onClose: l,
|
|
62
|
+
...x,
|
|
63
|
+
children: c
|
|
62
64
|
}
|
|
63
65
|
)
|
|
64
66
|
), null;
|
|
65
67
|
};
|
|
66
68
|
export {
|
|
67
|
-
|
|
69
|
+
R as ToastNotifier
|
|
68
70
|
};
|