Mini calendar
A one-week strip of seven day radios with previous and next week buttons, for picking a day in tight spaces.
pnpm dlx shadcn@latest add @haze/mini-calendar---
import { ChevronLeft, ChevronRight } from "@lucide/astro";
import { cn } from "../../../lib/haze/utils";
interface Props {
/** Required. Every radio id and the legend id are derived from it. */
id: string;
/** Submitted field name. Defaults to the id. */
name?: string;
/** Visible question above the strip. */
legend?: string;
/** Any ISO date (YYYY-MM-DD) inside the week to show. The strip starts on `weekStart`. */
start?: string;
/** ISO date that is selected on load. */
value?: string;
/** ISO date marked as today with a dot. Pass it in; the component never reads the clock. */
today?: string;
/** First day of the week: 0 is Sunday, 1 is Monday. */
weekStart?: 0 | 1;
/** ISO dates that cannot be chosen. */
disabled?: string[];
locale?: string;
required?: boolean;
previousLabel?: string;
nextLabel?: string;
/** Word added to the name of today's cell for screen readers. */
todayLabel?: string;
class?: string;
/** Any other fieldset attribute, for example form. */
[key: string]: unknown;
}
const DAY = 86400000;
const toMs = (iso: string) => Date.parse(`${iso}T00:00:00Z`);
const toIso = (ms: number) => new Date(ms).toISOString().slice(0, 10);
const {
id,
name = id,
legend = "Pick a day",
start = "2026-11-09",
value,
today,
weekStart = 1,
disabled = [],
locale = "en",
required,
previousLabel = "Previous week",
nextLabel = "Next week",
todayLabel = "today",
class: className,
...rest
} = Astro.props;
const anchor = Number.isNaN(toMs(start)) ? toMs("2026-11-09") : toMs(start);
const dow = new Date(anchor).getUTCDay();
const first = anchor - ((dow - weekStart + 7) % 7) * DAY;
const dates = Array.from({ length: 7 }, (_, i) => toIso(first + i * DAY));
const opts = { timeZone: "UTC" } as const;
const weekdayShort = new Intl.DateTimeFormat(locale, { weekday: "short", ...opts });
const dayNumber = new Intl.DateTimeFormat(locale, { day: "numeric", ...opts });
const full = new Intl.DateTimeFormat(locale, { weekday: "long", month: "long", day: "numeric", ...opts });
const range = new Intl.DateTimeFormat(locale, { month: "short", day: "numeric", year: "numeric", ...opts });
const rangeText = range.formatRange(new Date(first), new Date(first + 6 * DAY));
const disabledSet = new Set(disabled);
const selectedIso = value && !disabledSet.has(value) ? value : "";
const legendId = `${id}-legend`;
const stepBtn =
"hidden size-8 shrink-0 cursor-pointer items-center justify-center rounded-lg border border-frame bg-field text-muted-foreground transition-[background-color,color,scale] duration-150 ease-snappy group-data-[enhanced]:inline-flex hover:bg-accent hover:text-foreground active:scale-[0.97] active:duration-75 motion-reduce:active:scale-100 focus-visible:outline-2 focus-visible:outline-offset-1 focus-visible:outline-ring";
---
<fieldset
{...rest}
id={id}
data-haze-mini-calendar
data-start={dates[0]}
data-value={selectedIso}
data-required={required ? "" : undefined}
data-today={today}
data-today-label={todayLabel}
data-locale={locale}
data-disabled={disabled.join(",")}
data-name={name}
class={cn("group w-fit max-w-full min-w-0 border-0 p-0", className)}
>
<legend id={legendId} class="text-[0.8125rem]/5 font-medium text-foreground">{legend}</legend>
<div class="mt-2 flex items-center justify-center gap-1">
<button type="button" data-mini-calendar-prev aria-label={previousLabel} class={stepBtn}>
<ChevronLeft aria-hidden="true" class="size-4 rtl:rotate-180" />
</button>
<p data-mini-calendar-range aria-live="polite" class="w-36 min-w-0 text-center text-xs/4 font-medium text-muted-foreground tabular-nums">{rangeText}</p>
<button type="button" data-mini-calendar-next aria-label={nextLabel} class={stepBtn}>
<ChevronRight aria-hidden="true" class="size-4 rtl:rotate-180" />
</button>
</div>
<div data-mini-calendar-grid class="relative isolate mt-2 grid grid-cols-[repeat(7,minmax(0,2.5rem))] gap-0.5">
<span
data-mini-calendar-indicator
aria-hidden="true"
class="pointer-events-none absolute top-0 left-0 -z-10 hidden h-(--mc-h) w-(--mc-w) translate-x-(--mc-x) translate-y-(--mc-y) rounded-lg bg-primary group-data-[enhanced]:block [[data-ready]_&]:transition-[translate,width] [[data-ready]_&]:duration-200 [[data-ready]_&]:ease-snappy motion-reduce:[[data-ready]_&]:transition-none"
></span>
{
dates.map((iso, i) => {
const date = new Date(toMs(iso));
const isToday = iso === today;
const off = disabledSet.has(iso);
const inputId = `${id}-${i}`;
return (
<div class="min-w-0">
<input
type="radio"
id={inputId}
name={name}
value={iso}
checked={!off && iso === selectedIso}
disabled={off}
required={required}
aria-label={`${weekdayShort.format(date)} ${dayNumber.format(date)}, ${full.format(date)}${isToday ? `, ${todayLabel}` : ""}`}
class="peer sr-only"
/>
<label
for={inputId}
class="flex h-12 min-w-0 cursor-pointer flex-col items-center justify-center gap-0.5 rounded-lg border border-transparent text-foreground transition-[border-color,background-color,color,scale] duration-150 ease-snappy select-none hover:bg-accent active:scale-[0.97] active:duration-75 motion-reduce:active:scale-100 peer-checked:bg-primary peer-checked:text-primary-foreground peer-checked:hover:bg-primary group-data-[enhanced]:peer-checked:bg-transparent group-data-[enhanced]:peer-checked:hover:bg-transparent peer-focus-visible:outline-2 peer-focus-visible:outline-offset-1 peer-focus-visible:outline-ring peer-disabled:cursor-not-allowed peer-disabled:text-muted-foreground/60 peer-disabled:line-through peer-disabled:hover:bg-transparent peer-disabled:active:scale-100"
>
<span aria-hidden="true" class="max-w-full truncate text-[0.6875rem]/4 font-medium opacity-70">{weekdayShort.format(date)}</span>
<span aria-hidden="true" data-mini-calendar-day class="text-[0.8125rem]/5 font-medium tabular-nums">{dayNumber.format(date)}</span>
<span aria-hidden="true" data-mini-calendar-dot class={cn("size-1 rounded-full bg-current", !isToday && "invisible")} />
</label>
</div>
);
})
}
</div>
<input type="hidden" name={name} data-mini-calendar-keep disabled />
</fieldset>
<script>
const DAY = 86400000;
const toMs = (iso: string) => Date.parse(`${iso}T00:00:00Z`);
const toIso = (ms: number) => new Date(ms).toISOString().slice(0, 10);
function place(root: HTMLElement, slide: boolean) {
const indicator = root.querySelector<HTMLElement>("[data-mini-calendar-indicator]");
if (!indicator) return;
const checked = root.querySelector<HTMLInputElement>('input[type="radio"]:checked');
const label = checked?.parentElement?.querySelector<HTMLElement>("label");
root.toggleAttribute("data-ready", slide);
indicator.style.visibility = label ? "" : "hidden";
if (!label) return;
indicator.style.setProperty("--mc-x", `${label.offsetLeft}px`);
indicator.style.setProperty("--mc-y", `${label.offsetTop}px`);
indicator.style.setProperty("--mc-w", `${label.offsetWidth}px`);
indicator.style.setProperty("--mc-h", `${label.offsetHeight}px`);
}
function render(root: HTMLElement, slide = false) {
const locale = root.dataset.locale || "en";
const start = toMs(root.dataset.start || "");
if (Number.isNaN(start)) return;
const off = new Set((root.dataset.disabled || "").split(",").filter(Boolean));
const selected = off.has(root.dataset.value || "") ? "" : root.dataset.value || "";
const required = root.hasAttribute("data-required");
const today = root.dataset.today || "";
const todayLabel = root.dataset.todayLabel || "today";
const opts = { timeZone: "UTC" } as const;
const weekdayShort = new Intl.DateTimeFormat(locale, { weekday: "short", ...opts });
const dayNumber = new Intl.DateTimeFormat(locale, { day: "numeric", ...opts });
const full = new Intl.DateTimeFormat(locale, { weekday: "long", month: "long", day: "numeric", ...opts });
const range = new Intl.DateTimeFormat(locale, { month: "short", day: "numeric", year: "numeric", ...opts });
const inputs = root.querySelectorAll<HTMLInputElement>('input[type="radio"]');
let visible = false;
inputs.forEach((input, i) => {
const iso = toIso(start + i * DAY);
const date = new Date(start + i * DAY);
input.value = iso;
input.disabled = off.has(iso);
input.checked = !input.disabled && iso === selected;
if (input.checked) visible = true;
input.setAttribute("aria-label", `${weekdayShort.format(date)} ${dayNumber.format(date)}, ${full.format(date)}${iso === today ? `, ${todayLabel}` : ""}`);
const label = input.parentElement?.querySelector("label");
const num = label?.querySelector("[data-mini-calendar-day]");
if (num) num.textContent = dayNumber.format(date);
label?.querySelector("[data-mini-calendar-dot]")?.classList.toggle("invisible", iso !== today);
});
const text = root.querySelector("[data-mini-calendar-range]");
const next = range.formatRange(new Date(start), new Date(start + 6 * DAY));
if (text && text.textContent !== next) text.textContent = next;
// A chosen day in another week still submits through a hidden field.
const keep = root.querySelector<HTMLInputElement>("[data-mini-calendar-keep]");
const keeping = !visible && !!selected;
if (keep) {
keep.disabled = !keeping;
keep.value = selected;
}
// The hidden field carries the value, so the visible radios must not block validation.
inputs.forEach((input) => {
input.required = required && !keeping;
});
place(root, slide);
}
function shift(root: HTMLElement, weeks: number) {
const start = toMs(root.dataset.start || "");
if (Number.isNaN(start)) return;
root.dataset.start = toIso(start + weeks * 7 * DAY);
render(root);
}
const init = () => {
document.querySelectorAll<HTMLElement>("[data-haze-mini-calendar]").forEach((root) => {
if (root.hasAttribute("data-enhanced")) return;
root.setAttribute("data-enhanced", "");
root.querySelector("[data-mini-calendar-prev]")?.addEventListener("click", () => shift(root, -1));
root.querySelector("[data-mini-calendar-next]")?.addEventListener("click", () => shift(root, 1));
root.addEventListener("change", (event) => {
const target = event.target as HTMLInputElement;
if (target.type === "radio" && target.checked) root.dataset.value = target.value;
render(root, true);
});
render(root);
const grid = root.querySelector("[data-mini-calendar-grid]");
if (grid && "ResizeObserver" in window) new ResizeObserver(() => place(root, false)).observe(grid);
});
};
init();
if (!document.documentElement.hasAttribute("data-haze-mini-calendar-listener")) {
document.documentElement.setAttribute("data-haze-mini-calendar-listener", "");
document.addEventListener("astro:page-load", init);
}
</script>When to use
- The choice is a day in the next few days, such as a delivery date or a class, and a month grid is too big.
- The picker sits in a narrow card, sidebar or mobile sheet and must fit 240 px.
- The chosen day must submit with a plain form under a name, like any radio group.
When not to use
- The date can be months away or must be typed; use calendar or date-picker.
- The choice is a time of day on one date; use time-slot-picker.
Installation
Add the Haze registry to components.json once, then install Mini calendar with the shadcn CLI. Works in any Astro project with Tailwind CSS v4.
pnpm dlx shadcn@latest add @haze/mini-calendarnpx shadcn@latest add @haze/mini-calendaryarn dlx shadcn@latest add @haze/mini-calendarbunx --bun shadcn@latest add @haze/mini-calendarFirst time? Registry and theme setup
1. Add to components.json:
{
"registries": {
"@haze": "http://localhost:4329/r/{name}.json"
}
}2. Install the theme once: npx shadcn@latest add @haze/theme, then import it after Tailwind in your global CSS:@import "./haze.css";
API reference
| Prop | Type | Default | Description |
|---|---|---|---|
| id* | string | – | Unique id. Every radio id and the legend id are derived from it. |
| name | string | id | Submitted field name. |
| legend | string | Pick a day | Visible question above the strip. |
| start | string | 2026-11-09 | Any ISO date in the week to show; the strip begins on weekStart. |
| value | string | – | ISO date selected on load. |
| today | string | – | ISO date marked with a dot and the word 'today' for screen readers. Never read from the clock. |
| weekStart | 0 | 1 | 1 | First day of the week, Sunday or Monday. |
| disabled | string[] | [] | ISO dates that cannot be chosen. |
| locale | string | en | BCP 47 locale for weekday names and dates, formatted in UTC. |
| required | boolean | – | A day must be chosen before the form submits. |
| previousLabel | string | Previous week | Accessible name of the previous button. |
| nextLabel | string | Next week | Accessible name of the next button. |
| todayLabel | string | today | Word added to today's cell name. |
| class | string | – | Classes for the fieldset. |
Keyboard interactions
- Tab
- Move into the day group, onto the chosen day or the first enabled one.
- Arrow keys
- Move to the next or previous enabled day and select it.
- Space
- Select the focused day.
- Enter or Space on a week button
- Show the previous or next week.
Accessibility
- Each day is a real radio inside a fieldset with a legend; its name is the full date, such as 'Thursday, November 12, today'.
- Today is marked by a dot and the word in the accessible name, never by color alone. Disabled days are struck through.
- The week buttons are hidden until the script runs, so without script the strip shows the week from 'start' and stays fully usable.
- The date range above the strip is a polite live region, so paging is announced.
Notes for AI
Copy into Claude Code, Cursor, Codex or any coding agent. Agents can also read the Markdown version of this page.
Install and use
Install the Haze UI component "Mini calendar" with `npx shadcn@latest add @haze/mini-calendar`. If components.json has no "@haze" registry yet, add "registries": { "@haze": "http://localhost:4329/r/{name}.json" }. If src/styles/haze.css does not exist yet, run `npx shadcn@latest add @haze/theme` once and import it from the global stylesheet after Tailwind. The CLI stops at an overwrite question when a Haze file already exists and differs, even with --yes, and then installs nothing after it: read its output. If the user has not edited their Haze files, re-run with --overwrite to take the registry versions; if they have, ask them before overwriting. Then import MiniCalendar from "@/components/haze/ui/mini-calendar.astro" (or the relative path) and render it where it fits the page. Keep Haze token classes (bg-background, text-muted-foreground, border-border...) and never hardcode colors. Docs: http://localhost:4329/ui/mini-calendar.md
Customize with real content
Adapt the Haze mini-calendar ui for our product. Replace the demo values of these props with our real content: id, name, legend, start, value, today, weekStart, disabled, locale, required, previousLabel, nextLabel, todayLabel, class. Keep the layout, the heading level rules and these accessibility details: Each day is a real radio inside a fieldset with a legend; its name is the full date, such as 'Thursday, November 12, today'. Today is marked by a dot and the word in the accessible name, never by color alone. Disabled days are struck through. The week buttons are hidden until the script runs, so without script the strip shows the week from 'start' and stays fully usable. The date range above the strip is a polite live region, so paging is announced. Do not add raw color classes; use the Haze tokens.
Choose the right block
Before using mini-calendar, check it fits: use it when the choice is a day in the next few days, such as a delivery date or a class, and a month grid is too big.; the picker sits in a narrow card, sidebar or mobile sheet and must fit 240 px.; the chosen day must submit with a plain form under a name, like any radio group.. Avoid it when the date can be months away or must be typed; use calendar or date-picker.; the choice is a time of day on one date; use time-slot-picker.. Alternatives: @haze/calendar, @haze/date-picker, @haze/time-slot-picker.
Dependencies
- npm: @lucide/astro
- @haze/utils
- @haze/theme (one-time setup)
Source · Original Haze UI work.