iryx-ui 0.26.0 → 0.28.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.
@@ -1,14 +1,21 @@
1
1
  import { useIryxUiConfig as e } from "../config.js";
2
2
  import t from "./Icon.js";
3
- import { isSidebarGroup as n, toSidebarSections as r } from "../composables/sidebar.js";
4
- import { sidebarTheme as i } from "../theme/sidebar.js";
5
- import { Fragment as a, computed as o, createBlock as s, createCommentVNode as c, createElementBlock as l, createElementVNode as u, createVNode as d, defineComponent as f, mergeModels as p, normalizeClass as m, openBlock as h, renderList as g, renderSlot as _, resolveDynamicComponent as v, toDisplayString as y, unref as b, useModel as x, withCtx as S } from "vue";
6
- import { ArrowRight01Icon as C } from "@hugeicons/core-free-icons";
7
- import { CollapsibleContent as w, CollapsibleRoot as T, CollapsibleTrigger as E, Primitive as D } from "reka-ui";
3
+ import { isSidebarGroup as n, sidebarPlacementKey as r, toSidebarSections as i } from "../composables/sidebar.js";
4
+ import a from "./Tooltip.js";
5
+ import o from "./DropdownMenu.js";
6
+ import { sidebarTheme as s } from "../theme/sidebar.js";
7
+ import { Fragment as c, computed as l, createBlock as u, createCommentVNode as d, createElementBlock as f, createElementVNode as p, createTextVNode as m, createVNode as h, defineComponent as g, inject as _, mergeModels as v, normalizeClass as y, openBlock as b, ref as x, renderList as S, renderSlot as C, resolveDynamicComponent as w, toDisplayString as T, unref as E, useModel as D, withCtx as O } from "vue";
8
+ import { ArrowRight01Icon as k } from "@hugeicons/core-free-icons";
9
+ import { CollapsibleContent as A, CollapsibleRoot as j, CollapsibleTrigger as M, Primitive as N } from "reka-ui";
8
10
  //#region src/components/Sidebar.vue?vue&type=script&setup=true&lang.ts
