@ericrisco/rsc 1.1.4 → 1.1.6

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.
Files changed (66) hide show
  1. package/README.md +81 -11
  2. package/manifest.json +56 -231
  3. package/package.json +1 -1
  4. package/scripts/doctor.js +68 -1
  5. package/scripts/install-apply.js +91 -16
  6. package/scripts/lib/divergence.js +33 -0
  7. package/scripts/lib/domains.js +3 -3
  8. package/scripts/lib/manifest-file.js +53 -0
  9. package/scripts/lib/repair.js +156 -0
  10. package/scripts/lib/ui.js +5 -0
  11. package/scripts/rsc.js +84 -11
  12. package/skills/design/SKILL.md +3 -3
  13. package/skills/design/references/design-systems.md +1 -1
  14. package/skills/design/references/inspiration-sources.md +2 -2
  15. package/skills/design/references/motion-and-interaction.md +2 -2
  16. package/skills/design-dna/evals/cases.yaml +1 -1
  17. package/skills/design-loop/SKILL.md +3 -3
  18. package/skills/design-loop/evals/cases.yaml +3 -3
  19. package/skills/expo/SKILL.md +1 -1
  20. package/skills/motion-craft/SKILL.md +125 -0
  21. package/skills/motion-craft/evals/cases.yaml +38 -0
  22. package/skills/motion-craft/scripts/verify.sh +75 -0
  23. package/skills/react/SKILL.md +2 -2
  24. package/skills/react-native/SKILL.md +1 -1
  25. package/skills/suggest/SKILL.md +25 -1
  26. package/skills/swift-ios/SKILL.md +2 -2
  27. package/skills/ui-engineering/SKILL.md +114 -0
  28. package/skills/ui-engineering/evals/cases.yaml +38 -0
  29. package/skills/variant-explorer/SKILL.md +93 -0
  30. package/skills/variant-explorer/evals/cases.yaml +38 -0
  31. package/targets/_md-block.js +17 -4
  32. package/targets/claude.js +17 -7
  33. package/targets/index.js +66 -19
  34. package/skills/animate/SKILL.md +0 -851
  35. package/skills/animate/evals/cases.yaml +0 -36
  36. package/skills/animate/references/recipes.md +0 -324
  37. package/skills/animate-expo/SKILL.md +0 -281
  38. package/skills/animate-expo/evals/cases.yaml +0 -36
  39. package/skills/animate-expo/references/recipes.md +0 -385
  40. package/skills/animation-vocabulary/SKILL.md +0 -189
  41. package/skills/animation-vocabulary/evals/cases.yaml +0 -31
  42. package/skills/apple-design/SKILL.md +0 -301
  43. package/skills/apple-design/evals/cases.yaml +0 -33
  44. package/skills/ask-sonner/SKILL.md +0 -104
  45. package/skills/ask-sonner/evals/cases.yaml +0 -33
  46. package/skills/ask-sonner/references/api.md +0 -64
  47. package/skills/design-eng/SKILL.md +0 -88
  48. package/skills/design-eng/evals/cases.yaml +0 -36
  49. package/skills/find-animation-opportunities/SKILL.md +0 -150
  50. package/skills/find-animation-opportunities/evals/cases.yaml +0 -31
  51. package/skills/improve-animations/SKILL.md +0 -126
  52. package/skills/improve-animations/evals/cases.yaml +0 -31
  53. package/skills/improve-animations/references/audit.md +0 -115
  54. package/skills/improve-animations/references/plan-template.md +0 -73
  55. package/skills/pick-ui-library/SKILL.md +0 -101
  56. package/skills/pick-ui-library/evals/cases.yaml +0 -33
  57. package/skills/pick-ui-library/references/component-galleries.md +0 -59
  58. package/skills/prototype/SKILL.md +0 -113
  59. package/skills/prototype/evals/cases.yaml +0 -31
  60. package/skills/prototype/references/picker.md +0 -197
  61. package/skills/review-animations/SKILL.md +0 -188
  62. package/skills/review-animations/evals/cases.yaml +0 -34
  63. package/skills/review-animations/references/standards.md +0 -187
  64. package/skills/review-animations/scripts/verify.sh +0 -164
  65. package/skills/write-swift/SKILL.md +0 -413
  66. package/skills/write-swift/evals/cases.yaml +0 -36
