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,298 @@
1
+ "use client"
2
+
3
+ import { useEffect, useState, type CSSProperties } from "react"
4
+ import {
5
+ motion,
6
+ useReducedMotion,
7
+ useSpring,
8
+ useTransform,
9
+ } from "motion/react"
10
+
11
+ import { cn } from "@/lib/utils"
12
+
13
+ type RealisticSwitchSize = "sm" | "default" | "lg"
14
+ type RealisticSwitchTone = "auto" | "light" | "dark"
15
+
16
+ type RealisticSwitchProps = {
17
+ checked?: boolean
18
+ defaultChecked?: boolean
19
+ onCheckedChange?: (checked: boolean) => void
20
+ /** Cap color. Any CSS color; its walls, shading, and glow are mixed from it. */
21
+ color?: string
22
+ /** Color of the power mark on the cap. */
23
+ markColor?: string
24
+ /** Socket finish: follow the theme, or force ceramic white or graphite. */
25
+ tone?: RealisticSwitchTone
26
+ /** Light the cap from inside while it is latched on. */
27
+ illuminated?: boolean
28
+ /** Play a short mechanical click when it latches or releases. */
29
+ sound?: boolean
30
+ size?: RealisticSwitchSize
31
+ disabled?: boolean
32
+ className?: string
33
+ "aria-label"?: string
34
+ }
35
+
36
+ // Everything is sized in em, so one font size scales the whole switch.
37
+ const FONT_SIZE: Record<RealisticSwitchSize, number> = {
38
+ sm: 11,
39
+ default: 15,
40
+ lg: 19,
41
+ }
42
+
43
+ // Geometry, in em. The cap is a box standing on its own walls inside a
44
+ // recessed socket; its height above the socket floor is the one thing that
45
+ // moves. Cap and walls slide together on the same transform, and the walls are
46
+ // clipped at the floor, so nothing is resized and nothing snaps to a pixel.
47
+ const SOCKET = 4.4
48
+ const CAP = 3.3
49
+ const GAP = (SOCKET - CAP) / 2
50
+
51
+ // Cap height in each state: up, dipped under hover, fully pressed, and
52
+ // latched down while on.
53
+ const HEIGHT = {
54
+ up: 0.95,
55
+ hover: 0.82,
56
+ pressed: 0.1,
57
+ latched: 0.34,
58
+ latchedHover: 0.3,
59
+ }
60
+
61
+ // A touch of bounce, so a released cap settles like a spring without wobbling
62
+ // through the small hover dip.
63
+ const SPRING = { stiffness: 520, damping: 30, mass: 0.6 }
64
+
65
+ const TONES: Record<RealisticSwitchTone, string> = {
66
+ light:
67
+ "[--hi:#ffffff] [--mid:#efeff2] [--lo:#d9d9df] [--well:#c9c9d1] [--well-lo:#aeaeb8] [--floor:rgb(20_20_40/0.35)] [--spill:0.35]",
68
+ dark: "[--hi:#3a3a40] [--mid:#26262b] [--lo:#18181b] [--well:#0d0d10] [--well-lo:#050506] [--floor:rgb(0_0_0/0.8)] [--spill:0.6]",
69
+ auto: "[--hi:#ffffff] [--mid:#efeff2] [--lo:#d9d9df] [--well:#c9c9d1] [--well-lo:#aeaeb8] [--floor:rgb(20_20_40/0.35)] [--spill:0.35] dark:[--hi:#3a3a40] dark:[--mid:#26262b] dark:[--lo:#18181b] dark:[--well:#0d0d10] dark:[--well-lo:#050506] dark:[--floor:rgb(0_0_0/0.8)] dark:[--spill:0.6]",
70
+ }
71
+
72
+ const mix = (amount: number, toward: "white" | "black") =>
73
+ `color-mix(in oklab, var(--cap) ${amount}%, ${toward})`
74
+
75
+ const em = (value: number) => `${value}em`
76
+
77
+ let audio: AudioContext | null = null
78
+
79
+ // A switch click is a very short, bright burst of noise. Latching is pitched a
80
+ // little higher than releasing, like a real push switch's two stops.
81
+ function playClick(on: boolean) {
82
+ try {
83
+ audio ??= new AudioContext()
84
+ const length = Math.floor(audio.sampleRate * 0.03)
85
+ const buffer = audio.createBuffer(1, length, audio.sampleRate)
86
+ const data = buffer.getChannelData(0)
87
+ for (let i = 0; i < length; i++) {
88
+ data[i] = (Math.random() * 2 - 1) * (1 - i / length) ** 6
89
+ }
90
+ const source = audio.createBufferSource()
91
+ source.buffer = buffer
92
+ const filter = audio.createBiquadFilter()
93
+ filter.type = "bandpass"
94
+ filter.frequency.value = on ? 3400 : 2500
95
+ filter.Q.value = 1.1
96
+ const gain = audio.createGain()
97
+ gain.gain.value = 0.7
98
+ source.connect(filter).connect(gain).connect(audio.destination)
99
+ source.start()
100
+ } catch {
101
+ // No audio available: the switch still works silently.
102
+ }
103
+ }
104
+
105
+ function RealisticSwitch({
106
+ checked: checkedProp,
107
+ defaultChecked = false,
108
+ onCheckedChange,
109
+ color = "#e1261c",
110
+ markColor = "rgb(255 255 255 / 0.92)",
111
+ tone = "auto",
112
+ illuminated = true,
113
+ sound = false,
114
+ size = "default",
115
+ disabled = false,
116
+ className,
117
+ "aria-label": ariaLabel = "Power",
118
+ }: RealisticSwitchProps) {
119
+ const [internalChecked, setInternalChecked] = useState(defaultChecked)
120
+ const isControlled = checkedProp !== undefined
121
+ const checked = isControlled ? checkedProp : internalChecked
122
+ const [pressing, setPressing] = useState(false)
123
+ const [hovering, setHovering] = useState(false)
124
+ const reduceMotion = useReducedMotion()
125
+
126
+ const target = pressing
127
+ ? HEIGHT.pressed
128
+ : checked
129
+ ? hovering
130
+ ? HEIGHT.latchedHover
131
+ : HEIGHT.latched
132
+ : hovering
133
+ ? HEIGHT.hover
134
+ : HEIGHT.up
135
+ const height = useSpring(target, SPRING)
136
+
137
+ useEffect(() => {
138
+ if (reduceMotion) height.jump(target)
139
+ else height.set(target)
140
+ }, [height, target, reduceMotion])
141
+
142
+ // The walls fill the space under the cap, and the cast shadow spreads and
143
+ // fades as the cap rises away from the socket floor.
144
+ const capLift = useTransform(height, (h) => em(-h))
145
+ const shadowOpacity = useTransform(height, [0, HEIGHT.up], [0.35, 1])
146
+ const shadowScale = useTransform(height, [0, HEIGHT.up], [0.92, 1.06])
147
+ const shadowDrop = useTransform(height, (h) => em(0.05 + h * 0.35))
148
+
149
+ const toggle = () => {
150
+ const next = !checked
151
+ if (!isControlled) {
152
+ setInternalChecked(next)
153
+ }
154
+ onCheckedChange?.(next)
155
+ if (sound) {
156
+ playClick(next)
157
+ }
158
+ }
159
+
160
+ const lit = illuminated && checked
161
+
162
+ return (
163
+ <button
164
+ type="button"
165
+ role="switch"
166
+ aria-checked={checked}
167
+ aria-label={ariaLabel}
168
+ disabled={disabled}
169
+ onClick={toggle}
170
+ onPointerDown={(e) => {
171
+ if (e.button === 0) setPressing(true)
172
+ }}
173
+ onPointerUp={() => setPressing(false)}
174
+ onPointerEnter={(e) => {
175
+ if (e.pointerType === "mouse") setHovering(true)
176
+ }}
177
+ onPointerLeave={() => {
178
+ setPressing(false)
179
+ setHovering(false)
180
+ }}
181
+ onPointerCancel={() => setPressing(false)}
182
+ onKeyDown={(e) => {
183
+ if (e.key === " " || e.key === "Enter") setPressing(true)
184
+ }}
185
+ onKeyUp={() => setPressing(false)}
186
+ onBlur={() => setPressing(false)}
187
+ style={{ fontSize: FONT_SIZE[size], "--cap": color } as CSSProperties}
188
+ className={cn(
189
+ "group relative inline-flex cursor-pointer rounded-[1.1em] p-[0.5em] pt-[1.4em] outline-none select-none [-webkit-tap-highlight-color:transparent]",
190
+ "focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",
191
+ "disabled:cursor-not-allowed disabled:opacity-50",
192
+ TONES[tone],
193
+ className
194
+ )}
195
+ >
196
+ <span
197
+ aria-hidden
198
+ className="relative block"
199
+ style={{ width: em(SOCKET), height: em(SOCKET) }}
200
+ >
201
+ {/* Socket: a moulded plate with a lit top edge and a soft drop shadow. */}
202
+ <span
203
+ className="absolute -inset-[0.3em] rounded-[1.05em] shadow-[0_0.08em_0.1em_rgb(0_0_0/0.18),0_0.5em_1em_-0.3em_var(--floor),inset_0_0.05em_0_rgb(255_255_255/0.6),inset_0_-0.06em_0_rgb(0_0_0/0.18)]"
204
+ style={{ background: "linear-gradient(to bottom, var(--hi), var(--mid) 50%, var(--lo))" }}
205
+ />
206
+ {/* The well the cap travels in: darker the deeper it goes. */}
207
+ <span
208
+ className="absolute inset-0 rounded-[0.85em] shadow-[inset_0_0.14em_0.3em_rgb(0_0_0/0.5),inset_0_-0.04em_0_rgb(255_255_255/0.25),0_0.04em_0_rgb(255_255_255/0.5)]"
209
+ style={{ background: "linear-gradient(to bottom, var(--well-lo), var(--well))" }}
210
+ />
211
+ {/* Light from a latched cap pooling in the well. */}
212
+ <span
213
+ className="absolute inset-[0.15em] rounded-[0.75em] blur-[0.35em] transition-opacity duration-500"
214
+ style={{ background: "var(--cap)", opacity: lit ? "var(--spill)" : 0 }}
215
+ />
216
+ {/* Shadow the cap casts on the well floor. */}
217
+ <motion.span
218
+ className="absolute rounded-[0.7em] bg-black/70 blur-[0.3em]"
219
+ style={{
220
+ inset: em(GAP),
221
+ opacity: shadowOpacity,
222
+ scale: shadowScale,
223
+ y: shadowDrop,
224
+ }}
225
+ />
226
+ {/* Walls: a block that rides up with the cap, cut off at the floor. */}
227
+ <span
228
+ className="absolute overflow-hidden rounded-b-[0.7em]"
229
+ style={{ left: em(GAP), right: em(GAP), bottom: em(GAP), top: em(-HEIGHT.up) }}
230
+ >
231
+ <motion.span
232
+ className="absolute inset-x-0 overflow-hidden rounded-[0.7em] will-change-transform"
233
+ style={{
234
+ // Starts level with the cap's top and reaches the floor even at full lift.
235
+ top: em(GAP + HEIGHT.up),
236
+ height: em(CAP + HEIGHT.up),
237
+ y: capLift,
238
+ background: `linear-gradient(to bottom, ${mix(62, "black")}, ${mix(40, "black")})`,
239
+ }}
240
+ >
241
+ {/* Rounded corners turn away from the light at both sides. */}
242
+ <span className="absolute inset-0 bg-[linear-gradient(to_right,rgb(0_0_0/0.35),transparent_18%,rgb(255_255_255/0.08)_50%,transparent_82%,rgb(0_0_0/0.35))]" />
243
+ </motion.span>
244
+ </span>
245
+ {/* Cap: the top face, carried up by the walls. */}
246
+ <motion.span
247
+ className="absolute overflow-hidden rounded-[0.7em] will-change-transform"
248
+ style={{
249
+ left: em(GAP),
250
+ top: em(GAP),
251
+ width: em(CAP),
252
+ height: em(CAP),
253
+ y: capLift,
254
+ background: `linear-gradient(to bottom, ${mix(80, "white")}, var(--cap) 45%, ${mix(86, "black")})`,
255
+ boxShadow: `inset 0 0.06em 0 ${mix(45, "white")}, inset 0 -0.08em 0.05em ${mix(60, "black")}`,
256
+ }}
257
+ >
258
+ {/* A shallow dish in the middle of the cap, lit from above. */}
259
+ <span
260
+ className="absolute inset-[0.34em] rounded-[0.5em]"
261
+ style={{
262
+ background: `linear-gradient(to bottom, ${mix(82, "black")}, ${mix(92, "white")})`,
263
+ boxShadow: `inset 0 0.07em 0.12em ${mix(45, "black")}, 0 0.04em 0 ${mix(55, "white")}`,
264
+ }}
265
+ />
266
+ {/* Inner lamp: the cap glows through when latched on. */}
267
+ <span
268
+ className="absolute inset-0 transition-opacity duration-500"
269
+ style={{
270
+ opacity: lit ? 1 : 0,
271
+ background:
272
+ "radial-gradient(circle at 50% 50%, rgb(255 240 225 / 0.55), rgb(255 200 170 / 0.18) 50%, transparent 80%)",
273
+ }}
274
+ />
275
+ <svg
276
+ viewBox="0 0 24 24"
277
+ fill="none"
278
+ strokeWidth={2.4}
279
+ strokeLinecap="round"
280
+ className="absolute top-1/2 left-1/2 size-[1.25em] -translate-x-1/2 -translate-y-1/2 transition-[filter] duration-500"
281
+ style={{
282
+ stroke: markColor,
283
+ filter: lit
284
+ ? "drop-shadow(0 0 0.12em rgb(255 255 255 / 0.9))"
285
+ : "drop-shadow(0 0.04em 0 rgb(0 0 0 / 0.35))",
286
+ }}
287
+ >
288
+ <path d="M12 3v8" />
289
+ <path d="M7.05 6.4a7 7 0 1 0 9.9 0" />
290
+ </svg>
291
+ </motion.span>
292
+ </span>
293
+ </button>
294
+ )
295
+ }
296
+
297
+ export { RealisticSwitch }
298
+ export type { RealisticSwitchProps, RealisticSwitchSize, RealisticSwitchTone }
@@ -0,0 +1,197 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { AnimatePresence, motion } from "motion/react";
5
+ import { cn } from "@/lib/utils";
6
+
7
+ export type RevealButtonVariant = "dark" | "light";
8
+
9
+ // Graded surfaces matching MinimalButton: outer hairline, faint inner ring, top highlight, soft drop.
10
+ // Revealed swaps the neutral inner ring for an emerald one.
11
+ const surfaces: Record<
12
+ RevealButtonVariant,
13
+ {
14
+ base: string;
15
+ revealed: string;
16
+ label: string;
17
+ value: string;
18
+ chip: string;
19
+ chipRevealed: string;
20
+ }
21
+ > = {
22
+ dark: {
23
+ base: "text-neutral-50 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)]",
24
+ revealed:
25
+ "shadow-[0_0_0_1px_rgb(0_0_0/0.9),inset_0_0_0_1px_rgb(52_211_153/0.35),inset_0_1px_0_rgb(255_255_255/0.14),0_1px_2px_rgb(0_0_0/0.25),0_4px_12px_-4px_rgb(16_185_129/0.35)]",
26
+ label: "text-neutral-400",
27
+ value: "text-neutral-50",
28
+ chip: "bg-black/25 text-neutral-400 shadow-[inset_0_1px_2px_rgb(0_0_0/0.45),0_0_0_1px_rgb(255_255_255/0.07)]",
29
+ chipRevealed:
30
+ "text-emerald-400 shadow-[inset_0_1px_2px_rgb(0_0_0/0.45),0_0_0_1px_rgb(52_211_153/0.3)]",
31
+ },
32
+ light: {
33
+ base: "text-neutral-900 bg-linear-to-b from-white to-neutral-100 shadow-[0_0_0_1px_rgb(0_0_0/0.1),inset_0_1px_0_rgb(255_255_255/0.9),0_1px_2px_rgb(0_0_0/0.06),0_4px_12px_-4px_rgb(0_0_0/0.14)]",
34
+ revealed:
35
+ "shadow-[0_0_0_1px_rgb(16_185_129/0.45),inset_0_1px_0_rgb(255_255_255/0.9),0_1px_2px_rgb(0_0_0/0.06),0_4px_12px_-4px_rgb(16_185_129/0.3)]",
36
+ label: "text-neutral-500",
37
+ value: "text-neutral-900",
38
+ chip: "bg-neutral-200/60 text-neutral-500 shadow-[inset_0_1px_2px_rgb(0_0_0/0.12),0_0_0_1px_rgb(0_0_0/0.06)]",
39
+ chipRevealed:
40
+ "text-emerald-600 shadow-[inset_0_1px_2px_rgb(0_0_0/0.12),0_0_0_1px_rgb(16_185_129/0.35)]",
41
+ },
42
+ };
43
+
44
+ export interface RevealButtonProps
45
+ extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "children"> {
46
+ secret?: React.ReactNode;
47
+ label?: React.ReactNode;
48
+ hiddenLabel?: React.ReactNode;
49
+ revealMode?: "hold" | "toggle";
50
+ /** Dark (default) or light graded surface. */
51
+ variant?: RevealButtonVariant;
52
+ maskedValue?: string;
53
+ onRevealChange?: (revealed: boolean) => void;
54
+ }
55
+
56
+ export const RevealButton = React.forwardRef<
57
+ HTMLButtonElement,
58
+ RevealButtonProps
59
+ >(
60
+ (
61
+ {
62
+ secret = "sk_live_••••_9xQ4",
63
+ label = "Reveal",
64
+ hiddenLabel = "Hidden",
65
+ revealMode = "hold",
66
+ variant = "dark",
67
+ maskedValue = "•••• •••• ••••",
68
+ onRevealChange,
69
+ className,
70
+ type = "button",
71
+ ...props
72
+ },
73
+ ref,
74
+ ) => {
75
+ const [revealed, setRevealed] = React.useState(false);
76
+ const surface = surfaces[variant];
77
+
78
+ const updateRevealed = (next: boolean) => {
79
+ setRevealed(next);
80
+ onRevealChange?.(next);
81
+ };
82
+
83
+ const pressHandlers =
84
+ revealMode === "hold"
85
+ ? {
86
+ onPointerDown: () => updateRevealed(true),
87
+ onPointerUp: () => updateRevealed(false),
88
+ onPointerLeave: () => updateRevealed(false),
89
+ onBlur: () => updateRevealed(false),
90
+ onKeyDown: (e: React.KeyboardEvent<HTMLButtonElement>) => {
91
+ if ((e.key === " " || e.key === "Enter") && !e.repeat) {
92
+ e.preventDefault();
93
+ updateRevealed(true);
94
+ }
95
+ },
96
+ onKeyUp: (e: React.KeyboardEvent<HTMLButtonElement>) => {
97
+ if (e.key === " " || e.key === "Enter") {
98
+ e.preventDefault();
99
+ updateRevealed(false);
100
+ }
101
+ },
102
+ }
103
+ : {
104
+ onClick: () => updateRevealed(!revealed),
105
+ };
106
+
107
+ return (
108
+ <button
109
+ ref={ref}
110
+ type={type}
111
+ aria-pressed={revealed}
112
+ aria-live="polite"
113
+ data-state={revealed ? "revealed" : "hidden"}
114
+ className={cn(
115
+ "group relative inline-flex min-w-40 cursor-pointer items-center justify-between gap-3 overflow-hidden rounded-xl px-3 py-2 text-xs outline-none select-none sm:min-w-64 sm:gap-4 sm:px-4 sm:py-2.5 sm:text-sm",
116
+ surface.base,
117
+ "transition-[scale,filter,box-shadow] duration-300 ease-[cubic-bezier(0.34,1.35,0.64,1)] hover:brightness-110",
118
+ "active:scale-[0.98] active:brightness-95 active:duration-100 active:ease-out motion-reduce:active:scale-100",
119
+ "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",
120
+ revealed && surface.revealed,
121
+ className,
122
+ )}
123
+ {...pressHandlers}
124
+ {...props}
125
+ >
126
+ <span className="flex min-w-0 flex-col items-start">
127
+ <span
128
+ className={cn(
129
+ "text-xs font-medium uppercase tracking-wider",
130
+ surface.label,
131
+ )}
132
+ >
133
+ {revealed ? label : hiddenLabel}
134
+ </span>
135
+ <AnimatePresence initial={false} mode="wait">
136
+ <motion.span
137
+ key={revealed ? "secret" : "masked"}
138
+ initial={{ y: 6, opacity: 0, filter: "blur(4px)" }}
139
+ animate={{ y: 0, opacity: 1, filter: "blur(0px)" }}
140
+ exit={{ y: -6, opacity: 0, filter: "blur(4px)" }}
141
+ transition={{ duration: 0.16 }}
142
+ className={cn(
143
+ "block max-w-28 truncate font-mono text-xs font-semibold sm:max-w-44 sm:text-sm",
144
+ surface.value,
145
+ )}
146
+ >
147
+ {revealed ? secret : maskedValue}
148
+ </motion.span>
149
+ </AnimatePresence>
150
+ </span>
151
+ <span
152
+ aria-hidden
153
+ className={cn(
154
+ // Recessed chip: a sunken well with an inner shadow and a faint rim.
155
+ "inline-flex size-7 shrink-0 items-center justify-center rounded-full transition-colors sm:size-9",
156
+ surface.chip,
157
+ revealed && surface.chipRevealed,
158
+ )}
159
+ >
160
+ {revealed ? (
161
+ <svg
162
+ xmlns="http://www.w3.org/2000/svg"
163
+ viewBox="0 0 24 24"
164
+ fill="none"
165
+ stroke="currentColor"
166
+ strokeWidth="2.25"
167
+ strokeLinecap="round"
168
+ strokeLinejoin="round"
169
+ className="size-4"
170
+ >
171
+ <path d="m3 3 18 18" />
172
+ <path d="M10.58 10.58a2 2 0 0 0 2.83 2.83" />
173
+ <path d="M9.88 4.24A10.94 10.94 0 0 1 12 4c7 0 10 8 10 8a18.5 18.5 0 0 1-2.16 3.19" />
174
+ <path d="M6.61 6.61A18.7 18.7 0 0 0 2 12s3 8 10 8a10.8 10.8 0 0 0 5.39-1.61" />
175
+ </svg>
176
+ ) : (
177
+ <svg
178
+ xmlns="http://www.w3.org/2000/svg"
179
+ viewBox="0 0 24 24"
180
+ fill="none"
181
+ stroke="currentColor"
182
+ strokeWidth="2.25"
183
+ strokeLinecap="round"
184
+ strokeLinejoin="round"
185
+ className="size-4"
186
+ >
187
+ <path d="M2 12s3-8 10-8 10 8 10 8-3 8-10 8-10-8-10-8Z" />
188
+ <circle cx="12" cy="12" r="3" />
189
+ </svg>
190
+ )}
191
+ </span>
192
+ </button>
193
+ );
194
+ },
195
+ );
196
+
197
+ RevealButton.displayName = "RevealButton";
@@ -0,0 +1,87 @@
1
+ "use client";
2
+
3
+ import * as React from "react";
4
+ import { cn } from "@/lib/utils";
5
+
6
+ export interface ShinyButtonProps extends React.ButtonHTMLAttributes<HTMLButtonElement> {
7
+ /** Milliseconds the glint takes to sweep across on click. */
8
+ shineDuration?: number;
9
+ }
10
+
11
+ const ShinyButton = React.forwardRef<HTMLButtonElement, ShinyButtonProps>(
12
+ (
13
+ {
14
+ children,
15
+ className,
16
+ shineDuration = 650,
17
+ onClick,
18
+ type = "button",
19
+ ...props
20
+ },
21
+ ref,
22
+ ) => {
23
+ const shineRef = React.useRef<HTMLSpanElement>(null);
24
+ const faceRef = React.useRef<HTMLSpanElement>(null);
25
+
26
+ const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
27
+ onClick?.(event);
28
+ if (window.matchMedia("(prefers-reduced-motion: reduce)").matches) return;
29
+
30
+ // Web Animations restart cleanly on every click, even mid-sweep.
31
+ shineRef.current?.animate(
32
+ [
33
+ { transform: "translateX(-160%) skewX(-20deg)", opacity: 0 },
34
+ { opacity: 1, offset: 0.15 },
35
+ { opacity: 1, offset: 0.7 },
36
+ { transform: "translateX(420%) skewX(-20deg)", opacity: 0 },
37
+ ],
38
+ { duration: shineDuration, easing: "cubic-bezier(0.4, 0, 0.2, 1)" },
39
+ );
40
+ faceRef.current?.animate(
41
+ [
42
+ { filter: "brightness(1)" },
43
+ { filter: "brightness(1.25)", offset: 0.25 },
44
+ { filter: "brightness(1)" },
45
+ ],
46
+ { duration: shineDuration * 0.8, easing: "ease-out" },
47
+ );
48
+ };
49
+
50
+ return (
51
+ <button
52
+ ref={ref}
53
+ type={type}
54
+ onClick={handleClick}
55
+ className={cn(
56
+ "group/shiny relative inline-flex cursor-pointer rounded-2xl bg-linear-0 from-indigo-500 to-indigo-800 p-1 text-sm font-medium text-white shadow-[0_1px_2px_rgb(0_0_0/0.2),0_4px_12px_-2px_rgb(67_56_202/0.45)] outline-none select-none transition-[transform,box-shadow] duration-100",
57
+ "active:translate-y-0.5 active:scale-[0.99] active:shadow-[0_1px_1px_rgb(0_0_0/0.2),0_2px_6px_-2px_rgb(67_56_202/0.4)]",
58
+ "focus-visible:ring-2 focus-visible:ring-indigo-400 focus-visible:ring-offset-2 focus-visible:ring-offset-background disabled:pointer-events-none disabled:opacity-50",
59
+ className,
60
+ )}
61
+ {...props}
62
+ >
63
+ <span
64
+ ref={faceRef}
65
+ className="relative inline-flex items-center gap-1.5 overflow-hidden rounded-xl bg-linear-0 from-indigo-600 to-indigo-700 px-3 py-1 group-active/shiny:shadow-[inset_0_0_3px_0_#4338ca]"
66
+ >
67
+ <span className="relative">{children}</span>
68
+ </span>
69
+ {/* Glint that sweeps across the rim and face on click. */}
70
+ <span
71
+ aria-hidden
72
+ className="pointer-events-none absolute inset-0 overflow-hidden rounded-[inherit]"
73
+ >
74
+ <span
75
+ ref={shineRef}
76
+ className="absolute inset-y-0 left-0 w-1/3 bg-linear-to-r from-transparent via-white/55 to-transparent opacity-0"
77
+ />
78
+ </span>
79
+ </button>
80
+ );
81
+ },
82
+ );
83
+
84
+ ShinyButton.displayName = "ShinyButton";
85
+
86
+ export { ShinyButton };
87
+ export default ShinyButton;