3 Commits
Author SHA1 Message Date
CatoandClaude Sonnet 5.5 0173ac305c feat: DateInput — a drop-in for input type=date / datetime-local (0.3.0) (#4)
Same props and onChange(event) as the native input, so a call site changes
its tag and nothing else. The value shows in words in the app's OWN styling
(className lands on the visible box); the real input stays on top,
transparent, so the picker, keyboard, autofill, validation and form
submission keep working. Controlled or uncontrolled; locale and empty-state
words follow <html lang>.

The look is in @layer base so an app's classes win: unlayered defaults would
have beaten Tailwind v4's layered utilities. A browser check proves both a
plain class and a layered utility win, and fails without the layer.
DateField is now a labelled wrapper on DateInput.

Signed-off-by: Cato <41178744+catomean@users.noreply.github.com>
Co-authored-by: Claude Sonnet 5.5 <noreply@anthropic.com>
2026-10-08 05:13:34 -07:00
CatoandClaude Opus 5.5 ad4c1ed6f6 fix: the day strip never props open a dialog or grid column (0.2.1) (#3)
Fourteen chips side by side gave the strip a wide min-content width, and a
CSS grid item (a modal dialog's content) grows to that: in OrangeCat's
booking dialog it pushed Send off-screen at 390px. The strip now claims no
inline size of its own (contain: inline-size) and scrolls inside whatever
it is given.

The browser check could not see this: the demo gave its grid cells
min-width: 0. It now has a dialog-shaped container and checks the dialog's
button stays on screen — verified to FAIL without the fix.

Signed-off-by: Cato <41178744+catomean@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-08 03:05:22 -07:00
CatoandClaude Opus 5.5 5c16c5db12 feat: lengths prop — a fixed duration shows no length row (0.2.0) (#2)
A service with duration_minutes (a 60-minute session) should not ask how
long. lengths={[60]} uses that duration and hides the choice; several values
offer those instead of the defaults.

Signed-off-by: Cato <41178744+catomean@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
2026-10-08 02:53:29 -07:00
27 changed files with 607 additions and 148 deletions

No files matched your search

+25 -2
View File
@@ -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.1.0
pnpm add github:bitbaum/whenkit#v0.3.0
```
```tsx
@@ -20,6 +20,7 @@ const [choice, setChoice] = useState<BookingChoice | null>(null);
zone="Europe/Zurich" // the zone of the thing being booked
hours={{ start: "09:00", end: "18:00" }}
openWeekdays={[1, 2, 3, 4, 5]}
lengths={[60]} // optional: one value = fixed duration, no length row
value={choice}
onChange={setChoice}
/>;
@@ -47,6 +48,28 @@ rented by the day. Three decisions replace that:
autofill, a11y) transparent on top of a display that reads "Sat, 11 Oct ·
14:00", and opens the picker on tap.
## Replacing the date inputs you already have
`DateInput` is a drop-in for `<input type="date">` / `type="datetime-local"`:
same props, same `onChange(event)`, so a call site changes its tag and nothing
else.
```tsx
import { DateInput } from "@bitbaum/whenkit/react";
import "@bitbaum/whenkit/styles.css";
// before: <input type="date" value={due} onChange={(e) => setDue(e.target.value)} className="input" />
<DateInput value={due} onChange={(e) => setDue(e.target.value)} className="input" />;
```
Your own `className` lands on the visible box, and it wins: whenkit's look sits
in `@layer base`, below Tailwind utilities and plain app CSS. The real input
stays on top, invisible, so the picker, keyboard entry, autofill, `required`
validation and form submission all keep working. Controlled (`value`) or
uncontrolled (`defaultValue` + `name`, e.g. a server-action form). The empty
state and weekday/month words follow `<html lang>` (or pass `locale` /
`placeholder`).
## Rules it enforces
- Dates are `YYYY-MM-DD`, times `HH:MM` — wall-clock strings. They become an
@@ -70,7 +93,7 @@ rented by the day. Three decisions replace that:
`type BookingChoice`.
**React** (`@bitbaum/whenkit/react`): `BookingRequestPicker`, `DayStrip`,
`ChipGroup`, `DateField`.
`ChipGroup`, `DateInput`, `DateField` (a `DateInput` with its own label).
**Look** (`@bitbaum/whenkit/styles.css`): `--wk-*` variables default to
`@bitbaum/design-tokens`; set them once to match any other app.
+17 -1
View File
@@ -1,7 +1,7 @@
// Visual + browser check page. Not shipped.
import { useState } from "react";
import { createRoot } from "react-dom/client";
import { BookingRequestPicker, DateField } from "../src/react/index.js";
import { BookingRequestPicker, DateField, DateInput } from "../src/react/index.js";
import { resolveRequest, todayIn, type BookingChoice } from "../src/index.js";
const ZONE = "Europe/Zurich";
@@ -34,3 +34,19 @@ function Field() {
createRoot(document.getElementById("hourly")!).render(<Booking unit="hour" id="hourly" />);
createRoot(document.getElementById("daily")!).render(<Booking unit="day" id="daily" />);
createRoot(document.getElementById("field")!).render(<Field />);
createRoot(document.getElementById("dialog")!).render(
<>
<strong>Book a long studio name that goes on and on</strong>
<Booking unit="day" id="dialog" />
<button type="button" id="dialog-send">
Send booking request
</button>
</>,
);
createRoot(document.getElementById("own-class")!).render(
<DateInput className="app-input" defaultValue="2026-10-11" id="own" />,
);
createRoot(document.getElementById("util-class")!).render(
<DateInput className="util-input" defaultValue="2026-10-11" id="util" />,
);
+34 -3
View File
@@ -26,15 +26,41 @@
max-width: 1200px;
margin: 0 auto;
}
.grid > section {
min-width: 0;
}
h2 {
font-size: 14px;
margin: 0 0 12px;
opacity: 0.6;
font-weight: 500;
}
/* Shaped like a modal dialog (shadcn/Radix DialogContent): a grid whose
column is sized by its content. A picker that props this open
pushes the dialog's buttons off-screen. */
.dialog-like {
display: grid;
gap: 16px;
width: calc(100% - 32px);
max-width: 28rem;
margin: 32px auto 0;
padding: 24px;
border: 1px solid hsl(var(--border-default, 0 0% 82%));
border-radius: 12px;
background: hsl(var(--surface-base, 0 0% 100%));
box-sizing: border-box;
}
/* An app's OWN input class, unlayered plain CSS and a layered utility: both
must beat whenkit's defaults (they live in @layer base). */
.app-input {
padding: 2px 6px;
border: 3px solid rgb(255, 0, 0);
border-radius: 0;
}
@layer utilities {
.util-input {
border-width: 5px;
border-style: dashed;
border-color: rgb(0, 0, 255);
}
}
.resolved {
font-size: 11px;
opacity: 0.5;
@@ -59,6 +85,11 @@
<div id="field"></div>
</section>
</div>
<div class="grid" style="margin-top: 24px">
<section><div id="own-class"></div></section>
<section><div id="util-class"></div></section>
</div>
<div class="dialog-like" id="dialog"></div>
</main>
<script src="./dist/demo.js"></script>
</body>
+7 -1
View File
@@ -26,6 +26,12 @@ export interface BookingRequestPickerProps {
hours?: DailyHours;
/** Weekdays open, 0 = Sunday … 6 = Saturday. Omit for every day. */
openWeekdays?: number[];
/**
* Lengths to offer, minutes. Defaults to what fits the opening hours. Pass
* one value for a fixed duration (a 60-minute session): the length row is
* not shown and that duration is used.
*/
lengths?: number[];
/** Spacing of start times, minutes. */
stepMinutes?: number;
/** Days shown as chips. */
@@ -35,5 +41,5 @@ export interface BookingRequestPickerProps {
/** For tests and demos; defaults to now. */
now?: Date;
}
export declare function BookingRequestPicker({ unit, zone, locale, value, onChange, hours, openWeekdays, stepMinutes, daysAhead, allowFlexible, words: wordOverrides, now, }: BookingRequestPickerProps): import("react").JSX.Element;
export declare function BookingRequestPicker({ unit, zone, locale, value, onChange, hours, lengths: lengthsProp, openWeekdays, stepMinutes, daysAhead, allowFlexible, words: wordOverrides, now, }: BookingRequestPickerProps): import("react").JSX.Element;
//# sourceMappingURL=BookingRequestPicker.d.ts.map
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"BookingRequestPicker.d.ts","sourceRoot":"","sources":["../../src/react/BookingRequestPicker.tsx"],"names":[],"mappings":"AAiBA,OAAO,EAAmB,KAAK,aAAa,EAAE,KAAK,YAAY,EAAE,MAAM,eAAe,CAAC;AACvF,OAAO,EAA2C,KAAK,UAAU,EAAE,MAAM,aAAa,CAAC;AAIvF,MAAM,WAAW,kBAAmB,SAAQ,YAAY;IACtD,GAAG,EAAE,MAAM,CAAC;IACZ,IAAI,EAAE,MAAM,CAAC;IACb,IAAI,EAAE,MAAM,CAAC;IACb,MAAM,EAAE,MAAM,CAAC;IACf,IAAI,EAAE,MAAM,CAAC;IACb,SAAS,EAAE,MAAM,CAAC;IAClB,QAAQ,EAAE,MAAM,CAAC;IACjB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,YAAY,EAAE,MAAM,CAAC;IACrB,OAAO,EAAE,MAAM,CAAC;IAChB,SAAS,EAAE,MAAM,C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 -3
View File
@@ -27,7 +27,7 @@ function emptyFor(unit) {
? { kind: "days", from: null, to: null }
: { kind: "slot", date: null, time: null, lengthMinutes: null };
}
export function BookingRequestPicker({ unit, zone, locale = "en", value, onChange, hours = DEFAULT_HOURS, openWeekdays, stepMinutes = 60, daysAhead = 14, allowFlexible = true, words: wordOverrides, now, }) {
export function BookingRequestPicker({ unit, zone, locale = "en", value, onChange, hours = DEFAULT_HOURS, lengths: lengthsProp, openWeekdays, stepMinutes = 60, daysAhead = 14, allowFlexible = true, words: wordOverrides, now, }) {
const words = { ...DEFAULT_PICKER_WORDS, ...wordOverrides };
const instant = now ?? new Date();
const today = todayIn(zone, instant);
@@ -46,7 +46,9 @@ export function BookingRequestPicker({ unit, zone, locale = "en", value, onChang
body = (_jsx(DayStrip, { label: words.days, today: today, days: daysAhead, locale: locale, mode: "range", from: choice.from, to: choice.to, isDisabled: closed, otherDateLabel: words.otherDate, onChange: ({ from, to }) => onChange({ kind: "days", from, to }) }));
}
else {
const lengths = lengthOptions(hours);
const lengths = lengthsProp && lengthsProp.filter((m) => m > 0).length > 0
? lengthsProp.filter((m) => m > 0)
: lengthOptions(hours);
const length = choice.lengthMinutes ?? lengths[0];
const slots = choice.date
? timeSlots({
@@ -62,7 +64,7 @@ export function BookingRequestPicker({ unit, zone, locale = "en", value, onChang
time: null,
lengthMinutes: choice.lengthMinutes ?? length,
}) }), choice.date &&
(slots.length > 0 ? (_jsx(ChipGroup, { label: words.time, value: choice.time, options: slots.map((t) => ({ value: t, label: formatTime(t, locale) })), onChange: (time) => onChange({ ...choice, time, lengthMinutes: length }) })) : (_jsx("p", { className: "wk-hint", role: "status", children: words.noTimes }))), choice.date && slots.length > 0 && (_jsx(ChipGroup, { label: words.length, value: length, options: lengths.map((m) => ({ value: m, label: formatLength(m, locale) })), onChange: (lengthMinutes) => {
(slots.length > 0 ? (_jsx(ChipGroup, { label: words.time, value: choice.time, options: slots.map((t) => ({ value: t, label: formatTime(t, locale) })), onChange: (time) => onChange({ ...choice, time, lengthMinutes: length }) })) : (_jsx("p", { className: "wk-hint", role: "status", children: words.noTimes }))), choice.date && slots.length > 0 && lengths.length > 1 && (_jsx(ChipGroup, { label: words.length, value: length, options: lengths.map((m) => ({ value: m, label: formatLength(m, locale) })), onChange: (lengthMinutes) => {
// A longer booking may no longer fit after the chosen start.
const fits = timeSlots({
hours,
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"BookingRequestPicker.js","sourceRoot":"","sources":["../../src/react/BookingRequestPicker.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAeb,OAAO,EAAE,KAAK,EAAE,OAAO,EAAE,OAAO,EAA+B,MAAM,gBAAgB,CAAC;AACtF,OAAO,EAAE,YAAY,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACxD,OAAO,EAAE,eAAe,EAAyC,MAAM,eAAe,CAAC;AACvF,OAAO,EAAE,aAAa,EAAE,aAAa,EAAE,SAAS,EAAmB,MAAM,aAAa,CAAC;AACvF,OAAO,EAAE,SAAS,EAAE,MAAM,gBAAgB,CAAC;AAC3C,OAAO,EAAE,QAAQ,EAAE,MAAM,eAAe,CAAC;AAiBzC,MAAM,CAAC,MAAM,oBAAoB,GAAuB;IACtD,QAAQ,EAAE,yCAAyC;IACnD,cAAc,EAAE,kBAAkB;IAClC,GAAG,EAAE,KAAK;IACV,IAAI,EAAE,2CAA2C;IACjD,IAAI,EAAE,OAAO;IACb,MAAM,EAAE,cAAc;IACtB,IAAI,EAAE,MAAM;IACZ,SAAS,EAAE,aAAa;IACxB,QAAQ,EAAE,WAAW;IACrB,YAAY,EAAE,cAAc;IAC5B,YAAY,EAAE,0BAA0B;IACxC,YAAY,EAAE,oEAAoE;IAClF,OAAO,EAAE,iDAAiD;IAC1D,SAAS,EAAE,eAAe;CAC3B,CAAC;AAuBF,SAAS,QAAQ,CAAC,IAAoB;IACpC,OAAO,IAAI,KAAK,KAAK;QACnB,CAAC,CAAC,EAAE,IAAI,EAAE,MAAM,EAA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AAO,EAAE,KAAK,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,UAAU,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,EACvE,QAAQ,EAAE,CAAC,IAAI,EAAE,EAAE,CAAC,QAAQ,CAAC,EAAE,GAAG,MAAM,EAAE,IAAI,EAAE,aAAa,EAAE,MAAM,EAAE,CAAC,GACxE,CACH,CAAC,CAAC,CAAC,CACF,YAAG,SAAS,EAAC,SAAS,EAAC,IAAI,EAAC,QAAQ,YACjC,KAAK,CAAC,OAAO,GACZ,CACL,CAAC,EACH,MAAM,CAAC,IAAI,IAAI,KAAK,CAAC,MAAM,GAAG,CAAC,IAAI,OAAO,CAAC,MAAM,GAAG,CAAC,IAAI,CACxD,KAAC,SAAS,IACR,KAAK,EAAE,KAAK,CAAC,MAAM,EACnB,KAAK,EAAE,MAAM,EACb,OAAO,EAAE,OAAO,CAAC,GAAG,CAAC,CAAC,CAAC,EAAE,EAAE,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,EAAE,KAAK,EAAE,YAAY,CAAC,CAAC,EAAE,MAAM,CAAC,EAAE,CAAC,CAAC,EAC3E,QAAQ,EAAE,CAAC,aAAa,EAAE,EAAE;wBAC1B,6DAA6D;Line truncated
+3 -1
View File
@@ -1,3 +1,4 @@
import { describeValue } from "./DateInput.js";
export interface DateFieldProps {
label: string;
/** `YYYY-MM-DD` (date) or `YYYY-MM-DDTHH:MM` (withTime), or "" when empty. */
@@ -13,6 +14,7 @@ export interface DateFieldProps {
hint?: string;
className?: string;
}
export declare function describeFieldValue(value: string, withTime: boolean, locale?: string): string;
/** Kept for callers of 0.1–0.2: the words for a value, or "" if invalid. */
export declare const describeFieldValue: typeof describeValue;
export declare function DateField({ label, value, onChange, withTime, min, max, required, name, placeholder, locale, hint, className, }: DateFieldProps): import("react").JSX.Element;
//# sourceMappingURL=DateField.d.ts.map
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"DateField.d.ts","sourceRoot":"","sources":["../../src/react/DateField.tsx"],"names":[],"mappings":"AAoBA,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,8EAA8E;IAC9E,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,wBAAgB,kBAAkB,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,SAAO,GAAG,MAAM,CAa1F;AAED,wBAAgB,SAAS,CAAC,EACxB,KAAK,EACL,KAAK,EACL,QAAQ,EACR,QAAgB,EAChB,GAAG,EACH,GAAG,EACH,QAAQ,EACR,IAAI,EACJ,WAAW,EACX,MAAa,EACb,IAAI,EACJ,SAAS,GACV,EAAE,cAAc,+BA0DhB"}
{"version":3,"file":"DateField.d.ts","sourceRoot":"","sources":["../../src/react/DateField.tsx"],"names":[],"mappings":"AAWA,OAAO,EAAa,aAAa,EAAE,MAAM,gBAAgB,CAAC;AAE1D,MAAM,WAAW,cAAc;IAC7B,KAAK,EAAE,MAAM,CAAC;IACd,8EAA8E;IAC9E,KAAK,EAAE,MAAM,CAAC;IACd,QAAQ,EAAE,CAAC,KAAK,EAAE,MAAM,KAAK,IAAI,CAAC;IAClC,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,GAAG,CAAC,EAAE,MAAM,CAAC;IACb,QAAQ,CAAC,EAAE,OAAO,CAAC;IACnB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,IAAI,CAAC,EAAE,MAAM,CAAC;IACd,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAED,4EAA4E;AAC5E,eAAO,MAAM,kBAAkB,sBAAgB,CAAC;AAEhD,wBAAgB,SAAS,CAAC,EACxB,KAAK,EACL,KAAK,EACL,QAAQ,EACR,QAAgB,EAChB,GAAG,EACH,GAAG,EACH,QAAQ,EACR,IAAI,EACJ,WAAW,EACX,MAAM,EACN,IAAI,EACJ,SAAS,GACV,EAAE,cAAc,+BA2BhB"}
+8 -37
View File
@@ -1,48 +1,19 @@
"use client";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/**
* A date (or date + time) field that reads like a sentence and picks like the
* phone does.
*
* The native picker is the best one there is on a phone — what looked bad
* across the fleet was the raw field around it: the browser's locale
* placeholder ("tt.mm.jjjj, --:--"), unstyled, different in every browser.
* So the native input stays (keyboard entry, a11y, autofill all keep
* working) and sits transparently over a display that says "Sat, 11 Oct ·
* 14:00". A tap anywhere opens the platform picker via `showPicker()`.
* A labelled date (or date + time) field: `DateInput` with its own label and
* an optional hint, for places that do not already have a form-field wrapper.
* Apps that do (most) use `DateInput` directly.
*
* Values are `YYYY-MM-DD` or `YYYY-MM-DDTHH:MM` wall-clock strings — exactly
* what the native input speaks — never instants.
*/
import { useId } from "react";
import { dayLabel, formatTime } from "../labels.js";
import { isISODate, isWallTime } from "../calendar.js";
export function describeFieldValue(value, withTime, locale = "en") {
const [date, time] = value.split("T");
if (!isISODate(date))
return "";
const day = dayLabel(date, { locale });
const dayText = new Intl.DateTimeFormat(locale, {
timeZone: "UTC",
weekday: "short",
day: "numeric",
month: "short",
year: "numeric",
}).format(new Date(`${date}T00:00:00Z`));
if (withTime && isWallTime(time))
return `${dayText} · ${formatTime(time, locale)}`;
return dayText || day.short;
}
export function DateField({ label, value, onChange, withTime = false, min, max, required, name, placeholder, locale = "en", hint, className, }) {
import { DateInput, describeValue } from "./DateInput.js";
/** Kept for callers of 0.1–0.2: the words for a value, or "" if invalid. */
export const describeFieldValue = describeValue;
export function DateField({ label, value, onChange, withTime = false, min, max, required, name, placeholder, locale, hint, className, }) {
const id = useId();
const shown = value ? describeFieldValue(value, withTime, locale) : "";
return (_jsxs("div", { className: ["wk-field", className].filter(Boolean).join(" "), children: [_jsx("label", { className: "wk-label", htmlFor: id, children: label }), _jsxs("div", { className: "wk-field-box", "data-empty": shown ? undefined : true, children: [_jsx("span", { className: "wk-field-text", "aria-hidden": "true", children: shown || placeholder || (withTime ? "Pick a day and time" : "Pick a day") }), _jsxs("svg", { className: "wk-field-icon", viewBox: "0 0 24 24", "aria-hidden": "true", focusable: "false", children: [_jsx("rect", { x: "3.5", y: "5", width: "17", height: "15", rx: "2.5", fill: "none", stroke: "currentColor", strokeWidth: "1.6" }), _jsx("path", { d: "M3.5 9.5h17M8 3v4M16 3v4", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round" })] }), _jsx("input", { id: id, className: "wk-field-input", type: withTime ? "datetime-local" : "date", value: value, min: min, max: max, required: required, name: name, "aria-describedby": hint ? `${id}-hint` : undefined, onChange: (e) => onChange(e.target.value), onClick: (e) => {
try {
e.currentTarget.showPicker?.();
}
catch {
// Not allowed (e.g. cross-origin iframe): native focus still works.
}
} })] }), hint && (_jsx("p", { className: "wk-hint", id: `${id}-hint`, children: hint }))] }));
return (_jsxs("div", { className: ["wk-field", className].filter(Boolean).join(" "), children: [_jsx("label", { className: "wk-label", htmlFor: id, children: label }), _jsx(DateInput, { id: id, type: withTime ? "datetime-local" : "date", value: value, onChange: (e) => onChange(e.target.value), min: min, max: max, required: required, name: name, placeholder: placeholder, locale: locale, "aria-describedby": hint ? `${id}-hint` : undefined }), hint && (_jsx("p", { className: "wk-hint", id: `${id}-hint`, children: hint }))] }));
}
//# sourceMappingURL=DateField.js.map
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"DateField.js","sourceRoot":"","sources":["../../src/react/DateField.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb;;;;;;;;;;;;;GAaG;AACH,OAAO,EAAE,KAAK,EAAE,MAAM,OAAO,CAAC;AAC9B,OAAO,EAAE,QAAQ,EAAE,UAAU,EAAE,MAAM,cAAc,CAAC;AACpD,OAAO,EAAE,SAAS,EAAE,UAAU,EAAE,MAAM,gBAAgB,CAAC;AAkBvD,MAAM,UAAU,kBAAkB,CAAC,KAAa,EAAE,QAAiB,EAAE,MAAM,GAAG,IAAI;IAChF,MAAM,CAAC,IAAI,EAAE,IAAI,CAAC,GAAG,KAAK,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;IACtC,IAAI,CAAC,SAAS,CAAC,IAAI,CAAC;QAAE,OAAO,EAAE,CAAC;IAChC,MAAM,GAAG,GAAG,QAAQ,CAAC,IAAI,EAAE,EAAE,MAAM,EAAE,CAAC,CAAC;IACvC,MAAM,OAAO,GAAG,IAAI,IAAI,CAAC,cAAc,CAAC,MAAM,EAAE;QAC9C,QAAQ,EAAE,KAAK;QACf,OAAO,EAAE,OAAO;QAChB,GAAG,EAAE,SAAS;QACd,KAAK,EAAE,OAAO;QACd,IAAI,EAAE,SAAS;KAChB,CAAC,CAAC,MAAM,CAAC,IAAI,IAAI,CAAC,GAAG,IAAI,YAAY,CAAC,CAAC,CAAC;IACzC,IAAI,QAAQ,IAAI,UAAU,CAAC,IAAI,CAAC;QAAE,OAAO,GAAG,OAAO,MAAM,UAAU,CAAC,IAAI,EAAE,MAAM,CAAC,EAAE,CAAC;IACpF,OAAO,OAAO,IAAI,GAAG,CAAC,KAAK,CAAC;AAC9B,CAAC;AAED,MAAM,UAAU,SAAS,CAAC,EACxB,KAAK,EACL,KAAK,EACL,QAAQ,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E,CAAC,UAAU,EAAE,SAAS,CAAC,CAAC,MAAM,CAAC,OAAO,CAAC,CAAC,IAAI,CAAC,GAAG,CAAC,aAC/D,gBAAO,SAAS,EAAC,UAAU,EAAC,OAAO,EAAE,EAAE,YACpC,KAAK,GACA,EACR,KAAC,SAAS,IACR,EAAE,EAAE,EAAE,EACN,IAAI,EAAE,QAAQ,CAAC,CAAC,CAAC,gBAAgB,CAAC,CAAC,CAAC,MAAM,EAC1C,KAAK,EAAE,KAAK,EACZ,QAAQ,EAAE,CAAC,CAAC,EAAE,EAAE,CAAC,QAAQ,CAAC,CAAC,CAAC,MAAM,CAAC,KAAK,CAAC,EACzC,GAAG,EAAE,GAAG,EACR,GAAG,EAAE,GAAG,EACR,QAAQ,EAAE,QAAQ,EAClB,IAAI,EAAE,IAAI,EACV,WAAW,EAAE,WAAW,EACxB,MAAM,EAAE,MAAM,sBACI,IAAI,CAAC,CAAC,CAAC,GAAG,EAAE,OAAO,CAAC,CAAC,CAAC,SAAS,GACjD,EACD,IAAI,IAAI,CACP,YAAG,SAAS,EAAC,SAAS,EAAC,EAAE,EAAE,GAAG,EAAE,OAAO,YACpC,IAAI,GACH,CACL,IACG,CACP,CAAC;AACJ,CAAC"}
+34
View File
@@ -0,0 +1,34 @@
/**
* A drop-in for `<input type="date">` and `<input type="datetime-local">`.
*
* Same props, same `onChange(event)` — a call site changes its tag and
* nothing else. What changes is what a person sees: the browser's bare field
* ("tt.mm.jjjj, --:--", different in every browser) is replaced by the value
* in words ("Sat, 11 Oct 2026 · 14:00") in the app's OWN input styling (its
* `className` lands on the visible box), while the real input stays on top,
* transparent, so the platform picker, keyboard entry, autofill, validation
* bubbles and form submission all keep working.
*
* Controlled (`value`) or uncontrolled (`defaultValue`, e.g. a server-action
* form): the visible text follows whichever the app uses.
*/
import { type ChangeEvent, type InputHTMLAttributes } from "react";
export interface DateInputProps extends Omit<InputHTMLAttributes<HTMLInputElement>, "type" | "onChange" | "value" | "defaultValue"> {
/** `date` (default) or `datetime-local`. */
type?: "date" | "datetime-local";
/** `YYYY-MM-DD` or `YYYY-MM-DDTHH:MM`. */
value?: string;
defaultValue?: string;
onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
/** Words shown while empty. Defaults to a short phrase in the page language. */
placeholder?: string;
/** BCP 47 tag. Defaults to the page's `<html lang>` (read after mount). */
locale?: string;
/** Applied to the visible box — give it the same classes as the app's inputs. */
className?: string;
}
export declare function emptyWords(locale: string, withTime: boolean): string;
/** "Sat, 11 Oct 2026" or "Sat, 11 Oct 2026 · 14:00"; "" when not a valid value. */
export declare function describeValue(value: string, withTime: boolean, locale?: string): string;
export declare const DateInput: import("react").ForwardRefExoticComponent<DateInputProps & import("react").RefAttributes<HTMLInputElement>>;
//# sourceMappingURL=DateInput.d.ts.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"DateInput.d.ts","sourceRoot":"","sources":["../../src/react/DateInput.tsx"],"names":[],"mappings":"AAEA;;;;;;;;;;;;;GAaG;AACH,OAAO,EAIL,KAAK,WAAW,EAChB,KAAK,mBAAmB,EAEzB,MAAM,OAAO,CAAC;AAIf,MAAM,WAAW,cAAe,SAAQ,IAAI,CAC1C,mBAAmB,CAAC,gBAAgB,CAAC,EACrC,MAAM,GAAG,UAAU,GAAG,OAAO,GAAG,cAAc,CAC/C;IACC,4CAA4C;IAC5C,IAAI,CAAC,EAAE,MAAM,GAAG,gBAAgB,CAAC;IACjC,0CAA0C;IAC1C,KAAK,CAAC,EAAE,MAAM,CAAC;IACf,YAAY,CAAC,EAAE,MAAM,CAAC;IACtB,QAAQ,CAAC,EAAE,CAAC,KAAK,EAAE,WAAW,CAAC,gBAAgB,CAAC,KAAK,IAAI,CAAC;IAC1D,gFAAgF;IAChF,WAAW,CAAC,EAAE,MAAM,CAAC;IACrB,2EAA2E;IAC3E,MAAM,CAAC,EAAE,MAAM,CAAC;IAChB,iFAAiF;IACjF,SAAS,CAAC,EAAE,MAAM,CAAC;CACpB;AAUD,wBAAgB,UAAU,CAAC,MAAM,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,GAAG,MAAM,CAGpE;AAED,mFAAmF;AACnF,wBAAgB,aAAa,CAAC,KAAK,EAAE,MAAM,EAAE,QAAQ,EAAE,OAAO,EAAE,MAAM,SAAO,GAAG,MAAM,CAWrF;AAWD,eAAO,MAAM,SAAS,6GAiFpB,CAAC"}
+83
View File
@@ -0,0 +1,83 @@
"use client";
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
/**
* A drop-in for `<input type="date">` and `<input type="datetime-local">`.
*
* Same props, same `onChange(event)` — a call site changes its tag and
* nothing else. What changes is what a person sees: the browser's bare field
* ("tt.mm.jjjj, --:--", different in every browser) is replaced by the value
* in words ("Sat, 11 Oct 2026 · 14:00") in the app's OWN input styling (its
* `className` lands on the visible box), while the real input stays on top,
* transparent, so the platform picker, keyboard entry, autofill, validation
* bubbles and form submission all keep working.
*
* Controlled (`value`) or uncontrolled (`defaultValue`, e.g. a server-action
* form): the visible text follows whichever the app uses.
*/
import { forwardRef, useEffect, useState, } from "react";
import { isISODate, isWallTime } from "../calendar.js";
import { formatTime } from "../labels.js";
const EMPTY_WORDS = {
en: ["Pick a date", "Pick a date and time"],
de: ["Datum wählen", "Datum und Uhrzeit wählen"],
fr: ["Choisir une date", "Choisir la date et l'heure"],
it: ["Scegli una data", "Scegli data e ora"],
es: ["Elegir fecha", "Elegir fecha y hora"],
};
export function emptyWords(locale, withTime) {
const words = EMPTY_WORDS[locale.toLowerCase().split("-")[0]] ?? EMPTY_WORDS.en;
return words[withTime ? 1 : 0];
}
/** "Sat, 11 Oct 2026" or "Sat, 11 Oct 2026 · 14:00"; "" when not a valid value. */
export function describeValue(value, withTime, locale = "en") {
const [date, time] = value.split("T");
if (!isISODate(date))
return "";
const day = new Intl.DateTimeFormat(locale, {
timeZone: "UTC",
weekday: "short",
day: "numeric",
month: "short",
year: "numeric",
}).format(new Date(`${date}T00:00:00Z`));
return withTime && isWallTime(time) ? `${day} · ${formatTime(time, locale)}` : day;
}
/** An unknown tag from <html lang> must never throw during render. */
function safeDescribe(value, withTime, locale) {
try {
return describeValue(value, withTime, locale);
}
catch {
return describeValue(value, withTime, "en");
}
}
export const DateInput = forwardRef(function DateInput({ type = "date", value, defaultValue, onChange, placeholder, locale, className, style, onClick, ...rest }, ref) {
const withTime = type === "datetime-local";
const [inner, setInner] = useState(defaultValue ?? "");
const [lang, setLang] = useState(locale ?? "en");
useEffect(() => {
if (locale)
setLang(locale);
else
setLang(document.documentElement.lang || "en");
}, [locale]);
const current = value ?? inner;
const text = current ? safeDescribe(current, withTime, lang) : "";
const empty = !text;
const handleClick = (event) => {
onClick?.(event);
if (event.defaultPrevented)
return;
try {
event.currentTarget.showPicker?.();
}
catch {
// Not permitted here (e.g. a cross-origin frame): native focus still works.
}
};
return (_jsxs("span", { className: ["wk-input", className].filter(Boolean).join(" "), "data-empty": empty || undefined, "data-disabled": rest.disabled || undefined, "data-invalid": rest["aria-invalid"] === true || rest["aria-invalid"] === "true" || undefined, style: style, children: [_jsx("span", { className: "wk-input-text", "aria-hidden": "true", children: text || placeholder || emptyWords(lang, withTime) }), _jsxs("svg", { className: "wk-input-icon", viewBox: "0 0 24 24", "aria-hidden": "true", focusable: "false", children: [_jsx("rect", { x: "3.5", y: "5", width: "17", height: "15", rx: "2.5", fill: "none", stroke: "currentColor", strokeWidth: "1.6" }), _jsx("path", { d: "M3.5 9.5h17M8 3v4M16 3v4", fill: "none", stroke: "currentColor", strokeWidth: "1.6", strokeLinecap: "round" })] }), _jsx("input", { ...rest, ref: ref, type: type, className: "wk-input-native", ...(value !== undefined ? { value } : { defaultValue }), onClick: handleClick, onChange: (event) => {
setInner(event.target.value);
onChange?.(event);
} })] }));
});
//# sourceMappingURL=DateInput.js.map
+1
View File
@@ -0,0 +1 @@
{"version":3,"file":"DateInput.js","sourceRoot":"","sources":["../../src/react/DateInput.tsx"],"names":[],"mappings":"AAAA,YAAY,CAAC;;AAEb;;;;;;;;;;;;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B,WAAW,EAAC,KAAK,EACjB,aAAa,EAAC,OAAO,GACrB,IACE,EACN,mBACM,IAAI,EACR,GAAG,EAAE,GAAG,EACR,IAAI,EAAE,IAAI,EACV,SAAS,EAAC,iBAAiB,KACvB,CAAC,KAAK,KAAK,SAAS,CAAC,CAAC,CAAC,EAAE,KAAK,EAAE,CAAC,CAAC,CAAC,EAAE,YAAY,EAAE,CAAC,EACxD,OAAO,EAAE,WAAW,EACpB,QAAQ,EAAE,CAAC,KAAK,EAAE,EAAE;oBAClB,QAAQ,CAAC,KAAK,CAAC,MAAM,CAAC,KAAK,CAAC,CAAC;oBAC7B,QAAQ,EAAE,CAAC,KAAK,CAAC,CAAC;gBACpB,CAAC,GACD,IACG,CACR,CAAC;AACJ,CAAC,CAAC,CAAC"}
+1
View File
@@ -1,5 +1,6 @@
export { ChipGroup, type ChipGroupProps, type ChipOption } from "./ChipGroup.js";
export { DateField, describeFieldValue, type DateFieldProps } from "./DateField.js";
export { DateInput, describeValue, emptyWords, type DateInputProps } from "./DateInput.js";
export { DayStrip, type DayStripProps } from "./DayStrip.js";
export { BookingRequestPicker, DEFAULT_PICKER_WORDS, type BookingPickerWords, type BookingRequestPickerProps, } from "./BookingRequestPicker.js";
//# sourceMappingURL=index.d.ts.map
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,cAAc,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjF,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACpF,OAAO,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,GAC/B,MAAM,2BAA2B,CAAC"}
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAE,KAAK,cAAc,EAAE,KAAK,UAAU,EAAE,MAAM,gBAAgB,CAAC;AACjF,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AACpF,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAE,KAAK,cAAc,EAAE,MAAM,gBAAgB,CAAC;AAC3F,OAAO,EAAE,QAAQ,EAAE,KAAK,aAAa,EAAE,MAAM,eAAe,CAAC;AAC7D,OAAO,EACL,oBAAoB,EACpB,oBAAoB,EACpB,KAAK,kBAAkB,EACvB,KAAK,yBAAyB,GAC/B,MAAM,2BAA2B,CAAC"}
+1
View File
@@ -1,5 +1,6 @@
export { ChipGroup } from "./ChipGroup.js";
export { DateField, describeFieldValue } from "./DateField.js";
export { DateInput, describeValue, emptyWords } from "./DateInput.js";
export { DayStrip } from "./DayStrip.js";
export { BookingRequestPicker, DEFAULT_PICKER_WORDS, } from "./BookingRequestPicker.js";
//# sourceMappingURL=index.js.map
+1 -1
View File
@@ -1 +1 @@
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAwC,MAAM,gBAAgB,CAAC;AACjF,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAuB,MAAM,gBAAgB,CAAC;AACpF,OAAO,EAAE,QAAQ,EAAsB,MAAM,eAAe,CAAC;AAC7D,OAAO,EACL,oBAAoB,EACpB,oBAAoB,GAGrB,MAAM,2BAA2B,CAAC"}
{"version":3,"file":"index.js","sourceRoot":"","sources":["../../src/react/index.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,SAAS,EAAwC,MAAM,gBAAgB,CAAC;AACjF,OAAO,EAAE,SAAS,EAAE,kBAAkB,EAAuB,MAAM,gBAAgB,CAAC;AACpF,OAAO,EAAE,SAAS,EAAE,aAAa,EAAE,UAAU,EAAuB,MAAM,gBAAgB,CAAC;AAC3F,OAAO,EAAE,QAAQ,EAAsB,MAAM,eAAe,CAAC;AAC7D,OAAO,EACL,oBAAoB,EACpB,oBAAoB,GAGrB,MAAM,2BAA2B,CAAC"}
+1 -1
View File
@@ -1,6 +1,6 @@
{
"name": "@bitbaum/whenkit",
"version": "0.1.0",
"version": "0.3.0",
"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",
+12 -2
View File
@@ -63,6 +63,12 @@ export interface BookingRequestPickerProps {
hours?: DailyHours;
/** Weekdays open, 0 = Sunday … 6 = Saturday. Omit for every day. */
openWeekdays?: number[];
/**
* Lengths to offer, minutes. Defaults to what fits the opening hours. Pass
* one value for a fixed duration (a 60-minute session): the length row is
* not shown and that duration is used.
*/
lengths?: number[];
/** Spacing of start times, minutes. */
stepMinutes?: number;
/** Days shown as chips. */
@@ -86,6 +92,7 @@ export function BookingRequestPicker({
value,
onChange,
hours = DEFAULT_HOURS,
lengths: lengthsProp,
openWeekdays,
stepMinutes = 60,
daysAhead = 14,
@@ -149,7 +156,10 @@ export function BookingRequestPicker({
/>
);
} else {
const lengths = lengthOptions(hours);
const lengths =
lengthsProp && lengthsProp.filter((m) => m > 0).length > 0
? lengthsProp.filter((m) => m > 0)
: lengthOptions(hours);
const length = choice.lengthMinutes ?? lengths[0];
const slots = choice.date
? timeSlots({
@@ -191,7 +201,7 @@ export function BookingRequestPicker({
{words.noTimes}
</p>
))}
{choice.date && slots.length > 0 && (
{choice.date && slots.length > 0 && lengths.length > 1 && (
<ChipGroup<number>
label={words.length}
value={length}
+20 -70
View File
@@ -1,22 +1,15 @@
"use client";
/**
* A date (or date + time) field that reads like a sentence and picks like the
* phone does.
*
* The native picker is the best one there is on a phone — what looked bad
* across the fleet was the raw field around it: the browser's locale
* placeholder ("tt.mm.jjjj, --:--"), unstyled, different in every browser.
* So the native input stays (keyboard entry, a11y, autofill all keep
* working) and sits transparently over a display that says "Sat, 11 Oct ·
* 14:00". A tap anywhere opens the platform picker via `showPicker()`.
* A labelled date (or date + time) field: `DateInput` with its own label and
* an optional hint, for places that do not already have a form-field wrapper.
* Apps that do (most) use `DateInput` directly.
*
* Values are `YYYY-MM-DD` or `YYYY-MM-DDTHH:MM` wall-clock strings — exactly
* what the native input speaks — never instants.
*/
import { useId } from "react";
import { dayLabel, formatTime } from "../labels.js";
import { isISODate, isWallTime } from "../calendar.js";
import { DateInput, describeValue } from "./DateInput.js";
export interface DateFieldProps {
label: string;
@@ -34,20 +27,8 @@ export interface DateFieldProps {
className?: string;
}
export function describeFieldValue(value: string, withTime: boolean, locale = "en"): string {
const [date, time] = value.split("T");
if (!isISODate(date)) return "";
const day = dayLabel(date, { locale });
const dayText = new Intl.DateTimeFormat(locale, {
timeZone: "UTC",
weekday: "short",
day: "numeric",
month: "short",
year: "numeric",
}).format(new Date(`${date}T00:00:00Z`));
if (withTime && isWallTime(time)) return `${dayText} · ${formatTime(time, locale)}`;
return dayText || day.short;
}
/** Kept for callers of 0.1–0.2: the words for a value, or "" if invalid. */
export const describeFieldValue = describeValue;
export function DateField({
label,
@@ -59,60 +40,29 @@ export function DateField({
required,
name,
placeholder,
locale = "en",
locale,
hint,
className,
}: DateFieldProps) {
const id = useId();
const shown = value ? describeFieldValue(value, withTime, locale) : "";
return (
<div className={["wk-field", className].filter(Boolean).join(" ")}>
<label className="wk-label" htmlFor={id}>
{label}
</label>
<div className="wk-field-box" data-empty={shown ? undefined : true}>
<span className="wk-field-text" aria-hidden="true">
{shown || placeholder || (withTime ? "Pick a day and time" : "Pick a day")}
</span>
<svg className="wk-field-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
<rect
x="3.5"
y="5"
width="17"
height="15"
rx="2.5"
fill="none"
stroke="currentColor"
strokeWidth="1.6"
/>
<path
d="M3.5 9.5h17M8 3v4M16 3v4"
fill="none"
stroke="currentColor"
strokeWidth="1.6"
strokeLinecap="round"
/>
</svg>
<input
id={id}
className="wk-field-input"
type={withTime ? "datetime-local" : "date"}
value={value}
min={min}
max={max}
required={required}
name={name}
aria-describedby={hint ? `${id}-hint` : undefined}
onChange={(e) => onChange(e.target.value)}
onClick={(e) => {
try {
e.currentTarget.showPicker?.();
} catch {
// Not allowed (e.g. cross-origin iframe): native focus still works.
}
}}
/>
</div>
<DateInput
id={id}
type={withTime ? "datetime-local" : "date"}
value={value}
onChange={(e) => onChange(e.target.value)}
min={min}
max={max}
required={required}
name={name}
placeholder={placeholder}
locale={locale}
aria-describedby={hint ? `${id}-hint` : undefined}
/>
{hint && (
<p className="wk-hint" id={`${id}-hint`}>
{hint}
+163
View File
@@ -0,0 +1,163 @@
"use client";
/**
* A drop-in for `<input type="date">` and `<input type="datetime-local">`.
*
* Same props, same `onChange(event)` — a call site changes its tag and
* nothing else. What changes is what a person sees: the browser's bare field
* ("tt.mm.jjjj, --:--", different in every browser) is replaced by the value
* in words ("Sat, 11 Oct 2026 · 14:00") in the app's OWN input styling (its
* `className` lands on the visible box), while the real input stays on top,
* transparent, so the platform picker, keyboard entry, autofill, validation
* bubbles and form submission all keep working.
*
* Controlled (`value`) or uncontrolled (`defaultValue`, e.g. a server-action
* form): the visible text follows whichever the app uses.
*/
import {
forwardRef,
useEffect,
useState,
type ChangeEvent,
type InputHTMLAttributes,
type MouseEvent,
} from "react";
import { isISODate, isWallTime } from "../calendar.js";
import { formatTime } from "../labels.js";
export interface DateInputProps extends Omit<
InputHTMLAttributes<HTMLInputElement>,
"type" | "onChange" | "value" | "defaultValue"
> {
/** `date` (default) or `datetime-local`. */
type?: "date" | "datetime-local";
/** `YYYY-MM-DD` or `YYYY-MM-DDTHH:MM`. */
value?: string;
defaultValue?: string;
onChange?: (event: ChangeEvent<HTMLInputElement>) => void;
/** Words shown while empty. Defaults to a short phrase in the page language. */
placeholder?: string;
/** BCP 47 tag. Defaults to the page's `<html lang>` (read after mount). */
locale?: string;
/** Applied to the visible box — give it the same classes as the app's inputs. */
className?: string;
}
const EMPTY_WORDS: Record<string, [string, string]> = {
en: ["Pick a date", "Pick a date and time"],
de: ["Datum wählen", "Datum und Uhrzeit wählen"],
fr: ["Choisir une date", "Choisir la date et l'heure"],
it: ["Scegli una data", "Scegli data e ora"],
es: ["Elegir fecha", "Elegir fecha y hora"],
};
export function emptyWords(locale: string, withTime: boolean): string {
const words = EMPTY_WORDS[locale.toLowerCase().split("-")[0]] ?? EMPTY_WORDS.en;
return words[withTime ? 1 : 0];
}
/** "Sat, 11 Oct 2026" or "Sat, 11 Oct 2026 · 14:00"; "" when not a valid value. */
export function describeValue(value: string, withTime: boolean, locale = "en"): string {
const [date, time] = value.split("T");
if (!isISODate(date)) return "";
const day = new Intl.DateTimeFormat(locale, {
timeZone: "UTC",
weekday: "short",
day: "numeric",
month: "short",
year: "numeric",
}).format(new Date(`${date}T00:00:00Z`));
return withTime && isWallTime(time) ? `${day} · ${formatTime(time, locale)}` : day;
}
/** An unknown tag from <html lang> must never throw during render. */
function safeDescribe(value: string, withTime: boolean, locale: string): string {
try {
return describeValue(value, withTime, locale);
} catch {
return describeValue(value, withTime, "en");
}
}
export const DateInput = forwardRef<HTMLInputElement, DateInputProps>(function DateInput(
{
type = "date",
value,
defaultValue,
onChange,
placeholder,
locale,
className,
style,
onClick,
...rest
},
ref,
) {
const withTime = type === "datetime-local";
const [inner, setInner] = useState(defaultValue ?? "");
const [lang, setLang] = useState(locale ?? "en");
useEffect(() => {
if (locale) setLang(locale);
else setLang(document.documentElement.lang || "en");
}, [locale]);
const current = value ?? inner;
const text = current ? safeDescribe(current, withTime, lang) : "";
const empty = !text;
const handleClick = (event: MouseEvent<HTMLInputElement>) => {
onClick?.(event);
if (event.defaultPrevented) return;
try {
event.currentTarget.showPicker?.();
} catch {
// Not permitted here (e.g. a cross-origin frame): native focus still works.
}
};
return (
<span
className={["wk-input", className].filter(Boolean).join(" ")}
data-empty={empty || undefined}
data-disabled={rest.disabled || undefined}
data-invalid={rest["aria-invalid"] === true || rest["aria-invalid"] === "true" || undefined}
style={style}
>
<span className="wk-input-text" aria-hidden="true">
{text || placeholder || emptyWords(lang, withTime)}
</span>
<svg className="wk-input-icon" viewBox="0 0 24 24" aria-hidden="true" focusable="false">
<rect
x="3.5"
y="5"
width="17"
height="15"
rx="2.5"
fill="none"
stroke="currentColor"
strokeWidth="1.6"
/>
<path
d="M3.5 9.5h17M8 3v4M16 3v4"
fill="none"
stroke="currentColor"
strokeWidth="1.6"
strokeLinecap="round"
/>
</svg>
<input
{...rest}
ref={ref}
type={type}
className="wk-input-native"
{...(value !== undefined ? { value } : { defaultValue })}
onClick={handleClick}
onChange={(event) => {
setInner(event.target.value);
onChange?.(event);
}}
/>
</span>
);
});
+1
View File
@@ -1,5 +1,6 @@
export { ChipGroup, type ChipGroupProps, type ChipOption } from "./ChipGroup.js";
export { DateField, describeFieldValue, type DateFieldProps } from "./DateField.js";
export { DateInput, describeValue, emptyWords, type DateInputProps } from "./DateInput.js";
export { DayStrip, type DayStripProps } from "./DayStrip.js";
export {
BookingRequestPicker,
+63 -18
View File
@@ -26,6 +26,7 @@
--wk-accent-soft: color-mix(in srgb, var(--wk-accent) 14%, transparent);
--wk-radius: var(--radius-control, 0.625rem);
--wk-font: var(--font-sans, system-ui, -apple-system, "Segoe UI", sans-serif);
--wk-danger: hsl(var(--status-negative, 0 65% 50%));
--wk-text: 1rem;
--wk-small: 0.8125rem;
--wk-target: 2.75rem;
@@ -126,6 +127,12 @@
/* ---- the day strip ---- */
.wk-strip {
/* Claim no width of its own: fourteen chips side by side must scroll inside
whatever space the strip is given, not prop open a grid or dialog column
(a CSS grid item's min-width is its content's). Found in OrangeCat's
booking dialog, where it pushed Send off-screen at 390px. */
contain: inline-size;
width: 100%;
display: flex;
gap: 0.5rem;
overflow-x: auto;
@@ -202,7 +209,7 @@
text-decoration: line-through;
}
/* ---- the readable date field over the native picker ---- */
/* ---- the readable date input over the native picker ---- */
.wk-field {
display: flex;
@@ -210,47 +217,80 @@
gap: 0.375rem;
}
.wk-field-box {
/* The visible box, in two parts.
STRUCTURE (unlayered): what the stacked native input needs to work.
LOOK (@layer base): border, padding, colour, size. A named low layer, so an
app's own classes always win — Tailwind v4 utilities and component classes
sit in higher layers, plain app CSS is unlayered — and the date input then
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 {
position: relative;
display: flex;
align-items: center;
gap: 0.5rem;
min-height: var(--wk-target);
padding: 0 0.875rem;
border: 1px solid var(--wk-line-2);
border-radius: var(--wk-radius);
background: var(--wk-bg);
box-sizing: border-box;
min-width: 0;
}
.wk-field-box:focus-within {
@layer base {
.wk-input {
width: 100%;
padding: 0.7rem 0.875rem;
border: 1px solid var(--wk-line-2);
border-radius: var(--wk-radius);
background: var(--wk-bg);
color: inherit;
font: inherit;
font-size: var(--wk-text);
line-height: 1.3;
}
}
.wk-field .wk-input,
.wk-other .wk-input {
min-height: var(--wk-target);
}
.wk-input:focus-within {
outline: 2px solid var(--wk-accent);
outline-offset: 1px;
border-color: var(--wk-accent);
}
.wk-field-text {
.wk-input[data-invalid] {
border-color: var(--wk-danger, #dc2626);
}
.wk-input[data-disabled] {
opacity: 0.55;
cursor: not-allowed;
}
.wk-input-text {
flex: 1;
min-width: 0;
font-size: var(--wk-text);
overflow: hidden;
text-overflow: ellipsis;
white-space: nowrap;
text-align: left;
}
.wk-field-box[data-empty] .wk-field-text {
color: var(--wk-muted);
.wk-input[data-empty] .wk-input-text {
opacity: 0.55;
}
.wk-field-icon {
.wk-input-icon {
width: 1.25rem;
height: 1.25rem;
flex: 0 0 auto;
color: var(--wk-fg-2);
opacity: 0.7;
}
/* The real control: full-size, invisible, on top — taps open the native
picker, keyboard entry and autofill keep working. 16px so iOS does not zoom. */
.wk-field-input {
picker, keyboard entry, autofill and validation keep working. 16px so iOS
does not zoom the page on focus. */
.wk-input-native {
position: absolute;
inset: 0;
width: 100%;
@@ -264,6 +304,10 @@
color-scheme: light dark;
}
.wk-input-native:disabled {
cursor: not-allowed;
}
/* "Another date…" under the strip is a quiet secondary control. */
.wk-other .wk-label {
position: absolute;
@@ -273,8 +317,9 @@
clip: rect(0 0 0 0);
}
.wk-other .wk-field-box {
.wk-other .wk-input {
align-self: flex-start;
width: auto;
border-style: dashed;
}
+44 -2
View File
@@ -97,9 +97,34 @@ try {
`${name}: flexible request without a day`,
);
// The app's own classes win over whenkit's defaults — plain CSS and a
// layered (Tailwind-style) utility alike. Without @layer base for the
// defaults, whenkit's unlayered rules would beat the layered utility.
const own = await page.evaluate(() => {
const css = (sel) => getComputedStyle(document.querySelector(sel));
return {
plainBorder: css("#own-class .wk-input").borderTopColor,
plainWidth: css("#own-class .wk-input").borderTopWidth,
utilWidth: css("#util-class .wk-input").borderTopWidth,
utilStyle: css("#util-class .wk-input").borderTopStyle,
};
});
check(
own.plainBorder === "rgb(255, 0, 0)" && own.plainWidth === "3px",
`${name}: an app class beats whenkit's input look (${own.plainBorder} ${own.plainWidth})`,
);
check(
own.utilWidth === "5px" && own.utilStyle === "dashed",
`${name}: a layered utility beats it too (${own.utilWidth} ${own.utilStyle})`,
);
const small = await page.evaluate(
() =>
[...document.querySelectorAll(".wk-chip, .wk-day, .wk-field-box")]
[
...document.querySelectorAll(
".wk-chip, .wk-day, .wk-field .wk-input, .wk-other .wk-input",
),
]
.filter((el) => el.getClientRects().length > 0)
.map((el) => el.getBoundingClientRect())
.filter((r) => r.height < 43.5 || r.width < 43.5).length,
@@ -107,7 +132,7 @@ try {
check(small === 0, `${name}: every chip, day and field is at least 44px (${small} too small)`);
const inputSize = await page.evaluate(() =>
parseFloat(getComputedStyle(document.querySelector(".wk-field-input")).fontSize),
parseFloat(getComputedStyle(document.querySelector(".wk-input-native")).fontSize),
);
check(inputSize >= 16, `${name}: date input is ${inputSize}px (iOS zooms below 16)`);
@@ -115,6 +140,23 @@ try {
await page.evaluate(() => document.documentElement.scrollWidth <= window.innerWidth),
`${name}: still no horizontal scroll after picking`,
);
// Nothing may be wider than its column: a grid cell (like a dialog's) must
// not be propped open by the day strip.
const wider = await page.evaluate(
() =>
[...document.querySelectorAll(".grid > section, #dialog")].filter(
(s) =>
s.scrollWidth > s.clientWidth + 1 ||
s.getBoundingClientRect().right > window.innerWidth + 1,
).length,
);
check(wider === 0, `${name}: no column or dialog propped open by the picker (${wider})`);
const sendVisible = await page.evaluate(() => {
const r = document.getElementById("dialog-send").getBoundingClientRect();
return r.right <= window.innerWidth + 1;
});
check(sendVisible, `${name}: the dialog's button stays on screen`);
check(errors.length === 0, `${name}: no page errors ${errors.join(" | ")}`);
// Let chip colour transitions finish so the screenshot shows real states.
await page.waitForTimeout(300);
+77 -1
View File
@@ -5,7 +5,7 @@ import { test } from "node:test";
import assert from "node:assert/strict";
import { createElement as h } from "react";
import { renderToString } from "react-dom/server";
import { BookingRequestPicker, DateField, ChipGroup } from "../dist/react/index.js";
import { BookingRequestPicker, DateField, ChipGroup, DateInput } from "../dist/react/index.js";
const NOW = new Date("2026-10-10T08:00:00Z"); // 10:00 in Zurich, a Saturday
const base = { zone: "Europe/Zurich", locale: "en-GB", now: NOW, onChange: () => {} };
@@ -93,3 +93,79 @@ test("ChipGroup is a radiogroup with one tab stop", () => {
assert.equal((html.match(/tabindex="0"/g) ?? []).length, 1);
assert.match(html, /role="radio" aria-checked="true"/);
});
test("a fixed duration shows no length choice and is used for the slot", () => {
const html = renderToString(
h(BookingRequestPicker, {
...base,
unit: "hour",
lengths: [90],
value: { kind: "slot", date: "2026-10-11", time: "14:00", lengthMinutes: 90 },
}),
);
assert.doesNotMatch(html, /aria-label="For how long"/);
assert.match(html, /14:00–15:30/);
// 17:00 + 90 min would end after 18:00 closing, so it is not offered.
assert.doesNotMatch(html, />17:00</);
});
test("DateInput is a drop-in: every input prop reaches the real input, className the visible box", () => {
const html = renderToString(
h(DateInput, {
id: "due",
name: "due",
required: true,
min: "2026-10-01",
disabled: true,
"aria-invalid": true,
className: "ui-input-compact",
value: "2026-10-11",
onChange: () => {},
locale: "en-GB",
}),
);
assert.match(html, /<span class="wk-input ui-input-compact"/);
assert.match(html, /<input[^>]*id="due"/);
assert.match(html, /<input[^>]*name="due"/);
assert.match(html, /<input[^>]*required/);
assert.match(html, /<input[^>]*min="2026-10-01"/);
assert.match(html, /<input[^>]*disabled/);
assert.match(html, /<input[^>]*aria-invalid="true"/);
assert.match(html, /<input[^>]*type="date"/);
assert.match(html, /Sun, 11 Oct 2026/);
assert.match(html, /data-invalid/);
});
test("DateInput works uncontrolled (a server-action form): defaultValue shows and submits", () => {
const html = renderToString(
h(DateInput, { name: "date", defaultValue: "2026-03-05", locale: "de" }),
);
assert.match(html, /Do\., 5\. März 2026|Do, 5\. März 2026/);
assert.match(html, /<input[^>]*value="2026-03-05"/);
assert.match(html, /<input[^>]*name="date"/);
});
test("DateInput datetime-local shows the time, and an empty one shows words in the page language", () => {
const withTime = renderToString(
h(DateInput, {
type: "datetime-local",
value: "2026-10-11T14:30",
onChange: () => {},
locale: "en-GB",
}),
);
assert.match(withTime, /Sun, 11 Oct 2026 · 14:30/);
const empty = renderToString(h(DateInput, { value: "", onChange: () => {}, locale: "de" }));
assert.match(empty, /Datum wählen/);
assert.match(empty, /data-empty/);
const unknown = renderToString(h(DateInput, { value: "", onChange: () => {}, locale: "xx" }));
assert.match(unknown, /Pick a date/);
});
test("DateInput never throws on a bad value or a bad locale", () => {
assert.doesNotThrow(() =>
renderToString(
h(DateInput, { value: "not-a-date", onChange: () => {}, locale: "zz-INVALID-tag-!!" }),
),
);
});