Skip to content
Star

Event calendar

A week view where the agent finds a free slot for you. Free and MIT licensed, as HTML, a typed React component or an Astro component, in three styles with light and dark mode.

$npx designme add event-calendar
$npx shadcn@latest add https://designme.dev/r/shadcn/event-calendar.json

Need this designed into your product? Book a call

Oct 19 – 23, 2026
01

Install

Add it to your project with the CLI.

HTML, CSS and JS

$npx designme add event-calendar

React

$npx designme add event-calendar --react

Astro

$npx designme add event-calendar --astro

shadcn, React

$npx shadcn@latest add https://designme.dev/r/shadcn/event-calendar.json

shadcn, Astro

$npx shadcn@latest add https://designme.dev/r/shadcn/astro/event-calendar.json

The CLI copies the source into your project, so you own it and can change anything. Where each version lands, what it needs and the shadcn theme bridge: Installation.

02

About

What it is for and what it does.

A work-week calendar where people drag events to a new time or day, click free time to add one, and open any event for its details. An agent button in the header asks your agent to find a slot, and the slots it suggests appear as outlined blocks with Book and Other. It shows scheduling help from an agent right inside the calendar people already use.

  • When an agent schedules meetings or finds free time for a team.
  • When people need to move and add events in a simple week view without a full calendar app.
  • When the agent can prepare something for a meeting, such as prep notes, from the event itself.
03

Usage

Import it in React and drive it from your own state, or place it in an Astro page.

React

import { EventCalendar } from '@/components/designme/event-calendar/EventCalendar';

React example

The demo above as a React component, 57 lines you can copy.

'use client';
// The animated preview from designme.dev, rebuilt from the React component: an example of driving it from your own state.
import { useCallback, useRef, useState } from 'react';
import { EventCalendar, type EventCalendarEvent, type EventCalendarPerson, type EventCalendarSuggestion, type EventCalendarTone } from './EventCalendar';
import { useStory, useWait } from '../lib/useScript';

const WEEK = new Date(2026, 9, 19);
const at = (day: number, hour: number) => new Date(2026, 9, 19 + day, Math.floor(hour), Math.round((hour % 1) * 60));
const WHO: EventCalendarPerson[] = [{ initials: 'MK', color: 'var(--dm-av-l)' }, { initials: 'JO', color: 'var(--dm-av-m)' }, { initials: 'DA', color: 'var(--dm-av-b)' }, { initials: 'AR', color: 'var(--dm-av-p)' }];
// two to four people, the way the site picks them
const people = (title: string) => WHO.slice(0, 2 + title.length % 3);
const EVENTS: [number, number, number, string, EventCalendarTone][] = [
  [0, 9, 1, 'Standup', 'blue'], [0, 13, 1.5, 'Pricing workshop', 'orange'], [1, 10, 1, '1:1 with Maya', 'purple'], [1, 14, 2, 'Focus: checkout', 'teal'],
  [2, 9, 1, 'Standup', 'blue'], [2, 11.5, 1, 'Agent demo', 'yellow'], [3, 9, 1, 'Standup', 'blue'], [3, 12, 1, 'Lunch & learn', 'green'],
  [3, 15, 1.5, 'Launch review', 'red'], [4, 10, 1.5, 'Planning', 'orange']
];
const START: EventCalendarEvent[] = EVENTS.map(([d, h, len, title, tone], i) => ({ id: 'e' + i, title, start: at(d, h), end: at(d, h + len), tone, people: people(title) }));
const SLOTS: EventCalendarSuggestion[] = [
  { id: 'wed', title: 'Design review', start: at(2, 13.5), end: at(2, 14.25) },
  { id: 'fri', title: 'Design review', start: at(4, 13), end: at(4, 13.75) }
];

export default function EventCalendarDemo() {
  const [events, setEvents] = useState(START);
  const [suggestions, setSuggestions] = useState<EventCalendarSuggestion[]>([]);
  const [finding, setFinding] = useState(false);
  const [label, setLabel] = useState('Find 45 min for a design review');
  const skipped = useRef(false);
  const wait = useWait();

  // the agent checks everyone's calendar, then suggests the best slot with one more behind it
  const ask = useCallback(async () => {
    setSuggestions([]); skipped.current = false;
    setFinding(true); setLabel('Checking 4 calendars');
    await wait(1300);
    setSuggestions(SLOTS); setFinding(false); setLabel('Everyone is free Wed 1:30');
  }, [wait]);
  // the preview asks the agent for a slot once on its own, unless you take over first
  const ref = useRef<HTMLDivElement>(null);
  // the agent checking calendars keeps working under a resting pointer, as an agent at work does on designme.dev
  useStory(ref, async s => { await s.wait(1200); await ask(); }, { hold: false });

  return (
    <div ref={ref} style={{ width: '100%' }}>
      <EventCalendar week={WEEK} now={new Date(2026, 9, 19, 10, 42)} events={events} onEventsChange={setEvents}
        newEvent={{ tone: 'pink', people: people('New event') }}
        onPrepNotes={() => wait(1200).then(() => "Last week's decisions and 3 open questions.")} onJoin={() => {}}
        askLabel={label} onAsk={ask} finding={finding} suggestions={suggestions}
        onBook={s => {
          setEvents(es => [...es, { id: s.id + '-booked', title: s.title, start: s.start, end: s.end, tone: 'blue', people: people(s.title) }]);
          setSuggestions([]); setLabel(skipped.current ? 'Booked Fri 1:00, invites sent' : 'Booked, invites sent to 4 people');
        }}
        onSkip={() => { skipped.current = true; setSuggestions(ss => ss.slice(1)); setLabel('Next best: Fri 1:00'); }} />
    </div>
  );
}

Astro

In a page in src/pages. It plays the demo above; change its event-calendar.js to show your own data. Attributes like class go on its root element.

---
import EventCalendar from '../components/designme/event-calendar/EventCalendar.astro';
---
<EventCalendar />
<EventCalendar data-style="soft" class="my-class" />
04

Props

Everything EventCalendar takes.

PropTypeWhat it does
eventsEventCalendarEvent[]The events. Dragging moves them, clicking free time adds one, the details card names or removes it
defaultEventsEventCalendarEvent[]
onEventsChange(events: EventCalendarEvent[]) => void
weekrequiredDateThe first day shown, like Monday Oct 19. Its time of day is ignored
daysnumberHow many days to show, from `week`. Defaults to 5
startHournumberThe first hour on the grid, 9 for 9am
hoursnumberHow many hours the grid shows. Defaults to 8 (9am to 5pm)
titlestringThe heading. Defaults to the dates shown, like "Oct 19 – 23, 2026"
nowDateMarks today and draws the now line. Leave it out for neither
selectedstring | nullThe event whose details card is open
defaultSelectedstring | null
onSelectedChange(id: string | null) => void
newEvent{ tone?: EventCalendarTone; people?: EventCalendarPerson[]; hours?: number }What an event added by clicking free time starts with. Defaults to a pink, one hour event
onPrepNotes(event: EventCalendarEvent) => ReactNode | Promise<ReactNode>Adds Prep notes to the details card. Return the notes, or a promise of them; "Writing" shimmers until it settles, then the notes show above the buttons and Prep notes keeps its place with a green tick
onJoin(event: EventCalendarEvent) => voidAdds Join to the details card
askLabelstringAdds the agent's button to the header, like "Find 45 min for a design review"
onAsk() => void
findingbooleanThe agent is looking: its button thinks and a scan line sweeps the week
suggestionsEventCalendarSuggestion[]Slots the agent suggests. The first is the pick, the rest wait dimmed behind it
onBook(suggestion: EventCalendarSuggestion) => voidBook on the picked suggestion. Add the event and clear the suggestions
onSkip(suggestion: EventCalendarSuggestion) => voidOther on the picked suggestion, shown while there are more. Drop it and the next one becomes the pick
statusstringThe quiet line in the header. Defaults to what the person last did, like "Moved Standup to Wed 1:15"
daynumberThe day a narrow calendar shows, as its place in the week (0 for the first day). A calendar under 520px wide shows one day at a time, picked from a row of days; it opens on today, and moves to the day of the agent's pick when one comes
defaultDaynumber
onDayChange(day: number) => void
classNamestring
05

Code

The full source, as the CLI installs it.

EventCalendar.tsxReact · 394 lines
'use client';
import { useEffect, useId, useRef, useState, type CSSProperties, type KeyboardEvent, type MouseEvent, type PointerEvent, type ReactNode, type RefObject } from 'react';
import { cx } from '../lib/cx';
import { useControllable, useIsoLayoutEffect, useReducedMotion } from '../lib/hooks';
import { Icon } from '../lib/icons';
import { Avatar, enter, mxT, Swap, Think, Tip } from '../lib/motion';
import '../designme.css';
import './event-calendar.css';

export type EventCalendarTone = 'blue' | 'purple' | 'green' | 'orange' | 'red' | 'yellow' | 'pink' | 'teal';

export interface EventCalendarPerson {
  /** Like "MK" */
  initials: string;
  /** The avatar's colour, like 'var(--dm-av-l)' */
  color: string;
}

export interface EventCalendarEvent {
  id: string;
  /** Like "Pricing workshop". An empty title reads "New event" and opens with a box to name it */
  title: string;
  /** Read in the browser's local time */
  start: Date;
  end: Date;
  /** The block's colour. Defaults to blue */
  tone?: EventCalendarTone;
  /** Who is invited, shown in the details card */
  people?: EventCalendarPerson[];
}

/** A free slot the agent found, drawn as an outlined block with Book (and Other while there are more) */
export interface EventCalendarSuggestion {
  id: string;
  title: string;
  start: Date;
  end: Date;
}

export interface EventCalendarProps {
  /** The events. Dragging moves them, clicking free time adds one, the details card names or removes it */
  events?: EventCalendarEvent[];
  defaultEvents?: EventCalendarEvent[];
  onEventsChange?: (events: EventCalendarEvent[]) => void;
  /** The first day shown, like Monday Oct 19. Its time of day is ignored */
  week: Date;
  /** How many days to show, from `week`. Defaults to 5 */
  days?: number;
  /** The first hour on the grid, 9 for 9am */
  startHour?: number;
  /** How many hours the grid shows. Defaults to 8 (9am to 5pm) */
  hours?: number;
  /** The heading. Defaults to the dates shown, like "Oct 19 – 23, 2026" */
  title?: string;
  /** Marks today and draws the now line. Leave it out for neither */
  now?: Date;
  /** The event whose details card is open */
  selected?: string | null;
  defaultSelected?: string | null;
  onSelectedChange?: (id: string | null) => void;
  /** What an event added by clicking free time starts with. Defaults to a pink, one hour event */
  newEvent?: { tone?: EventCalendarTone; people?: EventCalendarPerson[]; hours?: number };
  /** Adds Prep notes to the details card. Return the notes, or a promise of them; "Writing" shimmers until it settles, then the
      notes show above the buttons and Prep notes keeps its place with a green tick */
  onPrepNotes?: (event: EventCalendarEvent) => ReactNode | Promise<ReactNode>;
  /** Adds Join to the details card */
  onJoin?: (event: EventCalendarEvent) => void;
  /** Adds the agent's button to the header, like "Find 45 min for a design review" */
  askLabel?: string;
  onAsk?: () => void;
  /** The agent is looking: its button thinks and a scan line sweeps the week */
  finding?: boolean;
  /** Slots the agent suggests. The first is the pick, the rest wait dimmed behind it */
  suggestions?: EventCalendarSuggestion[];
  /** Book on the picked suggestion. Add the event and clear the suggestions */
  onBook?: (suggestion: EventCalendarSuggestion) => void;
  /** Other on the picked suggestion, shown while there are more. Drop it and the next one becomes the pick */
  onSkip?: (suggestion: EventCalendarSuggestion) => void;
  /** The quiet line in the header. Defaults to what the person last did, like "Moved Standup to Wed 1:15" */
  status?: string;
  /** The day a narrow calendar shows, as its place in the week (0 for the first day). A calendar under 520px wide shows one
      day at a time, picked from a row of days; it opens on today, and moves to the day of the agent's pick when one comes */
  day?: number;
  defaultDay?: number;
  onDayChange?: (day: number) => void;
  className?: string;
}

/* an hour's height: --dm-ph in the CSS, 44px, or 56px on a narrow calendar where each 28px row is half an hour. Places are
   written in it, so events keep their times when the calendar narrows or widens */
const PX = (el?: Element | null) => (el && parseFloat(getComputedStyle(el).getPropertyValue('--dm-ph'))) || 44;
const ph = (n: number, px = 0) => `calc(var(--dm-ph) * ${n}${px ? (px > 0 ? ' + ' : ' - ') + Math.abs(px) + 'px' : ''})`;
const MONTHS = ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun', 'Jul', 'Aug', 'Sep', 'Oct', 'Nov', 'Dec'];
const DAYN = ['Sun', 'Mon', 'Tue', 'Wed', 'Thu', 'Fri', 'Sat'];
const TONE: Record<EventCalendarTone, string> = { blue: 'pb', purple: 'pl', green: 'pm', orange: 'pp', red: 'pr', yellow: 'py', pink: 'pk', teal: 'pt' };

