@ogcio/design-system-react 1.23.0 → 1.25.0

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.
@@ -12,46 +12,46 @@ import { SelectMenu as le, SelectMenuOption as J, SelectMenuGroupItem as ce } fr
12
12
  import { SelectSearch as ie } from "./select-search.js";
13
13
  const pe = B(
14
14
  ({
15
- children: x,
15
+ children: I,
16
16
  value: u,
17
17
  defaultValue: E = "",
18
- onChange: I,
18
+ onChange: v,
19
19
  onMenuClose: f,
20
- enableSearch: y,
20
+ enableSearch: h,
21
21
  disabled: s,
22
22
  name: i,
23
23
  onBlur: m,
24
24
  placeholder: P,
25
- ...v
25
+ ...N
26
26
  }, Q) => {
27
27
  const c = w(null), D = w(null), A = w(null), $ = w(!1), [a, j] = k(
28
28
  E || u
29
- ), [N, p] = k(!1), [W, K] = k(""), [b, V] = k(-1);
30
- ee(Q, () => c.current), ne(A, b);
31
- const h = R.toArray(x).filter(
29
+ ), [S, p] = k(!1), [W, K] = k(""), [g, V] = k(-1);
30
+ ee(Q, () => c.current), ne(A, g);
31
+ const d = R.toArray(I).filter(
32
32
  (e) => G(e)
33
33
  );
34
34
  O(() => {
35
35
  var r, t;
36
36
  let e;
37
- for (const n of h) {
37
+ for (const n of d) {
38
38
  const o = (r = n.type) == null ? void 0 : r.componentType;
39
39
  if (o === "SelectItemNext") {
40
- const g = n;
41
- if (g.props.value === a) {
42
- e = g;
40
+ const y = n;
41
+ if (y.props.value === a) {
42
+ e = y;
43
43
  break;
44
44
  }
45
45
  }
46
46
  if (o === "SelectGroupItemNext") {
47
- const g = n, d = R.toArray(g.props.children).find(
48
- (S) => {
47
+ const y = n, b = R.toArray(y.props.children).find(
48
+ (x) => {
49
49
  var z;
50
- return ((z = S == null ? void 0 : S.type) == null ? void 0 : z.componentType) === "SelectItemNext" && S.props.value === a;
50
+ return ((z = x == null ? void 0 : x.type) == null ? void 0 : z.componentType) === "SelectItemNext" && x.props.value === a;
51
51
  }
52
52
  );
53
- if (d && G(d)) {
54
- e = d;
53
+ if (b && G(b)) {
54
+ e = b;
55
55
  break;
56
56
  }
57
57
  }
@@ -61,9 +61,9 @@ const pe = B(
61
61
  K(n);
62
62
  } else
63
63
  K(""), c.current && (c.current.value = "");
64
- }, [a, h]), O(() => {
65
- N || V(-1);
66
- }, [N]), O(() => {
64
+ }, [a, d]), O(() => {
65
+ S || V(-1);
66
+ }, [S]), O(() => {
67
67
  u !== void 0 && j(u);
68
68
  }, [u]);
69
69
  const L = () => {
@@ -72,7 +72,7 @@ const pe = B(
72
72
  }, X = (e) => {
73
73
  p(e), e || f == null || f();
74
74
  }, U = (e) => {
75
- if (p(!1), j(e), I && (I({
75
+ if (p(!1), j(e), v && (v({
76
76
  target: { name: i, value: e },
77
77
  currentTarget: { name: i, value: e },
78
78
  type: "change",
@@ -86,36 +86,39 @@ const pe = B(
86
86
  };
87
87
  m == null || m(t);
88
88
  }
89
- }, Y = te((e) => {
90
- var r;
91
- if (!s)
92
- switch (e.key) {
93
- case "ArrowDown":
94
- case "ArrowUp": {
95
- e.preventDefault();
96
- const t = e.key === "ArrowDown" ? 1 : -1;
97
- V((n) => ae(h, n === -1 ? t === -1 ? 0 : -1 : n, t)), p(!0);
98
- break;
99
- }
100
- case "Enter":
101
- case "NumpadEnter": {
102
- if (e.preventDefault(), N && b != -1 && h[b]) {
103
- const t = h[b];
104
- (r = t.props) != null && r.disabled || U(t.props.value);
105
- } else
106
- p(!0);
107
- break;
108
- }
109
- case "Tab": {
110
- p(!1);
111
- break;
112
- }
113
- case "Escape": {
114
- e.preventDefault(), p(!1);
115
- break;
89
+ }, Y = te(
90
+ (e) => {
91
+ var r;
92
+ if (!s)
93
+ switch (e.key) {
94
+ case "ArrowDown":
95
+ case "ArrowUp": {
96
+ e.preventDefault();
97
+ const t = e.key === "ArrowDown" ? 1 : -1;
98
+ V((n) => ae(d, n === -1 ? t === -1 ? 0 : -1 : n, t)), p(!0);
99
+ break;
100
+ }
101
+ case "Enter":
102
+ case "NumpadEnter": {
103
+ if (e.preventDefault(), S && g != -1 && d[g]) {
104
+ const t = d[g];
105
+ (r = t.props) != null && r.disabled || U(t.props.value);
106
+ } else
107
+ p(!0);
108
+ break;
109
+ }
110
+ case "Tab": {
111
+ p(!1);
112
+ break;
113
+ }
114
+ case "Escape": {
115
+ e.preventDefault(), p(!1);
116
+ break;
117
+ }
116
118
  }
117
- }
118
- }, []), Z = (e) => {
119
+ },
120
+ [d, S, g]
121
+ ), Z = (e) => {
119
122
  var t, n;
120
123
  const r = e.relatedTarget;
121
124
  if (r && ((t = A.current) != null && t.contains(r) || (n = D.current) != null && n.contains(r)) || $.current) {
@@ -131,33 +134,33 @@ const pe = B(
131
134
  bubbles: !0
132
135
  });
133
136
  }
134
- }, C = re(), q = v["aria-label"] ?? F("select.next.placeholder", { defaultValue: "Select" });
137
+ }, C = re(), q = N["aria-label"] ?? F("select.next.placeholder", { defaultValue: "Select" });
135
138
  return O(() => {
136
139
  c.current && c.current.setAttribute("aria-labelledby", C);
137
- }, [C, y]), y ? /* @__PURE__ */ l("div", { className: H("gi-select-next", v.className), children: /* @__PURE__ */ l(
140
+ }, [C, h]), h ? /* @__PURE__ */ l("div", { className: H("gi-select-next", N.className), children: /* @__PURE__ */ l(
138
141
  ie,
139
142
  {
140
- ...v,
143
+ ...N,
141
144
  value: a,
142
- onChange: I,
145
+ onChange: v,
143
146
  disabled: s,
144
147
  ref: c,
145
148
  onBlur: m,
146
149
  name: i,
147
150
  placeholder: P,
148
- children: x
151
+ children: I
149
152
  }
150
153
  ) }) : /* @__PURE__ */ _(
151
154
  "div",
152
155
  {
153
156
  "aria-disabled": s,
154
- className: H("gi-select-next", v.className),
157
+ className: H("gi-select-next", N.className),
155
158
  children: [
156
159
  /* @__PURE__ */ l("span", { id: C, className: "gi-sr-only", children: q }),
157
160
  /* @__PURE__ */ l(
158
161
  oe,
159
162
  {
160
- ...v,
163
+ ...N,
161
164
  autoComplete: "off",
162
165
  "aria-label": q,
163
166
  "aria-disabled": s,
@@ -169,7 +172,7 @@ const pe = B(
169
172
  "gi-cursor-pointer": !s,
170
173
  "gi-cursor-not-allowed gi-pointer-events-none": s
171
174
  }),
172
- iconEnd: N ? "keyboard_arrow_up" : "keyboard_arrow_down",
175
+ iconEnd: S ? "keyboard_arrow_up" : "keyboard_arrow_down",
173
176
  onIconEndClick: L,
174
177
  ref: c,
175
178
  iconEndRef: D,
@@ -186,7 +189,7 @@ const pe = B(
186
189
  triggerRef: c,
187
190
  extraRefs: [D],
188
191
  onOpenChange: X,
189
- open: N,
192
+ open: S,
190
193
  maxHeight: 304,
191
194
  options: {
192
195
  placement: "bottom-start",
@@ -203,8 +206,8 @@ const pe = B(
203
206
  onChange: (e) => {
204
207
  p(!1), U(e);
205
208
  },
206
- enableSearch: y,
207
- children: h.map((e, r) => {
209
+ enableSearch: h,
210
+ children: d.map((e, r) => {
208
211
  var n;
209
212
  const t = (n = e == null ? void 0 : e.type) == null ? void 0 : n.componentType;
210
213
  if (t === "SelectItemNext") {
@@ -213,22 +216,22 @@ const pe = B(
213
216
  J,
214
217
  {
215
218
  ...o.props,
216
- isHighlighted: b === r,
219
+ isHighlighted: g === r,
217
220
  selected: (a == null ? void 0 : a.toString()) === o.props.value.toString(),
218
221
  index: r
219
222
  },
220
223
  `SelectItemNext-${o.props.value.toString()}`
221
224
  );
222
225
  } else if (t === "SelectGroupItemNext") {
223
- const o = e, g = R.toArray(o.props.children).filter((d) => G(d)).map((d, S) => {
224
- const T = d.props;
226
+ const o = e, y = R.toArray(o.props.children).filter((b) => G(b)).map((b, x) => {
227
+ const T = b.props;
225
228
  return /* @__PURE__ */ l(
226
229
  J,
227
230
  {
228
231
  ...T,
229
- isHighlighted: b === r,
232
+ isHighlighted: g === r,
230
233
  selected: (a == null ? void 0 : a.toString()) === T.value.toString(),
231
- index: S
234
+ index: x
232
235
  },
233
236
  `SelectGroupItemNext-SelectItemNext-${T.value.toString()}`
234
237
  );
@@ -237,7 +240,7 @@ const pe = B(
237
240
  ce,
238
241
  {
239
242
  label: o.props.label,
240
- children: g
243
+ children: y
241
244
  },
242
245
  `option-group-${r}`
243
246
  );
@@ -264,17 +267,17 @@ Object.defineProperty(ue, "componentType", {
264
267
  writable: !1,
265
268
  enumerable: !1
266
269
  });
267
- const Ne = (x) => {
268
- const { options: u, defaultValue: E, onChange: I, error: f } = x;
270
+ const Ne = (I) => {
271
+ const { options: u, defaultValue: E, onChange: v, error: f } = I;
269
272
  return /* @__PURE__ */ l(
270
273
  pe,
271
274
  {
272
- ...x,
275
+ ...I,
273
276
  defaultValue: E,
274
- onChange: I,
277
+ onChange: v,
275
278
  "data-table-cell": "true",
276
279
  "data-table-cell-error-state": f == null ? void 0 : f.toString(),
277
- children: u.map(({ value: y, label: s }) => /* @__PURE__ */ l(M, { value: y, children: s }, `${y}-${s}`))
280
+ children: u.map(({ value: h, label: s }) => /* @__PURE__ */ l(M, { value: h, children: s }, `${h}-${s}`))
278
281
  }
279
282
  );
280
283
  };
@@ -0,0 +1,2 @@
1
+ export { SideNav, SideNavItem, SideNavHeading } from './side-nav.js';
2
+ export type { SideNavItemProps, SideNavProps, SideNavHeadingProps, } from './types.js';
@@ -0,0 +1,6 @@
1
+ import { SideNav as d, SideNavHeading as i, SideNavItem as v } from "./side-nav.js";
2
+ export {
3
+ d as SideNav,
4
+ i as SideNavHeading,
5
+ v as SideNavItem
6
+ };
@@ -1,6 +1,7 @@
1
1
  import { default as React, PropsWithChildren } from 'react';
2
- import { SideNavItemProps, SideNavProps } from './types.js';
2
+ import { SideNavHeadingProps, SideNavItemProps, SideNavProps } from './types.js';
3
3
  export declare const SideNavItem: React.FC<PropsWithChildren<SideNavItemProps> & {
4
4
  open?: boolean;
5
5
  }>;
6
6
  export declare const SideNav: React.FC<PropsWithChildren<SideNavProps>>;
7
+ export declare const SideNavHeading: React.FC<SideNavHeadingProps>;
@@ -1,132 +1,133 @@
1
1
  "use client";
2
- import { jsxs as w, Fragment as V, jsx as s } from "react/jsx-runtime";
3
- import f, { memo as B, useEffect as q, useCallback as v, useState as _ } from "react";
4
- import { Button as A } from "../button/button.js";
5
- import { cn as N } from "../cn.js";
6
- import { Icon as $ } from "../icon/icon.js";
2
+ import { jsxs as x, Fragment as R, jsx as s } from "react/jsx-runtime";
3
+ import r, { memo as k, useEffect as V, useCallback as g, useState as $ } from "react";
4
+ import { Button as q } from "../button/button.js";
5
+ import { cn as m } from "../cn.js";
6
+ import { Heading as A } from "../heading/heading.js";
7
+ import { Icon as z } from "../icon/icon.js";
7
8
  import { Link as G } from "../link/link.js";
8
- import { Paragraph as H } from "../paragraph/paragraph.js";
9
- const j = f.createContext(
9
+ import { Paragraph as J } from "../paragraph/paragraph.js";
10
+ const C = r.createContext(
10
11
  void 0
11
- ), z = B(
12
+ ), B = k(
12
13
  ({
13
14
  icon: n,
14
- label: i,
15
- showExpandableIcon: c,
15
+ label: t,
16
+ showExpandableIcon: d,
16
17
  isOpen: e
17
- }) => /* @__PURE__ */ w(V, { children: [
18
- /* @__PURE__ */ w("div", { className: "gi-side-nav-item-left", children: [
19
- n && /* @__PURE__ */ s("div", { className: "gi-side-nav-item-icon", children: /* @__PURE__ */ s($, { icon: n }) }),
20
- /* @__PURE__ */ s("div", { className: "gi-side-nav-item-label", children: /* @__PURE__ */ s(H, { size: "md", children: i }) })
18
+ }) => /* @__PURE__ */ x(R, { children: [
19
+ /* @__PURE__ */ x("div", { className: "gi-side-nav-item-left", children: [
20
+ n && /* @__PURE__ */ s("div", { className: "gi-side-nav-item-icon", children: /* @__PURE__ */ s(z, { icon: n }) }),
21
+ /* @__PURE__ */ s("div", { className: "gi-side-nav-item-label", children: /* @__PURE__ */ s(J, { size: "md", children: t }) })
21
22
  ] }),
22
- c && /* @__PURE__ */ s("div", { className: "gi-side-nav-expandable-icon", children: /* @__PURE__ */ s(
23
- $,
23
+ d && /* @__PURE__ */ s("div", { className: "gi-side-nav-expandable-icon", children: /* @__PURE__ */ s(
24
+ z,
24
25
  {
25
- className: N(e && "gi-rotate-180"),
26
+ className: m(e && "gi-rotate-180"),
26
27
  icon: "keyboard_arrow_down"
27
28
  }
28
29
  ) })
29
30
  ] })
30
- ), J = f.memo(
31
+ ), K = r.memo(
31
32
  ({
32
33
  children: n,
33
- primary: i,
34
- secondary: c,
34
+ primary: t,
35
+ secondary: d,
35
36
  expandable: e,
36
- label: a,
37
- value: t,
38
- icon: u,
39
- href: m,
40
- asChild: g,
41
- open: r
37
+ label: c,
38
+ value: i,
39
+ icon: f,
40
+ href: l,
41
+ asChild: u,
42
+ open: v
42
43
  }) => {
43
- const l = f.useContext(j);
44
- if (!l)
44
+ const I = r.useContext(C);
45
+ if (!I)
45
46
  throw new Error("SideNavItem must be used within a SideNav");
46
47
  const {
47
48
  openItemIds: o,
48
49
  selectedItemId: S,
49
50
  setOpenItemIds: p,
50
- setSelectedItemId: C,
51
- navId: P
52
- } = l, I = o.includes(t), x = S === t;
53
- q(() => {
54
- r && p((d) => d.includes(t) ? d : [...d, t]);
55
- }, [r, p, t]);
56
- const h = v(() => {
57
- const d = I ? o.filter((R) => R !== t) : [...o, t];
58
- p(d);
59
- }, [I, o, p, t]), k = v(() => {
60
- C(t);
61
- }, [C, t]), E = `${P}-${t}`, O = i && e, b = m !== void 0, D = v(() => {
62
- i && e && h(), k();
63
- }, [i, e, h, k]), F = v(
64
- (d) => {
65
- d.preventDefault(), i && e ? h() : k();
51
+ setSelectedItemId: E,
52
+ navId: b
53
+ } = I, N = o.includes(i), H = S === i;
54
+ V(() => {
55
+ v && p((a) => a.includes(i) ? a : [...a, i]);
56
+ }, [v, p, i]);
57
+ const h = g(() => {
58
+ const a = N ? o.filter((M) => M !== i) : [...o, i];
59
+ p(a);
60
+ }, [N, o, p, i]), w = g(() => {
61
+ E(i);
62
+ }, [E, i]), O = `${b}-${i}`, _ = t && e, j = l !== void 0, P = g(() => {
63
+ t && e && h(), w();
64
+ }, [t, e, h, w]), D = g(
65
+ (a) => {
66
+ a.preventDefault(), t && e ? h() : w();
66
67
  },
67
- [i, e, h, k]
68
- ), L = N("gi-side-nav-item", {
69
- "gi-side-nav-item-selected": x,
70
- "gi-side-nav-item-primary": i,
71
- "gi-side-nav-item-secondary": c
72
- }), M = N("gi-side-nav-item", {
73
- "gi-side-nav-item-selected": x,
74
- "gi-side-nav-item-primary": i,
75
- "gi-side-nav-item-secondary": c
68
+ [t, e, h, w]
69
+ ), F = m("gi-side-nav-item", {
70
+ "gi-side-nav-item-selected": H,
71
+ "gi-side-nav-item-primary": t,
72
+ "gi-side-nav-item-secondary": d
73
+ }), L = m("gi-side-nav-item", {
74
+ "gi-side-nav-item-selected": H,
75
+ "gi-side-nav-item-primary": t,
76
+ "gi-side-nav-item-secondary": d
76
77
  });
77
- return /* @__PURE__ */ w(
78
+ return /* @__PURE__ */ x(
78
79
  "div",
79
80
  {
80
81
  role: "group",
81
- "aria-label": `${a} ${i && e ? "dropdown" : "item"}`,
82
+ "aria-label": `${c} ${t && e ? "dropdown" : "item"}`,
82
83
  children: [
83
- b ? /* @__PURE__ */ s(
84
+ j ? /* @__PURE__ */ s(
84
85
  G,
85
86
  {
86
- id: E,
87
- href: m,
88
- asChild: g,
87
+ id: O,
88
+ href: l,
89
+ asChild: u,
89
90
  asButton: {
90
91
  variant: "flat",
91
92
  appearance: "dark",
92
93
  size: "medium"
93
94
  },
94
- className: L,
95
- onClick: D,
96
- children: g ? n : /* @__PURE__ */ s(
97
- z,
95
+ className: F,
96
+ onClick: P,
97
+ children: u ? n : /* @__PURE__ */ s(
98
+ B,
98
99
  {
99
- icon: u,
100
- label: a,
101
- showExpandableIcon: O,
102
- isOpen: I
100
+ icon: f,
101
+ label: c,
102
+ showExpandableIcon: _,
103
+ isOpen: N
103
104
  }
104
105
  )
105
106
  }
106
107
  ) : /* @__PURE__ */ s(
107
- A,
108
+ q,
108
109
  {
109
110
  variant: "flat",
110
111
  appearance: "dark",
111
112
  size: "medium",
112
- onClick: F,
113
- className: M,
114
- id: E,
113
+ onClick: D,
114
+ className: L,
115
+ id: O,
115
116
  children: /* @__PURE__ */ s(
116
- z,
117
+ B,
117
118
  {
118
- icon: u,
119
- label: a,
120
- showExpandableIcon: O,
121
- isOpen: I
119
+ icon: f,
120
+ label: c,
121
+ showExpandableIcon: _,
122
+ isOpen: N
122
123
  }
123
124
  )
124
125
  }
125
126
  ),
126
- e && i && /* @__PURE__ */ s(
127
+ e && t && /* @__PURE__ */ s(
127
128
  "div",
128
129
  {
129
- className: N(I ? "gi-side-nav-item-content" : "gi-hidden"),
130
+ className: m(N ? "gi-side-nav-item-content" : "gi-hidden"),
130
131
  children: n
131
132
  }
132
133
  )
@@ -134,38 +135,58 @@ const j = f.createContext(
134
135
  }
135
136
  );
136
137
  }
137
- ), K = B(
138
- ({ children: n, className: i, dataTestid: c, onChange: e, value: a }) => {
139
- const [t, u] = _([]), [m, g] = _(
140
- a
141
- ), r = f.useId(), l = v(
138
+ ), Q = k(
139
+ ({ children: n, className: t, dataTestid: d, onChange: e, value: c }) => {
140
+ const [i, f] = $([]), [l, u] = $(
141
+ c
142
+ ), v = r.useId(), I = g(
142
143
  (S) => {
143
- g(S), e == null || e(S);
144
+ u(S), e == null || e(S);
144
145
  },
145
146
  [e]
146
- ), o = f.useMemo(
147
+ ), o = r.useMemo(
147
148
  () => ({
148
- openItemIds: t,
149
- selectedItemId: m,
150
- setOpenItemIds: u,
151
- setSelectedItemId: l,
152
- navId: r
149
+ openItemIds: i,
150
+ selectedItemId: l,
151
+ setOpenItemIds: f,
152
+ setSelectedItemId: I,
153
+ navId: v
153
154
  }),
154
- [t, m, l, r]
155
+ [i, l, I, v]
155
156
  );
156
- return /* @__PURE__ */ s(j.Provider, { value: o, children: /* @__PURE__ */ s(
157
+ return /* @__PURE__ */ s(C.Provider, { value: o, children: /* @__PURE__ */ s(
157
158
  "div",
158
159
  {
159
- className: N("gi-side-nav-container", i),
160
- "data-testid": c,
160
+ className: m("gi-side-nav-container", t),
161
+ "data-testid": d,
161
162
  children: n
162
163
  }
163
164
  ) });
164
165
  }
166
+ ), T = k(
167
+ ({ children: n, secondary: t, className: d, ...e }) => {
168
+ if (!r.useContext(C))
169
+ throw new Error("SideNavHeading must be used within a SideNav");
170
+ return /* @__PURE__ */ s(
171
+ A,
172
+ {
173
+ ...e,
174
+ as: "h5",
175
+ className: m(
176
+ "gi-side-nav-heading",
177
+ t ? "gi-px-6" : "gi-px-3",
178
+ d
179
+ ),
180
+ children: n
181
+ }
182
+ );
183
+ }
165
184
  );
166
- K.displayName = "SideNav";
167
- J.displayName = "SideNavItem";
185
+ Q.displayName = "SideNav";
186
+ K.displayName = "SideNavItem";
187
+ T.displayName = "SideNavHeading";
168
188
  export {
169
- K as SideNav,
170
- J as SideNavItem
189
+ Q as SideNav,
190
+ T as SideNavHeading,
191
+ K as SideNavItem
171
192
  };
@@ -1,3 +1,4 @@
1
+ import { HeadingProps } from '../heading/heading.js';
1
2
  import { IconId } from '../icon/icon.js';
2
3
  export type SideNavItemProps = {
3
4
  value: string;
@@ -16,3 +17,6 @@ export type SideNavProps = {
16
17
  value?: string;
17
18
  onChange?: (value: string) => void;
18
19
  };
20
+ export type SideNavHeadingProps = {
21
+ secondary?: boolean;
22
+ } & HeadingProps;