@duro-app/cli 5.16.0 → 5.18.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/README.md +12 -5
- package/dist/bin.js +3 -2
- package/dist/bin.js.map +1 -1
- package/dist/commands/hook.d.ts.map +1 -1
- package/dist/commands/hook.js +11 -2
- package/dist/commands/hook.js.map +1 -1
- package/dist/commands/list.d.ts.map +1 -1
- package/dist/commands/list.js +23 -2
- package/dist/commands/list.js.map +1 -1
- package/dist/commands/lookup.d.ts.map +1 -1
- package/dist/commands/lookup.js +15 -1
- package/dist/commands/lookup.js.map +1 -1
- package/dist/commands/mcp.d.ts +12 -0
- package/dist/commands/mcp.d.ts.map +1 -1
- package/dist/commands/mcp.js +51 -36
- package/dist/commands/mcp.js.map +1 -1
- package/dist/commands/skill.d.ts +6 -0
- package/dist/commands/skill.d.ts.map +1 -1
- package/dist/commands/skill.js +168 -24
- package/dist/commands/skill.js.map +1 -1
- package/dist/format.d.ts.map +1 -1
- package/dist/format.js +7 -0
- package/dist/format.js.map +1 -1
- package/dist/hook-script.d.ts +2 -2
- package/dist/hook-script.d.ts.map +1 -1
- package/dist/hook-script.js +1 -1
- package/dist/manifest.d.ts.map +1 -1
- package/dist/manifest.js +10 -4
- package/dist/manifest.js.map +1 -1
- package/dist/registry-types.d.ts +5 -0
- package/dist/registry-types.d.ts.map +1 -1
- package/dist/registry.d.ts +20 -0
- package/dist/registry.d.ts.map +1 -1
- package/dist/registry.js +38 -0
- package/dist/registry.js.map +1 -1
- package/package.json +6 -5
- package/registry.json +35 -0
- package/{LICENSE → skills/colors/LICENSE} +1 -1
- package/skills/colors/NOTICE.md +36 -0
- package/skills/colors/SKILL.md +99 -0
- package/skills/colors/color-formats.md +90 -0
- package/skills/colors/color-usage.md +109 -0
- package/skills/colors/contrast.md +70 -0
- package/skills/colors/palette-generation.md +108 -0
- package/skills/colors/palette-structure.md +72 -0
- package/skills/colors/token-naming.md +99 -0
- package/skills/typography/LICENSE +21 -0
- package/skills/typography/NOTICE.md +36 -0
- package/skills/typography/SKILL.md +169 -0
- package/skills/typography/choosing-fonts.md +53 -0
- package/skills/typography/css-cheat-sheet.md +67 -0
- package/skills/typography/details-and-accessibility.md +84 -0
- package/skills/typography/spacing-and-sizing.md +87 -0
- package/skills/typography/variable-fonts-and-opentype.md +100 -0
- package/skills/typography/wrapping-and-punctuation.md +23 -0
- package/skills/ui/LICENSE +21 -0
- package/skills/ui/NOTICE.md +37 -0
- package/skills/ui/SKILL.md +139 -0
- package/skills/ui/animations.md +170 -0
- package/skills/ui/enter-exit.md +157 -0
- package/skills/ui/icon-transitions.md +72 -0
- package/skills/ui/icons.md +105 -0
- package/skills/ui/performance.md +63 -0
- package/skills/ui/surfaces.md +166 -0
|
@@ -0,0 +1,139 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: ui
|
|
3
|
+
description: Polishes the surfaces, icons and motion in your project with exact values for border radius, optical alignment, shadows, icon states and animation. Use when adding or tuning a UI animation or transition, such as a menu or dialog enter and exit, staggered list items, hover and press feedback or an icon swap.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# UI polish
|
|
7
|
+
|
|
8
|
+
This skill holds the visual polish for surfaces, icons and motion, with the exact value each detail takes. It applies once the underlying interaction is sound, and a polish finding never outranks a broken interaction.
|
|
9
|
+
|
|
10
|
+
A decision of this repository (resolved at its applicable scope with `aval resolve`) outranks a value in this skill. Apply token requirements and gap routing only where the repository's decisions require them, keeping their named exemptions. On `duro-stack`, a non-exempt measure without a token is a design-system gap under ADR-0006/0027, never a local literal.
|
|
11
|
+
|
|
12
|
+
Where Duro defines the value, these win: the `spacing.css.ts` radii, `shadows.css.ts` and `motion.css.ts`.
|
|
13
|
+
|
|
14
|
+
The ui values with no token (`300ms` enter, `100ms` stagger, `cubic-bezier(0.2, 0, 0, 1)`) are known design-system gaps tracked in one issue (https://github.com/fredericrous/duro-design-system/issues/120), so a review reports them once against that issue and not per use.
|
|
15
|
+
|
|
16
|
+
## Exact values, optional polish
|
|
17
|
+
|
|
18
|
+
The values below are exact, not ranges to approximate. `cubic-bezier(0.2, 0, 0, 1)` is not `cubic-bezier(0.4, 0, 0.2, 1)`, and `0.96` is not `0.95`. The optical nudges and the concentric padding cutoff are the exceptions. They are starting points, judged by eye.
|
|
19
|
+
|
|
20
|
+
Keep the project's component library, tokens and density. A project token always wins over a value here, and this skill's value applies only where the project has no token for it. Match the project's motion language wherever no rule here gives a value. A deliberate and consistent project convention, such as a style with no shadows, is a preference and not a finding. The same detail done two ways within the project is a finding.
|
|
21
|
+
|
|
22
|
+
Text wrapping, font rendering, tabular numbers and text spacing belong to `typography`. Hit areas, keyboard support, ARIA and the reduced-motion requirement belong to `accessibility`. Grouping, section spacing, breakpoints and spatial RTL belong to `layout`, except directional icon mirroring. Color tokens and contrast measurement belong to `colors`.
|
|
23
|
+
|
|
24
|
+
## Outer radius equals inner radius plus padding
|
|
25
|
+
|
|
26
|
+
Where nested surfaces share a visible, even inset, the outer radius is the inner radius plus the padding plus any border width. Past `24px` of padding, or where the padding is deliberately asymmetric, treat the layers as separate surfaces and keep each one's radius token. Recipes are in [surfaces.md](surfaces.md).
|
|
27
|
+
|
|
28
|
+
## Align optically where geometry looks off
|
|
29
|
+
|
|
30
|
+
Where geometric centering looks off, nudge by eye. Give a button `2px` less padding on its icon side, shift a play triangle toward its point and fix asymmetric glyphs in the SVG itself. Recipes are in [surfaces.md](surfaces.md#optical-alignment).
|
|
31
|
+
|
|
32
|
+
## Shadows for elevation, borders for structure
|
|
33
|
+
|
|
34
|
+
Where a border exists only to create depth, replace it with layered transparent `box-shadow` values. Keep borders on dividers, separators, table cells and selected states. Keep them on form inputs too, whose boundary needs 3:1 non-text contrast under `accessibility`. Focus rings belong to `accessibility` as well.
|
|
35
|
+
|
|
36
|
+
Forced-colors mode removes every `box-shadow`. Keep `border: 1px solid transparent` under a shadow ring so that mode still draws an edge. Recipes are in [surfaces.md](surfaces.md#shadow-recipes).
|
|
37
|
+
|
|
38
|
+
## Outline images in pure black or white
|
|
39
|
+
|
|
40
|
+
Give content images a `1px` outline inset by `1px`. Use `oklch(0 0 0 / 0.1)` in light mode and `oklch(1 0 0 / 0.1)` in dark. Never use a palette near-black, a tinted neutral or the accent color, because the tint shows as a colored fringe on the image edge. Skip transparent artwork such as logos and illustrations. The recipe is in [surfaces.md](surfaces.md#image-outlines).
|
|
41
|
+
|
|
42
|
+
## Transitions, not keyframes, for interactive state
|
|
43
|
+
|
|
44
|
+
Drive interactive state changes with CSS transitions or a motion library's springs, which retarget when the user reverses mid-flight. Keyframes run a fixed timeline and cannot reverse, so reserve them for sequences that run once. See [animations.md](animations.md).
|
|
45
|
+
|
|
46
|
+
## Press scales to 0.96
|
|
47
|
+
|
|
48
|
+
A pressed button scales to `0.96` over `150ms` with `ease-out`, and a disabled one never scales. Give the button an opt-out where the motion would distract, through the component's existing variant API or a `static` prop. See [recipes for CSS, Tailwind and Motion](animations.md#scale-on-press).
|
|
49
|
+
|
|
50
|
+
## High-frequency interactions get no animation
|
|
51
|
+
|
|
52
|
+
Keystrokes, row hovers and tab switches get instant feedback, or a transition of `150ms` or less on `opacity` or `background-color`. Reserve expressive motion for infrequent moments such as a view's first load, a success state or an empty state.
|
|
53
|
+
|
|
54
|
+
Every animated state change also leaves a static cue in the form of a color, icon or label. Motion is never the only feedback channel.
|
|
55
|
+
|
|
56
|
+
## Gate motion behind the reduced-motion preference
|
|
57
|
+
|
|
58
|
+
`accessibility` owns the requirement, and no recipe here ships without it. Run movement, scale and blur only under `prefers-reduced-motion: no-preference`. Under reduced motion, replace them with an opacity cross-fade rather than removing the element instantly. Recipes for CSS, Tailwind and Motion are in [animations.md](animations.md#reduced-motion-fallback).
|
|
59
|
+
|
|
60
|
+
## Stagger infrequent entrances by 100ms
|
|
61
|
+
|
|
62
|
+
Where sequence communicates hierarchy in a staged entrance, split the content into semantic chunks such as title, description and actions. Stagger them `100ms` apart, each entering with opacity, `4px` of blur and `12px` of `translateY` over `300ms` with `ease-out`. Never stagger routine interactions. See [enter-exit.md](enter-exit.md).
|
|
63
|
+
|
|
64
|
+
## Exits are shorter and smaller than enters
|
|
65
|
+
|
|
66
|
+
Exit with opacity, `4px` of blur and a fixed `-12px` `translateY` over `150ms` with `ease-out`, never the full container height. Slide fully out only where the destination carries meaning, such as a drawer closing. Remove the element instantly where motion adds no information. See [enter-exit.md](enter-exit.md#exit-animations).
|
|
67
|
+
|
|
68
|
+
## Skip state animations on first render
|
|
69
|
+
|
|
70
|
+
Set `initial={false}` on an `AnimatePresence` that wraps a state swap, so the default state does not animate in on mount. Never set it around an intentional entrance such as a staggered hero. See [animations.md](animations.md#skip-animation-on-page-load).
|
|
71
|
+
|
|
72
|
+
## Cross-fade contextual icons with exact values
|
|
73
|
+
|
|
74
|
+
Where an icon swaps on an infrequent state change, such as play to pause or copy to copied, cross-fade it. Scale runs `0.25` to `1`, opacity `0` to `1` and blur `4px` to `0px`. With a motion library, use `{ type: "spring", duration: 0.3, bounce: 0 }`, and bounce is always `0`. Without one, keep both icons in the DOM and cross-fade over `300ms` with `cubic-bezier(0.2, 0, 0, 1)`.
|
|
75
|
+
|
|
76
|
+
A tab's icon swap and the actions a row reveals on hover fall under **High-frequency interactions get no animation**. Both recipes are in [icon-transitions.md](icon-transitions.md).
|
|
77
|
+
|
|
78
|
+
## Suppress transitions on theme switch
|
|
79
|
+
|
|
80
|
+
Disable every transition for the theme swap, force a style flush and restore transitions after the next frame. Otherwise every color transition fires at once and the switch smears. See the [recipe](animations.md#suppress-transitions-on-theme-switch).
|
|
81
|
+
|
|
82
|
+
## Transition only what changes
|
|
83
|
+
|
|
84
|
+
Name the exact properties, as in `transition-property: scale, opacity`, and never `all`. See [performance.md](performance.md).
|
|
85
|
+
|
|
86
|
+
## Name the animated property in will-change
|
|
87
|
+
|
|
88
|
+
Add `will-change` only after you see first-frame stutter, and name the property you animate: `scale` for `scale`, `transform` for `transform`. Limit it to transform properties, `opacity` and `filter`, and never use `all`. See [performance.md](performance.md#use-will-change-sparingly).
|
|
89
|
+
|
|
90
|
+
## Hover effects only on hover-capable pointers
|
|
91
|
+
|
|
92
|
+
Put hover-only styling behind `@media (hover: hover)`. On touch, `:hover` latches after a tap and reads as a stuck selected state. Tailwind 4's `hover:` variant already compiles under that query, and Tailwind 3's does not. Where a control draws its own pressed state, set `-webkit-tap-highlight-color: transparent` so the default gray flash does not double it.
|
|
93
|
+
|
|
94
|
+
## Contain scroll inside overlays
|
|
95
|
+
|
|
96
|
+
Give scrollable dialogs, drawers, menus and side panels `overscroll-behavior: contain`, so scrolling past their end never scrolls the page behind.
|
|
97
|
+
|
|
98
|
+
## Match icon stroke to text weight
|
|
99
|
+
|
|
100
|
+
An icon's rendered stroke tracks the weight of the text beside it, from `1.5px` at 400 to `2.5px` at 700. Use one icon library per surface. The table, sizing and grid rules are in [icons.md](icons.md).
|
|
101
|
+
|
|
102
|
+
## One SVG, recolored per state
|
|
103
|
+
|
|
104
|
+
Icons use `currentColor` and take hover, selected and disabled states from CSS color and opacity, never from separate assets. Outline is the default variant, and fill marks the active state. Under `dir="rtl"`, mirror only icons whose meaning follows reading direction. See [icons.md](icons.md#icons-in-rtl).
|
|
105
|
+
|
|
106
|
+
## Before you finish
|
|
107
|
+
|
|
108
|
+
| Detection | Fix |
|
|
109
|
+
| --- | --- |
|
|
110
|
+
| Padded parent and child with the same `rounded-*` or `border-radius` | Add the padding to the outer radius |
|
|
111
|
+
| `box-shadow: 0 0 0 1px` ring with no `border` beside it | `border: 1px solid transparent` |
|
|
112
|
+
| `outline-slate-*`, `outline-zinc-*` or a hex outline color on `img` | `outline-black/10` and `dark:outline-white/10` |
|
|
113
|
+
| `transition-all` or `transition: all` | Name the changing properties |
|
|
114
|
+
| `animation:` set on `:hover`, `.open` or another toggled class | A transition on the same properties |
|
|
115
|
+
| `active:scale-95`, `scale-90` or `whileTap` below `0.96` | `0.96` |
|
|
116
|
+
| `:active` scale with no `:disabled` exclusion | `enabled:active:` or `:not(:disabled):active` |
|
|
117
|
+
| `bounce:` set to anything but `0` | `bounce: 0` |
|
|
118
|
+
| `opacity: 0` in a base rule that only an `animation` reveals | Hidden state in the `from` keyframe, `animation-fill-mode: both` |
|
|
119
|
+
| `translate`, `scale`, `filter` or `motion.*` animation with no `prefers-reduced-motion`, `motion-safe:` or `MotionConfig` guard | Gate it and cross-fade opacity under reduced motion |
|
|
120
|
+
| Color transitions plus a theme toggle with no `disableTransitionOnChange` or override | The theme-switch suppression recipe |
|
|
121
|
+
| `will-change: all`, or `will-change` on an element that never animates | Name the animated property or delete it |
|
|
122
|
+
| `fill="#..."` or `stroke="#..."` inside an icon SVG | `currentColor` |
|
|
123
|
+
| Plain-CSS `:hover` or Tailwind 3 `hover:` outside `@media (hover: hover)` | Wrap it in the query |
|
|
124
|
+
| `overflow: auto` or `overflow-y-auto` on a dialog, drawer or menu with no `overscroll-behavior` | `overscroll-behavior: contain` |
|
|
125
|
+
|
|
126
|
+
## Reporting
|
|
127
|
+
|
|
128
|
+
**Severity.** `HIGH` breaks an interaction, as a keyframe toggle that cannot reverse or a hover state stuck on touch does. Two of `interface`'s escalation triggers land here and are `HIGH` on sight. One is motion that ignores `prefers-reduced-motion`, and the other is a state change carried by motion alone. `MEDIUM` is a visible inconsistency in surfaces, icons or motion. `LOW` is isolated polish.
|
|
129
|
+
|
|
130
|
+
**Verification.** Without a browser, read every state the component defines from the code, such as hover, pressed, selected, loading and empty, with its durations and easings. With one, walk each state and replay motion at 10% speed in the browser's Animations panel. Report every check you could not run as `Not verified`.
|
|
131
|
+
|
|
132
|
+
**Format.** Group findings under the principle each violates, ordered by severity, one row per root cause listing every location it appears in:
|
|
133
|
+
|
|
134
|
+
| Severity | Location | Before | After | Why |
|
|
135
|
+
| --- | --- | --- | --- | --- |
|
|
136
|
+
|
|
137
|
+
`Location` is `path/to/file:line`. `Why` names the principle and the user impact.
|
|
138
|
+
|
|
139
|
+
End with `Block` when any `HIGH` remains, `Approve` otherwise, leaving the rest in the table as work to do. Never `Approve` coverage you did not inspect. With nothing to report, state "No actionable UI-polish findings" and report verification.
|
|
@@ -0,0 +1,170 @@
|
|
|
1
|
+
# Animations
|
|
2
|
+
|
|
3
|
+
Recipes for interruptible transitions, press feedback, first-render behavior, theme switches and the reduced-motion fallback. Staged entrances and exits live in [enter-exit.md](enter-exit.md), and icon swaps in [icon-transitions.md](icon-transitions.md).
|
|
4
|
+
|
|
5
|
+
## Interruptible animations
|
|
6
|
+
|
|
7
|
+
| | CSS transitions | CSS keyframe animations |
|
|
8
|
+
| --- | --- | --- |
|
|
9
|
+
| **Behavior** | Interpolate toward the latest state | Run on a fixed timeline |
|
|
10
|
+
| **Interrupted** | Retarget mid-flight and reverse | Snap or restart from the beginning |
|
|
11
|
+
| **Use for** | Hover, toggle, open and close | Sequences that run once, such as enters and loading |
|
|
12
|
+
|
|
13
|
+
```css
|
|
14
|
+
/* Good: clicking again mid-animation reverses smoothly */
|
|
15
|
+
.drawer {
|
|
16
|
+
transform: translateX(-100%);
|
|
17
|
+
transition: transform 200ms ease-out;
|
|
18
|
+
}
|
|
19
|
+
.drawer.open {
|
|
20
|
+
transform: translateX(0);
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
/* Bad: closing mid-animation snaps */
|
|
24
|
+
.drawer.open {
|
|
25
|
+
animation: slideIn 200ms ease-out forwards;
|
|
26
|
+
}
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
## Scale on press
|
|
30
|
+
|
|
31
|
+
```css
|
|
32
|
+
.button {
|
|
33
|
+
transition-property: scale;
|
|
34
|
+
transition-duration: 150ms;
|
|
35
|
+
transition-timing-function: ease-out;
|
|
36
|
+
}
|
|
37
|
+
|
|
38
|
+
.button:not(:disabled):active {
|
|
39
|
+
scale: 0.96;
|
|
40
|
+
}
|
|
41
|
+
```
|
|
42
|
+
|
|
43
|
+
```tsx
|
|
44
|
+
// Tailwind
|
|
45
|
+
<button className="transition-transform duration-150 ease-out enabled:active:scale-[0.96]">
|
|
46
|
+
Click me
|
|
47
|
+
</button>
|
|
48
|
+
|
|
49
|
+
// Motion
|
|
50
|
+
<motion.button whileTap={disabled ? undefined : { scale: 0.96 }} disabled={disabled}>
|
|
51
|
+
Click me
|
|
52
|
+
</motion.button>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
### Static prop pattern
|
|
56
|
+
|
|
57
|
+
Where the button has no variant API to carry the opt-out, apply the scale class conditionally on a `static` prop:
|
|
58
|
+
|
|
59
|
+
```tsx
|
|
60
|
+
const tapScale = "enabled:active:scale-[0.96]";
|
|
61
|
+
|
|
62
|
+
function Button({ static: isStatic, className, children, ...props }) {
|
|
63
|
+
return (
|
|
64
|
+
<button
|
|
65
|
+
className={cn(
|
|
66
|
+
"transition-transform duration-150 ease-out",
|
|
67
|
+
!isStatic && tapScale,
|
|
68
|
+
className,
|
|
69
|
+
)}
|
|
70
|
+
{...props}
|
|
71
|
+
>
|
|
72
|
+
{children}
|
|
73
|
+
</button>
|
|
74
|
+
);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// Usage
|
|
78
|
+
<Button>Click me</Button> {/* scales on press */}
|
|
79
|
+
<Button static>Submit</Button> {/* no scale */}
|
|
80
|
+
```
|
|
81
|
+
|
|
82
|
+
## Skip animation on page load
|
|
83
|
+
|
|
84
|
+
The icon recipe in [icon-transitions.md](icon-transitions.md#motion) shows `initial={false}` used correctly. It suits icon swaps, toggles, tabs and segmented controls, anything with a default state on page load.
|
|
85
|
+
|
|
86
|
+
Setting it around a first-time entrance skips that entrance entirely. Check the component on a full page refresh before adding it.
|
|
87
|
+
|
|
88
|
+
```tsx
|
|
89
|
+
// Bad: initial={false} skips the staggered page enter
|
|
90
|
+
<AnimatePresence initial={false}>
|
|
91
|
+
<motion.div initial="hidden" animate="visible" variants={...}>
|
|
92
|
+
...
|
|
93
|
+
</motion.div>
|
|
94
|
+
</AnimatePresence>
|
|
95
|
+
```
|
|
96
|
+
|
|
97
|
+
## Suppress transitions on theme switch
|
|
98
|
+
|
|
99
|
+
Inject a stylesheet that turns off every transition, force a style flush so the new colors commit while it applies, then remove it after the next frame:
|
|
100
|
+
|
|
101
|
+
```tsx
|
|
102
|
+
"use client";
|
|
103
|
+
|
|
104
|
+
import { useEffect } from "react";
|
|
105
|
+
|
|
106
|
+
export function DisableThemeTransitions() {
|
|
107
|
+
useEffect(() => {
|
|
108
|
+
const mql = window.matchMedia("(prefers-color-scheme: dark)");
|
|
109
|
+
|
|
110
|
+
const handleChange = () => {
|
|
111
|
+
const style = document.createElement("style");
|
|
112
|
+
style.append(
|
|
113
|
+
document.createTextNode(
|
|
114
|
+
"*,*::before,*::after{transition:none !important}"
|
|
115
|
+
)
|
|
116
|
+
);
|
|
117
|
+
document.head.append(style);
|
|
118
|
+
|
|
119
|
+
void document.body.offsetHeight; // forces a synchronous style flush
|
|
120
|
+
|
|
121
|
+
requestAnimationFrame(() => {
|
|
122
|
+
requestAnimationFrame(() => style.remove());
|
|
123
|
+
});
|
|
124
|
+
};
|
|
125
|
+
|
|
126
|
+
mql.addEventListener("change", handleChange);
|
|
127
|
+
return () => mql.removeEventListener("change", handleChange);
|
|
128
|
+
}, []);
|
|
129
|
+
|
|
130
|
+
return null;
|
|
131
|
+
}
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
The new theme resolves while the override is still in the document, so no transition starts. The nested `requestAnimationFrame` removes the override only after that paint.
|
|
135
|
+
|
|
136
|
+
That covers the OS-level change. An in-app toggle needs the same steps around its own flip: apply the override, change the theme, flush and remove. `next-themes` ships this as `disableTransitionOnChange`.
|
|
137
|
+
|
|
138
|
+
## High-frequency motion
|
|
139
|
+
|
|
140
|
+
```css
|
|
141
|
+
/* Good: high-frequency hover gets a minimal transition */
|
|
142
|
+
.row:hover {
|
|
143
|
+
background-color: var(--surface-hover);
|
|
144
|
+
transition: background-color 100ms ease-out;
|
|
145
|
+
}
|
|
146
|
+
|
|
147
|
+
/* Bad: every hover replays a full entrance */
|
|
148
|
+
.row:hover .row-icon {
|
|
149
|
+
animation: bounceIn 500ms;
|
|
150
|
+
}
|
|
151
|
+
```
|
|
152
|
+
|
|
153
|
+
## Reduced-motion fallback
|
|
154
|
+
|
|
155
|
+
The opacity fade runs for everyone, and movement, scale and blur join it only without the preference:
|
|
156
|
+
|
|
157
|
+
```css
|
|
158
|
+
.panel {
|
|
159
|
+
transition: opacity 150ms ease-out;
|
|
160
|
+
}
|
|
161
|
+
|
|
162
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
163
|
+
.panel {
|
|
164
|
+
transition-property: opacity, translate, scale, filter;
|
|
165
|
+
transition-duration: 300ms;
|
|
166
|
+
}
|
|
167
|
+
}
|
|
168
|
+
```
|
|
169
|
+
|
|
170
|
+
In Tailwind, prefix movement, scale and blur utilities with `motion-safe:`. In Motion, wrap the app in `<MotionConfig reducedMotion="user">`. It turns off transform and layout animations under the preference and keeps opacity. Blur still runs there, so branch on `useReducedMotion()` where a recipe animates `filter`.
|
|
@@ -0,0 +1,157 @@
|
|
|
1
|
+
# Enter and exit animations
|
|
2
|
+
|
|
3
|
+
Recipes for staged entrances and the exits that follow them. For interactive state feedback see [animations.md](animations.md), and for icon swaps see [icon-transitions.md](icon-transitions.md).
|
|
4
|
+
|
|
5
|
+
## Enter animations
|
|
6
|
+
|
|
7
|
+
1. **Split** into semantic groups such as title, description and actions.
|
|
8
|
+
2. **Stagger** the groups `100ms` apart.
|
|
9
|
+
3. **Split a short display headline** into words, staggered `80ms` apart, where it should read word by word.
|
|
10
|
+
4. **Combine** `opacity`, `blur` and `translateY` for each group's enter.
|
|
11
|
+
|
|
12
|
+
### Motion
|
|
13
|
+
|
|
14
|
+
```tsx
|
|
15
|
+
const item = {
|
|
16
|
+
hidden: { opacity: 0, y: 12, filter: "blur(4px)" },
|
|
17
|
+
visible: {
|
|
18
|
+
opacity: 1,
|
|
19
|
+
y: 0,
|
|
20
|
+
filter: "blur(0px)",
|
|
21
|
+
transition: { duration: 0.3, ease: "easeOut" },
|
|
22
|
+
},
|
|
23
|
+
};
|
|
24
|
+
|
|
25
|
+
function PageHeader() {
|
|
26
|
+
return (
|
|
27
|
+
<motion.div
|
|
28
|
+
initial="hidden"
|
|
29
|
+
animate="visible"
|
|
30
|
+
variants={{ visible: { transition: { staggerChildren: 0.1 } } }}
|
|
31
|
+
>
|
|
32
|
+
<motion.h1 variants={item}>Welcome</motion.h1>
|
|
33
|
+
<motion.p variants={item}>A description of the page.</motion.p>
|
|
34
|
+
<motion.div variants={item}>
|
|
35
|
+
<Button>Get started</Button>
|
|
36
|
+
</motion.div>
|
|
37
|
+
</motion.div>
|
|
38
|
+
);
|
|
39
|
+
}
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
### CSS
|
|
43
|
+
|
|
44
|
+
The hidden state lives in the `from` keyframe, so an item whose animation never runs stays visible. Reduced motion keeps only the opacity keyframe.
|
|
45
|
+
|
|
46
|
+
```css
|
|
47
|
+
.stagger-item {
|
|
48
|
+
animation: fade-in 300ms ease-out both;
|
|
49
|
+
}
|
|
50
|
+
|
|
51
|
+
@media (prefers-reduced-motion: no-preference) {
|
|
52
|
+
.stagger-item {
|
|
53
|
+
animation-name: fade-in-up;
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
.stagger-item:nth-child(2) { animation-delay: 100ms; }
|
|
58
|
+
.stagger-item:nth-child(3) { animation-delay: 200ms; }
|
|
59
|
+
|
|
60
|
+
@keyframes fade-in {
|
|
61
|
+
from { opacity: 0; }
|
|
62
|
+
}
|
|
63
|
+
|
|
64
|
+
@keyframes fade-in-up {
|
|
65
|
+
from {
|
|
66
|
+
opacity: 0;
|
|
67
|
+
transform: translateY(12px);
|
|
68
|
+
filter: blur(4px);
|
|
69
|
+
}
|
|
70
|
+
}
|
|
71
|
+
```
|
|
72
|
+
|
|
73
|
+
### Entering from display: none
|
|
74
|
+
|
|
75
|
+
A popover, dialog or element toggled from `display: none` has no previous style to transition from. `@starting-style` supplies one, and `transition-behavior: allow-discrete` keeps it rendered through the exit. The open state's duration applies on enter and the closed state's on exit.
|
|
76
|
+
|
|
77
|
+
```css
|
|
78
|
+
[popover] {
|
|
79
|
+
opacity: 0;
|
|
80
|
+
translate: 0 12px;
|
|
81
|
+
transition-property: opacity, translate, display, overlay;
|
|
82
|
+
transition-duration: 150ms;
|
|
83
|
+
transition-timing-function: ease-out;
|
|
84
|
+
transition-behavior: allow-discrete;
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
[popover]:popover-open {
|
|
88
|
+
opacity: 1;
|
|
89
|
+
translate: 0 0;
|
|
90
|
+
transition-duration: 300ms;
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
@starting-style {
|
|
94
|
+
[popover]:popover-open {
|
|
95
|
+
opacity: 0;
|
|
96
|
+
translate: 0 12px;
|
|
97
|
+
}
|
|
98
|
+
}
|
|
99
|
+
```
|
|
100
|
+
|
|
101
|
+
`@starting-style` and discrete `display` transitions are Baseline 2024. `overlay` is Chromium only, and browsers without support show and hide instantly.
|
|
102
|
+
|
|
103
|
+
## Exit animations
|
|
104
|
+
|
|
105
|
+
### Subtle exit
|
|
106
|
+
|
|
107
|
+
```tsx
|
|
108
|
+
<motion.div
|
|
109
|
+
exit={{
|
|
110
|
+
opacity: 0,
|
|
111
|
+
y: -12,
|
|
112
|
+
filter: "blur(4px)",
|
|
113
|
+
transition: { duration: 0.15, ease: "easeOut" },
|
|
114
|
+
}}
|
|
115
|
+
>
|
|
116
|
+
{content}
|
|
117
|
+
</motion.div>
|
|
118
|
+
```
|
|
119
|
+
|
|
120
|
+
### Full exit
|
|
121
|
+
|
|
122
|
+
Slide fully out only where the destination carries meaning, such as a card returning to a list or a drawer closing:
|
|
123
|
+
|
|
124
|
+
```tsx
|
|
125
|
+
<motion.div
|
|
126
|
+
exit={{
|
|
127
|
+
opacity: 0,
|
|
128
|
+
x: "-100%",
|
|
129
|
+
transition: { duration: 0.2, ease: "easeOut" },
|
|
130
|
+
}}
|
|
131
|
+
>
|
|
132
|
+
{content}
|
|
133
|
+
</motion.div>
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
### Good and bad
|
|
137
|
+
|
|
138
|
+
```css
|
|
139
|
+
/* Good: subtle exit */
|
|
140
|
+
.item-exit {
|
|
141
|
+
opacity: 0;
|
|
142
|
+
transform: translateY(-12px);
|
|
143
|
+
transition: opacity 150ms ease-out, transform 150ms ease-out;
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
/* Bad: dramatic exit that steals focus */
|
|
147
|
+
.item-exit {
|
|
148
|
+
opacity: 0;
|
|
149
|
+
transform: translateY(-100%) scale(0.5);
|
|
150
|
+
transition: all 400ms ease-out;
|
|
151
|
+
}
|
|
152
|
+
|
|
153
|
+
/* Sometimes correct: remove at once when motion adds no information */
|
|
154
|
+
.item-exit {
|
|
155
|
+
display: none;
|
|
156
|
+
}
|
|
157
|
+
```
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# Icon transitions
|
|
2
|
+
|
|
3
|
+
Cross-fade recipes for an icon that swaps on a state change, with and without a motion library. Icon weight, color and direction live in [icons.md](icons.md).
|
|
4
|
+
|
|
5
|
+
## Which library
|
|
6
|
+
|
|
7
|
+
Check the project's `package.json`. Import from `"motion/react"` when `motion` is installed, or `"framer-motion"` when that is. Where both exist, follow the imports the component or its nearest peers already use. Where neither is present, use the CSS cross-fade and never add a dependency just for icon transitions.
|
|
8
|
+
|
|
9
|
+
## Motion
|
|
10
|
+
|
|
11
|
+
```tsx
|
|
12
|
+
import { AnimatePresence, motion } from "motion/react";
|
|
13
|
+
|
|
14
|
+
function IconButton({ isActive, icon: Icon }) {
|
|
15
|
+
return (
|
|
16
|
+
<button>
|
|
17
|
+
<AnimatePresence initial={false} mode="popLayout">
|
|
18
|
+
<motion.span
|
|
19
|
+
key={isActive ? "active" : "inactive"}
|
|
20
|
+
initial={{ opacity: 0, scale: 0.25, filter: "blur(4px)" }}
|
|
21
|
+
animate={{ opacity: 1, scale: 1, filter: "blur(0px)" }}
|
|
22
|
+
exit={{ opacity: 0, scale: 0.25, filter: "blur(4px)" }}
|
|
23
|
+
transition={{ type: "spring", duration: 0.3, bounce: 0 }}
|
|
24
|
+
>
|
|
25
|
+
<Icon />
|
|
26
|
+
</motion.span>
|
|
27
|
+
</AnimatePresence>
|
|
28
|
+
</button>
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
```
|
|
32
|
+
|
|
33
|
+
`initial={false}` keeps the default icon from animating in on mount.
|
|
34
|
+
|
|
35
|
+
## CSS, both icons in the DOM
|
|
36
|
+
|
|
37
|
+
Both icons stay mounted in one grid cell, so enter and exit both animate and the larger icon sets the size. The `motion-reduce:` classes leave only the opacity fade under reduced motion.
|
|
38
|
+
|
|
39
|
+
```tsx
|
|
40
|
+
const layer = cn(
|
|
41
|
+
"[grid-area:1/1] transition-[opacity,filter,scale] duration-300",
|
|
42
|
+
"ease-[cubic-bezier(0.2,0,0,1)]",
|
|
43
|
+
"motion-reduce:scale-100 motion-reduce:blur-[0px]"
|
|
44
|
+
);
|
|
45
|
+
const shown = "scale-100 opacity-100 blur-[0px]";
|
|
46
|
+
const hidden = "scale-[0.25] opacity-0 blur-[4px]";
|
|
47
|
+
|
|
48
|
+
function IconButton({ isActive, ActiveIcon, InactiveIcon }) {
|
|
49
|
+
return (
|
|
50
|
+
<button>
|
|
51
|
+
<span className="grid place-items-center">
|
|
52
|
+
<span className={cn(layer, isActive ? shown : hidden)}>
|
|
53
|
+
<ActiveIcon />
|
|
54
|
+
</span>
|
|
55
|
+
<span className={cn(layer, isActive ? hidden : shown)}>
|
|
56
|
+
<InactiveIcon />
|
|
57
|
+
</span>
|
|
58
|
+
</span>
|
|
59
|
+
</button>
|
|
60
|
+
);
|
|
61
|
+
}
|
|
62
|
+
```
|
|
63
|
+
|
|
64
|
+
Tailwind 4's `scale-*` utilities write the `scale` property, so `transition-[...scale]` animates them. Tailwind 3's write `transform`, so name `transform` in the transition instead.
|
|
65
|
+
|
|
66
|
+
## Which icons animate
|
|
67
|
+
|
|
68
|
+
| Animate | Don't animate |
|
|
69
|
+
| --- | --- |
|
|
70
|
+
| Infrequent state swaps such as play to pause, like to liked or copy to copied | Hover-revealed actions in list rows |
|
|
71
|
+
| Icons in a toolbar that appears on selection | Tab and navigation icon swaps |
|
|
72
|
+
| Loading and success indicators | Decorative or always-visible icons |
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
# Icons
|
|
2
|
+
|
|
3
|
+
Icon stroke weight, sizing, state colors, variants and RTL mirroring.
|
|
4
|
+
|
|
5
|
+
## Match icon stroke to text weight
|
|
6
|
+
|
|
7
|
+
| Adjacent text | Rendered stroke width |
|
|
8
|
+
| --- | --- |
|
|
9
|
+
| Regular (400), 14–16px | `1.5px` |
|
|
10
|
+
| Medium or semibold (500–600) | `2px` |
|
|
11
|
+
| Bold (700), or an emphasized standalone icon | `2.5px` |
|
|
12
|
+
|
|
13
|
+
The widths are rendered pixels. A 24px-grid icon drawn at 16px scales its stroke by 16/24, so `stroke-width="2"` paints about `1.33px`. Use the library's absolute-stroke option, such as Lucide's `absoluteStrokeWidth`, or set `vector-effect: non-scaling-stroke` on the SVG's shapes.
|
|
14
|
+
|
|
15
|
+
```tsx
|
|
16
|
+
// Good: stroke tuned to the semibold label
|
|
17
|
+
<button className="flex items-center gap-2 font-semibold">
|
|
18
|
+
<Plus size={16} strokeWidth={2} absoluteStrokeWidth />
|
|
19
|
+
New project
|
|
20
|
+
</button>
|
|
21
|
+
|
|
22
|
+
// Bad: 1.5px stroke against a bold label
|
|
23
|
+
<button className="flex items-center gap-2 font-bold">
|
|
24
|
+
<Plus size={16} strokeWidth={1.5} absoluteStrokeWidth />
|
|
25
|
+
New project
|
|
26
|
+
</button>
|
|
27
|
+
```
|
|
28
|
+
|
|
29
|
+
- **One library per surface.** Never mix icon libraries on one toolbar. Where the library has no stroke variants, keep its native stroke and use size or color for emphasis.
|
|
30
|
+
- **Size inline icons at `1em`–`1.25em`** of the adjacent font size, so the pair scales together.
|
|
31
|
+
|
|
32
|
+
## One SVG, recolored per state
|
|
33
|
+
|
|
34
|
+
Draw every icon with `currentColor` and let CSS state drive the color. Strip hardcoded fills such as `fill="#666"` to `currentColor` when importing icons.
|
|
35
|
+
|
|
36
|
+
```html
|
|
37
|
+
<svg fill="none" stroke="currentColor" stroke-width="2">…</svg>
|
|
38
|
+
```
|
|
39
|
+
|
|
40
|
+
```css
|
|
41
|
+
/* Use the project's color tokens */
|
|
42
|
+
.icon-button { color: var(--icon-muted); }
|
|
43
|
+
.icon-button:hover { color: var(--icon-strong); }
|
|
44
|
+
.icon-button[aria-pressed="true"] { color: var(--icon-active); }
|
|
45
|
+
.icon-button:disabled { opacity: 0.4; }
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
```html
|
|
49
|
+
<!-- Tailwind, with the project's token names -->
|
|
50
|
+
<button class="text-icon-muted hover:text-icon-strong aria-pressed:text-icon-active disabled:opacity-40">
|
|
51
|
+
<BookmarkIcon />
|
|
52
|
+
</button>
|
|
53
|
+
```
|
|
54
|
+
|
|
55
|
+
## Outline default, fill active
|
|
56
|
+
|
|
57
|
+
Where an icon set offers outline and filled variants, use them as a state pair, never interchangeably:
|
|
58
|
+
|
|
59
|
+
| Variant | Use for |
|
|
60
|
+
| --- | --- |
|
|
61
|
+
| Outline | Default state in toolbars, list rows and inline text |
|
|
62
|
+
| Fill | Selected or active state, such as the active tab, a toggled bookmark or a liked heart |
|
|
63
|
+
|
|
64
|
+
```tsx
|
|
65
|
+
// Good: variant communicates state
|
|
66
|
+
<TabIcon variant={isActive ? "solid" : "outline"} />
|
|
67
|
+
|
|
68
|
+
// Bad: filled everywhere, so the active tab has no state signal
|
|
69
|
+
<TabIcon variant="solid" />
|
|
70
|
+
```
|
|
71
|
+
|
|
72
|
+
Cross-fade the swap with the values in [icon-transitions.md](icon-transitions.md) only where the change is infrequent, such as a bookmark or a like. An active tab swaps instantly.
|
|
73
|
+
|
|
74
|
+
## Design at render size
|
|
75
|
+
|
|
76
|
+
- Test every icon at the smallest size it renders, often `16px`. It must stay recognizable there.
|
|
77
|
+
- Prefer a simplified glyph for small contexts over scaling down detailed artwork.
|
|
78
|
+
- Where the set ships per-size grids such as `16`, `20` and `24`, use the grid that matches the render size. A 24px drawing scaled to 16px lands off the pixel grid and renders soft.
|
|
79
|
+
- Always SVG, never raster.
|
|
80
|
+
|
|
81
|
+
## Icons in RTL
|
|
82
|
+
|
|
83
|
+
Under `dir="rtl"`, flip icons whose meaning is tied to reading direction, and leave the rest alone:
|
|
84
|
+
|
|
85
|
+
| Flip | Don't flip |
|
|
86
|
+
| --- | --- |
|
|
87
|
+
| Back and forward arrows, navigation chevrons | Logos and brand marks |
|
|
88
|
+
| Text-block glyphs for alignment, lists and indent | Checkmarks |
|
|
89
|
+
| Speaker and volume waves | Physical objects such as clocks, cups and pencils |
|
|
90
|
+
| Directional glyphs such as "send" | Media playback, which stays LTR by convention |
|
|
91
|
+
|
|
92
|
+
Use one mechanism per element. Two flips on one icon can compound back to unflipped.
|
|
93
|
+
|
|
94
|
+
```css
|
|
95
|
+
[dir="rtl"] .icon-directional {
|
|
96
|
+
scale: -1 1;
|
|
97
|
+
}
|
|
98
|
+
```
|
|
99
|
+
|
|
100
|
+
```tsx
|
|
101
|
+
// Tailwind
|
|
102
|
+
<ChevronRightIcon className="rtl:-scale-x-100" />
|
|
103
|
+
```
|
|
104
|
+
|
|
105
|
+
Analyze composite icons part by part. A badge or slash overlay may keep its position while the base glyph flips. Accessible names for icon-only buttons belong to `accessibility`.
|