@kahitsan/ksui 0.45.0 → 0.46.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.45.0",
3
+ "version": "0.46.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",
@@ -0,0 +1,130 @@
1
+ // The date field is a date-only picker by default; supplying `setTime` turns it
2
+ // into one native date-and-time input.
3
+ import { describe, expect, it, vi } from "vitest";
4
+ import { render, fireEvent } from "@solidjs/testing-library";
5
+ import TransactionForm, { type TransactionFormProps } from "./TransactionForm";
6
+
7
+ function baseProps(overrides: Partial<TransactionFormProps> = {}): TransactionFormProps {
8
+ const noop = vi.fn();
9
+ return {
10
+ error: "",
11
+ saving: false,
12
+ category: "expense",
13
+ setCategory: noop,
14
+ subcategory: "",
15
+ setSubcategory: noop,
16
+ sourceAccount: "",
17
+ setSourceAccount: noop,
18
+ destAccount: "",
19
+ setDestAccount: noop,
20
+ amount: "",
21
+ setAmount: noop,
22
+ description: "",
23
+ setDescription: noop,
24
+ notes: "",
25
+ setNotes: noop,
26
+ date: "2026-09-10",
27
+ setDate: noop,
28
+ isPrivate: false,
29
+ setIsPrivate: noop,
30
+ sharedWith: [],
31
+ setSharedWith: noop,
32
+ sharedRoleCodes: [],
33
+ setSharedRoleCodes: noop,
34
+ backdateReason: "",
35
+ setBackdateReason: noop,
36
+ payee: "",
37
+ setPayee: noop,
38
+ payeeId: null,
39
+ setPayeeId: noop,
40
+ refNumber: "",
41
+ setRefNumber: noop,
42
+ taxType: "vat_inclusive",
43
+ setTaxType: noop,
44
+ hasEwt: false,
45
+ setHasEwt: noop,
46
+ ewtRate: "",
47
+ setEwtRate: noop,
48
+ payableKind: "",
49
+ setPayableKind: noop,
50
+ dueDate: "",
51
+ setDueDate: noop,
52
+ chequeNumber: "",
53
+ setChequeNumber: noop,
54
+ pdcStatus: "",
55
+ setPdcStatus: noop,
56
+ transferFeeEnabled: false,
57
+ setTransferFeeEnabled: noop,
58
+ transferFeeAmount: "",
59
+ setTransferFeeAmount: noop,
60
+ allowTransferFee: false,
61
+ pendingFiles: [],
62
+ setPendingFiles: noop,
63
+ accounts: [],
64
+ orgMembers: [],
65
+ shareableRoles: [],
66
+ isAdmin: true,
67
+ canShare: false,
68
+ isBackdated: false,
69
+ saleItems: [],
70
+ setSaleItems: noop,
71
+ saleClient: null,
72
+ setSaleClient: noop,
73
+ saleVoucher: null,
74
+ setSaleVoucher: noop,
75
+ saleManualDiscount: "",
76
+ setSaleManualDiscount: noop,
77
+ onSubmit: noop,
78
+ submitLabel: "Save",
79
+ ...overrides,
80
+ };
81
+ }
82
+
83
+ describe("TransactionForm date and time", () => {
84
+ it("keeps the date-only picker when no time setter is supplied", () => {
85
+ const { queryByTestId, getByText } = render(() => <TransactionForm {...baseProps()} />);
86
+ expect(queryByTestId("transactions-form-datetime")).toBeNull();
87
+ expect(getByText("Date *")).toBeTruthy();
88
+ });
89
+
90
+ it("shows one date-and-time input holding both values", () => {
91
+ const { getByTestId, getByText } = render(() => (
92
+ <TransactionForm {...baseProps({ time: "09:30:15", setTime: vi.fn() })} />
93
+ ));
94
+ const input = getByTestId("transactions-form-datetime") as HTMLInputElement;
95
+ expect(input.type).toBe("datetime-local");
96
+ expect(input.value).toBe("2026-09-10T09:30");
97
+ expect(getByText("Date & time *")).toBeTruthy();
98
+ });
99
+
100
+ it("splits an edit into the date and the time", () => {
101
+ const setDate = vi.fn();
102
+ const setTime = vi.fn();
103
+ const { getByTestId } = render(() => (
104
+ <TransactionForm {...baseProps({ time: "09:30", setDate, setTime })} />
105
+ ));
106
+ const input = getByTestId("transactions-form-datetime") as HTMLInputElement;
107
+ fireEvent.input(input, { target: { value: "2026-09-11T18:45" } });
108
+ expect(setDate).toHaveBeenCalledWith("2026-09-11");
109
+ expect(setTime).toHaveBeenCalledWith("18:45");
110
+ });
111
+
112
+ it("ignores a cleared value instead of wiping the date", () => {
113
+ const setDate = vi.fn();
114
+ const setTime = vi.fn();
115
+ const { getByTestId } = render(() => (
116
+ <TransactionForm {...baseProps({ time: "09:30", setDate, setTime })} />
117
+ ));
118
+ fireEvent.input(getByTestId("transactions-form-datetime"), { target: { value: "" } });
119
+ expect(setDate).not.toHaveBeenCalled();
120
+ expect(setTime).not.toHaveBeenCalled();
121
+ });
122
+
123
+ it("locks the field and says why for non-admins", () => {
124
+ const { getByTestId, getByText } = render(() => (
125
+ <TransactionForm {...baseProps({ time: "09:30", setTime: vi.fn(), isAdmin: false })} />
126
+ ));
127
+ expect((getByTestId("transactions-form-datetime") as HTMLInputElement).disabled).toBe(true);
128
+ expect(getByText("Only admins can change the date and time")).toBeTruthy();
129
+ });
130
+ });
@@ -231,6 +231,11 @@ export interface TransactionFormProps {
231
231
  setNotes: (v: string) => void;
232
232
  date: string;
233
233
  setDate: (v: string) => void;
234
+ /** Wall-clock time of day for the transaction, `HH:MM` or `HH:MM:SS`.
235
+ * Supplying `setTime` switches the date field to a single native
236
+ * date-and-time input; leave both out to keep the date-only picker. */
237
+ time?: string;
238
+ setTime?: (v: string) => void;
234
239
  isPrivate: boolean;
235
240
  setIsPrivate: (v: boolean) => void;
236
241
  sharedWith: string[];
@@ -329,6 +334,10 @@ export default function TransactionForm(props: TransactionFormProps) {
329
334
  `,
330
335
  );
331
336
  const compact = () => props.layout === "compact";
337
+ const withTime = () => typeof props.setTime === "function";
338
+ // datetime-local wants exactly YYYY-MM-DDTHH:MM; a missing date reads as empty.
339
+ const dateTimeValue = () =>
340
+ props.date ? `${props.date}T${(props.time || "00:00").slice(0, 5)}` : "";
332
341
  const catConfig = () =>
333
342
  CATEGORY_FORM[props.category] || CATEGORY_FORM.expense;
334
343
  const [dragging, setDragging] = createSignal(false);
@@ -639,15 +648,48 @@ export default function TransactionForm(props: TransactionFormProps) {
639
648
  </Show>
640
649
 
641
650
  <div class={compact() ? "ks-transaction-compact-date" : undefined}>
642
- <FormField label={compact() ? "TRANSACTION DATE" : "Date *"}>
643
- <DatePicker
644
- value={props.date}
645
- onChange={(d: string | null) => d && props.setDate(d)}
646
- disabled={!props.isAdmin}
647
- />
651
+ <FormField
652
+ label={
653
+ withTime()
654
+ ? compact()
655
+ ? "TRANSACTION DATE & TIME"
656
+ : "Date & time *"
657
+ : compact()
658
+ ? "TRANSACTION DATE"
659
+ : "Date *"
660
+ }
661
+ >
662
+ <Show
663
+ when={withTime()}
664
+ fallback={
665
+ <DatePicker
666
+ value={props.date}
667
+ onChange={(d: string | null) => d && props.setDate(d)}
668
+ disabled={!props.isAdmin}
669
+ />
670
+ }
671
+ >
672
+ <input
673
+ type="datetime-local"
674
+ data-testid="transactions-form-datetime"
675
+ aria-label="Transaction date and time"
676
+ value={dateTimeValue()}
677
+ disabled={!props.isAdmin}
678
+ required
679
+ onInput={(e) => {
680
+ const v = e.currentTarget.value;
681
+ if (!/^\d{4}-\d{2}-\d{2}T\d{2}:\d{2}/.test(v)) return;
682
+ props.setDate(v.slice(0, 10));
683
+ props.setTime?.(v.slice(11, 16));
684
+ }}
685
+ class="w-full bg-[color-mix(in_srgb,var(--ks-overlay-surface,#18181b)_60%,transparent)] border border-[color-mix(in_srgb,var(--ks-border,rgba(39,39,42,0.5))_60%,transparent)] px-3 py-3 text-sm text-[var(--ks-fg,#ffffff)] ks-hud-clip-button focus:outline-none focus:border-[color-mix(in_srgb,var(--ks-focus-ring,#c9a961)_50%,transparent)] disabled:opacity-60"
686
+ />
687
+ </Show>
648
688
  <Show when={!props.isAdmin}>
649
689
  <p class="text-[10px] text-[var(--ks-fg-subtle,#71717a)] mt-0.5">
650
- Only admins can change the date
690
+ {withTime()
691
+ ? "Only admins can change the date and time"
692
+ : "Only admins can change the date"}
651
693
  </p>
652
694
  </Show>
653
695
  </FormField>