const addDays = (d: Date, n: number) => new Date(d.getFullYear(), d.getMonth(), d.getDate() + n);
const dayIndex = (week: Date, d: Date) => Math.round((addDays(d, 0).getTime() - addDays(week, 0).getTime()) / 864e5);
const hourOf = (d: Date) => d.getHours() + d.getMinutes() / 60;
const at = (week: Date, day: number, hour: number) => new Date(week.getFullYear(), week.getMonth(), week.getDate() + day, Math.floor(hour), Math.round((hour % 1) * 60));
/** 13.5 → "1:30", the way the site writes times */
const tm = (h: number) => { const hh = Math.floor(h), mm = Math.round((h - hh) * 60); return `${hh > 12 ? hh - 12 : hh}:${String(mm).padStart(2, '0')}`; };
const tint = (tone: EventCalendarTone = 'blue'): CSSProperties => ({ background: `var(--dm-${TONE[tone]}-bg)`, color: `var(--dm-${TONE[tone]})` });
const named = (e: EventCalendarEvent) => e.title || 'New event';

/** The details card: who is coming and what to do, or a box to name a new event */
function Details({ event, onClose, onSave, onDiscard, onPrepNotes, onJoin }: {
  event: EventCalendarEvent; onClose: () => void; onSave: (title: string) => void; onDiscard: () => void;
  onPrepNotes?: EventCalendarProps['onPrepNotes']; onJoin?: EventCalendarProps['onJoin'];
}) {
  const fresh = !event.title;
  const input = useRef<HTMLInputElement>(null);
  const prepBtn = useRef<HTMLButtonElement>(null);
  useEaseWidth(prepBtn);
  const [prep, setPrep] = useState<'idle' | 'writing' | 'done'>('idle');
  const [note, setNote] = useState<ReactNode>(null);
  useEffect(() => { if (fresh) input.current?.focus({ preventScroll: true }); }, [fresh]);
  const write = async () => {
    if (!onPrepNotes || prep !== 'idle') return;
    setPrep('writing');
    const n = await onPrepNotes(event);
    setNote(n); setPrep('done');
  };
  const key = (k: KeyboardEvent<HTMLInputElement>) => { if (k.key === 'Enter') onSave(k.currentTarget.value); if (k.key === 'Escape') onDiscard(); };
  const h = hourOf(event.start), end = hourOf(event.end), people = event.people ?? [];
  return (
    <>
      <div className="dm-ecx-ph">
        <i style={{ background: `var(--dm-${TONE[event.tone ?? 'blue']})` }} />
        {fresh ? <input ref={input} className="dm-ecx-ti" placeholder="Add a title" aria-label="Event title" onKeyDown={key} /> : <b>{event.title}</b>}
        <Tip label="Close"><button type="button" className="dm-ib dm-mx-press" aria-label="Close" onClick={onClose}><Icon name="x" size="xs" /></button></Tip>
      </div>
      <div className="dm-ecx-pt">{DAYN[event.start.getDay()]} {event.start.getDate()} {MONTHS[event.start.getMonth()]} · {tm(h)} – {tm(end)}</div>
      {people.length > 0 && (
        <div className="dm-ecx-pw">
          {people.map((p, i) => <Avatar key={i} initials={p.initials} color={p.color} />)}
          <span className="dm-muted">{people.length === 1 ? '1 person' : `${people.length} people`}</span>
        </div>
      )}
      {prep === 'done' && <div className={cx('dm-ecx-note', enter().className)}><Icon name="spark" size="xs" /><span>{note}</span></div>}
      {fresh ? (
        <div className="dm-ecx-pa">
          <button type="button" className="dm-pill dm-line dm-sm dm-mx-press" onClick={onDiscard}>Discard</button>
          <button type="button" className="dm-pill dm-primary dm-sm" onClick={() => onSave(input.current?.value ?? '')}>Save</button>
        </div>
      ) : (onPrepNotes || onJoin) && (
        <div className="dm-ecx-pa">
          {onPrepNotes && <button type="button" ref={prepBtn} className={cx('dm-pill dm-line dm-sm dm-ecx-prep dm-mx-press', prep === 'done' && 'dm-done')} aria-disabled={prep === 'done' || undefined} onClick={write}>
            {prep === 'writing' ? <><Think /><span className="dm-shim">Writing</span></> : <><Icon name={prep === 'done' ? 'check' : 'spark'} size="xs" />Prep notes</>}
          </button>}
          {onJoin && <button type="button" className="dm-pill dm-primary dm-sm" onClick={() => onJoin(event)}>Join</button>}
        </div>
      )}
    </>
  );
}

/** A work week of events you can drag to another time or day, add to by clicking free time, and open for details.
    The agent can look for a free slot and suggest it. */
/** A button as wide as its words: when they change it eases to its new width on the motion pieces' spring */
function useEaseWidth(ref: RefObject<HTMLElement | null>) {
  const reduce = useReducedMotion();
  useEffect(() => {
    const el = ref.current; if (!el || reduce || typeof ResizeObserver === 'undefined') return;
    let w = 0, busy: Animation | null = null;
    const ro = new ResizeObserver(() => {
      if (busy) return;
      const w1 = el.getBoundingClientRect().width;
      if (w && Math.abs(w1 - w) > .5) {
        el.style.overflow = 'clip';
        busy = el.animate([{ width: w + 'px' }, { width: w1 + 'px' }], { duration: mxT(el, 't-in', 360), easing: mxT(el, 'ease-spring', 'ease') });
        busy.finished.catch(() => {}).then(() => { busy = null; el.style.overflow = ''; w = el.getBoundingClientRect().width; });
      }
      w = w1;
    });
    ro.observe(el);
    return () => ro.disconnect();
  }, [ref, reduce]);
}

