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 X, jsx as x } from "@emotion/react/jsx-runtime";
3
- import { forwardRef as K, useState as y, useRef as H, useCallback as L, useEffect as U, useImperativeHandle as W } from "react";
4
- import { EMPTY_CLIENT_RECT as j, COMPONENT_NAME as m } from "./constants.js";
5
- import { MenuTriggerStyled as G, MenuContentStyled as R } from "./MenuStyled.js";
6
- import { useAnimationFrame as V } from "../../../utils/animationFrame.js";
7
- import { SelectContext as q } from "../Select/hooks/useSelectContext.js";
8
- import { convertToInlineBoxStyles as z } from "../../../tokens/utils.js";
9
- import { useTheme as J } from "../../../hooks/useTheme/useTheme.js";
10
- import { useLogger as Q } from "../../../hooks/useLogger/useLogger.js";
11
- import { Portal as Z } from "../Portal/Portal.js";
12
- import { KEYBOARD_KEYS as ee } from "../../../constants/keyboard.js";
13
- const n = 4, te = 400, oe = 80, ne = K(({
14
- onSelect: a,
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 = (f, r) => (f == null ? void 0 : f.value) === (r == null ? void 0 : r.value),
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
- }, v) => {
21
+ }, w) => {
22
22
  const {
23
- theme: f
24
- } = J(), r = Q(), [l, g] = y(!1), [i, P] = y(), [N, E] = y(), p = H(null), s = H(null), S = H({
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
- }), F = L(({
27
+ }), B = H(({
28
28
  width: t,
29
29
  height: e
30
30
  }) => {
31
- const o = p.current ? p.current.getBoundingClientRect() : j, w = window.innerWidth, d = window.innerHeight, h = window.scrollX || window.pageXOffset || 0, k = window.scrollY || window.pageYOffset || 0, O = _ || "bottom-right";
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 (O) {
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
- return c + t > w && (c = w - t - n), c < 0 && (c = n), u + e > d && (u = d - e - n), u < 0 && (u = n), {
52
- left: c + h,
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
- }, [_]), C = L(({
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: i == null ? void 0 : i.value,
63
- previousName: i == null ? void 0 : i.name
64
- }), a == null || a({
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 && g(!1);
68
- }, [a, M, i]), B = L(() => {
69
- g((t) => {
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: C,
77
- value: i,
79
+ onSelect: T,
80
+ value: s,
78
81
  itemIdentifier: I
79
82
  }, b = (t) => {
80
83
  var e;
81
- ((e = v == null ? void 0 : v.current) != null && e.isOpen || l) && t.key === ee.ESCAPE && (r.debug(`${m}: Close`, {
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
- }), g(!1));
84
- }, T = (t) => {
86
+ }), a(!1));
87
+ }, h = (t) => {
85
88
  var e, o;
86
- !((e = p == null ? void 0 : p.current) != null && e.contains(N || t.target)) && !((o = s == null ? void 0 : s.current) != null && o.contains(t.target)) && (r.debug(`${m}: Close`, {
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
- }), g(!1), E(null));
91
+ }), a(!1), C(null));
89
92
  };
90
- return U(() => (l ? (document.addEventListener("keydown", b), document.addEventListener("mousedown", T)) : (document.removeEventListener("keydown", b), document.removeEventListener("mousedown", T)), () => {
91
- document.removeEventListener("keydown", b), document.removeEventListener("mousedown", T);
92
- }), [l]), V(() => {
93
- if (s.current && l) {
94
- const t = s.current.getBoundingClientRect(), {
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
- } = F(t), w = window.innerHeight, d = window.scrollY || window.pageYOffset || 0, h = e - d, k = w - h - n, O = Math.max(oe, Math.min(te, k));
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
- }, s.current && (s.current.style.left = `${o}px`, s.current.style.top = `${e}px`, s.current.style.maxHeight = `${O}px`);
104
+ }, i.current && (i.current.style.left = `${o}px`, i.current.style.top = `${e}px`, i.current.style.maxHeight = `${p}px`);
102
105
  }
103
- }), W(v, () => ({
104
- ref: p,
106
+ }), V(w, () => ({
107
+ ref: f,
105
108
  isOpen: l,
106
- selectedValue: i,
107
- onSelect: C,
109
+ selectedValue: s,
110
+ onSelect: T,
108
111
  open: (t) => {
109
112
  r.debug(`${m}: Open`, {
110
113
  trigger: "ref"
111
- }), !l && (E(t || null), g(!0));
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 && (E(t || null), g(!1));
119
+ }), l && (C(t || null), a(!1));
117
120
  }
118
- }), [l, i, C]), /* @__PURE__ */ X(q.Provider, { value: D, children: [
119
- /* @__PURE__ */ x(G, { onClick: B, theme: f, ref: p, "data-testid": m, ...$, children: A }),
120
- l && /* @__PURE__ */ x(Z, { withWrapper: !1, children: /* @__PURE__ */ x(R, { ref: s, "data-testid": m, theme: f, ...z($), children: Y }) })
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
- ne.displayName = m;
126
+ le.displayName = m;
124
127
  export {
125
- ne as Menu
128
+ le as Menu
126
129
  };
@@ -1,13 +1,15 @@
1
1
  "use client";
2
- import { useState as i, useEffect as r } from "react";
2
+ import { useState as a, useEffect as c } from "react";
3
3
  const o = (e) => {
4
- const [a, s] = i(() => window.matchMedia(e).matches);
5
- return r(() => {
6
- const t = window.matchMedia(e), n = (c) => s(c.matches);
7
- return t.addEventListener("change", n), s(t.matches), () => {
8
- t.removeEventListener("change", n);
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]), a;
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
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "gd-design-library",
3
- "version": "1.2.0",
3
+ "version": "1.2.1",
4
4
  "license": "MIT",
5
5
  "type": "module",
6
6
  "main": "./index.js",
@@ -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 e } from "../utils/helpers.js";
2
- const r = {
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: (o) => e(o, "colors.neutral.white", "theme.colors.neutral.white"),
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
- overflow: "auto",
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
- r as menu
16
+ h as menu
17
17
  };