motion-ui-skill 2.0.0 → 2.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/README.md +71 -21
- package/SKILL.md +83 -9
- package/bin/index.mjs +2 -2
- package/bin/installer.mjs +6 -0
- package/catalog.json +1044 -139
- package/components/agents/thinking-states.tsx +156 -0
- package/components/buttons/aqua-button.tsx +145 -0
- package/components/buttons/ash-burst-button.tsx +528 -0
- package/components/buttons/brutal-button.tsx +68 -0
- package/components/buttons/chrome-button.tsx +444 -0
- package/components/buttons/click-powerup.tsx +203 -0
- package/components/buttons/command-button.tsx +226 -0
- package/components/buttons/confetti-button.tsx +132 -0
- package/components/buttons/cooldown-button.tsx +169 -0
- package/components/buttons/demonic-button.tsx +470 -0
- package/components/buttons/dither-button.tsx +192 -0
- package/components/buttons/doubt-button.tsx +240 -0
- package/components/buttons/evil-eye-button.tsx +563 -0
- package/components/buttons/frame-button.tsx +211 -0
- package/components/buttons/glitch-button.tsx +243 -0
- package/components/buttons/highlight-button.tsx +196 -0
- package/components/buttons/hold-button.tsx +245 -0
- package/components/buttons/minecraft-button.tsx +651 -0
- package/components/buttons/minimal-button.tsx +50 -0
- package/components/buttons/morph-status-button.tsx +264 -0
- package/components/buttons/movie-pass-button.tsx +205 -0
- package/components/buttons/realistic-switch.tsx +298 -0
- package/components/buttons/reveal-button.tsx +197 -0
- package/components/buttons/shiny-button.tsx +87 -0
- package/components/buttons/slide-to-detonate.tsx +444 -0
- package/components/buttons/sticky-button.tsx +184 -0
- package/components/buttons/thruster-button.tsx +920 -0
- package/components/buttons/troll-button.tsx +264 -0
- package/components/motion/banner-stacking.tsx +124 -0
- package/components/motion/delete-with-smoky-dissolve.tsx +145 -0
- package/components/motion/donut-chart.tsx +112 -0
- package/components/motion/drag-drop-with-physics.tsx +116 -0
- package/components/motion/dropdown-menu-morph.tsx +157 -0
- package/components/motion/get-pro-button.tsx +54 -0
- package/components/motion/image-open-tilt.tsx +79 -0
- package/components/motion/input-clear-with-dissolve.tsx +111 -0
- package/components/motion/learn-more-hover.tsx +71 -0
- package/components/motion/matrix-dot-loader.tsx +68 -0
- package/components/motion/organic-shimmer.tsx +49 -0
- package/components/motion/pro-gradient-text.tsx +46 -0
- package/components/motion/skeleton-loader-and-reveal.tsx +81 -0
- package/components/motion/spinner-to-check-morph.tsx +99 -0
- package/components/motion/spinning-counter.tsx +64 -0
- package/components/motion/text-morph.tsx +80 -0
- package/components/motion/texts-reveal.tsx +49 -0
- package/data/app-interface.csv +33 -0
- package/data/charts.csv +26 -0
- package/data/colors.csv +193 -0
- package/data/google-fonts.csv +1935 -0
- package/data/icons.csv +106 -0
- package/data/landing.csv +35 -0
- package/data/motion.csv +18 -0
- package/data/products.csv +193 -0
- package/data/react-performance.csv +45 -0
- package/data/stacks/angular.csv +51 -0
- package/data/stacks/astro.csv +54 -0
- package/data/stacks/avalonia.csv +57 -0
- package/data/stacks/flutter.csv +53 -0
- package/data/stacks/html-tailwind.csv +60 -0
- package/data/stacks/javafx.csv +76 -0
- package/data/stacks/jetpack-compose.csv +53 -0
- package/data/stacks/laravel.csv +51 -0
- package/data/stacks/nextjs.csv +62 -0
- package/data/stacks/nuxt-ui.csv +77 -0
- package/data/stacks/nuxtjs.csv +68 -0
- package/data/stacks/react-native.csv +52 -0
- package/data/stacks/react.csv +67 -0
- package/data/stacks/shadcn.csv +69 -0
- package/data/stacks/svelte.csv +56 -0
- package/data/stacks/swiftui.csv +51 -0
- package/data/stacks/threejs.csv +54 -0
- package/data/stacks/uno.csv +60 -0
- package/data/stacks/uwp.csv +56 -0
- package/data/stacks/vue.csv +50 -0
- package/data/stacks/winui.csv +60 -0
- package/data/stacks/wpf.csv +57 -0
- package/data/styles.csv +89 -0
- package/data/typography.csv +75 -0
- package/data/ui-reasoning.csv +193 -0
- package/data/ux-guidelines.csv +120 -0
- package/evals/catalog_eval.py +56 -0
- package/icons/annotations/loop-arrow.tsx +61 -0
- package/icons/brands/anthropic.tsx +26 -0
- package/icons/brands/apple.tsx +26 -0
- package/icons/brands/canva.tsx +26 -0
- package/icons/brands/claude-ai.tsx +26 -0
- package/icons/brands/discord.tsx +26 -0
- package/icons/brands/github.tsx +26 -0
- package/icons/brands/gmail.tsx +26 -0
- package/icons/brands/google.tsx +26 -0
- package/icons/brands/linkedin.tsx +29 -0
- package/icons/brands/microsoft.tsx +26 -0
- package/icons/brands/next-js.tsx +26 -0
- package/icons/brands/producthunt.tsx +26 -0
- package/icons/brands/react-js.tsx +29 -0
- package/icons/brands/shadcn-ui.tsx +26 -0
- package/icons/brands/tailwind-css.tsx +26 -0
- package/icons/brands/twitter.tsx +30 -0
- package/icons/brands/typescript.tsx +26 -0
- package/icons/brands/unsplash.tsx +27 -0
- package/icons/brands/vercel.tsx +26 -0
- package/icons/brands/whatsapp.tsx +26 -0
- package/package.json +9 -3
- package/prompts/install-motion-ui.md +17 -0
- package/references/agents/thinking-states.md +56 -0
- package/references/craft/aqua-button.md +53 -0
- package/references/craft/ash-burst-button.md +55 -0
- package/references/craft/brutal-button.md +52 -0
- package/references/craft/chrome-button.md +53 -0
- package/references/craft/click-powerup.md +53 -0
- package/references/craft/command-button.md +53 -0
- package/references/craft/confetti-button.md +54 -0
- package/references/craft/cooldown-button.md +54 -0
- package/references/craft/demonic-button.md +53 -0
- package/references/craft/dither-button.md +52 -0
- package/references/craft/doubt-button.md +53 -0
- package/references/craft/evil-eye-button.md +52 -0
- package/references/craft/frame-button.md +54 -0
- package/references/craft/glitch-button.md +52 -0
- package/references/craft/highlight-button.md +53 -0
- package/references/craft/hold-button.md +53 -0
- package/references/craft/minecraft-button.md +53 -0
- package/references/craft/minimal-button.md +52 -0
- package/references/craft/morph-status-button.md +53 -0
- package/references/craft/movie-pass-button.md +53 -0
- package/references/craft/realistic-switch.md +54 -0
- package/references/craft/reveal-button.md +53 -0
- package/references/craft/shiny-button.md +52 -0
- package/references/craft/slide-to-detonate.md +53 -0
- package/references/craft/sticky-button.md +54 -0
- package/references/craft/thruster-button.md +53 -0
- package/references/craft/troll-button.md +54 -0
- package/references/guides/design-intelligence.md +125 -0
- package/references/guides/interaction-transitions.md +56 -38
- package/references/guides/motion-polish-rules.md +75 -0
- package/references/guides/stack-best-practices.md +38 -0
- package/references/motion/banner-stacking.md +67 -0
- package/references/motion/delete-with-smoky-dissolve.md +60 -0
- package/references/motion/donut-chart.md +79 -0
- package/references/motion/drag-drop-with-physics.md +61 -0
- package/references/motion/dropdown-menu-morph.md +55 -0
- package/references/motion/get-pro-button.md +56 -0
- package/references/motion/image-open-tilt.md +60 -0
- package/references/motion/input-clear-with-dissolve.md +58 -0
- package/references/motion/learn-more-hover.md +56 -0
- package/references/motion/matrix-dot-loader.md +58 -0
- package/references/motion/organic-shimmer.md +63 -0
- package/references/motion/pro-gradient-text.md +57 -0
- package/references/motion/skeleton-loader-and-reveal.md +67 -0
- package/references/motion/spinner-to-check-morph.md +67 -0
- package/references/motion/spinning-counter.md +74 -0
- package/references/motion/text-morph.md +64 -0
- package/references/motion/texts-reveal.md +56 -0
- package/scripts/build_docs.py +39 -4
- package/scripts/core.py +993 -0
- package/scripts/design_system.py +1668 -0
- package/scripts/reasoning_contract.py +123 -0
- package/scripts/search.py +177 -0
- package/scripts/test_release.py +12 -0
- package/scripts/verify_skill.py +4 -4
- package/test/test_installer.mjs +133 -0
|
@@ -0,0 +1,226 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { cn } from "@/lib/utils";
|
|
5
|
+
|
|
6
|
+
export interface CommandButtonProps extends Omit<
|
|
7
|
+
React.ButtonHTMLAttributes<HTMLButtonElement>,
|
|
8
|
+
"onDrag" | "onDragStart" | "onDragEnd" | "onAnimationStart"
|
|
9
|
+
> {
|
|
10
|
+
/** Shortcut like `"mod+s"`. `mod` is ⌘ on Apple devices and Ctrl elsewhere. */
|
|
11
|
+
shortcut?: string;
|
|
12
|
+
/** Fired when the keyboard shortcut is pressed. */
|
|
13
|
+
onCommand?: () => void;
|
|
14
|
+
/** Stop the browser's own handling of the shortcut, like the save dialog. */
|
|
15
|
+
preventDefault?: boolean;
|
|
16
|
+
/** Show the shortcut as keycaps inside the button. */
|
|
17
|
+
showShortcut?: boolean;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
const MODIFIERS = ["mod", "ctrl", "alt", "shift"] as const;
|
|
21
|
+
/** How long a fired shortcut keeps every cap pressed. */
|
|
22
|
+
const FIRE_MS = 160;
|
|
23
|
+
|
|
24
|
+
function normalizeKey(value: string) {
|
|
25
|
+
const key = value.toLowerCase();
|
|
26
|
+
if (key === "cmd" || key === "command" || key === "meta") return "mod";
|
|
27
|
+
if (key === "control") return "ctrl";
|
|
28
|
+
if (key === "option") return "alt";
|
|
29
|
+
if (key === "escape") return "esc";
|
|
30
|
+
if (key === "return") return "enter";
|
|
31
|
+
if (key === " " || key === "spacebar") return "space";
|
|
32
|
+
return key;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
function parseShortcut(shortcut: string) {
|
|
36
|
+
return shortcut
|
|
37
|
+
.split("+")
|
|
38
|
+
.map((part) => normalizeKey(part.trim()))
|
|
39
|
+
.filter(Boolean);
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
function shortcutMatches(event: KeyboardEvent, parts: string[], isApple: boolean) {
|
|
43
|
+
const wantsMod = parts.includes("mod");
|
|
44
|
+
const wantsCtrl = parts.includes("ctrl");
|
|
45
|
+
const finalKey = parts.find(
|
|
46
|
+
(part) => !(MODIFIERS as readonly string[]).includes(part),
|
|
47
|
+
);
|
|
48
|
+
|
|
49
|
+
const reqMeta = wantsMod ? isApple : false;
|
|
50
|
+
const reqCtrl = wantsCtrl || (wantsMod && !isApple);
|
|
51
|
+
|
|
52
|
+
if (event.metaKey !== reqMeta) return false;
|
|
53
|
+
if (event.ctrlKey !== reqCtrl) return false;
|
|
54
|
+
if (event.altKey !== parts.includes("alt")) return false;
|
|
55
|
+
if (event.shiftKey !== parts.includes("shift")) return false;
|
|
56
|
+
return finalKey ? normalizeKey(event.key) === finalKey : false;
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
/** Whether a single shortcut part is physically held in this key event. */
|
|
60
|
+
function partHeld(part: string, event: KeyboardEvent, isApple: boolean) {
|
|
61
|
+
if (part === "mod") return isApple ? event.metaKey : event.ctrlKey;
|
|
62
|
+
if (part === "ctrl") return event.ctrlKey;
|
|
63
|
+
if (part === "alt") return event.altKey;
|
|
64
|
+
if (part === "shift") return event.shiftKey;
|
|
65
|
+
return false;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function formatPart(part: string, isApple: boolean) {
|
|
69
|
+
if (part === "mod") return isApple ? "⌘" : "Ctrl";
|
|
70
|
+
if (part === "ctrl") return isApple ? "⌃" : "Ctrl";
|
|
71
|
+
if (part === "alt") return isApple ? "⌥" : "Alt";
|
|
72
|
+
if (part === "shift") return isApple ? "⇧" : "Shift";
|
|
73
|
+
if (part === "enter") return "↵";
|
|
74
|
+
if (part === "esc") return "Esc";
|
|
75
|
+
if (part === "space") return "Space";
|
|
76
|
+
if (part === "arrowup") return "↑";
|
|
77
|
+
if (part === "arrowdown") return "↓";
|
|
78
|
+
if (part === "arrowleft") return "←";
|
|
79
|
+
if (part === "arrowright") return "→";
|
|
80
|
+
return part.length === 1 ? part.toUpperCase() : part;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
function detectApple() {
|
|
84
|
+
if (typeof navigator === "undefined") return false;
|
|
85
|
+
return /mac|iphone|ipad|ipod/i.test(
|
|
86
|
+
navigator.platform || navigator.userAgent,
|
|
87
|
+
);
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
export const CommandButton = React.forwardRef<
|
|
91
|
+
HTMLButtonElement,
|
|
92
|
+
CommandButtonProps
|
|
93
|
+
>(
|
|
94
|
+
(
|
|
95
|
+
{
|
|
96
|
+
shortcut = "mod+s",
|
|
97
|
+
onCommand,
|
|
98
|
+
preventDefault = true,
|
|
99
|
+
showShortcut = true,
|
|
100
|
+
className,
|
|
101
|
+
children = "Save",
|
|
102
|
+
disabled,
|
|
103
|
+
onClick,
|
|
104
|
+
type = "button",
|
|
105
|
+
...props
|
|
106
|
+
},
|
|
107
|
+
ref,
|
|
108
|
+
) => {
|
|
109
|
+
const parts = React.useMemo(() => parseShortcut(shortcut), [shortcut]);
|
|
110
|
+
const [isApple, setIsApple] = React.useState(false);
|
|
111
|
+
const [held, setHeld] = React.useState<ReadonlySet<string>>(new Set());
|
|
112
|
+
const [firing, setFiring] = React.useState(false);
|
|
113
|
+
const fireTimerRef = React.useRef<number | undefined>(undefined);
|
|
114
|
+
const onCommandRef = React.useRef(onCommand);
|
|
115
|
+
|
|
116
|
+
React.useEffect(() => {
|
|
117
|
+
onCommandRef.current = onCommand;
|
|
118
|
+
}, [onCommand]);
|
|
119
|
+
|
|
120
|
+
// Platform is only known on the client, so detect it after hydration.
|
|
121
|
+
React.useEffect(() => setIsApple(detectApple()), []);
|
|
122
|
+
|
|
123
|
+
const fire = React.useCallback(() => {
|
|
124
|
+
setFiring(true);
|
|
125
|
+
window.clearTimeout(fireTimerRef.current);
|
|
126
|
+
fireTimerRef.current = window.setTimeout(() => setFiring(false), FIRE_MS);
|
|
127
|
+
}, []);
|
|
128
|
+
|
|
129
|
+
React.useEffect(() => {
|
|
130
|
+
if (disabled) return;
|
|
131
|
+
|
|
132
|
+
// Mirror which modifier caps are held so each one sinks as it's pressed.
|
|
133
|
+
const syncModifiers = (event: KeyboardEvent) => {
|
|
134
|
+
const next = new Set(
|
|
135
|
+
parts.filter((part) => partHeld(part, event, isApple)),
|
|
136
|
+
);
|
|
137
|
+
setHeld((current) =>
|
|
138
|
+
current.size === next.size &&
|
|
139
|
+
[...next].every((part) => current.has(part))
|
|
140
|
+
? current
|
|
141
|
+
: next,
|
|
142
|
+
);
|
|
143
|
+
};
|
|
144
|
+
|
|
145
|
+
const handleKeyDown = (event: KeyboardEvent) => {
|
|
146
|
+
syncModifiers(event);
|
|
147
|
+
if (event.repeat || !shortcutMatches(event, parts, isApple)) return;
|
|
148
|
+
if (preventDefault) event.preventDefault();
|
|
149
|
+
fire();
|
|
150
|
+
onCommandRef.current?.();
|
|
151
|
+
};
|
|
152
|
+
const clear = () => setHeld(new Set());
|
|
153
|
+
|
|
154
|
+
window.addEventListener("keydown", handleKeyDown);
|
|
155
|
+
window.addEventListener("keyup", syncModifiers);
|
|
156
|
+
window.addEventListener("blur", clear);
|
|
157
|
+
return () => {
|
|
158
|
+
window.removeEventListener("keydown", handleKeyDown);
|
|
159
|
+
window.removeEventListener("keyup", syncModifiers);
|
|
160
|
+
window.removeEventListener("blur", clear);
|
|
161
|
+
clear();
|
|
162
|
+
};
|
|
163
|
+
}, [disabled, fire, isApple, parts, preventDefault]);
|
|
164
|
+
|
|
165
|
+
React.useEffect(() => () => window.clearTimeout(fireTimerRef.current), []);
|
|
166
|
+
|
|
167
|
+
const label = parts.map((part) => formatPart(part, isApple)).join(" ");
|
|
168
|
+
|
|
169
|
+
return (
|
|
170
|
+
<button
|
|
171
|
+
ref={ref}
|
|
172
|
+
type={type}
|
|
173
|
+
disabled={disabled}
|
|
174
|
+
data-shortcut={shortcut}
|
|
175
|
+
data-firing={firing || undefined}
|
|
176
|
+
aria-keyshortcuts={parts
|
|
177
|
+
.map((part) =>
|
|
178
|
+
part === "mod" ? (isApple ? "Meta" : "Control") : part,
|
|
179
|
+
)
|
|
180
|
+
.join("+")}
|
|
181
|
+
onClick={onClick}
|
|
182
|
+
className={cn(
|
|
183
|
+
"group/cmd relative inline-flex h-9 cursor-pointer items-center justify-center gap-2.5 rounded-[10px] px-4 text-sm font-medium outline-none select-none",
|
|
184
|
+
// Graded dark surface: dark outer hairline, faint inner ring, top highlight, soft drop.
|
|
185
|
+
"bg-linear-to-b from-[#353535] to-[#272727] text-neutral-50 shadow-[0_0_0_1px_rgb(0_0_0/0.9),inset_0_0_0_1px_rgb(255_255_255/0.06),inset_0_1px_0_rgb(255_255_255/0.14),0_1px_2px_rgb(0_0_0/0.25),0_4px_12px_-4px_rgb(0_0_0/0.4)]",
|
|
186
|
+
"transition-[scale,filter,box-shadow] duration-300 ease-[cubic-bezier(0.34,1.35,0.64,1)] hover:brightness-110",
|
|
187
|
+
// Press eases in fast and settles the shadow; release springs back on the slower base curve.
|
|
188
|
+
"active:scale-[0.97] active:brightness-95 active:duration-100 active:ease-out active:shadow-[0_0_0_1px_rgb(0_0_0/0.9),inset_0_0_0_1px_rgb(255_255_255/0.05),inset_0_1px_0_rgb(255_255_255/0.08),0_0_1px_rgb(0_0_0/0.2),0_1px_3px_-2px_rgb(0_0_0/0.3)] motion-reduce:active:scale-100",
|
|
189
|
+
// The shortcut has no :active state, so data-firing plays the same press.
|
|
190
|
+
"data-firing:scale-[0.97] data-firing:brightness-95 data-firing:duration-100 data-firing:ease-out data-firing:shadow-[0_0_0_1px_rgb(0_0_0/0.9),inset_0_0_0_1px_rgb(255_255_255/0.05),inset_0_1px_0_rgb(255_255_255/0.08),0_0_1px_rgb(0_0_0/0.2),0_1px_3px_-2px_rgb(0_0_0/0.3)] motion-reduce:data-firing:scale-100",
|
|
191
|
+
showShortcut && "pr-2",
|
|
192
|
+
"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50",
|
|
193
|
+
className,
|
|
194
|
+
)}
|
|
195
|
+
{...props}
|
|
196
|
+
>
|
|
197
|
+
<span>{children}</span>
|
|
198
|
+
{showShortcut ? (
|
|
199
|
+
<kbd
|
|
200
|
+
aria-label={label}
|
|
201
|
+
className="inline-flex items-center gap-0.5 font-sans"
|
|
202
|
+
>
|
|
203
|
+
{parts.map((part) => (
|
|
204
|
+
<span
|
|
205
|
+
key={part}
|
|
206
|
+
aria-hidden
|
|
207
|
+
data-pressed={held.has(part) || undefined}
|
|
208
|
+
className={cn(
|
|
209
|
+
"inline-flex h-5 min-w-5 items-center justify-center rounded-[4px] bg-white/8 px-1 text-[11px] leading-none font-medium text-neutral-50/55 inset-ring inset-ring-white/6 transition-[translate,background-color,color] duration-300 ease-[cubic-bezier(0.34,1.35,0.64,1)]",
|
|
210
|
+
// Same states and timing as the button's press, so caps and button move on the same frame.
|
|
211
|
+
"data-pressed:translate-y-px data-pressed:bg-white/20 data-pressed:text-neutral-50 data-pressed:duration-100 data-pressed:ease-out",
|
|
212
|
+
"group-active/cmd:translate-y-px group-active/cmd:bg-white/20 group-active/cmd:text-neutral-50 group-active/cmd:duration-100 group-active/cmd:ease-out",
|
|
213
|
+
"group-data-firing/cmd:translate-y-px group-data-firing/cmd:bg-white/20 group-data-firing/cmd:text-neutral-50 group-data-firing/cmd:duration-100 group-data-firing/cmd:ease-out",
|
|
214
|
+
)}
|
|
215
|
+
>
|
|
216
|
+
{formatPart(part, isApple)}
|
|
217
|
+
</span>
|
|
218
|
+
))}
|
|
219
|
+
</kbd>
|
|
220
|
+
) : null}
|
|
221
|
+
</button>
|
|
222
|
+
);
|
|
223
|
+
},
|
|
224
|
+
);
|
|
225
|
+
|
|
226
|
+
CommandButton.displayName = "CommandButton";
|
|
@@ -0,0 +1,132 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import confetti from "canvas-confetti";
|
|
5
|
+
import { cn } from "@/lib/utils";
|
|
6
|
+
|
|
7
|
+
export interface ConfettiButtonProps
|
|
8
|
+
extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
9
|
+
/** Label used when no children are provided. */
|
|
10
|
+
label?: React.ReactNode;
|
|
11
|
+
/** Confetti particles per burst. */
|
|
12
|
+
particleCount?: number;
|
|
13
|
+
/** Confetti spread in degrees. */
|
|
14
|
+
spread?: number;
|
|
15
|
+
/** Launch velocity of the burst. */
|
|
16
|
+
startVelocity?: number;
|
|
17
|
+
/** Custom confetti colors. */
|
|
18
|
+
colors?: string[];
|
|
19
|
+
/** Show the leading sparkle icon. */
|
|
20
|
+
icon?: boolean;
|
|
21
|
+
/** Fired after each confetti burst. */
|
|
22
|
+
onCelebrate?: () => void;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
/** Soft neutrals with a few cool accents, so the burst reads as polish, not a party. */
|
|
26
|
+
const CONFETTI_COLORS = ["#fafafa", "#d4d4d4", "#a3a3a3", "#93c5fd", "#c4b5fd", "#fcd34d"];
|
|
27
|
+
/** How long the sparkle stays lit after a burst. */
|
|
28
|
+
const FIRE_MS = 420;
|
|
29
|
+
|
|
30
|
+
function burstFromElement(
|
|
31
|
+
element: HTMLElement,
|
|
32
|
+
options: { particleCount: number; spread: number; startVelocity: number; colors: string[] },
|
|
33
|
+
) {
|
|
34
|
+
const rect = element.getBoundingClientRect();
|
|
35
|
+
const origin = {
|
|
36
|
+
x: (rect.left + rect.width / 2) / window.innerWidth,
|
|
37
|
+
y: (rect.top + rect.height / 3) / window.innerHeight,
|
|
38
|
+
};
|
|
39
|
+
|
|
40
|
+
// One tight burst of small flat pieces that fall and fade quickly.
|
|
41
|
+
void confetti({
|
|
42
|
+
...options,
|
|
43
|
+
origin,
|
|
44
|
+
angle: 90,
|
|
45
|
+
gravity: 1.1,
|
|
46
|
+
decay: 0.9,
|
|
47
|
+
ticks: 160,
|
|
48
|
+
scalar: 0.75,
|
|
49
|
+
shapes: ["square", "circle"],
|
|
50
|
+
disableForReducedMotion: true,
|
|
51
|
+
});
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export const ConfettiButton = React.forwardRef<HTMLButtonElement, ConfettiButtonProps>(
|
|
55
|
+
(
|
|
56
|
+
{
|
|
57
|
+
children,
|
|
58
|
+
label = "Continue",
|
|
59
|
+
particleCount = 80,
|
|
60
|
+
spread = 64,
|
|
61
|
+
startVelocity = 32,
|
|
62
|
+
colors = CONFETTI_COLORS,
|
|
63
|
+
icon = true,
|
|
64
|
+
onCelebrate,
|
|
65
|
+
onClick,
|
|
66
|
+
className,
|
|
67
|
+
disabled,
|
|
68
|
+
type = "button",
|
|
69
|
+
...props
|
|
70
|
+
},
|
|
71
|
+
ref,
|
|
72
|
+
) => {
|
|
73
|
+
const [firing, setFiring] = React.useState(false);
|
|
74
|
+
const fireTimerRef = React.useRef<number | undefined>(undefined);
|
|
75
|
+
|
|
76
|
+
React.useEffect(() => () => window.clearTimeout(fireTimerRef.current), []);
|
|
77
|
+
|
|
78
|
+
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
|
79
|
+
onClick?.(event);
|
|
80
|
+
if (disabled || event.defaultPrevented) return;
|
|
81
|
+
|
|
82
|
+
burstFromElement(event.currentTarget, { particleCount, spread, startVelocity, colors });
|
|
83
|
+
setFiring(true);
|
|
84
|
+
window.clearTimeout(fireTimerRef.current);
|
|
85
|
+
fireTimerRef.current = window.setTimeout(() => setFiring(false), FIRE_MS);
|
|
86
|
+
onCelebrate?.();
|
|
87
|
+
};
|
|
88
|
+
|
|
89
|
+
return (
|
|
90
|
+
<button
|
|
91
|
+
ref={ref}
|
|
92
|
+
type={type}
|
|
93
|
+
disabled={disabled}
|
|
94
|
+
data-firing={firing || undefined}
|
|
95
|
+
onClick={handleClick}
|
|
96
|
+
className={cn(
|
|
97
|
+
"group/confetti inline-flex h-9 cursor-pointer items-center justify-center gap-2 rounded-[10px] px-4 text-sm font-medium text-neutral-50 outline-none select-none",
|
|
98
|
+
// Graded dark surface: dark outer hairline, faint inner ring, top highlight, soft drop.
|
|
99
|
+
"bg-linear-to-b from-[#353535] to-[#272727] shadow-[0_0_0_1px_rgb(0_0_0/0.9),inset_0_0_0_1px_rgb(255_255_255/0.06),inset_0_1px_0_rgb(255_255_255/0.14),0_1px_2px_rgb(0_0_0/0.25),0_4px_12px_-4px_rgb(0_0_0/0.4)]",
|
|
100
|
+
"transition-[scale,filter,box-shadow] duration-300 ease-[cubic-bezier(0.34,1.35,0.64,1)] hover:brightness-110",
|
|
101
|
+
// Press eases in fast and settles the shadow; release springs back on the slower base curve.
|
|
102
|
+
"active:scale-[0.97] active:brightness-95 active:duration-100 active:ease-out active:shadow-[0_0_0_1px_rgb(0_0_0/0.9),inset_0_0_0_1px_rgb(255_255_255/0.05),inset_0_1px_0_rgb(255_255_255/0.08),0_0_1px_rgb(0_0_0/0.2),0_1px_3px_-2px_rgb(0_0_0/0.3)] motion-reduce:active:scale-100",
|
|
103
|
+
"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50",
|
|
104
|
+
icon && "pl-3",
|
|
105
|
+
className,
|
|
106
|
+
)}
|
|
107
|
+
{...props}
|
|
108
|
+
>
|
|
109
|
+
{icon ? (
|
|
110
|
+
<svg
|
|
111
|
+
aria-hidden
|
|
112
|
+
viewBox="0 0 16 16"
|
|
113
|
+
fill="currentColor"
|
|
114
|
+
className={cn(
|
|
115
|
+
"size-3.5 text-neutral-50/45 transition-[rotate,scale,color] duration-300 ease-[cubic-bezier(0.34,1.35,0.64,1)]",
|
|
116
|
+
"group-hover/confetti:rotate-12 group-hover/confetti:text-neutral-50/75",
|
|
117
|
+
"group-data-firing/confetti:scale-125 group-data-firing/confetti:rotate-45 group-data-firing/confetti:text-amber-200 motion-reduce:transform-none",
|
|
118
|
+
)}
|
|
119
|
+
>
|
|
120
|
+
<path d="M8 1.5c.3 2.9 1.6 4.2 4.5 4.5-2.9.3-4.2 1.6-4.5 4.5-.3-2.9-1.6-4.2-4.5-4.5 2.9-.3 4.2-1.6 4.5-4.5Z" />
|
|
121
|
+
<path d="M12.5 10c.15 1.3.7 1.85 2 2-1.3.15-1.85.7-2 2-.15-1.3-.7-1.85-2-2 1.3-.15 1.85-.7 2-2Z" />
|
|
122
|
+
</svg>
|
|
123
|
+
) : null}
|
|
124
|
+
<span>{children ?? label}</span>
|
|
125
|
+
</button>
|
|
126
|
+
);
|
|
127
|
+
},
|
|
128
|
+
);
|
|
129
|
+
|
|
130
|
+
ConfettiButton.displayName = "ConfettiButton";
|
|
131
|
+
|
|
132
|
+
export default ConfettiButton;
|
|
@@ -0,0 +1,169 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import {
|
|
5
|
+
AnimatePresence,
|
|
6
|
+
animate,
|
|
7
|
+
motion,
|
|
8
|
+
useMotionTemplate,
|
|
9
|
+
useMotionValue,
|
|
10
|
+
useReducedMotion,
|
|
11
|
+
} from "motion/react";
|
|
12
|
+
import { cn } from "@/lib/utils";
|
|
13
|
+
|
|
14
|
+
type CooldownState = "idle" | "cooldown";
|
|
15
|
+
|
|
16
|
+
export interface CooldownButtonProps
|
|
17
|
+
extends React.ButtonHTMLAttributes<HTMLButtonElement> {
|
|
18
|
+
/** Idle label. Falls back to `label`. */
|
|
19
|
+
children?: React.ReactNode;
|
|
20
|
+
/** Idle label used when no children are provided. */
|
|
21
|
+
label?: React.ReactNode;
|
|
22
|
+
/** Cooldown duration in milliseconds after each click. */
|
|
23
|
+
cooldown?: number;
|
|
24
|
+
/** Rotating taunts shown while locked. One is picked per cooldown. */
|
|
25
|
+
taunts?: string[];
|
|
26
|
+
/**
|
|
27
|
+
* When true, the remaining seconds are appended to the taunt while locked.
|
|
28
|
+
* @default true
|
|
29
|
+
*/
|
|
30
|
+
showCountdown?: boolean;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
const DEFAULT_TAUNTS = [
|
|
34
|
+
"Patience.",
|
|
35
|
+
"Again? Wait.",
|
|
36
|
+
"Not so fast.",
|
|
37
|
+
"Cool it.",
|
|
38
|
+
"Hold your horses.",
|
|
39
|
+
];
|
|
40
|
+
|
|
41
|
+
export const CooldownButton = React.forwardRef<
|
|
42
|
+
HTMLButtonElement,
|
|
43
|
+
CooldownButtonProps
|
|
44
|
+
>(
|
|
45
|
+
(
|
|
46
|
+
{
|
|
47
|
+
children,
|
|
48
|
+
label = "Send it",
|
|
49
|
+
cooldown = 3000,
|
|
50
|
+
taunts = DEFAULT_TAUNTS,
|
|
51
|
+
showCountdown = true,
|
|
52
|
+
onClick,
|
|
53
|
+
className,
|
|
54
|
+
disabled,
|
|
55
|
+
...props
|
|
56
|
+
},
|
|
57
|
+
ref,
|
|
58
|
+
) => {
|
|
59
|
+
const reduceMotion = useReducedMotion();
|
|
60
|
+
|
|
61
|
+
const [state, setState] = React.useState<CooldownState>("idle");
|
|
62
|
+
const [taunt, setTaunt] = React.useState("");
|
|
63
|
+
const [remaining, setRemaining] = React.useState(0);
|
|
64
|
+
|
|
65
|
+
const timeoutRef = React.useRef<number | null>(null);
|
|
66
|
+
const intervalRef = React.useRef<number | null>(null);
|
|
67
|
+
|
|
68
|
+
// Drains 360 -> 0 over the cooldown, painted as a conic sweep.
|
|
69
|
+
const sweep = useMotionValue(360);
|
|
70
|
+
const sweepBackground = useMotionTemplate`conic-gradient(currentColor ${sweep}deg, transparent 0deg)`;
|
|
71
|
+
|
|
72
|
+
const clearTimers = React.useCallback(() => {
|
|
73
|
+
if (timeoutRef.current !== null) {
|
|
74
|
+
window.clearTimeout(timeoutRef.current);
|
|
75
|
+
timeoutRef.current = null;
|
|
76
|
+
}
|
|
77
|
+
if (intervalRef.current !== null) {
|
|
78
|
+
window.clearInterval(intervalRef.current);
|
|
79
|
+
intervalRef.current = null;
|
|
80
|
+
}
|
|
81
|
+
}, []);
|
|
82
|
+
|
|
83
|
+
React.useEffect(() => () => clearTimers(), [clearTimers]);
|
|
84
|
+
|
|
85
|
+
const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
86
|
+
if (state === "cooldown") return;
|
|
87
|
+
onClick?.(e);
|
|
88
|
+
if (e.defaultPrevented || cooldown <= 0) return;
|
|
89
|
+
|
|
90
|
+
const pick =
|
|
91
|
+
taunts.length > 0
|
|
92
|
+
? taunts[Math.floor(Math.random() * taunts.length)]
|
|
93
|
+
: "";
|
|
94
|
+
setTaunt(pick);
|
|
95
|
+
setRemaining(Math.ceil(cooldown / 1000));
|
|
96
|
+
setState("cooldown");
|
|
97
|
+
|
|
98
|
+
clearTimers();
|
|
99
|
+
sweep.set(360);
|
|
100
|
+
if (!reduceMotion) {
|
|
101
|
+
animate(sweep, 0, { duration: cooldown / 1000, ease: "linear" });
|
|
102
|
+
}
|
|
103
|
+
const end = performance.now() + cooldown;
|
|
104
|
+
intervalRef.current = window.setInterval(() => {
|
|
105
|
+
setRemaining(Math.max(0, Math.ceil((end - performance.now()) / 1000)));
|
|
106
|
+
}, 200);
|
|
107
|
+
timeoutRef.current = window.setTimeout(() => {
|
|
108
|
+
clearTimers();
|
|
109
|
+
setState("idle");
|
|
110
|
+
}, cooldown);
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
const isCooling = state === "cooldown";
|
|
114
|
+
const idleLabel = children ?? label;
|
|
115
|
+
const cooldownLabel =
|
|
116
|
+
showCountdown && remaining > 0 ? `${taunt} ${remaining}s` : taunt;
|
|
117
|
+
|
|
118
|
+
return (
|
|
119
|
+
<button
|
|
120
|
+
ref={ref}
|
|
121
|
+
type="button"
|
|
122
|
+
onClick={handleClick}
|
|
123
|
+
disabled={disabled || isCooling}
|
|
124
|
+
aria-live="polite"
|
|
125
|
+
data-state={state}
|
|
126
|
+
className={cn(
|
|
127
|
+
"relative inline-flex h-9 min-w-40 cursor-pointer items-center justify-center overflow-hidden rounded-[10px] px-4 text-sm font-medium text-neutral-50 outline-none select-none",
|
|
128
|
+
// Graded dark surface matching MinimalButton: dark outer hairline, faint inner ring, top highlight, soft drop.
|
|
129
|
+
"bg-linear-to-b from-[#353535] to-[#272727] shadow-[0_0_0_1px_rgb(0_0_0/0.9),inset_0_0_0_1px_rgb(255_255_255/0.06),inset_0_1px_0_rgb(255_255_255/0.14),0_1px_2px_rgb(0_0_0/0.25),0_4px_12px_-4px_rgb(0_0_0/0.4)]",
|
|
130
|
+
"transition-[scale,filter,box-shadow,color] duration-300 ease-[cubic-bezier(0.34,1.35,0.64,1)] hover:brightness-110",
|
|
131
|
+
"active:scale-[0.97] active:brightness-95 active:duration-100 active:ease-out active:shadow-[0_0_0_1px_rgb(0_0_0/0.9),inset_0_0_0_1px_rgb(255_255_255/0.05),inset_0_1px_0_rgb(255_255_255/0.08),0_0_1px_rgb(0_0_0/0.2),0_1px_3px_-2px_rgb(0_0_0/0.3)] motion-reduce:active:scale-100",
|
|
132
|
+
"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:cursor-not-allowed disabled:opacity-50",
|
|
133
|
+
// Locked by the cooldown, not disabled: stay solid, dim the label, no hover lift.
|
|
134
|
+
isCooling && "text-neutral-50/55 hover:brightness-100 disabled:opacity-100",
|
|
135
|
+
className,
|
|
136
|
+
)}
|
|
137
|
+
{...props}
|
|
138
|
+
>
|
|
139
|
+
{/* Radial sweep that drains over the cooldown duration. */}
|
|
140
|
+
{isCooling && (
|
|
141
|
+
<motion.span
|
|
142
|
+
aria-hidden
|
|
143
|
+
className="pointer-events-none absolute inset-0 z-0 opacity-[0.12]"
|
|
144
|
+
style={{ background: sweepBackground }}
|
|
145
|
+
/>
|
|
146
|
+
)}
|
|
147
|
+
|
|
148
|
+
<span className="relative z-10 inline-block">
|
|
149
|
+
<AnimatePresence initial={false} mode="wait">
|
|
150
|
+
<motion.span
|
|
151
|
+
key={isCooling ? `cool-${taunt}` : "idle"}
|
|
152
|
+
initial={reduceMotion ? false : { y: 8, opacity: 0 }}
|
|
153
|
+
animate={{ y: 0, opacity: 1 }}
|
|
154
|
+
exit={reduceMotion ? undefined : { y: -8, opacity: 0 }}
|
|
155
|
+
transition={{ duration: 0.16 }}
|
|
156
|
+
className="inline-block whitespace-nowrap"
|
|
157
|
+
>
|
|
158
|
+
{isCooling ? cooldownLabel : idleLabel}
|
|
159
|
+
</motion.span>
|
|
160
|
+
</AnimatePresence>
|
|
161
|
+
</span>
|
|
162
|
+
</button>
|
|
163
|
+
);
|
|
164
|
+
},
|
|
165
|
+
);
|
|
166
|
+
|
|
167
|
+
CooldownButton.displayName = "CooldownButton";
|
|
168
|
+
|
|
169
|
+
export default CooldownButton;
|