export function EventCalendar({
  events, defaultEvents = [], onEventsChange, week, days = 5, startHour = 9, hours = 8, title, now,
  selected, defaultSelected = null, onSelectedChange, newEvent, onPrepNotes, onJoin,
  askLabel = 'Find a time', onAsk, finding = false, suggestions = [], onBook, onSkip, status, day, defaultDay, onDayChange, className
}: EventCalendarProps) {
  const [list, setList] = useControllable(events, defaultEvents, onEventsChange);
  const [openId, setOpenId] = useControllable(selected, defaultSelected, onSelectedChange);
  const [msg, setMsg] = useState('');
  const uid = useId();
  const made = useRef(0);

  const root = useRef<HTMLDivElement>(null);
  const pop = useRef<HTMLDivElement>(null);
  const cols = useRef<(HTMLDivElement | null)[]>([]);
  const blocks = useRef(new Map<string, HTMLElement>());

  // the first events stagger in; an event added later, or dropped after a drag, plays the entrance again
  const delays = useRef<Map<string, number> | null>(null);
  if (!delays.current) delays.current = new Map(list.map((e, i) => [e.id, i * 30]));
  // a dropped event goes last in its day, so it sits on top, as on the site
  const [moves, setMoves] = useState<Record<string, number>>({});
  const drops = useRef(0);

  const end = startHour + hours;
  const inView = (d: Date) => { const i = dayIndex(week, d); return i >= 0 && i < days; };
  const shown = list.filter(e => inView(e.start));
  const open = openId != null ? list.find(e => e.id === openId) ?? null : null;
  // the card keeps what it showed while it fades out, and starts afresh each time it opens
  const [card, setCard] = useState(open);
  if (open && open !== card) setCard(open);
  const [runs, setRuns] = useState(0);

  const select = (id: string | null) => { if (id !== null) setRuns(n => n + 1); setOpenId(id); };
  const close = () => setOpenId(null);
  // opened with Enter or Space, the card takes the focus; closed with the focus in it, its event gets it back
  const keyOpen = useRef(false), inPop = useRef(false), lastOpen = useRef<string | null>(null);
  useIsoLayoutEffect(() => {
    if (openId != null) {
      lastOpen.current = openId;
      if (keyOpen.current) { keyOpen.current = false; pop.current?.querySelector<HTMLElement>('input,button')?.focus({ preventScroll: true }); }
      return;
    }
    if (inPop.current) { inPop.current = false; const b = lastOpen.current && blocks.current.get(lastOpen.current); if (b && b.isConnected) b.focus({ preventScroll: true }); }
  }, [openId]);

  /* ---------- the details card: beside its event, inside the calendar ---------- */
  const [place, setPlace] = useState<CSSProperties>({});
  useIsoLayoutEffect(() => {
    const el = open && blocks.current.get(open.id), p = pop.current, panel = root.current;
    if (!el || !p || !panel) return;
    const pr = panel.getBoundingClientRect(), er = el.getBoundingClientRect(), w = 248;
    let x = er.right - pr.left + 8; if (x + w > pr.width - 8) x = er.left - pr.left - w - 8; x = Math.max(8, x);
    const y = Math.max(8, Math.min(er.top - pr.top, pr.height - p.offsetHeight - 8));
    // (it scales and fades from the event's side, where Studio's popovers start)
    setPlace({ left: x, top: y, ['--dm-origin' as string]: (x > er.left - pr.left ? 'left' : 'right') + ' top' });
  }, [open?.id, runs]);
  useEffect(() => {
    if (!open) return;
    const down = (e: globalThis.PointerEvent) => { const t = e.target as Node; if (!pop.current?.contains(t) && !blocks.current.get(open.id)?.contains(t)) close(); };
    const key = (e: globalThis.KeyboardEvent) => { if (e.key === 'Escape') close(); };
    document.addEventListener('pointerdown', down); document.addEventListener('keydown', key);
    return () => { document.removeEventListener('pointerdown', down); document.removeEventListener('keydown', key); };
  }); // eslint-disable-line react-hooks/exhaustive-deps

  const update = (id: string, change: Partial<EventCalendarEvent>) => setList(list.map(e => e.id === id ? { ...e, ...change } : e));
  const remove = (id: string) => { setList(list.filter(e => e.id !== id)); close(); };
  const save = (e: EventCalendarEvent, value: string) => {
    const v = value.trim() || 'Untitled';
    update(e.id, { title: v }); close();
    setMsg(`Added ${v}, ${DAYN[e.start.getDay()]} ${tm(hourOf(e.start))}`);
  };

  /* ---------- dragging: to another time or day, in 15 minute steps; a click without moving opens the card ---------- */
  const drag = useRef<{ id: string; x: number; y: number; moved: boolean; day: number; hour: number } | null>(null);
  const [dragging, setDragging] = useState<{ id: string; day: number; hour: number; dx: number } | null>(null);
  const colX = (i: number) => cols.current[i]?.getBoundingClientRect().left ?? 0;
  const down = (p: PointerEvent<HTMLElement>, e: EventCalendarEvent) => {
    if (p.button) return;
    p.currentTarget.setPointerCapture(p.pointerId);
    drag.current = { id: e.id, x: p.clientX, y: p.clientY, moved: false, day: dayIndex(week, e.start), hour: hourOf(e.start) };
  };
  const move = (p: PointerEvent<HTMLElement>, e: EventCalendarEvent) => {
    const d = drag.current; if (!d || d.id !== e.id) return;
    const dx = p.clientX - d.x, dy = p.clientY - d.y;
    if (!d.moved && Math.hypot(dx, dy) < 5) return;
    if (!d.moved) { d.moved = true; if (openId != null) close(); setGhost(null); }
    const from = dayIndex(week, e.start), len = hourOf(e.end) - hourOf(e.start);
    d.hour = Math.max(startHour, Math.min(end - len, hourOf(e.start) + Math.round(dy / PX(cols.current[d.day]) * 4) / 4));
    const under = document.elementsFromPoint(p.clientX, p.clientY).find(x => x.classList?.contains('dm-ecx-col')) as HTMLElement | undefined;
    if (under) d.day = +(under.dataset.d ?? d.day);
    setDragging({ id: e.id, day: d.day, hour: d.hour, dx: colX(d.day) - colX(from) });
  };
  const up = (e: EventCalendarEvent) => {
    const d = drag.current; drag.current = null; if (!d || d.id !== e.id) return;
    if (!d.moved) { select(openId === e.id ? null : e.id); return; }
    setDragging(null);
    const n = ++drops.current; setMoves(m => ({ ...m, [e.id]: n }));
    const from = dayIndex(week, e.start), h = hourOf(e.start), len = hourOf(e.end) - h;
    if (d.day === from && d.hour === h) return;
    update(e.id, { start: at(week, d.day, d.hour), end: at(week, d.day, d.hour + len) });
    setMsg(`Moved ${named(e)} to ${DAYN[addDays(week, d.day).getDay()]} ${tm(d.hour)}`);
  };

  /* ---------- free time: a dashed slot follows the pointer, a click adds an event there ---------- */
  const [ghost, setGhost] = useState<{ day: number; hour: number } | null>(null);
  const hover = (p: PointerEvent<HTMLDivElement>, day: number) => {
    if (p.target !== p.currentTarget || dragging) { if (ghost) setGhost(null); return; }
    const hour = startHour + Math.min(hours * 2 - 1, Math.floor((p.clientY - p.currentTarget.getBoundingClientRect().top) / PX(p.currentTarget) * 2)) / 2;
    if (ghost?.day !== day || ghost.hour !== hour) setGhost({ day, hour });
  };
  const add = (p: MouseEvent<HTMLDivElement>, day: number) => {
    if (p.target !== p.currentTarget || !ghost || ghost.day !== day) return;
    const len = newEvent?.hours ?? 1, id = `${uid}-new-${++made.current}`;
    setList([...list, { id, title: '', start: at(week, day, ghost.hour), end: at(week, day, ghost.hour + len), tone: newEvent?.tone ?? 'pink', people: newEvent?.people }]);
    setGhost(null); select(id);
  };

  /* ---------- the agent's scan ---------- */
  const [scans, setScans] = useState(0);
  useEffect(() => { if (finding) setScans(n => n + 1); }, [finding]);

  const heading = title ?? (() => { const a = week, b = addDays(week, days - 1); return `${MONTHS[a.getMonth()]} ${a.getDate()} – ${b.getMonth() !== a.getMonth() ? MONTHS[b.getMonth()] + ' ' : ''}${b.getDate()}, ${b.getFullYear()}`; })();
  const today = now && inView(now) ? dayIndex(week, now) : -1;
  const sizes: CSSProperties | undefined = days !== 5 ? { ['--dm-days' as string]: days } : undefined;
  /* ---------- a narrow calendar: one day at a time ---------- */
  const [shownDay, setShownDay] = useControllable(day, defaultDay ?? Math.max(0, today), onDayChange);
  const daysRow = useRef<HTMLDivElement>(null);
  const askBtn = useRef<HTMLButtonElement>(null);
  useEaseWidth(askBtn);
  const narrow = () => !!daysRow.current?.getClientRects().length;
  const [turns, setTurns] = useState(0);
  const pickDay = (d: number) => { if (d === shownDay) return; if (narrow()) { close(); setTurns(n => n + 1); } setShownDay(d); };
  // the agent's pick opens on its day
  const pick = suggestions[0], pickDayOf = pick && inView(pick.start) ? dayIndex(week, pick.start) : -1;
  useEffect(() => { if (pickDayOf >= 0) pickDay(pickDayOf); }, [pick?.id]); // eslint-disable-line react-hooks/exhaustive-deps
  const tall: CSSProperties | undefined = hours !== 8 ? { height: ph(hours) } : undefined;
  const top = (h: number) => ph(h - startHour, 1);

  return (
    <div ref={root} data-dm="" className={cx('dm-ecx dm-panel', className)}>
      <div className="dm-ecx-h">
        <b>{heading}</b><span className="dm-ecx-sp" />
        <Swap className="dm-ecx-msg dm-muted">{status ?? msg}</Swap>
        {onAsk && <button ref={askBtn} type="button" className="dm-pill dm-soft dm-sm dm-ecx-ask" onClick={onAsk}>{finding ? <Think /> : <Icon name="spark" size="xs" />}<Swap key={finding ? 'f' : 'i'} className={finding ? 'dm-shim' : undefined}>{askLabel}</Swap></button>}
      </div>
      <div ref={daysRow} className="dm-ecx-days" role="group" aria-label="Day">
        {Array.from({ length: days }, (_, d) => {
          const date = addDays(week, d);
          return (
            <button key={d} type="button" className={d === today ? 'dm-t' : undefined} aria-pressed={d === shownDay} onClick={() => pickDay(d)}
              aria-label={date.toLocaleDateString('en-US', { weekday: 'long', month: 'long', day: 'numeric' })}>
              <span>{DAYN[date.getDay()]}</span><b>{date.getDate()}</b>
            </button>
          );
        })}
      </div>
      <div className="dm-ecx-sc">
        <div className="dm-ecx-grid" style={sizes}>
          {/* an hour a row (9am), or on a narrow calendar half an hour a row (9:00, 9:30) */}
          <div className="dm-ecx-tm">{Array.from({ length: hours * 2 }, (_, i) => { const h = startHour + Math.floor(i / 2), h12 = h > 12 ? h - 12 : h; return i % 2 ? <span key={i} className="dm-hf"><i className="dm-n">{h12}:30</i></span> : <span key={i}><i className="dm-w">{h12}{h >= 12 ? 'pm' : 'am'}</i><i className="dm-n">{h12}:00</i></span>; })}</div>
          {Array.from({ length: days }, (_, d) => {
            const date = addDays(week, d);
            return (
              <div key={d === shownDay ? `${d}:${turns}` : d} className={cx('dm-ecx-day', d === shownDay && 'dm-on', d === shownDay && turns > 0 && 'dm-enter')}>
                <div className={cx('dm-ecx-dh', d === today && 'dm-t')}>{DAYN[date.getDay()]} <b>{date.getDate()}</b></div>
                <div ref={el => { cols.current[d] = el; }} className="dm-ecx-col" data-d={d} style={tall}
                  onPointerMove={p => hover(p, d)} onPointerLeave={() => setGhost(null)} onClick={p => add(p, d)}>
                  {shown.filter(e => dayIndex(week, e.start) === d).sort((a, b) => (moves[a.id] ?? 0) - (moves[b.id] ?? 0)).map(e => {
                    const h = hourOf(e.start), len = hourOf(e.end) - h, live = dragging?.id === e.id ? dragging : null, at_ = live?.hour ?? h;
                    if (h + len <= startHour || h >= end) return null;
                    // an hour or more keeps its exact height; anything shorter grows to show its time, like a booked suggestion on the site
                    return (
                      <Tip key={`${e.id}:${moves[e.id] ?? 0}`} label={`${named(e)}, ${tm(at_)}`} off={!!dragging || openId === e.id}>
                        <button type="button" ref={el => { if (el) blocks.current.set(e.id, el); else blocks.current.delete(e.id); }}
                          className={cx('dm-ecx-e dm-enter', live && 'dm-drag', openId === e.id && 'dm-on')}
                          style={{ ...tint(e.tone), top: top(at_), [len < 1 ? 'minHeight' : 'height']: ph(len, -3), transform: live ? `translateX(${live.dx}px)` : undefined, animationDelay: (delays.current!.get(e.id) ?? 0) + 'ms' }}
                          onPointerDown={p => down(p, e)} onPointerMove={p => move(p, e)} onPointerUp={() => up(e)} onPointerCancel={() => up(e)}
                          onClick={c => { if (c.detail !== 0) return; keyOpen.current = openId !== e.id; select(openId === e.id ? null : e.id); }}>
                          <b>{named(e)}</b><span>{tm(at_)} – {tm(at_ + len)}</span>
                        </button>
                      </Tip>
                    );
                  })}
                  {suggestions.filter(s => dayIndex(week, s.start) === d).map(s => {
                    const i = suggestions.indexOf(s), h = hourOf(s.start), len = hourOf(s.end) - h;
                    return (
                      <div key={s.id} className={cx('dm-ecx-e dm-sug', i > 0 && 'dm-alt')} style={{ ...tint('blue'), top: top(h), height: 'auto', minHeight: ph(len, -3), animationDelay: i * 120 + 'ms' }}>
                        <b>{s.title}</b><span>{tm(h)} – {tm(h + len)}</span>
                        {i === 0 && (onBook || onSkip) && (
                          <div className="dm-ecx-sg">
                            {onBook && <button type="button" className="dm-y" onClick={() => onBook(s)}>Book</button>}
                            {onSkip && suggestions.length > 1 && <button type="button" className="dm-n" onClick={() => onSkip(s)}>Other</button>}
                          </div>
                        )}
                      </div>
                    );
                  })}
                  {d === today && now && <Tip label={`Now, ${tm(hourOf(now))}`}><div className="dm-ecx-now" style={{ top: ph(hourOf(now) - startHour) }} /></Tip>}
                  {ghost?.day === d && <div className="dm-ecx-ghost" style={{ top: top(ghost.hour) }}>+ New event</div>}
                </div>
              </div>
            );
          })}
          <div key={scans} className={cx('dm-ecx-scan', scans > 0 && 'dm-go')} />
        </div>
      </div>
      <div ref={pop} className={cx('dm-ecx-pop dm-mx-pop', open && 'dm-open')} role="dialog" aria-label="Event" inert={!open} style={place}
        onFocus={() => { inPop.current = true; }} onBlur={f => { if (!pop.current?.contains(f.relatedTarget as Node)) inPop.current = false; }}>
        {card && <Details key={`${card.id}:${runs}`} event={card} onClose={close} onSave={v => save(card, v)} onDiscard={() => remove(card.id)} onPrepNotes={onPrepNotes} onJoin={onJoin} />}
      </div>
    </div>
  );
}
event-calendar.cssReact · 171 lines
/* Generated from designme.dev by scripts/sync.mjs. Edit the site, then sync. */
/* ---------- Event calendar ---------- */
.dm-ecx{overflow:hidden;position:relative;container:ecx/inline-size}
/* the Ask pill crossfades its words but stays a flex row, so the spark keeps its gap */
.dm-ecx-ask.dm-sw{display:inline-flex}
/* while the agent checks, its words carry the loaders' highlight sweep in the pill's own colour */
.dm-ecx-ask .dm-shim{color:inherit;-webkit-text-fill-color:transparent;background-image:linear-gradient(90deg,currentColor 0%,currentColor 38%,var(--dm-faint) 50%,currentColor 62%,currentColor 100%)}
/* the Ask pill is an accent tint, like a picked preset in Date range picker */
.dm-pill.dm-soft.dm-ecx-ask{background:var(--dm-sel);color:var(--dm-accent-fg,var(--dm-accent));box-shadow:none}
@media (hover:hover) and (pointer:fine){.dm-pill.dm-soft.dm-ecx-ask:hover{background:color-mix(in srgb,var(--dm-accent) 14%,transparent)}}
.dm-ecx-h{display:flex;align-items:center;gap:var(--dm-s-2);padding:10px var(--dm-s-3);border-bottom:1px solid color-mix(in srgb,var(--dm-line) 50%,transparent);font-size:13.5px;flex-wrap:wrap}
.dm-ecx-h b{font-weight:500}
.dm-ecx-sp{flex:1}
/* the library's calendar (the Sales CRM's keeps its own layout): the head and the days sit 16px in from the card's sides, and
   the head's week and agent's button 16px from its top and from its hairline, in every style */
.dm-ecx.dm-panel:not(.dm-crm-ecx){padding:0 var(--dm-s-4)}
.dm-ecx.dm-panel:not(.dm-crm-ecx)>.dm-ecx-h{margin:0 calc(-1 * var(--dm-s-4));padding:var(--dm-s-4)}
.dm-ecx-sc{overflow-x:auto}
/* --dm-ph is the height of an hour: every event, the grid lines and the time column are laid out in hours of it */
.dm-ecx-grid{display:grid;grid-template-columns:44px repeat(var(--dm-days,5),minmax(76px,1fr));min-width:424px;position:relative;--dm-ph:44px}
.dm-ecx-tm{grid-row:1/3;display:flex;flex-direction:column;padding-top:var(--dm-s-8)}
.dm-ecx-tm span{height:var(--dm-ph);font-size:10.5px;color:var(--dm-muted);text-align:right;padding-right:var(--dm-s-2);transform:translateY(-6px)}
.dm-ecx-tm i{font-style:normal}
/* the time column reads in hours (9am), and in half hours (9:00, 9:30) where one row is 30 minutes */
.dm-ecx-tm .dm-hf,.dm-ecx-tm .dm-n{display:none}
.dm-ecx-day{border-left:1px solid color-mix(in srgb,var(--dm-line) 50%,transparent)}
.dm-ecx-dh{height:32px;display:flex;align-items:center;justify-content:center;gap:5px;font-size:12px;color:var(--dm-fg2);border-bottom:1px solid color-mix(in srgb,var(--dm-line) 50%,transparent)}
.dm-ecx-dh b{font-weight:500;color:var(--dm-fg)}
.dm-ecx-dh.dm-t b{width:22px;height:22px;border-radius:50%;background:var(--dm-accent);color:var(--dm-on-accent);display:grid;place-items:center;font-size:11.5px}
.dm-ecx-col{position:relative;height:calc(var(--dm-ph) * 8);background-image:linear-gradient(color-mix(in srgb,var(--dm-line) 50%,transparent) 1px,transparent 1px);background-size:100% var(--dm-ph)}
.dm-ecx-e{position:absolute;left:3px;right:3px;border-radius:var(--dm-r-sm);padding:var(--dm-s-1) 7px;font-size:11.5px;line-height:1.3;text-align:left;overflow:hidden;transition:transform .25s var(--dm-ease),box-shadow .25s}
@media (hover:hover) and (pointer:fine){.dm-ecx-e:hover{transform:translateY(-1px);box-shadow:var(--dm-shadow)}}
/* every event keeps its pastel pair at full strength, and its hover is a deeper fill in its own colour; an event whose card is
   open is a step deeper, with a faint ring in its colour. No lift, no drop shadow, no grey ring (owner, 20 Nov: "the selected
   state hover shadow is so bad"). (The Sales CRM's calendar has its own, the same) */
