@dinachi/cli 1.1.0 → 1.4.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.
- package/CHANGELOG.md +81 -0
- package/README.md +1 -0
- package/dist/index.js +698 -314
- package/package.json +5 -1
- package/templates/agent/agent.tsx +35 -18
- package/templates/alert/alert.tsx +345 -0
- package/templates/alert/index.ts +16 -0
- package/templates/ask-bar/ask-bar.tsx +1061 -0
- package/templates/ask-bar/index.ts +1 -0
- package/templates/autocomplete/autocomplete.tsx +0 -1
- package/templates/breadcrumb/breadcrumb.tsx +606 -0
- package/templates/breadcrumb/index.ts +9 -0
- package/templates/calendar/calendar.tsx +1155 -0
- package/templates/calendar/index.ts +15 -0
- package/templates/combobox/combobox.tsx +0 -1
- package/templates/command-items/command-items.tsx +69 -0
- package/templates/command-items/index.ts +1 -0
- package/templates/command-palette/command-palette.tsx +954 -0
- package/templates/command-palette/index.ts +1 -0
- package/templates/comparison-table/comparison-table.tsx +540 -0
- package/templates/comparison-table/index.ts +15 -0
- package/templates/data-table/data-table.tsx +2077 -0
- package/templates/data-table/index.ts +14 -0
- package/templates/date-picker/date-picker.tsx +527 -0
- package/templates/date-picker/index.ts +2 -0
- package/templates/date-range-picker/date-range-picker.tsx +504 -0
- package/templates/date-range-picker/index.ts +2 -0
- package/templates/detail-list/detail-list.tsx +419 -0
- package/templates/detail-list/index.ts +12 -0
- package/templates/heat-table/heat-table.tsx +613 -0
- package/templates/heat-table/index.ts +9 -0
- package/templates/menu/menu.tsx +8 -3
- package/templates/month-picker/index.ts +1 -0
- package/templates/month-picker/month-picker.tsx +351 -0
- package/templates/omnibar/index.ts +1 -0
- package/templates/omnibar/omnibar.tsx +1009 -0
- package/templates/pagination/index.ts +8 -0
- package/templates/pagination/pagination.tsx +389 -0
- package/templates/table/index.ts +13 -0
- package/templates/table/table.tsx +265 -0
- package/templates/time-slots/index.ts +1 -0
- package/templates/time-slots/time-slots.tsx +589 -0
- package/templates/week-strip/index.ts +1 -0
- package/templates/week-strip/week-strip.tsx +329 -0
- package/templates/year-view/index.ts +1 -0
- package/templates/year-view/year-view.tsx +362 -0
|
@@ -0,0 +1,362 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { format, type Locale } from "date-fns";
|
|
5
|
+
import { cn } from "@/lib/utils";
|
|
6
|
+
import { changeAsAgent, useAgentControl, useAgentState, useHasAgent, useMergedRef } from "@/components/ui/agent";
|
|
7
|
+
import {
|
|
8
|
+
type CalendarChangeDetails,
|
|
9
|
+
addDays,
|
|
10
|
+
dayFirst,
|
|
11
|
+
fromISODate,
|
|
12
|
+
isSameDay,
|
|
13
|
+
parseDate,
|
|
14
|
+
startOfDay,
|
|
15
|
+
toISODate,
|
|
16
|
+
} from "@/components/ui/calendar";
|
|
17
|
+
|
|
18
|
+
function changeDetails(reason: string, event?: Event): CalendarChangeDetails {
|
|
19
|
+
const details: CalendarChangeDetails = {
|
|
20
|
+
reason,
|
|
21
|
+
event,
|
|
22
|
+
isCanceled: false,
|
|
23
|
+
cancel() {
|
|
24
|
+
details.isCanceled = true;
|
|
25
|
+
},
|
|
26
|
+
};
|
|
27
|
+
return details;
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
const WIDE = "(min-width: 768px)";
|
|
31
|
+
|
|
32
|
+
/** `weeks` from 768px up, `months` below, unless one is asked for. */
|
|
33
|
+
function useLayout(layout: "auto" | "weeks" | "months"): "weeks" | "months" {
|
|
34
|
+
const wide = React.useSyncExternalStore(
|
|
35
|
+
(onChange) => {
|
|
36
|
+
const query = window.matchMedia?.(WIDE);
|
|
37
|
+
query?.addEventListener("change", onChange);
|
|
38
|
+
return () => query?.removeEventListener("change", onChange);
|
|
39
|
+
},
|
|
40
|
+
() => window.matchMedia?.(WIDE).matches ?? true,
|
|
41
|
+
() => true
|
|
42
|
+
);
|
|
43
|
+
return layout === "auto" ? (wide ? "weeks" : "months") : layout;
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
const startOfWeek = (d: Date, weekStartsOn: number) => addDays(d, -((d.getDay() - weekStartsOn + 7) % 7));
|
|
47
|
+
|
|
48
|
+
/** Shade is the only channel: one step per quarter of the busiest day. */
|
|
49
|
+
const SHADE = [
|
|
50
|
+
"var(--muted)",
|
|
51
|
+
"color-mix(in oklab, var(--year-view-color, var(--success)) 28%, var(--muted))",
|
|
52
|
+
"color-mix(in oklab, var(--year-view-color, var(--success)) 52%, var(--muted))",
|
|
53
|
+
"color-mix(in oklab, var(--year-view-color, var(--success)) 76%, var(--muted))",
|
|
54
|
+
"var(--year-view-color, var(--success))",
|
|
55
|
+
];
|
|
56
|
+
|
|
57
|
+
export interface YearViewProps extends Omit<React.HTMLAttributes<HTMLDivElement>, "defaultValue" | "onChange" | "dir"> {
|
|
58
|
+
/** How many things happened each day, keyed YYYY-MM-DD. */
|
|
59
|
+
counts?: Record<string, number>;
|
|
60
|
+
/** The picked day. */
|
|
61
|
+
value?: Date | null;
|
|
62
|
+
defaultValue?: Date | null;
|
|
63
|
+
onValueChange?: (value: Date | null, details: CalendarChangeDetails) => void;
|
|
64
|
+
/** The last day shown. Defaults to today. */
|
|
65
|
+
end?: Date;
|
|
66
|
+
/** The first day shown. Defaults to 53 weeks before `end`'s week ends. */
|
|
67
|
+
start?: Date;
|
|
68
|
+
/** The last day that can be picked. Defaults to `today`, so later days are outlined. */
|
|
69
|
+
max?: Date;
|
|
70
|
+
/** Pressing the picked day keeps it instead of clearing it. */
|
|
71
|
+
required?: boolean;
|
|
72
|
+
/** Counts at or above each step get shades 1 to 4. Defaults to quarters of the busiest day. */
|
|
73
|
+
thresholds?: [number, number, number, number];
|
|
74
|
+
/** How a count reads in the heading, the readout and each day's name. Defaults to `3 events`. */
|
|
75
|
+
formatCount?: (count: number) => string;
|
|
76
|
+
/** The line above the grid. Defaults to the total over the year. */
|
|
77
|
+
heading?: (total: number) => React.ReactNode;
|
|
78
|
+
/** `weeks`: a year of weeks side by side. `months`: months stacked, squares big enough to tap. `auto` switches at 768px. */
|
|
79
|
+
layout?: "auto" | "weeks" | "months";
|
|
80
|
+
/** A date-fns locale, for day and month names and the first day of the week. */
|
|
81
|
+
locale?: Locale;
|
|
82
|
+
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
83
|
+
dir?: "ltr" | "rtl";
|
|
84
|
+
/** Defaults to the current day. */
|
|
85
|
+
today?: Date;
|
|
86
|
+
disabled?: boolean;
|
|
87
|
+
/** Submits the picked day as YYYY-MM-DD. */
|
|
88
|
+
name?: string;
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
/**
|
|
92
|
+
* A year of activity in one grid, a square per day shaded by how much happened. Picking
|
|
93
|
+
* a day gives its date and count under the grid.
|
|
94
|
+
*/
|
|
95
|
+
const YearView = React.forwardRef<HTMLDivElement, YearViewProps>((props, ref) => {
|
|
96
|
+
const {
|
|
97
|
+
counts = {},
|
|
98
|
+
value: valueProp,
|
|
99
|
+
defaultValue,
|
|
100
|
+
onValueChange,
|
|
101
|
+
end: endProp,
|
|
102
|
+
start: startProp,
|
|
103
|
+
max: maxProp,
|
|
104
|
+
required,
|
|
105
|
+
thresholds,
|
|
106
|
+
formatCount: formatCountProp,
|
|
107
|
+
heading,
|
|
108
|
+
layout: layoutProp = "auto",
|
|
109
|
+
locale,
|
|
110
|
+
weekStartsOn = locale?.options?.weekStartsOn ?? 1,
|
|
111
|
+
dir,
|
|
112
|
+
today: todayProp,
|
|
113
|
+
disabled,
|
|
114
|
+
name,
|
|
115
|
+
className,
|
|
116
|
+
"aria-label": ariaLabel = "Activity",
|
|
117
|
+
...rest
|
|
118
|
+
} = props;
|
|
119
|
+
const hasAgent = useHasAgent();
|
|
120
|
+
const layout = useLayout(layoutProp);
|
|
121
|
+
const today = React.useMemo(() => startOfDay(todayProp ?? new Date()), [todayProp ? toISODate(todayProp) : null]);
|
|
122
|
+
const end = startOfDay(endProp ?? today);
|
|
123
|
+
const last = addDays(startOfWeek(end, weekStartsOn), 6);
|
|
124
|
+
const start = startProp ? startOfDay(startProp) : null;
|
|
125
|
+
const first = start ? startOfWeek(start, weekStartsOn) : addDays(last, -53 * 7 + 1);
|
|
126
|
+
const weeks = Math.max(1, Math.round(((last.getTime() - first.getTime()) / 864e5 + 1) / 7));
|
|
127
|
+
const days = React.useMemo(() => Array.from({ length: weeks * 7 }, (_, i) => addDays(first, i)), [toISODate(first), weeks]);
|
|
128
|
+
const max = maxProp ? startOfDay(maxProp) : today;
|
|
129
|
+
const lo = start ?? first;
|
|
130
|
+
const open = (d: Date) => d >= lo && d <= end && d <= max;
|
|
131
|
+
const lastOpen = end < max ? end : max;
|
|
132
|
+
|
|
133
|
+
const formatCount =
|
|
134
|
+
formatCountProp ?? ((n: number) => `${n.toLocaleString(locale?.code ?? "en-US")} ${n === 1 ? "event" : "events"}`);
|
|
135
|
+
const countOf = (d: Date) => counts[toISODate(d)] ?? 0;
|
|
136
|
+
const total = days.reduce((t, d) => t + (open(d) ? countOf(d) : 0), 0);
|
|
137
|
+
const busiest = Math.max(1, ...days.map((d) => (open(d) ? countOf(d) : 0)));
|
|
138
|
+
const shade = (n: number) =>
|
|
139
|
+
n <= 0 ? 0 : thresholds ? thresholds.filter((s) => n >= s).length : Math.min(4, Math.ceil((4 * n) / busiest));
|
|
140
|
+
|
|
141
|
+
const [raw, change] = useAgentState<Date | null, CalendarChangeDetails>(valueProp, defaultValue ?? null, onValueChange);
|
|
142
|
+
const value = raw && startOfDay(raw);
|
|
143
|
+
const root = React.useRef<HTMLDivElement>(null);
|
|
144
|
+
const scroller = React.useRef<HTMLDivElement>(null);
|
|
145
|
+
|
|
146
|
+
const select = (d: Date | null, reason: string, event?: Event) => {
|
|
147
|
+
if (disabled || (d && !open(d)) || isSameDay(d, value) || (!d && (!value || required))) return;
|
|
148
|
+
change(d, changeDetails(reason, event));
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
/* ---- keyboard: arrows move focus, Enter or Space picks ---- */
|
|
152
|
+
const [focused, setFocused] = React.useState<string | null>(null);
|
|
153
|
+
const valueKey = value ? toISODate(value) : null;
|
|
154
|
+
const [seen, setSeen] = React.useState(valueKey);
|
|
155
|
+
if (seen !== valueKey) {
|
|
156
|
+
setSeen(valueKey);
|
|
157
|
+
if (valueKey) setFocused(null);
|
|
158
|
+
}
|
|
159
|
+
const focusNext = React.useRef(false);
|
|
160
|
+
React.useEffect(() => {
|
|
161
|
+
if (!focusNext.current || !focused) return;
|
|
162
|
+
focusNext.current = false;
|
|
163
|
+
root.current?.querySelector<HTMLElement>(`[data-day="${focused}"]`)?.focus();
|
|
164
|
+
}, [focused]);
|
|
165
|
+
|
|
166
|
+
const focusedDay = focused ? fromISODate(focused) : null;
|
|
167
|
+
const tabStop = focusedDay && open(focusedDay) ? focusedDay : value && open(value) ? value : lastOpen < lo ? lo : lastOpen;
|
|
168
|
+
|
|
169
|
+
// The latest weeks are the ones in view when the grid is too wide for its box.
|
|
170
|
+
React.useLayoutEffect(() => {
|
|
171
|
+
const sc = scroller.current;
|
|
172
|
+
if (sc && layout === "weeks") sc.scrollLeft = getComputedStyle(sc).direction === "rtl" ? -sc.scrollWidth : sc.scrollWidth;
|
|
173
|
+
}, [layout]);
|
|
174
|
+
|
|
175
|
+
const onKeyDown = (e: React.KeyboardEvent) => {
|
|
176
|
+
const rtl = root.current?.closest("[dir]")?.getAttribute("dir") === "rtl";
|
|
177
|
+
const across = layout === "weeks" ? 7 : 1;
|
|
178
|
+
const down = layout === "weeks" ? 1 : 7;
|
|
179
|
+
const from = tabStop;
|
|
180
|
+
const n = { ArrowLeft: rtl ? across : -across, ArrowRight: rtl ? -across : across, ArrowUp: -down, ArrowDown: down }[e.key];
|
|
181
|
+
const month = (k: number) => {
|
|
182
|
+
const d = new Date(from.getFullYear(), from.getMonth() + k, 1);
|
|
183
|
+
d.setDate(Math.min(from.getDate(), new Date(d.getFullYear(), d.getMonth() + 1, 0).getDate()));
|
|
184
|
+
return d < lo ? lo : d > lastOpen ? lastOpen : d;
|
|
185
|
+
};
|
|
186
|
+
const next =
|
|
187
|
+
n !== undefined ? addDays(from, n)
|
|
188
|
+
: e.key === "PageUp" ? month(-1)
|
|
189
|
+
: e.key === "PageDown" ? month(1)
|
|
190
|
+
: e.key === "Home" ? lo
|
|
191
|
+
: e.key === "End" ? lastOpen
|
|
192
|
+
: null;
|
|
193
|
+
if (!next) return;
|
|
194
|
+
e.preventDefault();
|
|
195
|
+
if (!open(next)) return;
|
|
196
|
+
focusNext.current = true;
|
|
197
|
+
setFocused(toISODate(next));
|
|
198
|
+
};
|
|
199
|
+
|
|
200
|
+
/* ---- agent ---- */
|
|
201
|
+
const clear = () =>
|
|
202
|
+
required ? "A day is required." : changeAsAgent((_: null, details: CalendarChangeDetails) => value && change(null, details), null);
|
|
203
|
+
useAgentControl(() => ({
|
|
204
|
+
kind: "date",
|
|
205
|
+
element: root.current,
|
|
206
|
+
value: value ? toISODate(value) : undefined,
|
|
207
|
+
disabled,
|
|
208
|
+
actions: {
|
|
209
|
+
setValue: (wanted: unknown) => {
|
|
210
|
+
if (wanted === null || wanted === "") return clear();
|
|
211
|
+
const d =
|
|
212
|
+
wanted instanceof Date
|
|
213
|
+
? isNaN(wanted.getTime()) ? null : startOfDay(wanted)
|
|
214
|
+
: typeof wanted === "string"
|
|
215
|
+
? fromISODate(wanted) ?? parseDate(wanted, { today, order: dayFirst(locale) ? "day-first" : "month-first", weekStartsOn })
|
|
216
|
+
: null;
|
|
217
|
+
if (!d) return `"${String(wanted)}" is not a date. Send YYYY-MM-DD.`;
|
|
218
|
+
if (d < lo) return `The view starts on ${toISODate(lo)}.`;
|
|
219
|
+
if (!open(d)) return `${toISODate(d)} is after ${toISODate(lastOpen)}, the last day that can be picked.`;
|
|
220
|
+
return changeAsAgent((next: Date, details: CalendarChangeDetails) => {
|
|
221
|
+
if (!isSameDay(next, value)) change(next, details);
|
|
222
|
+
}, d);
|
|
223
|
+
},
|
|
224
|
+
clear,
|
|
225
|
+
},
|
|
226
|
+
}));
|
|
227
|
+
|
|
228
|
+
/* ---- render ---- */
|
|
229
|
+
const square = (d: Date, className: string) => {
|
|
230
|
+
const n = countOf(d);
|
|
231
|
+
const live = open(d);
|
|
232
|
+
const selected = isSameDay(d, value);
|
|
233
|
+
return (
|
|
234
|
+
<button
|
|
235
|
+
key={toISODate(d)}
|
|
236
|
+
type="button"
|
|
237
|
+
data-slot="year-view-day"
|
|
238
|
+
data-day={toISODate(d)}
|
|
239
|
+
data-agent-part={hasAgent ? "" : undefined}
|
|
240
|
+
data-level={live ? shade(n) : undefined}
|
|
241
|
+
data-future={!live || undefined}
|
|
242
|
+
aria-label={`${format(d, "EEEE d MMMM yyyy", { locale })}: ${formatCount(live ? n : 0)}`}
|
|
243
|
+
aria-pressed={selected}
|
|
244
|
+
aria-disabled={!live || disabled || undefined}
|
|
245
|
+
tabIndex={isSameDay(d, tabStop) ? 0 : -1}
|
|
246
|
+
// Pressing the picked day again clears it, so a filter can be lifted.
|
|
247
|
+
onClick={(e) => {
|
|
248
|
+
if (live) setFocused(toISODate(d));
|
|
249
|
+
select(selected ? null : d, "day-press", e.nativeEvent);
|
|
250
|
+
}}
|
|
251
|
+
style={live ? { backgroundColor: SHADE[shade(n)] } : undefined}
|
|
252
|
+
className={cn(
|
|
253
|
+
"p-0 focus-visible:outline-none",
|
|
254
|
+
"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-1 focus-visible:ring-offset-background",
|
|
255
|
+
"aria-pressed:outline aria-pressed:outline-2 aria-pressed:outline-offset-1 aria-pressed:outline-foreground",
|
|
256
|
+
"data-[future]:cursor-default data-[future]:bg-transparent data-[future]:ring-1 data-[future]:ring-inset data-[future]:ring-border",
|
|
257
|
+
className
|
|
258
|
+
)}
|
|
259
|
+
/>
|
|
260
|
+
);
|
|
261
|
+
};
|
|
262
|
+
|
|
263
|
+
const weekdays = Array.from({ length: 7 }, (_, i) => addDays(first, i));
|
|
264
|
+
const monthsShown: Date[] = [];
|
|
265
|
+
for (let m = new Date(end.getFullYear(), end.getMonth(), 1); m >= new Date(first.getFullYear(), first.getMonth(), 1); m = new Date(m.getFullYear(), m.getMonth() - 1, 1)) {
|
|
266
|
+
monthsShown.push(m);
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
return (
|
|
270
|
+
<div
|
|
271
|
+
{...rest}
|
|
272
|
+
ref={useMergedRef(ref, root)}
|
|
273
|
+
role="group"
|
|
274
|
+
aria-label={ariaLabel}
|
|
275
|
+
aria-disabled={disabled || undefined}
|
|
276
|
+
dir={dir}
|
|
277
|
+
data-slot="year-view"
|
|
278
|
+
data-layout={layout}
|
|
279
|
+
className={cn(layout === "weeks" ? "w-full" : "w-full max-w-[22rem]", disabled && "opacity-50", className)}
|
|
280
|
+
>
|
|
281
|
+
<div data-slot="year-view-heading" className="mb-3 text-[0.9375rem] font-semibold">
|
|
282
|
+
{heading
|
|
283
|
+
? heading(total)
|
|
284
|
+
: start
|
|
285
|
+
? `${formatCount(total)} from ${format(start, "d MMM yyyy", { locale })} to ${format(end, "d MMM yyyy", { locale })}`
|
|
286
|
+
: `${formatCount(total)} ${isSameDay(end, today) ? "in the last 12 months" : `in the year to ${format(end, "d MMM yyyy", { locale })}`}`}
|
|
287
|
+
</div>
|
|
288
|
+
{layout === "weeks" ? (
|
|
289
|
+
<div className="flex gap-1.5">
|
|
290
|
+
{/* Outside the scroller, so the weekdays stay put while the year scrolls. */}
|
|
291
|
+
<div aria-hidden className="mt-4 grid w-5 shrink-0 grid-rows-[repeat(7,0.6875rem)] gap-y-[3px] text-[0.625rem] leading-[0.6875rem] text-muted-foreground">
|
|
292
|
+
{weekdays.map((d, i) => (
|
|
293
|
+
<span key={i}>{i % 2 === 0 && i < 6 ? format(d, "EEE", { locale }) : null}</span>
|
|
294
|
+
))}
|
|
295
|
+
</div>
|
|
296
|
+
<div ref={scroller} className="min-w-0 overflow-x-auto pb-1" onKeyDown={onKeyDown}>
|
|
297
|
+
<div className="w-max">
|
|
298
|
+
<div aria-hidden className="grid h-4 auto-cols-[0.6875rem] grid-flow-col gap-x-[3px] text-[0.6875rem] text-muted-foreground">
|
|
299
|
+
{Array.from({ length: weeks }, (_, w) => {
|
|
300
|
+
const d = addDays(first, w * 7);
|
|
301
|
+
return (
|
|
302
|
+
<span key={w} className="overflow-visible whitespace-nowrap">
|
|
303
|
+
{d.getDate() <= 7 ? format(d, "MMM", { locale }) : null}
|
|
304
|
+
</span>
|
|
305
|
+
);
|
|
306
|
+
})}
|
|
307
|
+
</div>
|
|
308
|
+
<div data-slot="year-view-grid" className="grid grid-flow-col grid-rows-[repeat(7,0.6875rem)] auto-cols-[0.6875rem] gap-[3px]">
|
|
309
|
+
{days.map((d) => square(d, "size-[0.6875rem] rounded-[3px]"))}
|
|
310
|
+
</div>
|
|
311
|
+
</div>
|
|
312
|
+
</div>
|
|
313
|
+
</div>
|
|
314
|
+
) : (
|
|
315
|
+
<div onKeyDown={onKeyDown}>
|
|
316
|
+
<div aria-hidden className="grid grid-cols-7 gap-1.5 border-b pb-2 text-center text-[0.6875rem] text-muted-foreground">
|
|
317
|
+
{weekdays.map((d, i) => (
|
|
318
|
+
<span key={i}>{format(d, "EEEEE", { locale })}</span>
|
|
319
|
+
))}
|
|
320
|
+
</div>
|
|
321
|
+
{/* Its own scroll, so a year of months never stretches the page. */}
|
|
322
|
+
<div className="max-h-[var(--year-view-height,22rem)] overflow-y-auto overflow-x-hidden overscroll-contain pt-3 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden">
|
|
323
|
+
{monthsShown.map((m) => {
|
|
324
|
+
const lead = (m.getDay() - weekStartsOn + 7) % 7;
|
|
325
|
+
const length = new Date(m.getFullYear(), m.getMonth() + 1, 0).getDate();
|
|
326
|
+
return (
|
|
327
|
+
<div key={m.getTime()} data-slot="year-view-month" className="mb-[1.125rem]">
|
|
328
|
+
<div data-slot="year-view-month-label" className="mb-2 text-[0.8125rem] font-semibold">{format(m, "MMMM yyyy", { locale })}</div>
|
|
329
|
+
<div data-slot="year-view-grid" className="grid grid-cols-7 gap-1.5">
|
|
330
|
+
{Array.from({ length: lead }, (_, i) => (
|
|
331
|
+
<span key={`lead-${i}`} />
|
|
332
|
+
))}
|
|
333
|
+
{Array.from({ length }, (_, i) => {
|
|
334
|
+
const d = new Date(m.getFullYear(), m.getMonth(), i + 1);
|
|
335
|
+
return d < lo ? <span key={i} /> : square(d, "aspect-square w-full rounded-[0.4375rem]");
|
|
336
|
+
})}
|
|
337
|
+
</div>
|
|
338
|
+
</div>
|
|
339
|
+
);
|
|
340
|
+
})}
|
|
341
|
+
</div>
|
|
342
|
+
</div>
|
|
343
|
+
)}
|
|
344
|
+
<p
|
|
345
|
+
data-slot="year-view-readout"
|
|
346
|
+
aria-live="polite"
|
|
347
|
+
className={cn("mt-3.5 min-h-5 text-[0.8125rem]", layout === "months" && "mt-0 border-t pt-3")}
|
|
348
|
+
>
|
|
349
|
+
{value && (
|
|
350
|
+
<>
|
|
351
|
+
{format(value, layout === "weeks" ? "EEEE d MMMM yyyy" : "EEEE d MMMM", { locale })}{" "}
|
|
352
|
+
<span className="text-muted-foreground">· {formatCount(countOf(value))}</span>
|
|
353
|
+
</>
|
|
354
|
+
)}
|
|
355
|
+
</p>
|
|
356
|
+
{name && <input type="hidden" name={name} disabled={disabled} value={value ? toISODate(value) : ""} />}
|
|
357
|
+
</div>
|
|
358
|
+
);
|
|
359
|
+
});
|
|
360
|
+
YearView.displayName = "YearView";
|
|
361
|
+
|
|
362
|
+
export { YearView };
|