@dinachi/cli 1.0.0 → 1.3.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 +69 -0
- package/dist/index.js +244 -72
- package/package.json +5 -1
- package/templates/accordion/accordion.tsx +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/alert-dialog/alert-dialog.tsx +14 -3
- package/templates/animated-icon/animated-icon.tsx +1 -0
- package/templates/animated-list/animated-list.tsx +2 -1
- package/templates/animated-tabs/animated-tabs.tsx +4 -0
- package/templates/ask-bar/ask-bar.tsx +1061 -0
- package/templates/ask-bar/index.ts +1 -0
- package/templates/autocomplete/autocomplete.tsx +14 -4
- package/templates/avatar/avatar.tsx +3 -0
- package/templates/badge/badge.tsx +1 -0
- package/templates/breadcrumb/breadcrumb.tsx +606 -0
- package/templates/breadcrumb/index.ts +9 -0
- package/templates/button/button.tsx +1 -0
- package/templates/calendar/calendar.tsx +1155 -0
- package/templates/calendar/index.ts +15 -0
- package/templates/card/card.tsx +6 -1
- package/templates/carousel/carousel.tsx +7 -0
- package/templates/checkbox/checkbox.tsx +1 -0
- package/templates/checkbox-group/checkbox-group.tsx +1 -0
- package/templates/collapsible/collapsible.tsx +3 -1
- package/templates/combobox/combobox.tsx +15 -4
- 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/compare-slider/compare-slider.tsx +1 -0
- package/templates/comparison-table/comparison-table.tsx +540 -0
- package/templates/comparison-table/index.ts +15 -0
- package/templates/context-menu/context-menu.tsx +61 -14
- 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/dialog/dialog.tsx +13 -3
- package/templates/drawer/drawer.tsx +19 -6
- package/templates/expandable-card/expandable-card.tsx +5 -1
- package/templates/field/field.tsx +5 -1
- package/templates/fieldset/fieldset.tsx +2 -0
- package/templates/form/form.tsx +1 -0
- package/templates/heat-table/heat-table.tsx +613 -0
- package/templates/heat-table/index.ts +9 -0
- package/templates/hold-to-confirm/hold-to-confirm.tsx +1 -0
- package/templates/input/input.tsx +1 -0
- package/templates/label/label.tsx +1 -0
- package/templates/link/link.tsx +1 -0
- package/templates/load-transition/load-transition.tsx +1 -0
- package/templates/marquee/marquee.tsx +1 -0
- package/templates/menu/menu.tsx +27 -6
- package/templates/menubar/menubar.tsx +15 -3
- package/templates/meter/meter.tsx +5 -1
- package/templates/month-picker/index.ts +1 -0
- package/templates/month-picker/month-picker.tsx +351 -0
- package/templates/navigation-menu/navigation-menu.tsx +13 -2
- package/templates/number-field/number-field.tsx +7 -1
- package/templates/number-ticker/number-ticker.tsx +3 -0
- package/templates/omnibar/index.ts +1 -0
- package/templates/omnibar/omnibar.tsx +1009 -0
- package/templates/otp-field/otp-field.tsx +4 -0
- package/templates/pagination/index.ts +8 -0
- package/templates/pagination/pagination.tsx +389 -0
- package/templates/popover/popover.tsx +19 -5
- package/templates/preview-card/preview-card.tsx +11 -3
- package/templates/progress/progress.tsx +5 -1
- package/templates/progress-ring/progress-ring.tsx +1 -0
- package/templates/radio/radio.tsx +3 -0
- package/templates/scroll-area/scroll-area.tsx +14 -4
- package/templates/scroll-progress/scroll-progress.tsx +1 -0
- package/templates/scroll-reveal/scroll-reveal.tsx +1 -0
- package/templates/select/select.tsx +18 -2
- package/templates/separator/separator.tsx +1 -0
- package/templates/skeleton/skeleton.tsx +1 -0
- package/templates/slider/slider.tsx +7 -0
- package/templates/sortable/sortable.tsx +3 -0
- package/templates/stagger-list/stagger-list.tsx +2 -0
- package/templates/streaming-text/streaming-text.tsx +1 -0
- package/templates/swipeable-row/swipeable-row.tsx +1 -0
- package/templates/switch/switch.tsx +2 -0
- package/templates/table/index.ts +13 -0
- package/templates/table/table.tsx +265 -0
- package/templates/tabs/tabs.tsx +5 -0
- package/templates/text/text.tsx +1 -0
- package/templates/text-morph/text-morph.tsx +2 -0
- package/templates/text-shimmer/text-shimmer.tsx +1 -0
- package/templates/textarea/textarea.tsx +1 -0
- package/templates/time-slots/index.ts +1 -0
- package/templates/time-slots/time-slots.tsx +589 -0
- package/templates/toast/toast.tsx +10 -1
- package/templates/toggle/toggle.tsx +1 -0
- package/templates/toggle-group/toggle-group.tsx +2 -0
- package/templates/toolbar/toolbar.tsx +6 -0
- package/templates/tooltip/tooltip.tsx +9 -3
- 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
|
@@ -17,6 +17,7 @@ export type ToastViewportProps = React.ComponentProps<
|
|
|
17
17
|
const ToastViewport = React.forwardRef<HTMLDivElement, ToastViewportProps>(
|
|
18
18
|
({ className, ...props }, ref) => (
|
|
19
19
|
<BaseToast.Viewport
|
|
20
|
+
data-slot="toast-viewport"
|
|
20
21
|
ref={ref}
|
|
21
22
|
className={cn(
|
|
22
23
|
"fixed z-10 top-auto right-4 bottom-4 mx-auto flex w-[250px] sm:right-8 sm:bottom-8 sm:w-[300px]",
|
|
@@ -100,6 +101,7 @@ export interface ToastProps
|
|
|
100
101
|
const ToastRoot = React.forwardRef<HTMLDivElement, ToastProps>(
|
|
101
102
|
({ className, variant, ...props }, ref) => (
|
|
102
103
|
<BaseToast.Root
|
|
104
|
+
data-slot="toast-root"
|
|
103
105
|
ref={ref}
|
|
104
106
|
className={cn(toastVariants({ variant }), className)}
|
|
105
107
|
{...props}
|
|
@@ -114,6 +116,7 @@ const ToastTitle = React.forwardRef<
|
|
|
114
116
|
React.ComponentProps<typeof BaseToast.Title>
|
|
115
117
|
>(({ className, ...props }, ref) => (
|
|
116
118
|
<BaseToast.Title
|
|
119
|
+
data-slot="toast-title"
|
|
117
120
|
ref={ref}
|
|
118
121
|
className={cn("text-[0.975rem] leading-5 font-medium", className)}
|
|
119
122
|
{...props}
|
|
@@ -127,6 +130,7 @@ const ToastDescription = React.forwardRef<
|
|
|
127
130
|
React.ComponentProps<typeof BaseToast.Description>
|
|
128
131
|
>(({ className, ...props }, ref) => (
|
|
129
132
|
<BaseToast.Description
|
|
133
|
+
data-slot="toast-description"
|
|
130
134
|
ref={ref}
|
|
131
135
|
className={cn("text-[0.925rem] leading-5 opacity-90", className)}
|
|
132
136
|
{...props}
|
|
@@ -142,6 +146,7 @@ const ToastContent = React.forwardRef<
|
|
|
142
146
|
React.ComponentProps<typeof BaseToast.Content>
|
|
143
147
|
>(({ className, ...props }, ref) => (
|
|
144
148
|
<BaseToast.Content
|
|
149
|
+
data-slot="toast-content"
|
|
145
150
|
ref={ref}
|
|
146
151
|
className={cn(
|
|
147
152
|
"flex items-start gap-3 overflow-hidden pr-6 transition-opacity [transition-duration:250ms]",
|
|
@@ -160,6 +165,7 @@ const ToastAction = React.forwardRef<
|
|
|
160
165
|
React.ComponentProps<typeof BaseToast.Action>
|
|
161
166
|
>(({ className, ...props }, ref) => (
|
|
162
167
|
<BaseToast.Action
|
|
168
|
+
data-slot="toast-action"
|
|
163
169
|
ref={ref}
|
|
164
170
|
className={cn(
|
|
165
171
|
"inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium transition-colors",
|
|
@@ -178,6 +184,7 @@ const ToastClose = React.forwardRef<
|
|
|
178
184
|
React.ComponentProps<typeof BaseToast.Close>
|
|
179
185
|
>(({ className, children, ...props }, ref) => (
|
|
180
186
|
<BaseToast.Close
|
|
187
|
+
data-slot="toast-close"
|
|
181
188
|
ref={ref}
|
|
182
189
|
aria-label="Close"
|
|
183
190
|
data-agent-dismiss=""
|
|
@@ -201,6 +208,7 @@ const ToastPositioner = React.forwardRef<
|
|
|
201
208
|
React.ComponentProps<typeof BaseToast.Positioner>
|
|
202
209
|
>(({ className, ...props }, ref) => (
|
|
203
210
|
<BaseToast.Positioner
|
|
211
|
+
data-slot="toast-positioner"
|
|
204
212
|
ref={ref}
|
|
205
213
|
className={cn("z-50", className)}
|
|
206
214
|
{...props}
|
|
@@ -214,6 +222,7 @@ const ToastArrow = React.forwardRef<
|
|
|
214
222
|
React.ComponentProps<typeof BaseToast.Arrow>
|
|
215
223
|
>(({ className, ...props }, ref) => (
|
|
216
224
|
<BaseToast.Arrow
|
|
225
|
+
data-slot="toast-arrow"
|
|
217
226
|
ref={ref}
|
|
218
227
|
className={cn(
|
|
219
228
|
"fill-background [stroke-width:1px] stroke-border",
|
|
@@ -315,7 +324,7 @@ const Toast = React.forwardRef<HTMLDivElement, ToastComponentProps>(
|
|
|
315
324
|
<ToastProvider limit={limit} timeout={timeout} toastManager={toastManager}>
|
|
316
325
|
{children}
|
|
317
326
|
<ToastPortal>
|
|
318
|
-
<ToastViewport ref={ref} className={className} {...props}>
|
|
327
|
+
<ToastViewport data-slot="toast" ref={ref} className={className} {...props}>
|
|
319
328
|
<ToastList renderToast={renderToast} />
|
|
320
329
|
</ToastViewport>
|
|
321
330
|
</ToastPortal>
|
|
@@ -110,6 +110,7 @@ const ToggleGroup = React.forwardRef<
|
|
|
110
110
|
<ToggleAgentContext.Provider value={useHasAgent() ? items : null}>
|
|
111
111
|
<ToggleGroupPrimitive
|
|
112
112
|
ref={mergedRef}
|
|
113
|
+
data-slot="toggle-group"
|
|
113
114
|
className={cn(
|
|
114
115
|
"inline-flex items-center justify-center gap-1",
|
|
115
116
|
"data-[orientation=vertical]:flex-col",
|
|
@@ -138,6 +139,7 @@ const ToggleGroupItem = React.forwardRef<
|
|
|
138
139
|
return (
|
|
139
140
|
<TogglePrimitive
|
|
140
141
|
ref={mergedRef}
|
|
142
|
+
data-slot="toggle-group-item"
|
|
141
143
|
data-agent-part={items ? "" : undefined}
|
|
142
144
|
className={cn(toggleGroupItemVariants({ variant, size }), className)}
|
|
143
145
|
{...props}
|
|
@@ -7,6 +7,7 @@ const ToolbarRoot = React.forwardRef<
|
|
|
7
7
|
React.ComponentProps<typeof BaseToolbar.Root>
|
|
8
8
|
>(({ className, ...props }, ref) => (
|
|
9
9
|
<BaseToolbar.Root
|
|
10
|
+
data-slot="toolbar"
|
|
10
11
|
ref={ref}
|
|
11
12
|
className={cn(
|
|
12
13
|
"flex flex-wrap items-center gap-1 rounded-md border bg-background p-1",
|
|
@@ -23,6 +24,7 @@ const ToolbarButton = React.forwardRef<
|
|
|
23
24
|
React.ComponentProps<typeof BaseToolbar.Button>
|
|
24
25
|
>(({ className, ...props }, ref) => (
|
|
25
26
|
<BaseToolbar.Button
|
|
27
|
+
data-slot="toolbar-button"
|
|
26
28
|
ref={ref}
|
|
27
29
|
className={cn(
|
|
28
30
|
"inline-flex shrink-0 items-center justify-center rounded-sm px-3 py-2 text-sm font-medium transition-colors",
|
|
@@ -42,6 +44,7 @@ const ToolbarLink = React.forwardRef<
|
|
|
42
44
|
React.ComponentProps<typeof BaseToolbar.Link>
|
|
43
45
|
>(({ className, ...props }, ref) => (
|
|
44
46
|
<BaseToolbar.Link
|
|
47
|
+
data-slot="toolbar-link"
|
|
45
48
|
ref={ref}
|
|
46
49
|
className={cn(
|
|
47
50
|
"inline-flex shrink-0 items-center justify-center rounded-sm px-3 py-2 text-sm font-medium transition-colors",
|
|
@@ -60,6 +63,7 @@ const ToolbarSeparator = React.forwardRef<
|
|
|
60
63
|
React.ComponentProps<typeof BaseToolbar.Separator>
|
|
61
64
|
>(({ className, orientation = "vertical", ...props }, ref) => (
|
|
62
65
|
<BaseToolbar.Separator
|
|
66
|
+
data-slot="toolbar-separator"
|
|
63
67
|
ref={ref}
|
|
64
68
|
orientation={orientation}
|
|
65
69
|
className={cn(
|
|
@@ -77,6 +81,7 @@ const ToolbarGroup = React.forwardRef<
|
|
|
77
81
|
React.ComponentProps<typeof BaseToolbar.Group>
|
|
78
82
|
>(({ className, ...props }, ref) => (
|
|
79
83
|
<BaseToolbar.Group
|
|
84
|
+
data-slot="toolbar-group"
|
|
80
85
|
ref={ref}
|
|
81
86
|
className={cn("flex shrink-0 items-center gap-1", className)}
|
|
82
87
|
{...props}
|
|
@@ -89,6 +94,7 @@ const ToolbarInput = React.forwardRef<
|
|
|
89
94
|
React.ComponentProps<typeof BaseToolbar.Input>
|
|
90
95
|
>(({ className, ...props }, ref) => (
|
|
91
96
|
<BaseToolbar.Input
|
|
97
|
+
data-slot="toolbar-input"
|
|
92
98
|
ref={ref}
|
|
93
99
|
className={cn(
|
|
94
100
|
"flex h-9 w-full rounded-md border border-input bg-transparent px-3 py-1 text-sm shadow-sm transition-colors",
|
|
@@ -15,12 +15,14 @@ const TooltipTrigger = React.forwardRef<
|
|
|
15
15
|
HTMLButtonElement,
|
|
16
16
|
React.ComponentProps<typeof BaseTooltip.Trigger>
|
|
17
17
|
>(({ className, ...props }, ref) => (
|
|
18
|
-
<BaseTooltip.Trigger ref={ref} className={className} {...props} />
|
|
18
|
+
<BaseTooltip.Trigger ref={ref} className={className} data-slot="tooltip-trigger" {...props} />
|
|
19
19
|
));
|
|
20
20
|
TooltipTrigger.displayName = "TooltipTrigger";
|
|
21
21
|
|
|
22
22
|
// Portal Component
|
|
23
|
-
|
|
23
|
+
function TooltipPortal(props: React.ComponentProps<typeof BaseTooltip.Portal>): React.JSX.Element {
|
|
24
|
+
return <BaseTooltip.Portal data-slot="tooltip-portal" {...props} />;
|
|
25
|
+
}
|
|
24
26
|
|
|
25
27
|
// Positioner Component
|
|
26
28
|
const TooltipPositioner: React.ForwardRefExoticComponent<
|
|
@@ -34,6 +36,7 @@ const TooltipPositioner: React.ForwardRefExoticComponent<
|
|
|
34
36
|
ref={ref}
|
|
35
37
|
sideOffset={sideOffset}
|
|
36
38
|
className={cn("z-50", className)}
|
|
39
|
+
data-slot="tooltip-positioner"
|
|
37
40
|
{...props}
|
|
38
41
|
/>
|
|
39
42
|
));
|
|
@@ -73,6 +76,7 @@ const TooltipPopup: React.ForwardRefExoticComponent<
|
|
|
73
76
|
variantStyles[variant],
|
|
74
77
|
className
|
|
75
78
|
)}
|
|
79
|
+
data-slot="tooltip-popup"
|
|
76
80
|
{...props}
|
|
77
81
|
/>
|
|
78
82
|
);
|
|
@@ -99,6 +103,7 @@ const TooltipArrow: React.ForwardRefExoticComponent<
|
|
|
99
103
|
"data-[side=top]:bottom-[-8px] data-[side=top]:rotate-180",
|
|
100
104
|
className
|
|
101
105
|
)}
|
|
106
|
+
data-slot="tooltip-arrow"
|
|
102
107
|
{...props}
|
|
103
108
|
>
|
|
104
109
|
{children || <TooltipArrowSvg variant={variant} />}
|
|
@@ -139,6 +144,7 @@ const TooltipContent: React.ForwardRefExoticComponent<
|
|
|
139
144
|
ref={ref}
|
|
140
145
|
className={className}
|
|
141
146
|
variant={variant}
|
|
147
|
+
data-slot="tooltip-content"
|
|
142
148
|
{...props}
|
|
143
149
|
>
|
|
144
150
|
{showArrow && <TooltipArrow variant={variant} />}
|
|
@@ -164,7 +170,7 @@ const TooltipArrowSvg: React.MemoExoticComponent<
|
|
|
164
170
|
variant === "inverse" ? "fill-primary" : "fill-border";
|
|
165
171
|
|
|
166
172
|
return (
|
|
167
|
-
<svg width="20" height="10" viewBox="0 0 20 10" fill="none" {...props}>
|
|
173
|
+
<svg width="20" height="10" viewBox="0 0 20 10" fill="none" data-slot="tooltip-arrow-svg" {...props}>
|
|
168
174
|
<path
|
|
169
175
|
d="M9.66437 2.60207L4.80758 6.97318C4.07308 7.63423 3.11989 8 2.13172 8H0V10H20V8H18.5349C17.5468 8 16.5936 7.63423 15.8591 6.97318L11.0023 2.60207C10.622 2.2598 10.0447 2.25979 9.66437 2.60207Z"
|
|
170
176
|
className={fillClasses}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { WeekStrip, type WeekStripProps } from "./week-strip";
|
|
@@ -0,0 +1,329 @@
|
|
|
1
|
+
"use client"
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { format, type Locale } from "date-fns";
|
|
5
|
+
import { ChevronLeft, ChevronRight } from "lucide-react";
|
|
6
|
+
import { cn } from "@/lib/utils";
|
|
7
|
+
import { changeAsAgent, useAgentControl, useAgentState, useHasAgent } from "@/components/ui/agent";
|
|
8
|
+
import {
|
|
9
|
+
type CalendarChangeDetails,
|
|
10
|
+
addDays,
|
|
11
|
+
dayFirst,
|
|
12
|
+
daysBetween,
|
|
13
|
+
fromISODate,
|
|
14
|
+
isSameDay,
|
|
15
|
+
parseDate,
|
|
16
|
+
startOfDay,
|
|
17
|
+
toISODate,
|
|
18
|
+
} from "@/components/ui/calendar";
|
|
19
|
+
|
|
20
|
+
function changeDetails(reason: string, event?: Event): CalendarChangeDetails {
|
|
21
|
+
const details: CalendarChangeDetails = {
|
|
22
|
+
reason,
|
|
23
|
+
event,
|
|
24
|
+
isCanceled: false,
|
|
25
|
+
cancel() {
|
|
26
|
+
details.isCanceled = true;
|
|
27
|
+
},
|
|
28
|
+
};
|
|
29
|
+
return details;
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
const reducedMotion = () => typeof window !== "undefined" && window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
|
|
33
|
+
|
|
34
|
+
const startOfWeek = (d: Date, weekStartsOn: number) => addDays(d, -((d.getDay() - weekStartsOn + 7) % 7));
|
|
35
|
+
|
|
36
|
+
/** Weeks rendered either side of the selected one. */
|
|
37
|
+
const SPAN = 8;
|
|
38
|
+
|
|
39
|
+
const events = (n: number) => `${n} ${n === 1 ? "event" : "events"}`;
|
|
40
|
+
|
|
41
|
+
export interface WeekStripProps
|
|
42
|
+
extends Omit<React.HTMLAttributes<HTMLDivElement>, "defaultValue" | "onChange" | "dir"> {
|
|
43
|
+
/** The selected day. Defaults to today. */
|
|
44
|
+
value?: Date;
|
|
45
|
+
defaultValue?: Date;
|
|
46
|
+
onValueChange?: (value: Date, details: CalendarChangeDetails) => void;
|
|
47
|
+
/** The first day in the strip. Defaults to the start of last week. */
|
|
48
|
+
min?: Date;
|
|
49
|
+
/** The last day in the strip. Defaults to the end of the third week ahead. */
|
|
50
|
+
max?: Date;
|
|
51
|
+
/** How busy each day is, keyed YYYY-MM-DD. Up to three dots show under the date. */
|
|
52
|
+
counts?: Record<string, number>;
|
|
53
|
+
/** Counts at or above each step get one more dot. Defaults to one dot per count, up to three. */
|
|
54
|
+
thresholds?: [number, number, number];
|
|
55
|
+
/** How a day's count reads to screen readers. Defaults to `2 events`. */
|
|
56
|
+
formatCount?: (count: number) => string;
|
|
57
|
+
/** A date-fns locale, for day names and the first day of the week. */
|
|
58
|
+
locale?: Locale;
|
|
59
|
+
weekStartsOn?: 0 | 1 | 2 | 3 | 4 | 5 | 6;
|
|
60
|
+
dir?: "ltr" | "rtl";
|
|
61
|
+
/** Defaults to the current day. */
|
|
62
|
+
today?: Date;
|
|
63
|
+
disabled?: boolean;
|
|
64
|
+
/** Submits the day as YYYY-MM-DD. */
|
|
65
|
+
name?: string;
|
|
66
|
+
/** What the content under the strip shows for the selected day. */
|
|
67
|
+
children?: React.ReactNode;
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Days in a row that snaps a week at a time, for schedules and bookings where the week
|
|
72
|
+
* matters more than the month. The content under it follows the selected day.
|
|
73
|
+
*/
|
|
74
|
+
const WeekStrip = React.forwardRef<HTMLDivElement, WeekStripProps>((props, ref) => {
|
|
75
|
+
const {
|
|
76
|
+
value: valueProp,
|
|
77
|
+
defaultValue,
|
|
78
|
+
onValueChange,
|
|
79
|
+
min: minProp,
|
|
80
|
+
max: maxProp,
|
|
81
|
+
counts,
|
|
82
|
+
thresholds,
|
|
83
|
+
formatCount = events,
|
|
84
|
+
locale,
|
|
85
|
+
weekStartsOn = locale?.options?.weekStartsOn ?? 1,
|
|
86
|
+
dir,
|
|
87
|
+
today: todayProp,
|
|
88
|
+
disabled,
|
|
89
|
+
name,
|
|
90
|
+
className,
|
|
91
|
+
children,
|
|
92
|
+
"aria-label": ariaLabel = "Day",
|
|
93
|
+
"aria-labelledby": labelledBy,
|
|
94
|
+
...rest
|
|
95
|
+
} = props;
|
|
96
|
+
const hasAgent = useHasAgent();
|
|
97
|
+
const today = React.useMemo(() => startOfDay(todayProp ?? new Date()), [todayProp ? toISODate(todayProp) : null]);
|
|
98
|
+
const thisWeek = startOfWeek(today, weekStartsOn);
|
|
99
|
+
const min = startOfDay(minProp ?? addDays(thisWeek, -7));
|
|
100
|
+
const max = startOfDay(maxProp ?? addDays(thisWeek, 27));
|
|
101
|
+
const clamp = (d: Date) => (d < min ? min : d > max ? max : d);
|
|
102
|
+
|
|
103
|
+
const [raw, change] = useAgentState<Date, CalendarChangeDetails>(valueProp, defaultValue ?? clamp(today), onValueChange);
|
|
104
|
+
const value = startOfDay(raw);
|
|
105
|
+
// A value off the strip still leaves a day to tab to and step from.
|
|
106
|
+
const stop = clamp(value);
|
|
107
|
+
const strip = React.useRef<HTMLDivElement>(null);
|
|
108
|
+
|
|
109
|
+
/* ---- only the weeks around the stop render, and more as the strip scrolls ---- */
|
|
110
|
+
const around = startOfWeek(stop, weekStartsOn);
|
|
111
|
+
const near = { from: clamp(addDays(around, -7 * SPAN)), to: clamp(addDays(around, 7 * SPAN + 6)) };
|
|
112
|
+
const [shown, setShown] = React.useState(() => ({ from: toISODate(near.from), to: toISODate(near.to) }));
|
|
113
|
+
let from = fromISODate(shown.from)!;
|
|
114
|
+
let to = fromISODate(shown.to)!;
|
|
115
|
+
if (from < min || to > max || near.from < from || near.to > to) {
|
|
116
|
+
const joined = near.from <= addDays(to, 1) && near.to >= addDays(from, -1);
|
|
117
|
+
from = clamp(joined && from < near.from ? from : near.from);
|
|
118
|
+
to = clamp(joined && to > near.to ? to : near.to);
|
|
119
|
+
setShown({ from: toISODate(from), to: toISODate(to) });
|
|
120
|
+
}
|
|
121
|
+
const days = Array.from({ length: daysBetween(from, to) + 1 }, (_, i) => addDays(from, i));
|
|
122
|
+
const widthBefore = React.useRef<number | null>(null);
|
|
123
|
+
const grow = () => {
|
|
124
|
+
const sc = strip.current;
|
|
125
|
+
const pills = sc?.querySelectorAll<HTMLElement>("[data-day]");
|
|
126
|
+
if (!sc || !pills?.length) return;
|
|
127
|
+
const rtl = getComputedStyle(sc).direction === "rtl";
|
|
128
|
+
const box = sc.getBoundingClientRect();
|
|
129
|
+
const head = pills[0].getBoundingClientRect();
|
|
130
|
+
const tail = pills[pills.length - 1].getBoundingClientRect();
|
|
131
|
+
const before = rtl ? head.right - box.right : box.left - head.left;
|
|
132
|
+
const after = rtl ? box.left - tail.left : tail.right - box.right;
|
|
133
|
+
if (before < box.width && from > min) {
|
|
134
|
+
widthBefore.current = sc.scrollWidth;
|
|
135
|
+
setShown((s) => ({ ...s, from: toISODate(clamp(addDays(fromISODate(s.from)!, -7 * SPAN))) }));
|
|
136
|
+
} else if (after < box.width && to < max) {
|
|
137
|
+
setShown((s) => ({ ...s, to: toISODate(clamp(addDays(fromISODate(s.to)!, 7 * SPAN))) }));
|
|
138
|
+
}
|
|
139
|
+
};
|
|
140
|
+
// Days added before the ones in view push them along; scrolling back by as much keeps them still.
|
|
141
|
+
React.useLayoutEffect(() => {
|
|
142
|
+
const sc = strip.current;
|
|
143
|
+
if (!sc || widthBefore.current === null) return;
|
|
144
|
+
const added = sc.scrollWidth - widthBefore.current;
|
|
145
|
+
widthBefore.current = null;
|
|
146
|
+
sc.scrollLeft += getComputedStyle(sc).direction === "rtl" ? -added : added;
|
|
147
|
+
}, [shown.from]);
|
|
148
|
+
|
|
149
|
+
const select = (d: Date, reason: string, event?: Event) => {
|
|
150
|
+
if (disabled || d < min || d > max || isSameDay(d, value)) return;
|
|
151
|
+
change(d, changeDetails(reason, event));
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
/* ---- the selected day's week stays in view ---- */
|
|
155
|
+
// The day a key or Today asked for, focused once it is the value.
|
|
156
|
+
const focusNext = React.useRef<string | null>(null);
|
|
157
|
+
const first = React.useRef(true);
|
|
158
|
+
React.useLayoutEffect(() => {
|
|
159
|
+
const sc = strip.current;
|
|
160
|
+
const pill = sc?.querySelector<HTMLElement>(`[data-day="${toISODate(stop)}"]`);
|
|
161
|
+
const start = sc?.querySelector<HTMLElement>(`[data-day="${toISODate(clamp(startOfWeek(stop, weekStartsOn)))}"]`);
|
|
162
|
+
if (!sc || !pill) return;
|
|
163
|
+
if (start) {
|
|
164
|
+
// Scrolls the strip only; scrollIntoView would move the page too.
|
|
165
|
+
const box = sc.getBoundingClientRect();
|
|
166
|
+
const at = start.getBoundingClientRect();
|
|
167
|
+
const pad = parseFloat(getComputedStyle(sc).scrollPaddingInlineStart) || 0;
|
|
168
|
+
const rtl = getComputedStyle(sc).direction === "rtl";
|
|
169
|
+
const delta = rtl ? at.right - box.right + pad : at.left - box.left - pad;
|
|
170
|
+
sc.scrollTo?.({ left: sc.scrollLeft + delta, behavior: first.current || reducedMotion() ? "auto" : "smooth" });
|
|
171
|
+
}
|
|
172
|
+
first.current = false;
|
|
173
|
+
if (focusNext.current === toISODate(value)) pill.focus({ preventScroll: true });
|
|
174
|
+
focusNext.current = null;
|
|
175
|
+
}, [toISODate(value)]);
|
|
176
|
+
|
|
177
|
+
/* ---- agent ---- */
|
|
178
|
+
useAgentControl(() => ({
|
|
179
|
+
kind: "date",
|
|
180
|
+
element: strip.current,
|
|
181
|
+
value: toISODate(value),
|
|
182
|
+
disabled,
|
|
183
|
+
actions: {
|
|
184
|
+
setValue: (wanted: unknown) => {
|
|
185
|
+
const d =
|
|
186
|
+
wanted instanceof Date
|
|
187
|
+
? isNaN(wanted.getTime()) ? null : startOfDay(wanted)
|
|
188
|
+
: typeof wanted === "string"
|
|
189
|
+
? fromISODate(wanted) ?? parseDate(wanted, { today, order: dayFirst(locale) ? "day-first" : "month-first", weekStartsOn })
|
|
190
|
+
: null;
|
|
191
|
+
if (!d) return `"${String(wanted)}" is not a date. Send YYYY-MM-DD, or a phrase such as next fri.`;
|
|
192
|
+
if (d < min) return `The strip starts on ${toISODate(min)}.`;
|
|
193
|
+
if (d > max) return `The strip ends on ${toISODate(max)}.`;
|
|
194
|
+
return changeAsAgent((next: Date, details: CalendarChangeDetails) => {
|
|
195
|
+
if (!isSameDay(next, value)) change(next, details);
|
|
196
|
+
}, d);
|
|
197
|
+
},
|
|
198
|
+
},
|
|
199
|
+
}));
|
|
200
|
+
|
|
201
|
+
/* ---- render ---- */
|
|
202
|
+
const isToday = isSameDay(value, today);
|
|
203
|
+
const week = (n: -1 | 1) => clamp(addDays(stop, 7 * n));
|
|
204
|
+
const otherYear = (d: Date) => d.getFullYear() !== today.getFullYear();
|
|
205
|
+
const iconButton = "inline-flex size-8 items-center justify-center rounded-md text-muted-foreground hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-40";
|
|
206
|
+
|
|
207
|
+
return (
|
|
208
|
+
<div {...rest} ref={ref} dir={dir} data-slot="week-strip" data-disabled={disabled || undefined} className={cn("w-full", className)}>
|
|
209
|
+
<div data-slot="week-strip-header" className="flex items-center gap-2 px-[1.125rem] pb-3">
|
|
210
|
+
<div
|
|
211
|
+
data-slot="week-strip-title"
|
|
212
|
+
aria-live="polite"
|
|
213
|
+
className="min-w-0 flex-1 truncate text-[1.625rem] font-semibold tracking-[-0.02em] md:text-[0.9375rem] md:tracking-normal"
|
|
214
|
+
>
|
|
215
|
+
{/* A phone's title is the screen's own, so it is short and says Today when it is. */}
|
|
216
|
+
<span className="md:hidden">{isToday ? "Today" : format(value, otherYear(value) ? "EEE d MMM yyyy" : "EEE d MMM", { locale })}</span>
|
|
217
|
+
<span className="max-md:hidden">{format(value, otherYear(value) ? "EEEE d MMMM yyyy" : "EEEE d MMMM", { locale })}</span>
|
|
218
|
+
</div>
|
|
219
|
+
{!isToday && today >= min && today <= max && (
|
|
220
|
+
<button
|
|
221
|
+
type="button"
|
|
222
|
+
data-slot="week-strip-today"
|
|
223
|
+
data-agent-part={hasAgent ? "" : undefined}
|
|
224
|
+
disabled={disabled}
|
|
225
|
+
onClick={(e) => {
|
|
226
|
+
focusNext.current = toISODate(today);
|
|
227
|
+
select(today, "today-press", e.nativeEvent);
|
|
228
|
+
}}
|
|
229
|
+
className="inline-flex h-8 items-center rounded-md px-3 text-sm font-medium hover:bg-accent hover:text-accent-foreground focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring disabled:pointer-events-none disabled:opacity-50"
|
|
230
|
+
>
|
|
231
|
+
Today
|
|
232
|
+
</button>
|
|
233
|
+
)}
|
|
234
|
+
{([-1, 1] as const).map((n) => (
|
|
235
|
+
<button
|
|
236
|
+
key={n}
|
|
237
|
+
type="button"
|
|
238
|
+
aria-label={n < 0 ? "Previous week" : "Next week"}
|
|
239
|
+
data-slot={n < 0 ? "week-strip-previous" : "week-strip-next"}
|
|
240
|
+
data-agent-part={hasAgent ? "" : undefined}
|
|
241
|
+
disabled={disabled || isSameDay(week(n), stop)}
|
|
242
|
+
onClick={(e) => select(week(n), "week-step", e.nativeEvent)}
|
|
243
|
+
className={iconButton}
|
|
244
|
+
>
|
|
245
|
+
{n < 0 ? <ChevronLeft className="size-4 rtl:rotate-180" aria-hidden /> : <ChevronRight className="size-4 rtl:rotate-180" aria-hidden />}
|
|
246
|
+
</button>
|
|
247
|
+
))}
|
|
248
|
+
</div>
|
|
249
|
+
<div
|
|
250
|
+
ref={strip}
|
|
251
|
+
role="listbox"
|
|
252
|
+
aria-orientation="horizontal"
|
|
253
|
+
aria-label={ariaLabel}
|
|
254
|
+
aria-labelledby={labelledBy}
|
|
255
|
+
aria-disabled={disabled || undefined}
|
|
256
|
+
data-slot="week-strip-days"
|
|
257
|
+
className={cn(
|
|
258
|
+
"flex snap-x snap-mandatory scroll-px-[1.125rem] gap-1.5 overflow-x-auto px-[1.125rem] pb-2.5 pt-1 [scrollbar-width:none] [&::-webkit-scrollbar]:hidden",
|
|
259
|
+
// The clipped day fades, so it reads as more to scroll rather than a cut.
|
|
260
|
+
"[mask-image:linear-gradient(to_right,transparent,#000_14px,#000_calc(100%-32px),transparent)]",
|
|
261
|
+
"rtl:[mask-image:linear-gradient(to_left,transparent,#000_14px,#000_calc(100%-32px),transparent)]"
|
|
262
|
+
)}
|
|
263
|
+
onScroll={grow}
|
|
264
|
+
onKeyDown={(e) => {
|
|
265
|
+
const rtl = strip.current?.closest("[dir]")?.getAttribute("dir") === "rtl";
|
|
266
|
+
const step: Record<string, number> = { ArrowLeft: rtl ? 1 : -1, ArrowRight: rtl ? -1 : 1 };
|
|
267
|
+
const next =
|
|
268
|
+
e.key === "Home" ? clamp(today)
|
|
269
|
+
: e.key === "End" ? max
|
|
270
|
+
: e.key === "PageUp" ? week(-1)
|
|
271
|
+
: e.key === "PageDown" ? week(1)
|
|
272
|
+
: step[e.key] !== undefined ? addDays(stop, step[e.key])
|
|
273
|
+
: null;
|
|
274
|
+
if (!next) return;
|
|
275
|
+
e.preventDefault();
|
|
276
|
+
if (next < min || next > max) return;
|
|
277
|
+
focusNext.current = toISODate(next);
|
|
278
|
+
select(next, "keyboard", e.nativeEvent);
|
|
279
|
+
}}
|
|
280
|
+
>
|
|
281
|
+
{days.map((d) => {
|
|
282
|
+
const n = counts?.[toISODate(d)] ?? 0;
|
|
283
|
+
const dots = n <= 0 ? 0 : thresholds ? thresholds.filter((t) => n >= t).length : Math.min(n, 3);
|
|
284
|
+
const selected = isSameDay(d, value);
|
|
285
|
+
return (
|
|
286
|
+
<button
|
|
287
|
+
key={toISODate(d)}
|
|
288
|
+
type="button"
|
|
289
|
+
role="option"
|
|
290
|
+
data-slot="week-strip-day"
|
|
291
|
+
data-day={toISODate(d)}
|
|
292
|
+
data-today={isSameDay(d, today) || undefined}
|
|
293
|
+
aria-selected={selected}
|
|
294
|
+
aria-label={`${format(d, otherYear(d) ? "EEEE d MMMM yyyy" : "EEEE d MMMM", { locale })}${counts ? `, ${formatCount(n)}` : ""}`}
|
|
295
|
+
tabIndex={isSameDay(d, stop) ? 0 : -1}
|
|
296
|
+
disabled={disabled}
|
|
297
|
+
onClick={(e) => select(d, "day-press", e.nativeEvent)}
|
|
298
|
+
className={cn(
|
|
299
|
+
"grid w-[2.625rem] shrink-0 snap-start justify-items-center gap-[3px] rounded-[0.875rem] border border-transparent pb-[9px] pt-2 md:w-16",
|
|
300
|
+
"transition-colors duration-150 motion-reduce:transition-none hover:bg-accent",
|
|
301
|
+
"focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",
|
|
302
|
+
"data-[today]:border-muted-foreground",
|
|
303
|
+
"aria-selected:bg-primary aria-selected:text-primary-foreground aria-selected:hover:bg-primary",
|
|
304
|
+
"disabled:pointer-events-none disabled:opacity-50",
|
|
305
|
+
// A gap between weeks shows where each starts.
|
|
306
|
+
d.getDay() === weekStartsOn && !isSameDay(d, from) && "ms-2.5"
|
|
307
|
+
)}
|
|
308
|
+
>
|
|
309
|
+
<span className={cn("text-[0.6875rem] uppercase tracking-[0.04em] text-muted-foreground", selected && "text-current opacity-70")}>
|
|
310
|
+
{format(d, "EEE", { locale })}
|
|
311
|
+
</span>
|
|
312
|
+
<span className="text-[1.0625rem] font-medium tabular-nums md:text-lg">{d.getDate()}</span>
|
|
313
|
+
<span aria-hidden className="flex h-1 gap-[3px]">
|
|
314
|
+
{Array.from({ length: dots }, (_, i) => (
|
|
315
|
+
<i key={i} className={cn("size-1 rounded-full bg-muted-foreground", selected && "bg-primary-foreground")} />
|
|
316
|
+
))}
|
|
317
|
+
</span>
|
|
318
|
+
</button>
|
|
319
|
+
);
|
|
320
|
+
})}
|
|
321
|
+
</div>
|
|
322
|
+
{children}
|
|
323
|
+
{name && <input type="hidden" name={name} disabled={disabled} value={toISODate(value)} />}
|
|
324
|
+
</div>
|
|
325
|
+
);
|
|
326
|
+
});
|
|
327
|
+
WeekStrip.displayName = "WeekStrip";
|
|
328
|
+
|
|
329
|
+
export { WeekStrip };
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export { YearView, type YearViewProps } from "./year-view";
|