.dm-ecx:not(.dm-crm-ecx) .dm-ecx-e{transition:box-shadow var(--dm-t-fast) var(--dm-ease)}
@media (hover:hover) and (pointer:fine){.dm-ecx:not(.dm-crm-ecx) .dm-ecx-e:hover{transform:none}}
@media (hover:hover) and (pointer:fine){.dm-ecx:not(.dm-crm-ecx) .dm-ecx-e:not(.dm-sug,.dm-drag):hover{box-shadow:none}}
@media (hover:hover) and (pointer:fine){.dm-ecx:not(.dm-crm-ecx) .dm-ecx-e:not(.dm-sug,.dm-drag):hover{box-shadow:inset 0 0 0 100vmax color-mix(in srgb,currentColor 7%,transparent)}}
.dm-ecx:not(.dm-crm-ecx) .dm-ecx-e.dm-on:not(.dm-sug,.dm-drag){box-shadow:inset 0 0 0 100vmax color-mix(in srgb,currentColor 10%,transparent),inset 0 0 0 1px color-mix(in srgb,currentColor 35%,transparent)}
/* events sit in the scrolling grid, which would cut an outside ring: theirs is drawn inside */
.dm-ecx-e:focus-visible{outline-offset:-2px}
.dm-ecx-e{cursor:grab;touch-action:none}
.dm-ecx-e.dm-drag{transition:none;z-index:6;box-shadow:var(--dm-shadow-pop);cursor:grabbing}
.dm-ecx-col{cursor:copy}
.dm-ecx-ghost{position:absolute;left:3px;right:3px;height:calc(var(--dm-ph) - 3px);border-radius:var(--dm-r-sm);border:1.5px dashed color-mix(in srgb,var(--dm-accent-mark,var(--dm-accent)) 45%,transparent);background:color-mix(in srgb,var(--dm-accent) 5%,transparent);color:var(--dm-accent-fg,var(--dm-accent));font-size:11px;font-weight:500;padding:var(--dm-s-1) 7px;pointer-events:none}
.dm-ecx-now{position:absolute;left:0;right:0;height:2px;margin-top:-1px;background:var(--dm-bad-mark);z-index:3}
.dm-ecx-now::before{content:"";position:absolute;left:-4px;top:-3px;width:8px;height:8px;border-radius:50%;background:var(--dm-bad-mark)}
.dm-ecx-msg{font-size:12.5px;margin-right:var(--dm-s-2)}
.dm-ecx-pop{position:absolute;z-index:20;width:248px;padding:var(--dm-s-3);background:var(--dm-raised);border-radius:calc(14px * var(--dm-rk-l,var(--dm-rk)));box-shadow:var(--dm-shadow-pop);opacity:0;visibility:hidden;transform:translateY(6px);filter:blur(3px);pointer-events:none;transition:opacity .2s var(--dm-ease),transform .35s var(--dm-ease),filter .2s,visibility 0s .2s}
.dm-ecx-pop.dm-open{opacity:1;visibility:visible;transform:none;filter:none;pointer-events:auto;transition-property:opacity,transform,filter}
/* its motion (the core's motion pieces, owner, 26 Nov): the event's card grows out of the event's side (.mx-pop) and goes back
   quicker; a press shows at once (.mx-press); Ask's and Prep notes' boxes ease to the width of their new words (mxWidth()) */
.dm-ecx-pop.dm-mx-pop{transform:scale(.95);filter:blur(var(--dm-blur-in));transform-origin:var(--dm-origin,top left);transition:opacity var(--dm-t-out) var(--dm-ease-io),transform var(--dm-t-out) var(--dm-ease-io),filter var(--dm-t-out) var(--dm-ease-io),visibility 0s var(--dm-t-out)}
.dm-ecx-pop.dm-mx-pop.dm-open{transform:none;filter:none;transition:opacity calc(var(--dm-t-in) * .6) var(--dm-ease),transform var(--dm-t-in) var(--dm-ease-pop),filter calc(var(--dm-t-in) * .7) var(--dm-ease),visibility 0s}
@media (prefers-reduced-motion:reduce){.dm-ecx-pop.dm-mx-pop{filter:none}}
.dm-ecx-ph{display:flex;align-items:center;gap:var(--dm-s-2);font-size:13.5px}
.dm-ecx-ph>i{width:10px;height:10px;border-radius:var(--dm-r-tiny,3px);flex:none}
.dm-ecx-ph b{font-weight:500;flex:1;min-width:0}
.dm-ecx-ph .dm-ib{width:24px;height:24px;margin:-4px -4px -4px auto}
/* a new event's title is a field like any other: white, the dimmed field edge, one step stronger while you type */
.dm-ecx-ti{flex:1;min-width:0;height:32px;padding:0 var(--dm-s-3);border:0;outline:0;border-radius:var(--dm-r-field);background:var(--dm-surface);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dm-field-line) 50%,transparent);font:inherit;font-weight:500;color:var(--dm-fg);transition:box-shadow var(--dm-t-fast)}
@supports (corner-shape:squircle){.dm-ecx-ti{corner-shape:squircle;border-radius:var(--dm-r-field-sq)}}
.dm-ecx-ti::placeholder{color:var(--dm-muted)}
.dm-ecx-ti:focus{box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dm-field-line-strong) 50%,transparent)}
.dm-ecx-pt{font-size:12.5px;color:var(--dm-fg2);margin:var(--dm-s-1) 0 0 18px}
.dm-ecx-pw{display:flex;align-items:center;margin:10px 0 0 18px}
.dm-ecx-pw .dm-av{width:22px;height:22px;font-size:9px;margin-right:-4px;box-shadow:0 0 0 2px var(--dm-raised)}
.dm-ecx-pw .dm-muted{margin-left:10px;font-size:12px}
/* the library's event card (the Sales CRM's, built on it, keeps its own): 16px in from its edges, the close button's glyph
   16px in on the title's line, and the people side by side, never stacked over each other. Everything under the title (the
   time, the people, the notes and the buttons) starts at the card's left content edge, where the colour dot sits, so both
   sides have the same room (owner, 20 Nov) */
.dm-ecx-pop:not(.dm-crm-cpop){padding:var(--dm-s-4)}
.dm-ecx-pop:not(.dm-crm-cpop) :is(.dm-ecx-pt,.dm-ecx-pw,.dm-ecx-note,.dm-ecx-pa){margin-left:0}
.dm-ecx-pop:not(.dm-crm-cpop) .dm-ecx-ph .dm-ib{margin:-4px -6px -4px auto}
.dm-ecx-pop:not(.dm-crm-cpop) .dm-ecx-pw{gap:var(--dm-s-1)}
.dm-ecx-pop:not(.dm-crm-cpop) .dm-ecx-pw .dm-av{margin-right:0;box-shadow:none}
.dm-ecx-pop:not(.dm-crm-cpop) .dm-ecx-pw .dm-muted{margin-left:6px}
.dm-ecx-note{display:flex;gap:6px;align-items:flex-start;margin:10px 0 0 18px;font-size:12px;line-height:1.45;color:var(--dm-fg2)}
.dm-ecx-note .dm-i{color:var(--dm-accent-fg,var(--dm-accent));margin-top:2px}
.dm-ecx-pa{display:flex;justify-content:flex-end;gap:6px;margin:var(--dm-s-3) 0 0 18px}
/* the card's buttons share the width of its text column, the main one last (owner, 10 Nov) */
.dm-ecx-pa>.dm-pill{flex:1 1 0;justify-content:center}
.dm-ecx-prep.dm-done{color:var(--dm-fg2)}
.dm-ecx-prep.dm-done>.dm-i{color:var(--dm-ok-mark)}
/* nothing in it grows or shrinks when it is pressed (owner, 18 Nov); Studio's ink primary alone presses */
.dm-ecx:not(.dm-crm-ecx) :is(.dm-ib,.dm-pill,.dm-ecx-days button):active,:root[data-style="studio"] .dm-ecx:not(.dm-crm-ecx) .dm-ib:active,:root [data-style="studio"] .dm-ecx:not(.dm-crm-ecx) .dm-ib:active,:root [data-style="studio"].dm-ecx:not(.dm-crm-ecx) .dm-ib:active{transform:none}
.dm-ecx-e b{display:block;font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.dm-ecx-e span{font-size:10.5px}
.dm-ecx-e.dm-sug{background:var(--dm-surface)!important;color:var(--dm-accent-fg,var(--dm-accent))!important;box-shadow:inset 0 0 0 1.5px var(--dm-accent-mark,var(--dm-accent));animation:dm-ecs .6s var(--dm-ease) both}
.dm-ecx-e.dm-sug.dm-alt{box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dm-accent-mark,var(--dm-accent)) 40%,transparent)}
@keyframes dm-ecs{from{opacity:0;transform:scale(.92);filter:blur(3px)}}
.dm-ecx-sg{display:flex;gap:var(--dm-s-1);margin-top:var(--dm-s-1)}
.dm-ecx-sg button{font-size:10.5px;padding:2px 6px;border-radius:var(--dm-r-tiny,5px);background:var(--dm-accent);color:var(--dm-on-accent)}
.dm-ecx-sg button.dm-n{background:transparent;color:var(--dm-accent-fg,var(--dm-accent))}
.dm-ecx-scan{position:absolute;left:44px;right:0;height:2px;background:linear-gradient(90deg,transparent,var(--dm-accent),transparent);top:32px;opacity:0;pointer-events:none}
.dm-ecx-scan.dm-go{animation:dm-ecsc 1.2s var(--dm-ease-io) both}
@keyframes dm-ecsc{0%{opacity:0;top:32px}20%{opacity:1}100%{opacity:0;top:384px}}
/* a narrow calendar, on a phone or in a narrow card: one day at a time, picked from a row of days, so every event has room
   for its whole title and time. Each row of the grid is half an hour (owner, 4 Nov): an hour is two rows, so an event from
   9 to 10 is two rows tall, and the time column reads 9:00, 9:30, 10:00 */
.dm-ecx-days{display:none}
@container ecx (max-width:519px){
  .dm-ecx-days{display:flex;gap:var(--dm-s-1);padding:var(--dm-s-2) var(--dm-s-3);border-bottom:1px solid color-mix(in srgb,var(--dm-line) 50%,transparent)}
  .dm-ecx-days button{flex:1;min-width:0;display:flex;flex-direction:column;align-items:center;gap:2px;padding:var(--dm-s-1) 0;border-radius:var(--dm-r-sm);font-size:11.5px;color:var(--dm-fg2);transition:background var(--dm-t-fast),color var(--dm-t-fast)}
  @media (hover:hover) and (pointer:fine){.dm-ecx-days button:hover{background:var(--dm-row);color:var(--dm-fg)}}
  .dm-ecx-days button[aria-pressed="true"]{background:var(--dm-surface);color:var(--dm-fg);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dm-pick-on) 50%,transparent)}
  .dm-ecx-days b{display:grid;place-items:center;width:24px;height:24px;border-radius:50%;font-size:13px;font-weight:500;color:var(--dm-fg)}
  .dm-ecx-days .dm-t b{background:var(--dm-accent);color:var(--dm-on-accent)}
  .dm-ecx-sc{overflow:visible}
  .dm-ecx-grid{grid-template-columns:44px minmax(0,1fr);min-width:0;padding-top:var(--dm-s-2);--dm-ph:56px}
  .dm-ecx-col{background-size:100% calc(var(--dm-ph) / 2)}
  .dm-ecx-tm span{height:calc(var(--dm-ph) / 2)}
  .dm-ecx-tm .dm-hf,.dm-ecx-tm .dm-n{display:block}
  .dm-ecx-tm .dm-w{display:none}
  .dm-ecx-day:not(.dm-on){display:none}
  .dm-ecx-dh{display:none}
  .dm-ecx-tm{grid-row:auto;padding-top:0}
  .dm-ecx-scan{top:8px}
  .dm-ecx-scan.dm-go{animation-name:dm-ecscn}
  .dm-ecx-pop{max-width:calc(100% - 16px)}
  .dm-ecx:not(.dm-crm-ecx) .dm-ecx-days{padding:var(--dm-s-2) 0}
}
/* a calendar too narrow for the week and the agent's button side by side stacks its head: the week on its line, the button under
   it on the same left edge */
@container ecx (max-width:360px){
  .dm-ecx:not(.dm-crm-ecx)>.dm-ecx-h{flex-direction:column;align-items:flex-start}
  .dm-ecx:not(.dm-crm-ecx)>.dm-ecx-h>:is(.dm-ecx-sp,.dm-ecx-msg:empty){display:none}
}
@keyframes dm-ecscn{0%{opacity:0;top:8px}20%{opacity:1}100%{opacity:0;top:calc(var(--dm-ph) * 8 + 8px)}}
/* Studio (owner, 17 and 18 Nov): an off-white head strip with the week and the agent's ask, which sits 16px from the card's edges
   and the strip's hairline (owner, 23 Nov); the days 16px in from the card's sides, running on to its foot as Soft's do. Events keep their colours and are
   ordinary rounded rectangles, never pills. The event card takes the card's 22px corners and is 16px in on every side, as in
   Soft (owner, 20 Nov). Book is the ink button. (The Sales CRM's calendar and event card are built on these classes and keep
   their own layout) */
