mirror of
https://github.com/bitbaum/whenkit.git
synced 2026-12-04 00:47:32 +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>
41 lines
2.3 KiB
JavaScript
41 lines
2.3 KiB
JavaScript
"use client";
|
|
import { jsx as _jsx, jsxs as _jsxs } from "react/jsx-runtime";
|
|
/**
|
|
* A row of tappable choices that is a real radio group: arrow keys move
|
|
* between chips, one is selected, a screen reader hears "3 of 6". Every chip
|
|
* is a 44px target. Used for times, lengths and modes — anything that would
|
|
* otherwise be a select or a typed value.
|
|
*/
|
|
import { useRef } from "react";
|
|
export function ChipGroup({ label, hideLabel, options, value, onChange, className, }) {
|
|
const refs = useRef([]);
|
|
const enabled = options.map((o, i) => (o.disabled ? -1 : i)).filter((i) => i >= 0);
|
|
const selectedIndex = options.findIndex((o) => o.value === value);
|
|
// Roving tab stop: the selected chip, else the first enabled one.
|
|
const tabStop = selectedIndex >= 0 && !options[selectedIndex].disabled ? selectedIndex : enabled[0];
|
|
const move = (from, delta) => {
|
|
const pos = enabled.indexOf(from);
|
|
const next = enabled[(pos + delta + enabled.length) % enabled.length];
|
|
if (next === undefined)
|
|
return;
|
|
onChange(options[next].value);
|
|
refs.current[next]?.focus();
|
|
};
|
|
const onKeyDown = (event, index) => {
|
|
if (event.key === "ArrowRight" || event.key === "ArrowDown") {
|
|
event.preventDefault();
|
|
move(index, 1);
|
|
}
|
|
else if (event.key === "ArrowLeft" || event.key === "ArrowUp") {
|
|
event.preventDefault();
|
|
move(index, -1);
|
|
}
|
|
};
|
|
return (_jsxs("div", { className: ["wk-group", className].filter(Boolean).join(" "), children: [_jsx("span", { className: hideLabel ? "wk-sr-only" : "wk-label", children: label }), _jsx("div", { className: "wk-chips", role: "radiogroup", "aria-label": label, children: options.map((option, index) => {
|
|
const selected = option.value === value;
|
|
return (_jsx("button", { ref: (el) => {
|
|
refs.current[index] = el;
|
|
}, type: "button", role: "radio", "aria-checked": selected, "aria-label": option.ariaLabel, disabled: option.disabled, tabIndex: index === tabStop ? 0 : -1, className: "wk-chip", "data-selected": selected || undefined, onClick: () => onChange(option.value), onKeyDown: (e) => onKeyDown(e, index), children: option.label }, String(option.value)));
|
|
}) })] }));
|
|
}
|
|
//# sourceMappingURL=ChipGroup.js.map
|