@kahitsan/ksui 0.45.0 → 0.46.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.
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@kahitsan/ksui",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.46.1",
|
|
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",
|
|
@@ -1,6 +1,5 @@
|
|
|
1
|
-
import { describe, expect, it, vi } from "vitest";
|
|
2
|
-
import { render } from "@solidjs/testing-library";
|
|
3
|
-
import { Show, createSignal } from "solid-js";
|
|
1
|
+
import { afterEach, beforeEach, describe, expect, it, vi } from "vitest";
|
|
2
|
+
import { cleanup, render } from "@solidjs/testing-library";
|
|
4
3
|
import Modal from "./Modal";
|
|
5
4
|
|
|
6
5
|
// Modal is the most critical shared widget — it wraps a native <dialog> with
|
|
@@ -68,4 +67,71 @@ describe("Modal", () => {
|
|
|
68
67
|
const card = container.querySelector(".ksui-modal-card")!;
|
|
69
68
|
expect(card.className).toContain("danger");
|
|
70
69
|
});
|
|
70
|
+
|
|
71
|
+
describe("sheet variant", () => {
|
|
72
|
+
// jsdom has no showModal()/close(); stand them in so a stacked dialog is open.
|
|
73
|
+
const proto = HTMLDialogElement.prototype;
|
|
74
|
+
const original = { showModal: proto.showModal, close: proto.close };
|
|
75
|
+
beforeEach(() => {
|
|
76
|
+
proto.showModal = function (this: HTMLDialogElement) {
|
|
77
|
+
this.setAttribute("open", "");
|
|
78
|
+
};
|
|
79
|
+
proto.close = function (this: HTMLDialogElement) {
|
|
80
|
+
this.removeAttribute("open");
|
|
81
|
+
};
|
|
82
|
+
});
|
|
83
|
+
afterEach(() => {
|
|
84
|
+
cleanup(); // unmount while the stubs still exist
|
|
85
|
+
proto.showModal = original.showModal;
|
|
86
|
+
proto.close = original.close;
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
it("calls onClose on Escape", () => {
|
|
90
|
+
const onClose = vi.fn();
|
|
91
|
+
render(() => (
|
|
92
|
+
<Modal variant="sheet" onClose={onClose}>
|
|
93
|
+
<p>sheet</p>
|
|
94
|
+
</Modal>
|
|
95
|
+
));
|
|
96
|
+
window.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true }));
|
|
97
|
+
expect(onClose).toHaveBeenCalledOnce();
|
|
98
|
+
});
|
|
99
|
+
|
|
100
|
+
it("leaves Escape to a dialog opened on top of it", () => {
|
|
101
|
+
const onSheetClose = vi.fn();
|
|
102
|
+
const onDialogClose = vi.fn();
|
|
103
|
+
const { container } = render(() => (
|
|
104
|
+
<Modal variant="sheet" onClose={onSheetClose}>
|
|
105
|
+
<Modal onClose={onDialogClose}>
|
|
106
|
+
<button type="button">inside</button>
|
|
107
|
+
</Modal>
|
|
108
|
+
</Modal>
|
|
109
|
+
));
|
|
110
|
+
const dialog = container.querySelector("dialog")!;
|
|
111
|
+
expect(dialog.open).toBe(true);
|
|
112
|
+
|
|
113
|
+
// A browser delivers Escape as keydown (bubbling to window) and then
|
|
114
|
+
// fires cancel on the topmost modal dialog.
|
|
115
|
+
dialog
|
|
116
|
+
.querySelector("button")!
|
|
117
|
+
.dispatchEvent(new KeyboardEvent("keydown", { key: "Escape", bubbles: true }));
|
|
118
|
+
dialog.dispatchEvent(new Event("cancel", { cancelable: true }));
|
|
119
|
+
|
|
120
|
+
expect(onSheetClose).not.toHaveBeenCalled();
|
|
121
|
+
expect(onDialogClose).toHaveBeenCalledOnce();
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
it("ignores an Escape keydown another handler already consumed", () => {
|
|
125
|
+
const onClose = vi.fn();
|
|
126
|
+
render(() => (
|
|
127
|
+
<Modal variant="sheet" onClose={onClose}>
|
|
128
|
+
<p>sheet</p>
|
|
129
|
+
</Modal>
|
|
130
|
+
));
|
|
131
|
+
const e = new KeyboardEvent("keydown", { key: "Escape", bubbles: true, cancelable: true });
|
|
132
|
+
e.preventDefault();
|
|
133
|
+
window.dispatchEvent(e);
|
|
134
|
+
expect(onClose).not.toHaveBeenCalled();
|
|
135
|
+
});
|
|
136
|
+
});
|
|
71
137
|
});
|
|
@@ -155,13 +155,28 @@ function DialogModal(local: LocalProps): JSX.Element {
|
|
|
155
155
|
);
|
|
156
156
|
}
|
|
157
157
|
|
|
158
|
+
function openModalDialogs(): HTMLDialogElement[] {
|
|
159
|
+
const open = [...document.querySelectorAll<HTMLDialogElement>("dialog[open]")];
|
|
160
|
+
try {
|
|
161
|
+
return open.filter((d) => d.matches(":modal"));
|
|
162
|
+
} catch {
|
|
163
|
+
// Engines without :modal support; treat every open dialog as modal.
|
|
164
|
+
return open;
|
|
165
|
+
}
|
|
166
|
+
}
|
|
167
|
+
|
|
158
168
|
function SheetModal(local: LocalProps, size?: ModalSize): JSX.Element {
|
|
169
|
+
let overlayEl: HTMLDivElement | undefined;
|
|
170
|
+
|
|
159
171
|
lockPullToRefresh();
|
|
160
172
|
onCleanup(unlockPullToRefresh);
|
|
161
173
|
|
|
162
174
|
const handleKey = (e: KeyboardEvent) => {
|
|
163
|
-
if (e.key !== "Escape") return;
|
|
175
|
+
if (e.key !== "Escape" || e.defaultPrevented) return;
|
|
164
176
|
if (local.dismissable === false) return;
|
|
177
|
+
// A modal <dialog> stacked above this sheet owns Escape (it gets `cancel`);
|
|
178
|
+
// closing here too would discard the sheet underneath.
|
|
179
|
+
if (openModalDialogs().some((d) => !d.contains(overlayEl ?? null))) return;
|
|
165
180
|
local.onClose();
|
|
166
181
|
};
|
|
167
182
|
if (typeof window !== "undefined") {
|
|
@@ -179,7 +194,7 @@ function SheetModal(local: LocalProps, size?: ModalSize): JSX.Element {
|
|
|
179
194
|
// ModalLayerContext value is already ambient (an outer DialogModal's
|
|
180
195
|
// dialogEl if nested inside one, otherwise the default null/document.body).
|
|
181
196
|
return (
|
|
182
|
-
<div class="ksui-modal-sheet-overlay">
|
|
197
|
+
<div ref={overlayEl} class="ksui-modal-sheet-overlay">
|
|
183
198
|
{/* eslint-disable-next-line jsx-a11y/click-events-have-key-events, jsx-a11y/no-static-element-interactions */}
|
|
184
199
|
<div class="ksui-modal-sheet-backdrop" onClick={handleBackdropClick} />
|
|
185
200
|
<div
|
|
@@ -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
|
|
643
|
-
|
|
644
|
-
|
|
645
|
-
|
|
646
|
-
|
|
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
|
-
|
|
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>
|