:root[data-style="studio"] .dm-ecx.dm-panel:not(.dm-crm-ecx),:root [data-style="studio"] .dm-ecx.dm-panel:not(.dm-crm-ecx),:root [data-style="studio"].dm-ecx.dm-panel:not(.dm-crm-ecx){padding:0 16px}
/* (the Sales CRM's calendar keeps the padding this card's earlier Studio rule gave it) */
:root[data-style="studio"] .dm-ecx.dm-panel.dm-crm-ecx,:root [data-style="studio"] .dm-ecx.dm-panel.dm-crm-ecx,:root [data-style="studio"].dm-ecx.dm-panel.dm-crm-ecx{padding:10px 17px 0 10px}
:root[data-style="studio"] .dm-ecx:not(.dm-crm-ecx)>.dm-ecx-h,:root [data-style="studio"] .dm-ecx:not(.dm-crm-ecx)>.dm-ecx-h,:root [data-style="studio"].dm-ecx:not(.dm-crm-ecx)>.dm-ecx-h{min-height:calc(28px + 2 * var(--dm-strip-y) + 1px);margin:0 -16px;padding:var(--dm-strip-y) 16px;background:var(--dm-strip);border-bottom:1px solid var(--dm-line);border-radius:var(--dm-r-card) var(--dm-r-card) 0 0}
:root[data-style="studio"] .dm-ecx-e,:root [data-style="studio"] .dm-ecx-e,:root [data-style="studio"].dm-ecx-e,:root[data-style="studio"] .dm-ecx-ghost,:root [data-style="studio"] .dm-ecx-ghost,:root [data-style="studio"].dm-ecx-ghost{border-radius:var(--dm-r-sm)}
:root[data-style="studio"] .dm-ecx:not(.dm-crm-ecx) .dm-ecx-sg button,:root [data-style="studio"] .dm-ecx:not(.dm-crm-ecx) .dm-ecx-sg button,:root [data-style="studio"].dm-ecx:not(.dm-crm-ecx) .dm-ecx-sg button{border-radius:var(--dm-r-xs)}
:root[data-style="studio"] .dm-ecx:not(.dm-crm-ecx) .dm-ecx-sg button.dm-y,:root [data-style="studio"] .dm-ecx:not(.dm-crm-ecx) .dm-ecx-sg button.dm-y,:root [data-style="studio"].dm-ecx:not(.dm-crm-ecx) .dm-ecx-sg button.dm-y{background:var(--dm-btn-2);color:var(--dm-on-btn)}
:root[data-style="studio"] .dm-ecx:not(.dm-crm-ecx) .dm-ecx-sg button.dm-n,:root [data-style="studio"] .dm-ecx:not(.dm-crm-ecx) .dm-ecx-sg button.dm-n,:root [data-style="studio"].dm-ecx:not(.dm-crm-ecx) .dm-ecx-sg button.dm-n{color:var(--dm-fg)}
:root[data-style="studio"] .dm-ecx-pop:not(.dm-crm-cpop),:root [data-style="studio"] .dm-ecx-pop:not(.dm-crm-cpop),:root [data-style="studio"].dm-ecx-pop:not(.dm-crm-cpop){border-radius:var(--dm-r-card)}
:root[data-style="studio"] .dm-ecx-pop:not(.dm-crm-cpop) .dm-ecx-note .dm-i,:root [data-style="studio"] .dm-ecx-pop:not(.dm-crm-cpop) .dm-ecx-note .dm-i,:root [data-style="studio"].dm-ecx-pop:not(.dm-crm-cpop) .dm-ecx-note .dm-i{color:var(--dm-fg2)}
/* Studio (owner, 21 Nov: "same with calendar components especially the popup"). The events keep their saturated colours (owner,
   20 Nov: no washed-out calendars) with Studio's touches: 10px corners, their tint with the title and time in their own colour
   and no line down their left (owner, 26 Nov: the tint-only option of lab/calendar-events), the words 8px in on both sides
   (the dashed new-event slot matches), a hover that deepens their fill, eased, and an open event ringed in a neutral grey. The now line is a crisp 1px
   red line. The event card is Studio's popover (22px corners, its shadow, scaling and fading from the event it opens beside):
   a head strip with the event's colour, its title and a ghost ×; the time and the people (side by side, as in Soft, and how
   many) in its body; and Prep notes (a flat secondary) and Join (the ink primary), the same height, in its foot strip */
:root[data-style="studio"] .dm-ecx:not(.dm-crm-ecx) .dm-ecx-e,:root [data-style="studio"] .dm-ecx:not(.dm-crm-ecx) .dm-ecx-e,:root [data-style="studio"].dm-ecx:not(.dm-crm-ecx) .dm-ecx-e{border-radius:10px;padding:4px 8px;transition:box-shadow var(--dm-t-fast) var(--dm-ease)}
:root[data-style="studio"] .dm-ecx:not(.dm-crm-ecx) .dm-ecx-ghost,:root [data-style="studio"] .dm-ecx:not(.dm-crm-ecx) .dm-ecx-ghost,:root [data-style="studio"].dm-ecx:not(.dm-crm-ecx) .dm-ecx-ghost{border-radius:10px;padding:4px 8px}
@media (hover:hover) and (pointer:fine){:root[data-style="studio"] .dm-ecx:not(.dm-crm-ecx) .dm-ecx-e:not(.dm-sug,.dm-drag):hover,:root [data-style="studio"] .dm-ecx:not(.dm-crm-ecx) .dm-ecx-e:not(.dm-sug,.dm-drag):hover,:root [data-style="studio"].dm-ecx:not(.dm-crm-ecx) .dm-ecx-e:not(.dm-sug,.dm-drag):hover{box-shadow:inset 0 0 0 100vmax color-mix(in srgb,currentColor 9%,transparent)}}
:root[data-style="studio"] .dm-ecx:not(.dm-crm-ecx) .dm-ecx-e.dm-on:not(.dm-sug,.dm-drag),:root [data-style="studio"] .dm-ecx:not(.dm-crm-ecx) .dm-ecx-e.dm-on:not(.dm-sug,.dm-drag),:root [data-style="studio"].dm-ecx:not(.dm-crm-ecx) .dm-ecx-e.dm-on:not(.dm-sug,.dm-drag){box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dm-fg) 40%,transparent),inset 0 0 0 100vmax color-mix(in srgb,currentColor 11%,transparent)}
:root[data-style="studio"] .dm-ecx:not(.dm-crm-ecx) .dm-ecx-e.dm-drag,:root [data-style="studio"] .dm-ecx:not(.dm-crm-ecx) .dm-ecx-e.dm-drag,:root [data-style="studio"].dm-ecx:not(.dm-crm-ecx) .dm-ecx-e.dm-drag{box-shadow:var(--dm-shadow-pop)}
:root[data-style="studio"] .dm-ecx:not(.dm-crm-ecx) .dm-ecx-now,:root [data-style="studio"] .dm-ecx:not(.dm-crm-ecx) .dm-ecx-now,:root [data-style="studio"].dm-ecx:not(.dm-crm-ecx) .dm-ecx-now{height:1px;margin-top:-.5px}
:root[data-style="studio"] .dm-ecx:not(.dm-crm-ecx) .dm-ecx-now::before,:root [data-style="studio"] .dm-ecx:not(.dm-crm-ecx) .dm-ecx-now::before,:root [data-style="studio"].dm-ecx:not(.dm-crm-ecx) .dm-ecx-now::before{left:-3px;top:-3px;width:7px;height:7px}
:root[data-style="studio"] .dm-ecx-pop:not(.dm-crm-cpop),:root [data-style="studio"] .dm-ecx-pop:not(.dm-crm-cpop),:root [data-style="studio"].dm-ecx-pop:not(.dm-crm-cpop){padding:0 16px 16px;filter:none;transform:scale(.96);transform-origin:var(--dm-origin,top left);transition:opacity var(--dm-t-fast) var(--dm-ease),transform var(--dm-t) var(--dm-ease),visibility 0s var(--dm-t-fast)}
:root[data-style="studio"] .dm-ecx-pop.dm-open:not(.dm-crm-cpop),:root [data-style="studio"] .dm-ecx-pop.dm-open:not(.dm-crm-cpop),:root [data-style="studio"].dm-ecx-pop.dm-open:not(.dm-crm-cpop){transform:none;transition:opacity var(--dm-t-fast) var(--dm-ease),transform var(--dm-t) var(--dm-ease)}
:root[data-style="studio"] .dm-ecx-pop:not(.dm-crm-cpop) .dm-ecx-ph,:root [data-style="studio"] .dm-ecx-pop:not(.dm-crm-cpop) .dm-ecx-ph,:root [data-style="studio"].dm-ecx-pop:not(.dm-crm-cpop) .dm-ecx-ph{min-height:calc(28px + 2 * var(--dm-strip-y) + 1px);margin:0 -16px;padding:var(--dm-strip-y) 16px;background:var(--dm-strip);border-bottom:1px solid var(--dm-line);border-radius:var(--dm-r-card) var(--dm-r-card) 0 0}
:root[data-style="studio"] .dm-ecx-pop:not(.dm-crm-cpop) .dm-ecx-ph>i,:root [data-style="studio"] .dm-ecx-pop:not(.dm-crm-cpop) .dm-ecx-ph>i,:root [data-style="studio"].dm-ecx-pop:not(.dm-crm-cpop) .dm-ecx-ph>i{width:10px;height:10px;border-radius:50%}
:root[data-style="studio"] .dm-ecx-pop:not(.dm-crm-cpop) .dm-ecx-ph .dm-ib,:root [data-style="studio"] .dm-ecx-pop:not(.dm-crm-cpop) .dm-ecx-ph .dm-ib,:root [data-style="studio"].dm-ecx-pop:not(.dm-crm-cpop) .dm-ecx-ph .dm-ib{width:28px;height:28px;margin:-4px -8px -4px auto;border-radius:50%}
:root[data-style="studio"] .dm-ecx-pop:not(.dm-crm-cpop) .dm-ecx-pt,:root [data-style="studio"] .dm-ecx-pop:not(.dm-crm-cpop) .dm-ecx-pt,:root [data-style="studio"].dm-ecx-pop:not(.dm-crm-cpop) .dm-ecx-pt{margin-top:16px}
:root[data-style="studio"] .dm-ecx-pop:not(.dm-crm-cpop) .dm-ecx-pw,:root [data-style="studio"] .dm-ecx-pop:not(.dm-crm-cpop) .dm-ecx-pw,:root [data-style="studio"].dm-ecx-pop:not(.dm-crm-cpop) .dm-ecx-pw{margin-top:12px}
:root[data-style="studio"] .dm-ecx-pop:not(.dm-crm-cpop) .dm-ecx-pa,:root [data-style="studio"] .dm-ecx-pop:not(.dm-crm-cpop) .dm-ecx-pa,:root [data-style="studio"].dm-ecx-pop:not(.dm-crm-cpop) .dm-ecx-pa{margin:16px -16px -16px;padding:var(--dm-strip-y) 16px;background:var(--dm-strip);border-top:1px solid var(--dm-line);border-radius:0 0 var(--dm-r-card) var(--dm-r-card)}
:root[data-style="studio"] .dm-ecx-pop:not(.dm-crm-cpop) .dm-ecx-pa>.dm-pill,:root [data-style="studio"] .dm-ecx-pop:not(.dm-crm-cpop) .dm-ecx-pa>.dm-pill,:root [data-style="studio"].dm-ecx-pop:not(.dm-crm-cpop) .dm-ecx-pa>.dm-pill{height:28px}
@container ecx (max-width:360px){:root[data-style="studio"] .dm-ecx:not(.dm-crm-ecx)>.dm-ecx-h,:root [data-style="studio"] .dm-ecx:not(.dm-crm-ecx)>.dm-ecx-h,:root [data-style="studio"].dm-ecx:not(.dm-crm-ecx)>.dm-ecx-h{padding-top:var(--dm-strip-y)}}
EventCalendar.astroAstro · 28 lines
---
// Generated from designme.dev by scripts/sync.mjs. Edit the site, then sync.
// Event calendar: A week view where the agent finds a free slot for you.
// The markup, CSS and script are designme.dev's own, run by the shared core in ../core, which mounts the component when it scrolls
// into view and plays its demo. To show your own data, change event-calendar.js. The markup is kept exactly as it is (is:raw).
import type { HTMLAttributes } from 'astro/types';
import '../core/designme.css';
import './event-calendar.css';

export interface Props extends HTMLAttributes<'div'> {
  /** "soft" or "studio" draws it in that style. Leave it out for Blueprint, or for the style set on <html> (data-style="soft" or "studio") */
  'data-style'?: 'soft' | 'studio';
}
const { class: className, ...rest } = Astro.props;
---
<div class:list={['card', 'wide', className]} data-c="event-calendar" {...rest}>
  <div class="stage-in"><Fragment is:raw>
<div class="ecx panel">
  <div class="ecx-h"><b>Oct 19 – 23, 2026</b><span class="ecx-sp"></span><span class="ecx-msg muted"></span><button class="pill soft sm ecx-ask mx-w"><svg class="i xs"><use href="#i-spark"/></svg>Find 45 min for a design review</button></div>
  <div class="ecx-days" role="group" aria-label="Day"></div>
  <div class="ecx-sc"><div class="ecx-grid"><div class="ecx-tm"></div></div></div>
</div>
  </Fragment></div>
</div>
<script>
  import './event-calendar.js';
</script>
event-calendar.htmlHTML · 10 lines
<div class="card wide" data-c="event-calendar">
  <div class="stage-in">
    <div class="ecx panel">
      <div class="ecx-h"><b>Oct 19 – 23, 2026</b><span class="ecx-sp"></span><span class="ecx-msg muted"></span><button class="pill soft sm ecx-ask mx-w"><svg class="i xs"><use href="#i-spark"/></svg>Find 45 min for a design review</button></div>
      <div class="ecx-days" role="group" aria-label="Day"></div>
      <div class="ecx-sc"><div class="ecx-grid"><div class="ecx-tm"></div></div></div>
    </div>
  </div>
</div>
event-calendar.cssHTML · 170 lines
/* ---------- Event calendar ---------- */
.ecx{overflow:hidden;position:relative;container:ecx/inline-size}
/* the Ask pill crossfades its words but stays a flex row, so the spark keeps its gap */
.ecx-ask.sw{display:inline-flex}
/* while the agent checks, its words carry the loaders' highlight sweep in the pill's own colour */
.ecx-ask .shim{color:inherit;-webkit-text-fill-color:transparent;background-image:linear-gradient(90deg,currentColor 0%,currentColor 38%,var(--dm-faint) 50%,currentColor 62%,currentColor 100%)}
/* the Ask pill is an accent tint, like a picked preset in Date range picker */
.pill.soft.ecx-ask{background:var(--dm-sel);color:var(--dm-accent-fg,var(--dm-accent));box-shadow:none}
@media (hover:hover) and (pointer:fine){.pill.soft.ecx-ask:hover{background:color-mix(in srgb,var(--dm-accent) 14%,transparent)}}
.ecx-h{display:flex;align-items:center;gap:var(--dm-s-2);padding:10px var(--dm-s-3);border-bottom:1px solid color-mix(in srgb,var(--dm-line) 50%,transparent);font-size:13.5px;flex-wrap:wrap}
.ecx-h b{font-weight:500}
.ecx-sp{flex:1}
/* the library's calendar (the Sales CRM's keeps its own layout): the head and the days sit 16px in from the card's sides, and
   the head's week and agent's button 16px from its top and from its hairline, in every style */
