mirror of
https://github.com/bitbaum/whenkit.git
synced 2026-12-04 04:27:25 +01:00
Day chips, time chips, length chips, a readable date field over the native
picker, and a booking request that resolves to {startsAt, endsAt} in the
provider's zone.
- Core (no React): wall-clock YYYY-MM-DD / HH:MM strings, one zonedToUtc
(DST gaps resolve forward), todayIn(zone), slots inside opening hours,
lengths that fit, resolveRequest / describeRequest for three choices:
slot, days, flexible.
- React: BookingRequestPicker, DayStrip, ChipGroup (real radio groups),
DateField (native input transparent over a readable display).
- styles.css: --wk-* variables defaulting to @bitbaum/design-tokens; 44px
targets, 16px input, strip scrolls inside itself.
- Tests: 15 core + 8 server-render, and a Chromium check at 1280/390,
light/dark that taps bookings end to end. dist/ committed for github: installs.
Signed-off-by: Cato <41178744+catomean@users.noreply.github.com>
Co-authored-by: Claude Opus 5.5 (1M context) <noreply@anthropic.com>
48 lines
3.2 KiB
JavaScript
48 lines
3.2 KiB
JavaScript
"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()`.
|
|
*
|
|
* 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, }) {
|
|
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 }))] }));
|
|
}
|
|
//# sourceMappingURL=DateField.js.map
|