gd-design-library 1.2.0 → 1.2.1
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,36 +1,36 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { jsxs as
|
|
3
|
-
import { forwardRef as
|
|
4
|
-
import { EMPTY_CLIENT_RECT as
|
|
5
|
-
import { MenuTriggerStyled as
|
|
6
|
-
import { useAnimationFrame as
|
|
7
|
-
import { SelectContext as
|
|
8
|
-
import { convertToInlineBoxStyles as
|
|
9
|
-
import { useTheme as
|
|
10
|
-
import { useLogger as
|
|
11
|
-
import { Portal as
|
|
12
|
-
import { KEYBOARD_KEYS as
|
|
13
|
-
const n = 4,
|
|
14
|
-
onSelect:
|
|
2
|
+
import { jsxs as W, jsx as O } from "@emotion/react/jsx-runtime";
|
|
3
|
+
import { forwardRef as j, useState as x, useRef as y, useCallback as H, useEffect as G, useImperativeHandle as V } from "react";
|
|
4
|
+
import { EMPTY_CLIENT_RECT as q, COMPONENT_NAME as m } from "./constants.js";
|
|
5
|
+
import { MenuTriggerStyled as z, MenuContentStyled as J } from "./MenuStyled.js";
|
|
6
|
+
import { useAnimationFrame as Q } from "../../../utils/animationFrame.js";
|
|
7
|
+
import { SelectContext as Z } from "../Select/hooks/useSelectContext.js";
|
|
8
|
+
import { convertToInlineBoxStyles as ee } from "../../../tokens/utils.js";
|
|
9
|
+
import { useTheme as te } from "../../../hooks/useTheme/useTheme.js";
|
|
10
|
+
import { useLogger as oe } from "../../../hooks/useLogger/useLogger.js";
|
|
11
|
+
import { Portal as ne } from "../Portal/Portal.js";
|
|
12
|
+
import { KEYBOARD_KEYS as re } from "../../../constants/keyboard.js";
|
|
13
|
+
const n = 4, se = 400, ie = 80, le = j(({
|
|
14
|
+
onSelect: v,
|
|
15
15
|
children: A,
|
|
16
16
|
content: Y,
|
|
17
|
-
itemIdentifier: I = (
|
|
17
|
+
itemIdentifier: I = (g, r) => (g == null ? void 0 : g.value) === (r == null ? void 0 : r.value),
|
|
18
18
|
closeOnSelect: M = !0,
|
|
19
19
|
placement: _,
|
|
20
20
|
...$
|
|
21
|
-
},
|
|
21
|
+
}, w) => {
|
|
22
22
|
const {
|
|
23
|
-
theme:
|
|
24
|
-
} =
|
|
23
|
+
theme: g
|
|
24
|
+
} = te(), r = oe(), [l, a] = x(!1), [s, P] = x(), [N, C] = x(), f = y(null), i = y(null), S = y({
|
|
25
25
|
top: 0,
|
|
26
26
|
left: 0
|
|
27
|
-
}),
|
|
27
|
+
}), B = H(({
|
|
28
28
|
width: t,
|
|
29
29
|
height: e
|
|
30
30
|
}) => {
|
|
31
|
-
const o =
|
|
31
|
+
const o = f.current ? f.current.getBoundingClientRect() : q, d = window.innerWidth, E = window.innerHeight, L = window.scrollX || window.pageXOffset || 0, k = window.scrollY || window.pageYOffset || 0, p = _ || "bottom-right";
|
|
32
32
|
let c, u;
|
|
33
|
-
switch (
|
|
33
|
+
switch (p) {
|
|
34
34
|
case "top-left": {
|
|
35
35
|
c = o.left - t, u = o.top - e - n;
|
|
36
36
|
break;
|
|
@@ -48,79 +48,82 @@ const n = 4, te = 400, oe = 80, ne = K(({
|
|
|
48
48
|
break;
|
|
49
49
|
}
|
|
50
50
|
}
|
|
51
|
-
|
|
52
|
-
|
|
51
|
+
const X = c + t > d, K = c < 0;
|
|
52
|
+
(X || K) && (p === "top-left" || p === "bottom-left" ? c = n : c = d - t - n);
|
|
53
|
+
const R = u + e > E, U = u < 0;
|
|
54
|
+
return (R || U) && (p === "top-left" || p === "top-right" ? u = n : u = E - e - n), {
|
|
55
|
+
left: c + L,
|
|
53
56
|
top: u + k
|
|
54
57
|
};
|
|
55
|
-
}, [_]),
|
|
58
|
+
}, [_]), T = H(({
|
|
56
59
|
event: t,
|
|
57
60
|
data: e
|
|
58
61
|
}) => {
|
|
59
62
|
r.debug(`${m}: Select`, {
|
|
60
63
|
value: e == null ? void 0 : e.value,
|
|
61
64
|
name: e == null ? void 0 : e.name,
|
|
62
|
-
previousValue:
|
|
63
|
-
previousName:
|
|
64
|
-
}),
|
|
65
|
+
previousValue: s == null ? void 0 : s.value,
|
|
66
|
+
previousName: s == null ? void 0 : s.name
|
|
67
|
+
}), v == null || v({
|
|
65
68
|
event: t,
|
|
66
69
|
data: e
|
|
67
|
-
}), P(e), M &&
|
|
68
|
-
}, [
|
|
69
|
-
|
|
70
|
+
}), P(e), M && a(!1);
|
|
71
|
+
}, [v, M, s]), F = H(() => {
|
|
72
|
+
a((t) => {
|
|
70
73
|
const e = !t;
|
|
71
74
|
return r.debug(`${m}: ${e ? "Open" : "Close"}`, {
|
|
72
75
|
trigger: "toggle"
|
|
73
76
|
}), e;
|
|
74
77
|
});
|
|
75
78
|
}, []), D = {
|
|
76
|
-
onSelect:
|
|
77
|
-
value:
|
|
79
|
+
onSelect: T,
|
|
80
|
+
value: s,
|
|
78
81
|
itemIdentifier: I
|
|
79
82
|
}, b = (t) => {
|
|
80
83
|
var e;
|
|
81
|
-
((e =
|
|
84
|
+
((e = w == null ? void 0 : w.current) != null && e.isOpen || l) && t.key === re.ESCAPE && (r.debug(`${m}: Close`, {
|
|
82
85
|
trigger: "escape"
|
|
83
|
-
}),
|
|
84
|
-
},
|
|
86
|
+
}), a(!1));
|
|
87
|
+
}, h = (t) => {
|
|
85
88
|
var e, o;
|
|
86
|
-
!((e =
|
|
89
|
+
!((e = f == null ? void 0 : f.current) != null && e.contains(N || t.target)) && !((o = i == null ? void 0 : i.current) != null && o.contains(t.target)) && (r.debug(`${m}: Close`, {
|
|
87
90
|
trigger: "outsideClick"
|
|
88
|
-
}),
|
|
91
|
+
}), a(!1), C(null));
|
|
89
92
|
};
|
|
90
|
-
return
|
|
91
|
-
document.removeEventListener("keydown", b), document.removeEventListener("mousedown",
|
|
92
|
-
}), [l]),
|
|
93
|
-
if (
|
|
94
|
-
const t =
|
|
93
|
+
return G(() => (l ? (document.addEventListener("keydown", b), document.addEventListener("mousedown", h)) : (document.removeEventListener("keydown", b), document.removeEventListener("mousedown", h)), () => {
|
|
94
|
+
document.removeEventListener("keydown", b), document.removeEventListener("mousedown", h);
|
|
95
|
+
}), [l]), Q(() => {
|
|
96
|
+
if (i.current && l) {
|
|
97
|
+
const t = i.current.getBoundingClientRect(), {
|
|
95
98
|
top: e,
|
|
96
99
|
left: o
|
|
97
|
-
} =
|
|
100
|
+
} = B(t), d = window.innerHeight, E = window.scrollY || window.pageYOffset || 0, L = e - E, k = d - L - n, p = Math.max(ie, Math.min(se, k));
|
|
98
101
|
S.current = {
|
|
99
102
|
top: e,
|
|
100
103
|
left: o
|
|
101
|
-
},
|
|
104
|
+
}, i.current && (i.current.style.left = `${o}px`, i.current.style.top = `${e}px`, i.current.style.maxHeight = `${p}px`);
|
|
102
105
|
}
|
|
103
|
-
}),
|
|
104
|
-
ref:
|
|
106
|
+
}), V(w, () => ({
|
|
107
|
+
ref: f,
|
|
105
108
|
isOpen: l,
|
|
106
|
-
selectedValue:
|
|
107
|
-
onSelect:
|
|
109
|
+
selectedValue: s,
|
|
110
|
+
onSelect: T,
|
|
108
111
|
open: (t) => {
|
|
109
112
|
r.debug(`${m}: Open`, {
|
|
110
113
|
trigger: "ref"
|
|
111
|
-
}), !l && (
|
|
114
|
+
}), !l && (C(t || null), a(!0));
|
|
112
115
|
},
|
|
113
116
|
close: (t) => {
|
|
114
117
|
r.debug(`${m}: Close`, {
|
|
115
118
|
trigger: "ref"
|
|
116
|
-
}), l && (
|
|
119
|
+
}), l && (C(t || null), a(!1));
|
|
117
120
|
}
|
|
118
|
-
}), [l,
|
|
119
|
-
/* @__PURE__ */
|
|
120
|
-
l && /* @__PURE__ */
|
|
121
|
+
}), [l, s, T]), /* @__PURE__ */ W(Z.Provider, { value: D, children: [
|
|
122
|
+
/* @__PURE__ */ O(z, { onClick: F, theme: g, ref: f, "data-testid": m, ...$, children: A }),
|
|
123
|
+
l && /* @__PURE__ */ O(ne, { withWrapper: !1, children: /* @__PURE__ */ O(J, { ref: i, "data-testid": m, theme: g, ...ee($), children: Y }) })
|
|
121
124
|
] });
|
|
122
125
|
});
|
|
123
|
-
|
|
126
|
+
le.displayName = m;
|
|
124
127
|
export {
|
|
125
|
-
|
|
128
|
+
le as Menu
|
|
126
129
|
};
|
|
@@ -1,13 +1,15 @@
|
|
|
1
1
|
"use client";
|
|
2
|
-
import { useState as
|
|
2
|
+
import { useState as a, useEffect as c } from "react";
|
|
3
3
|
const o = (e) => {
|
|
4
|
-
const [
|
|
5
|
-
return
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
4
|
+
const [i, n] = a(() => typeof window > "u" ? !1 : window.matchMedia(e).matches);
|
|
5
|
+
return c(() => {
|
|
6
|
+
if (typeof window > "u")
|
|
7
|
+
return;
|
|
8
|
+
const t = window.matchMedia(e), s = (r) => n(r.matches);
|
|
9
|
+
return t.addEventListener("change", s), n(t.matches), () => {
|
|
10
|
+
t.removeEventListener("change", s);
|
|
9
11
|
};
|
|
10
|
-
}, [e]),
|
|
12
|
+
}, [e]), i;
|
|
11
13
|
};
|
|
12
14
|
export {
|
|
13
15
|
o as useMediaQuery
|
|
@@ -3205,8 +3205,8 @@ export declare class NoOpTheme implements ITheme {
|
|
|
3205
3205
|
content: {
|
|
3206
3206
|
default: {
|
|
3207
3207
|
backgroundColor: (theme: Record<symbol, unknown>) => string;
|
|
3208
|
+
zIndex: (theme: Record<symbol, unknown>) => string;
|
|
3208
3209
|
position: string;
|
|
3209
|
-
overflow: string;
|
|
3210
3210
|
boxShadow: (theme: Record<symbol, unknown>) => string;
|
|
3211
3211
|
};
|
|
3212
3212
|
};
|
package/package.json
CHANGED
package/tokens/defaultTheme.d.ts
CHANGED
|
@@ -3203,8 +3203,8 @@ export declare const defaultTheme: {
|
|
|
3203
3203
|
content: {
|
|
3204
3204
|
default: {
|
|
3205
3205
|
backgroundColor: (theme: Record<symbol, unknown>) => string;
|
|
3206
|
+
zIndex: (theme: Record<symbol, unknown>) => string;
|
|
3206
3207
|
position: string;
|
|
3207
|
-
overflow: string;
|
|
3208
3208
|
boxShadow: (theme: Record<symbol, unknown>) => string;
|
|
3209
3209
|
};
|
|
3210
3210
|
};
|
package/tokens/index.d.ts
CHANGED
|
@@ -3574,8 +3574,8 @@ export declare const defaultTokens: {
|
|
|
3574
3574
|
content: {
|
|
3575
3575
|
default: {
|
|
3576
3576
|
backgroundColor: (theme: Record<symbol, unknown>) => string;
|
|
3577
|
+
zIndex: (theme: Record<symbol, unknown>) => string;
|
|
3577
3578
|
position: string;
|
|
3578
|
-
overflow: string;
|
|
3579
3579
|
boxShadow: (theme: Record<symbol, unknown>) => string;
|
|
3580
3580
|
};
|
|
3581
3581
|
};
|
package/tokens/menu.d.ts
CHANGED
|
@@ -5,8 +5,8 @@ export declare const menu: {
|
|
|
5
5
|
content: {
|
|
6
6
|
default: {
|
|
7
7
|
backgroundColor: (theme: Record<symbol, unknown>) => string;
|
|
8
|
+
zIndex: (theme: Record<symbol, unknown>) => string;
|
|
8
9
|
position: string;
|
|
9
|
-
overflow: string;
|
|
10
10
|
boxShadow: (theme: Record<symbol, unknown>) => string;
|
|
11
11
|
};
|
|
12
12
|
};
|
package/tokens/menu.js
CHANGED
|
@@ -1,17 +1,17 @@
|
|
|
1
|
-
import { get as
|
|
2
|
-
const
|
|
1
|
+
import { get as o } from "../utils/helpers.js";
|
|
2
|
+
const h = {
|
|
3
3
|
wrapper: {
|
|
4
4
|
default: {}
|
|
5
5
|
},
|
|
6
6
|
content: {
|
|
7
7
|
default: {
|
|
8
|
-
backgroundColor: (
|
|
8
|
+
backgroundColor: (e) => o(e, "colors.neutral.white", "theme.colors.neutral.white"),
|
|
9
|
+
zIndex: (e) => o(e, "zIndex.high", "theme.zIndex.high"),
|
|
9
10
|
position: "absolute",
|
|
10
|
-
|
|
11
|
-
boxShadow: (o) => e(o, 'shadows.box["1"]', 'theme.shadows.box["1"]')
|
|
11
|
+
boxShadow: (e) => o(e, 'shadows.box["1"]', 'theme.shadows.box["1"]')
|
|
12
12
|
}
|
|
13
13
|
}
|
|
14
14
|
};
|
|
15
15
|
export {
|
|
16
|
-
|
|
16
|
+
h as menu
|
|
17
17
|
};
|