.ecx.panel:not(.crm-ecx){padding:0 var(--dm-s-4)}
.ecx.panel:not(.crm-ecx)>.ecx-h{margin:0 calc(-1 * var(--dm-s-4));padding:var(--dm-s-4)}
.ecx-sc{overflow-x:auto}
/* --dm-ph is the height of an hour: every event, the grid lines and the time column are laid out in hours of it */
.ecx-grid{display:grid;grid-template-columns:44px repeat(var(--dm-days,5),minmax(76px,1fr));min-width:424px;position:relative;--dm-ph:44px}
.ecx-tm{grid-row:1/3;display:flex;flex-direction:column;padding-top:var(--dm-s-8)}
.ecx-tm span{height:var(--dm-ph);font-size:10.5px;color:var(--dm-muted);text-align:right;padding-right:var(--dm-s-2);transform:translateY(-6px)}
.ecx-tm i{font-style:normal}
/* the time column reads in hours (9am), and in half hours (9:00, 9:30) where one row is 30 minutes */
.ecx-tm .hf,.ecx-tm .n{display:none}
.ecx-day{border-left:1px solid color-mix(in srgb,var(--dm-line) 50%,transparent)}
.ecx-dh{height:32px;display:flex;align-items:center;justify-content:center;gap:5px;font-size:12px;color:var(--dm-fg2);border-bottom:1px solid color-mix(in srgb,var(--dm-line) 50%,transparent)}
.ecx-dh b{font-weight:500;color:var(--dm-fg)}
.ecx-dh.t b{width:22px;height:22px;border-radius:50%;background:var(--dm-accent);color:var(--dm-on-accent);display:grid;place-items:center;font-size:11.5px}
.ecx-col{position:relative;height:calc(var(--dm-ph) * 8);background-image:linear-gradient(color-mix(in srgb,var(--dm-line) 50%,transparent) 1px,transparent 1px);background-size:100% var(--dm-ph)}
.ecx-e{position:absolute;left:3px;right:3px;border-radius:var(--dm-r-sm);padding:var(--dm-s-1) 7px;font-size:11.5px;line-height:1.3;text-align:left;overflow:hidden;transition:transform .25s var(--dm-ease),box-shadow .25s}
@media (hover:hover) and (pointer:fine){.ecx-e:hover{transform:translateY(-1px);box-shadow:var(--dm-shadow)}}
/* every event keeps its pastel pair at full strength, and its hover is a deeper fill in its own colour; an event whose card is
   open is a step deeper, with a faint ring in its colour. No lift, no drop shadow, no grey ring (owner, 20 Nov: "the selected
   state hover shadow is so bad"). (The Sales CRM's calendar has its own, the same) */
.ecx:not(.crm-ecx) .ecx-e{transition:box-shadow var(--dm-t-fast) var(--dm-ease)}
@media (hover:hover) and (pointer:fine){.ecx:not(.crm-ecx) .ecx-e:hover{transform:none}}
@media (hover:hover) and (pointer:fine){.ecx:not(.crm-ecx) .ecx-e:not(.sug,.drag):hover{box-shadow:none}}
@media (hover:hover) and (pointer:fine){.ecx:not(.crm-ecx) .ecx-e:not(.sug,.drag):hover{box-shadow:inset 0 0 0 100vmax color-mix(in srgb,currentColor 7%,transparent)}}
.ecx:not(.crm-ecx) .ecx-e.on:not(.sug,.drag){box-shadow:inset 0 0 0 100vmax color-mix(in srgb,currentColor 10%,transparent),inset 0 0 0 1px color-mix(in srgb,currentColor 35%,transparent)}
/* events sit in the scrolling grid, which would cut an outside ring: theirs is drawn inside */
.ecx-e:focus-visible{outline-offset:-2px}
.ecx-e{cursor:grab;touch-action:none}
.ecx-e.drag{transition:none;z-index:6;box-shadow:var(--dm-shadow-pop);cursor:grabbing}
.ecx-col{cursor:copy}
.ecx-ghost{position:absolute;left:3px;right:3px;height:calc(var(--dm-ph) - 3px);border-radius:var(--dm-r-sm);border:1.5px dashed color-mix(in srgb,var(--dm-accent-mark,var(--dm-accent)) 45%,transparent);background:color-mix(in srgb,var(--dm-accent) 5%,transparent);color:var(--dm-accent-fg,var(--dm-accent));font-size:11px;font-weight:500;padding:var(--dm-s-1) 7px;pointer-events:none}
.ecx-now{position:absolute;left:0;right:0;height:2px;margin-top:-1px;background:var(--dm-bad-mark);z-index:3}
.ecx-now::before{content:"";position:absolute;left:-4px;top:-3px;width:8px;height:8px;border-radius:50%;background:var(--dm-bad-mark)}
.ecx-msg{font-size:12.5px;margin-right:var(--dm-s-2)}
.ecx-pop{position:absolute;z-index:20;width:248px;padding:var(--dm-s-3);background:var(--dm-raised);border-radius:calc(14px * var(--dm-rk-l,var(--dm-rk)));box-shadow:var(--dm-shadow-pop);opacity:0;visibility:hidden;transform:translateY(6px);filter:blur(3px);pointer-events:none;transition:opacity .2s var(--dm-ease),transform .35s var(--dm-ease),filter .2s,visibility 0s .2s}
.ecx-pop.open{opacity:1;visibility:visible;transform:none;filter:none;pointer-events:auto;transition-property:opacity,transform,filter}
/* its motion (the core's motion pieces, owner, 26 Nov): the event's card grows out of the event's side (.mx-pop) and goes back
   quicker; a press shows at once (.mx-press); Ask's and Prep notes' boxes ease to the width of their new words (mxWidth()) */
.ecx-pop.mx-pop{transform:scale(.95);filter:blur(var(--dm-blur-in));transform-origin:var(--dm-origin,top left);transition:opacity var(--dm-t-out) var(--dm-ease-io),transform var(--dm-t-out) var(--dm-ease-io),filter var(--dm-t-out) var(--dm-ease-io),visibility 0s var(--dm-t-out)}
.ecx-pop.mx-pop.open{transform:none;filter:none;transition:opacity calc(var(--dm-t-in) * .6) var(--dm-ease),transform var(--dm-t-in) var(--dm-ease-pop),filter calc(var(--dm-t-in) * .7) var(--dm-ease),visibility 0s}
@media (prefers-reduced-motion:reduce){.ecx-pop.mx-pop{filter:none}}
.ecx-ph{display:flex;align-items:center;gap:var(--dm-s-2);font-size:13.5px}
.ecx-ph>i{width:10px;height:10px;border-radius:var(--dm-r-tiny,3px);flex:none}
.ecx-ph b{font-weight:500;flex:1;min-width:0}
.ecx-ph .ib{width:24px;height:24px;margin:-4px -4px -4px auto}
/* a new event's title is a field like any other: white, the dimmed field edge, one step stronger while you type */
.ecx-ti{flex:1;min-width:0;height:32px;padding:0 var(--dm-s-3);border:0;outline:0;border-radius:var(--dm-r-field);background:var(--dm-surface);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dm-field-line) 50%,transparent);font:inherit;font-weight:500;color:var(--dm-fg);transition:box-shadow var(--dm-t-fast)}
@supports (corner-shape:squircle){.ecx-ti{corner-shape:squircle;border-radius:var(--dm-r-field-sq)}}
.ecx-ti::placeholder{color:var(--dm-muted)}
.ecx-ti:focus{box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dm-field-line-strong) 50%,transparent)}
.ecx-pt{font-size:12.5px;color:var(--dm-fg2);margin:var(--dm-s-1) 0 0 18px}
.ecx-pw{display:flex;align-items:center;margin:10px 0 0 18px}
.ecx-pw .av{width:22px;height:22px;font-size:9px;margin-right:-4px;box-shadow:0 0 0 2px var(--dm-raised)}
.ecx-pw .muted{margin-left:10px;font-size:12px}
/* the library's event card (the Sales CRM's, built on it, keeps its own): 16px in from its edges, the close button's glyph
   16px in on the title's line, and the people side by side, never stacked over each other. Everything under the title (the
   time, the people, the notes and the buttons) starts at the card's left content edge, where the colour dot sits, so both
   sides have the same room (owner, 20 Nov) */
.ecx-pop:not(.crm-cpop){padding:var(--dm-s-4)}
.ecx-pop:not(.crm-cpop) :is(.ecx-pt,.ecx-pw,.ecx-note,.ecx-pa){margin-left:0}
.ecx-pop:not(.crm-cpop) .ecx-ph .ib{margin:-4px -6px -4px auto}
.ecx-pop:not(.crm-cpop) .ecx-pw{gap:var(--dm-s-1)}
.ecx-pop:not(.crm-cpop) .ecx-pw .av{margin-right:0;box-shadow:none}
.ecx-pop:not(.crm-cpop) .ecx-pw .muted{margin-left:6px}
.ecx-note{display:flex;gap:6px;align-items:flex-start;margin:10px 0 0 18px;font-size:12px;line-height:1.45;color:var(--dm-fg2)}
.ecx-note .i{color:var(--dm-accent-fg,var(--dm-accent));margin-top:2px}
.ecx-pa{display:flex;justify-content:flex-end;gap:6px;margin:var(--dm-s-3) 0 0 18px}
/* the card's buttons share the width of its text column, the main one last (owner, 10 Nov) */
.ecx-pa>.pill{flex:1 1 0;justify-content:center}
.ecx-prep.done{color:var(--dm-fg2)}
.ecx-prep.done>.i{color:var(--dm-ok-mark)}
/* nothing in it grows or shrinks when it is pressed (owner, 18 Nov); Studio's ink primary alone presses */
.ecx:not(.crm-ecx) :is(.ib,.pill,.ecx-days button):active,:root[data-style="studio"] .ecx:not(.crm-ecx) .ib:active,:root [data-style="studio"] .ecx:not(.crm-ecx) .ib:active,:root [data-style="studio"].ecx:not(.crm-ecx) .ib:active{transform:none}
.ecx-e b{display:block;font-weight:500;white-space:nowrap;overflow:hidden;text-overflow:ellipsis}
.ecx-e span{font-size:10.5px}
.ecx-e.sug{background:var(--dm-surface)!important;color:var(--dm-accent-fg,var(--dm-accent))!important;box-shadow:inset 0 0 0 1.5px var(--dm-accent-mark,var(--dm-accent));animation:ecs .6s var(--dm-ease) both}
.ecx-e.sug.alt{box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dm-accent-mark,var(--dm-accent)) 40%,transparent)}
@keyframes ecs{from{opacity:0;transform:scale(.92);filter:blur(3px)}}
.ecx-sg{display:flex;gap:var(--dm-s-1);margin-top:var(--dm-s-1)}
.ecx-sg button{font-size:10.5px;padding:2px 6px;border-radius:var(--dm-r-tiny,5px);background:var(--dm-accent);color:var(--dm-on-accent)}
.ecx-sg button.n{background:transparent;color:var(--dm-accent-fg,var(--dm-accent))}
.ecx-scan{position:absolute;left:44px;right:0;height:2px;background:linear-gradient(90deg,transparent,var(--dm-accent),transparent);top:32px;opacity:0;pointer-events:none}
.ecx-scan.go{animation:ecsc 1.2s var(--dm-ease-io) both}
@keyframes ecsc{0%{opacity:0;top:32px}20%{opacity:1}100%{opacity:0;top:384px}}
/* a narrow calendar, on a phone or in a narrow card: one day at a time, picked from a row of days, so every event has room
   for its whole title and time. Each row of the grid is half an hour (owner, 4 Nov): an hour is two rows, so an event from
   9 to 10 is two rows tall, and the time column reads 9:00, 9:30, 10:00 */
.ecx-days{display:none}
@container ecx (max-width:519px){
  .ecx-days{display:flex;gap:var(--dm-s-1);padding:var(--dm-s-2) var(--dm-s-3);border-bottom:1px solid color-mix(in srgb,var(--dm-line) 50%,transparent)}
  .ecx-days button{flex:1;min-width:0;display:flex;flex-direction:column;align-items:center;gap:2px;padding:var(--dm-s-1) 0;border-radius:var(--dm-r-sm);font-size:11.5px;color:var(--dm-fg2);transition:background var(--dm-t-fast),color var(--dm-t-fast)}
  @media (hover:hover) and (pointer:fine){.ecx-days button:hover{background:var(--dm-row);color:var(--dm-fg)}}
  .ecx-days button[aria-pressed="true"]{background:var(--dm-surface);color:var(--dm-fg);box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dm-pick-on) 50%,transparent)}
  .ecx-days b{display:grid;place-items:center;width:24px;height:24px;border-radius:50%;font-size:13px;font-weight:500;color:var(--dm-fg)}
  .ecx-days .t b{background:var(--dm-accent);color:var(--dm-on-accent)}
  .ecx-sc{overflow:visible}
  .ecx-grid{grid-template-columns:44px minmax(0,1fr);min-width:0;padding-top:var(--dm-s-2);--dm-ph:56px}
  .ecx-col{background-size:100% calc(var(--dm-ph) / 2)}
  .ecx-tm span{height:calc(var(--dm-ph) / 2)}
  .ecx-tm .hf,.ecx-tm .n{display:block}
  .ecx-tm .w{display:none}
  .ecx-day:not(.on){display:none}
  .ecx-dh{display:none}
  .ecx-tm{grid-row:auto;padding-top:0}
  .ecx-scan{top:8px}
  .ecx-scan.go{animation-name:ecscn}
  .ecx-pop{max-width:calc(100% - 16px)}
  .ecx:not(.crm-ecx) .ecx-days{padding:var(--dm-s-2) 0}
}
/* a calendar too narrow for the week and the agent's button side by side stacks its head: the week on its line, the button under
   it on the same left edge */
