@kahitsan/ksui 0.36.0 → 0.37.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.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@kahitsan/ksui",
3
- "version": "0.36.0",
3
+ "version": "0.37.0",
4
4
  "description": "ksui is a standalone set of SolidJS UI components for KahitSan/Hilinga and any SolidJS app. Published to the public npm registry and consumed as a normal dependency. Ships source under a `solid` export condition so the consumer's vite-plugin-solid compiles it with only solid-js externalized; it depends on nothing but solid-js + lucide-solid and injects its own CSS.",
5
5
  "type": "module",
6
6
  "main": "./src/index.ts",
@@ -32,6 +32,10 @@ const styles: Record<string, string> = {
32
32
  "animate-shimmer": "ks-progress-shimmer",
33
33
  };
34
34
 
35
+ // ProgressColor is derived from COLOR_MAP so adding a hue later flows here
36
+ // without re-syncing a hardcoded list.
37
+ export type ProgressColor = keyof typeof COLOR_MAP;
38
+
35
39
  export interface ProgressBarProps extends JSX.HTMLAttributes<HTMLDivElement> {
36
40
  progress: number;
37
41
  icon?: Component<{ size: number; class?: string }>;
@@ -45,6 +49,9 @@ export interface ProgressBarProps extends JSX.HTMLAttributes<HTMLDivElement> {
45
49
  // LiveTimer push the live countdown into the right slot while the
46
50
  // total label sits on the left.
47
51
  rightLabel?: string;
52
+ // Explicit color signal — class-substring sniffing broke when COLOR_AMBER
53
+ // was tokenized (4f6ed40 dropped the literal "amber" from the class).
54
+ color?: ProgressColor;
48
55
  class?: string;
49
56
  }
50
57
 
@@ -163,6 +170,7 @@ const ProgressBar: Component<ProgressBarProps> = (props) => {
163
170
  "position",
164
171
  "hidePercentage",
165
172
  "rightLabel",
173
+ "color",
166
174
  "class",
167
175
  ]);
168
176
 
@@ -184,7 +192,12 @@ const ProgressBar: Component<ProgressBarProps> = (props) => {
184
192
  return { progress: Math.max(0, Math.min(100, raw)), overflow: Math.max(0, raw - 100) };
185
193
  });
186
194
 
187
- const colorInfo = createMemo(() => extractColorInfo(classProp() ?? ""));
195
+ const colorInfo = createMemo(() => {
196
+ // Explicit color wins; fall back to class-substring sniffing for back-compat
197
+ // with every caller that still drives color via a "text-red-400"-style class.
198
+ if (local.color) return COLOR_MAP[local.color];
199
+ return extractColorInfo(classProp() ?? "");
200
+ });
188
201
  const iconSize = createMemo(() => extractTextSize(classProp() ?? ""));
189
202
 
