@moltenship/calendar 1.0.0-rc.1 → 2.0.0-beta.1
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/README.md +24 -4
- package/dist/index.d.mts +2 -2
- package/docs/accessibility.md +304 -0
- package/docs/agents/changes.md +449 -0
- package/docs/agents/coding-agents.md +117 -0
- package/docs/agents/connect.md +435 -0
- package/docs/agents/deleting.md +296 -0
- package/docs/agents/reference.md +512 -0
- package/docs/agents/server.md +317 -0
- package/docs/agents/webmcp.md +153 -0
- package/docs/agents.md +353 -0
- package/docs/annotations.md +196 -0
- package/docs/api/changes.md +248 -0
- package/docs/api/dnd-kit.md +267 -0
- package/docs/api/events.md +152 -0
- package/docs/api/ics.md +524 -0
- package/docs/api/primitives.md +168 -0
- package/docs/api/react.md +236 -0
- package/docs/api/recurrence.md +586 -0
- package/docs/api/solid.md +460 -0
- package/docs/api/store.md +92 -0
- package/docs/api/temporal.md +172 -0
- package/docs/api.md +57 -0
- package/docs/availability.md +573 -0
- package/docs/comparison.md +279 -0
- package/docs/concepts/anatomy.md +73 -0
- package/docs/concepts/events.md +164 -0
- package/docs/concepts/how-it-works.md +95 -0
- package/docs/concepts/recurrence.md +127 -0
- package/docs/concepts/state.md +244 -0
- package/docs/concepts/time.md +170 -0
- package/docs/guides/dnd-kit.md +333 -0
- package/docs/guides/google-calendar-sync.md +1246 -0
- package/docs/guides/google-calendar.md +367 -0
- package/docs/guides/ics.md +486 -0
- package/docs/guides/motion.md +414 -0
- package/docs/guides/nextjs-app-router.md +630 -0
- package/docs/guides/nextjs.md +149 -0
- package/docs/guides/performance.md +103 -0
- package/docs/guides/recurring-events.md +583 -0
- package/docs/guides/tanstack-query.md +485 -0
- package/docs/index.md +118 -0
- package/docs/installation.md +194 -0
- package/docs/interactions.md +408 -0
- package/docs/llms.txt +86 -0
- package/docs/migrating-to-2.md +322 -0
- package/docs/quick-start.md +159 -0
- package/docs/stylex.md +265 -0
- package/docs/testing.md +581 -0
- package/docs/theme-builder.md +81 -0
- package/docs/theming.md +169 -0
- package/docs/undo-redo.md +339 -0
- package/docs/views/agenda.md +221 -0
- package/docs/views/custom-views.md +192 -0
- package/docs/views/month.md +109 -0
- package/docs/views/resource-columns.md +261 -0
- package/docs/views/resource-timeline.md +225 -0
- package/docs/views/scrolling.md +192 -0
- package/docs/views/week-and-day.md +257 -0
- package/docs/views/year.md +138 -0
- package/docs/views.md +69 -0
- package/package.json +41 -14
- package/skills/moltenship-time/SKILL.md +75 -0
- package/skills/moltenship-time/references/agent-ready.md +272 -0
- package/skills/moltenship-time/references/changes.md +188 -0
- package/skills/moltenship-time/references/compose.md +168 -0
- package/skills/moltenship-time/references/mistakes.md +98 -0
- package/skills/moltenship-time/references/solid.md +202 -0
- package/skills/moltenship-time/references/state.md +129 -0
- package/skills/moltenship-time/references/testing.md +176 -0
|
@@ -0,0 +1,414 @@
|
|
|
1
|
+
# Animate with Motion
|
|
2
|
+
|
|
3
|
+
Grow a clicked meeting into its card and let a card follow each drag, with Motion and the calendar's own hooks.
|
|
4
|
+
|
|
5
|
+
Source: https://time.molten.sh/docs/guides/motion
|
|
6
|
+
|
|
7
|
+
> Live example: see it at https://time.molten.sh/docs/guides/motion
|
|
8
|
+
|
|
9
|
+
Click a meeting: its chip grows into a card, and its title flies into the card's heading. Close
|
|
10
|
+
the card and it shrinks back into the meeting. Drag a meeting: a copy of it trails the pointer on a
|
|
11
|
+
spring, tilting with its speed, shows the time it would land at, and settles into the slot when
|
|
12
|
+
you let go, or flies back after Escape.
|
|
13
|
+
|
|
14
|
+
The calendar doesn't animate any of this itself. [Motion](https://motion.dev) does, through hooks
|
|
15
|
+
the calendar keeps for it:
|
|
16
|
+
|
|
17
|
+
- Every event is a `[data-event-id]` button, and its title is marked
|
|
18
|
+
`data-slot="calendar-event-title"` in every view, so a transition can find both.
|
|
19
|
+
- `monitorCalendarDrags` tells a follower where the pointer is, what the preview shows, and where
|
|
20
|
+
the drop landed.
|
|
21
|
+
|
|
22
|
+
You don't edit the calendar's code, and the calendar's packages don't depend on Motion.
|
|
23
|
+
|
|
24
|
+
## Install
|
|
25
|
+
|
|
26
|
+
**pnpm**
|
|
27
|
+
|
|
28
|
+
```bash
|
|
29
|
+
pnpm add motion
|
|
30
|
+
```
|
|
31
|
+
|
|
32
|
+
**npm**
|
|
33
|
+
|
|
34
|
+
```bash
|
|
35
|
+
npm install motion
|
|
36
|
+
```
|
|
37
|
+
|
|
38
|
+
**yarn**
|
|
39
|
+
|
|
40
|
+
```bash
|
|
41
|
+
yarn add motion
|
|
42
|
+
```
|
|
43
|
+
|
|
44
|
+
**bun**
|
|
45
|
+
|
|
46
|
+
```bash
|
|
47
|
+
bun add motion
|
|
48
|
+
```
|
|
49
|
+
|
|
50
|
+
## A meeting grows into its card
|
|
51
|
+
|
|
52
|
+
Motion's [`animateView`](https://motion.dev/docs/animate-view) runs a state update inside a view
|
|
53
|
+
transition, and `.add(from, to)` morphs one element into another. `grow` morphs the clicked chip
|
|
54
|
+
into the card and the chip's title into the card's heading, and `shrink` morphs them back:
|
|
55
|
+
|
|
56
|
+
```tsx title="motion-calendar.tsx"
|
|
57
|
+
// Settles in about half a second.
|
|
58
|
+
const spring = { bounce: 0.1, type: "spring", visualDuration: 0.3 } as const;
|
|
59
|
+
const reducedMotion = () => matchMedia("(prefers-reduced-motion: reduce)").matches;
|
|
60
|
+
|
|
61
|
+
const chipTitle = '[data-slot="calendar-event-title"]';
|
|
62
|
+
const card = '[data-slot="meeting-card"]';
|
|
63
|
+
const cardTitle = '[data-slot="meeting-card-title"]';
|
|
64
|
+
|
|
65
|
+
/** An element on the page now, and what it becomes: an element, or a selector found after. */
|
|
66
|
+
type Pair = readonly [from: Element | null, to: Element | string | null];
|
|
67
|
+
|
|
68
|
+
/**
|
|
69
|
+
* Runs `update` in a view transition that morphs a box into another, on a spring, and a title
|
|
70
|
+
* into another. What's inside the box swaps at `swapAt` seconds, while it's small, so neither
|
|
71
|
+
* side's contents stretch. Under reduced motion, or in a browser without view transitions, it
|
|
72
|
+
* only runs `update`.
|
|
73
|
+
*/
|
|
74
|
+
function morph(update: () => void, [box, title]: readonly [Pair, Pair], swapAt: number) {
|
|
75
|
+
if (reducedMotion()) return update();
|
|
76
|
+
const view = animateView(
|
|
77
|
+
async () => {
|
|
78
|
+
flushSync(update);
|
|
79
|
+
// Base UI places a popover a task after it mounts.
|
|
80
|
+
await new Promise((resolve) => setTimeout(resolve));
|
|
81
|
+
},
|
|
82
|
+
// A new morph, such as opening again right after Escape, cuts the last one short. Start one
|
|
83
|
+
// per event: Motion runs morphs started in the same task as one, without the wait above.
|
|
84
|
+
{ interrupt: "immediate" },
|
|
85
|
+
);
|
|
86
|
+
const swap = { delay: swapAt, duration: 0.15 };
|
|
87
|
+
if (box[0] !== null && box[1] !== null) {
|
|
88
|
+
view
|
|
89
|
+
.add(box[0], box[1])
|
|
90
|
+
.layout(spring)
|
|
91
|
+
.old({ opacity: [1, 0] }, swap)
|
|
92
|
+
.new({ opacity: [0, 1] }, swap);
|
|
93
|
+
}
|
|
94
|
+
if (title[0] !== null && title[1] !== null) {
|
|
95
|
+
// Uncropped, with `.morph-text` in your CSS, so each side of the text keeps its size.
|
|
96
|
+
view.add(title[0], title[1]).crop(false).class("morph-text").layout(spring);
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
/** The meeting's chip grows into the card, and its title into the card's heading. */
|
|
101
|
+
function grow(chip: Element, update: () => void) {
|
|
102
|
+
morph(
|
|
103
|
+
update,
|
|
104
|
+
[
|
|
105
|
+
[chip, card],
|
|
106
|
+
[chip.querySelector(chipTitle), cardTitle],
|
|
107
|
+
],
|
|
108
|
+
0,
|
|
109
|
+
);
|
|
110
|
+
}
|
|
111
|
+
|
|
112
|
+
/** The card shrinks back into the chip, and swaps back once it's small. */
|
|
113
|
+
function shrink(chip: Element, update: () => void) {
|
|
114
|
+
const popup = document.querySelector(card);
|
|
115
|
+
morph(
|
|
116
|
+
update,
|
|
117
|
+
[
|
|
118
|
+
[popup, chip],
|
|
119
|
+
[popup?.querySelector(cardTitle) ?? null, chip.querySelector(chipTitle)],
|
|
120
|
+
],
|
|
121
|
+
0.2,
|
|
122
|
+
);
|
|
123
|
+
}
|
|
124
|
+
```
|
|
125
|
+
|
|
126
|
+
- The update runs in `flushSync`, so React has rendered the card when the browser captures the new
|
|
127
|
+
state, and then waits a task, because Base UI places a popover just after it mounts.
|
|
128
|
+
- The box grows on a spring while what's inside it swaps with a short fade: early when it opens,
|
|
129
|
+
late when it closes, so neither the chip's text nor the card's is ever stretched.
|
|
130
|
+
- In a browser without view transitions, `animateView` only runs the update, and the card opens
|
|
131
|
+
at once.
|
|
132
|
+
|
|
133
|
+
A view transition draws each side of a morph as a picture stretched to the moving box. That suits
|
|
134
|
+
the card, whose insides swap while it's small, but would blow the title's text up as its box
|
|
135
|
+
widens. The title's morph gets the class `morph-text`, and one rule in your CSS keeps each side of
|
|
136
|
+
it at its own size:
|
|
137
|
+
|
|
138
|
+
```css title="app.css"
|
|
139
|
+
::view-transition-old(.morph-text),
|
|
140
|
+
::view-transition-new(.morph-text) {
|
|
141
|
+
width: auto;
|
|
142
|
+
height: auto;
|
|
143
|
+
}
|
|
144
|
+
```
|
|
145
|
+
|
|
146
|
+
The card is an ordinary Base UI popover. Its `data-slot`s are what `grow` looks for, and closing it
|
|
147
|
+
calls `shrink`:
|
|
148
|
+
|
|
149
|
+
```tsx title="motion-calendar.tsx"
|
|
150
|
+
interface Opened {
|
|
151
|
+
readonly anchor: HTMLElement;
|
|
152
|
+
readonly meeting: Meeting;
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
function MeetingCard({ onClose, opened }: { opened: Opened | null; onClose: () => void }) {
|
|
156
|
+
const close = () => {
|
|
157
|
+
if (opened !== null) shrink(opened.anchor, onClose);
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
return (
|
|
161
|
+
<Popover.Root open={opened !== null} onOpenChange={(open) => !open && close()}>
|
|
162
|
+
{opened !== null && (
|
|
163
|
+
<Popover.Portal>
|
|
164
|
+
<Popover.Positioner anchor={opened.anchor} align="start" sideOffset={6}>
|
|
165
|
+
<Popover.Popup
|
|
166
|
+
// Escape or a click outside returns focus to the meeting it opened from.
|
|
167
|
+
finalFocus={() => opened.anchor}
|
|
168
|
+
data-slot="meeting-card"
|
|
169
|
+
data-color={opened.meeting.color}
|
|
170
|
+
className="flex w-72 flex-col gap-1 rounded-xl border-s-4 border-calendar-event-border bg-calendar-event p-4 text-calendar-event-foreground shadow-xl outline-none"
|
|
171
|
+
>
|
|
172
|
+
<Popover.Title data-slot="meeting-card-title" className="text-lg font-semibold">
|
|
173
|
+
{opened.meeting.title}
|
|
174
|
+
</Popover.Title>
|
|
175
|
+
<p className="text-sm opacity-80">{formatWhen(opened.meeting)}</p>
|
|
176
|
+
<Button className="mt-2 self-end" onClick={close} size="sm" variant="secondary">
|
|
177
|
+
Close
|
|
178
|
+
</Button>
|
|
179
|
+
</Popover.Popup>
|
|
180
|
+
</Popover.Positioner>
|
|
181
|
+
</Popover.Portal>
|
|
182
|
+
)}
|
|
183
|
+
</Popover.Root>
|
|
184
|
+
);
|
|
185
|
+
}
|
|
186
|
+
```
|
|
187
|
+
|
|
188
|
+
Open the card from a click on the viewport. Every view renders events as `[data-event-id]`
|
|
189
|
+
buttons, so one listener opens any of them, and `eventIdOf` reads the meeting's ID:
|
|
190
|
+
|
|
191
|
+
```tsx title="motion-calendar.tsx"
|
|
192
|
+
type MeetingChange = CalendarEventChange<Meeting, string, never>;
|
|
193
|
+
|
|
194
|
+
function moveMeeting(meetings: readonly Meeting[], change: MeetingChange): readonly Meeting[] {
|
|
195
|
+
if (change.cause === "create" || change.cause === "delete") return meetings;
|
|
196
|
+
if (change.proposed.kind !== "timed") return meetings;
|
|
197
|
+
const { end, start } = change.proposed;
|
|
198
|
+
return meetings.map((meeting) =>
|
|
199
|
+
meeting.id === change.eventId ? { ...meeting, end, start } : meeting,
|
|
200
|
+
);
|
|
201
|
+
}
|
|
202
|
+
|
|
203
|
+
export function MotionCalendar() {
|
|
204
|
+
const [meetings, setMeetings] = useState(initialMeetings);
|
|
205
|
+
const [opened, setOpened] = useState<Opened | null>(null);
|
|
206
|
+
const viewport = useRef<HTMLDivElement>(null);
|
|
207
|
+
|
|
208
|
+
// Views render each meeting as a `[data-event-id]` button, so one listener opens any of them.
|
|
209
|
+
const openClicked = (click: MouseEvent) => {
|
|
210
|
+
const anchor =
|
|
211
|
+
click.target instanceof Element ? click.target.closest<HTMLElement>("[data-event-id]") : null;
|
|
212
|
+
const meeting = meetings.find(({ id }) => anchor !== null && id === eventIdOf(anchor));
|
|
213
|
+
if (anchor === null || meeting === undefined) return;
|
|
214
|
+
grow(anchor, () => setOpened({ anchor, meeting }));
|
|
215
|
+
};
|
|
216
|
+
|
|
217
|
+
return (
|
|
218
|
+
<Calendar.Root
|
|
219
|
+
events={meetings}
|
|
220
|
+
onEventChange={(change) => setMeetings((current) => moveMeeting(current, change))}
|
|
221
|
+
defaultAnchorDate={Temporal.PlainDate.from("2026-10-08")}
|
|
222
|
+
defaultTimeZone="Europe/Berlin"
|
|
223
|
+
locale="en-US"
|
|
224
|
+
weekRules={weekRules}
|
|
225
|
+
>
|
|
226
|
+
<Calendar.Frame className="flex h-full flex-col">
|
|
227
|
+
<CalendarToolbar calendar={Calendar} />
|
|
228
|
+
<Calendar.Viewport
|
|
229
|
+
// The calendar's preview stays as the slot the card lands in: faint, without a shadow.
|
|
230
|
+
className="min-h-0 flex-1 [&_[data-calendar-ghost=event]]:[--calendar-ghost-opacity:0.35] [&_[data-calendar-ghost=event]]:[--calendar-ghost-shadow:none]"
|
|
231
|
+
onClick={openClicked}
|
|
232
|
+
ref={viewport}
|
|
233
|
+
>
|
|
234
|
+
<Calendar.ActiveView />
|
|
235
|
+
</Calendar.Viewport>
|
|
236
|
+
</Calendar.Frame>
|
|
237
|
+
<MeetingCard opened={opened} onClose={() => setOpened(null)} />
|
|
238
|
+
<DragCard within={viewport} />
|
|
239
|
+
<Calendar.Announcer messages={calendarAnnouncements} />
|
|
240
|
+
</Calendar.Root>
|
|
241
|
+
);
|
|
242
|
+
}
|
|
243
|
+
```
|
|
244
|
+
|
|
245
|
+
While a view transition runs, about half a second, the page takes no clicks. That suits
|
|
246
|
+
opening a card. It doesn't suit the calendar's own navigation, which you click through quickly, so
|
|
247
|
+
leave paging and view switches without transitions.
|
|
248
|
+
|
|
249
|
+
## A card follows each drag
|
|
250
|
+
|
|
251
|
+
`monitorCalendarDrags` hears each meeting a view starts to move, and the follower you return
|
|
252
|
+
hears the rest of the drag:
|
|
253
|
+
|
|
254
|
+
| Follower method | Called |
|
|
255
|
+
| ----------------------- | --------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------- |
|
|
256
|
+
| `move(point)` | On every pointer move, with the pointer in viewport coordinates |
|
|
257
|
+
| `preview(preview)` | Whenever the view's preview changes, or moves as the view scrolls: its boxes (`rects`), the time it shows (`label`), and whether a policy would reject or flag it (`validity`). `null` when the view shows none |
|
|
258
|
+
| `end(dropped, landing)` | When the drag ends. `landing` is the preview the release proposed the move at, or `null` when it proposed nothing, as after Escape. No `preview(null)` comes first |
|
|
259
|
+
|
|
260
|
+
The follower here has no `claims`, so it only watches: the drag works as it would without it. The
|
|
261
|
+
card is a Motion element whose position follows the pointer through a spring, and whose rotation
|
|
262
|
+
follows the spring's speed. When the drag ends, it flies to the landing's first box, or back to
|
|
263
|
+
the meeting when nothing was dropped or a policy would reject the drop. It follows only drags in
|
|
264
|
+
its own calendar, should the page have another:
|
|
265
|
+
|
|
266
|
+
```tsx title="motion-calendar.tsx"
|
|
267
|
+
interface Held {
|
|
268
|
+
readonly color: string | undefined;
|
|
269
|
+
readonly height: number;
|
|
270
|
+
readonly title: string;
|
|
271
|
+
readonly width: number;
|
|
272
|
+
}
|
|
273
|
+
|
|
274
|
+
const follow = { damping: 30, stiffness: 400 } as const;
|
|
275
|
+
|
|
276
|
+
/**
|
|
277
|
+
* A copy of each meeting moved in `within` that trails the pointer on a spring and tilts with its
|
|
278
|
+
* speed, over the calendar's own preview, which marks the slot. It lands where the drop is, or
|
|
279
|
+
* flies back.
|
|
280
|
+
*/
|
|
281
|
+
function DragCard({ within }: { readonly within: RefObject<HTMLElement | null> }) {
|
|
282
|
+
const [held, setHeld] = useState<Held | null>(null);
|
|
283
|
+
const [time, setTime] = useState<string | null>(null);
|
|
284
|
+
const [landed, setLanded] = useState(false);
|
|
285
|
+
const x = useMotionValue(0);
|
|
286
|
+
const y = useMotionValue(0);
|
|
287
|
+
const springX = useSpring(x, follow);
|
|
288
|
+
const springY = useSpring(y, follow);
|
|
289
|
+
const rotate = useTransform(useVelocity(springX), [-1500, 0, 1500], [-8, 0, 8], {
|
|
290
|
+
clamp: true,
|
|
291
|
+
});
|
|
292
|
+
|
|
293
|
+
useEffect(
|
|
294
|
+
() =>
|
|
295
|
+
monitorCalendarDrags(({ element, event, origin }) => {
|
|
296
|
+
// Drags in other calendars on the page are theirs. Under reduced motion the calendar's
|
|
297
|
+
// preview alone follows the pointer.
|
|
298
|
+
if (within.current?.contains(element) !== true || reducedMotion()) return;
|
|
299
|
+
const box = element.getBoundingClientRect();
|
|
300
|
+
const grab = { x: origin.x - box.x, y: origin.y - box.y };
|
|
301
|
+
const moveTo = ({ x: left, y: top }: Pick<CalendarRect, "x" | "y">) => {
|
|
302
|
+
x.set(left);
|
|
303
|
+
y.set(top);
|
|
304
|
+
};
|
|
305
|
+
for (const [value, at] of [
|
|
306
|
+
[x, box.x],
|
|
307
|
+
[springX, box.x],
|
|
308
|
+
[y, box.y],
|
|
309
|
+
[springY, box.y],
|
|
310
|
+
] as const) {
|
|
311
|
+
value.jump(at);
|
|
312
|
+
}
|
|
313
|
+
setLanded(false);
|
|
314
|
+
setTime(null);
|
|
315
|
+
setHeld({
|
|
316
|
+
color: element.dataset.color,
|
|
317
|
+
height: box.height,
|
|
318
|
+
title: event.title,
|
|
319
|
+
width: box.width,
|
|
320
|
+
});
|
|
321
|
+
// No `claims`: this follower only watches, and the drag goes on as before.
|
|
322
|
+
return {
|
|
323
|
+
move: (point) => moveTo({ x: point.x - grab.x, y: point.y - grab.y }),
|
|
324
|
+
preview: (preview) => setTime(preview?.label ?? null),
|
|
325
|
+
end: (_dropped, landing) => {
|
|
326
|
+
// Into the slot it was dropped in, or back to where it started.
|
|
327
|
+
const slot = landing?.validity === "invalid" ? undefined : landing?.rects[0];
|
|
328
|
+
moveTo(slot ?? element.getBoundingClientRect());
|
|
329
|
+
setLanded(true);
|
|
330
|
+
},
|
|
331
|
+
};
|
|
332
|
+
}),
|
|
333
|
+
[springX, springY, within, x, y],
|
|
334
|
+
);
|
|
335
|
+
|
|
336
|
+
if (held === null) return null;
|
|
337
|
+
return createPortal(
|
|
338
|
+
<motion.div
|
|
339
|
+
aria-hidden
|
|
340
|
+
data-color={held.color}
|
|
341
|
+
className="pointer-events-none fixed top-0 left-0 z-50 flex flex-col overflow-hidden rounded-md border-s-3 border-calendar-event-border bg-calendar-event px-2 py-1 text-xs leading-tight font-medium text-calendar-event-foreground"
|
|
342
|
+
style={{ height: held.height, rotate, width: held.width, x: springX, y: springY }}
|
|
343
|
+
animate={
|
|
344
|
+
landed
|
|
345
|
+
? { boxShadow: "0 0 0 rgb(0 0 0 / 0)", opacity: 0, scale: 1 }
|
|
346
|
+
: { boxShadow: "0 16px 32px rgb(0 0 0 / 0.25)", opacity: 1, scale: 1.05 }
|
|
347
|
+
}
|
|
348
|
+
transition={spring}
|
|
349
|
+
// Gone once it has landed, unless another drag picked it up again.
|
|
350
|
+
onAnimationComplete={() => {
|
|
351
|
+
if (landed) setHeld((current) => (current === held ? null : current));
|
|
352
|
+
}}
|
|
353
|
+
>
|
|
354
|
+
<span className="line-clamp-2">{held.title}</span>
|
|
355
|
+
{time !== null && <span className="truncate font-normal opacity-80">{time}</span>}
|
|
356
|
+
</motion.div>,
|
|
357
|
+
document.body,
|
|
358
|
+
);
|
|
359
|
+
}
|
|
360
|
+
```
|
|
361
|
+
|
|
362
|
+
The calendar's own preview still marks the slot under the card. The viewport above makes it faint
|
|
363
|
+
and drops its shadow, through the preview's custom properties.
|
|
364
|
+
|
|
365
|
+
## Without JavaScript
|
|
366
|
+
|
|
367
|
+
The preview itself takes CSS. The pointer layer moves it with `transform`, so the independent
|
|
368
|
+
`scale`, `rotate` and `translate` properties add to that rather than replace it. This lifts and
|
|
369
|
+
tilts it as it's picked up, with no Motion at all:
|
|
370
|
+
|
|
371
|
+
```css title="app.css"
|
|
372
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
373
|
+
[data-calendar-ghost="event"] {
|
|
374
|
+
rotate: -2deg;
|
|
375
|
+
scale: 1.05;
|
|
376
|
+
transition:
|
|
377
|
+
rotate 150ms ease-out,
|
|
378
|
+
scale 150ms ease-out;
|
|
379
|
+
|
|
380
|
+
@starting-style {
|
|
381
|
+
rotate: 0deg;
|
|
382
|
+
scale: 1;
|
|
383
|
+
}
|
|
384
|
+
}
|
|
385
|
+
}
|
|
386
|
+
```
|
|
387
|
+
|
|
388
|
+
The media query keeps the preview still for people who ask for less motion.
|
|
389
|
+
`--calendar-ghost-opacity`, `--calendar-ghost-shadow`, `--calendar-ghost-background` and
|
|
390
|
+
`--calendar-ghost-radius` restyle it, and `data-invalid` and `data-warning` mark a drop the
|
|
391
|
+
policies would reject or flag.
|
|
392
|
+
|
|
393
|
+
## Reduced motion and accessibility
|
|
394
|
+
|
|
395
|
+
- `morph` checks `prefers-reduced-motion` and only runs the update when it's set. `DragCard`
|
|
396
|
+
follows no drag then, and the calendar's preview does the job alone.
|
|
397
|
+
- Focus never waits on an animation. Base UI moves focus into the card as it opens and back to the
|
|
398
|
+
meeting as it closes, and the calendar's `Announcer` speaks each drag as it happens.
|
|
399
|
+
- The drag card is `aria-hidden`: it repeats what the preview and the announcements already say.
|
|
400
|
+
|
|
401
|
+
## Cost
|
|
402
|
+
|
|
403
|
+
Motion is your app's dependency, not the calendar's. What this page's code bundles, minified and
|
|
404
|
+
gzipped:
|
|
405
|
+
|
|
406
|
+
| Code | Size |
|
|
407
|
+
| -------------------------------------------------------- | -------- |
|
|
408
|
+
| `grow` and `shrink`: `animateView` from `motion` | 6.6 KiB |
|
|
409
|
+
| `DragCard`: `motion.div` and springs from `motion/react` | 45.8 KiB |
|
|
410
|
+
| Both | 49.6 KiB |
|
|
411
|
+
|
|
412
|
+
If your app already uses Motion, they cost nothing more. With
|
|
413
|
+
[`LazyMotion`](https://motion.dev/docs/react-lazy-motion), `m.div` and `domAnimation`, the drag card
|
|
414
|
+
takes 31.8 KiB.
|