@container ecx (max-width:360px){
  .ecx:not(.crm-ecx)>.ecx-h{flex-direction:column;align-items:flex-start}
  .ecx:not(.crm-ecx)>.ecx-h>:is(.ecx-sp,.ecx-msg:empty){display:none}
}
@keyframes ecscn{0%{opacity:0;top:8px}20%{opacity:1}100%{opacity:0;top:calc(var(--dm-ph) * 8 + 8px)}}
/* Studio (owner, 17 and 18 Nov): an off-white head strip with the week and the agent's ask, which sits 16px from the card's edges
   and the strip's hairline (owner, 23 Nov); the days 16px in from the card's sides, running on to its foot as Soft's do. Events keep their colours and are
   ordinary rounded rectangles, never pills. The event card takes the card's 22px corners and is 16px in on every side, as in
   Soft (owner, 20 Nov). Book is the ink button. (The Sales CRM's calendar and event card are built on these classes and keep
   their own layout) */
:root[data-style="studio"] .ecx.panel:not(.crm-ecx),:root [data-style="studio"] .ecx.panel:not(.crm-ecx),:root [data-style="studio"].ecx.panel:not(.crm-ecx){padding:0 16px}
/* (the Sales CRM's calendar keeps the padding this card's earlier Studio rule gave it) */
:root[data-style="studio"] .ecx.panel.crm-ecx,:root [data-style="studio"] .ecx.panel.crm-ecx,:root [data-style="studio"].ecx.panel.crm-ecx{padding:10px 17px 0 10px}
:root[data-style="studio"] .ecx:not(.crm-ecx)>.ecx-h,:root [data-style="studio"] .ecx:not(.crm-ecx)>.ecx-h,:root [data-style="studio"].ecx:not(.crm-ecx)>.ecx-h{min-height:calc(28px + 2 * var(--dm-strip-y) + 1px);margin:0 -16px;padding:var(--dm-strip-y) 16px;background:var(--dm-strip);border-bottom:1px solid var(--dm-line);border-radius:var(--dm-r-card) var(--dm-r-card) 0 0}
:root[data-style="studio"] .ecx-e,:root [data-style="studio"] .ecx-e,:root [data-style="studio"].ecx-e,:root[data-style="studio"] .ecx-ghost,:root [data-style="studio"] .ecx-ghost,:root [data-style="studio"].ecx-ghost{border-radius:var(--dm-r-sm)}
:root[data-style="studio"] .ecx:not(.crm-ecx) .ecx-sg button,:root [data-style="studio"] .ecx:not(.crm-ecx) .ecx-sg button,:root [data-style="studio"].ecx:not(.crm-ecx) .ecx-sg button{border-radius:var(--dm-r-xs)}
:root[data-style="studio"] .ecx:not(.crm-ecx) .ecx-sg button.y,:root [data-style="studio"] .ecx:not(.crm-ecx) .ecx-sg button.y,:root [data-style="studio"].ecx:not(.crm-ecx) .ecx-sg button.y{background:var(--dm-btn-2);color:var(--dm-on-btn)}
:root[data-style="studio"] .ecx:not(.crm-ecx) .ecx-sg button.n,:root [data-style="studio"] .ecx:not(.crm-ecx) .ecx-sg button.n,:root [data-style="studio"].ecx:not(.crm-ecx) .ecx-sg button.n{color:var(--dm-fg)}
:root[data-style="studio"] .ecx-pop:not(.crm-cpop),:root [data-style="studio"] .ecx-pop:not(.crm-cpop),:root [data-style="studio"].ecx-pop:not(.crm-cpop){border-radius:var(--dm-r-card)}
:root[data-style="studio"] .ecx-pop:not(.crm-cpop) .ecx-note .i,:root [data-style="studio"] .ecx-pop:not(.crm-cpop) .ecx-note .i,:root [data-style="studio"].ecx-pop:not(.crm-cpop) .ecx-note .i{color:var(--dm-fg2)}
/* Studio (owner, 21 Nov: "same with calendar components especially the popup"). The events keep their saturated colours (owner,
   20 Nov: no washed-out calendars) with Studio's touches: 10px corners, their tint with the title and time in their own colour
   and no line down their left (owner, 26 Nov: the tint-only option of lab/calendar-events), the words 8px in on both sides
   (the dashed new-event slot matches), a hover that deepens their fill, eased, and an open event ringed in a neutral grey. The now line is a crisp 1px
   red line. The event card is Studio's popover (22px corners, its shadow, scaling and fading from the event it opens beside):
   a head strip with the event's colour, its title and a ghost ×; the time and the people (side by side, as in Soft, and how
   many) in its body; and Prep notes (a flat secondary) and Join (the ink primary), the same height, in its foot strip */