@@ -1,851 +0,0 @@
1
- ---
2
- name: animate
3
- description: "Build a web animation: whether it should animate at all, the purpose, the tool, the properties, the easing curve, the duration, interruption and exit. Writes the CSS or Motion code for dropdowns, modals, toasts, tooltips, accordions, press feedback, stagger and scroll reveals. Use to animate something or make a component feel alive."
4
- tags: [motion, animation, css, transitions, ui]
5
- recommends: [review-animations, pick-ui-library, apple-design]
6
- profiles: [full]
7
- origin: emilkowalski (MIT, adapted)
8
- ---
9
-
10
- # Building Animations
11
-
12
- > **SDD gate.** If this fired on a **new, non-trivial feature or behaviour change** and there is
13
- > **no approved spec + plan** under `02-DOCS/wiki/sdd/`, hand off to `../specify/SKILL.md` first —
14
- > it runs brainstorm → spec → plan → tasks before any code, then routes back here once the plan is
15
- > approved. Build straight from here only for a genuinely one-line / low-risk change, or a bug fix
16
- > restoring intended behaviour. Method: `../sdd/SKILL.md`.
17
-
18
- **Hand-offs.** The **visual system** — palette, type scale, spacing, brand grounding, landing
19
- composition — is `../design/SKILL.md`'s; this skill only sets motion. **React Native / Expo** motion
20
- is `../animate-expo/SKILL.md`'s: no hover, two runtimes, gestures as the baseline. **Gesture physics**
21
- — velocity handoff, momentum projection, rubber-banding, translucent materials — is
22
- `../apple-design/SKILL.md`'s. Reviewing motion someone else wrote is `../review-animations/SKILL.md`'s.
23
- The countable half of the bar below is executable: `../review-animations/scripts/verify.sh` flags
24
- `transition: all`, a `scale(0)` entrance, `ease-in` on UI, a centered popover origin, and motion with
25
- no reduced-motion guard. Run it before you claim the animation is done.
26
-
27
- A construction skill. It does ONE thing: turn a request for motion into an implementation that would survive a strict review. It does not audit a codebase (that's `improve-animations`), critique a diff (that's `review-animations`), hunt for places that could animate (that's `find-animation-opportunities`), or build for React Native (that's `animate-expo`).
28
-
29
- ## Operating Posture
30
-
31
- You are a senior design engineer building the animation yourself. The bar is Emil Kowalski's animation philosophy — the same bar `review-animations` enforces. Write it so it passes that review the first time.
32
-
33
- Two failure modes, and the first is worse:
34
-
35
- 1. **Animating something that shouldn't animate.** The gate below exists to produce zero lines of code sometimes. That's a success, not a dodge.
36
- 2. **Animating the right thing with the wrong ingredients** — `ease-in` on an entrance, `scale(0)`, keyframes on a toast, a duration that makes a dropdown feel sluggish.
37
-
38
- Never present motion options as a menu. Make the call, state the reasoning in one line, write the code.
39
-
40
- ## Hard Rules
41
-
42
- 1. **Run the sequence in order.** Steps 1 and 2 gate everything. Don't reach for a curve before you know whether it animates at all.
43
- 2. **No approximated values.** Every curve, duration, and spring config comes from the tables below. Never invent `cubic-bezier(0.4, 0, 0.2, 1)` because it looks familiar.
44
- 3. **Extend the codebase's tokens, don't fork them.** If `--ease-out` or a duration scale already exists, use it. Adding a parallel system is a defect.
45
- 4. **Reduced motion and hover gating ship with the animation**, not as a follow-up.
46
- 5. **Cheapest tool that works.** Don't install a motion library for a fade.
47
-
48
- ## The Build Sequence
49
-
50
- ### 1. Should this animate at all?
51
-
52
- | Frequency | Decision |
53
- | --- | --- |
54
- | 100+ times/day (keyboard shortcuts, command palette toggle) | **No animation. Ever.** Stop here. |
55
- | Tens of times/day (hover effects, list navigation) | Near-imperceptible only — fast and subtle, or nothing |
56
- | Occasional (modals, drawers, toasts) | Standard animation |
57
- | Rare / first-time (onboarding, success, celebration) | The delight budget lives here |
58
-
59
- **Keyboard-initiated actions are a disqualifier, not a judgment call.** Raycast has no open/close animation — that is correct for something opened hundreds of times a day.
60
-
61
- If the request fails this gate, say so plainly and don't write the animation. Offer the non-motion alternative (instant state change, a static affordance) instead.
62
-
63
- ### 2. What is the purpose?
64
-
65
- Name it in one of these words before continuing:
66
-
67
- - **Feedback** — confirming the interface heard the user
68
- - **Spatial consistency** — showing where something came from or went
69
- - **State indication** — making a state change legible
70
- - **Preventing a jarring change** — bridging content that would otherwise teleport
71
- - **Explanation** — demonstrating how something works (marketing/onboarding only)
72
- - **Delight** — allowed *only* at the rare/first-time tier
73
-
74
- Can't name it? Don't build it. "It looks cool" on a frequently-seen element is a reason to stop.
75
-
76
- Also check **function**: data the user is reading or acting on should not move for style. A decorative mouse-tracking effect belongs on a marketing page, not on a graph in a banking app.
77
-
78
- ### 3. Pick the tool — cheapest that works
79
-
80
- Walk down; stop at the first that fits.
81
-
82
- | Need | Tool |
83
- | --- | --- |
84
- | Hover, press, color, a state toggle you control with a class or attribute | **CSS transition** |
85
- | Entry animation on mount, no JS state | **CSS `@starting-style`** |
86
- | Predetermined motion that must stay smooth while the page is busy loading | **CSS animation** (runs off the main thread) |
87
- | Programmatic control with CSS performance, no library | **WAAPI** (`element.animate()`) |
88
- | Springs, layout animations, exit animations, gesture-driven values | **Motion** (`motion.dev`) |
89
-
90
- CSS animations beat JS under load — they run off the main thread, while `requestAnimationFrame`-based animation drops frames while the browser loads, scripts, or paints. Use CSS for predetermined motion, JS for dynamic and interruptible motion.
91
-
92
- If the task needs a *component* rather than an animation — a toast, a drawer, a command menu, a dropdown — stop and invoke `pick-ui-library`. Hand-rolling those is how you end up with a `<div>` dropdown and no focus management.
93
-
94
- ### 4. Pick the properties
95
-
96
- - **`transform` and `opacity` only.** They skip layout and paint and run on the GPU. `width`/`height`/`margin`/`padding`/`top`/`left` trigger all three. (`clip-path` is the sanctioned fourth — see [references/recipes.md](references/recipes.md). `height` is tolerated only for accordions, where there's no transform equivalent.)
97
- - **Never `scale(0)`.** Start from `scale(0.9–0.97)` + `opacity: 0`. Nothing in the real world appears from nothing.
98
- - **`transform-origin` at the trigger** for popovers, dropdowns, menus, tooltips — `var(--transform-origin)` in Base UI. **Modals are exempt**; they're not anchored to a trigger, so they stay centered.
99
- - **Percentages in `translate()`** are relative to the element's own size — `translateY(100%)` moves by its own height whatever the content. Prefer over hardcoded pixels.
100
- - **In Motion, use the full transform string.** `x`/`y`/`scale` shorthands are not hardware-accelerated and drop frames under load:
101
-
102
- ```jsx
103
- <motion.div animate={{ x: 100 }} /> // drops frames under load
104
- <motion.div animate={{ transform: "translateX(100px)" }} /> // hardware accelerated
105
- ```
106
-
107
- - **Never drive a child's transform from a CSS variable on the parent** — it recalculates styles for every child. Set `transform` on the element directly.
108
-
109
- ### 5. Easing and duration — or a spring
110
-
111
- **Easing**, in decision order:
112
-
113
- | Situation | Easing |
114
- | --- | --- |
115
- | Entering or exiting | `ease-out` |
116
- | Moving / morphing on screen | `ease-in-out` |
117
- | Hover / color change | `ease` |
118
- | Constant motion (marquee, progress) | `linear` |
119
- | Default | `ease-out` |
120
-
121
- **Never `ease-in` on UI.** It starts slow, delaying the exact moment the user is watching. `ease-out` at 200ms *feels* faster than `ease-in` at 200ms.
122
-
123
- Built-in CSS easings are too weak. Use these:
124
-
125
- ```css
126
- --ease-out: cubic-bezier(0.23, 1, 0.32, 1); /* strong ease-out for UI */
127
- --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1); /* strong ease-in-out for on-screen movement */
128
- --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1); /* iOS-like drawer curve (Ionic) */
129
- ```
130
-
131
- Need a curve that isn't here? Take it from [easing.dev](https://easing.dev/) or [easings.co](https://easings.co/). Don't hand-roll one.
132
-
133
- **Duration:**
134
-
135
- | Element | Duration |
136
- | --- | --- |
137
- | Button press feedback | 100–160ms |
138
- | Tooltips, small popovers | 125–200ms |
139
- | Dropdowns, selects | 150–250ms |
140
- | Modals, drawers | 200–500ms |
141
- | Marketing / explanatory | Can be longer |
142
-
143
- **UI animations stay under 300ms.** A 180ms dropdown feels more responsive than a 400ms one.
144
-
145
- **Reach for a spring instead** when the motion is drag with momentum, an element that should feel alive, a gesture the user can interrupt or reverse, or decorative mouse-tracking:
146
-
147
- ```js
148
- { type: "spring", duration: 0.5, bounce: 0.2 } // Apple-style — easier to reason about
149
- { type: "spring", mass: 1, stiffness: 100, damping: 10 } // traditional physics — more control
150
- ```
151
-
152
- Keep bounce at 0.1–0.3, and avoid bounce in most UI — reserve it for drag-to-dismiss and playful interactions.
153
-
154
- ### 6. Interruption and exit
155
-
156
- - **Transitions, not keyframes, for anything triggered rapidly** — toasts, toggles, anything a user can fire twice in a second. Transitions retarget from the current value; keyframes restart from zero.
157
- - **Springs for gestures**, because they carry velocity through an interruption.
158
- - **Exit the way it entered.** A toast that slides in from the bottom leaves through the bottom. Symmetric paths are what make swipe-to-dismiss feel obvious.
159
- - **Asymmetric timing where the user is deciding.** Slow on the deliberate phase (a hold-to-confirm press: 2s linear), snappy on the system response (release: 200ms ease-out).
160
-
161
- ### 7. Reduced motion and pointer gating
162
-
163
- Ships with the animation, every time.
164
-
165
- ```css
166
- @media (prefers-reduced-motion: reduce) {
167
- .element { animation: fade 0.2s ease; } /* keep opacity/color, drop transform-based motion */
168
- }
169
-
170
- @media (hover: hover) and (pointer: fine) {
171
- .element:hover { transform: scale(1.05); } /* touch fires false hovers on tap */
172
- }
173
- ```
174
-
175
- ```jsx
176
- const reduce = useReducedMotion();
177
- const closedX = reduce ? 0 : '-100%';
178
- ```
179
-
180
- Reduced motion means **fewer and gentler** animations, not zero — keep transitions that aid comprehension, remove movement and position changes.
181
-
182
- ## Recipes
183
-
184
- For ready-to-build implementations of the common cases — button press, dropdown, tooltip, modal, drawer, toast, accordion, stagger, hold-to-confirm, tab indicator, scroll reveal, drag-to-dismiss — see [references/recipes.md](references/recipes.md). Load it whenever the request matches one of those components; start from the recipe rather than from a blank file.
185
-
186
- ## Never Ship
187
-
188
- Self-check before you finish. Each of these is an automatic block in `review-animations`:
189
-
190
- | Never | Instead |
191
- | --- | --- |
192
- | `transition: all` | Name the exact properties |
193
- | `transform: scale(0)` entrance | `scale(0.95)` + `opacity: 0` |
194
- | `ease-in` on a UI element | `ease-out` or a strong custom curve |
195
- | Built-in `ease-out` on a deliberate animation | `cubic-bezier(0.23, 1, 0.32, 1)` |
196
- | Animation on a keyboard shortcut or 100+/day action | No animation |
197
- | UI duration over 300ms with no reason | 150–250ms |
198
- | `transform-origin: center` on a trigger-anchored popover | `var(--transform-origin)` (modals exempt) |
199
- | Keyframes on toasts, toggles, rapidly-triggered elements | CSS transitions |
200
- | Animating `width`/`height`/`margin`/`padding`/`top`/`left` | `transform` / `opacity` |
201
- | Motion `x`/`y`/`scale` props under load | Full `transform` string |
202
- | Ungated `:hover` motion | `@media (hover: hover) and (pointer: fine)` |
203
- | Missing `prefers-reduced-motion` | Gentler variant, not zero |
204
- | Everything entering at once | 30–80ms stagger |
205
-
206
- ## Output
207
-
208
- Write the code. Then, in at most a few lines:
209
-
210
- - **The gate result** — frequency tier and the named purpose. If something in the request was rejected, say which and why.
211
- - **The ingredients** — tool, properties, curve, duration or spring config, in one line each.
212
- - **What to feel-check** — if the result depends on feel you can't judge from code (a crossfade, a spring's bounce, the opacity/height balance in an entering list), say so and point at the check: play it at 2–5× duration or in the DevTools animation inspector, step it frame by frame, test gestures on a real device, and look again the next day with fresh eyes.
213
-
214
- Don't pad this into a report. The code is the deliverable.
215
-
216
- ## Tone
217
-
218
- Opinionated and brief. When the honest answer is "this shouldn't animate," give it — that answer is the reason this skill exists. When feel genuinely can't be settled from code, say so instead of guessing at a value.
219
-
220
- ---
221
-
222
- ## Credit
223
-
224
- Adapted for the rsc catalog from **[emilkowalski/skills](https://github.com/emilkowalski/skills)**
225
- (MIT, commit `d23d7f8`) by Emil Kowalski — the design-engineering and animation philosophy behind
226
- [Sonner](https://sonner.emilkowal.ski), [Vaul](https://vaul.emilkowal.ski) and
227
- [animations.dev](https://animations.dev). The craft bar here is his; the routing, gates and evals
228
- that make it an rsc skill are not. Nothing in this body is a substitute for his course.
229
- ---
230
-
231
- # Craft reference, inherited from the umbrella
232
-
233
- *Moved here from `design-eng` (spec: `design-area-cleanup`), which routes and no longer teaches.
234
- This is the same material by the same author; where it overlaps a rule stated above, the above is
235
- the summary and this is the reasoning.*
236
-
237
- ## The Animation Decision Framework
238
-
239
- Before writing any animation code, answer these questions in order:
240
-
241
- ### 1. Should this animate at all?
242
-
243
- **Ask:** How often will users see this animation?
244
-
245
- | Frequency | Decision |
246
- | ----------------------------------------------------------- | ---------------------------- |
247
- | 100+ times/day (keyboard shortcuts, command palette toggle) | No animation. Ever. |
248
- | Tens of times/day (hover effects, list navigation) | Remove or drastically reduce |
249
- | Occasional (modals, drawers, toasts) | Standard animation |
250
- | Rare/first-time (onboarding, feedback forms, celebrations) | Can add delight |
251
-
252
- **Never animate keyboard-initiated actions.** These actions are repeated hundreds of times daily. Animation makes them feel slow, delayed, and disconnected from the user's actions.
253
-
254
- Raycast has no open/close animation. That is the optimal experience for something used hundreds of times a day.
255
-
256
- ### 2. What is the purpose?
257
-
258
- Every animation must have a clear answer to "why does this animate?"
259
-
260
- Valid purposes:
261
-
262
- - **Spatial consistency**: toast enters and exits from the same direction, making swipe-to-dismiss feel intuitive
263
- - **State indication**: a morphing feedback button shows the state change
264
- - **Explanation**: a marketing animation that shows how a feature works
265
- - **Feedback**: a button scales down on press, confirming the interface heard the user
266
- - **Preventing jarring changes**: elements appearing or disappearing without transition feel broken
267
-
268
- If the purpose is just "it looks cool" and the user will see it often, don't animate.
269
-
270
- ### 3. What easing should it use?
271
-
272
- Is the element entering or exiting?
273
- Yes → ease-out (starts fast, feels responsive)
274
- No →
275
- Is it moving/morphing on screen?
276
- Yes → ease-in-out (natural acceleration/deceleration)
277
- Is it a hover/color change?
278
- Yes → ease
279
- Is it constant motion (marquee, progress bar)?
280
- Yes → linear
281
- Default → ease-out
282
-
283
- **Critical: use custom easing curves.** The built-in CSS easings are too weak. They lack the punch that makes animations feel intentional.
284
-
285
- ```css
286
- /* Strong ease-out for UI interactions */
287
- --ease-out: cubic-bezier(0.23, 1, 0.32, 1);
288
-
289
- /* Strong ease-in-out for on-screen movement */
290
- --ease-in-out: cubic-bezier(0.77, 0, 0.175, 1);
291
-
292
- /* iOS-like drawer curve (from Ionic Framework) */
293
- --ease-drawer: cubic-bezier(0.32, 0.72, 0, 1);
294
- ```
295
-
296
- **Never use ease-in for UI animations.** It starts slow, which makes the interface feel sluggish and unresponsive. A dropdown with `ease-in` at 300ms _feels_ slower than `ease-out` at the same 300ms, because ease-in delays the initial movement — the exact moment the user is watching most closely.
297
-
298
- **Easing curve resources:** Don't create curves from scratch. Use [easing.dev](https://easing.dev/) or [easings.co](https://easings.co/) to find stronger custom variants of standard easings.
299
-
300
- ### 4. How fast should it be?
301
-
302
- | Element | Duration |
303
- | ------------------------ | ------------- |
304
- | Button press feedback | 100-160ms |
305
- | Tooltips, small popovers | 125-200ms |
306
- | Dropdowns, selects | 150-250ms |
307
- | Modals, drawers | 200-500ms |
308
- | Marketing/explanatory | Can be longer |
309
-
310
- **Rule: UI animations should stay under 300ms.** A 180ms dropdown feels more responsive than a 400ms one. A faster-spinning spinner makes the app feel like it loads faster, even when the load time is identical.
311
-
312
- ### Perceived performance
313
-
314
- Speed in animation is not just about feeling snappy — it directly affects how users perceive your app's performance:
315
-
316
- - A **fast-spinning spinner** makes loading feel faster (same load time, different perception)
317
- - A **180ms select** animation feels more responsive than a **400ms** one
318
- - **Instant tooltips** after the first one is open (skip delay + skip animation) make the whole toolbar feel faster
319
-
320
- The perception of speed matters as much as actual speed. Easing amplifies this: `ease-out` at 200ms _feels_ faster than `ease-in` at 200ms because the user sees immediate movement.
321
-
322
- ## Spring Animations
323
-
324
- Springs feel more natural than duration-based animations because they simulate real physics. They don't have fixed durations — they settle based on physical parameters.
325
-
326
- ### When to use springs
327
-
328
- - Drag interactions with momentum
329
- - Elements that should feel "alive" (like Apple's Dynamic Island)
330
- - Gestures that can be interrupted mid-animation
331
- - Decorative mouse-tracking interactions
332
-
333
- ### Spring-based mouse interactions
334
-
335
- Tying visual changes directly to mouse position feels artificial because it lacks motion. Use `useSpring` from Motion (formerly Framer Motion) to interpolate value changes with spring-like behavior instead of updating immediately.
336
-
337
- ```jsx
338
- import { useSpring } from 'framer-motion';
339
-
340
- // Without spring: feels artificial, instant
341
- const rotation = mouseX * 0.1;
342
-
343
- // With spring: feels natural, has momentum
344
- const springRotation = useSpring(mouseX * 0.1, {
345
- stiffness: 100,
346
- damping: 10,
347
- });
348
- ```
349
-
350
- This works because the animation is **decorative** — it doesn't serve a function. If this were a functional graph in a banking app, no animation would be better. Know when decoration helps and when it hinders.
351
-
352
- ### Spring configuration
353
-
354
- **Apple's approach (recommended — easier to reason about):**
355
-
356
- ```js
357
- { type: "spring", duration: 0.5, bounce: 0.2 }
358
- ```
359
-
360
- **Traditional physics (more control):**
361
-
362
- ```js
363
- { type: "spring", mass: 1, stiffness: 100, damping: 10 }
364
- ```
365
-
366
- Keep bounce subtle (0.1-0.3) when used. Avoid bounce in most UI contexts. Use it for drag-to-dismiss and playful interactions.
367
-
368
- ### Interruptibility advantage
369
-
370
- Springs maintain velocity when interrupted — CSS animations and keyframes restart from zero. This makes springs ideal for gestures users might change mid-motion. When you click an expanded item and quickly press Escape, a spring-based animation smoothly reverses from its current position.
371
-
372
- ## Component Building Principles
373
-
374
- ### Buttons must feel responsive
375
-
376
- Add `transform: scale(0.97)` on `:active`. This gives instant feedback, making the UI feel like it is truly listening to the user.
377
-
378
- ```css
379
- .button {
380
- transition: transform 160ms ease-out;
381
- }
382
-
383
- .button:active {
384
- transform: scale(0.97);
385
- }
386
- ```
387
-
388
- This applies to any pressable element. The scale should be subtle (0.95-0.98).
389
-
390
- ### Never animate from scale(0)
391
-
392
- Nothing in the real world disappears and reappears completely. Elements animating from `scale(0)` look like they come out of nowhere.
393
-
394
- Start from `scale(0.9)` or higher, combined with opacity. Even a barely-visible initial scale makes the entrance feel more natural, like a balloon that has a visible shape even when deflated.
395
-
396
- ```css
397
- /* Bad */
398
- .entering {
399
- transform: scale(0);
400
- }
401
-
402
- /* Good */
403
- .entering {
404
- transform: scale(0.95);
405
- opacity: 0;
406
- }
407
- ```
408
-
409
- ### Make popovers origin-aware
410
-
411
- Popovers should scale in from their trigger, not from center. The default `transform-origin: center` is wrong for almost every popover. **Exception: modals.** Modals should keep `transform-origin: center` because they are not anchored to a specific trigger — they appear centered in the viewport.
412
-
413
- ```css
414
- /* Base UI */
415
- .popover {
416
- transform-origin: var(--transform-origin);
417
- }
418
- ```
419
-
420
- Whether the user notices the difference individually does not matter. In the aggregate, unseen details become visible. They compound.
421
-
422
- ### Tooltips: skip delay on subsequent hovers
423
-
424
- Tooltips should delay before appearing to prevent accidental activation. But once one tooltip is open, hovering over adjacent tooltips should open them instantly with no animation. This feels faster without defeating the purpose of the initial delay.
425
-
426
- ```css
427
- .tooltip {
428
- transition: transform 125ms ease-out, opacity 125ms ease-out;
429
- transform-origin: var(--transform-origin);
430
- }
431
-
432
- .tooltip[data-starting-style],
433
- .tooltip[data-ending-style] {
434
- opacity: 0;
435
- transform: scale(0.97);
436
- }
437
-
438
- /* Skip animation on subsequent tooltips */
439
- .tooltip[data-instant] {
440
- transition-duration: 0ms;
441
- }
442
- ```
443
-
444
- ### Use CSS transitions over keyframes for interruptible UI
445
-
446
- CSS transitions can be interrupted and retargeted mid-animation. Keyframes restart from zero. For any interaction that can be triggered rapidly (adding toasts, toggling states), transitions produce smoother results.
447
-
448
- ```css
449
- /* Interruptible - good for UI */
450
- .toast {
451
- transition: transform 400ms ease;
452
- }
453
-
454
- /* Not interruptible - avoid for dynamic UI */
455
- @keyframes slideIn {
456
- from {
457
- transform: translateY(100%);
458
- }
459
- to {
460
- transform: translateY(0);
461
- }
462
- }
463
- ```
464
-
465
- ### Use blur to mask imperfect transitions
466
-
467
- When a crossfade between two states feels off despite trying different easings and durations, add subtle `filter: blur(2px)` during the transition.
468
-
469
- **Why blur works:** Without blur, you see two distinct objects during a crossfade — the old state and the new state overlapping. This looks unnatural. Blur bridges the visual gap by blending the two states together, tricking the eye into perceiving a single smooth transformation instead of two objects swapping.
470
-
471
- Combine blur with scale-on-press (`scale(0.97)`) for a polished button state transition:
472
-
473
- ```css
474
- .button {
475
- transition: transform 160ms ease-out;
476
- }
477
-
478
- .button:active {
479
- transform: scale(0.97);
480
- }
481
-
482
- .button-content {
483
- transition: filter 200ms ease, opacity 200ms ease;
484
- }
485
-
486
- .button-content.transitioning {
487
- filter: blur(2px);
488
- opacity: 0.7;
489
- }
490
- ```
491
-
492
- Keep blur under 20px. Heavy blur is expensive, especially in Safari.
493
-
494
- ### Animate enter states with @starting-style
495
-
496
- The modern CSS way to animate element entry without JavaScript:
497
-
498
- ```css
499
- .toast {
500
- opacity: 1;
501
- transform: translateY(0);
502
- transition: opacity 400ms ease, transform 400ms ease;
503
-
504
- @starting-style {
505
- opacity: 0;
506
- transform: translateY(100%);
507
- }
508
- }
509
- ```
510
-
511
- This replaces the common React pattern of using `useEffect` to set `mounted: true` after initial render. Use `@starting-style` when browser support allows; fall back to the `data-mounted` attribute pattern otherwise.
512
-
513
- ```jsx
514
- // Legacy pattern (still works everywhere)
515
- useEffect(() => {
516
- setMounted(true);
517
- }, []);
518
- // <div data-mounted={mounted}>
519
- ```
520
-
521
- ## CSS Transform Mastery
522
-
523
- ### translateY with percentages
524
-
525
- Percentage values in `translate()` are relative to the element's own size. Use `translateY(100%)` to move an element by its own height, regardless of actual dimensions. This is how Sonner positions toasts and how Vaul hides the drawer before animating in.
526
-
527
- ```css
528
- /* Works regardless of drawer height */
529
- .drawer-hidden {
530
- transform: translateY(100%);
531
- }
532
-
533
- /* Works regardless of toast height */
534
- .toast-enter {
535
- transform: translateY(-100%);
536
- }
537
- ```
538
-
539
- Prefer percentages over hardcoded pixel values. They are less error-prone and adapt to content.
540
-
541
- ### scale() scales children too
542
-
543
- Unlike `width`/`height`, `scale()` also scales an element's children. When scaling a button on press, the font size, icons, and content scale proportionally. This is a feature, not a bug.
544
-
545
- ### 3D transforms for depth
546
-
547
- `rotateX()`, `rotateY()` with `transform-style: preserve-3d` create real 3D effects in CSS. Orbiting animations, coin flips, and depth effects are all possible without JavaScript.
548
-
549
- ```css
550
- .wrapper {
551
- transform-style: preserve-3d;
552
- }
553
-
554
- @keyframes orbit {
555
- from {
556
- transform: translate(-50%, -50%) rotateY(0deg) translateZ(72px) rotateY(360deg);
557
- }
558
- to {
559
- transform: translate(-50%, -50%) rotateY(360deg) translateZ(72px) rotateY(0deg);
560
- }
561
- }
562
- ```
563
-
564
- ### transform-origin
565
-
566
- Every element has an anchor point from which transforms execute. The default is center. Set it to match where the trigger lives for origin-aware interactions.
567
-
568
- ## clip-path for Animation
569
-
570
- `clip-path` is not just for shapes. It is one of the most powerful animation tools in CSS.
571
-
572
- ### The inset shape
573
-
574
- `clip-path: inset(top right bottom left)` defines a rectangular clipping region. Each value "eats" into the element from that side.
575
-
576
- ```css
577
- /* Fully hidden from right */
578
- .hidden {
579
- clip-path: inset(0 100% 0 0);
580
- }
581
-
582
- /* Fully visible */
583
- .visible {
584
- clip-path: inset(0 0 0 0);
585
- }
586
-
587
- /* Reveal from left to right */
588
- .overlay {
589
- clip-path: inset(0 100% 0 0);
590
- transition: clip-path 200ms ease-out;
591
- }
592
- .button:active .overlay {
593
- clip-path: inset(0 0 0 0);
594
- transition: clip-path 2s linear;
595
- }
596
- ```
597
-
598
- ### Tabs with perfect color transitions
599
-
600
- Duplicate the tab list. Style the copy as "active" (different background, different text color). Clip the copy so only the active tab is visible. Animate the clip on tab change. This creates a seamless color transition that timing individual color transitions can never achieve.
601
-
602
- ### Hold-to-delete pattern
603
-
604
- Use `clip-path: inset(0 100% 0 0)` on a colored overlay. On `:active`, transition to `inset(0 0 0 0)` over 2s with linear timing. On release, snap back with 200ms ease-out. Add `scale(0.97)` on the button for press feedback.
605
-
606
- ### Image reveals on scroll
607
-
608
- Start with `clip-path: inset(0 0 100% 0)` (hidden from bottom). Animate to `inset(0 0 0 0)` when the element enters the viewport. Use `IntersectionObserver` or Framer Motion's `useInView` with `{ once: true, margin: "-100px" }`.
609
-
610
- ### Comparison sliders
611
-
612
- Overlay two images. Clip the top one with `clip-path: inset(0 50% 0 0)`. Adjust the right inset value based on drag position. No extra DOM elements needed, fully hardware-accelerated.
613
-
614
- ## Gesture and Drag Interactions
615
-
616
- ### Momentum-based dismissal
617
-
618
- Don't require dragging past a threshold. Calculate velocity: `Math.abs(dragDistance) / elapsedTime`. If velocity exceeds ~0.11, dismiss regardless of distance. A quick flick should be enough.
619
-
620
- ```js
621
- const timeTaken = new Date().getTime() - dragStartTime.current.getTime();
622
- const velocity = Math.abs(swipeAmount) / timeTaken;
623
-
624
- if (Math.abs(swipeAmount) >= SWIPE_THRESHOLD || velocity > 0.11) {
625
- dismiss();
626
- }
627
- ```
628
-
629
- ### Damping at boundaries
630
-
631
- When a user drags past the natural boundary (e.g., dragging a drawer up when already at top), apply damping. The more they drag, the less the element moves. Things in real life don't suddenly stop; they slow down first.
632
-
633
- ### Pointer capture for drag
634
-
635
- Once dragging starts, set the element to capture all pointer events. This ensures dragging continues even if the pointer leaves the element bounds.
636
-
637
- ### Multi-touch protection
638
-
639
- Ignore additional touch points after the initial drag begins. Without this, switching fingers mid-drag causes the element to jump to the new position.
640
-
641
- ```js
642
- function onPress() {
643
- if (isDragging) return;
644
- // Start drag...
645
- }
646
- ```
647
-
648
- ### Friction instead of hard stops
649
-
650
- Instead of preventing upward drag entirely, allow it with increasing friction. It feels more natural than hitting an invisible wall.
651
-
652
- ## Performance Rules
653
-
654
- ### Only animate transform and opacity
655
-
656
- These properties skip layout and paint, running on the GPU. Animating `padding`, `margin`, `height`, or `width` triggers all three rendering steps.
657
-
658
- ### CSS variables are inheritable
659
-
660
- Changing a CSS variable on a parent recalculates styles for all children. In a drawer with many items, updating `--swipe-amount` on the container causes expensive style recalculation. Update `transform` directly on the element instead.
661
-
662
- ```js
663
- // Bad: triggers recalc on all children
664
- element.style.setProperty('--swipe-amount', `${distance}px`);
665
-
666
- // Good: only affects this element
667
- element.style.transform = `translateY(${distance}px)`;
668
- ```
669
-
670
- ### Framer Motion hardware acceleration caveat
671
-
672
- Framer Motion's shorthand properties (`x`, `y`, `scale`) are NOT hardware-accelerated. They use `requestAnimationFrame` on the main thread. For hardware acceleration, use the full `transform` string:
673
-
674
- ```jsx
675
- // NOT hardware accelerated (convenient but drops frames under load)
676
- <motion.div animate={{ x: 100 }} />
677
-
678
- // Hardware accelerated (stays smooth even when main thread is busy)
679
- <motion.div animate={{ transform: "translateX(100px)" }} />
680
- ```
681
-
682
- This matters when the browser is simultaneously loading content, running scripts, or painting. At Vercel, the dashboard tab animation used Shared Layout Animations and dropped frames during page loads. Switching to CSS animations (off main thread) fixed it.
683
-
684
- ### CSS animations beat JS under load
685
-
686
- CSS animations run off the main thread. When the browser is busy loading a new page, Framer Motion animations (using `requestAnimationFrame`) drop frames. CSS animations remain smooth. Use CSS for predetermined animations; JS for dynamic, interruptible ones.
687
-
688
- ### Use WAAPI for programmatic CSS animations
689
-
690
- The Web Animations API gives you JavaScript control with CSS performance. Hardware-accelerated, interruptible, and no library needed.
691
-
692
- ```js
693
- element.animate([{ clipPath: 'inset(0 0 100% 0)' }, { clipPath: 'inset(0 0 0 0)' }], {
694
- duration: 1000,
695
- fill: 'forwards',
696
- easing: 'cubic-bezier(0.77, 0, 0.175, 1)',
697
- });
698
- ```
699
-
700
- ## Accessibility
701
-
702
- ### prefers-reduced-motion
703
-
704
- Animations can cause motion sickness. Reduced motion means fewer and gentler animations, not zero. Keep opacity and color transitions that aid comprehension. Remove movement and position animations.
705
-
706
- ```css
707
- @media (prefers-reduced-motion: reduce) {
708
- .element {
709
- animation: fade 0.2s ease;
710
- /* No transform-based motion */
711
- }
712
- }
713
- ```
714
-
715
- ```jsx
716
- const shouldReduceMotion = useReducedMotion();
717
- const closedX = shouldReduceMotion ? 0 : '-100%';
718
- ```
719
-
720
- ### Touch device hover states
721
-
722
- ```css
723
- @media (hover: hover) and (pointer: fine) {
724
- .element:hover {
725
- transform: scale(1.05);
726
- }
727
- }
728
- ```
729
-
730
- Touch devices trigger hover on tap, causing false positives. Gate hover animations behind this media query.
731
-
732
- ## The Sonner Principles (Building Loved Components)
733
-
734
- These principles come from building Sonner (13M+ weekly npm downloads) and apply to any component:
735
-
736
- 1. **Developer experience is key.** No hooks, no context, no complex setup. Insert `<Toaster />` once, call `toast()` from anywhere. The less friction to adopt, the more people will use it.
737
-
738
- 2. **Good defaults matter more than options.** Ship beautiful out of the box. Most users never customize. The default easing, timing, and visual design should be excellent.
739
-
740
- 3. **Naming creates identity.** "Sonner" (French for "to ring") feels more elegant than "react-toast". Sacrifice discoverability for memorability when appropriate.
741
-
742
- 4. **Handle edge cases invisibly.** Pause toast timers when the tab is hidden. Fill gaps between stacked toasts with pseudo-elements to maintain hover state. Capture pointer events during drag. Users never notice these, and that is exactly right.
743
-
744
- 5. **Use transitions, not keyframes, for dynamic UI.** Toasts are added rapidly. Keyframes restart from zero on interruption. Transitions retarget smoothly.
745
-
746
- 6. **Build a great documentation site.** Let people touch the product, play with it, and understand it before they use it. Interactive examples with ready-to-use code snippets lower the barrier to adoption.
747
-
748
- ### Cohesion matters
749
-
750
- Sonner's animation feels satisfying partly because the whole experience is cohesive. The easing and duration fit the vibe of the library. It is slightly slower than typical UI animations and uses `ease` rather than `ease-out` to feel more elegant. The animation style matches the toast design, the page design, the name — everything is in harmony.
751
-
752
- When choosing animation values, consider the personality of the component. A playful component can be bouncier. A professional dashboard should be crisp and fast. Match the motion to the mood.
753
-
754
- ### The opacity + height combination
755
-
756
- When items enter and exit a list (like Family's drawer), the opacity change must work well with the height animation. This is often trial and error. There is no formula — you adjust until it feels right.
757
-
758
- ### Review your work the next day
759
-
760
- Review animations with fresh eyes. You notice imperfections the next day that you missed during development. Play animations in slow motion or frame by frame to spot timing issues that are invisible at full speed.
761
-
762
- ### Asymmetric enter/exit timing
763
-
764
- Pressing should be slow when it needs to be deliberate (hold-to-delete: 2s linear), but release should always be snappy (200ms ease-out). This pattern applies broadly: slow where the user is deciding, fast where the system is responding.
765
-
766
- ```css
767
- /* Release: fast */
768
- .overlay {
769
- transition: clip-path 200ms ease-out;
770
- }
771
-
772
- /* Press: slow and deliberate */
773
- .button:active .overlay {
774
- transition: clip-path 2s linear;
775
- }
776
- ```
777
-
778
- ## Stagger Animations
779
-
780
- When multiple elements enter together, stagger their appearance. Each element animates in with a small delay after the previous one. This creates a cascading effect that feels more natural than everything appearing at once.
781
-
782
- ```css
783
- .item {
784
- opacity: 0;
785
- transform: translateY(8px);
786
- animation: fadeIn 300ms ease-out forwards;
787
- }
788
-
789
- .item:nth-child(1) {
790
- animation-delay: 0ms;
791
- }
792
- .item:nth-child(2) {
793
- animation-delay: 50ms;
794
- }
795
- .item:nth-child(3) {
796
- animation-delay: 100ms;
797
- }
798
- .item:nth-child(4) {
799
- animation-delay: 150ms;
800
- }
801
-
802
- @keyframes fadeIn {
803
- to {
804
- opacity: 1;
805
- transform: translateY(0);
806
- }
807
- }
808
- ```
809
-
810
- Keep stagger delays short (30-80ms between items). Long delays make the interface feel slow. Stagger is decorative — never block interaction while stagger animations are playing.
811
-
812
- ## Debugging Animations
813
-
814
- ### Slow motion testing
815
-
816
- Play animations at reduced speed to spot issues invisible at full speed. Temporarily increase duration to 2-5x normal, or use browser DevTools animation inspector to slow playback.
817
-
818
- Things to look for in slow motion:
819
-
820
- - Do colors transition smoothly, or do you see two distinct states overlapping?
821
- - Does the easing feel right, or does it start/stop abruptly?
822
- - Is the transform-origin correct, or does the element scale from the wrong point?
823
- - Are multiple animated properties (opacity, transform, color) in sync?
824
-
825
- ### Frame-by-frame inspection
826
-
827
- Step through animations frame by frame in Chrome DevTools (Animations panel). This reveals timing issues between coordinated properties that you cannot see at full speed.
828
-
829
- ### Test on real devices
830
-
831
- For touch interactions (drawers, swipe gestures), test on physical devices. Connect your phone via USB, visit your local dev server by IP address, and use Safari's remote devtools. The Xcode Simulator is an alternative but real hardware is better for gesture testing.
832
-
833
- ## Core Philosophy
834
-
835
- ### Taste is trained, not innate
836
-
837
- Good taste is not personal preference. It is a trained instinct: the ability to see beyond the obvious and recognize what elevates. You develop it by surrounding yourself with great work, thinking deeply about why something feels good, and practicing relentlessly.
838
-
839
- When building UI, don't just make it work. Study why the best interfaces feel the way they do. Reverse engineer animations. Inspect interactions. Be curious.
840
-
841
- ### Unseen details compound
842
-
843
- Most details users never consciously notice. That is the point. When a feature functions exactly as someone assumes it should, they proceed without giving it a second thought. That is the goal.
844
-
845
- > "All those unseen details combine to produce something that's just stunning, like a thousand barely audible voices all singing in tune." - Paul Graham
846
-
847
- Every decision below exists because the aggregate of invisible correctness creates interfaces people love without knowing why.
848
-
849
- ### Beauty is leverage
850
-
851
- People select tools based on the overall experience, not just functionality. Good defaults and good animations are real differentiators. Beauty is underutilized in software. Use it as leverage to stand out.