@cascivo/react 0.6.3 → 0.7.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.
@@ -2,51 +2,51 @@
2
2
 
3
3
  import { usePopover as e } from "../popover/use-popover.js";
4
4
  import t from "./shell-header.module.js";
5
- import { cn as n, useSignal as r, useSignalEffect as i, useSignals as a } from "@cascivo/core";
6
- import { builtin as o, t as s } from "@cascivo/i18n";
7
- import { jsx as c, jsxs as l } from "react/jsx-runtime";
5
+ import { cn as n, getLinkComponent as r, useSignal as i, useSignalEffect as a, useSignals as o } from "@cascivo/core";
6
+ import { builtin as s, t as c } from "@cascivo/i18n";
7
+ import { jsx as l, jsxs as u } from "react/jsx-runtime";
8
8
  //#region ../components/src/shell-header/shell-header.tsx
9
- function u(e) {
9
+ function d(e) {
10
10
  return typeof e == "object" && !!e && "name" in e;
11
11
  }
12
- function d(e) {
12
+ function f(e) {
13
13
  return "items" in e;
14
14
  }
15
- function f({ item: n }) {
16
- a();
17
- let { triggerRef: o, popoverRef: s, isOpen: u, anchorName: d, toggle: f, close: p } = e(), m = n.items.some((e) => e.active), h = r(!1);
18
- i(() => {
19
- if (!h.value || !u.value) return;
20
- h.value = !1;
21
- let e = s.current;
15
+ function p({ item: n }) {
16
+ o();
17
+ let s = r(), { triggerRef: c, popoverRef: d, isOpen: f, anchorName: p, toggle: m, close: h } = e(), g = n.items.some((e) => e.active), _ = i(!1);
18
+ a(() => {
19
+ if (!_.value || !f.value) return;
20
+ _.value = !1;
21
+ let e = d.current;
22
22
  e && e.querySelector("[role=\"menuitem\"]")?.focus();
23
23
  });
24
- function g(e) {
25
- e.key === "ArrowDown" ? (e.preventDefault(), u.value ? s.current?.querySelector("[role=\"menuitem\"]")?.focus() : (h.value = !0, f())) : e.key === "Escape" && (e.preventDefault(), p());
24
+ function v(e) {
25
+ e.key === "ArrowDown" ? (e.preventDefault(), f.value ? d.current?.querySelector("[role=\"menuitem\"]")?.focus() : (_.value = !0, m())) : e.key === "Escape" && (e.preventDefault(), h());
26
26
  }
27
- function _(e) {
28
- let t = Array.from(s.current?.querySelectorAll("[role=\"menuitem\"]") ?? []), n = t.indexOf(document.activeElement);
29
- e.key === "ArrowDown" ? (e.preventDefault(), t[(n + 1) % t.length]?.focus()) : e.key === "ArrowUp" ? (e.preventDefault(), t[(n - 1 + t.length) % t.length]?.focus()) : e.key === "Escape" && (p(), o.current?.focus());
27
+ function y(e) {
28
+ let t = Array.from(d.current?.querySelectorAll("[role=\"menuitem\"]") ?? []), n = t.indexOf(document.activeElement);
29
+ e.key === "ArrowDown" ? (e.preventDefault(), t[(n + 1) % t.length]?.focus()) : e.key === "ArrowUp" ? (e.preventDefault(), t[(n - 1 + t.length) % t.length]?.focus()) : e.key === "Escape" && (h(), c.current?.focus());
30
30
  }
31
- return /* @__PURE__ */ l("li", {
31
+ return /* @__PURE__ */ u("li", {
32
32
  className: t.navMenuWrapper,
33
- children: [/* @__PURE__ */ l("button", {
34
- ref: o,
33
+ children: [/* @__PURE__ */ u("button", {
34
+ ref: c,
35
35
  type: "button",
36
36
  "aria-haspopup": "menu",
37
- "aria-expanded": u.value,
38
- "data-state": m ? "active" : void 0,
39
- style: { anchorName: d },
37
+ "aria-expanded": f.value,
38
+ "data-state": g ? "active" : void 0,
39
+ style: { anchorName: p },
40
40
  className: t.navMenuTrigger,
41
- onClick: f,
42
- onKeyDown: g,
43
- children: [n.label, /* @__PURE__ */ c("svg", {
41
+ onClick: m,
42
+ onKeyDown: v,
43
+ children: [n.label, /* @__PURE__ */ l("svg", {
44
44
  viewBox: "0 0 16 16",
45
45
  width: "12",
46
46
  height: "12",
47
47
  "aria-hidden": "true",
48
48
  className: t.chevron,
49
- children: /* @__PURE__ */ c("path", {
49
+ children: /* @__PURE__ */ l("path", {
50
50
  d: "M4 6l4 4 4-4",
51
51
  fill: "none",
52
52
  stroke: "currentColor",
@@ -55,51 +55,51 @@ function f({ item: n }) {
55
55
  strokeLinejoin: "round"
56
56
  })
57
57
  })]
58
- }), /* @__PURE__ */ c("div", {
59
- ref: s,
58
+ }), /* @__PURE__ */ l("div", {
59
+ ref: d,
60
60
  popover: "auto",
61
61
  role: "menu",
62
62
  "aria-label": n.label,
63
- "data-state": u.value ? "open" : "closed",
64
- style: { positionAnchor: d },
63
+ "data-state": f.value ? "open" : "closed",
64
+ style: { positionAnchor: p },
65
65
  className: t.navMenuPanel,
66
- onKeyDown: _,
67
- children: n.items.map((e, n) => /* @__PURE__ */ c("a", {
66
+ onKeyDown: y,
67
+ children: n.items.map((e, n) => /* @__PURE__ */ l(s, {
68
68
  href: e.href,
69
69
  role: "menuitem",
70
70
  "aria-current": e.active ? "page" : void 0,
71
71
  "data-state": e.active ? "active" : void 0,
72
72
  className: t.navMenuItem,
73
- onClick: p,
73
+ onClick: h,
74
74
  children: e.label
75
75
  }, e.id ?? `${n}-${e.href}`))
76
76
  })]
77
77
  });
78
78
  }
79
- function p({ brand: e, nav: r, actions: i, end: p, onMenuClick: m, menuExpanded: h, skipToContentHref: g = "#cascade-main", labels: _, className: v }) {
80
- a();
81
- let y = _?.nav ?? s(o.shellHeader.nav), b = h ? _?.closeMenu ?? s(o.shellHeader.closeMenu) : _?.openMenu ?? s(o.shellHeader.openMenu);
82
- return /* @__PURE__ */ l("header", {
79
+ function m({ brand: e, nav: i, actions: a, end: m, onMenuClick: h, menuExpanded: g, skipToContentHref: _ = "#cascade-main", labels: v, className: y }) {
80
+ o();
81
+ let b = r(), x = v?.nav ?? c(s.shellHeader.nav), S = g ? v?.closeMenu ?? c(s.shellHeader.closeMenu) : v?.openMenu ?? c(s.shellHeader.openMenu);
82
+ return /* @__PURE__ */ u("header", {
83
83
  role: "banner",
84
- className: n(t.header, v),
84
+ className: n(t.header, y),
85
85
  children: [
86
- g !== !1 && /* @__PURE__ */ c("a", {
87
- href: g,
86
+ _ !== !1 && /* @__PURE__ */ l("a", {
87
+ href: _,
88
88
  className: t.skipLink,
89
- children: _?.skipToContent ?? s(o.shellHeader.skipToContent)
89
+ children: v?.skipToContent ?? c(s.shellHeader.skipToContent)
90
90
  }),
91
- m && /* @__PURE__ */ c("button", {
91
+ h && /* @__PURE__ */ l("button", {
92
92
  type: "button",
93
- "aria-label": b,
94
- "aria-expanded": h ?? !1,
93
+ "aria-label": S,
94
+ "aria-expanded": g ?? !1,
95
95
  className: t.menuButton,
96
- onClick: m,
97
- children: /* @__PURE__ */ c("svg", {
96
+ onClick: h,
97
+ children: /* @__PURE__ */ l("svg", {
98
98
  viewBox: "0 0 16 16",
99
99
  width: "16",
100
100
  height: "16",
101
101
  "aria-hidden": "true",
102
- children: /* @__PURE__ */ c("path", {
102
+ children: /* @__PURE__ */ l("path", {
103
103
  d: "M2 4h12M2 8h12M2 12h12",
104
104
  stroke: "currentColor",
105
105
  strokeWidth: "1.5",
@@ -107,27 +107,27 @@ function p({ brand: e, nav: r, actions: i, end: p, onMenuClick: m, menuExpanded:
107
107
  })
108
108
  })
109
109
  }),
110
- e != null && (u(e) ? /* @__PURE__ */ l("a", {
110
+ e != null && (d(e) ? /* @__PURE__ */ u(b, {
111
111
  href: e.href ?? "/",
112
112
  "aria-label": [e.prefix, e.name].filter(Boolean).join(" "),
113
113
  className: t.brand,
114
- children: [e.prefix && /* @__PURE__ */ c("span", {
114
+ children: [e.prefix && /* @__PURE__ */ l("span", {
115
115
  className: t.brandPrefix,
116
116
  children: e.prefix
117
- }), /* @__PURE__ */ c("span", {
117
+ }), /* @__PURE__ */ l("span", {
118
118
  className: t.brandName,
119
119
  children: e.name
120
120
  })]
121
- }) : /* @__PURE__ */ c("div", {
121
+ }) : /* @__PURE__ */ l("div", {
122
122
  className: t.brand,
123
123
  children: e
124
124
  })),
125
- r && r.length > 0 && /* @__PURE__ */ c("nav", {
126
- "aria-label": y,
125
+ i && i.length > 0 && /* @__PURE__ */ l("nav", {
126
+ "aria-label": x,
127
127
  className: t.nav,
128
- children: /* @__PURE__ */ c("ul", {
128
+ children: /* @__PURE__ */ l("ul", {
129
129
  className: t.navList,
130
- children: r.map((e, n) => d(e) ? /* @__PURE__ */ c(f, { item: e }, e.id ?? `${n}-${e.label}`) : /* @__PURE__ */ c("li", { children: /* @__PURE__ */ c("a", {
130
+ children: i.map((e, n) => f(e) ? /* @__PURE__ */ l(p, { item: e }, e.id ?? `${n}-${e.label}`) : /* @__PURE__ */ l("li", { children: /* @__PURE__ */ l(b, {
131
131
  href: e.href,
132
132
  "aria-current": e.active ? "page" : void 0,
133
133
  "data-state": e.active ? "active" : void 0,
@@ -137,10 +137,10 @@ function p({ brand: e, nav: r, actions: i, end: p, onMenuClick: m, menuExpanded:
137
137
  }) }, e.id ?? `${n}-${e.href}`))
138
138
  })
139
139
  }),
140
- /* @__PURE__ */ c("div", { className: t.spacer }),
141
- i && i.length > 0 && /* @__PURE__ */ c("div", {
140
+ /* @__PURE__ */ l("div", { className: t.spacer }),
141
+ a && a.length > 0 && /* @__PURE__ */ l("div", {
142
142
  className: t.actions,
143
- children: i.map((e) => /* @__PURE__ */ c("button", {
143
+ children: a.map((e) => /* @__PURE__ */ l("button", {
144
144
  type: "button",
145
145
  "aria-label": e.label,
146
146
  "aria-pressed": e.active ?? !1,
@@ -148,19 +148,19 @@ function p({ brand: e, nav: r, actions: i, end: p, onMenuClick: m, menuExpanded:
148
148
  "data-state": e.active ? "active" : void 0,
149
149
  className: t.action,
150
150
  onClick: e.onClick,
151
- children: /* @__PURE__ */ c("span", {
151
+ children: /* @__PURE__ */ l("span", {
152
152
  className: t.actionIcon,
153
153
  "aria-hidden": "true",
154
154
  children: e.icon
155
155
  })
156
156
  }, e.id))
157
157
  }),
158
- p && /* @__PURE__ */ c("div", {
158
+ m && /* @__PURE__ */ l("div", {
159
159
  className: t.end,
160
- children: p
160
+ children: m
161
161
  })
162
162
  ]
163
163
  });
164
164
  }
165
165
  //#endregion
166
- export { p as ShellHeader };
166
+ export { m as ShellHeader };