motion-ui-skill 2.0.0 → 2.1.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.
Files changed (166) hide show
  1. package/README.md +71 -21
  2. package/SKILL.md +83 -9
  3. package/bin/index.mjs +2 -2
  4. package/bin/installer.mjs +6 -0
  5. package/catalog.json +1044 -139
  6. package/components/agents/thinking-states.tsx +156 -0
  7. package/components/buttons/aqua-button.tsx +145 -0
  8. package/components/buttons/ash-burst-button.tsx +528 -0
  9. package/components/buttons/brutal-button.tsx +68 -0
  10. package/components/buttons/chrome-button.tsx +444 -0
  11. package/components/buttons/click-powerup.tsx +203 -0
  12. package/components/buttons/command-button.tsx +226 -0
  13. package/components/buttons/confetti-button.tsx +132 -0
  14. package/components/buttons/cooldown-button.tsx +169 -0
  15. package/components/buttons/demonic-button.tsx +470 -0
  16. package/components/buttons/dither-button.tsx +192 -0
  17. package/components/buttons/doubt-button.tsx +240 -0
  18. package/components/buttons/evil-eye-button.tsx +563 -0
  19. package/components/buttons/frame-button.tsx +211 -0
  20. package/components/buttons/glitch-button.tsx +243 -0
  21. package/components/buttons/highlight-button.tsx +196 -0
  22. package/components/buttons/hold-button.tsx +245 -0
  23. package/components/buttons/minecraft-button.tsx +651 -0
  24. package/components/buttons/minimal-button.tsx +50 -0
  25. package/components/buttons/morph-status-button.tsx +264 -0
  26. package/components/buttons/movie-pass-button.tsx +205 -0
  27. package/components/buttons/realistic-switch.tsx +298 -0
  28. package/components/buttons/reveal-button.tsx +197 -0
  29. package/components/buttons/shiny-button.tsx +87 -0
  30. package/components/buttons/slide-to-detonate.tsx +444 -0
  31. package/components/buttons/sticky-button.tsx +184 -0
  32. package/components/buttons/thruster-button.tsx +920 -0
  33. package/components/buttons/troll-button.tsx +264 -0
  34. package/components/motion/banner-stacking.tsx +124 -0
  35. package/components/motion/delete-with-smoky-dissolve.tsx +145 -0
  36. package/components/motion/donut-chart.tsx +112 -0
  37. package/components/motion/drag-drop-with-physics.tsx +116 -0
  38. package/components/motion/dropdown-menu-morph.tsx +157 -0
  39. package/components/motion/get-pro-button.tsx +54 -0
  40. package/components/motion/image-open-tilt.tsx +79 -0
  41. package/components/motion/input-clear-with-dissolve.tsx +111 -0
  42. package/components/motion/learn-more-hover.tsx +71 -0
  43. package/components/motion/matrix-dot-loader.tsx +68 -0
  44. package/components/motion/organic-shimmer.tsx +49 -0
  45. package/components/motion/pro-gradient-text.tsx +46 -0
  46. package/components/motion/skeleton-loader-and-reveal.tsx +81 -0
  47. package/components/motion/spinner-to-check-morph.tsx +99 -0
  48. package/components/motion/spinning-counter.tsx +64 -0
  49. package/components/motion/text-morph.tsx +80 -0
  50. package/components/motion/texts-reveal.tsx +49 -0
  51. package/data/app-interface.csv +33 -0
  52. package/data/charts.csv +26 -0
  53. package/data/colors.csv +193 -0
  54. package/data/google-fonts.csv +1935 -0
  55. package/data/icons.csv +106 -0
  56. package/data/landing.csv +35 -0
  57. package/data/motion.csv +18 -0
  58. package/data/products.csv +193 -0
  59. package/data/react-performance.csv +45 -0
  60. package/data/stacks/angular.csv +51 -0
  61. package/data/stacks/astro.csv +54 -0
  62. package/data/stacks/avalonia.csv +57 -0
  63. package/data/stacks/flutter.csv +53 -0
  64. package/data/stacks/html-tailwind.csv +60 -0
  65. package/data/stacks/javafx.csv +76 -0
  66. package/data/stacks/jetpack-compose.csv +53 -0
  67. package/data/stacks/laravel.csv +51 -0
  68. package/data/stacks/nextjs.csv +62 -0
  69. package/data/stacks/nuxt-ui.csv +77 -0
  70. package/data/stacks/nuxtjs.csv +68 -0
  71. package/data/stacks/react-native.csv +52 -0
  72. package/data/stacks/react.csv +67 -0
  73. package/data/stacks/shadcn.csv +69 -0
  74. package/data/stacks/svelte.csv +56 -0
  75. package/data/stacks/swiftui.csv +51 -0
  76. package/data/stacks/threejs.csv +54 -0
  77. package/data/stacks/uno.csv +60 -0
  78. package/data/stacks/uwp.csv +56 -0
  79. package/data/stacks/vue.csv +50 -0
  80. package/data/stacks/winui.csv +60 -0
  81. package/data/stacks/wpf.csv +57 -0
  82. package/data/styles.csv +89 -0
  83. package/data/typography.csv +75 -0
  84. package/data/ui-reasoning.csv +193 -0
  85. package/data/ux-guidelines.csv +120 -0
  86. package/evals/catalog_eval.py +56 -0
  87. package/icons/annotations/loop-arrow.tsx +61 -0
  88. package/icons/brands/anthropic.tsx +26 -0
  89. package/icons/brands/apple.tsx +26 -0
  90. package/icons/brands/canva.tsx +26 -0
  91. package/icons/brands/claude-ai.tsx +26 -0
  92. package/icons/brands/discord.tsx +26 -0
  93. package/icons/brands/github.tsx +26 -0
  94. package/icons/brands/gmail.tsx +26 -0
  95. package/icons/brands/google.tsx +26 -0
  96. package/icons/brands/linkedin.tsx +29 -0
  97. package/icons/brands/microsoft.tsx +26 -0
  98. package/icons/brands/next-js.tsx +26 -0
  99. package/icons/brands/producthunt.tsx +26 -0
  100. package/icons/brands/react-js.tsx +29 -0
  101. package/icons/brands/shadcn-ui.tsx +26 -0
  102. package/icons/brands/tailwind-css.tsx +26 -0
  103. package/icons/brands/twitter.tsx +30 -0
  104. package/icons/brands/typescript.tsx +26 -0
  105. package/icons/brands/unsplash.tsx +27 -0
  106. package/icons/brands/vercel.tsx +26 -0
  107. package/icons/brands/whatsapp.tsx +26 -0
  108. package/package.json +9 -3
  109. package/prompts/install-motion-ui.md +17 -0
  110. package/references/agents/thinking-states.md +56 -0
  111. package/references/craft/aqua-button.md +53 -0
  112. package/references/craft/ash-burst-button.md +55 -0
  113. package/references/craft/brutal-button.md +52 -0
  114. package/references/craft/chrome-button.md +53 -0
  115. package/references/craft/click-powerup.md +53 -0
  116. package/references/craft/command-button.md +53 -0
  117. package/references/craft/confetti-button.md +54 -0
  118. package/references/craft/cooldown-button.md +54 -0
  119. package/references/craft/demonic-button.md +53 -0
  120. package/references/craft/dither-button.md +52 -0
  121. package/references/craft/doubt-button.md +53 -0
  122. package/references/craft/evil-eye-button.md +52 -0
  123. package/references/craft/frame-button.md +54 -0
  124. package/references/craft/glitch-button.md +52 -0
  125. package/references/craft/highlight-button.md +53 -0
  126. package/references/craft/hold-button.md +53 -0
  127. package/references/craft/minecraft-button.md +53 -0
  128. package/references/craft/minimal-button.md +52 -0
  129. package/references/craft/morph-status-button.md +53 -0
  130. package/references/craft/movie-pass-button.md +53 -0
  131. package/references/craft/realistic-switch.md +54 -0
  132. package/references/craft/reveal-button.md +53 -0
  133. package/references/craft/shiny-button.md +52 -0
  134. package/references/craft/slide-to-detonate.md +53 -0
  135. package/references/craft/sticky-button.md +54 -0
  136. package/references/craft/thruster-button.md +53 -0
  137. package/references/craft/troll-button.md +54 -0
  138. package/references/guides/design-intelligence.md +125 -0
  139. package/references/guides/interaction-transitions.md +56 -38
  140. package/references/guides/motion-polish-rules.md +75 -0
  141. package/references/guides/stack-best-practices.md +38 -0
  142. package/references/motion/banner-stacking.md +67 -0
  143. package/references/motion/delete-with-smoky-dissolve.md +60 -0
  144. package/references/motion/donut-chart.md +79 -0
  145. package/references/motion/drag-drop-with-physics.md +61 -0
  146. package/references/motion/dropdown-menu-morph.md +55 -0
  147. package/references/motion/get-pro-button.md +56 -0
  148. package/references/motion/image-open-tilt.md +60 -0
  149. package/references/motion/input-clear-with-dissolve.md +58 -0
  150. package/references/motion/learn-more-hover.md +56 -0
  151. package/references/motion/matrix-dot-loader.md +58 -0
  152. package/references/motion/organic-shimmer.md +63 -0
  153. package/references/motion/pro-gradient-text.md +57 -0
  154. package/references/motion/skeleton-loader-and-reveal.md +67 -0
  155. package/references/motion/spinner-to-check-morph.md +67 -0
  156. package/references/motion/spinning-counter.md +74 -0
  157. package/references/motion/text-morph.md +64 -0
  158. package/references/motion/texts-reveal.md +56 -0
  159. package/scripts/build_docs.py +39 -4
  160. package/scripts/core.py +993 -0
  161. package/scripts/design_system.py +1668 -0
  162. package/scripts/reasoning_contract.py +123 -0
  163. package/scripts/search.py +177 -0
  164. package/scripts/test_release.py +12 -0
  165. package/scripts/verify_skill.py +4 -4
  166. package/test/test_installer.mjs +133 -0
