TypeScript
feat: make the calendar responsive with touch gestures
Vipul Kumar74315fd56fed
diff --git a/src/components/calendar/all-day-row.tsx b/src/components/calendar/all-day-row.tsxindex 791951a..1ef1259 100644--- a/src/components/calendar/all-day-row.tsx+++ b/src/components/calendar/all-day-row.tsx@@ -14,7 +14,7 @@ const CHIP_GAP = 4;const ROW_PADDING = 5.5;/** The all-day lane above the time grid: holidays first, then all-day events. */-export function AllDayRow({ days, axisWidth }: { days: string[]; axisWidth: number }) {+export function AllDayRow({ days }: { days: string[] }) {const events = useAppStore((s) => s.events);const holidays = useAppStore((s) => s.holidays);const openPopover = useCalendarStore((s) => s.openPopover);@@ -37,8 +37,8 @@ export function AllDayRow({ days, axisWidth }: { days: string[]; axisWidth: numbreturn (<div className="flex w-full shrink-0 items-stretch overflow-hidden border-b border-hairline" style={{ height }}>- <div className="flex shrink-0 items-center justify-end pr-3" style={{ width: axisWidth }}>- {most > 1 && <span className="t-12 text-placeholder">All day</span>}+ <div className="flex w-(--axis) shrink-0 items-center justify-end pr-3 max-md:pr-1.5">+ {most > 1 && <span className="t-12 text-placeholder max-md:text-[10px]">All day</span>}</div>{days.map((day, i) => (<div@@ -48,7 +48,7 @@ export function AllDayRow({ days, axisWidth }: { days: string[]; axisWidth: numbonClick={(e) => {if (e.target === e.currentTarget) openOverlay({ kind: "event", date: day, allDay: true });}}- className="flex min-w-0 flex-1 cursor-default flex-col justify-center gap-1 overflow-hidden border-l border-hairline px-1"+ className="flex min-w-0 flex-1 cursor-default flex-col justify-center gap-1 overflow-hidden border-l border-hairline px-1 max-md:px-0.5">{chipsByDay[i].map((chip) => (<button@@ -56,12 +56,12 @@ export function AllDayRow({ days, axisWidth }: { days: string[]; axisWidth: numbtype="button"onClick={(e) => openPopover(chip.kind, chip.id, e.currentTarget)}className={cn(- "press flex h-7 w-full shrink-0 items-center overflow-hidden rounded-lg px-2 text-left outline-none",+ "press flex h-7 w-full shrink-0 items-center overflow-hidden rounded-lg px-2 text-left outline-none max-md:rounded-md max-md:px-1","hover-fine:brightness-[0.97] focus-visible:ring-2 focus-visible:ring-brand/60 dark:hover-fine:brightness-110",)}style={chip.style}>- <span className="t-14 salt min-w-0 flex-1 truncate">{chip.title}</span>+ <span className="t-14 salt min-w-0 flex-1 truncate max-md:text-[11px] max-md:tracking-normal">{chip.title}</span></button>))}</div>diff --git a/src/components/calendar/calendar-header.tsx b/src/components/calendar/calendar-header.tsxindex 7885354..eb2d93e 100644--- a/src/components/calendar/calendar-header.tsx+++ b/src/components/calendar/calendar-header.tsx@@ -54,26 +54,30 @@ export function CalendarHeader() {const active = VIEWS.find((v) => v.id === view)!;const unit = view === "day" ? "day" : view === "week" ? "week" : "month";+ const activeIndex = VIEWS.indexOf(active);+return (- <div className="flex h-[68px] w-full shrink-0 items-center gap-2 overflow-hidden border-b border-hairline px-4">- <div className="flex min-w-0 flex-1 flex-col items-start gap-1.5 overflow-hidden whitespace-nowrap">- <h2 className="t-16 text-fg">{title}</h2>- <p className="t-14 salt text-fg-2">{subtitle}</p>- </div>+ // Phones: two rows (range + navigation, then a full-width view switcher).+ // md+: the single 68px row from the design.+ <div className="flex w-full shrink-0 flex-col gap-3 overflow-hidden border-b border-hairline px-4 py-3 md:h-[68px] md:flex-row md:items-center md:gap-2 md:py-0">+ <div className="flex min-w-0 items-center gap-2 md:contents">+ <div className="flex min-w-0 flex-1 flex-col items-start gap-1.5 overflow-hidden whitespace-nowrap">+ <h2 className="t-16 max-w-full truncate text-fg">{title}</h2>+ <p className="t-14 salt max-w-full truncate text-fg-2">{subtitle}</p>+ </div>- <div className="flex items-center gap-2">- <Button size="sm" onClick={() => setDate(today)} aria-keyshortcuts="T">+ <Button size="sm" className="shrink-0 max-md:h-8" onClick={() => setDate(today)} aria-keyshortcuts="T">Today</Button>- <div className="flex h-[30px] items-center overflow-hidden rounded-lg border border-control bg-surface">+ <div className="flex h-[30px] shrink-0 items-center overflow-hidden rounded-lg border border-control bg-surface max-md:h-8"><Tooltip><TooltipTrigger asChild><buttontype="button"onClick={() => step(-1)}aria-label={`Previous ${unit}`}- className="press flex h-full w-[29px] items-center justify-center outline-none hover-fine:bg-hover focus-visible:bg-hover"+ className="press flex h-full w-[29px] items-center justify-center outline-none hover-fine:bg-hover focus-visible:bg-hover max-md:w-9"><Icon name="arrow-left" /></button>@@ -87,7 +91,7 @@ export function CalendarHeader() {type="button"onClick={() => step(1)}aria-label={`Next ${unit}`}- className="press flex h-full w-[29px] items-center justify-center outline-none hover-fine:bg-hover focus-visible:bg-hover"+ className="press flex h-full w-[29px] items-center justify-center outline-none hover-fine:bg-hover focus-visible:bg-hover max-md:w-9"><Icon name="arrow-right" className="-scale-x-100" /></button>@@ -95,31 +99,39 @@ export function CalendarHeader() {<TooltipContent>Next {unit}</TooltipContent></Tooltip></div>+ </div>- <div role="tablist" aria-label="Calendar view" className="relative flex h-[30px] w-[163px] items-center gap-0.5 overflow-hidden rounded-lg bg-app p-px">- <span- aria-hidden- className="absolute top-px left-0 h-7 rounded-lg border border-segment bg-surface transition-[transform,width] duration-200 ease-(--ease-out)"- style={{ width: active.width, transform: `translateX(${active.left}px)` }}- />- {VIEWS.map((v) => (- <button- key={v.id}- type="button"- role="tab"- aria-selected={view === v.id}- aria-keyshortcuts={v.key}- onClick={() => setView(v.id)}- style={{ width: v.width }}- className={cn(- "t-14 salt relative z-10 flex h-7 shrink-0 items-center justify-center rounded-md outline-none transition-colors duration-150 focus-visible:ring-2 focus-visible:ring-brand/40",- view === v.id ? "text-fg" : "text-fg-2 hover-fine:text-fg",- )}- >- {v.label}- </button>- ))}- </div>+ <div+ role="tablist"+ aria-label="Calendar view"+ className="relative flex h-[34px] w-full items-center gap-0.5 overflow-hidden rounded-lg bg-app p-px md:h-[30px] md:w-[163px]"+ style={{ "--w": `${active.width}px`, "--x": `${active.left}px`, "--i": activeIndex } as React.CSSProperties}+ >+ <span+ aria-hidden+ className={cn(+ "absolute top-px left-0 h-8 rounded-lg border border-segment bg-surface transition-[translate,width] duration-200 ease-(--ease-out) md:h-7",+ // Equal thirds on phones; the design's exact segment geometry from md up.+ "w-[calc((100%-6px)/3)] translate-x-[calc(var(--i)*(100%+2px)+1px)] md:w-(--w) md:translate-x-(--x)",+ )}+ />+ {VIEWS.map((v) => (+ <button+ key={v.id}+ type="button"+ role="tab"+ aria-selected={view === v.id}+ aria-keyshortcuts={v.key}+ onClick={() => setView(v.id)}+ style={{ "--seg": `${v.width}px` } as React.CSSProperties}+ className={cn(+ "t-14 salt relative z-10 flex h-8 flex-1 items-center justify-center rounded-md outline-none transition-colors duration-150 focus-visible:ring-2 focus-visible:ring-brand/40 md:h-7 md:w-(--seg) md:flex-none md:shrink-0",+ view === v.id ? "text-fg" : "text-fg-2 hover-fine:text-fg",+ )}+ >+ {v.label}+ </button>+ ))}</div></div>);diff --git a/src/components/calendar/calendar.tsx b/src/components/calendar/calendar.tsxindex 22a816d..f8e0b54 100644--- a/src/components/calendar/calendar.tsx+++ b/src/components/calendar/calendar.tsx@@ -1,7 +1,8 @@"use client";-import { useMemo } from "react";+import { useEffect, useMemo } from "react";import { isWeekend, weekDays } from "@/lib/dates";+import { useIsMobile } from "@/hooks/use-media-query";import { useAppStore } from "@/stores/app-store";import { useCalendarStore } from "@/stores/calendar-store";import { CalendarHeader } from "./calendar-header";@@ -9,22 +10,37 @@ import { EventPopover } from "./event-popover";import { MonthView } from "./month-view";import { TimeGrid } from "./time-grid";+// Phones open on the day view once per session (a 7-column week is cramped+// there); after that the user's choice sticks.+let mobileViewApplied = false;+export function Calendar() {const view = useCalendarStore((s) => s.view);const date = useCalendarStore((s) => s.date);const weekStartsOn = useAppStore((s) => s.settings.weekStartsOn);const showWeekends = useAppStore((s) => s.settings.showWeekends);+ const isMobile = useIsMobile();++ useEffect(() => {+ if (!isMobile || mobileViewApplied) return;+ mobileViewApplied = true;+ if (useCalendarStore.getState().view === "week") useCalendarStore.getState().setView("day");+ }, [isMobile]);++ const week = useMemo(() => {+ const all = weekDays(date, weekStartsOn);+ return showWeekends ? all : all.filter((d) => !isWeekend(d));+ }, [date, weekStartsOn, showWeekends]);- const days = useMemo(() => {- if (view === "day") return [date];- const week = weekDays(date, weekStartsOn);- return showWeekends ? week : week.filter((d) => !isWeekend(d));- }, [view, date, weekStartsOn, showWeekends]);+ const days = view === "day" ? [date] : week;return (- <section aria-label="Calendar" className="flex h-full min-w-0 flex-1 flex-col overflow-hidden bg-surface">+ <section+ aria-label="Calendar"+ className="flex h-full min-w-0 flex-1 flex-col overflow-hidden bg-surface [--axis:44px] md:[--axis:70px]"+ ><CalendarHeader />- {view === "month" ? <MonthView /> : <TimeGrid key={view} days={days} />}+ {view === "month" ? <MonthView /> : <TimeGrid key={view} days={days} strip={view === "day" ? week : undefined} />}<EventPopover /></section>);diff --git a/src/components/calendar/event-popover.tsx b/src/components/calendar/event-popover.tsxindex 59c8edb..bbe7f77 100644--- a/src/components/calendar/event-popover.tsx+++ b/src/components/calendar/event-popover.tsx@@ -8,6 +8,7 @@ import { Tooltip, TooltipContent, TooltipTrigger } from "@/components/ui/tooltipimport { StatusBadge } from "@/components/time-off/status-badge";import { formatLong, formatTimeRange, formatWeekday } from "@/lib/dates";import { formatDuration } from "@/lib/dates";+import { useIsMobile } from "@/hooks/use-media-query";import { useAppStore } from "@/stores/app-store";import { useCalendarStore } from "@/stores/calendar-store";import { openOverlay } from "@/stores/overlay-store";@@ -23,6 +24,7 @@ export function EventPopover() {const deleteEvent = useAppStore((s) => s.deleteEvent);const duplicateEvent = useAppStore((s) => s.duplicateEvent);+ const isMobile = useIsMobile();const rect = target?.rect;const virtualRef = useMemo(() => ({@@ -40,11 +42,11 @@ export function EventPopover() {<Popover open={open} onOpenChange={(v) => !v && close()}><PopoverAnchor virtualRef={virtualRef} /><PopoverContent- side="right"- align="start"+ side={isMobile ? "bottom" : "right"}+ align={isMobile ? "center" : "start"}sideOffset={8}collisionPadding={12}- className="w-[300px] gap-0 p-0"+ className="w-[300px] max-w-[calc(100vw-24px)] gap-0 p-0"onOpenAutoFocus={(e) => e.preventDefault()}>{event && (diff --git a/src/components/calendar/month-view.tsx b/src/components/calendar/month-view.tsxindex 5e29ad8..a12091b 100644--- a/src/components/calendar/month-view.tsx+++ b/src/components/calendar/month-view.tsx@@ -3,6 +3,7 @@import { useMemo } from "react";import { WEEKDAYS_SHORT, dayOfWeek, formatTime, fromKey, isWeekend, monthGrid } from "@/lib/dates";import { cn } from "@/lib/utils";+import { useIsMobile } from "@/hooks/use-media-query";import { useToday } from "@/hooks/use-today";import { useAppStore } from "@/stores/app-store";import { useCalendarStore } from "@/stores/calendar-store";@@ -20,6 +21,12 @@ export function MonthView() {const holidays = useAppStore((s) => s.holidays);const { weekStartsOn, showWeekends, timeFormat } = useAppStore((s) => s.settings);const today = useToday();+ const isMobile = useIsMobile();+ // On phones a tap on a day opens it (cells are too small to act on chips).+ const openDay = (d: string) => {+ setDate(d);+ setView("day");+ };const grid = useMemo(() => {const all = monthGrid(date, weekStartsOn);@@ -47,8 +54,11 @@ export function MonthView() {<div className="flex min-h-0 flex-1 flex-col"><div className="grid h-10 shrink-0 border-b border-hairline" style={{ gridTemplateColumns: `repeat(${cols}, minmax(0, 1fr))` }}>{headers.map((h, i) => (- <div key={h} className={cn("t-14 flex items-center px-3 text-dayname", i > 0 && "border-l border-hairline")}>- {h}+ <div key={h} className={cn("t-14 flex items-center px-3 text-dayname max-md:justify-center max-md:px-0 max-md:text-[11px]", i > 0 && "border-l border-hairline")}>+ <span className="max-md:hidden">{h}</span>+ <span className="md:hidden" aria-hidden>+ {h[0]}+ </span></div>))}</div>@@ -66,22 +76,27 @@ export function MonthView() {<divkey={d}onClick={(e) => {- if (e.target === e.currentTarget) setDate(d);+ if (isMobile) openDay(d);+ else if (e.target === e.currentTarget) setDate(d);}}onDoubleClick={(e) => {if (e.target === e.currentTarget) openOverlay({ kind: "event", date: d, start: 540, end: 600 });}}className={cn(- "flex min-h-0 flex-col gap-1 overflow-hidden border-b border-hairline p-1.5",+ "flex min-h-0 flex-col gap-1 overflow-hidden border-b border-hairline p-1.5 max-md:items-center max-md:gap-1 max-md:p-1",i % cols > 0 && "border-l",!inMonth && "bg-app/60",)}><buttontype="button"- onClick={() => (selected ? setView("day") : setDate(d))}+ onClick={(e) => {+ e.stopPropagation();+ if (isMobile || selected) openDay(d);+ else setDate(d);+ }}className={cn(- "t-14 flex h-6 min-w-6 shrink-0 items-center justify-center self-start rounded-lg px-1 transition-[background-color,color] duration-150 outline-none focus-visible:ring-2 focus-visible:ring-brand/50",+ "t-14 flex h-6 min-w-6 shrink-0 items-center justify-center self-start rounded-lg px-1 max-md:self-center transition-[background-color,color] duration-150 outline-none focus-visible:ring-2 focus-visible:ring-brand/50",selected? "accent-badge font-semibold": isToday@@ -94,13 +109,21 @@ export function MonthView() {>{fromKey(d).getDate()}</button>+ {/* Phones: up to three colour dots per day */}+ {items.length > 0 && (+ <span className="flex gap-0.5 md:hidden" aria-label={`${items.length} ${items.length === 1 ? "item" : "items"}`}>+ {items.slice(0, 3).map((it) => (+ <span key={it.id} className="size-1.5 rounded-full" style={{ background: `var(--event-${it.color}-fg)` }} />+ ))}+ </span>+ )}{items.slice(0, MAX_CHIPS).map((it) => (<buttonkey={it.id}type="button"onClick={(e) => openPopover(it.kind, it.id, e.currentTarget)}className={cn(- "t-12 salt flex h-[22px] w-full shrink-0 items-center truncate rounded-md px-1.5 text-left outline-none",+ "t-12 salt flex h-[22px] w-full shrink-0 items-center truncate rounded-md px-1.5 text-left outline-none max-md:hidden","hover-fine:brightness-[0.97] focus-visible:ring-2 focus-visible:ring-brand/50 dark:hover-fine:brightness-110",!inMonth && "opacity-60",)}@@ -116,7 +139,7 @@ export function MonthView() {setDate(d);setView("day");}}- className="t-12 self-start rounded-md px-1.5 py-1 text-fg-2 hover-fine:bg-hover hover-fine:text-fg"+ className="t-12 self-start rounded-md px-1.5 py-1 text-fg-2 hover-fine:bg-hover hover-fine:text-fg max-md:hidden">+{hidden} more</button>diff --git a/src/components/calendar/time-grid.tsx b/src/components/calendar/time-grid.tsxindex 3f1ad10..706012b 100644--- a/src/components/calendar/time-grid.tsx+++ b/src/components/calendar/time-grid.tsx@@ -22,9 +22,12 @@ import {SNAP_MINUTES,} from "./layout";-const AXIS_WIDTH = 70;const HOURS = Array.from({ length: 23 }, (_, i) => i + 1);const DRAG_THRESHOLD = 4;+/** Touch: hold this long on an event before it lifts for dragging. */+const LONG_PRESS_MS = 350;+/** Touch: a horizontal flick this long switches to the previous/next period. */+const SWIPE_DISTANCE = 64;type Drag =| { type: "create"; dayIndex: number; anchor: number; current: number; moved: boolean }@@ -47,7 +50,7 @@ export function DayHeaders({ days }: { days: string[] }) {return (<div className="flex h-14 w-full shrink-0 items-start overflow-hidden border-b border-hairline">- <div className="h-full shrink-0" style={{ width: AXIS_WIDTH }} />+ <div className="h-full w-(--axis) shrink-0" />{days.map((d) => {const isSelected = d === selected;const isToday = d === today;@@ -58,9 +61,11 @@ export function DayHeaders({ days }: { days: string[] }) {onClick={() => (isSelected ? setView("day") : setDate(d))}aria-label={`${fromKey(d).toDateString()}${isSelected ? ", selected — open day view" : ""}`}aria-pressed={isSelected}- className="group flex h-full min-w-0 flex-1 items-center gap-2 overflow-hidden border-l border-hairline px-3 text-left outline-none focus-visible:bg-hover"+ className="group flex h-full min-w-0 flex-1 items-center gap-2 overflow-hidden border-l border-hairline px-3 text-left outline-none focus-visible:bg-hover max-md:flex-col max-md:justify-center max-md:gap-1 max-md:px-0">- <span className="t-14 shrink-0 text-center whitespace-nowrap text-dayname">{WEEKDAYS_SHORT[dayOfWeek(d)]}</span>+ <span className="t-14 shrink-0 text-center whitespace-nowrap text-dayname max-md:text-[11px] max-md:tracking-normal">+ {WEEKDAYS_SHORT[dayOfWeek(d)]}+ </span><spanclassName={cn("t-16 flex h-6 min-w-6 shrink-0 items-center justify-center overflow-hidden rounded-lg px-1 whitespace-nowrap transition-[background-color,color] duration-150",@@ -80,7 +85,43 @@ export function DayHeaders({ days }: { days: string[] }) {);}-export function TimeGrid({ days }: { days: string[] }) {+/** Phones in day view: a 7-day strip to hop between days of the week. */+function WeekStrip({ days }: { days: string[] }) {+ const selected = useCalendarStore((s) => s.date);+ const setDate = useCalendarStore((s) => s.setDate);+ const today = useToday();++ return (+ <div className="flex h-16 w-full shrink-0 items-center gap-1 border-b border-hairline px-2 md:hidden" role="tablist" aria-label="Days of the week">+ {days.map((d) => {+ const isSelected = d === selected;+ const isToday = d === today;+ return (+ <button+ key={d}+ type="button"+ role="tab"+ aria-selected={isSelected}+ onClick={() => setDate(d)}+ className="press flex h-12 min-w-0 flex-1 flex-col items-center justify-center gap-1 rounded-lg outline-none focus-visible:ring-2 focus-visible:ring-brand/40"+ >+ <span className="text-[11px] leading-none text-dayname">{WEEKDAYS_SHORT[dayOfWeek(d)]}</span>+ <span+ className={cn(+ "t-16 flex size-7 items-center justify-center rounded-lg transition-[background-color,color] duration-150",+ isSelected ? "accent-badge font-semibold" : isToday ? "text-brand" : "text-fg",+ )}+ >+ {fromKey(d).getDate()}+ </span>+ </button>+ );+ })}+ </div>+ );+}++export function TimeGrid({ days, strip }: { days: string[]; strip?: string[] }) {const events = useAppStore((s) => s.events);const timeFormat = useAppStore((s) => s.settings.timeFormat);const dayStartHour = useAppStore((s) => s.settings.dayStartHour);@@ -96,6 +137,28 @@ export function TimeGrid({ days }: { days: string[] }) {const pointerStart = useRef<{ x: number; y: number; target: Element | null } | null>(null);const [drag, setDrag] = useState<Drag | null>(null);const [highlightId, setHighlightId] = useState<string | null>(null);+ const step = useCalendarStore((s) => s.step);+ // Touch gesture state: long-press to lift an event, flick to change period.+ const touch = useRef<{+ x: number;+ y: number;+ t: number;+ timer: ReturnType<typeof setTimeout> | null;+ eventEl: HTMLElement | null;+ lifted: boolean;+ } | null>(null);+ const dragActive = useRef(false);++ // While an event is lifted, stop the page from scrolling under the finger.+ useEffect(() => {+ const el = scrollRef.current;+ if (!el) return;+ const onTouchMove = (e: TouchEvent) => {+ if (dragActive.current && e.cancelable) e.preventDefault();+ };+ el.addEventListener("touchmove", onTouchMove, { passive: false });+ return () => el.removeEventListener("touchmove", onTouchMove);+ }, []);// Open on the working day, like the design (06:00 at the top edge).useLayoutEffect(() => {@@ -143,28 +206,54 @@ export function TimeGrid({ days }: { days: string[] }) {};}+ function startDrag(eventEl: HTMLElement, minutes: number, resizing: boolean) {+ const ev = events.find((x) => x.id === eventEl.dataset.eventId);+ if (!ev) return;+ setDrag({+ type: resizing ? "resize" : "move",+ eventId: ev.id,+ dayIndex: days.indexOf(ev.date),+ start: ev.start,+ end: ev.end,+ grabOffset: minutes - ev.start,+ moved: false,+ locked: Boolean(ev.requestId),+ });+ }+function onPointerDown(e: React.PointerEvent<HTMLDivElement>) {if (e.button !== 0) return;const target = e.target as Element;const eventEl = target.closest<HTMLElement>("[data-event-id]");const { dayIndex, minutes } = pointToSlot(e.clientX, e.clientY);pointerStart.current = { x: e.clientX, y: e.clientY, target: eventEl };++ if (e.pointerType === "touch") {+ // Touch: scrolling wins by default. Tap opens/creates, long-press lifts an event.+ const state: NonNullable<typeof touch.current> = {+ x: e.clientX,+ y: e.clientY,+ t: e.timeStamp,+ timer: null,+ eventEl,+ lifted: false,+ };+ if (eventEl && !eventEl.dataset.locked) {+ state.timer = setTimeout(() => {+ state.lifted = true;+ dragActive.current = true;+ navigator.vibrate?.(8);+ startDrag(eventEl, minutes, false);+ }, LONG_PRESS_MS);+ }+ touch.current = state;+ return;+ }+e.currentTarget.setPointerCapture(e.pointerId);if (eventEl) {- const ev = events.find((x) => x.id === eventEl.dataset.eventId);- if (!ev) return;- const resizing = Boolean(target.closest("[data-resize]"));- setDrag({- type: resizing ? "resize" : "move",- eventId: ev.id,- dayIndex: days.indexOf(ev.date),- start: ev.start,- end: ev.end,- grabOffset: minutes - ev.start,- moved: false,- locked: Boolean(ev.requestId),- });+ startDrag(eventEl, minutes, Boolean(target.closest("[data-resize]")));} else {const m = snap(minutes - SNAP_MINUTES / 2);setDrag({ type: "create", dayIndex, anchor: m, current: m, moved: false });@@ -172,6 +261,11 @@ export function TimeGrid({ days }: { days: string[] }) {}function onPointerMove(e: React.PointerEvent<HTMLDivElement>) {+ const t = touch.current;+ if (t && !t.lifted && t.timer && Math.hypot(e.clientX - t.x, e.clientY - t.y) > 8) {+ clearTimeout(t.timer);+ t.timer = null;+ }if (!drag || !pointerStart.current) return;const dist = Math.hypot(e.clientX - pointerStart.current.x, e.clientY - pointerStart.current.y);const moved = drag.moved || dist > DRAG_THRESHOLD;@@ -192,7 +286,31 @@ export function TimeGrid({ days }: { days: string[] }) {}}- function onPointerUp() {+ function endTouch(e: React.PointerEvent<HTMLDivElement>): boolean {+ const t = touch.current;+ if (!t) return false;+ touch.current = null;+ if (t.timer) clearTimeout(t.timer);+ if (t.lifted) return false; // a lifted event finishes like a mouse drag below+ const dx = e.clientX - t.x;+ const dy = e.clientY - t.y;+ if (Math.abs(dx) > SWIPE_DISTANCE && Math.abs(dy) < Math.abs(dx) * 0.6 && e.timeStamp - t.t < 600) {+ step(dx < 0 ? 1 : -1);+ } else if (Math.hypot(dx, dy) < 8) {+ if (t.eventEl) {+ openPopover("event", t.eventEl.dataset.eventId!, t.eventEl);+ } else {+ const { dayIndex, minutes } = pointToSlot(t.x, t.y);+ const s = clamp(Math.floor(minutes / 30) * 30, 0, 1380);+ openOverlay({ kind: "event", date: days[dayIndex], start: s, end: s + 60 });+ }+ }+ return true;+ }++ function onPointerUp(e: React.PointerEvent<HTMLDivElement>) {+ dragActive.current = false;+ if (endTouch(e)) return;const d = drag;const start = pointerStart.current;setDrag(null);@@ -237,8 +355,17 @@ export function TimeGrid({ days }: { days: string[] }) {return (<>- <DayHeaders days={days} />- <AllDayRow days={days} axisWidth={AXIS_WIDTH} />+ {strip ? (+ <>+ <WeekStrip days={strip} />+ <div className="max-md:hidden">+ <DayHeaders days={days} />+ </div>+ </>+ ) : (+ <DayHeaders days={days} />+ )}+ <AllDayRow days={days} /><divref={scrollRef}onScroll={() => useCalendarStore.getState().popover && useCalendarStore.getState().closePopover()}@@ -246,24 +373,24 @@ export function TimeGrid({ days }: { days: string[] }) {>{/* Masks the line/label that sits exactly on the top edge when scrolled to an hour. */}<div className="pointer-events-none sticky top-0 z-20 h-0 w-full" aria-hidden>- <div className="absolute top-0 left-0 h-2 bg-surface" style={{ width: AXIS_WIDTH }} />- <div className="absolute top-0 right-0 h-px bg-surface" style={{ left: AXIS_WIDTH }} />+ <div className="absolute top-0 left-0 h-2 w-(--axis) bg-surface" />+ <div className="absolute top-0 right-0 left-(--axis) h-px bg-surface" /></div><div className="relative flex w-full" style={{ height: 24 * HOUR_HEIGHT }}>{/* Hour lines */}- <div className="pointer-events-none absolute inset-y-0 right-0" style={{ left: AXIS_WIDTH }} aria-hidden>+ <div className="pointer-events-none absolute inset-y-0 right-0 left-(--axis)" aria-hidden>{HOURS.map((h) => (<div key={h} className="absolute inset-x-0 h-px bg-hairline" style={{ top: h * HOUR_HEIGHT }} />))}</div>{/* Time axis */}- <div className="relative h-full shrink-0 select-none" style={{ width: AXIS_WIDTH }} aria-hidden>+ <div className="relative h-full w-(--axis) shrink-0 select-none" aria-hidden>{HOURS.map((h) => (<spankey={h}- className="t-14 absolute right-3 whitespace-nowrap text-fg-2"+ className="t-14 absolute right-3 whitespace-nowrap text-fg-2 max-md:right-1.5 max-md:text-[11px] max-md:tracking-normal"style={{ top: h * HOUR_HEIGHT - 7 }}>{formatTime(h * 60, timeFormat).replace(":00 ", " ")}@@ -274,11 +401,16 @@ export function TimeGrid({ days }: { days: string[] }) {{/* Day columns */}<divref={bodyRef}- className={cn("relative flex h-full min-w-0 flex-1 touch-none select-none", drag?.moved && drag.type === "move" && !drag.locked && "cursor-grabbing")}+ className={cn("relative flex h-full min-w-0 flex-1 touch-pan-y select-none", drag?.moved && drag.type === "move" && !drag.locked && "cursor-grabbing")}onPointerDown={onPointerDown}onPointerMove={onPointerMove}onPointerUp={onPointerUp}- onPointerCancel={() => setDrag(null)}+ onPointerCancel={() => {+ if (touch.current?.timer) clearTimeout(touch.current.timer);+ touch.current = null;+ dragActive.current = false;+ setDrag(null);+ }}>{days.map((day, i) => (<div@@ -367,11 +499,11 @@ function EventBlock({onOpen(e.currentTarget);}}}+ data-locked={locked || undefined}className={cn(- "group/event absolute flex overflow-hidden rounded-lg font-medium outline-none",+ "group/event @container absolute overflow-hidden rounded-lg font-medium outline-none","transition-[box-shadow,filter,opacity] duration-150 focus-visible:ring-2 focus-visible:ring-brand/60","hover-fine:brightness-[0.97] dark:hover-fine:brightness-110",- compact ? "items-center px-2" : "flex-col gap-0.5 p-2",locked ? "cursor-pointer" : "cursor-grab",dragging && "z-30 opacity-95 shadow-[0_8px_24px_-6px_rgba(15,15,15,0.28)]",highlighted && "animate-[event-pulse_1.4s_var(--ease-out)]",@@ -383,29 +515,37 @@ function EventBlock({left: `calc((100% - 5px) * ${column / count} + 2px)`,width: `calc((100% - 5px) / ${count} - ${count > 1 ? 2 : 0}px)`,zIndex: dragging ? 30 : 10 + column,+ ["--lines" as string]: Math.max(1, Math.floor((height - 6) / 13)),}}>{compact ? (- <p className="t-14 salt min-w-0 flex-1 truncate">- {event.title}- {height >= 28 ? null : <span className="t-12 ml-1 opacity-80">{formatTime(event.start, timeFormat)}</span>}- </p>+ <div className="flex h-full w-full items-center px-2 @max-[84px]:px-1">+ <p className="t-14 salt min-w-0 flex-1 truncate @max-[84px]:text-[11px] @max-[84px]:tracking-normal">+ {event.title}+ {height >= 28 ? null : <span className="t-12 ml-1 opacity-80 @max-[84px]:hidden">{formatTime(event.start, timeFormat)}</span>}+ </p>+ </div>) : (- <>- {height >= 60 ? (- <TwoLineTitle text={event.title} className="t-14 salt w-full shrink-0 overflow-hidden" />- ) : (- <p className="t-14 salt w-full shrink-0 truncate">{event.title}</p>- )}- <p className="t-12 salt w-full shrink-0 truncate">{time}</p>- {event.note && <p className="t-12 salt w-full shrink-0 truncate">{event.note}</p>}- </>+ <div className="flex h-full w-full flex-col gap-0.5 p-2 @max-[84px]:p-1">+ {/* Regular columns: the design's title / time / note stack */}+ <div className="contents @max-[84px]:hidden">+ {height >= 60 ? (+ <TwoLineTitle text={event.title} className="t-14 salt w-full shrink-0 overflow-hidden" />+ ) : (+ <p className="t-14 salt w-full shrink-0 truncate">{event.title}</p>+ )}+ <p className="t-12 salt w-full shrink-0 truncate">{time}</p>+ {event.note && <p className="t-12 salt w-full shrink-0 truncate">{event.note}</p>}+ </div>+ {/* Narrow columns (phone week view, side-by-side overlaps): title only, wrapping anywhere */}+ <p className="hidden text-[11px] leading-[13px] break-words hyphens-auto @max-[84px]:line-clamp-(--lines)">{event.title}</p>+ </div>)}{!locked && (<spandata-resizearia-hidden- className="absolute inset-x-0 bottom-0 h-1.5 cursor-ns-resize"+ className="absolute inset-x-0 bottom-0 h-1.5 cursor-ns-resize pointer-coarse:hidden"/>)}</div>