@tristan2828/ui-foundation 4.137.2 → 4.138.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -42,8 +42,8 @@
42
42
  - [Filling in what's missing](#filling-in-whats-missing) · lines 1891–1958
43
43
  - [Values edited in place: the presets' looks](#values-edited-in-place-the-presets-looks) · lines 1960–1979
44
44
  - [A quick add line](#a-quick-add-line) · lines 1981–2009
45
- - [A month calendar](#a-month-calendar) · lines 2011–2035
46
- - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 2037–2089
45
+ - [A month calendar](#a-month-calendar) · lines 2011–2041
46
+ - [The sidebar and the phone's bar](#the-sidebar-and-the-phones-bar) · lines 2043–2095
47
47
 
48
48
  <!-- /index -->
49
49
 
@@ -2021,6 +2021,12 @@ package's `MonthCalendar`. Not a date picker, which is
2021
2021
  ("All day" without one), its `detail` and a link (`to`). The app's own
2022
2022
  actions for that day sit beside its heading (`dayActions`, an Add
2023
2023
  button); what picking a day does beyond that is the app's (`onSelect`).
2024
+ - **How an item opens its record** is `opens`, DataTable's kinds
2025
+ (add-an-entity.md "How a list opens a record"). Left out (`page`), a
2026
+ link goes to the record's page. `dialog` (or `dialog-only`) opens it in
2027
+ a dialog over the month, Open Full Page and all: the calendar's route is
2028
+ a `RecordDialogRoute` with the calendar as its `list` and the records
2029
+ as its children, as any list's is.
2024
2030
  - **Tones** are the semantic ones plus `neutral` (design-language
2025
2031
  "Semantic tones"): pick one per kind of thing (an event `info`, a visit
2026
2032
  `success`), not per item, and say in the list's `detail` what it is.
@@ -13,7 +13,7 @@ export type MonthCalendarItem = {
13
13
  time?: string | null;
14
14
  /** Its dot and mark (design-language.md "Semantic tones"). Defaults to `info`. */
15
15
  tone?: MonthCalendarTone;
16
- /** Where its row in the day's list goes. */
16
+ /** Where its row in the day's list goes (how, `opens`). */
17
17
  to?: To;
18
18
  /** A word after the time in the day's list ("Visit"). */
19
19
  detail?: string;
@@ -33,6 +33,14 @@ export type MonthCalendarProps = {
33
33
  onMonthChange?: (month: string) => void;
34
34
  /** The app's actions for the picked day, beside its heading (an Add button). */
35
35
  dayActions?: (day: PlainDate) => ReactNode;
36
+ /**
37
+ * How an item's link opens its record, DataTable's `opens` kinds
38
+ * (add-an-entity.md "How a list opens a record"): `dialog` and
39
+ * `dialog-only` open it over the calendar (the calendar's route a
40
+ * `RecordDialogRoute`, the record one of its children); `page`, the
41
+ * default, goes to its page.
42
+ */
43
+ opens?: 'dialog' | 'dialog-only' | 'page';
36
44
  /** The first day of the week. Defaults to Monday. */
37
45
  weekStart?: 'MO' | 'SU';
38
46
  isLoading?: boolean;
@@ -43,4 +51,4 @@ export type MonthCalendarProps = {
43
51
  locale?: string;
44
52
  className?: string;
45
53
  };
46
- export declare function MonthCalendar({ label, items, today, selected, onSelect, month, onMonthChange, dayActions, weekStart, isLoading, error, onRetry, emptyText, locale, className, }: MonthCalendarProps): import("react").JSX.Element;
54
+ export declare function MonthCalendar({ label, items, today, selected, onSelect, month, onMonthChange, dayActions, opens, weekStart, isLoading, error, onRetry, emptyText, locale, className, }: MonthCalendarProps): import("react").JSX.Element;
@@ -12,17 +12,23 @@ import { jsx as _jsx, jsxs as _jsxs, Fragment as _Fragment } from "react/jsx-run
12
12
  // past the month's edge turns the page. Every day is a plain day
13
13
  // (`'YYYY-MM-DD'`), never an instant, so no zone shifts one.
14
14
  //
15
+ // How an item's link opens its record is `opens`, DataTable's words: a
16
+ // dialog over the calendar (`dialog`, `dialog-only`: the link carries
17
+ // RecordDialogRoute's state, as a RecordLink does) or its page (`page`,
18
+ // the default).
19
+ //
15
20
  // Four states: loading (the month's frame with placeholders), error
16
21
  // (ErrorState in place of the days, the arrows still there), empty
17
22
  // ("Nothing this month" over the days) and success.
18
- import { useEffect, useMemo, useRef, useState } from 'react';
23
+ import { useContext, useEffect, useMemo, useRef, useState } from 'react';
19
24
  import { ChevronLeftIcon, ChevronRightIcon } from 'lucide-react';
20
- import { Link } from 'react-router';
25
+ import { Link, UNSAFE_LocationContext as LocationContext } from 'react-router';
21
26
  import { cn } from 'cn';
22
27
  import { Button } from '../ui/button.js';
23
28
  import { Skeleton } from '../ui/skeleton.js';
24
29
  import { formatPlainDate, localToPlainDate } from '../../lib/plain-date.js';
25
30
  import { ErrorState } from './error-state.js';
31
+ import { recordDialogState } from './record-dialog-context.js';
26
32
  const TONE_DOT = {
27
33
  neutral: 'bg-muted-foreground',
28
34
  info: 'bg-info',
@@ -61,11 +67,15 @@ function weekdayIndex(day) {
61
67
  return (new Date(Date.UTC(year, month - 1, date)).getUTCDay() + 6) % 7;
62
68
  }
63
69
  const byTime = (a, b) => (a.time ?? '').localeCompare(b.time ?? '');
64
- export function MonthCalendar({ label, items = [], today, selected, onSelect, month, onMonthChange, dayActions, weekStart = 'MO', isLoading, error, onRetry, emptyText = 'Nothing this month', locale, className, }) {
70
+ export function MonthCalendar({ label, items = [], today, selected, onSelect, month, onMonthChange, dayActions, opens = 'page', weekStart = 'MO', isLoading, error, onRetry, emptyText = 'Nothing this month', locale, className, }) {
65
71
  const [ownSelected, setOwnSelected] = useState(selected ?? today);
66
72
  const picked = selected ?? ownSelected;
67
73
  const [ownMonth, setOwnMonth] = useState(month ?? monthOf(picked));
68
74
  const shown = month ?? ownMonth;
75
+ // Read through the router's context, not useLocation, so a calendar
76
+ // with no links outside a router still renders (as DataTable does).
77
+ const routerLocation = useContext(LocationContext);
78
+ const linkState = opens !== 'page' && routerLocation ? recordDialogState(routerLocation.location) : undefined;
69
79
  const gridRef = useRef(null);
70
80
  const focusAfter = useRef(false);
71
81
  const byDay = useMemo(() => {
@@ -155,6 +165,6 @@ export function MonthCalendar({ label, items = [], today, selected, onSelect, mo
155
165
  }) }, row))) })] }), _jsxs("div", { role: "group", "aria-label": `${dayLabel(picked)}${picked === today ? ', today' : ''}`, "data-slot": "month-calendar-day", className: "flex flex-col gap-1", children: [_jsxs("div", { className: "flex items-center gap-2", children: [_jsxs("h3", { className: cn('mr-auto text-sm font-semibold', picked === today ? 'text-link' : 'text-foreground'), children: [dayLabel(picked), picked === today && ' · Today'] }), dayActions?.(picked)] }), isLoading ? (_jsxs("div", { className: "flex flex-col gap-2 py-1", children: [_jsx(Skeleton, { className: "h-4 w-2/3" }), _jsx(Skeleton, { className: "h-4 w-1/2" })] })) : pickedItems.length === 0 ? (_jsx("p", { className: "border-t border-border py-1.5 text-sm text-muted-foreground", children: "Nothing that day." })) : (_jsx("ul", { className: "flex flex-col", children: pickedItems.map((item) => {
156
166
  const when = [item.time ? clock(item.time, locale) : 'All day', item.detail].filter(Boolean).join(' · ');
157
167
  const body = (_jsxs(_Fragment, { children: [_jsx("span", { className: cn('size-2 shrink-0 rounded-full', TONE_DOT[item.tone ?? 'info']), "aria-hidden": "true" }), _jsx("span", { className: "min-w-0 flex-1 truncate", children: item.title }), _jsx("span", { className: "shrink-0 text-xs text-muted-foreground", children: when })] }));
158
- return (_jsx("li", { className: "border-t border-border", children: item.to ? (_jsx(Link, { to: item.to, className: "flex min-h-10 items-center gap-2 py-1.5 text-sm text-foreground outline-none hover:underline focus-visible:ring-3 focus-visible:ring-ring/50", children: body })) : (_jsx("div", { className: "flex min-h-10 items-center gap-2 py-1.5 text-sm text-foreground", children: body })) }, item.id));
168
+ return (_jsx("li", { className: "border-t border-border", children: item.to ? (_jsx(Link, { to: item.to, state: linkState, className: "flex min-h-10 items-center gap-2 py-1.5 text-sm text-foreground outline-none hover:underline focus-visible:ring-3 focus-visible:ring-ring/50", children: body })) : (_jsx("div", { className: "flex min-h-10 items-center gap-2 py-1.5 text-sm text-foreground", children: body })) }, item.id));
159
169
  }) }))] })] }))] }));
160
170
  }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@tristan2828/ui-foundation",
3
- "version": "4.137.2",
3
+ "version": "4.138.0",
4
4
  "description": "Shared UI foundation for contract-first, database-backed React apps: shadcn primitives, DataTable/EntityForm composites, auth, the gateway error seam, design tokens, lint rules and the AI playbook.",
5
5
  "license": "MIT",
6
6
  "repository": {