@kahitsan/ksui 0.47.2 → 0.48.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.
|
|
3
|
+
"version": "0.48.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",
|
|
@@ -52,6 +52,9 @@ interface ComboBoxCommonProps<T> {
|
|
|
52
52
|
icon: (p: { size?: number; class?: string }) => JSX.Element;
|
|
53
53
|
/** Singular noun for UI copy: "payee", "client". */
|
|
54
54
|
noun: string;
|
|
55
|
+
/** Custom text for the create row, given the typed name. Defaults to
|
|
56
|
+
* `New <noun> "<name>"`. */
|
|
57
|
+
createLabel?: (name: string) => string;
|
|
55
58
|
|
|
56
59
|
placeholder?: string;
|
|
57
60
|
disabled?: boolean;
|
|
@@ -303,7 +306,12 @@ function SingleComboBox<T>(props: ComboBoxSingleProps<T>): JSX.Element {
|
|
|
303
306
|
<UserPlus size={14} class="text-[var(--ks-success-fg,#34d399)] shrink-0" />
|
|
304
307
|
</Show>
|
|
305
308
|
<span class="text-sm text-[var(--ks-success-fg,#34d399)]">
|
|
306
|
-
|
|
309
|
+
<Show
|
|
310
|
+
when={props.createLabel}
|
|
311
|
+
fallback={<>New {props.noun} "<span class="font-medium">{eng.trimmedQuery()}</span>"</>}
|
|
312
|
+
>
|
|
313
|
+
{(label) => label()(eng.trimmedQuery())}
|
|
314
|
+
</Show>
|
|
307
315
|
</span>
|
|
308
316
|
</button>
|
|
309
317
|
</div>
|
|
@@ -606,7 +614,12 @@ function MultiComboBox<T>(props: ComboBoxMultiProps<T>): JSX.Element {
|
|
|
606
614
|
<UserPlus size={14} class="text-[var(--ks-success-fg,#34d399)] shrink-0 mt-0.5" />
|
|
607
615
|
</Show>
|
|
608
616
|
<span class="flex-1 text-[var(--ks-success-fg,#34d399)]">
|
|
609
|
-
|
|
617
|
+
<Show
|
|
618
|
+
when={props.createLabel}
|
|
619
|
+
fallback={<>New {props.noun} "<span class="font-medium">{eng.trimmedQuery()}</span>"</>}
|
|
620
|
+
>
|
|
621
|
+
{(label) => label()(eng.trimmedQuery())}
|
|
622
|
+
</Show>
|
|
610
623
|
</span>
|
|
611
624
|
</button>
|
|
612
625
|
</Show>
|
|
@@ -720,3 +720,18 @@ describe("VoucherPicker dialog", () => {
|
|
|
720
720
|
document.removeEventListener("keydown", ancestorEsc);
|
|
721
721
|
});
|
|
722
722
|
});
|
|
723
|
+
|
|
724
|
+
describe("VoucherPicker applyOnSelect", () => {
|
|
725
|
+
it("applies on tap, closes, and shows no Apply footer", async () => {
|
|
726
|
+
mockPagedFetch([voucher({ id: 1, code: "TAP_ME" })]);
|
|
727
|
+
const onChange = vi.fn();
|
|
728
|
+
const { getByTestId, queryByTestId, findByTestId } = render(() => (
|
|
729
|
+
<VoucherPicker selected={null} onChange={onChange} subtotal={100} packageIds={[]} applyOnSelect />
|
|
730
|
+
));
|
|
731
|
+
fireEvent.click(getByTestId("voucher-picker-trigger"));
|
|
732
|
+
expect(queryByTestId("voucher-picker-confirm")).toBeNull();
|
|
733
|
+
fireEvent.click(await findByTestId("voucher-picker-result-1"));
|
|
734
|
+
expect(onChange).toHaveBeenCalledWith(expect.objectContaining({ id: 1 }));
|
|
735
|
+
await waitFor(() => expect(queryByTestId("voucher-picker-popup")).toBeNull());
|
|
736
|
+
});
|
|
737
|
+
});
|
|
@@ -54,6 +54,9 @@ interface VoucherPickerProps {
|
|
|
54
54
|
* preview a discount RANGE while `subtotal` is still 0, instead of a
|
|
55
55
|
* meaningless zero. */
|
|
56
56
|
subtotalRange?: { min: number; max: number };
|
|
57
|
+
/** Apply a voucher the moment its row is tapped and drop the staged
|
|
58
|
+
* Apply/Cancel footer. Off by default (select, then confirm). */
|
|
59
|
+
applyOnSelect?: boolean;
|
|
57
60
|
}
|
|
58
61
|
|
|
59
62
|
function asNumber(v: string | number | null | undefined): number {
|
|
@@ -333,6 +336,11 @@ export default function VoucherPicker(props: VoucherPickerProps): JSX.Element {
|
|
|
333
336
|
// Picking a row only stages it; nothing reaches the cart until Confirm, so a
|
|
334
337
|
// mis-tap on a touch screen can be corrected without re-opening the dialog.
|
|
335
338
|
const stage = (v: VoucherOption) => {
|
|
339
|
+
if (props.applyOnSelect) {
|
|
340
|
+
props.onChange(props.selected?.id === v.id ? null : v);
|
|
341
|
+
close();
|
|
342
|
+
return;
|
|
343
|
+
}
|
|
336
344
|
setDraft((current) => (current?.id === v.id ? null : v));
|
|
337
345
|
};
|
|
338
346
|
|
|
@@ -455,7 +463,7 @@ export default function VoucherPicker(props: VoucherPickerProps): JSX.Element {
|
|
|
455
463
|
</button>
|
|
456
464
|
|
|
457
465
|
<Show when={open()}>
|
|
458
|
-
<Modal onClose={close} size="xl" ariaLabel="Select a voucher">
|
|
466
|
+
<Modal onClose={close} size="xl" ariaLabel={props.applyOnSelect ? "Choose a voucher" : "Select a voucher"}>
|
|
459
467
|
<div data-testid="voucher-picker-popup" class="flex flex-col max-h-[70vh]">
|
|
460
468
|
{/* Bled to the card edges (the card owns the padding) so the rule
|
|
461
469
|
under the title spans the full width. */}
|
|
@@ -463,7 +471,7 @@ export default function VoucherPicker(props: VoucherPickerProps): JSX.Element {
|
|
|
463
471
|
<div class="flex items-center gap-2 min-w-0">
|
|
464
472
|
<Ticket size={16} class="text-[var(--ks-fg-muted,#a1a1aa)] shrink-0" aria-hidden="true" />
|
|
465
473
|
<h2 class="m-0 text-base font-semibold text-[var(--ks-fg,#ffffff)] truncate">
|
|
466
|
-
Select a voucher
|
|
474
|
+
{props.applyOnSelect ? "Choose a voucher" : "Select a voucher"}
|
|
467
475
|
</h2>
|
|
468
476
|
<Show when={loading()}>
|
|
469
477
|
<Loader2 size={14} class="animate-spin text-[var(--ks-fg-subtle,#71717a)] shrink-0" />
|
|
@@ -487,7 +495,7 @@ export default function VoucherPicker(props: VoucherPickerProps): JSX.Element {
|
|
|
487
495
|
data-testid="voucher-picker-search"
|
|
488
496
|
value={query()}
|
|
489
497
|
onInput={(e) => setQuery(e.currentTarget.value)}
|
|
490
|
-
placeholder="Search voucher code…"
|
|
498
|
+
placeholder={props.applyOnSelect ? "Search code or name" : "Search voucher code…"}
|
|
491
499
|
aria-label="Search voucher code"
|
|
492
500
|
class="flex-1 min-w-0 bg-transparent border-0 outline-none text-sm text-[var(--ks-fg,#ffffff)] placeholder:text-[var(--ks-fg-subtle,#71717a)]"
|
|
493
501
|
/>
|
|
@@ -641,6 +649,7 @@ export default function VoucherPicker(props: VoucherPickerProps): JSX.Element {
|
|
|
641
649
|
|
|
642
650
|
{/* Bled to the card edges so the rule spans the full width, matching
|
|
643
651
|
the header. */}
|
|
652
|
+
<Show when={!props.applyOnSelect}>
|
|
644
653
|
<div class="-mx-6 -mb-6 mt-4 px-5 sm:px-6 py-3 border-t border-[color-mix(in_srgb,var(--ks-border,rgba(39,39,42,0.5))_60%,transparent)] flex items-center justify-between gap-3 shrink-0">
|
|
645
654
|
<div class="min-w-0 flex flex-col gap-1">
|
|
646
655
|
<Show
|
|
@@ -712,6 +721,7 @@ export default function VoucherPicker(props: VoucherPickerProps): JSX.Element {
|
|
|
712
721
|
</button>
|
|
713
722
|
</div>
|
|
714
723
|
</div>
|
|
724
|
+
</Show>
|
|
715
725
|
</div>
|
|
716
726
|
</Modal>
|
|
717
727
|
</Show>
|