@rt-tools/agent-kit 0.33.1 → 0.34.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 +8 -7
- package/assets/agents/goal-critic.md +67 -0
- package/assets/agents/product-strategist.md +90 -0
- package/assets/agents/qa-engineer.md +3 -0
- package/assets/checks/check-specs.mjs +11 -2
- package/assets/checks/rt-kit-checks.config.mjs +6 -0
- package/assets/checks/spec-common.mjs +6 -3
- package/assets/checks/spec-scenarios.mjs +9 -1
- package/assets/checks/task-new.github.mjs +6 -0
- package/assets/defaults/project.sh +10 -81
- package/assets/defaults/push.sh +100 -0
- package/assets/docs/GLOSSARY.md +4 -0
- package/assets/hooks/browser-guard-no-other-drivers.sh +6 -3
- package/assets/hooks/claim-guard.sh +6 -6
- package/assets/hooks/dispatch.sh +56 -3
- package/assets/hooks/exam-guard.sh +1 -1
- package/assets/hooks/git-guard-delivery-body.sh +25 -3
- package/assets/hooks/git-guard-delivery-folder.sh +17 -1
- package/assets/hooks/git-guard-delivery-pipeline.sh +99 -0
- package/assets/hooks/git-guard-delivery.sh +17 -10
- package/assets/hooks/git-guard-main.sh +17 -4
- package/assets/hooks/git-guard-push-ahead.sh +89 -0
- package/assets/hooks/git-guard-push-marks.sh +99 -0
- package/assets/hooks/git-guard-push-tests.sh +101 -83
- package/assets/hooks/pre-push.sh +113 -0
- package/assets/hooks/push-set.sh +150 -0
- package/assets/hooks/push-sign.sh +433 -0
- package/assets/hooks/rerun-guard.sh +14 -6
- package/assets/hooks/turn-exit-guard.sh +2 -2
- package/assets/hooks/turn-exit-patterns.sh +4 -3
- package/assets/hooks/turn-exit-verdict.sh +18 -1
- package/assets/hooks/waiting-turn-guard.sh +2 -1
- package/assets/hooks/write-targets.sh +21 -0
- package/assets/patterns/git-workflow-commit.github.md +11 -0
- package/assets/patterns/git-workflow-pr-body.github.md +20 -3
- package/assets/patterns/git-workflow-pr.azure.md +30 -0
- package/assets/patterns/git-workflow-pr.github.md +57 -1
- package/assets/patterns/git-workflow-pr.gitlab.md +33 -0
- package/assets/patterns/mockups-measure.needs-mockups.md +19 -3
- package/assets/patterns/task-flow-close.md +27 -16
- package/assets/patterns/task-flow-start.md +3 -3
- package/assets/rules/browser-verification.md +4 -0
- package/assets/rules/deploy-flow.azure.md +5 -0
- package/assets/rules/deploy-flow.github.md +5 -0
- package/assets/rules/deploy-flow.gitlab.md +5 -0
- package/assets/rules/git-workflow.azure.md +15 -0
- package/assets/rules/git-workflow.github.md +15 -0
- package/assets/rules/git-workflow.gitlab.md +15 -0
- package/assets/rules/mockups.needs-mockups.md +13 -5
- package/assets/rules/task-flow.md +21 -16
- package/assets/samples/tasks/_template/plan.md +7 -0
- package/assets/skills/interface-review-annotate.needs-mockups.md +142 -0
- package/assets/skills/interface-review-icons.needs-app.md +136 -0
- package/assets/skills/interface-review-motion-states.needs-app.md +230 -0
- package/assets/skills/interface-review-motion.needs-app.md +209 -0
- package/assets/skills/interface-review-performance.needs-app.md +110 -0
- package/assets/skills/interface-review-principles.needs-app.md +263 -0
- package/assets/skills/interface-review-surfaces.needs-app.md +249 -0
- package/assets/skills/interface-review.needs-app.md +199 -0
- package/assets/skills/write-a-skill.md +16 -3
- package/assets/workflows/feature.js +33 -5
- package/assets/workflows/plan.js +71 -4
- package/package.json +1 -1
|
@@ -0,0 +1,142 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: interface-review-annotate
|
|
3
|
+
description: Puts the findings of an interface review on a Figma canvas as cards beside the frame: card anatomy, the Plugin API build sequence, placement, connectors. Load when a reviewed Figma frame is to be annotated. The review itself is in interface-review.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Annotate the frame
|
|
7
|
+
|
|
8
|
+
## When to use
|
|
9
|
+
|
|
10
|
+
- An interface review by `interface-review` ran on a Figma frame, and its findings table is ready.
|
|
11
|
+
- The annotations of an earlier review are to be replaced after a re-run.
|
|
12
|
+
|
|
13
|
+
Every row in the findings table also lands on the canvas as a card. Cards go on one top-level layer
|
|
14
|
+
named `Interface review`, in the empty space to the left and right of the frame — never on top of
|
|
15
|
+
the design, and never overlapping the frame's own titles or chrome.
|
|
16
|
+
|
|
17
|
+
Never reparent, edit, lock, or restyle the frames under review. Annotations are additive; the review
|
|
18
|
+
is otherwise read-only.
|
|
19
|
+
|
|
20
|
+
## Card anatomy
|
|
21
|
+
|
|
22
|
+
Each card is a vertical auto-layout frame: `280px` fixed width, height hugging its contents, `12px`
|
|
23
|
+
padding, `8px` item spacing, `8px` corner radius, `oklch(1 0 0)` fill, `1px` `oklch(0 0 0 / 0.08)`
|
|
24
|
+
stroke.
|
|
25
|
+
|
|
26
|
+
Three stacked children, in order:
|
|
27
|
+
|
|
28
|
+
1. **Severity pill** — hug-width rounded rect, `4px` radius, `2px` vertical and `6px` horizontal
|
|
29
|
+
padding, filled with the severity color below. Label is the severity word in uppercase, `9px`,
|
|
30
|
+
weight `600`, `0.04em` letter-spacing.
|
|
31
|
+
2. **Title** — `#4 CTA contrast`. The finding number, then a three-to-five-word summary. `12px`,
|
|
32
|
+
weight `600`, `oklch(0.15 0 0)`.
|
|
33
|
+
3. **Body** — one or two sentences: what is wrong, then what to do. `11px`, weight `400`,
|
|
34
|
+
line-height `1.4`, `oklch(0.45 0 0)`. Cap at `240` characters; the full reasoning stays in the
|
|
35
|
+
findings table.
|
|
36
|
+
|
|
37
|
+
| Severity | Pill fill | Pill text |
|
|
38
|
+
| --- | --- | --- |
|
|
39
|
+
| `HIGH` | `oklch(0.577 0.245 27.325)` red | `oklch(1 0 0)` white |
|
|
40
|
+
| `MEDIUM` | `oklch(0.705 0.213 47.604)` orange | `oklch(0.15 0 0)` near-black |
|
|
41
|
+
| `LOW` | `oklch(0.852 0.199 91.936)` yellow | `oklch(0.15 0 0)` near-black |
|
|
42
|
+
|
|
43
|
+
White on orange and yellow measures below 4.5:1; use the near-black. The pill names the severity in
|
|
44
|
+
words, so color never carries it alone and no separate legend is needed.
|
|
45
|
+
|
|
46
|
+
## Building the card
|
|
47
|
+
|
|
48
|
+
Hug sizing is not the default, and children only participate in auto-layout once appended. Follow
|
|
49
|
+
this sequence exactly:
|
|
50
|
+
|
|
51
|
+
```js
|
|
52
|
+
await figma.loadFontAsync({ family: "Inter", style: "Semi Bold" });
|
|
53
|
+
await figma.loadFontAsync({ family: "Inter", style: "Regular" });
|
|
54
|
+
|
|
55
|
+
const card = figma.createFrame();
|
|
56
|
+
card.layoutMode = "VERTICAL"; // must come before any sizing property
|
|
57
|
+
card.primaryAxisSizingMode = "AUTO"; // hug height
|
|
58
|
+
card.counterAxisSizingMode = "FIXED"; // fixed width
|
|
59
|
+
card.resize(280, card.height);
|
|
60
|
+
card.verticalPadding = 12;
|
|
61
|
+
card.horizontalPadding = 12;
|
|
62
|
+
card.itemSpacing = 8;
|
|
63
|
+
|
|
64
|
+
// Children must be appended to the card. Creating a node and setting its
|
|
65
|
+
// x/y puts it on the canvas as a sibling: the card then hugs to nothing
|
|
66
|
+
// and its contents float outside the frame.
|
|
67
|
+
card.appendChild(pill);
|
|
68
|
+
card.appendChild(title);
|
|
69
|
+
card.appendChild(body);
|
|
70
|
+
|
|
71
|
+
// Text wraps to the card width and grows downward
|
|
72
|
+
for (const text of [title, body]) {
|
|
73
|
+
text.layoutAlign = "STRETCH";
|
|
74
|
+
text.textAutoResize = "HEIGHT";
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
// The pill hugs its own label instead of stretching
|
|
78
|
+
pill.layoutMode = "HORIZONTAL";
|
|
79
|
+
pill.primaryAxisSizingMode = "AUTO";
|
|
80
|
+
pill.counterAxisSizingMode = "AUTO";
|
|
81
|
+
pill.layoutAlign = "INHERIT";
|
|
82
|
+
pillLabel.textAutoResize = "WIDTH_AND_HEIGHT";
|
|
83
|
+
|
|
84
|
+
// x and y are ignored on auto-layout children. Position the card only.
|
|
85
|
+
card.x = gutterX;
|
|
86
|
+
card.y = stackY;
|
|
87
|
+
```
|
|
88
|
+
|
|
89
|
+
Load every font with `figma.loadFontAsync` before setting `characters`. Text set with an unloaded
|
|
90
|
+
font measures at zero, so the card hugs to nothing.
|
|
91
|
+
|
|
92
|
+
Gate on the result before positioning anything else:
|
|
93
|
+
|
|
94
|
+
```js
|
|
95
|
+
if (card.children.length !== 3 || card.height < 56) {
|
|
96
|
+
throw new Error(
|
|
97
|
+
`Finding ${n}: card built empty — ${card.children.length} children, ${card.height}px tall`
|
|
98
|
+
);
|
|
99
|
+
}
|
|
100
|
+
```
|
|
101
|
+
|
|
102
|
+
A correctly built card is at least `56px` tall. Anything near `26px` is padding with no content in
|
|
103
|
+
between.
|
|
104
|
+
|
|
105
|
+
| Symptom | Cause |
|
|
106
|
+
| --- | --- |
|
|
107
|
+
| Card hugs to ~`26px` with contents floating outside it | Children created but never `appendChild`ed to the card |
|
|
108
|
+
| Every card is the same height | `primaryAxisSizingMode` left at `FIXED` |
|
|
109
|
+
| Card is as wide as its longest line | `counterAxisSizingMode` left at `AUTO` |
|
|
110
|
+
| Body text runs off the card on one line | Text missing `layoutAlign = "STRETCH"` and `textAutoResize = "HEIGHT"` |
|
|
111
|
+
| Pill spans the full card width | Pill missing `AUTO` sizing on both axes |
|
|
112
|
+
| Children ignore the positions you set | Expected — auto-layout owns child position; set `x`/`y` on the card only |
|
|
113
|
+
|
|
114
|
+
## Placement
|
|
115
|
+
|
|
116
|
+
Cards sit in two gutters: one starting `80px` to the left of the frame, one `80px` to the right.
|
|
117
|
+
Assign each card to the gutter nearer its target node, then within a gutter sort by the target's
|
|
118
|
+
vertical position and stack top to bottom with `16px` between cards. If a stack would run past the
|
|
119
|
+
frame's bottom edge, move the overflow to the other gutter rather than shrinking cards or letting
|
|
120
|
+
them overlap.
|
|
121
|
+
|
|
122
|
+
Position cards only after all children are appended and sized; a card's final height is not known
|
|
123
|
+
until then.
|
|
124
|
+
|
|
125
|
+
Draw a `1.5px` dashed connector from the card's inner edge to the target node's nearest edge,
|
|
126
|
+
stroked in that finding's severity color, routed as a single elbow: horizontal out of the card, then
|
|
127
|
+
horizontal into the node. End it with a `4px` dot on the node, not an arrowhead. A finding that spans
|
|
128
|
+
the whole flow gets no connector.
|
|
129
|
+
|
|
130
|
+
Card and connector for one finding are grouped together and named `#4 MEDIUM Layout`.
|
|
131
|
+
|
|
132
|
+
## Scale
|
|
133
|
+
|
|
134
|
+
The values above assume a frame between `1000px` and `1600px` wide. Outside that range, multiply
|
|
135
|
+
every annotation dimension and type size by `frameWidth / 1400` so cards stay readable at the zoom
|
|
136
|
+
level where the whole frame fits on screen.
|
|
137
|
+
|
|
138
|
+
## Re-running
|
|
139
|
+
|
|
140
|
+
Delete the existing `Interface review` layer before drawing the new one. Annotations replace; they
|
|
141
|
+
never stack. If the file is view-only or the user asked for the report only, output the table alone
|
|
142
|
+
and say the frame was not annotated.
|
|
@@ -0,0 +1,136 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: interface-review-icons
|
|
3
|
+
description: Icon recipes for an interface review: stroke matched to text weight, one SVG recolored per state, outline by default and fill when active, render size, RTL mirroring. Load when an icon finding is worded or fixed. Icon swaps are in interface-review-motion-states.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Icons
|
|
7
|
+
|
|
8
|
+
Icon weight, states, sizing, and direction: the details that make icons sit naturally in an
|
|
9
|
+
interface.
|
|
10
|
+
|
|
11
|
+
## When to use
|
|
12
|
+
|
|
13
|
+
- A finding of `interface-review` is about an icon that looks too heavy or too thin, separate icon
|
|
14
|
+
assets per state, filled icons everywhere, an icon that blurs at small size, or an arrow that
|
|
15
|
+
points the wrong way in RTL.
|
|
16
|
+
|
|
17
|
+
## Match Icon Stroke to Text Weight
|
|
18
|
+
|
|
19
|
+
An icon next to text should carry the same optical weight as the text, or the pair looks mismatched:
|
|
20
|
+
a hairline icon beside semibold text reads as broken, a heavy icon beside regular text shouts.
|
|
21
|
+
|
|
22
|
+
| Adjacent text | Icon stroke width (24px grid) |
|
|
23
|
+
| --- | --- |
|
|
24
|
+
| Regular (400), 14–16px | `1.5px` |
|
|
25
|
+
| Medium/Semibold (500–600) | `2px` |
|
|
26
|
+
| Bold (700), or emphasized standalone | `2.5px` |
|
|
27
|
+
|
|
28
|
+
```html
|
|
29
|
+
<!-- Good: stroke tuned to the label weight -->
|
|
30
|
+
<button class="flex items-center gap-2 font-semibold">
|
|
31
|
+
<PlusIcon stroke-width="2" class="size-4" />
|
|
32
|
+
New project
|
|
33
|
+
</button>
|
|
34
|
+
|
|
35
|
+
<!-- Bad: default 1.5px stroke against a bold label -->
|
|
36
|
+
<button class="flex items-center gap-2 font-bold">
|
|
37
|
+
<PlusIcon stroke-width="1.5" class="size-4" />
|
|
38
|
+
New project
|
|
39
|
+
</button>
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
Two related consistency rules:
|
|
43
|
+
|
|
44
|
+
- **One optical strategy per surface.** Do not mix icon libraries with incompatible stroke
|
|
45
|
+
conventions on one toolbar. If the chosen library intentionally supports stroke variants, match
|
|
46
|
+
them to adjacent text as above; otherwise preserve the set's native stroke and use size or color
|
|
47
|
+
for emphasis.
|
|
48
|
+
- **Size icons relative to the text's cap height**, typically `1em`–`1.25em` when inline with text,
|
|
49
|
+
so the pair scales together.
|
|
50
|
+
|
|
51
|
+
## One SVG, Recolored per State
|
|
52
|
+
|
|
53
|
+
Never ship separate icon assets for default/hover/selected/disabled states. Use a single SVG drawn
|
|
54
|
+
with `currentColor` and let CSS state drive the color:
|
|
55
|
+
|
|
56
|
+
```html
|
|
57
|
+
<!-- Good: one asset, states are CSS -->
|
|
58
|
+
<svg fill="none" stroke="currentColor" stroke-width="2">…</svg>
|
|
59
|
+
```
|
|
60
|
+
|
|
61
|
+
```css
|
|
62
|
+
.icon-button { color: oklch(0.552 0.016 285.938); }
|
|
63
|
+
.icon-button:hover { color: oklch(0.21 0.006 285.885); }
|
|
64
|
+
.icon-button[aria-pressed="true"] { color: oklch(0.623 0.188 259.815); }
|
|
65
|
+
.icon-button:disabled { opacity: 0.4; }
|
|
66
|
+
```
|
|
67
|
+
|
|
68
|
+
```html
|
|
69
|
+
<!-- Tailwind -->
|
|
70
|
+
<button class="text-zinc-500 hover:text-zinc-900 aria-pressed:text-blue-600 disabled:opacity-40">
|
|
71
|
+
<BookmarkIcon />
|
|
72
|
+
</button>
|
|
73
|
+
```
|
|
74
|
+
|
|
75
|
+
Hardcoded fills inside the SVG (`fill="#666"`) break this; strip them to `currentColor` when
|
|
76
|
+
importing icons.
|
|
77
|
+
|
|
78
|
+
## Outline Default, Fill Active
|
|
79
|
+
|
|
80
|
+
When an icon set offers outline and filled variants, use them as a state pair, not interchangeably:
|
|
81
|
+
|
|
82
|
+
| Variant | Use for |
|
|
83
|
+
| --- | --- |
|
|
84
|
+
| Outline | Default state: toolbars, list rows, inline with text |
|
|
85
|
+
| Fill | Selected/active state: the active tab, a toggled bookmark, a liked heart |
|
|
86
|
+
|
|
87
|
+
```tsx
|
|
88
|
+
// Good: variant communicates state
|
|
89
|
+
<TabIcon variant={isActive ? "solid" : "outline"} />
|
|
90
|
+
|
|
91
|
+
// Bad: filled icons everywhere, so the active tab has no state signal
|
|
92
|
+
<TabIcon variant="solid" />
|
|
93
|
+
```
|
|
94
|
+
|
|
95
|
+
The swap between variants is a contextual icon animation; use the exact cross-fade values in
|
|
96
|
+
`interface-review-motion-states`.
|
|
97
|
+
|
|
98
|
+
## Design at Render Size
|
|
99
|
+
|
|
100
|
+
An icon that looks great at 48px can collapse into mush at 16px. Details that read at large sizes
|
|
101
|
+
(thin interior lines, tight counters, fine texture) blur or alias when small.
|
|
102
|
+
|
|
103
|
+
- Test every icon at the smallest size it will render (often `16px`); it must stay recognizable
|
|
104
|
+
there.
|
|
105
|
+
- Prefer simplified glyphs for small contexts over scaling down detailed artwork.
|
|
106
|
+
- Keep icons on the pixel grid at their render size: a 16px icon drawn on a 24px grid with
|
|
107
|
+
fractional scaling renders soft. Use the icon set's native grid sizes (`16`, `20`, `24`) rather
|
|
108
|
+
than arbitrary scales.
|
|
109
|
+
- Always SVG, never raster, so the same asset stays crisp at every density.
|
|
110
|
+
|
|
111
|
+
## Icons in RTL
|
|
112
|
+
|
|
113
|
+
Under `dir="rtl"`, flip icons whose meaning is tied to reading direction, and leave the rest alone:
|
|
114
|
+
|
|
115
|
+
| Flip | Don't flip |
|
|
116
|
+
| --- | --- |
|
|
117
|
+
| Back/forward arrows, chevrons in navigation | Logos and brand marks |
|
|
118
|
+
| Text-block glyphs (alignment, lists, indent) | Checkmarks |
|
|
119
|
+
| Speaker/volume waves (emanate in reading direction) | Physical objects: clocks, cups, pencils |
|
|
120
|
+
| "Send" style directional glyphs | Media playback (play/rewind refer to tape direction, convention keeps them LTR) |
|
|
121
|
+
|
|
122
|
+
```css
|
|
123
|
+
/* Good: mirror only direction-dependent icons */
|
|
124
|
+
[dir="rtl"] .icon-directional {
|
|
125
|
+
scale: -1 1;
|
|
126
|
+
}
|
|
127
|
+
```
|
|
128
|
+
|
|
129
|
+
```html
|
|
130
|
+
<!-- Tailwind -->
|
|
131
|
+
<ChevronRightIcon class="icon-directional rtl:-scale-x-100" />
|
|
132
|
+
```
|
|
133
|
+
|
|
134
|
+
Analyze composite icons part by part: a badge or slash overlay may keep its position even when the
|
|
135
|
+
base glyph flips. Accessible names for icon-only buttons are covered by the accessibility principles
|
|
136
|
+
in `interface-review-principles`.
|
|
@@ -0,0 +1,230 @@
|
|
|
1
|
+
---
|
|
2
|
+
name: interface-review-motion-states
|
|
3
|
+
description: Recipes for animated state changes in an interface review: contextual icon swaps with exact values, scale on press, no animation on page load, with CSS, Tailwind and Motion code. Load when such a finding is worded or fixed. Entrances and exits are in interface-review-motion.
|
|
4
|
+
---
|
|
5
|
+
|
|
6
|
+
# Animated state changes
|
|
7
|
+
|
|
8
|
+
Contextual icon animations, scale on press and skipping animation on page load. Interruptible
|
|
9
|
+
animations, entrances and exits are in `interface-review-motion`; its scope applies here too.
|
|
10
|
+
|
|
11
|
+
## When to use
|
|
12
|
+
|
|
13
|
+
- A finding of `interface-review` is about an icon that pops instead of animating, missing press
|
|
14
|
+
feedback, or a toggle that animates its default state on page load.
|
|
15
|
+
|
|
16
|
+
## Contextual Icon Animations
|
|
17
|
+
|
|
18
|
+
When icons appear or disappear contextually (on hover, on state change), animate them with
|
|
19
|
+
`opacity`, `scale`, and `blur` rather than just toggling visibility.
|
|
20
|
+
|
|
21
|
+
### Motion Example
|
|
22
|
+
|
|
23
|
+
This example uses the `motion` package. If the project instead has `framer-motion`, import the same
|
|
24
|
+
APIs from `"framer-motion"`; never mix an installed package with the other package's import path.
|
|
25
|
+
|
|
26
|
+
```tsx
|
|
27
|
+
import { AnimatePresence, motion } from "motion/react";
|
|
28
|
+
|
|
29
|
+
function IconButton({ isActive, icon: Icon }) {
|
|
30
|
+
return (
|
|
31
|
+
<button>
|
|
32
|
+
<AnimatePresence mode="popLayout">
|
|
33
|
+
<motion.span
|
|
34
|
+
key={isActive ? "active" : "inactive"}
|
|
35
|
+
initial={{ opacity: 0, scale: 0.25, filter: "blur(4px)" }}
|
|
36
|
+
animate={{ opacity: 1, scale: 1, filter: "blur(0px)" }}
|
|
37
|
+
exit={{ opacity: 0, scale: 0.25, filter: "blur(4px)" }}
|
|
38
|
+
transition={{ type: "spring", duration: 0.3, bounce: 0 }}
|
|
39
|
+
>
|
|
40
|
+
<Icon />
|
|
41
|
+
</motion.span>
|
|
42
|
+
</AnimatePresence>
|
|
43
|
+
</button>
|
|
44
|
+
);
|
|
45
|
+
}
|
|
46
|
+
```
|
|
47
|
+
|
|
48
|
+
### CSS Transition Approach (No Motion)
|
|
49
|
+
|
|
50
|
+
If the project doesn't use Motion (Framer Motion), keep both icons in the DOM and cross-fade them
|
|
51
|
+
with CSS transitions. Because neither icon unmounts, both enter and exit animate smoothly.
|
|
52
|
+
|
|
53
|
+
The trick: one icon is absolutely positioned on top of the other. Toggling state cross-fades them:
|
|
54
|
+
the entering icon scales up from `0.25` while the exiting icon scales down to `0.25`, both with
|
|
55
|
+
opacity and blur.
|
|
56
|
+
|
|
57
|
+
```tsx
|
|
58
|
+
function IconButton({ isActive, ActiveIcon, InactiveIcon }) {
|
|
59
|
+
return (
|
|
60
|
+
<button>
|
|
61
|
+
<div className="relative">
|
|
62
|
+
<div
|
|
63
|
+
className={cn(
|
|
64
|
+
"absolute inset-0 flex items-center justify-center",
|
|
65
|
+
"transition-[opacity,filter,scale] duration-300",
|
|
66
|
+
"ease-[cubic-bezier(0.2,0,0,1)]",
|
|
67
|
+
isActive
|
|
68
|
+
? "scale-100 opacity-100 blur-0"
|
|
69
|
+
: "scale-[0.25] opacity-0 blur-[4px]"
|
|
70
|
+
)}
|
|
71
|
+
>
|
|
72
|
+
<ActiveIcon />
|
|
73
|
+
</div>
|
|
74
|
+
<div
|
|
75
|
+
className={cn(
|
|
76
|
+
"transition-[opacity,filter,scale] duration-300",
|
|
77
|
+
"ease-[cubic-bezier(0.2,0,0,1)]",
|
|
78
|
+
isActive
|
|
79
|
+
? "scale-[0.25] opacity-0 blur-[4px]"
|
|
80
|
+
: "scale-100 opacity-100 blur-0"
|
|
81
|
+
)}
|
|
82
|
+
>
|
|
83
|
+
<InactiveIcon />
|
|
84
|
+
</div>
|
|
85
|
+
</div>
|
|
86
|
+
</button>
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
```
|
|
90
|
+
|
|
91
|
+
The non-absolute icon (InactiveIcon) defines the layout size. The absolute icon (ActiveIcon)
|
|
92
|
+
overlays it without affecting flow.
|
|
93
|
+
|
|
94
|
+
### Choosing Between Motion and CSS
|
|
95
|
+
|
|
96
|
+
| | Motion (Framer Motion) | CSS transitions (both icons in DOM) |
|
|
97
|
+
| --- | --- | --- |
|
|
98
|
+
| **Enter animation** | Yes | Yes |
|
|
99
|
+
| **Exit animation** | Yes (via `AnimatePresence`) | Yes (cross-fade, icon never unmounts) |
|
|
100
|
+
| **Spring physics** | Yes | No, use `cubic-bezier(0.2, 0, 0, 1)` as approximation |
|
|
101
|
+
| **When to use** | Project already uses `motion` or `framer-motion` | No motion dependency, or keeping bundle small |
|
|
102
|
+
|
|
103
|
+
**Rule:** Check the project's `package.json`. Import from `"motion/react"` when `motion` is
|
|
104
|
+
installed, or from `"framer-motion"` when `framer-motion` is installed. If both exist, follow the
|
|
105
|
+
imports already used by the component or its nearest peers. If neither is present, use the CSS
|
|
106
|
+
cross-fade pattern; don't add a dependency just for icon transitions.
|
|
107
|
+
|
|
108
|
+
### When to Animate Icons
|
|
109
|
+
|
|
110
|
+
| Animate | Don't animate |
|
|
111
|
+
| --- | --- |
|
|
112
|
+
| Icons that appear on hover (action buttons) | Static navigation icons |
|
|
113
|
+
| State change icons (play → pause, like → liked) | Decorative icons |
|
|
114
|
+
| Icons in contextual toolbars | Icons that are always visible |
|
|
115
|
+
| Loading/success state indicators | Icon labels (text next to icon) |
|
|
116
|
+
|
|
117
|
+
**Important:** Always use exactly these values for contextual icon animations; do not deviate:
|
|
118
|
+
- `scale`: `0.25` → `1` (never use `0.5` or `0.6`)
|
|
119
|
+
- `opacity`: `0` → `1`
|
|
120
|
+
- `filter`: `"blur(4px)"` → `"blur(0px)"`
|
|
121
|
+
- `transition`: `{ type: "spring", duration: 0.3, bounce: 0 }`; **bounce must always be `0`**, never
|
|
122
|
+
`0.1` or any other value
|
|
123
|
+
|
|
124
|
+
## Scale on Press
|
|
125
|
+
|
|
126
|
+
A subtle scale-down on click gives buttons tactile feedback. Always use `scale(0.96)`. Never use a
|
|
127
|
+
value smaller than `0.95`: anything below feels exaggerated. Use CSS transitions for
|
|
128
|
+
interruptibility, so that if the user releases mid-press, it smoothly returns.
|
|
129
|
+
|
|
130
|
+
Not every button needs this. Add a `static` prop to your button component that disables the scale
|
|
131
|
+
effect when the motion would be distracting.
|
|
132
|
+
|
|
133
|
+
### CSS Example
|
|
134
|
+
|
|
135
|
+
```css
|
|
136
|
+
.button {
|
|
137
|
+
transition-property: scale;
|
|
138
|
+
transition-duration: 150ms;
|
|
139
|
+
transition-timing-function: ease-out;
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
.button:active {
|
|
143
|
+
scale: 0.96;
|
|
144
|
+
}
|
|
145
|
+
```
|
|
146
|
+
|
|
147
|
+
### Tailwind Example
|
|
148
|
+
|
|
149
|
+
```tsx
|
|
150
|
+
<button className="transition-transform duration-150 ease-out active:scale-[0.96]">
|
|
151
|
+
Click me
|
|
152
|
+
</button>
|
|
153
|
+
```
|
|
154
|
+
|
|
155
|
+
### Motion Example
|
|
156
|
+
|
|
157
|
+
```tsx
|
|
158
|
+
<motion.button whileTap={{ scale: 0.96 }}>
|
|
159
|
+
Click me
|
|
160
|
+
</motion.button>
|
|
161
|
+
```
|
|
162
|
+
|
|
163
|
+
### Static Prop Pattern
|
|
164
|
+
|
|
165
|
+
Extract the scale class into a variable and conditionally apply it based on a `static` prop:
|
|
166
|
+
|
|
167
|
+
```tsx
|
|
168
|
+
const tapScale = "active:not-disabled:scale-[0.96]";
|
|
169
|
+
|
|
170
|
+
function Button({ static: isStatic, className, children, ...props }) {
|
|
171
|
+
return (
|
|
172
|
+
<button
|
|
173
|
+
className={cn(
|
|
174
|
+
"transition-transform duration-150 ease-out",
|
|
175
|
+
!isStatic && tapScale,
|
|
176
|
+
className,
|
|
177
|
+
)}
|
|
178
|
+
{...props}
|
|
179
|
+
>
|
|
180
|
+
{children}
|
|
181
|
+
</button>
|
|
182
|
+
);
|
|
183
|
+
}
|
|
184
|
+
|
|
185
|
+
// Usage
|
|
186
|
+
<Button>Click me</Button> {/* scales on press */}
|
|
187
|
+
<Button static>Submit</Button> {/* no scale */}
|
|
188
|
+
```
|
|
189
|
+
|
|
190
|
+
## Skip Animation on Page Load
|
|
191
|
+
|
|
192
|
+
Use `initial={false}` on `AnimatePresence` to prevent enter animations from firing on first render.
|
|
193
|
+
Elements that are already in their default state shouldn't animate in on page load, only on
|
|
194
|
+
subsequent state changes.
|
|
195
|
+
|
|
196
|
+
### When It Works
|
|
197
|
+
|
|
198
|
+
```tsx
|
|
199
|
+
// Good: icon doesn't animate in on mount, only on state change
|
|
200
|
+
<AnimatePresence initial={false} mode="popLayout">
|
|
201
|
+
<motion.span
|
|
202
|
+
key={isActive ? "active" : "inactive"}
|
|
203
|
+
initial={{ opacity: 0, scale: 0.25, filter: "blur(4px)" }}
|
|
204
|
+
animate={{ opacity: 1, scale: 1, filter: "blur(0px)" }}
|
|
205
|
+
exit={{ opacity: 0, scale: 0.25, filter: "blur(4px)" }}
|
|
206
|
+
>
|
|
207
|
+
<Icon />
|
|
208
|
+
</motion.span>
|
|
209
|
+
</AnimatePresence>
|
|
210
|
+
```
|
|
211
|
+
|
|
212
|
+
Works well for: icon swaps, toggles, tabs, segmented controls: anything that has a default state on
|
|
213
|
+
page load.
|
|
214
|
+
|
|
215
|
+
### When It Breaks
|
|
216
|
+
|
|
217
|
+
Don't use `initial={false}` when the component relies on its `initial` prop to set up a first-time
|
|
218
|
+
enter animation, like a staggered page hero or a loading state. In those cases, removing the initial
|
|
219
|
+
animation skips the entire entrance.
|
|
220
|
+
|
|
221
|
+
```tsx
|
|
222
|
+
// Bad: initial={false} would skip the staggered page enter entirely
|
|
223
|
+
<AnimatePresence initial={false}>
|
|
224
|
+
<motion.div initial="hidden" animate="visible" variants={...}>
|
|
225
|
+
...
|
|
226
|
+
</motion.div>
|
|
227
|
+
</AnimatePresence>
|
|
228
|
+
```
|
|
229
|
+
|
|
230
|
+
Verify the component still looks right on a full page refresh before applying this.
|