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.
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,211 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import type { ComponentPropsWithoutRef } from "react";
5
+ import { motion, type Variants } from "motion/react";
6
+ import { cn } from "@/lib/utils";
7
+
8
+ type ButtonVariant = "default" | "secondary" | "outline";
9
+ type Href = string;
10
+
11
+ const MotionLink = motion.a;
12
+
13
+ type BaseProps = {
14
+ children: React.ReactNode;
15
+ variant?: ButtonVariant;
16
+ className?: string;
17
+ /** Soft glow that blooms behind the button on hover. */
18
+ glow?: boolean;
19
+ /** Corner marker size: px as a number, or a Tailwind size class like `"size-4"`. */
20
+ size?: number | string;
21
+ /** Distance in px the markers sit outside the button's edge. */
22
+ offset?: number;
23
+ /** How far in px the markers spread out on hover. */
24
+ hoverOffset?: number;
25
+ };
26
+
27
+ type ButtonProps = BaseProps &
28
+ Omit<ComponentPropsWithoutRef<typeof motion.button>, "children"> & {
29
+ as?: "button";
30
+ href?: never;
31
+ };
32
+
33
+ type AnchorProps = BaseProps &
34
+ Omit<ComponentPropsWithoutRef<typeof motion.a>, "href" | "children"> & {
35
+ as: "link";
36
+ href: Href;
37
+ };
38
+
39
+ export type FrameButtonProps = ButtonProps | AnchorProps;
40
+
41
+ const VARIANTS: Record<ButtonVariant, string> = {
42
+ // Graded dark surface: dark outer hairline, faint inner ring, top highlight, soft drop, plus the shared press.
43
+ default: "border-transparent text-neutral-50 hover:brightness-110 active:brightness-95 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)] 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)]",
44
+ secondary:
45
+ "border-border bg-secondary text-secondary-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)] hover:border-foreground hover:bg-foreground hover:text-background",
46
+ outline: "border-border bg-transparent text-foreground hover:bg-foreground/5 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)]",
47
+ };
48
+
49
+ const SPRING = { type: "spring", stiffness: 380, damping: 24 } as const;
50
+
51
+ // Diagonal light band that sweeps across the face on hover.
52
+ const sweepVariants: Variants = {
53
+ rest: { x: "-120%", transition: { duration: 0 } },
54
+ hover: { x: "320%", transition: { duration: 0.9, ease: [0.4, 0, 0.2, 1] } },
55
+ tap: { x: "320%" },
56
+ };
57
+
58
+ const glowVariants: Variants = {
59
+ rest: { opacity: 0, scale: 0.9 },
60
+ hover: { opacity: 0.35, scale: 1.08 },
61
+ tap: { opacity: 0.5, scale: 1 },
62
+ };
63
+
64
+ export function FrameButton({
65
+ children,
66
+ className,
67
+ variant = "default",
68
+ glow = false,
69
+ size = 14,
70
+ offset = 6,
71
+ hoverOffset = 5,
72
+ ...props
73
+ }: FrameButtonProps) {
74
+ const classes = cn(
75
+ "group/frame relative inline-flex cursor-pointer items-center justify-center border px-8 py-3.5 text-xs font-medium tracking-[0.22em] uppercase no-underline outline-none select-none",
76
+ // Press eases in fast; release springs back on the slower base curve.
77
+ "transition-[scale,filter,box-shadow,background-color,border-color,color] duration-300 ease-[cubic-bezier(0.34,1.35,0.64,1)] active:scale-[0.97] active:duration-100 active:ease-out motion-reduce:active:scale-100",
78
+ "focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-4 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-50",
79
+ VARIANTS[variant],
80
+ className,
81
+ );
82
+
83
+ const content = (
84
+ <>
85
+ {glow ? (
86
+ <motion.span
87
+ aria-hidden
88
+ variants={glowVariants}
89
+ transition={SPRING}
90
+ className="pointer-events-none absolute inset-0 -z-10 bg-foreground blur-2xl"
91
+ />
92
+ ) : null}
93
+ <span
94
+ aria-hidden
95
+ className="pointer-events-none absolute inset-0 overflow-hidden"
96
+ >
97
+ <motion.span
98
+ variants={sweepVariants}
99
+ className="absolute inset-y-0 left-0 w-1/3 -skew-x-12 bg-linear-to-r from-transparent via-current/15 to-transparent"
100
+ />
101
+ </span>
102
+ <span className="relative inline-flex items-center gap-2">
103
+ {children}
104
+ </span>
105
+ <FrameMarkers size={size} offset={offset} hoverOffset={hoverOffset} />
106
+ </>
107
+ );
108
+
109
+ const motionProps = {
110
+ initial: "rest",
111
+ animate: "rest",
112
+ whileHover: "hover",
113
+ whileTap: "tap",
114
+ whileFocus: "hover",
115
+ } as const;
116
+
117
+ if (props.as === "link") {
118
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
119
+ const { as, href, ...anchorProps } = props;
120
+ return (
121
+ <MotionLink
122
+ href={href}
123
+ className={classes}
124
+ {...motionProps}
125
+ {...anchorProps}
126
+ >
127
+ {content}
128
+ </MotionLink>
129
+ );
130
+ }
131
+
132
+ // eslint-disable-next-line @typescript-eslint/no-unused-vars
133
+ const { as, type = "button", ...buttonProps } = props;
134
+ return (
135
+ <motion.button
136
+ type={type}
137
+ className={classes}
138
+ {...motionProps}
139
+ {...buttonProps}
140
+ >
141
+ {content}
142
+ </motion.button>
143
+ );
144
+ }
145
+
146
+ interface FrameMarkersProps {
147
+ className?: string;
148
+ size?: number | string;
149
+ offset?: number;
150
+ hoverOffset?: number;
151
+ }
152
+
153
+ const MARKERS = [
154
+ { key: "tl", x: -1, y: -1, className: "border-t-[1.5px] border-l-[1.5px]" },
155
+ { key: "tr", x: 1, y: -1, className: "border-t-[1.5px] border-r-[1.5px]" },
156
+ { key: "bl", x: -1, y: 1, className: "border-b-[1.5px] border-l-[1.5px]" },
157
+ { key: "br", x: 1, y: 1, className: "border-b-[1.5px] border-r-[1.5px]" },
158
+ ] as const;
159
+
160
+ const markerVariants: Variants = {
161
+ rest: { x: 0, y: 0 },
162
+ hover: ({ x, y, spread }: { x: number; y: number; spread: number }) => ({
163
+ x: x * spread,
164
+ y: y * spread,
165
+ }),
166
+ // Lock on: snap in tight against the button's edge.
167
+ tap: ({ x, y, offset }: { x: number; y: number; offset: number }) => ({
168
+ x: -x * (offset - 1),
169
+ y: -y * (offset - 1),
170
+ }),
171
+ };
172
+
173
+ /**
174
+ * Four corner brackets around the nearest `motion` parent. They follow its
175
+ * `rest` / `hover` / `tap` variants, so the parent needs those states set.
176
+ */
177
+ export function FrameMarkers({
178
+ className,
179
+ size = 14,
180
+ offset = 6,
181
+ hoverOffset = 5,
182
+ }: FrameMarkersProps) {
183
+ const sizeClass = typeof size === "string" ? size : undefined;
184
+ const sizeStyle =
185
+ typeof size === "number" ? { width: size, height: size } : {};
186
+
187
+ return (
188
+ <>
189
+ {MARKERS.map((marker) => (
190
+ <motion.span
191
+ key={marker.key}
192
+ aria-hidden
193
+ custom={{ x: marker.x, y: marker.y, spread: hoverOffset, offset }}
194
+ variants={markerVariants}
195
+ transition={SPRING}
196
+ className={cn(
197
+ "pointer-events-none absolute border-foreground/35 transition-colors duration-300 group-hover/frame:border-foreground group-focus-visible/frame:border-foreground",
198
+ marker.className,
199
+ sizeClass,
200
+ className,
201
+ )}
202
+ style={{
203
+ ...sizeStyle,
204
+ [marker.y < 0 ? "top" : "bottom"]: -offset,
205
+ [marker.x < 0 ? "left" : "right"]: -offset,
206
+ }}
207
+ />
208
+ ))}
209
+ </>
210
+ );
211
+ }
@@ -0,0 +1,243 @@
1
+ "use client";
2
+
3
+ import {
4
+ useEffect,
5
+ useRef,
6
+ useState,
7
+ useSyncExternalStore,
8
+ type ButtonHTMLAttributes,
9
+ type CSSProperties,
10
+ type MouseEvent,
11
+ } from "react";
12
+ import { cn } from "@/lib/utils";
13
+
14
+ const STYLES = `
15
+ @keyframes eb-glitch-1 {
16
+ 0% { clip-path: inset(31% 0 40% 0); transform: translate(calc(-3px * var(--eb-shift, 1)), 0); }
17
+ 20% { clip-path: inset(76% 0 5% 0); transform: translate(calc( 3px * var(--eb-shift, 1)), 0); }
18
+ 40% { clip-path: inset(10% 0 63% 0); transform: translate(calc(-2px * var(--eb-shift, 1)), 0); }
19
+ 60% { clip-path: inset(55% 0 18% 0); transform: translate(calc( 4px * var(--eb-shift, 1)), 0); }
20
+ 80% { clip-path: inset( 2% 0 84% 0); transform: translate(calc(-3px * var(--eb-shift, 1)), 0); }
21
+ 100% { clip-path: inset(31% 0 40% 0); transform: translate(calc(-3px * var(--eb-shift, 1)), 0); }
22
+ }
23
+ @keyframes eb-glitch-2 {
24
+ 0% { clip-path: inset(60% 0 10% 0); transform: translate(calc( 2px * var(--eb-shift, 1)), 0); }
25
+ 20% { clip-path: inset(14% 0 52% 0); transform: translate(calc(-4px * var(--eb-shift, 1)), 0); }
26
+ 40% { clip-path: inset(82% 0 3% 0); transform: translate(calc( 2px * var(--eb-shift, 1)), 0); }
27
+ 60% { clip-path: inset(25% 0 45% 0); transform: translate(calc(-3px * var(--eb-shift, 1)), 0); }
28
+ 80% { clip-path: inset( 6% 0 70% 0); transform: translate(calc( 3px * var(--eb-shift, 1)), 0); }
29
+ 100% { clip-path: inset(60% 0 10% 0); transform: translate(calc( 2px * var(--eb-shift, 1)), 0); }
30
+ }
31
+ @keyframes eb-glitch-shake {
32
+ 0%, 100% { transform: translate(0, 0); }
33
+ 15% { transform: translate(calc(-2px * var(--eb-shift, 1)), calc( 1px * var(--eb-shift, 1))); }
34
+ 35% { transform: translate(calc( 2px * var(--eb-shift, 1)), calc(-1px * var(--eb-shift, 1))); }
35
+ 55% { transform: translate(calc(-1px * var(--eb-shift, 1)), calc( 2px * var(--eb-shift, 1))); }
36
+ 75% { transform: translate(calc( 1px * var(--eb-shift, 1)), calc(-2px * var(--eb-shift, 1))); }
37
+ 90% { transform: translate(calc(-2px * var(--eb-shift, 1)), 0); }
38
+ }
39
+ @keyframes eb-glitch-flicker {
40
+ 0%, 18%, 22%, 25%, 53%, 57%, 100% { opacity: 1; }
41
+ 19%, 23%, 54%, 56% { opacity: 0.35; }
42
+ }
43
+ `;
44
+
45
+ function injectKeyframes() {
46
+ if (typeof document === "undefined") return;
47
+ if (document.querySelector("style[data-eb-glitch]")) return;
48
+ const el = document.createElement("style");
49
+ el.setAttribute("data-eb-glitch", "");
50
+ el.textContent = STYLES;
51
+ document.head.appendChild(el);
52
+ }
53
+
54
+ const REDUCED_MOTION_QUERY = "(prefers-reduced-motion: reduce)";
55
+
56
+ function subscribeReducedMotion(callback: () => void) {
57
+ const query = window.matchMedia(REDUCED_MOTION_QUERY);
58
+ query.addEventListener("change", callback);
59
+ return () => query.removeEventListener("change", callback);
60
+ }
61
+
62
+ function usePrefersReducedMotion() {
63
+ return useSyncExternalStore(
64
+ subscribeReducedMotion,
65
+ () => window.matchMedia(REDUCED_MOTION_QUERY).matches,
66
+ () => false,
67
+ );
68
+ }
69
+
70
+ /** When the glitch fires: timed bursts, only on hover, or continuously. */
71
+ export type GlitchTrigger = "auto" | "hover" | "always";
72
+
73
+ const DEFAULT_COLORS: [string, string] = ["#ef4444", "#22d3ee"];
74
+
75
+ export type GlitchButtonProps = ButtonHTMLAttributes<HTMLButtonElement> & {
76
+ /** Base milliseconds between automatic glitch bursts (±20% random jitter). Used when `trigger` is `"auto"`. */
77
+ glitchInterval?: number;
78
+ /** Duration in milliseconds of a single glitch burst. */
79
+ glitchDuration?: number;
80
+ /** The two RGB-split channel colors, `[channelA, channelB]`. */
81
+ colors?: [string, string];
82
+ /** Multiplier on the channel and shake displacement. Higher is more violent. */
83
+ intensity?: number;
84
+ /** When the glitch fires. */
85
+ trigger?: GlitchTrigger;
86
+ /** Toggle the scanline overlay. */
87
+ scanlines?: boolean;
88
+ };
89
+
90
+ export function GlitchButton({
91
+ children,
92
+ className,
93
+ glitchInterval = 3500,
94
+ glitchDuration = 450,
95
+ colors = DEFAULT_COLORS,
96
+ intensity = 1,
97
+ trigger = "hover",
98
+ scanlines = true,
99
+ style,
100
+ onMouseEnter,
101
+ onMouseLeave,
102
+ ...props
103
+ }: GlitchButtonProps) {
104
+ const reduceMotion = usePrefersReducedMotion();
105
+ const [bursting, setBursting] = useState(false);
106
+ const [hovered, setHovered] = useState(false);
107
+ const hoverRef = useRef(false);
108
+
109
+ useEffect(() => {
110
+ injectKeyframes();
111
+ if (reduceMotion || trigger !== "auto") return;
112
+
113
+ let offTimer: ReturnType<typeof setTimeout> | undefined;
114
+ let nextTimer: ReturnType<typeof setTimeout> | undefined;
115
+
116
+ const schedule = () => {
117
+ const jitter = (Math.random() - 0.5) * glitchInterval * 0.4;
118
+ nextTimer = setTimeout(() => {
119
+ if (hoverRef.current) {
120
+ schedule();
121
+ return;
122
+ }
123
+ setBursting(true);
124
+ offTimer = setTimeout(() => {
125
+ setBursting(false);
126
+ schedule();
127
+ }, glitchDuration);
128
+ }, glitchInterval + jitter);
129
+ };
130
+
131
+ schedule();
132
+
133
+ return () => {
134
+ clearTimeout(offTimer);
135
+ clearTimeout(nextTimer);
136
+ };
137
+ }, [trigger, glitchInterval, glitchDuration, reduceMotion]);
138
+
139
+ const hoverDriven = trigger !== "always";
140
+
141
+ const handleMouseEnter = (event: MouseEvent<HTMLButtonElement>) => {
142
+ if (hoverDriven && !reduceMotion) {
143
+ hoverRef.current = true;
144
+ setHovered(true);
145
+ }
146
+ onMouseEnter?.(event);
147
+ };
148
+
149
+ const handleMouseLeave = (event: MouseEvent<HTMLButtonElement>) => {
150
+ if (hoverDriven && !reduceMotion) {
151
+ hoverRef.current = false;
152
+ setHovered(false);
153
+ setBursting(false);
154
+ }
155
+ onMouseLeave?.(event);
156
+ };
157
+
158
+ const active = reduceMotion
159
+ ? false
160
+ : trigger === "always"
161
+ ? true
162
+ : trigger === "hover"
163
+ ? hovered
164
+ : bursting || hovered;
165
+
166
+ const burst = `${Math.round(glitchDuration * 0.7)}ms`;
167
+ const [channelA, channelB] = colors;
168
+
169
+ const rootStyle = {
170
+ isolation: "isolate",
171
+ "--eb-shift": intensity,
172
+ animation: active ? `eb-glitch-shake ${burst} linear infinite` : undefined,
173
+ ...style,
174
+ } as CSSProperties;
175
+
176
+ return (
177
+ <button
178
+ {...props}
179
+ onMouseEnter={handleMouseEnter}
180
+ onMouseLeave={handleMouseLeave}
181
+ className={cn(
182
+ "relative inline-flex h-9 cursor-pointer items-center justify-center overflow-hidden rounded-[10px] px-6 font-mono text-xs font-semibold tracking-widest text-neutral-50 uppercase select-none",
183
+ // Graded dark surface: dark outer hairline, faint inner ring, top highlight, soft drop.
184
+ "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)]",
185
+ // The glitch shake keyframes own `transform`, so the press animates the separate `scale` property.
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
+ "outline-none 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",
190
+ className,
191
+ )}
192
+ style={rootStyle}
193
+ >
194
+ <span
195
+ aria-hidden
196
+ className="pointer-events-none absolute inset-0 flex items-center justify-center px-6 font-mono text-xs font-semibold tracking-widest uppercase"
197
+ >
198
+ <span
199
+ style={{
200
+ color: channelA,
201
+ mixBlendMode: "screen",
202
+ animation: active ? `eb-glitch-1 ${burst} steps(1) infinite` : undefined,
203
+ }}
204
+ >
205
+ {children}
206
+ </span>
207
+ </span>
208
+
209
+ <span
210
+ aria-hidden
211
+ className="pointer-events-none absolute inset-0 flex items-center justify-center px-6 font-mono text-xs font-semibold tracking-widest uppercase"
212
+ >
213
+ <span
214
+ style={{
215
+ color: channelB,
216
+ mixBlendMode: "screen",
217
+ animation: active ? `eb-glitch-2 ${burst} steps(1) infinite` : undefined,
218
+ }}
219
+ >
220
+ {children}
221
+ </span>
222
+ </span>
223
+
224
+ {scanlines ? (
225
+ <span
226
+ aria-hidden
227
+ className="pointer-events-none absolute inset-0 bg-[repeating-linear-gradient(0deg,transparent,transparent_2px,rgba(0,0,0,0.1)_2px,rgba(0,0,0,0.1)_4px)]"
228
+ />
229
+ ) : null}
230
+
231
+ <span
232
+ className="relative z-10"
233
+ style={{
234
+ animation: active ? `eb-glitch-flicker ${burst} linear infinite` : undefined,
235
+ }}
236
+ >
237
+ {children}
238
+ </span>
239
+ </button>
240
+ );
241
+ }
242
+
243
+ export default GlitchButton;
@@ -0,0 +1,196 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { motion } from "motion/react";
5
+ import { cn } from "@/lib/utils";
6
+
7
+ export interface HighlightButtonProps extends Omit<
8
+ React.ButtonHTMLAttributes<HTMLButtonElement>,
9
+ "onDrag" | "onDragStart" | "onDragEnd" | "onAnimationStart"
10
+ > {
11
+ /** Surface style of the button. */
12
+ variant?: "default" | "secondary" | "outline";
13
+ /** Color of the cursor spotlight and click ripple. */
14
+ highlightColor?: string;
15
+ /** Radius in px of the cursor spotlight. */
16
+ highlightSize?: number;
17
+ /** Color the border lights up with near the cursor. */
18
+ borderColor?: string;
19
+ }
20
+
21
+ type Ripple = { id: number; x: number; y: number; size: number };
22
+
23
+ const VARIANTS = {
24
+ // Graded dark surface: dark outer hairline, faint inner ring, top highlight, soft drop.
25
+ default:
26
+ "border-transparent text-neutral-50 hover:brightness-110 active:brightness-95 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)] 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)]",
27
+ secondary:
28
+ "border-transparent bg-secondary text-secondary-foreground hover:bg-secondary/80 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)]",
29
+ outline: "border-border bg-background text-foreground hover:bg-accent/40 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)]",
30
+ } as const;
31
+
32
+ // Paints only the 1px border ring: the content box is cut out of the full box.
33
+ const BORDER_MASK = {
34
+ padding: 1,
35
+ mask: "linear-gradient(#000 0 0) content-box exclude, linear-gradient(#000 0 0)",
36
+ WebkitMask:
37
+ "linear-gradient(#000 0 0) content-box xor, linear-gradient(#000 0 0)",
38
+ } satisfies React.CSSProperties;
39
+
40
+ export const HighlightButton = React.forwardRef<
41
+ HTMLButtonElement,
42
+ HighlightButtonProps
43
+ >(
44
+ (
45
+ {
46
+ variant = "default",
47
+ highlightColor = "color-mix(in oklab, currentColor 28%, transparent)",
48
+ highlightSize = 90,
49
+ borderColor = "color-mix(in oklab, currentColor 75%, transparent)",
50
+ className,
51
+ style,
52
+ children,
53
+ onPointerMove,
54
+ onPointerDown,
55
+ onClick,
56
+ type = "button",
57
+ ...props
58
+ },
59
+ ref,
60
+ ) => {
61
+ const buttonRef = React.useRef<HTMLButtonElement | null>(null);
62
+ const rippleIdRef = React.useRef(0);
63
+ const [ripples, setRipples] = React.useState<Ripple[]>([]);
64
+
65
+ const setRefs = React.useCallback(
66
+ (node: HTMLButtonElement | null) => {
67
+ buttonRef.current = node;
68
+ if (typeof ref === "function") ref(node);
69
+ else if (ref) ref.current = node;
70
+ },
71
+ [ref],
72
+ );
73
+
74
+ /** Cursor position relative to the button, written to CSS vars without re-rendering. */
75
+ const track = (clientX: number, clientY: number) => {
76
+ const button = buttonRef.current;
77
+ if (!button) return null;
78
+ const rect = button.getBoundingClientRect();
79
+ const x = clientX - rect.left;
80
+ const y = clientY - rect.top;
81
+ button.style.setProperty("--hl-x", `${x}px`);
82
+ button.style.setProperty("--hl-y", `${y}px`);
83
+ return { x, y, rect };
84
+ };
85
+
86
+ const addRipple = (x: number, y: number, rect: DOMRect) => {
87
+ // Big enough to reach the farthest corner from where it starts.
88
+ const size =
89
+ 2 *
90
+ Math.hypot(Math.max(x, rect.width - x), Math.max(y, rect.height - y));
91
+ const id = ++rippleIdRef.current;
92
+ setRipples((current) => [...current, { id, x, y, size }]);
93
+ };
94
+
95
+ const handlePointerMove = (
96
+ event: React.PointerEvent<HTMLButtonElement>,
97
+ ) => {
98
+ onPointerMove?.(event);
99
+ track(event.clientX, event.clientY);
100
+ };
101
+
102
+ const handlePointerDown = (
103
+ event: React.PointerEvent<HTMLButtonElement>,
104
+ ) => {
105
+ onPointerDown?.(event);
106
+ const hit = track(event.clientX, event.clientY);
107
+ if (hit) addRipple(hit.x, hit.y, hit.rect);
108
+ };
109
+
110
+ const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
111
+ onClick?.(event);
112
+ // Keyboard activation has no pointer, so ripple from the center.
113
+ if (event.detail === 0 && buttonRef.current) {
114
+ const rect = buttonRef.current.getBoundingClientRect();
115
+ addRipple(rect.width / 2, rect.height / 2, rect);
116
+ }
117
+ };
118
+
119
+ return (
120
+ <motion.button
121
+ ref={setRefs}
122
+ type={type}
123
+ onPointerMove={handlePointerMove}
124
+ onPointerDown={handlePointerDown}
125
+ onClick={handleClick}
126
+ style={
127
+ {
128
+ "--hl-color": highlightColor,
129
+ "--hl-border": borderColor,
130
+ "--hl-size": `${highlightSize}px`,
131
+ ...style,
132
+ } as React.CSSProperties
133
+ }
134
+ className={cn(
135
+ "group/highlight relative inline-flex h-9 cursor-pointer items-center justify-center rounded-[10px] border px-4 text-sm font-medium whitespace-nowrap outline-none select-none",
136
+ // Press eases in fast and settles; release springs back on the slower base curve.
137
+ "transition-[scale,filter,box-shadow,background-color,color] duration-300 ease-[cubic-bezier(0.34,1.35,0.64,1)] active:scale-[0.97] active:duration-100 active:ease-out motion-reduce:active:scale-100",
138
+ "focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-50",
139
+ VARIANTS[variant],
140
+ className,
141
+ )}
142
+ {...props}
143
+ >
144
+ <span
145
+ aria-hidden
146
+ className="pointer-events-none absolute inset-0 overflow-hidden rounded-[inherit]"
147
+ >
148
+ {/* Soft spotlight under the cursor. */}
149
+ <span
150
+ className="absolute inset-0 opacity-0 transition-opacity duration-300 group-hover/highlight:opacity-100"
151
+ style={{
152
+ background:
153
+ "radial-gradient(var(--hl-size) circle at var(--hl-x, 50%) var(--hl-y, 50%), var(--hl-color), transparent 70%)",
154
+ }}
155
+ />
156
+ {ripples.map((ripple) => (
157
+ <motion.span
158
+ key={ripple.id}
159
+ className="absolute rounded-full"
160
+ style={{
161
+ left: ripple.x - ripple.size / 2,
162
+ top: ripple.y - ripple.size / 2,
163
+ width: ripple.size,
164
+ height: ripple.size,
165
+ background: "var(--hl-color)",
166
+ }}
167
+ initial={{ scale: 0, opacity: 1 }}
168
+ animate={{ scale: 1, opacity: 0 }}
169
+ transition={{ duration: 0.6, ease: [0.22, 1, 0.36, 1] }}
170
+ onAnimationComplete={() =>
171
+ setRipples((current) =>
172
+ current.filter(({ id }) => id !== ripple.id),
173
+ )
174
+ }
175
+ />
176
+ ))}
177
+ </span>
178
+ {/* Border that lights up near the cursor. */}
179
+ <span
180
+ aria-hidden
181
+ className="pointer-events-none absolute -inset-px rounded-[inherit] opacity-0 transition-opacity duration-300 group-hover/highlight:opacity-100"
182
+ style={{
183
+ ...BORDER_MASK,
184
+ background:
185
+ "radial-gradient(calc(var(--hl-size) * 0.9) circle at var(--hl-x, 50%) var(--hl-y, 50%), var(--hl-border), transparent 75%)",
186
+ }}
187
+ />
188
+ <span className="relative inline-flex items-center gap-1.5">
189
+ {children}
190
+ </span>
191
+ </motion.button>
192
+ );
193
+ },
194
+ );
195
+
196
+ HighlightButton.displayName = "HighlightButton";