mirror of
https://github.com/bitbaum/whenkit.git
synced 2026-12-05 06:38:27 +01:00
Compare commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
f5e0a24208 |
No files matched your search
@@ -5,7 +5,7 @@ length chips, a readable date field over the native picker, and a booking
|
||||
request that resolves to `{ startsAt, endsAt }` in the provider's time zone.
|
||||
|
||||
```bash
|
||||
pnpm add github:bitbaum/whenkit#v0.3.1
|
||||
pnpm add github:bitbaum/whenkit#v0.3.2
|
||||
```
|
||||
|
||||
```tsx
|
||||
|
||||
@@ -47,6 +47,12 @@ createRoot(document.getElementById("dialog")!).render(
|
||||
createRoot(document.getElementById("own-class")!).render(
|
||||
<DateInput className="app-input" defaultValue="2026-10-11" id="own" />,
|
||||
);
|
||||
createRoot(document.getElementById("match-date")!).render(
|
||||
<DateInput className="match-input" defaultValue="2026-10-11" id="match" />,
|
||||
);
|
||||
createRoot(document.getElementById("block-class")!).render(
|
||||
<DateInput className="block-input" defaultValue="2026-10-11" id="blocked" />,
|
||||
);
|
||||
createRoot(document.getElementById("compact-class")!).render(
|
||||
<DateInput className="compact-input" defaultValue="2026-10-11" id="compact" />,
|
||||
);
|
||||
|
||||
@@ -67,6 +67,21 @@
|
||||
border-color: rgb(0, 0, 255);
|
||||
}
|
||||
}
|
||||
/* An app's input, applied to a native input AND to DateInput: they must end up
|
||||
the same height (a serif so its natural line height differs from 1.3). */
|
||||
.match-input {
|
||||
font-family: Georgia, serif;
|
||||
font-size: 14px;
|
||||
padding: 10px 14px;
|
||||
border: 1.5px solid rgb(150, 150, 150);
|
||||
border-radius: 10px;
|
||||
width: 100%;
|
||||
box-sizing: border-box;
|
||||
}
|
||||
/* A hostile app class: display:block on the same element (unlayered, later). */
|
||||
.block-input {
|
||||
display: block;
|
||||
}
|
||||
.resolved {
|
||||
font-size: 11px;
|
||||
opacity: 0.5;
|
||||
@@ -95,6 +110,11 @@
|
||||
<section><div id="own-class"></div></section>
|
||||
<section><div id="util-class"></div></section>
|
||||
<section><div id="compact-class"></div></section>
|
||||
<section>
|
||||
<input id="match-native" class="match-input" value="Bello" />
|
||||
<div id="match-date" style="margin-top: 8px"></div>
|
||||
</section>
|
||||
<section><div id="block-class"></div></section>
|
||||
</div>
|
||||
<div class="dialog-like" id="dialog"></div>
|
||||
</main>
|
||||
|
||||
+1
-1
@@ -1,6 +1,6 @@
|
||||
{
|
||||
"name": "@bitbaum/whenkit",
|
||||
"version": "0.3.1",
|
||||
"version": "0.3.2",
|
||||
"description": "Dates and times people can pick without typing: day chips, time chips, length chips, a readable date field over the native picker, and a low-friction booking request that resolves to {startsAt, endsAt} in the provider's zone.",
|
||||
"license": "MIT",
|
||||
"author": "Cato",
|
||||
|
||||
@@ -116,7 +116,9 @@ for (const file of walk(root)) {
|
||||
last = m.index + m[0].length;
|
||||
count++;
|
||||
const line = src.slice(0, m.index).split("\n").length;
|
||||
if (/\{\s*\.\.\./.test(attrs))
|
||||
// A JSX prop spread is `{...x}` at attribute level; `({ ...form, a })` inside
|
||||
// an onChange arrow is an object literal and is not worth a human's time.
|
||||
if (/(^|[\s"'}/])\{\s*\.\.\.[A-Za-z_$]/.test(attrs.replace(/=\{[^}]*\}/g, "=")))
|
||||
review.push(`${relative(root, file)}:${line} spreads props — check they are input props`);
|
||||
} else if (TYPE_ANY.test(attrs) && /date/i.test(src.slice(m.index, m.index + 400))) {
|
||||
const line = src.slice(0, m.index).split("\n").length;
|
||||
|
||||
+11
-6
@@ -225,7 +225,9 @@
|
||||
looks like the app's other inputs, not like ours. (Unlayered defaults would
|
||||
have beaten Tailwind's layered utilities.) No min-height: a compact input
|
||||
stays compact; the picker sets its own 44px where it needs it. */
|
||||
.wk-input {
|
||||
/* span.wk-input, not .wk-input: structure must hold even when an app's own
|
||||
unlayered input class sets display:block on this same element. */
|
||||
span.wk-input {
|
||||
position: relative;
|
||||
display: flex;
|
||||
align-items: center;
|
||||
@@ -244,7 +246,9 @@
|
||||
color: inherit;
|
||||
font: inherit;
|
||||
font-size: var(--wk-text);
|
||||
line-height: 1.3;
|
||||
/* The font's own line height, exactly like a native input — a fixed 1.3
|
||||
made the date box a different height from its neighbours. */
|
||||
line-height: normal;
|
||||
}
|
||||
}
|
||||
|
||||
@@ -281,10 +285,11 @@
|
||||
}
|
||||
|
||||
.wk-input-icon {
|
||||
/* em, not rem: the icon scales with the field's own text, so a dense 12px
|
||||
input is not made taller than its neighbours by a fixed 20px icon. */
|
||||
width: 1.25em;
|
||||
height: 1.25em;
|
||||
/* em, not rem, and no taller than a normal line: the icon scales with the
|
||||
field's own text, so neither a dense 12px input nor a serif-font one is made
|
||||
taller than its neighbours by it. */
|
||||
width: 1.1em;
|
||||
height: 1.1em;
|
||||
flex: 0 0 auto;
|
||||
opacity: 0.7;
|
||||
}
|
||||
|
||||
@@ -128,6 +128,23 @@ try {
|
||||
`${name}: a 12px compact date input stays compact (${Math.round(compactHeight)}px)`,
|
||||
);
|
||||
|
||||
// The date box is the same height as a native input given the same class —
|
||||
// so a form row does not step when one field is a date.
|
||||
const heights = await page.evaluate(() => ({
|
||||
native: document.getElementById("match-native").getBoundingClientRect().height,
|
||||
date: document.querySelector("#match-date .wk-input").getBoundingClientRect().height,
|
||||
}));
|
||||
check(
|
||||
Math.abs(heights.native - heights.date) <= 1,
|
||||
`${name}: date box matches a native input's height (${heights.date} vs ${heights.native})`,
|
||||
);
|
||||
// An app class with display:block on the same element must not break the layout.
|
||||
const stacked = await page.evaluate(() => {
|
||||
const box = document.querySelector("#block-class .wk-input");
|
||||
return getComputedStyle(box).display;
|
||||
});
|
||||
check(stacked === "flex", `${name}: an app's display:block cannot break the box (${stacked})`);
|
||||
|
||||
const small = await page.evaluate(
|
||||
() =>
|
||||
[
|
||||
|
||||
@@ -160,3 +160,13 @@ test("a URL in a string does not hide the rest of the line", () => {
|
||||
run(dir, ["--write"]);
|
||||
assert.match(read(dir, "a.tsx"), /<DateInput type="date" \/>; \/\/ after/);
|
||||
});
|
||||
|
||||
test("an object spread inside onChange is not flagged; a JSX prop spread still is", () => {
|
||||
const dir = project({
|
||||
"a.tsx": `import x from "x";\nexport const A = () => <input type="date" onChange={(e) => set({ ...form, date: e.target.value })} />;\n`,
|
||||
"b.tsx": `import x from "x";\nexport const B = () => <input type="date" {...register("when")} />;\n`,
|
||||
});
|
||||
const out = run(dir);
|
||||
assert.doesNotMatch(out, /a\.tsx:\d+ spreads props/);
|
||||
assert.match(out, /b\.tsx:\d+ spreads props/);
|
||||
});
|
||||
Reference in new issue
Block a user