9
- var O = /*@__PURE__*/ f({
11
+ var P = ["data-pinned"], F = [
12
+ "aria-label",
13
+ "disabled",
14
+ "data-active",
15
+ "data-disabled"
16
+ ], I = /*@__PURE__*/ g({
10
17
  __name: "Sidebar",
11
- props: /*@__PURE__*/ p({
18
+ props: /*@__PURE__*/ v({
12
19
  items: {},
13
20
  side: { default: "left" },
14
21
  label: { default: "Sidebar" },
@@ -31,61 +38,114 @@ var O = /*@__PURE__*/ f({
31
38
  collapsedModifiers: {}
32
39
  }),
33
40
  emits: ["update:collapsed"],
34
- setup(f) {
35
- let p = f, O = x(f, "collapsed"), k = e(), A = o(() => p.unstyled ?? k.unstyled), j = o(() => r(p.items)), M = o(() => i({
36
- side: p.side,
37
- collapsed: O.value
41
+ setup(g) {
42
+ let v = g, I = D(g, "collapsed"), L = _(r, void 0), R = l(() => I.value && L !== "drawer"), z = e(), B = l(() => v.unstyled ?? z.unstyled), V = l(() => i(v.items)), H = l(() => V.value.findIndex((e) => e.pinned)), U = l(() => s({
43
+ side: v.side,
44
+ collapsed: R.value,
45
+ inShell: L !== void 0
38
46
  }));
39
- function N(e) {
40
- let t = p.ui?.[e];
41
- return A.value ? t : M.value[e]({ class: t });
47
+ function W(e) {
48
+ let t = v.ui?.[e];
49
+ return B.value ? t : U.value[e]({ class: t });
42
50
  }
43
- let P = (e) => e.href ? "a" : "button";
44
- function F(e, t) {
51
+ let G = l(() => v.side === "right" ? "left" : "right"), K = x({}), q = (e, t) => `${e}:${t.label}`, J = (e) => e.href ? "a" : "button", Y = (e) => [...e.label][0], X = (e) => e.badge === void 0 ? e.label : `${e.label} (${e.badge})`;
52
+ function Z(e) {
53
+ return (e.items ?? []).map((e) => ({
54
+ label: e.label,
55
+ icon: e.icon,
56
+ disabled: e.disabled,
57
+ href: e.href,
58
+ onSelect: e.onSelect
59
+ }));
60
+ }
61
+ function Q(e, t) {
45
62
  if (e.disabled) {
46
63
  t.preventDefault();
47
64
  return;
48
65
  }
49
66
  e.onSelect?.();
50
67
  }
51
- let I = (e) => e.label;
52
- return (e, r) => (h(), s(b(D), {
68
+ let $ = (e) => e.label;
69
+ return (e, r) => (b(), u(E(N), {
53
70
  as: "nav",
54
- "aria-label": p.label,
55
- "data-collapsed": O.value ? "" : void 0,
56
- class: m(A.value ? [p.ui?.root, p.class] : M.value.root({ class: [p.ui?.root, p.class] }))
71
+ "aria-label": v.label,
72
+ "data-collapsed": R.value ? "" : void 0,
73
+ class: y(B.value ? [v.ui?.root, v.class] : U.value.root({ class: [v.ui?.root, v.class] }))
57
74
  }, {
58
- default: S(() => [
59
- e.$slots.header ? (h(), l("div", {
75
+ default: O(() => [
76
+ e.$slots.header ? (b(), f("div", {
60
77
  key: 0,
61
- class: m(N("header"))
62
- }, [_(e.$slots, "header", { collapsed: O.value })], 2)) : c("", !0),
63
- u("div", { class: m(N("nav")) }, [_(e.$slots, "default", { collapsed: O.value }, () => [(h(!0), l(a, null, g(j.value, (r, i) => (h(), l("div", {
78
+ class: y(W("header"))
79
+ }, [C(e.$slots, "header", { collapsed: R.value })], 2)) : d("", !0),
80
+ p("div", { class: y(W("nav")) }, [C(e.$slots, "default", { collapsed: R.value }, () => [(b(!0), f(c, null, S(V.value, (r, i) => (b(), f("div", {
64
81
  key: r.section || i,
65
- class: m(N("section"))
66
- }, [r.section ? (h(), l("p", {
82
+ "data-pinned": r.pinned ? "" : void 0,
83
+ class: y([W("section"), i === H.value && "mt-auto"])
84
+ }, [r.section ? (b(), f("p", {
67
85
  key: 0,
68
- class: m(N("sectionLabel"))
69
- }, y(r.section), 3)) : c("", !0), (h(!0), l(a, null, g(r.items, (r) => (h(), l(a, { key: r.label }, [b(n)(r) ? (h(), s(b(T), {
86
+ class: y(W("sectionLabel"))
87
+ }, T(r.section), 3)) : d("", !0), (b(!0), f(c, null, S(r.items, (r) => (b(), f(c, { key: r.label }, [E(n)(r) && R.value ? (b(), u(a, {
70
88
  key: 0,
71
- "default-open": r.defaultOpen,
72
- disabled: r.disabled
89
+ text: X(r),
90
+ side: G.value,
91
+ unstyled: B.value
92
+ }, {
93
+ trigger: O(() => [h(o, {
94
+ items: Z(r),
95
+ side: G.value,
96
+ unstyled: B.value
97
+ }, {
98
+ trigger: O(() => [p("button", {
99
+ type: "button",
100
+ "aria-label": $(r),
101
+ disabled: r.disabled,
102
+ "data-active": r.active ? "" : void 0,
103
+ "data-disabled": r.disabled ? "" : void 0,
104
+ class: y(W("link"))
105
+ }, [C(e.$slots, "link", {
106
+ link: r,
107
+ collapsed: R.value
108
+ }, () => [r.icon ? (b(), u(t, {
109
+ key: 0,
110
+ icon: r.icon
111
+ }, null, 8, ["icon"])) : (b(), f("span", {
112
+ key: 1,
113
+ "aria-hidden": "true",
114
+ class: y(W("linkInitial"))
115
+ }, T(Y(r)), 3))])], 10, F)]),
116
+ header: O(() => [m(T(r.label), 1)]),
117
+ _: 2
118
+ }, 1032, [
119
+ "items",
120
+ "side",
121
+ "unstyled"
122
+ ])]),
123
+ _: 2
124
+ }, 1032, [
125
+ "text",
126
+ "side",
127
+ "unstyled"
128
+ ])) : E(n)(r) ? (b(), u(E(j), {
129
+ key: 1,
130
+ open: K.value[q(i, r)] ?? r.defaultOpen ?? !1,
131
+ disabled: r.disabled,
132
+ "onUpdate:open": (e) => K.value[q(i, r)] = e
73
133
  }, {
74
- default: S(() => [d(b(E), {
75
- "aria-label": I(r),
134
+ default: O(() => [h(E(M), {
135
+ "aria-label": $(r),
76
136
  "data-active": r.active ? "" : void 0,
77
137
  "data-disabled": r.disabled ? "" : void 0,
78
- class: m(N("link"))
138
+ class: y(W("link"))
79
139
  }, {
80
- default: S(() => [
81
- r.icon ? (h(), s(t, {
140
+ default: O(() => [
141
+ r.icon ? (b(), u(t, {
82
142
  key: 0,
83
143
  icon: r.icon
84
- }, null, 8, ["icon"])) : c("", !0),
85
- u("span", { class: m(N("linkLabel")) }, y(r.label), 3),
86
- d(t, {
87
- icon: b(C),
88
- class: m(N("groupIcon"))
144
+ }, null, 8, ["icon"])) : d("", !0),
145
+ p("span", { class: y(W("linkLabel")) }, T(r.label), 3),
146
+ h(t, {
147
+ icon: E(k),
148
+ class: y(W("groupIcon"))
89
149
  }, null, 8, ["icon", "class"])
90
150
  ]),
91
151
  _: 2
@@ -94,29 +154,29 @@ var O = /*@__PURE__*/ f({
94
154
  "data-active",
95
155
  "data-disabled",
96
156
  "class"
97
- ]), d(b(w), { class: m(N("groupContent")) }, {
98
- default: S(() => [u("div", { class: m(N("groupInner")) }, [(h(!0), l(a, null, g(r.items, (e) => (h(), s(v(P(e)), {
157
+ ]), h(E(A), { class: y(W("groupContent")) }, {
158
+ default: O(() => [p("div", { class: y(W("groupInner")) }, [(b(!0), f(c, null, S(r.items, (e) => (b(), u(w(J(e)), {
99
159
  key: e.label,
100
160
  href: e.href,
101
161
  type: e.href ? void 0 : "button",
102
- "aria-label": I(e),
162
+ "aria-label": $(e),
103
163
  "aria-current": e.active ? "page" : void 0,
104
164
  "aria-disabled": e.disabled || void 0,
105
165
  "data-active": e.active ? "" : void 0,
106
166
  "data-disabled": e.disabled ? "" : void 0,
107
- class: m(N("link")),
108
- onClick: (t) => F(e, t)
167
+ class: y(W("link")),
168
+ onClick: (t) => Q(e, t)
109
169
  }, {
110
- default: S(() => [
111
- e.icon ? (h(), s(t, {
170
+ default: O(() => [
171
+ e.icon ? (b(), u(t, {
112
172
  key: 0,
113
173
  icon: e.icon
114
- }, null, 8, ["icon"])) : c("", !0),
115
- u("span", { class: m(N("linkLabel")) }, y(e.label), 3),
116
- e.badge === void 0 ? c("", !0) : (h(), l("span", {
174
+ }, null, 8, ["icon"])) : d("", !0),
175
+ p("span", { class: y(W("linkLabel")) }, T(e.label), 3),
176
+ e.badge === void 0 ? d("", !0) : (b(), f("span", {
117
177
  key: 1,
118
- class: m(N("linkBadge"))
119
- }, y(e.badge), 3))
178
+ class: y(W("linkBadge"))
179
+ }, T(e.badge), 3))
120
180
  ]),
121
181
  _: 2
122
182
  }, 1032, [
@@ -133,48 +193,69 @@ var O = /*@__PURE__*/ f({
133
193
  _: 2
134
194
  }, 1032, ["class"])]),
135
195
  _: 2
136
- }, 1032, ["default-open", "disabled"])) : (h(), s(v(P(r)), {
137
- key: 1,
138
- href: r.href,
139
- type: r.href ? void 0 : "button",
140
- "aria-label": I(r),
141
- "aria-current": r.active ? "page" : void 0,
142
- "aria-disabled": r.disabled || void 0,
143
- "data-active": r.active ? "" : void 0,
144
- "data-disabled": r.disabled ? "" : void 0,
145
- class: m(N("link")),
146
- onClick: (e) => F(r, e)
196
+ }, 1032, [
197
+ "open",
198
+ "disabled",
199
+ "onUpdate:open"
200
+ ])) : (b(), u(a, {
201
+ key: 2,
202
+ text: X(r),
203
+ side: G.value,
204
+ disabled: !R.value,
205
+ unstyled: B.value
147
206
  }, {
148
- default: S(() => [_(e.$slots, "link", {
149
- link: r,
150
- collapsed: O.value
151
- }, () => [
152
- r.icon ? (h(), s(t, {
153
- key: 0,
154
- icon: r.icon
155
- }, null, 8, ["icon"])) : c("", !0),
156
- u("span", { class: m(N("linkLabel")) }, y(r.label), 3),
157
- r.badge === void 0 ? c("", !0) : (h(), l("span", {
158
- key: 1,
159
- class: m(N("linkBadge"))
160
- }, y(r.badge), 3))
161
- ])]),
207
+ trigger: O(() => [(b(), u(w(J(r)), {
208
+ href: r.href,
209
+ type: r.href ? void 0 : "button",
210
+ "aria-label": $(r),
211
+ "aria-current": r.active ? "page" : void 0,
212
+ "aria-disabled": r.disabled || void 0,
213
+ "data-active": r.active ? "" : void 0,
214
+ "data-disabled": r.disabled ? "" : void 0,
215
+ class: y(W("link")),
216
+ onClick: (e) => Q(r, e)
217
+ }, {
218
+ default: O(() => [C(e.$slots, "link", {
219
+ link: r,
220
+ collapsed: R.value
221
+ }, () => [
222
+ r.icon ? (b(), u(t, {
223
+ key: 0,
224
+ icon: r.icon
225
+ }, null, 8, ["icon"])) : R.value ? (b(), f("span", {
226
+ key: 1,
227
+ "aria-hidden": "true",
228
+ class: y(W("linkInitial"))
229
+ }, T(Y(r)), 3)) : d("", !0),
230
+ p("span", { class: y(W("linkLabel")) }, T(r.label), 3),
231
+ r.badge === void 0 ? d("", !0) : (b(), f("span", {
232
+ key: 2,
233
+ class: y(W("linkBadge"))
234
+ }, T(r.badge), 3))
235
+ ])]),
236
+ _: 2
237
+ }, 1032, [
238
+ "href",
239
+ "type",
240
+ "aria-label",
241
+ "aria-current",
242
+ "aria-disabled",
243
+ "data-active",
244
+ "data-disabled",
245
+ "class",
246
+ "onClick"
247
+ ]))]),
162
248
  _: 2
163
249
  }, 1032, [
164
- "href",
165
- "type",
166
- "aria-label",
167
- "aria-current",
168
- "aria-disabled",
169
- "data-active",
170
- "data-disabled",
171
- "class",
172
- "onClick"
173
- ]))], 64))), 128))], 2))), 128))])], 2),
174
- e.$slots.footer ? (h(), l("div", {
250
+ "text",
251
+ "side",
252
+ "disabled",
253
+ "unstyled"
254
+ ]))], 64))), 128))], 10, P))), 128))])], 2),
255
+ e.$slots.footer ? (b(), f("div", {
175
256
  key: 1,
176
- class: m(N("footer"))
177
- }, [_(e.$slots, "footer", { collapsed: O.value })], 2)) : c("", !0)
257
+ class: y(W("footer"))
258
+ }, [C(e.$slots, "footer", { collapsed: R.value })], 2)) : d("", !0)
178
259
  ]),
179
260
  _: 3
180
261
  }, 8, [
@@ -185,4 +266,4 @@ var O = /*@__PURE__*/ f({
185
266
  }
186
267
  });
187
268
  //#endregion
188
- export { O as default };
269
+ export { I as default };
@@ -20,7 +20,7 @@ export interface TextareaProps {
20
20
  /** Mark the field as invalid — styles the border and ring red. */
21
21
  invalid?: boolean;
22
22
  /** Hard limit in characters, enforced by the browser. */
23
- maxlength?: number;
23
+ maxlength?: number | string;
24
24
  /**
25
25
  * Show a character count under the field — "120/500" with `maxlength`,
26
26
  * turning red within the last tenth of the limit.
@@ -1,5 +1,5 @@
1
1
  export declare function defaultCountLabel(remaining: number): string;
2
- export declare function useCharacterCount(value: () => string | number | null | undefined, max: () => number | undefined): {
2
+ export declare function useCharacterCount(value: () => string | number | null | undefined, maxRaw: () => number | string | undefined): {
3
3
  remaining: import("vue").ComputedRef<number | undefined>;
4
4
  nearLimit: import("vue").ComputedRef<boolean>;
5
5
  text: import("vue").ComputedRef<string>;
@@ -4,14 +4,17 @@ function t(e) {
4
4
  return `${e} ${e === 1 ? "character" : "characters"} left`;
5
5
  }
6
6
  function n(t, n) {
7
- let r = e(() => String(t() ?? "").length), i = e(() => {
7
+ let r = () => {
8
8
  let e = n();
9
- return e == null ? void 0 : e - r.value;
9
+ return e == null || e === "" ? void 0 : Number(e);
10
+ }, i = e(() => String(t() ?? "").length), a = e(() => {
11
+ let e = r();
12
+ return e == null ? void 0 : e - i.value;
10
13
  });
11
14
  return {
12
- remaining: i,
13
- nearLimit: e(() => i.value != null && i.value <= Math.ceil(n() * .1)),
14
- text: e(() => n() == null ? `${r.value}` : `${r.value}/${n()}`)
15
+ remaining: a,
16
+ nearLimit: e(() => a.value != null && a.value <= Math.ceil(r() * .1)),
17
+ text: e(() => r() == null ? `${i.value}` : `${i.value}/${r()}`)
15
18
  };
16
19
  }
17
20
  //#endregion
@@ -6,6 +6,8 @@ export interface DropdownMenuItemOption {
6
6
  disabled?: boolean;
7
7
  /** Style the item as destructive. */
8
8
  danger?: boolean;
9
+ /** Renders the item as a link. */
10
+ href?: string;
9
11
  /** Run when the item is chosen. Omit on an entry that opens a submenu. */
10
12
  onSelect?: () => void;
11
13
  /** Nested entries. Turns this item into a submenu trigger. */
@@ -15,7 +17,7 @@ export interface DropdownMenuItemOption {
15
17
  * One row of a menu.
16
18
  *
17
19
  * `'-'` renders a separator. An option with `items` opens a submenu, and one
18
- * with neither `items` nor `onSelect` is a non-interactive group label.
20
+ * with none of `items`, `href` or `onSelect` is a non-interactive group label.
19
21
  */
20
22
  export type DropdownMenuEntry = DropdownMenuItemOption | '-';
21
23
  export declare function isSeparator(entry: DropdownMenuEntry): entry is '-';
@@ -1,3 +1,4 @@
1
+ import type { InjectionKey, Ref } from 'vue';
1
2
  import type { IconLike } from './icon';
2
3
  export interface SidebarLink {
3
4
  label: string;
@@ -27,9 +28,21 @@ export interface SidebarLink {
27
28
  export interface SidebarSection {
28
29
  section: string;
29
30
  items: SidebarLink[];
31
+ /** Push to the bottom of the column, above the footer. Pass `section: ''` for no heading. */
32
+ pinned?: boolean;
30
33
  }
31
34
  export type SidebarItems = (SidebarLink | SidebarSection)[];
35
+ /** Provided by `IAppShell` around each copy of its sidebar slot. */
36
+ export declare const sidebarPlacementKey: InjectionKey<'column' | 'drawer'>;
32
37
  export declare function isSidebarSection(item: SidebarLink | SidebarSection): item is SidebarSection;
33
38
  /** Normalise to sections, so the template has a single path to render. */
34
39
  export declare function toSidebarSections(items: SidebarItems | undefined): SidebarSection[];
35
40
  export declare function isSidebarGroup(link: SidebarLink): boolean;
41
+ export declare const sidebarCollapsedCookie = "iryx-ui-sidebar-collapsed";
42
+ /**
43
+ * Provide a ref read from the request cookie so the server renders the sidebar
44
+ * the way the user left it. The Nuxt module does this for you.
45
+ */
46
+ export declare const sidebarCollapsedKey: InjectionKey<Ref<boolean>>;
47
+ /** Collapsed state remembered in a cookie. Bind it with `v-model:collapsed`. */
48
+ export declare function useSidebarCollapsed(): Ref<boolean>;
@@ -1,23 +1,35 @@
1
+ import { inject as e, ref as t, watch as n } from "vue";
1
2
  //#region src/composables/sidebar.ts
2
- function e(e) {
3
+ var r = Symbol.for("iryx-ui:sidebar-placement");
4
+ function i(e) {
3
5
  return typeof e.section == "string";
4
6
  }
5
- function t(t) {
6
- let n = [], r;
7
- for (let i of t ?? []) {
8
- if (e(i)) {
9
- n.push(i), r = void 0;
7
+ function a(e) {
8
+ let t = [], n;
9
+ for (let r of e ?? []) {
10
+ if (i(r)) {
11
+ t.push(r), n = void 0;
10
12
  continue;
11
13
  }
12
- r || (r = [], n.push({
14
+ n || (n = [], t.push({
13
15
  section: "",
14
- items: r
15
- })), r.push(i);
16
+ items: n
17
+ })), n.push(r);
16
18
  }
17
- return n;
19
+ return [...t.filter((e) => !e.pinned), ...t.filter((e) => e.pinned)];
18
20
  }
19
- function n(e) {
21
+ function o(e) {
20
22
  return Array.isArray(e.items) && e.items.length > 0;
21
23
  }
24
+ var s = "iryx-ui-sidebar-collapsed", c = Symbol.for("iryx-ui:sidebar-collapsed");
25
+ function l() {
26
+ let r = e(c, null);
27
+ if (r) return r;
28
+ if (typeof document > "u") return t(!1);
29
+ let i = t(document.cookie.match(RegExp(`(?:^|; )${s}=([^;]*)`))?.[1] === "true");
30
+ return n(i, (e) => {
31
+ document.cookie = `${s}=${e}; path=/; max-age=31536000; samesite=lax`;
32
+ }), i;
33
+ }
22
34
  //#endregion
23
- export { n as isSidebarGroup, e as isSidebarSection, t as toSidebarSections };
35
+ export { o as isSidebarGroup, i as isSidebarSection, s as sidebarCollapsedCookie, c as sidebarCollapsedKey, r as sidebarPlacementKey, a as toSidebarSections, l as useSidebarCollapsed };