@marianmeres/stuic 3.70.0 → 3.70.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,12 +1,13 @@
1
1
  <script lang="ts" module>
2
2
  import type { HTMLAttributes } from "svelte/elements";
3
3
  import type { THC } from "../Thc/index.js";
4
+ import { tr, type MaybeLocalized } from "../../utils/tr.js";
4
5
  import { twMerge } from "../../utils/tw-merge.js";
5
6
  import Thc from "../Thc/Thc.svelte";
6
7
 
7
8
  export interface TabbedMenuItem {
8
9
  id: string | number;
9
- label: THC;
10
+ label: THC | MaybeLocalized;
10
11
  disabled?: boolean;
11
12
  class?: string;
12
13
  data?: Record<string, any>;
@@ -20,6 +21,8 @@
20
21
  disabled?: boolean;
21
22
  onSelect?: (item: TabbedMenuItem) => void;
22
23
  orientation?: "horizontal" | "vertical";
24
+ /** Current locale for MaybeLocalized resolution */
25
+ locale?: string;
23
26
  //
24
27
  class?: string;
25
28
  classItem?: string;
@@ -41,6 +44,7 @@
41
44
  disabled,
42
45
  onSelect,
43
46
  orientation = "horizontal",
47
+ locale,
44
48
  //
45
49
  class: classProp,
46
50
  classItem,
@@ -54,6 +58,26 @@
54
58
  ...rest
55
59
  }: Props = $props();
56
60
 
61
+ // The `label` accepts both THC and MaybeLocalized. Since MaybeLocalized's
62
+ // `Record<string, string>` shape has no discriminator key that Thc recognizes
63
+ // (`text`/`html`/`component`/`snippet`), a locale-keyed object would otherwise
64
+ // fall through to Thc's string-cast fallback and render as `[object Object]`.
65
+ // So we detect that case here and resolve it via `tr()` before handing to Thc.
66
+ function resolveLabel(label: TabbedMenuItem["label"]): THC {
67
+ if (
68
+ label &&
69
+ typeof label === "object" &&
70
+ typeof label !== "function" &&
71
+ !("text" in label) &&
72
+ !("html" in label) &&
73
+ !("component" in label) &&
74
+ !("snippet" in label)
75
+ ) {
76
+ return tr(label as MaybeLocalized, locale);
77
+ }
78
+ return label as THC;
79
+ }
80
+
57
81
  let buttonEls = $state<Record<string | number, HTMLButtonElement | HTMLAnchorElement>>(
58
82
  {}
59
83
  );
@@ -136,11 +160,11 @@
136
160
  >
137
161
  {#if item.href}
138
162
  <a href={item.href} {...props} bind:this={buttonEls[item.id]}>
139
- <Thc thc={item.label} />
163
+ <Thc thc={resolveLabel(item.label)} />
140
164
  </a>
141
165
  {:else}
142
166
  <button type="button" {...props} bind:this={buttonEls[item.id]}>
143
- <Thc thc={item.label} />
167
+ <Thc thc={resolveLabel(item.label)} />
144
168
  </button>
145
169
  {/if}
146
170
  </li>
@@ -1,8 +1,9 @@
1
1
  import type { HTMLAttributes } from "svelte/elements";
2
2
  import type { THC } from "../Thc/index.js";
3
+ import { type MaybeLocalized } from "../../utils/tr.js";
3
4
  export interface TabbedMenuItem {
4
5
  id: string | number;
5
- label: THC;
6
+ label: THC | MaybeLocalized;
6
7
  disabled?: boolean;
7
8
  class?: string;
8
9
  data?: Record<string, any>;
@@ -15,6 +16,8 @@ export interface Props extends Omit<HTMLAttributes<HTMLUListElement>, "children"
15
16
  disabled?: boolean;
16
17
  onSelect?: (item: TabbedMenuItem) => void;
17
18
  orientation?: "horizontal" | "vertical";
19
+ /** Current locale for MaybeLocalized resolution */
20
+ locale?: string;
18
21
  class?: string;
19
22
  classItem?: string;
20
23
  classButton?: string;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@marianmeres/stuic",
3
- "version": "3.70.0",
3
+ "version": "3.70.1",
4
4
  "files": [
5
5
  "dist",
6
6
  "!dist/**/*.test.*",