@@ -0,0 +1,444 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import {
5
+ animate,
6
+ motion,
7
+ useMotionValue,
8
+ useReducedMotion,
9
+ useTransform,
10
+ type AnimationPlaybackControls,
11
+ type Transition,
12
+ } from "motion/react";
13
+ import { cn } from "@/lib/utils";
14
+
15
+ type SlideState = "idle" | "sliding" | "success";
16
+
17
+ export interface SlideToDetonateProps
18
+ extends Omit<
19
+ React.ButtonHTMLAttributes<HTMLButtonElement>,
20
+ | "onClick"
21
+ | "onDrag"
22
+ | "onDragStart"
23
+ | "onDragEnd"
24
+ | "onAnimationStart"
25
+ | "style"
26
+ > {
27
+ /** Track label shown while idle. Falls back to `label`. */
28
+ children?: React.ReactNode;
29
+ /** Idle label used when no children are provided. */
30
+ label?: React.ReactNode;
31
+ /** Fired once the handle is released past the threshold. */
32
+ onConfirm?: () => void;
33
+ /**
34
+ * Fraction of the track (0-1) the handle must cross to arm the action.
35
+ * @default 0.9
36
+ */
37
+ threshold?: number;
38
+ /** Milliseconds to stay in the success state before resetting. Set to 0 to stay. */
39
+ resetAfter?: number;
40
+ /**
41
+ * How hard the fuse pushes back (0-1). At 0 the handle tracks the pointer
42
+ * one to one; higher values make it lag further behind the pointer the
43
+ * closer it gets to the end, though it still reaches the end.
44
+ * @default 0.35
45
+ */
46
+ resistance?: number;
47
+ /**
48
+ * How softly the handle follows the pointer (0-1). At 0 it is locked to the
49
+ * pointer; higher values let it glide behind on a spring.
50
+ * @default 0.4
51
+ */
52
+ smoothness?: number;
53
+ /**
54
+ * Surface style: a recessed dark groove or a light one.
55
+ * @default "dark"
56
+ */
57
+ variant?: SlideToDetonateVariant;
58
+ }
59
+
60
+ export type SlideToDetonateVariant = "dark" | "light";
61
+
62
+ const VARIANTS: Record<
63
+ SlideToDetonateVariant,
64
+ { track: string; trail: string; handle: string; shimmer: string }
65
+ > = {
66
+ dark: {
67
+ // Recessed track: dark hairline, faint inner ring, soft inner shadow from the top.
68
+ track:
69
+ "bg-[#1c1c1c] shadow-[0_0_0_1px_rgb(0_0_0/0.9),inset_0_0_0_1px_rgb(255_255_255/0.05),inset_0_2px_6px_rgb(0_0_0/0.5),0_1px_0_rgb(255_255_255/0.04)]",
70
+ trail:
71
+ "from-white/0 to-white/12 group-data-armed/slide:to-white/20 group-data-[state=success]/slide:to-white/20",
72
+ handle: cn(
73
+ "text-neutral-50/70",
74
+ // Raised handle: graded dark surface, hairline ring, top highlight, soft drop.
75
+ "bg-linear-to-b from-[#3a3a3a] to-[#2a2a2a] 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.16),0_1px_2px_rgb(0_0_0/0.3),0_4px_10px_-2px_rgb(0_0_0/0.5)]",
76
+ // Armed: the handle lights up with a soft white glow.
77
+ "data-armed:text-neutral-50 data-armed:shadow-[0_0_0_1px_rgb(0_0_0/0.9),inset_0_0_0_1px_rgb(255_255_255/0.18),inset_0_1px_0_rgb(255_255_255/0.2),0_1px_2px_rgb(0_0_0/0.3),0_0_16px_-2px_rgb(255_255_255/0.35)]",
78
+ "data-[state=success]:text-neutral-50",
79
+ "focus-visible:ring-white/40 focus-visible:ring-offset-[#1c1c1c]",
80
+ ),
81
+ shimmer: "250 250 250",
82
+ },
83
+ light: {
84
+ // Recessed track: light hairline, soft inner shadow from the top, white lip below.
85
+ track:
86
+ "bg-neutral-100 shadow-[0_0_0_1px_rgb(0_0_0/0.08),inset_0_1px_3px_rgb(0_0_0/0.08),inset_0_0_0_1px_rgb(0_0_0/0.02),0_1px_0_rgb(255_255_255/0.9)]",
87
+ trail:
88
+ "from-black/0 to-black/8 group-data-armed/slide:to-black/14 group-data-[state=success]/slide:to-black/14",
89
+ handle: cn(
90
+ "text-neutral-500",
91
+ // Raised handle: white face, hairline ring, top highlight, soft drop.
92
+ "bg-linear-to-b from-white to-neutral-50 shadow-[0_0_0_1px_rgb(0_0_0/0.1),inset_0_1px_0_rgb(255_255_255),0_1px_2px_rgb(0_0_0/0.1),0_4px_10px_-2px_rgb(0_0_0/0.12)]",
93
+ // Armed: the ring darkens and a soft shadow halo gathers around it.
94
+ "data-armed:text-neutral-900 data-armed:shadow-[0_0_0_1px_rgb(0_0_0/0.22),inset_0_1px_0_rgb(255_255_255),0_1px_2px_rgb(0_0_0/0.12),0_0_14px_-2px_rgb(0_0_0/0.22)]",
95
+ "data-[state=success]:text-neutral-900",
96
+ "focus-visible:ring-black/25 focus-visible:ring-offset-neutral-100",
97
+ ),
98
+ shimmer: "23 23 23",
99
+ },
100
+ };
101
+
102
+ const HANDLE = 40;
103
+ const TRACK_PADDING = 4;
104
+ /** Keyboard step as a fraction of the track. */
105
+ const KEY_STEP = 0.1;
106
+ /** Farthest in px the handle stretches when pulled back past the start. */
107
+ const PULL_BACK = 10;
108
+
109
+ const SNAP_BACK: Transition = { type: "spring", stiffness: 520, damping: 34, mass: 0.7 };
110
+ const SNAP_END: Transition = { type: "spring", stiffness: 700, damping: 40 };
111
+
112
+ const clamp01 = (value: number) => Math.min(1, Math.max(0, value));
113
+
114
+ /** Pointer travel (0-1) to handle travel (0-1); resistance bends the curve so the end is heavier. */
115
+ function resist(t: number, resistance: number) {
116
+ return Math.pow(t, 1 + resistance * 1.5);
117
+ }
118
+
119
+ function unresist(t: number, resistance: number) {
120
+ return Math.pow(t, 1 / (1 + resistance * 1.5));
121
+ }
122
+
123
+ /** Spring that follows the pointer: stiff and critically damped at 0, loose and floaty at 1. */
124
+ function followSpring(smoothness: number): Transition {
125
+ const s = clamp01(smoothness);
126
+ return {
127
+ type: "spring",
128
+ stiffness: 1400 - s * 1220,
129
+ damping: 70 - s * 46,
130
+ mass: 0.4 + s * 0.4,
131
+ };
132
+ }
133
+
134
+ const ChevronsIcon = () => (
135
+ <svg
136
+ viewBox="0 0 24 24"
137
+ fill="none"
138
+ stroke="currentColor"
139
+ strokeWidth="2"
140
+ strokeLinecap="round"
141
+ strokeLinejoin="round"
142
+ className="size-4"
143
+ aria-hidden
144
+ >
145
+ <path d="m6 17 5-5-5-5" />
146
+ <path d="m13 17 5-5-5-5" />
147
+ </svg>
148
+ );
149
+
150
+ const CheckIcon = ({ className }: { className?: string }) => (
151
+ <svg
152
+ viewBox="0 0 24 24"
153
+ fill="none"
154
+ stroke="currentColor"
155
+ strokeWidth="2.25"
156
+ strokeLinecap="round"
157
+ strokeLinejoin="round"
158
+ className={cn("size-4", className)}
159
+ aria-hidden
160
+ >
161
+ <path d="M20 6 9 17l-5-5" />
162
+ </svg>
163
+ );
164
+
165
+ export const SlideToDetonate = React.forwardRef<
166
+ HTMLButtonElement,
167
+ SlideToDetonateProps
168
+ >(
169
+ (
170
+ {
171
+ children,
172
+ label = "Slide to detonate",
173
+ onConfirm,
174
+ threshold = 0.9,
175
+ resetAfter = 1600,
176
+ resistance = 0.35,
177
+ smoothness = 0.4,
178
+ variant = "dark",
179
+ className,
180
+ disabled,
181
+ onPointerDown,
182
+ onKeyDown,
183
+ onBlur,
184
+ ...props
185
+ },
186
+ ref,
187
+ ) => {
188
+ const reduceMotion = useReducedMotion();
189
+
190
+ const trackRef = React.useRef<HTMLDivElement | null>(null);
191
+ const resetTimeoutRef = React.useRef<number | null>(null);
192
+ const controlsRef = React.useRef<AnimationPlaybackControls | null>(null);
193
+ // Pointer x at which the handle would sit at the start of the track.
194
+ const originRef = React.useRef(0);
195
+ const armedRef = React.useRef(false);
196
+ const draggingRef = React.useRef(false);
197
+
198
+ const [state, setState] = React.useState<SlideState>("idle");
199
+ const [armed, setArmed] = React.useState(false);
200
+ const [range, setRange] = React.useState(0);
201
+ const [percent, setPercent] = React.useState(0);
202
+
203
+ const x = useMotionValue(0);
204
+ const progress = useTransform(() => (range > 0 ? clamp01(x.get() / range) : 0));
205
+ const labelOpacity = useTransform(progress, [0, 0.6], [1, 0]);
206
+ const trailWidth = useTransform(() => Math.max(0, x.get()) + HANDLE);
207
+ const trailOpacity = useTransform(progress, [0, 0.15, 1], [0, 0.55, 1]);
208
+
209
+ const safeThreshold = clamp01(threshold);
210
+ const isSuccess = state === "success";
211
+ const locked = disabled || isSuccess;
212
+ const labelText = children ?? label;
213
+ const styles = VARIANTS[variant];
214
+
215
+ const measure = React.useCallback(() => {
216
+ const node = trackRef.current;
217
+ if (!node) return;
218
+ setRange(Math.max(0, node.clientWidth - HANDLE - TRACK_PADDING * 2));
219
+ }, []);
220
+
221
+ React.useEffect(() => {
222
+ measure();
223
+ const node = trackRef.current;
224
+ if (!node || typeof ResizeObserver === "undefined") return;
225
+ const observer = new ResizeObserver(measure);
226
+ observer.observe(node);
227
+ return () => observer.disconnect();
228
+ }, [measure]);
229
+
230
+ React.useEffect(
231
+ () => () => {
232
+ controlsRef.current?.stop();
233
+ if (resetTimeoutRef.current !== null) {
234
+ window.clearTimeout(resetTimeoutRef.current);
235
+ }
236
+ },
237
+ [],
238
+ );
239
+
240
+ // Mirror progress into a coarse percentage for aria-valuenow without re-rendering every frame.
241
+ React.useEffect(
242
+ () =>
243
+ progress.on("change", (value) => {
244
+ setPercent((current) => {
245
+ const next = Math.round(value * 100);
246
+ return current === next ? current : next;
247
+ });
248
+ }),
249
+ [progress],
250
+ );
251
+
252
+ const moveTo = (to: number, transition: Transition | null) => {
253
+ controlsRef.current?.stop();
254
+ if (!transition || reduceMotion) {
255
+ x.set(to);
256
+ return;
257
+ }
258
+ controlsRef.current = animate(x, to, transition);
259
+ };
260
+
261
+ const setArmedState = (next: boolean) => {
262
+ if (armedRef.current === next) return;
263
+ armedRef.current = next;
264
+ setArmed(next);
265
+ // A tiny tick on phones when the fuse arms.
266
+ if (next) navigator.vibrate?.(8);
267
+ };
268
+
269
+ const fire = () => {
270
+ setArmedState(false);
271
+ setState("success");
272
+ moveTo(range, SNAP_END);
273
+ onConfirm?.();
274
+ if (resetAfter > 0) {
275
+ resetTimeoutRef.current = window.setTimeout(() => {
276
+ resetTimeoutRef.current = null;
277
+ setState("idle");
278
+ moveTo(0, SNAP_BACK);
279
+ }, resetAfter);
280
+ }
281
+ };
282
+
283
+ const release = () => {
284
+ if (armedRef.current) {
285
+ fire();
286
+ } else {
287
+ setState("idle");
288
+ moveTo(0, SNAP_BACK);
289
+ }
290
+ };
291
+
292
+ const handlePointerDown = (event: React.PointerEvent<HTMLButtonElement>) => {
293
+ onPointerDown?.(event);
294
+ if (locked || range <= 0 || event.defaultPrevented) return;
295
+ if (event.pointerType === "mouse" && event.button !== 0) return;
296
+
297
+ event.currentTarget.setPointerCapture(event.pointerId);
298
+ // Start from wherever the handle currently is, mapped back into pointer space.
299
+ const current = clamp01(x.get() / range);
300
+ originRef.current = event.clientX - unresist(current, resistance) * range;
301
+ draggingRef.current = true;
302
+ setState("sliding");
303
+ };
304
+
305
+ const handlePointerMove = (event: React.PointerEvent<HTMLButtonElement>) => {
306
+ if (!draggingRef.current || range <= 0) return;
307
+
308
+ const raw = event.clientX - originRef.current;
309
+ let next: number;
310
+ if (raw < 0) {
311
+ // Rubber-band a little when pulled back past the start.
312
+ next = -PULL_BACK * (1 - 1 / (1 + -raw / 60));
313
+ } else {
314
+ next = resist(clamp01(raw / range), resistance) * range;
315
+ }
316
+
317
+ moveTo(next, smoothness > 0 ? followSpring(smoothness) : null);
318
+ setArmedState(next / range >= safeThreshold);
319
+ };
320
+
321
+ const handlePointerEnd = () => {
322
+ if (!draggingRef.current) return;
323
+ draggingRef.current = false;
324
+ release();
325
+ };
326
+
327
+ const handleKeyDown = (event: React.KeyboardEvent<HTMLButtonElement>) => {
328
+ onKeyDown?.(event);
329
+ if (locked || range <= 0 || event.defaultPrevented) return;
330
+
331
+ const current = clamp01(x.get() / range);
332
+ let next: number | null = null;
333
+ if (event.key === "ArrowRight" || event.key === "ArrowUp") next = current + KEY_STEP;
334
+ else if (event.key === "ArrowLeft" || event.key === "ArrowDown") next = current - KEY_STEP;
335
+ else if (event.key === "Home") next = 0;
336
+ else if (event.key === "End") next = 1;
337
+ if (next === null) return;
338
+
339
+ event.preventDefault();
340
+ next = clamp01(next);
341
+ if (next >= safeThreshold) {
342
+ fire();
343
+ return;
344
+ }
345
+ setState(next > 0 ? "sliding" : "idle");
346
+ moveTo(next * range, followSpring(smoothness));
347
+ };
348
+
349
+ const handleBlur = (event: React.FocusEvent<HTMLButtonElement>) => {
350
+ onBlur?.(event);
351
+ // Keyboard progress doesn't linger once focus leaves.
352
+ if (!isSuccess && x.get() !== 0) {
353
+ setArmedState(false);
354
+ setState("idle");
355
+ moveTo(0, SNAP_BACK);
356
+ }
357
+ };
358
+
359
+ return (
360
+ <div
361
+ ref={trackRef}
362
+ data-state={state}
363
+ data-armed={armed || undefined}
364
+ className={cn(
365
+ "group/slide relative inline-flex h-12 min-w-72 items-center overflow-hidden rounded-full select-none",
366
+ styles.track,
367
+ disabled && "cursor-not-allowed opacity-50",
368
+ className,
369
+ )}
370
+ >
371
+ {/* Trail that fills in behind the handle. */}
372
+ <motion.span
373
+ aria-hidden
374
+ className={cn(
375
+ "pointer-events-none absolute top-1 bottom-1 left-1 rounded-full bg-linear-to-r",
376
+ styles.trail,
377
+ )}
378
+ style={{ width: trailWidth, opacity: trailOpacity }}
379
+ />
380
+
381
+ {/* Label centered in the free part of the track, right of the handle. Once detonated only the handle's check remains. */}
382
+ <span className="pointer-events-none absolute inset-0 flex items-center justify-center pl-11 text-sm font-medium">
383
+ {isSuccess ? null : (
384
+ <motion.span
385
+ style={{
386
+ opacity: labelOpacity,
387
+ backgroundImage: `linear-gradient(90deg, rgb(${styles.shimmer} / 0.4) 0%, rgb(${styles.shimmer} / 0.4) 40%, rgb(${styles.shimmer} / 0.95) 50%, rgb(${styles.shimmer} / 0.4) 60%, rgb(${styles.shimmer} / 0.4) 100%)`,
388
+ backgroundSize: "250% 100%",
389
+ }}
390
+ // A slow shimmer sweeping toward the end, like "slide to unlock".
391
+ animate={
392
+ reduceMotion || disabled
393
+ ? { backgroundPosition: "50% 0" }
394
+ : { backgroundPosition: ["100% 0", "0% 0"] }
395
+ }
396
+ transition={{ duration: 2.6, ease: "linear", repeat: Infinity }}
397
+ className="bg-clip-text text-transparent"
398
+ >
399
+ {labelText}
400
+ </motion.span>
401
+ )}
402
+ </span>
403
+
404
+ {/* Draggable handle. */}
405
+ <motion.button
406
+ ref={ref}
407
+ type="button"
408
+ role="slider"
409
+ aria-label={typeof labelText === "string" ? labelText : "Slide to confirm"}
410
+ aria-valuemin={0}
411
+ aria-valuemax={100}
412
+ aria-valuenow={isSuccess ? 100 : percent}
413
+ aria-valuetext={isSuccess ? "Confirmed" : `${percent}%`}
414
+ disabled={disabled}
415
+ data-state={state}
416
+ data-armed={armed || undefined}
417
+ onPointerDown={handlePointerDown}
418
+ onPointerMove={handlePointerMove}
419
+ onPointerUp={handlePointerEnd}
420
+ onPointerCancel={handlePointerEnd}
421
+ onLostPointerCapture={handlePointerEnd}
422
+ onKeyDown={handleKeyDown}
423
+ onBlur={handleBlur}
424
+ style={{ x }}
425
+ className={cn(
426
+ "absolute top-1 left-1 z-10 inline-flex size-10 touch-none items-center justify-center rounded-full outline-none",
427
+ "transition-[color,filter,box-shadow] duration-200 hover:brightness-110",
428
+ "focus-visible:ring-2 focus-visible:ring-offset-2",
429
+ styles.handle,
430
+ locked ? "cursor-default" : "cursor-grab data-[state=sliding]:cursor-grabbing",
431
+ disabled && "cursor-not-allowed",
432
+ )}
433
+ {...props}
434
+ >
435
+ {isSuccess ? <CheckIcon /> : <ChevronsIcon />}
436
+ </motion.button>
437
+ </div>
438
+ );
439
+ },
440
+ );
441
+
442
+ SlideToDetonate.displayName = "SlideToDetonate";
443
+
444
+ export default SlideToDetonate;
@@ -0,0 +1,184 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import {
5
+ motion,
6
+ useMotionTemplate,
7
+ useMotionValue,
8
+ useReducedMotion,
9
+ useSpring,
10
+ useTransform,
11
+ } from "motion/react";
12
+ import { cn } from "@/lib/utils";
13
+
14
+ export interface StickyButtonProps
15
+ extends Omit<
16
+ React.ButtonHTMLAttributes<HTMLButtonElement>,
17
+ "onDrag" | "onDragStart" | "onDragEnd" | "onAnimationStart"
18
+ > {
19
+ /** Distance in px beyond the button's edge where the pull starts. */
20
+ radius?: number;
21
+ /** How far the body follows the cursor, as a fraction of the cursor offset. */
22
+ strength?: number;
23
+ /** How far the label drifts inside the body, from 0 (fixed) to 1 (edge of the padding). */
24
+ parallax?: number;
25
+ /** Maximum tilt in degrees while the body is pulled. */
26
+ tilt?: number;
27
+ }
28
+
29
+ // Largest label drift at `parallax = 1`, kept inside the button's padding.
30
+ const MAX_LABEL_SHIFT = { x: 12, y: 5 };
31
+
32
+ const BODY_SPRING = { stiffness: 170, damping: 16, mass: 0.6 };
33
+ // The label lags a little behind the body so the two layers visibly separate.
34
+ const LABEL_SPRING = { stiffness: 120, damping: 14, mass: 0.7 };
35
+
36
+ /** 1 inside the button, easing smoothly to 0 at the edge of the field. */
37
+ function falloff(t: number) {
38
+ if (t <= 0) return 1;
39
+ if (t >= 1) return 0;
40
+ return 1 - t * t * (3 - 2 * t);
41
+ }
42
+
43
+ const StickyButton = React.forwardRef<HTMLButtonElement, StickyButtonProps>(
44
+ (
45
+ {
46
+ children,
47
+ className,
48
+ radius = 120,
49
+ strength = 0.45,
50
+ parallax = 0.35,
51
+ tilt = 8,
52
+ disabled,
53
+ type = "button",
54
+ ...props
55
+ },
56
+ ref,
57
+ ) => {
58
+ const wrapperRef = React.useRef<HTMLSpanElement>(null);
59
+ const reduceMotion = useReducedMotion();
60
+
61
+ const pullX = useMotionValue(0);
62
+ const pullY = useMotionValue(0);
63
+ const labelPullX = useMotionValue(0);
64
+ const labelPullY = useMotionValue(0);
65
+ const glowX = useMotionValue(0);
66
+ const glowY = useMotionValue(0);
67
+ const engaged = useMotionValue(0);
68
+
69
+ const x = useSpring(pullX, BODY_SPRING);
70
+ const y = useSpring(pullY, BODY_SPRING);
71
+ const labelX = useSpring(labelPullX, LABEL_SPRING);
72
+ const labelY = useSpring(labelPullY, LABEL_SPRING);
73
+ const glowOpacity = useSpring(engaged, { stiffness: 200, damping: 30 });
74
+
75
+ const reach = Math.max(radius, 1) * strength;
76
+ const rotateY = useTransform(x, [-reach, reach], [-tilt, tilt]);
77
+ const rotateX = useTransform(y, [-reach, reach], [tilt, -tilt]);
78
+ const glow = useMotionTemplate`radial-gradient(120px circle at ${glowX}px ${glowY}px, color-mix(in oklab, var(--foreground) 12%, transparent), transparent 70%)`;
79
+
80
+ React.useEffect(() => {
81
+ if (reduceMotion || disabled) return;
82
+
83
+ const release = () => {
84
+ pullX.set(0);
85
+ pullY.set(0);
86
+ labelPullX.set(0);
87
+ labelPullY.set(0);
88
+ engaged.set(0);
89
+ };
90
+
91
+ const onPointerMove = (event: PointerEvent) => {
92
+ if (event.pointerType === "touch") return;
93
+ const wrapper = wrapperRef.current;
94
+ if (!wrapper) return;
95
+
96
+ // The wrapper never moves, so it is a stable resting frame to measure from.
97
+ const rect = wrapper.getBoundingClientRect();
98
+ const dx = event.clientX - (rect.left + rect.width / 2);
99
+ const dy = event.clientY - (rect.top + rect.height / 2);
100
+ const outsideX = Math.max(Math.abs(dx) - rect.width / 2, 0);
101
+ const outsideY = Math.max(Math.abs(dy) - rect.height / 2, 0);
102
+ const pull = falloff(Math.hypot(outsideX, outsideY) / radius);
103
+
104
+ if (pull === 0) {
105
+ release();
106
+ return;
107
+ }
108
+
109
+ pullX.set(dx * strength * pull);
110
+ pullY.set(dy * strength * pull);
111
+ const nx = Math.max(-1, Math.min(1, dx / (rect.width / 2)));
112
+ const ny = Math.max(-1, Math.min(1, dy / (rect.height / 2)));
113
+ labelPullX.set(nx * MAX_LABEL_SHIFT.x * parallax * pull);
114
+ labelPullY.set(ny * MAX_LABEL_SHIFT.y * parallax * pull);
115
+ glowX.set(event.clientX - rect.left);
116
+ glowY.set(event.clientY - rect.top);
117
+ engaged.set(pull);
118
+ };
119
+
120
+ window.addEventListener("pointermove", onPointerMove, { passive: true });
121
+ document.documentElement.addEventListener("pointerleave", release);
122
+ window.addEventListener("blur", release);
123
+ return () => {
124
+ window.removeEventListener("pointermove", onPointerMove);
125
+ document.documentElement.removeEventListener("pointerleave", release);
126
+ window.removeEventListener("blur", release);
127
+ release();
128
+ };
129
+ }, [
130
+ radius,
131
+ strength,
132
+ parallax,
133
+ reduceMotion,
134
+ disabled,
135
+ pullX,
136
+ pullY,
137
+ labelPullX,
138
+ labelPullY,
139
+ glowX,
140
+ glowY,
141
+ engaged,
142
+ ]);
143
+
144
+ return (
145
+ <span
146
+ ref={wrapperRef}
147
+ className="relative inline-flex [perspective:600px]"
148
+ >
149
+ <motion.button
150
+ ref={ref}
151
+ type={type}
152
+ disabled={disabled}
153
+ style={{ x, y, rotateX, rotateY }}
154
+ whileTap={disabled ? undefined : { scale: 0.95 }}
155
+ transition={{ type: "spring", stiffness: 400, damping: 22 }}
156
+ className={cn(
157
+ "relative inline-flex h-9 cursor-pointer items-center justify-center rounded-md border border-dashed border-border bg-background px-4 text-sm font-medium text-foreground shadow-[0_1px_2px_rgb(0_0_0/0.05),0_2px_6px_-3px_rgb(0_0_0/0.07),inset_0_-1px_0_rgb(0_0_0/0.03)] dark:shadow-[0_1px_2px_rgb(0_0_0/0.4),inset_0_1px_0_rgb(255_255_255/0.05)] outline-none select-none transform-3d",
158
+ "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",
159
+ className,
160
+ )}
161
+ {...props}
162
+ >
163
+ {/* Soft spotlight that tracks the cursor across the face. */}
164
+ <motion.span
165
+ aria-hidden
166
+ className="pointer-events-none absolute inset-0 rounded-[inherit]"
167
+ style={{ backgroundImage: glow, opacity: glowOpacity }}
168
+ />
169
+ <motion.span
170
+ className="relative inline-flex items-center gap-1.5 whitespace-nowrap"
171
+ style={{ x: labelX, y: labelY }}
172
+ >
173
+ {children}
174
+ </motion.span>
175
+ </motion.button>
176
+ </span>
177
+ );
178
+ },
179
+ );
180
+
181
+ StickyButton.displayName = "StickyButton";
182
+
183
+ export { StickyButton };
184
+ export default StickyButton;