:root[data-style="studio"] .ecx:not(.crm-ecx) .ecx-e,:root [data-style="studio"] .ecx:not(.crm-ecx) .ecx-e,:root [data-style="studio"].ecx:not(.crm-ecx) .ecx-e{border-radius:10px;padding:4px 8px;transition:box-shadow var(--dm-t-fast) var(--dm-ease)}
:root[data-style="studio"] .ecx:not(.crm-ecx) .ecx-ghost,:root [data-style="studio"] .ecx:not(.crm-ecx) .ecx-ghost,:root [data-style="studio"].ecx:not(.crm-ecx) .ecx-ghost{border-radius:10px;padding:4px 8px}
@media (hover:hover) and (pointer:fine){:root[data-style="studio"] .ecx:not(.crm-ecx) .ecx-e:not(.sug,.drag):hover,:root [data-style="studio"] .ecx:not(.crm-ecx) .ecx-e:not(.sug,.drag):hover,:root [data-style="studio"].ecx:not(.crm-ecx) .ecx-e:not(.sug,.drag):hover{box-shadow:inset 0 0 0 100vmax color-mix(in srgb,currentColor 9%,transparent)}}
:root[data-style="studio"] .ecx:not(.crm-ecx) .ecx-e.on:not(.sug,.drag),:root [data-style="studio"] .ecx:not(.crm-ecx) .ecx-e.on:not(.sug,.drag),:root [data-style="studio"].ecx:not(.crm-ecx) .ecx-e.on:not(.sug,.drag){box-shadow:inset 0 0 0 1px color-mix(in srgb,var(--dm-fg) 40%,transparent),inset 0 0 0 100vmax color-mix(in srgb,currentColor 11%,transparent)}
:root[data-style="studio"] .ecx:not(.crm-ecx) .ecx-e.drag,:root [data-style="studio"] .ecx:not(.crm-ecx) .ecx-e.drag,:root [data-style="studio"].ecx:not(.crm-ecx) .ecx-e.drag{box-shadow:var(--dm-shadow-pop)}
:root[data-style="studio"] .ecx:not(.crm-ecx) .ecx-now,:root [data-style="studio"] .ecx:not(.crm-ecx) .ecx-now,:root [data-style="studio"].ecx:not(.crm-ecx) .ecx-now{height:1px;margin-top:-.5px}
:root[data-style="studio"] .ecx:not(.crm-ecx) .ecx-now::before,:root [data-style="studio"] .ecx:not(.crm-ecx) .ecx-now::before,:root [data-style="studio"].ecx:not(.crm-ecx) .ecx-now::before{left:-3px;top:-3px;width:7px;height:7px}
:root[data-style="studio"] .ecx-pop:not(.crm-cpop),:root [data-style="studio"] .ecx-pop:not(.crm-cpop),:root [data-style="studio"].ecx-pop:not(.crm-cpop){padding:0 16px 16px;filter:none;transform:scale(.96);transform-origin:var(--dm-origin,top left);transition:opacity var(--dm-t-fast) var(--dm-ease),transform var(--dm-t) var(--dm-ease),visibility 0s var(--dm-t-fast)}
:root[data-style="studio"] .ecx-pop.open:not(.crm-cpop),:root [data-style="studio"] .ecx-pop.open:not(.crm-cpop),:root [data-style="studio"].ecx-pop.open:not(.crm-cpop){transform:none;transition:opacity var(--dm-t-fast) var(--dm-ease),transform var(--dm-t) var(--dm-ease)}
:root[data-style="studio"] .ecx-pop:not(.crm-cpop) .ecx-ph,:root [data-style="studio"] .ecx-pop:not(.crm-cpop) .ecx-ph,:root [data-style="studio"].ecx-pop:not(.crm-cpop) .ecx-ph{min-height:calc(28px + 2 * var(--dm-strip-y) + 1px);margin:0 -16px;padding:var(--dm-strip-y) 16px;background:var(--dm-strip);border-bottom:1px solid var(--dm-line);border-radius:var(--dm-r-card) var(--dm-r-card) 0 0}
:root[data-style="studio"] .ecx-pop:not(.crm-cpop) .ecx-ph>i,:root [data-style="studio"] .ecx-pop:not(.crm-cpop) .ecx-ph>i,:root [data-style="studio"].ecx-pop:not(.crm-cpop) .ecx-ph>i{width:10px;height:10px;border-radius:50%}
:root[data-style="studio"] .ecx-pop:not(.crm-cpop) .ecx-ph .ib,:root [data-style="studio"] .ecx-pop:not(.crm-cpop) .ecx-ph .ib,:root [data-style="studio"].ecx-pop:not(.crm-cpop) .ecx-ph .ib{width:28px;height:28px;margin:-4px -8px -4px auto;border-radius:50%}
:root[data-style="studio"] .ecx-pop:not(.crm-cpop) .ecx-pt,:root [data-style="studio"] .ecx-pop:not(.crm-cpop) .ecx-pt,:root [data-style="studio"].ecx-pop:not(.crm-cpop) .ecx-pt{margin-top:16px}
:root[data-style="studio"] .ecx-pop:not(.crm-cpop) .ecx-pw,:root [data-style="studio"] .ecx-pop:not(.crm-cpop) .ecx-pw,:root [data-style="studio"].ecx-pop:not(.crm-cpop) .ecx-pw{margin-top:12px}
:root[data-style="studio"] .ecx-pop:not(.crm-cpop) .ecx-pa,:root [data-style="studio"] .ecx-pop:not(.crm-cpop) .ecx-pa,:root [data-style="studio"].ecx-pop:not(.crm-cpop) .ecx-pa{margin:16px -16px -16px;padding:var(--dm-strip-y) 16px;background:var(--dm-strip);border-top:1px solid var(--dm-line);border-radius:0 0 var(--dm-r-card) var(--dm-r-card)}
:root[data-style="studio"] .ecx-pop:not(.crm-cpop) .ecx-pa>.pill,:root [data-style="studio"] .ecx-pop:not(.crm-cpop) .ecx-pa>.pill,:root [data-style="studio"].ecx-pop:not(.crm-cpop) .ecx-pa>.pill{height:28px}
@container ecx (max-width:360px){:root[data-style="studio"] .ecx:not(.crm-ecx)>.ecx-h,:root [data-style="studio"] .ecx:not(.crm-ecx)>.ecx-h,:root [data-style="studio"].ecx:not(.crm-ecx)>.ecx-h{padding-top:var(--dm-strip-y)}}
event-calendar.jsHTML · 99 lines
DM.def('event-calendar', (r, c) => {
  r.innerHTML = r.innerHTML.replace('{spark}', I('spark','xs'));
  const DAYS = ['Mon 19','Tue 20','Wed 21','Thu 22','Fri 23'], H0 = 9;
  const EV = [[0,9,1,'Standup','b'],[0,13,1.5,'Pricing workshop','p'],[1,10,1,'1:1 with Maya','l'],[1,14,2,'Focus: checkout','t'],[2,9,1,'Standup','b'],[2,11.5,1,'Agent demo','y'],[3,9,1,'Standup','b'],[3,12,1,'Lunch & learn','m'],[3,15,1.5,'Launch review','r'],[4,10,1.5,'Planning','p']];
  const grid = $('.ecx-grid', r);
  // an hour's height (--ph): 44px, or 56px on a narrow calendar where each 28px row is half an hour. Places are written in it,
  // so events keep their times when the calendar narrows or widens
  const PX = () => parseFloat(getComputedStyle(grid).getPropertyValue('--dm-ph')) || 44, at = h => `calc(var(--dm-ph) * ${h - H0} + 1px)`, tall = n => `calc(var(--dm-ph) * ${n} - 3px)`;
  // the time column: an hour a row (9am), or on a narrow calendar half an hour a row (9:00, 9:30)
  $('.ecx-tm', r).innerHTML = Array.from({ length:16 }, (_, i) => { const h = H0 + Math.floor(i / 2), h12 = h > 12 ? h - 12 : h; return i % 2 ? `<span class="hf"><i class="n">${h12}:30</i></span>` : `<span><i class="w">${h12}${h >= 12 ? 'pm' : 'am'}</i><i class="n">${h12}:00</i></span>`; }).join('');
  grid.insertAdjacentHTML('beforeend', DAYS.map((d, i) => `<div class="ecx-day"><div class="ecx-dh${i === 0 ? ' t' : ''}">${d.split(' ')[0]} <b>${d.split(' ')[1]}</b></div><div class="ecx-col" data-d="${i}"></div></div>`).join('') + '<div class="ecx-scan"></div>');
  const col = i => $(`.ecx-col[data-d="${i}"]`, grid);
  /* a narrow calendar shows one day: the row of days picks it, and an answer from the agent opens the day it found */
  const days = $('.ecx-days', r);
  days.innerHTML = DAYS.map((d, i) => `<button aria-pressed="false" data-d="${i}"${i === 0 ? ' class="t"' : ''} aria-label="${['Monday','Tuesday','Wednesday','Thursday','Friday'][i]} ${d.split(' ')[1]} October"><span>${d.split(' ')[0]}</span><b>${d.split(' ')[1]}</b></button>`).join('');
  let day = -1;
  const narrow = () => !!days.getClientRects().length;
  function showDay(i){
    if (i === day) return; const was = day; day = i;
    $$('button', days).forEach(b => b.setAttribute('aria-pressed', +b.dataset.d === i));
    $$('.ecx-day', grid).forEach((d, k) => d.classList.toggle('on', k === i));
    if (was >= 0 && narrow()){ closePop(); enter(col(i).parentElement); }
  }
  $$('button', days).forEach(b => b.onclick = () => showDay(+b.dataset.d));
  const tm = h => { const hh = Math.floor(h), mm = Math.round((h - hh) * 60); return `${hh > 12 ? hh - 12 : hh}:${String(mm).padStart(2, '0')}`; };
  const ev = (e, cls = '') => html(`<button class="ecx-e ${cls}" style="top:${at(e[1])};height:${tall(e[2])};background:var(--dm-p${e[4]}-bg);color:var(--dm-p${e[4]})"><b>${e[3]}</b><span>${tm(e[1])} – ${tm(e[1] + e[2])}</span></button>`);
  const panel = $('.ecx', r), msg = $('.ecx-msg', r), pop = html('<div class="ecx-pop mx-pop" role="dialog" aria-label="Event"></div>'); panel.appendChild(pop);
  const WHO = [['MK','var(--dm-av-l)','MK-g03'],['JO','var(--dm-av-m)','JO-g01'],['DA','var(--dm-av-b)'],['AR','var(--dm-av-p)','AR-g02']], DAYN = ['Mon','Tue','Wed','Thu','Fri'];
  let openFor = null;
  const say = t => swap(msg, t);
  // closing gives the focus back to the event when it was in the card
  const closePop = () => { const back = pop.contains(document.activeElement) && openFor; pop.classList.remove('open'); if (openFor) openFor.classList.remove('on'); openFor = null; if (back && back.isConnected) back.focus({ preventScroll:true }); };
  /* the details card opens beside the event and stays inside the calendar */
  function openPop(el){
    const e = el._e; if (openFor === el){ closePop(); return; } if (openFor) openFor.classList.remove('on'); openFor = el; el.classList.add('on'); const n = 2 + e[3].length % 3, fresh = e[3] === 'New event';
    pop.innerHTML = `<div class="ecx-ph"><i style="background:var(--dm-p${e[4]})"></i>${fresh ? '<input class="ecx-ti" placeholder="Add a title" aria-label="Event title">' : `<b>${e[3]}</b>`}<button class="ib ecx-px mx-press" aria-label="Close" data-tip="Close">${I('x','xs')}</button></div><div class="ecx-pt">${DAYN[e[0]]} ${DAYS[e[0]].split(' ')[1]} Oct · ${tm(e[1])} – ${tm(e[1] + e[2])}</div><div class="ecx-pw">${WHO.slice(0, n).map(w => AV(w[0], w[1], w[2])).join('')}<span class="muted">${n} people</span></div><div class="ecx-pa">${fresh ? '<button class="pill line sm ecx-del mx-press">Discard</button><button class="pill primary sm ecx-save">Save</button>' : `<button class="pill line sm ecx-prep mx-press">${I('spark','xs')}Prep notes</button><button class="pill primary sm">Join</button>`}</div>`;
    const pr = panel.getBoundingClientRect(), er = el.getBoundingClientRect(), w = 248;
    let x = er.right - pr.left + 8; if (x + w > pr.width - 16) x = er.left - pr.left - w - 8; x = Math.max(16, x);
    let y = er.top - pr.top; y = Math.max(16, Math.min(y, pr.height - pop.offsetHeight - 24));
    // (it scales and fades from the event's side, where Studio's popovers start)
    pop.style.left = x + 'px'; pop.style.top = y + 'px'; pop.style.setProperty('--dm-origin', (x > er.left - pr.left ? 'left' : 'right') + ' top');
    pop.classList.remove('open'); void pop.offsetWidth; pop.classList.add('open'); hideTip();
    $('.ecx-px', pop).onclick = closePop;
    // Prep notes: its words shimmer while the agent writes; then the notes arrive above the buttons and the button stays, with
    // the green tick in place of its spark
    // (the button eases to the width of what it says now: mxWidth(), motion pieces)
    const relabel = (b, h) => { const w0 = b.offsetWidth; b.innerHTML = h; if (!REDUCE && w0) mxWidth(b, w0); };
    const prep = $('.ecx-prep', pop); if (prep) prep.onclick = () => { if (prep._busy) return; prep._busy = true; relabel(prep, '<span class="think on"><i></i><i></i><i></i><i></i></span><span class="shim">Writing</span>'); c.later(1200, () => { if (!prep.isConnected) return; const nt = html(`<div class="ecx-note">${I('spark','xs')}<span>Last week's decisions and 3 open questions.</span></div>`); prep.closest('.ecx-pa').before(nt); enter(nt); relabel(prep, I('check','xs') + 'Prep notes'); prep.classList.add('done'); prep.setAttribute('aria-disabled', 'true'); }); };
    const ti = $('.ecx-ti', pop); if (ti){ ti.focus({ preventScroll:true });
      const save = () => { const v = ti.value.trim() || 'Untitled'; e[3] = v; $('b', el).textContent = v; el.dataset.tip = v + ', ' + tm(e[1]); closePop(); say('Added ' + v + ', ' + DAYN[e[0]] + ' ' + tm(e[1])); };
      ti.onkeydown = k => { if (k.key === 'Enter') save(); if (k.key === 'Escape'){ el.remove(); closePop(); } };
      $('.ecx-save', pop).onclick = save; $('.ecx-del', pop).onclick = () => { el.remove(); closePop(); }; }
  }
  /* drag to another time or day, snapping to 15 minutes; a click without moving opens the details */
  const colX = i => col(i).getBoundingClientRect().left;
  function bind(el, e){ el._e = e; el.dataset.tip = e[3] + ', ' + tm(e[1]);
    // Enter or Space opens its card with the focus in it (a pointer opens it on release, below)
    el.onclick = k => { if (!k.isTrusted || k.detail) return; openPop(el); if (openFor === el){ const f = $('.ecx-ti', pop) || $('button', pop); if (f) f.focus({ preventScroll:true }); } };
    el.onpointerdown = d => { if (d.button || d.target.closest('.ecx-sg')) return; const sx = d.clientX, sy = d.clientY; let moved = false, nd = e[0], nh = e[1]; el.setPointerCapture(d.pointerId);
      el.onpointermove = m => { const dx = m.clientX - sx, dy = m.clientY - sy; if (!moved && Math.hypot(dx, dy) < 5) return; if (!moved){ moved = true; el.classList.add('drag'); closePop(); hideTip(); }
        nh = Math.max(H0, Math.min(H0 + 8 - e[2], e[1] + Math.round(dy / PX() * 4) / 4));
        const under = document.elementsFromPoint(m.clientX, m.clientY).find(x => x.classList && x.classList.contains('ecx-col')); if (under) nd = +under.dataset.d;
        el.style.transform = `translateX(${colX(nd) - colX(e[0])}px)`; el.style.top = at(nh); $('span', el).textContent = `${tm(nh)} – ${tm(nh + e[2])}`; };
      el.onpointerup = el.onpointercancel = () => { el.onpointermove = el.onpointerup = el.onpointercancel = null; if (!moved){ openPop(el); return; }
        el.classList.remove('drag'); el.style.transform = ''; const was = e[0] !== nd || e[1] !== nh; e[0] = nd; e[1] = nh; col(nd).appendChild(el); el.dataset.tip = e[3] + ', ' + tm(nh);
        if (was) say(`Moved ${e[3]} to ${DAYN[nd]} ${tm(nh)}`); }; }; }
  EV.forEach((e, i) => { const el = ev(e); col(e[0]).appendChild(el); enter(el, i * 30); bind(el, e); });
  showDay(0);
  /* now line on today's column */
  col(0).insertAdjacentHTML('beforeend', `<div class="ecx-now" style="top:calc(var(--dm-ph) * ${10.7 - H0})" data-tip="Now, 10:42"></div>`);
  /* a dashed slot follows the pointer over free time; click it to add an event there */
  const ghost = html('<div class="ecx-ghost">+ New event</div>');
  $$('.ecx-col', grid).forEach(cl => {
    cl.onpointermove = m => { if (m.target !== cl || $('.ecx-e.drag', grid)){ ghost.remove(); return; } const h = H0 + Math.min(15, Math.floor((m.clientY - cl.getBoundingClientRect().top) / PX() * 2)) / 2;
      ghost.style.top = at(h); ghost._h = h; if (ghost.parentElement !== cl) cl.appendChild(ghost); };
    cl.onpointerleave = () => ghost.remove();
    cl.onclick = m => { if (m.target !== cl || ghost.parentElement !== cl) return; const e = [+cl.dataset.d, ghost._h, 1, 'New event', 'k']; ghost.remove(); const el = ev(e); cl.appendChild(el); enter(el); bind(el, e); openPop(el); };
  });
  c.on(document, 'pointerdown', d => { if (openFor && !pop.contains(d.target) && !openFor.contains(d.target)) closePop(); });
  c.on(document, 'keydown', k => { if (k.key === 'Escape') closePop(); });
  const ask = $('.ecx-ask', r);
  // the button keeps its spark, only the words crossfade
  const tell = t => swap(ask, I('spark','xs') + t, true);
  ask.onclick = () => c.run(async () => {
    $$('.ecx-e.sug', grid).forEach(x => x.remove());
    const w0 = ask.offsetWidth; ask.innerHTML = '<span class="think on"><i></i><i></i><i></i><i></i></span><span class="shim">Checking 4 calendars</span>'; if (!REDUCE && w0) mxWidth(ask, w0); const sc = $('.ecx-scan', grid); sc.classList.remove('go'); void sc.offsetWidth; sc.classList.add('go');
    await c.wait(1300);
    const S = [[2,13.5,.75,'Design review','b'],[4,13,.75,'Design review','b']];
    S.forEach((s, i) => { const el = ev(s, 'sug' + (i ? ' alt' : '')); if (!i) el.insertAdjacentHTML('beforeend', '<div class="ecx-sg"><button class="y">Book</button><button class="n">Other</button></div>'); col(s[0]).appendChild(el); el.style.animationDelay = i * 120 + 'ms'; el.style.height = 'auto'; el.style.minHeight = tall(s[2]); });
    { const w0 = ask.offsetWidth; ask.innerHTML = I('spark','xs') + 'Everyone is free Wed 1:30'; if (!REDUCE && w0) mxWidth(ask, w0); }
    showDay(S[0][0]);
    const best = $('.ecx-e.sug:not(.alt)', grid);
    $('.y', best).onclick = e => { e.stopPropagation(); best.classList.remove('sug'); best.style.background = 'var(--dm-pb-bg)'; best.style.color = 'var(--dm-pb)'; best.style.boxShadow = ''; $('.ecx-sg', best).remove(); enter(best); bind(best, S[0]); $$('.ecx-e.sug', grid).forEach(x => x.remove()); tell('Booked, invites sent to 4 people'); };
    $('.n', best).onclick = e => { e.stopPropagation(); const alt = $('.ecx-e.sug.alt', grid); best.remove(); alt.classList.remove('alt'); alt.insertAdjacentHTML('beforeend', '<div class="ecx-sg"><button class="y">Book</button></div>'); $('.y', alt).onclick = ev2 => { ev2.stopPropagation(); alt.classList.remove('sug'); alt.style.background = 'var(--dm-pb-bg)'; alt.style.color = 'var(--dm-pb)'; $('.ecx-sg', alt).remove(); bind(alt, S[1]); tell('Booked Fri 1:00, invites sent'); }; tell('Next best: Fri 1:00'); showDay(S[1][0]); };
  });
  // the preview asks the agent for a slot once on its own, unless you take over first
  c.auto(1200, () => ask.click());
});
06

Questions

What people ask about it.

Does the calendar find free slots by itself?
No. onAsk tells you the person pressed the agent's button. Set finding to true while your agent looks, then pass what it found as suggestions and set finding back to false.
What should Book and Other do?
onBook gets the picked suggestion: add it to events and clear suggestions. onSkip gets the one being skipped: drop it from suggestions and the next one becomes the pick.
How do I save events after someone drags or adds one?
Pass events and onEventsChange. Every move, new event, rename and removal comes back as the full updated list, with times as local Dates.
Does it work on a phone?
Yes. Below 520px wide the week turns into a day view with a row of days to switch between, and dragging an event moves it within that day. The width of the calendar decides, not the screen, so a narrow card on a wide screen gets the day view too.
Can I show a full week or longer hours?
Yes. Set days to 7 for a full week, and startHour and hours for the time range, like startHour={8} and hours={10} for 8am to 6pm.
07

More in Dates

Pickers for single dates and date ranges.

Date pickerA field that opens a calendar, with quick picks and natural language.
Segmented controlSwitch between views of the same thing, with a sliding indicator.
Meeting cardThe next meeting from countdown to wrap-up, with the time already gone hatched out and a join that stays open.