@celestia-island/hikari 0.55.236 → 0.55.238
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 +1 -1
- package/src/DemoApp.tsx +4 -1
- package/src/components/HkFaceShell.rail.test.tsx +35 -0
- package/src/components/HkFaceShell.tsx +27 -6
- package/src/components/HkInput.number.test.tsx +219 -0
- package/src/components/HkInput.scss +32 -0
- package/src/components/HkInput.tsx +93 -11
- package/src/components/HkNumberInput.affix.test.ts +11 -3
- package/src/components/HkNumberInput.scss +3 -66
- package/src/components/HkNumberInput.tsx +12 -81
- package/src/components/HkNumberSteppers.scss +85 -0
- package/src/components/HkNumberSteppers.test.tsx +267 -0
- package/src/components/HkNumberSteppers.tsx +158 -0
- package/src/components/HkSidebar.rail.test.tsx +44 -6
- package/src/components/HkSidebar.scss +9 -1
- package/src/components/HkSidebar.styles.test.ts +8 -2
- package/src/components/HkSidebar.tsx +70 -24
- package/src/components/HkSidebarRail.scss +44 -0
- package/src/components/HkSidebarRail.styles.test.ts +25 -0
- package/src/components/HkSidebarRailSwap.test.tsx +254 -0
- package/src/components/HkSidebarRailSwap.tsx +102 -0
- package/src/index.ts +6 -0
package/package.json
CHANGED
package/src/DemoApp.tsx
CHANGED
|
@@ -360,12 +360,15 @@ export default defineComponent({
|
|
|
360
360
|
</section>
|
|
361
361
|
|
|
362
362
|
<section>
|
|
363
|
-
<h2>HInput (text / password) / HSearchInput / HNumberInput / HTextarea</h2>
|
|
363
|
+
<h2>HInput (text / password / number) / HSearchInput / HNumberInput / HTextarea</h2>
|
|
364
364
|
<div class="form-grid">
|
|
365
365
|
<HInput modelValue={form.value.text} onUpdate:modelValue={(v: string) => (form.value.text = v)} placeholder="Text input" />
|
|
366
366
|
<HInput modelValue={form.value.text} onUpdate:modelValue={(v: string) => (form.value.text = v)} placeholder="Disabled" disabled />
|
|
367
367
|
<HSearchInput modelValue={form.value.search} onUpdate:modelValue={(v: string | number) => (form.value.search = String(v))} placeholder="Search..." />
|
|
368
368
|
<HNumberInput modelValue={form.value.number} onUpdate:modelValue={(v: number) => (form.value.number = v)} placeholder="Number" />
|
|
369
|
+
{/* The plain input's number variant — same shared lucide stepper
|
|
370
|
+
column, no browser-native spin buttons. */}
|
|
371
|
+
<HInput type="number" modelValue={String(form.value.number)} onUpdate:modelValue={(v: string) => (form.value.number = v === "" ? 0 : Number(v))} placeholder="Number (steppers)" />
|
|
369
372
|
<HInput variant="password" modelValue={form.value.password} onUpdate:modelValue={(v: string) => (form.value.password = v)} placeholder="Password (filter reveal — default)" />
|
|
370
373
|
<HInput variant="password" revealStrategy="sweep" modelValue={form.value.password} onUpdate:modelValue={(v: string) => (form.value.password = v)} placeholder="Password (sweep reveal — readable band)" />
|
|
371
374
|
<HInput variant="password" revealStrategy="noise" modelValue={form.value.password} onUpdate:modelValue={(v: string) => (form.value.password = v)} placeholder="Password (noise reveal — screenshot-safe)" />
|
|
@@ -424,6 +424,41 @@ describe("HkFaceShell rail chrome: toggle placement and the clip wrapper", () =>
|
|
|
424
424
|
expect(clip!.querySelector(".sidebar-mock"), "the sidebar slot renders in the clip").toBeTruthy();
|
|
425
425
|
});
|
|
426
426
|
|
|
427
|
+
it("hands the sidebar slot to the rail/full generations through the SWAP", async () => {
|
|
428
|
+
// The density dress rides the swap's GENERATION, never the host root:
|
|
429
|
+
// a root-level data-rail would restyle the frozen leaving generation
|
|
430
|
+
// mid-dissolve and reintroduce the squeeze this wave fixes. The root
|
|
431
|
+
// keeps data-rail as a STATE MARKER only (hosts/tests read it).
|
|
432
|
+
vi.useFakeTimers();
|
|
433
|
+
vi.stubGlobal("requestAnimationFrame", () => 0 as unknown as number);
|
|
434
|
+
vi.stubGlobal("cancelAnimationFrame", () => {});
|
|
435
|
+
const c = mountShell({ sidebarCollapsible: true });
|
|
436
|
+
const clip = () =>
|
|
437
|
+
c.panel().querySelector(":scope > .hk-sidebar-rail-clip") as HTMLElement;
|
|
438
|
+
const gens = () =>
|
|
439
|
+
Array.from(clip().querySelectorAll<HTMLElement>(".hk-sidebar-rail-generation"));
|
|
440
|
+
|
|
441
|
+
expect(clip().querySelector(".hk-sidebar-rail-swap"), "the swap mounts inside the clip").toBeTruthy();
|
|
442
|
+
expect(gens()).toHaveLength(1);
|
|
443
|
+
expect(gens()[0]!.hasAttribute("data-rail"), "expanded carries no rail density").toBe(false);
|
|
444
|
+
expect(gens()[0]!.style.width, "the generation pins the shell's sidebar width").toBe("224px");
|
|
445
|
+
expect(c.aside().hasAttribute("data-rail")).toBe(false);
|
|
446
|
+
|
|
447
|
+
c.toggle().click();
|
|
448
|
+
await vi.advanceTimersByTimeAsync(100); // mid-dissolve
|
|
449
|
+
const mid = gens();
|
|
450
|
+
expect(mid.length, "both generations share the swap's cell").toBe(2);
|
|
451
|
+
expect(mid[0]!.hasAttribute("data-rail"), "the leaving copy keeps the full dress").toBe(false);
|
|
452
|
+
expect(mid[0]!.style.width).toBe("224px");
|
|
453
|
+
expect(mid[1]!.hasAttribute("data-rail"), "the entering copy takes the rail dress").toBe(true);
|
|
454
|
+
expect(mid[1]!.style.width, "the rail generation pins the collapsed width").toBe("56px");
|
|
455
|
+
// The slot ran for the entering generation at its density; the root
|
|
456
|
+
// marker reads rail while the DENSITY lives on the generation.
|
|
457
|
+
expect(c.slotParams[c.slotParams.length - 1]!.collapsed).toBe(true);
|
|
458
|
+
expect(c.aside().hasAttribute("data-rail"), "the root keeps the state marker").toBe(true);
|
|
459
|
+
vi.unstubAllGlobals();
|
|
460
|
+
});
|
|
461
|
+
|
|
427
462
|
it("does not touch the legacy sidebar path (no clip wrapper, no rail classes)", () => {
|
|
428
463
|
const c = mountShell();
|
|
429
464
|
expect(c.container.querySelector(".hk-sidebar-rail-clip")).toBeFalsy();
|
|
@@ -2,6 +2,7 @@ import { computed, defineComponent, ref, watch, type PropType } from "vue";
|
|
|
2
2
|
import { HkCrossfade, HDrawer, HScrollContainer, useBreakpoint } from "@celestia-island/hikari";
|
|
3
3
|
import { useI18n } from "../i18n/context";
|
|
4
4
|
import { useSidebarRail } from "../composables/useSidebarRail";
|
|
5
|
+
import HkSidebarRailSwap from "./HkSidebarRailSwap";
|
|
5
6
|
import HkSidebarRailToggle, { isPointerOverRailToggle } from "./HkSidebarRailToggle";
|
|
6
7
|
|
|
7
8
|
/** CSS-wide keywords. A shorthand rebuilt from one of them is NOT a
|
|
@@ -435,6 +436,10 @@ export const HkFaceShell = defineComponent({
|
|
|
435
436
|
<aside
|
|
436
437
|
ref={railHostRef}
|
|
437
438
|
class="hk-sidebar-rail-host"
|
|
439
|
+
// STATE marker only (hosts/tests read "the rail layout is
|
|
440
|
+
// active"): the rail DENSITY dress itself rides the swap's
|
|
441
|
+
// generation inside the clip, so it can freeze on the
|
|
442
|
+
// leaving generation during the dissolve.
|
|
438
443
|
data-rail={railActive.value || undefined}
|
|
439
444
|
data-peeking={rail.peeking.value || undefined}
|
|
440
445
|
// Transient rail -> expanded window (useSidebarRail.pinning):
|
|
@@ -466,13 +471,29 @@ export const HkFaceShell = defineComponent({
|
|
|
466
471
|
border), so the slot's content clips inside this
|
|
467
472
|
wrapper — full rows stay inside rail width while the
|
|
468
473
|
panel width animates. The toggle stays a DIRECT child
|
|
469
|
-
of the panel: it must never be clipped.
|
|
474
|
+
of the panel: it must never be clipped. Inside the
|
|
475
|
+
clip, the crossfade handoff (HkSidebarRailSwap)
|
|
476
|
+
exchanges the rail and full generations through the
|
|
477
|
+
tab-panel dissolve at width-pinned boxes, so the
|
|
478
|
+
slot's content never re-lays-out at the panel's
|
|
479
|
+
transient width — each generation sees its own
|
|
480
|
+
`collapsed` dress, and the leaving copy stays
|
|
481
|
+
frozen (and unclickable) while it dissolves. */}
|
|
470
482
|
<div class="hk-sidebar-rail-clip">
|
|
471
|
-
|
|
472
|
-
|
|
473
|
-
|
|
474
|
-
|
|
475
|
-
|
|
483
|
+
<HkSidebarRailSwap
|
|
484
|
+
rail={railActive.value && !rail.peeking.value}
|
|
485
|
+
railWidth={props.sidebarCollapsedWidth}
|
|
486
|
+
expandedWidth={props.sidebarWidth}
|
|
487
|
+
>
|
|
488
|
+
{/* NOT `rail` — the scoped param would shadow the
|
|
489
|
+
useSidebarRail handle the outer bindings read. */}
|
|
490
|
+
{({ rail: density }: { rail: boolean }) =>
|
|
491
|
+
slots.sidebar?.({
|
|
492
|
+
collapsed: density,
|
|
493
|
+
onNavigate: onSidebarNavigate,
|
|
494
|
+
peeking: rail.peeking.value,
|
|
495
|
+
})}
|
|
496
|
+
</HkSidebarRailSwap>
|
|
476
497
|
</div>
|
|
477
498
|
<HkSidebarRailToggle expanded={!railActive.value} onToggle={rail.toggle} />
|
|
478
499
|
</div>
|
|
@@ -0,0 +1,219 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Behavior + source contract for HkInput's number variant (2026-10-30
|
|
3
|
+
* user request via the wowsp overlay settings): a number field used to
|
|
4
|
+
* carry the browser's NATIVE spin buttons — platform-drawn, unthemeable,
|
|
5
|
+
* the tiny up/down stack WebKit paints inside the field's right edge. The
|
|
6
|
+
* box now hides them (SCSS) and hosts the shared lucide stepper column
|
|
7
|
+
* (HkNumberSteppers) instead: pointer stepping runs through the component,
|
|
8
|
+
* keyboard stepping stays native (the field keeps type="number").
|
|
9
|
+
*
|
|
10
|
+
* Pinned guarantees:
|
|
11
|
+
* 1. type="number" AND variant="number" render the steppers + the box
|
|
12
|
+
* markers (.hk-input-box-number, data-number-steppers); text and
|
|
13
|
+
* textarea fields render none.
|
|
14
|
+
* 2. The native spin buttons are killed in SCSS under .hk-input-box-number
|
|
15
|
+
* (-moz-appearance: textfield + the webkit pseudo-elements).
|
|
16
|
+
* 3. Pointer steps parse the STRING model (Number.parseFloat), honor the
|
|
17
|
+
* min/max/step ATTRS (the same numbers the DOM input receives through
|
|
18
|
+
* the spread), and emit the string form without float dust.
|
|
19
|
+
* 4. An unparsable draft restarts from the nearest meaningful bound.
|
|
20
|
+
* 5. The steppers' width folds into --hk-input-affix-end-w (suffix +
|
|
21
|
+
* steppers SUM) so centered text and the marquee clear them.
|
|
22
|
+
* 6. disabled / readonly grey the column out.
|
|
23
|
+
*/
|
|
24
|
+
import { afterEach, describe, expect, it } from "vitest";
|
|
25
|
+
import { readFileSync } from "node:fs";
|
|
26
|
+
import { createApp, h, nextTick, ref, type Component } from "vue";
|
|
27
|
+
import { dirname, join } from "node:path";
|
|
28
|
+
import { fileURLToPath } from "node:url";
|
|
29
|
+
|
|
30
|
+
import HkInput from "./HkInput";
|
|
31
|
+
|
|
32
|
+
const here = dirname(fileURLToPath(import.meta.url));
|
|
33
|
+
const scss = readFileSync(join(here, "HkInput.scss"), "utf-8");
|
|
34
|
+
|
|
35
|
+
const mounts: Array<{ app: ReturnType<typeof createApp>; container: HTMLElement }> = [];
|
|
36
|
+
|
|
37
|
+
interface NumberHarness {
|
|
38
|
+
container: HTMLElement;
|
|
39
|
+
emitted: string[];
|
|
40
|
+
setModel: (v: string) => void;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
function mountNumber(
|
|
44
|
+
opts: { props?: Record<string, unknown>; slots?: Record<string, Component>; initial?: string } = {},
|
|
45
|
+
): NumberHarness {
|
|
46
|
+
const model = ref(opts.initial ?? "60");
|
|
47
|
+
const emitted: string[] = [];
|
|
48
|
+
const container = document.createElement("div");
|
|
49
|
+
document.body.appendChild(container);
|
|
50
|
+
const app = createApp({
|
|
51
|
+
render: () =>
|
|
52
|
+
h(
|
|
53
|
+
HkInput,
|
|
54
|
+
{
|
|
55
|
+
type: "number",
|
|
56
|
+
placeholder: "Hang",
|
|
57
|
+
modelValue: model.value,
|
|
58
|
+
"onUpdate:modelValue": (v: string) => {
|
|
59
|
+
model.value = v;
|
|
60
|
+
emitted.push(v);
|
|
61
|
+
},
|
|
62
|
+
...opts.props,
|
|
63
|
+
},
|
|
64
|
+
opts.slots ?? {},
|
|
65
|
+
),
|
|
66
|
+
});
|
|
67
|
+
app.mount(container);
|
|
68
|
+
mounts.push({ app, container });
|
|
69
|
+
return { container, emitted, setModel: (v: string) => { model.value = v; } };
|
|
70
|
+
}
|
|
71
|
+
|
|
72
|
+
function query<T extends HTMLElement = HTMLElement>(container: HTMLElement, selector: string): T | null {
|
|
73
|
+
return container.querySelector<T>(selector);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function click(container: HTMLElement, dir: "up" | "down"): void {
|
|
77
|
+
const el = query(container, `.hk-number-input-step-${dir}`);
|
|
78
|
+
expect(el, `${dir} stepper must render`).not.toBeNull();
|
|
79
|
+
el!.dispatchEvent(new MouseEvent("click", { bubbles: true, cancelable: true }));
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
afterEach(() => {
|
|
83
|
+
for (const { app, container } of mounts.splice(0)) {
|
|
84
|
+
app.unmount();
|
|
85
|
+
container.remove();
|
|
86
|
+
}
|
|
87
|
+
document.body.innerHTML = "";
|
|
88
|
+
});
|
|
89
|
+
|
|
90
|
+
describe("HkInput number variant — stepper column", () => {
|
|
91
|
+
it("renders the steppers for type=number and variant=number, none for other types", async () => {
|
|
92
|
+
const typed = mountNumber();
|
|
93
|
+
await nextTick();
|
|
94
|
+
expect(query(typed.container, ".hk-number-input-steppers")).not.toBeNull();
|
|
95
|
+
const box = query(typed.container, ".hk-input-box")!;
|
|
96
|
+
expect(box.classList.contains("hk-input-box-number")).toBe(true);
|
|
97
|
+
expect(box.getAttribute("data-number-steppers")).toBe("true");
|
|
98
|
+
// The field stays native — keyboard stepping and validation untouched.
|
|
99
|
+
expect(query<HTMLInputElement>(typed.container, ".hk-input-element")!.type).toBe("number");
|
|
100
|
+
|
|
101
|
+
const variant = mountNumber({ props: { type: "text", variant: "number" }, initial: "3" });
|
|
102
|
+
await nextTick();
|
|
103
|
+
expect(query(variant.container, ".hk-number-input-steppers")).not.toBeNull();
|
|
104
|
+
|
|
105
|
+
const text = mountNumber({ props: { type: "text" }, initial: "abc" });
|
|
106
|
+
await nextTick();
|
|
107
|
+
expect(query(text.container, ".hk-number-input-steppers")).toBeNull();
|
|
108
|
+
expect(query(text.container, ".hk-input-box-number")).toBeNull();
|
|
109
|
+
|
|
110
|
+
const ta = mountNumber({ props: { type: "textarea" } });
|
|
111
|
+
await nextTick();
|
|
112
|
+
expect(query(ta.container, ".hk-number-input-steppers")).toBeNull();
|
|
113
|
+
});
|
|
114
|
+
|
|
115
|
+
it("steps the parsed string model and clears float dust", async () => {
|
|
116
|
+
const harness = mountNumber({ initial: "60" });
|
|
117
|
+
await nextTick();
|
|
118
|
+
click(harness.container, "up");
|
|
119
|
+
await nextTick(); // props (the model) settle before the next parse
|
|
120
|
+
click(harness.container, "down");
|
|
121
|
+
expect(harness.emitted).toEqual(["61", "60"]);
|
|
122
|
+
|
|
123
|
+
const dust = mountNumber({ initial: "0.2", props: { step: "0.1" } });
|
|
124
|
+
await nextTick();
|
|
125
|
+
click(dust.container, "up");
|
|
126
|
+
expect(dust.emitted).toEqual(["0.3"]);
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("honors the min/max/step attrs the DOM input also receives", async () => {
|
|
130
|
+
const harness = mountNumber({ initial: "60", props: { min: "60", max: "240", step: "10" } });
|
|
131
|
+
await nextTick();
|
|
132
|
+
const up = query<HTMLButtonElement>(harness.container, ".hk-number-input-step-up")!;
|
|
133
|
+
const down = query<HTMLButtonElement>(harness.container, ".hk-number-input-step-down")!;
|
|
134
|
+
expect(down.disabled, "at the min bound the down stepper greys out").toBe(true);
|
|
135
|
+
expect(up.disabled).toBe(false);
|
|
136
|
+
|
|
137
|
+
click(harness.container, "down");
|
|
138
|
+
expect(harness.emitted, "a dead stepper must not emit").toEqual([]);
|
|
139
|
+
|
|
140
|
+
click(harness.container, "up");
|
|
141
|
+
expect(harness.emitted).toEqual(["70"]);
|
|
142
|
+
|
|
143
|
+
harness.setModel("240");
|
|
144
|
+
await nextTick();
|
|
145
|
+
expect(up.disabled, "at the max bound the up stepper greys out").toBe(true);
|
|
146
|
+
expect(down.disabled).toBe(false);
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("restarts an unparsable draft from the nearest meaningful bound", async () => {
|
|
150
|
+
const harness = mountNumber({ initial: "", props: { min: "2", max: "5" } });
|
|
151
|
+
await nextTick();
|
|
152
|
+
click(harness.container, "up");
|
|
153
|
+
expect(harness.emitted).toEqual(["2"]);
|
|
154
|
+
harness.setModel("garbage");
|
|
155
|
+
await nextTick();
|
|
156
|
+
click(harness.container, "down");
|
|
157
|
+
expect(harness.emitted).toEqual(["2", "5"]);
|
|
158
|
+
});
|
|
159
|
+
|
|
160
|
+
it("greys the column out while disabled or readonly", async () => {
|
|
161
|
+
const disabled = mountNumber({ props: { disabled: true } });
|
|
162
|
+
await nextTick();
|
|
163
|
+
expect(query<HTMLButtonElement>(disabled.container, ".hk-number-input-step-up")!.disabled).toBe(true);
|
|
164
|
+
expect(query<HTMLButtonElement>(disabled.container, ".hk-number-input-step-down")!.disabled).toBe(true);
|
|
165
|
+
|
|
166
|
+
const readonly = mountNumber({ props: { readonly: true } });
|
|
167
|
+
await nextTick();
|
|
168
|
+
expect(query<HTMLButtonElement>(readonly.container, ".hk-number-input-step-up")!.disabled).toBe(true);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it("folds the stepper width into the end-side affix reservation", async () => {
|
|
172
|
+
const receiver = Object.getOwnPropertyDescriptor(HTMLElement.prototype, "offsetWidth");
|
|
173
|
+
expect(receiver, "offsetWidth accessor exists on HTMLElement").toBeTruthy();
|
|
174
|
+
Object.defineProperty(HTMLElement.prototype, "offsetWidth", {
|
|
175
|
+
configurable: true,
|
|
176
|
+
get: () => 96,
|
|
177
|
+
});
|
|
178
|
+
try {
|
|
179
|
+
// suffix slot (96) + steppers column (96) — the end var is the SUM.
|
|
180
|
+
const both = mountNumber({ slots: { suffix: () => h("span", "px") } });
|
|
181
|
+
await nextTick();
|
|
182
|
+
const box = query(both.container, ".hk-input-box")!;
|
|
183
|
+
expect(box.style.getPropertyValue("--hk-input-affix-end-w")).toBe("192px");
|
|
184
|
+
|
|
185
|
+
const steppersOnly = mountNumber();
|
|
186
|
+
await nextTick();
|
|
187
|
+
expect(
|
|
188
|
+
query(steppersOnly.container, ".hk-input-box")!.style.getPropertyValue("--hk-input-affix-end-w"),
|
|
189
|
+
).toBe("96px");
|
|
190
|
+
} finally {
|
|
191
|
+
if (receiver) {
|
|
192
|
+
Object.defineProperty(HTMLElement.prototype, "offsetWidth", receiver);
|
|
193
|
+
}
|
|
194
|
+
}
|
|
195
|
+
});
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
describe("HkInput number variant — SCSS contract", () => {
|
|
199
|
+
it("kills the native spin buttons under the number box", () => {
|
|
200
|
+
const rule = scss.match(/\.hk-input-box-number \.hk-input-element\s*{[^}]*}/)?.[0] ?? "";
|
|
201
|
+
expect(rule, "number element rule must exist").toContain("-moz-appearance: textfield");
|
|
202
|
+
expect(rule).toContain("::-webkit-inner-spin-button");
|
|
203
|
+
expect(rule).toContain("::-webkit-outer-spin-button");
|
|
204
|
+
expect(rule).toContain("-webkit-appearance: none");
|
|
205
|
+
expect(rule).toContain("margin: 0");
|
|
206
|
+
});
|
|
207
|
+
|
|
208
|
+
it("parks the suffix next to the steppers via the box marker", () => {
|
|
209
|
+
const rule =
|
|
210
|
+
scss.match(
|
|
211
|
+
/\.hk-input-box\[data-number-steppers\] \.hk-input-affix\.hk-input-suffix\s*{[^}]*}/,
|
|
212
|
+
)?.[0] ?? "";
|
|
213
|
+
expect(rule, "suffix park rule must exist").toContain("margin-inline-start: 0");
|
|
214
|
+
|
|
215
|
+
const column = scss.match(/\.hk-input-box \.hk-number-input-steppers\s*{[^}]*}/)?.[0] ?? "";
|
|
216
|
+
expect(column, "stepper column context rule must exist").toContain("margin-inline-start: auto");
|
|
217
|
+
expect(column).toContain("z-index: 1");
|
|
218
|
+
});
|
|
219
|
+
});
|
|
@@ -186,6 +186,38 @@
|
|
|
186
186
|
margin-inline-start: auto;
|
|
187
187
|
}
|
|
188
188
|
|
|
189
|
+
/* ── Number fields (type="number" / variant="number") ───────────────
|
|
190
|
+
* The browser's native spin buttons are retired: the shared lucide
|
|
191
|
+
* stepper column (HkNumberSteppers) takes the trailing edge instead, so
|
|
192
|
+
* every hikari number field draws the same up/down affordance regardless
|
|
193
|
+
* of host platform. The field itself keeps type="number" — keyboard
|
|
194
|
+
* arrows and min/max validation stay native. */
|
|
195
|
+
.hk-input-box-number .hk-input-element {
|
|
196
|
+
-moz-appearance: textfield;
|
|
197
|
+
|
|
198
|
+
&::-webkit-inner-spin-button,
|
|
199
|
+
&::-webkit-outer-spin-button {
|
|
200
|
+
-webkit-appearance: none;
|
|
201
|
+
margin: 0;
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
/* The stepper column is an in-flow sibling riding ABOVE the absolutely
|
|
206
|
+
* positioned element (z-index 1, exactly like the affixes) and it owns the
|
|
207
|
+
* trailing auto margin — the slot the suffix's auto margin occupies when no
|
|
208
|
+
* steppers render. */
|
|
209
|
+
.hk-input-box .hk-number-input-steppers {
|
|
210
|
+
position: relative;
|
|
211
|
+
z-index: 1;
|
|
212
|
+
margin-inline-start: auto;
|
|
213
|
+
}
|
|
214
|
+
|
|
215
|
+
/* With the steppers present the suffix parks NEXT to them: two auto margins
|
|
216
|
+
* would split the free space and float the suffix mid-gap. */
|
|
217
|
+
.hk-input-box[data-number-steppers] .hk-input-affix.hk-input-suffix {
|
|
218
|
+
margin-inline-start: 0;
|
|
219
|
+
}
|
|
220
|
+
|
|
189
221
|
/* The placeholder-marquee window shares the element's content box: inset
|
|
190
222
|
* by the same base padding plus the affix clearance, so the scrolling
|
|
191
223
|
* strip never slides underneath the affixes either. Like the element,
|
|
@@ -1,9 +1,10 @@
|
|
|
1
|
-
import { computed, defineComponent, nextTick, onBeforeUnmount, onMounted, ref, useAttrs, useId, watch, type PropType } from "vue";
|
|
1
|
+
import { computed, defineComponent, nextTick, onBeforeUnmount, onMounted, ref, useAttrs, useId, watch, type PropType, type Ref } from "vue";
|
|
2
2
|
|
|
3
3
|
import type { PasswordStrengthEvaluator } from "../utils/password";
|
|
4
4
|
|
|
5
5
|
import { HkPlaceholderMarquee } from "./HkPlaceholderMarquee";
|
|
6
6
|
import HkPasswordSurface from "./HkPasswordSurface";
|
|
7
|
+
import HkNumberSteppers from "./HkNumberSteppers";
|
|
7
8
|
import "./HkInput.scss";
|
|
8
9
|
|
|
9
10
|
export default defineComponent({
|
|
@@ -210,6 +211,13 @@ export default defineComponent({
|
|
|
210
211
|
return props.type;
|
|
211
212
|
});
|
|
212
213
|
|
|
214
|
+
/* A number field (type="number" or variant="number") carries the shared
|
|
215
|
+
lucide stepper column (HkNumberSteppers) INSTEAD of the browser's
|
|
216
|
+
native spin buttons — the field keeps its native semantics (arrow
|
|
217
|
+
keys step, min/max validation), the column is the pointer
|
|
218
|
+
affordance riding the trailing edge. */
|
|
219
|
+
const isNumberField = computed(() => resolvedType.value === "number");
|
|
220
|
+
|
|
213
221
|
const filteredAttrs = computed(() => {
|
|
214
222
|
const { class: _, style: __, ...rest } = attrs as Record<string, unknown>;
|
|
215
223
|
return rest;
|
|
@@ -237,12 +245,17 @@ export default defineComponent({
|
|
|
237
245
|
// / "end" pads each side only by its own affix.
|
|
238
246
|
const prefixEl = ref<HTMLElement | null>(null);
|
|
239
247
|
const suffixEl = ref<HTMLElement | null>(null);
|
|
248
|
+
/* The number steppers' column — measured INTO the end-side clearance
|
|
249
|
+
(summed with the suffix span) so centered text and the marquee
|
|
250
|
+
window always end short of the buttons. */
|
|
251
|
+
const steppersEl = ref<HTMLElement | null>(null);
|
|
240
252
|
const affixStartW = ref(0);
|
|
241
253
|
const affixEndW = ref(0);
|
|
242
254
|
|
|
243
255
|
function measureAffixes() {
|
|
244
256
|
affixStartW.value = prefixEl.value?.offsetWidth ?? 0;
|
|
245
|
-
affixEndW.value =
|
|
257
|
+
affixEndW.value =
|
|
258
|
+
(suffixEl.value?.offsetWidth ?? 0) + (steppersEl.value?.offsetWidth ?? 0);
|
|
246
259
|
}
|
|
247
260
|
|
|
248
261
|
const affixRO: ResizeObserver | null =
|
|
@@ -251,14 +264,13 @@ export default defineComponent({
|
|
|
251
264
|
affixRO?.disconnect();
|
|
252
265
|
});
|
|
253
266
|
|
|
254
|
-
/** Stable ref callback for one
|
|
255
|
-
* so width changes (a longer chip label, a swapped
|
|
256
|
-
*
|
|
257
|
-
|
|
258
|
-
|
|
267
|
+
/** Stable ref callback factory for one measured slot — observes the
|
|
268
|
+
* live element so width changes (a longer chip label, a swapped
|
|
269
|
+
* icon, a steppers size flip) re-publish the custom properties
|
|
270
|
+
* without any consumer involvement. */
|
|
271
|
+
function bindMeasured(slot: () => Ref<HTMLElement | null>) {
|
|
259
272
|
const set = (node: HTMLElement | null) => {
|
|
260
|
-
|
|
261
|
-
else suffixEl.value = node;
|
|
273
|
+
slot().value = node;
|
|
262
274
|
};
|
|
263
275
|
return (el: unknown) => {
|
|
264
276
|
const node = (el as HTMLElement | null) ?? null;
|
|
@@ -288,8 +300,9 @@ export default defineComponent({
|
|
|
288
300
|
measureAffixes();
|
|
289
301
|
};
|
|
290
302
|
}
|
|
291
|
-
const prefixAffixRef =
|
|
292
|
-
const suffixAffixRef =
|
|
303
|
+
const prefixAffixRef = bindMeasured(() => prefixEl);
|
|
304
|
+
const suffixAffixRef = bindMeasured(() => suffixEl);
|
|
305
|
+
const steppersRootRef = bindMeasured(() => steppersEl);
|
|
293
306
|
|
|
294
307
|
const boxVars = computed(
|
|
295
308
|
() =>
|
|
@@ -299,6 +312,60 @@ export default defineComponent({
|
|
|
299
312
|
}) as Record<string, string>,
|
|
300
313
|
);
|
|
301
314
|
|
|
315
|
+
/* ── number steppers (type="number" / variant="number") ──
|
|
316
|
+
min/max/step reach the DOM input as undeclared attrs through the
|
|
317
|
+
spread; the steppers read the SAME numbers so pointer stepping
|
|
318
|
+
agrees with the native keyboard stepping and validation. */
|
|
319
|
+
function attrNumber(key: string): number | undefined {
|
|
320
|
+
const raw = attrs[key];
|
|
321
|
+
if (raw == null || raw === "") return undefined;
|
|
322
|
+
const n = Number(raw);
|
|
323
|
+
return Number.isFinite(n) ? n : undefined;
|
|
324
|
+
}
|
|
325
|
+
|
|
326
|
+
const numberBounds = computed(() => ({
|
|
327
|
+
min: attrNumber("min"),
|
|
328
|
+
max: attrNumber("max"),
|
|
329
|
+
step: attrNumber("step") ?? 1,
|
|
330
|
+
}));
|
|
331
|
+
|
|
332
|
+
const currentNumber = computed(() =>
|
|
333
|
+
Number.parseFloat(String(props.modelValue ?? "")),
|
|
334
|
+
);
|
|
335
|
+
|
|
336
|
+
const canStepUp = computed(() => {
|
|
337
|
+
const { max } = numberBounds.value;
|
|
338
|
+
if (max == null) return true;
|
|
339
|
+
const current = currentNumber.value;
|
|
340
|
+
// An unparsable draft leaves the end open — the value itself picks
|
|
341
|
+
// the restart bound in stepNumberValue.
|
|
342
|
+
return !Number.isFinite(current) || current < max;
|
|
343
|
+
});
|
|
344
|
+
|
|
345
|
+
const canStepDown = computed(() => {
|
|
346
|
+
const { min } = numberBounds.value;
|
|
347
|
+
if (min == null) return true;
|
|
348
|
+
const current = currentNumber.value;
|
|
349
|
+
return !Number.isFinite(current) || current > min;
|
|
350
|
+
});
|
|
351
|
+
|
|
352
|
+
function stepNumberValue(dir: "up" | "down") {
|
|
353
|
+
if (props.disabled || props.readonly) return;
|
|
354
|
+
const { min, max, step } = numberBounds.value;
|
|
355
|
+
const current = currentNumber.value;
|
|
356
|
+
// An unparsable draft lands ON the bound (native number-input
|
|
357
|
+
// behavior): up restarts at min (else 0), down at max (else 0).
|
|
358
|
+
if (!Number.isFinite(current)) {
|
|
359
|
+
emit("update:modelValue", String(dir === "up" ? (min ?? 0) : (max ?? 0)));
|
|
360
|
+
return;
|
|
361
|
+
}
|
|
362
|
+
let next = dir === "up" ? current + step : current - step;
|
|
363
|
+
if (min != null && next < min) next = min;
|
|
364
|
+
if (max != null && next > max) next = max;
|
|
365
|
+
// Kill float dust (0.1 + 0.2 must not surface as 0.30000000000000004).
|
|
366
|
+
emit("update:modelValue", String(Number.parseFloat(next.toFixed(10))));
|
|
367
|
+
}
|
|
368
|
+
|
|
302
369
|
function onInput(e: Event) {
|
|
303
370
|
const target = e.target as HTMLInputElement | HTMLTextAreaElement;
|
|
304
371
|
emit("update:modelValue", target.value);
|
|
@@ -348,6 +415,7 @@ export default defineComponent({
|
|
|
348
415
|
`hk-input-box-${props.size}`,
|
|
349
416
|
props.error ? "hk-input-box-error" : "",
|
|
350
417
|
props.disabled ? "hk-input-box-disabled" : "",
|
|
418
|
+
isNumberField.value ? "hk-input-box-number" : "",
|
|
351
419
|
]);
|
|
352
420
|
|
|
353
421
|
const isText = !isTextarea.value;
|
|
@@ -419,6 +487,10 @@ export default defineComponent({
|
|
|
419
487
|
class={boxClass.value}
|
|
420
488
|
style={boxVars.value}
|
|
421
489
|
data-autogrow={isAutoGrow.value || undefined}
|
|
490
|
+
// Number boxes carry the marker so the SCSS can hide the native
|
|
491
|
+
// spin buttons and park the suffix next to the steppers (the
|
|
492
|
+
// column owns the trailing auto margin).
|
|
493
|
+
data-number-steppers={isNumberField.value || undefined}
|
|
422
494
|
// Textarea boxes never carry the marker: their element is
|
|
423
495
|
// excluded by :not() anyway, and keeping it off also spares
|
|
424
496
|
// a textarea-scoped marquee from the per-side window insets.
|
|
@@ -545,6 +617,16 @@ export default defineComponent({
|
|
|
545
617
|
{slots.suffixIcon()}
|
|
546
618
|
</span>
|
|
547
619
|
)}
|
|
620
|
+
{isNumberField.value && (
|
|
621
|
+
<HkNumberSteppers
|
|
622
|
+
rootRef={steppersRootRef}
|
|
623
|
+
size={props.size}
|
|
624
|
+
canUp={canStepUp.value}
|
|
625
|
+
canDown={canStepDown.value}
|
|
626
|
+
disabled={props.disabled || props.readonly}
|
|
627
|
+
onStep={stepNumberValue}
|
|
628
|
+
/>
|
|
629
|
+
)}
|
|
548
630
|
</div>
|
|
549
631
|
)}
|
|
550
632
|
{props.error ? (
|
|
@@ -27,6 +27,11 @@ import HkNumberInput from "./HkNumberInput";
|
|
|
27
27
|
|
|
28
28
|
const here = dirname(fileURLToPath(import.meta.url));
|
|
29
29
|
const scss = readFileSync(join(here, "HkNumberInput.scss"), "utf-8");
|
|
30
|
+
/* The stepper column's rules moved to the shared HkNumberSteppers
|
|
31
|
+
stylesheet (2026-10-30) — the same affordance now renders inside
|
|
32
|
+
HkInput's number variant, so its geometry contract ships with the
|
|
33
|
+
component that draws it. */
|
|
34
|
+
const steppersScss = readFileSync(join(here, "HkNumberSteppers.scss"), "utf-8");
|
|
30
35
|
|
|
31
36
|
const mounts: Array<{ app: ReturnType<typeof createApp>; container: HTMLElement }> = [];
|
|
32
37
|
|
|
@@ -65,9 +70,9 @@ describe("HkNumberInput affix contract", () => {
|
|
|
65
70
|
});
|
|
66
71
|
|
|
67
72
|
it("stretches the stepper column so height:50% steps and the divider span the box", () => {
|
|
68
|
-
const rule =
|
|
73
|
+
const rule = steppersScss.match(/\.hk-number-input-steppers\s*{[^}]*}/)?.[0] ?? "";
|
|
69
74
|
expect(rule, "steppers rule must exist").toContain("align-self: stretch");
|
|
70
|
-
const steps =
|
|
75
|
+
const steps = steppersScss.match(/\.hk-number-input-step\s*{[^}]*}/)?.[0] ?? "";
|
|
71
76
|
expect(steps).toContain("height: 50%");
|
|
72
77
|
});
|
|
73
78
|
|
|
@@ -101,10 +106,13 @@ describe("HkNumberInput affix contract", () => {
|
|
|
101
106
|
|
|
102
107
|
const inner = query(container, ".hk-number-input-inner");
|
|
103
108
|
const children = Array.from(inner?.children ?? []).map((el) => el.className);
|
|
109
|
+
// The stepper column carries its size class on the stack root (the
|
|
110
|
+
// shared HkNumberSteppers sizes from it — HkNumberInput.scss no longer
|
|
111
|
+
// holds per-size step rules).
|
|
104
112
|
expect(children).toEqual([
|
|
105
113
|
"hk-number-input-field",
|
|
106
114
|
"hk-number-input-suffix",
|
|
107
|
-
"hk-number-input-steppers",
|
|
115
|
+
"hk-number-input-steppers hk-number-input-steppers-md",
|
|
108
116
|
]);
|
|
109
117
|
});
|
|
110
118
|
|