190
203
  const containerClasses = createMemo(() =>
@@ -11,7 +11,7 @@ import Play from "lucide-solid/icons/play";
11
11
  import AlertTriangle from "lucide-solid/icons/triangle-alert";
12
12
  import Check from "lucide-solid/icons/check";
13
13
  import Calendar from "lucide-solid/icons/calendar";
14
- import ProgressBar from "../base/ProgressBar";
14
+ import ProgressBar, { type ProgressColor } from "../base/ProgressBar";
15
15
 
16
16
  export interface LiveTimerProps extends Omit<JSX.HTMLAttributes<HTMLDivElement>, "class"> {
17
17
  // Core timing
@@ -354,6 +354,29 @@ const LiveTimer: Component<LiveTimerProps> = (props) => {
354
354
  return staticConfig().colorClass;
355
355
  });
356
356
 
357
+ // Mirrors colorClass's scenario logic but returns a COLOR_MAP key for
358
+ // ProgressBar's `color` prop — the class strings above were tokenized
359
+ // (4f6ed40) so the fill's class-substring sniff can no longer recover
360
+ // the hue. COMPLETED had no color substring even pre-tokenization, so it
361
+ // relies on the explicit prop rather than ever reaching the back-compat path.
362
+ const colorName = createMemo<ProgressColor>(() => {
363
+ switch (scenario()) {
364
+ case SCENARIO_COUNTDOWN_TIMER: {
365
+ const p = progress();
366
+ return p <= 25 ? "green" : p <= 75 ? "amber" : "red";
367
+ }
368
+ case SCENARIO_COUNTDOWN_TO_START:
369
+ return "blue";
370
+ case SCENARIO_OPEN_TIMER:
371
+ return "green";
372
+ case SCENARIO_OVERDUE:
373
+ return "purple";
374
+ case SCENARIO_COMPLETED:
375
+ default:
376
+ return "slate";
377
+ }
378
+ });
379
+
357
380
  const finalClass = createMemo(() => {
358
381
  const user = local.class ?? "";
359
382
  if (user.includes("border-") && user.includes("text-")) return user;
@@ -410,6 +433,7 @@ const LiveTimer: Component<LiveTimerProps> = (props) => {
410
433
  position={staticConfig().position}
411
434
  hidePercentage={resolvedHidePercentage()}
412
435
  shimmer={staticConfig().shimmer}
436
+ color={colorName()}
413
437
  class={finalClass()}
414
438
  {...others}
415
439
  />
@@ -424,6 +448,7 @@ const LiveTimer: Component<LiveTimerProps> = (props) => {
424
448
  hidePercentage
425
449
  rightLabel={statusLabel()}
426
450
  shimmer={staticConfig().shimmer}
451
+ color={colorName()}
427
452
  class={finalClass()}
428
453
  {...others}
429
454
  />
@@ -0,0 +1,51 @@
1
+ // fetchUrl prop threading — the default stays the vouchers plugin's own API so
2
+ // existing consumers are unaffected; a consumer without vouchers.view can
3
+ // point the picker at a peer proxy route with the same response shape.
4
+ import { describe, expect, it, vi } from "vitest";
5
+ import { fireEvent, render, waitFor } from "@solidjs/testing-library";
6
+ import VoucherPicker from "./VoucherPicker";
7
+
8
+ function mockFetchOnce(): typeof fetch {
9
+ const impl = vi.fn(async () => ({
10
+ ok: true,
11
+ json: async () => ({ data: [] }),
12
+ })) as unknown as typeof fetch;
13
+ vi.stubGlobal("fetch", impl);
14
+ return impl;
15
+ }
16
+
17
+ describe("VoucherPicker fetchUrl", () => {
18
+ it("defaults to the vouchers plugin's own API when fetchUrl is omitted", async () => {
19
+ const fetchMock = mockFetchOnce();
20
+ const { getByTestId } = render(() => (
21
+ <VoucherPicker selected={null} onChange={vi.fn()} subtotal={100} packageIds={[]} />
22
+ ));
23
+ fireEvent.click(getByTestId("voucher-picker-trigger"));
24
+
25
+ await waitFor(() => expect(fetchMock).toHaveBeenCalled());
26
+ expect(fetchMock).toHaveBeenCalledWith(
27
+ "/api/vouchers?status=active&limit=200",
28
+ expect.objectContaining({ credentials: "include" }),
29
+ );
30
+ });
31
+
32
+ it("fetches the overridden URL when fetchUrl is provided", async () => {
33
+ const fetchMock = mockFetchOnce();
34
+ const { getByTestId } = render(() => (
35
+ <VoucherPicker
36
+ selected={null}
37
+ onChange={vi.fn()}
38
+ subtotal={100}
39
+ packageIds={[]}
40
+ fetchUrl="/api/counter/vouchers"
41
+ />
42
+ ));
43
+ fireEvent.click(getByTestId("voucher-picker-trigger"));
44
+
45
+ await waitFor(() => expect(fetchMock).toHaveBeenCalled());
46
+ expect(fetchMock).toHaveBeenCalledWith(
47
+ "/api/counter/vouchers",
48
+ expect.objectContaining({ credentials: "include" }),
49
+ );
50
+ });
51
+ });
@@ -1,9 +1,11 @@
1
1
  // Vendored into plugin remotes.
2
2
  //
3
- // Cross-plugin picker: fetches the SIBLING vouchers plugin's public API at
4
- // /api/vouchers and degrades gracefully: when the vouchers plugin isn't
5
- // deployed the popup shows a "couldn't load" notice and the sale records with
6
- // no voucher (the manual-discount field stays available).
3
+ // Cross-plugin picker: fetches vouchers over HTTP and degrades gracefully:
4
+ // when the endpoint isn't reachable the popup shows a "couldn't load" notice
5
+ // and the sale records with no voucher (the manual-discount field stays
6
+ // available). Defaults to the vouchers plugin's own public API
7
+ // (/api/vouchers); `fetchUrl` overrides it for a consumer that reaches
8
+ // vouchers through a peer proxy route instead (same response shape required).
7
9
 
8
10
  import { Portal } from "solid-js/web";
9
11
  import { createEffect, createMemo, createSignal, For, onCleanup, Show, type JSX } from "solid-js";
@@ -24,6 +26,8 @@ export interface VoucherOption {
24
26
  is_active: boolean;
25
27
  }
26
28
 
29
+ const DEFAULT_FETCH_URL = "/api/vouchers?status=active&limit=200";
30
+
27
31
  interface VoucherPickerProps {
28
32
  selected: VoucherOption | null;
29
33
  onChange: (next: VoucherOption | null) => void;
@@ -31,6 +35,10 @@ interface VoucherPickerProps {
31
35
  packageIds: number[];
32
36
  disabled?: boolean;
33
37
  compact?: boolean;
38
+ /** Same-shape endpoint override (defaults to the vouchers plugin's own API) —
39
+ * a consumer with no `vouchers.view` grant can point this at a peer proxy
40
+ * route instead. */
41
+ fetchUrl?: string;
34
42
  }
35
43
 
36
44
  const POPUP_MAX_HEIGHT = 360;
@@ -105,7 +113,7 @@ export default function VoucherPicker(props: VoucherPickerProps): JSX.Element {
105
113
  const token = ++activeFetchToken;
106
114
  setLoading(true);
107
115
  setError(null);
108
- fetch("/api/vouchers?status=active&limit=200", { credentials: "include" })
116
+ fetch(props.fetchUrl ?? DEFAULT_FETCH_URL, { credentials: "include" })
109
117
  .then((r) => {
110
118
  if (!r.ok)
111
119
  throw new Error(