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.
- package/README.md +71 -21
- package/SKILL.md +83 -9
- package/bin/index.mjs +2 -2
- package/bin/installer.mjs +6 -0
- package/catalog.json +1044 -139
- package/components/agents/thinking-states.tsx +156 -0
- package/components/buttons/aqua-button.tsx +145 -0
- package/components/buttons/ash-burst-button.tsx +528 -0
- package/components/buttons/brutal-button.tsx +68 -0
- package/components/buttons/chrome-button.tsx +444 -0
- package/components/buttons/click-powerup.tsx +203 -0
- package/components/buttons/command-button.tsx +226 -0
- package/components/buttons/confetti-button.tsx +132 -0
- package/components/buttons/cooldown-button.tsx +169 -0
- package/components/buttons/demonic-button.tsx +470 -0
- package/components/buttons/dither-button.tsx +192 -0
- package/components/buttons/doubt-button.tsx +240 -0
- package/components/buttons/evil-eye-button.tsx +563 -0
- package/components/buttons/frame-button.tsx +211 -0
- package/components/buttons/glitch-button.tsx +243 -0
- package/components/buttons/highlight-button.tsx +196 -0
- package/components/buttons/hold-button.tsx +245 -0
- package/components/buttons/minecraft-button.tsx +651 -0
- package/components/buttons/minimal-button.tsx +50 -0
- package/components/buttons/morph-status-button.tsx +264 -0
- package/components/buttons/movie-pass-button.tsx +205 -0
- package/components/buttons/realistic-switch.tsx +298 -0
- package/components/buttons/reveal-button.tsx +197 -0
- package/components/buttons/shiny-button.tsx +87 -0
- package/components/buttons/slide-to-detonate.tsx +444 -0
- package/components/buttons/sticky-button.tsx +184 -0
- package/components/buttons/thruster-button.tsx +920 -0
- package/components/buttons/troll-button.tsx +264 -0
- package/components/motion/banner-stacking.tsx +124 -0
- package/components/motion/delete-with-smoky-dissolve.tsx +145 -0
- package/components/motion/donut-chart.tsx +112 -0
- package/components/motion/drag-drop-with-physics.tsx +116 -0
- package/components/motion/dropdown-menu-morph.tsx +157 -0
- package/components/motion/get-pro-button.tsx +54 -0
- package/components/motion/image-open-tilt.tsx +79 -0
- package/components/motion/input-clear-with-dissolve.tsx +111 -0
- package/components/motion/learn-more-hover.tsx +71 -0
- package/components/motion/matrix-dot-loader.tsx +68 -0
- package/components/motion/organic-shimmer.tsx +49 -0
- package/components/motion/pro-gradient-text.tsx +46 -0
- package/components/motion/skeleton-loader-and-reveal.tsx +81 -0
- package/components/motion/spinner-to-check-morph.tsx +99 -0
- package/components/motion/spinning-counter.tsx +64 -0
- package/components/motion/text-morph.tsx +80 -0
- package/components/motion/texts-reveal.tsx +49 -0
- package/data/app-interface.csv +33 -0
- package/data/charts.csv +26 -0
- package/data/colors.csv +193 -0
- package/data/google-fonts.csv +1935 -0
- package/data/icons.csv +106 -0
- package/data/landing.csv +35 -0
- package/data/motion.csv +18 -0
- package/data/products.csv +193 -0
- package/data/react-performance.csv +45 -0
- package/data/stacks/angular.csv +51 -0
- package/data/stacks/astro.csv +54 -0
- package/data/stacks/avalonia.csv +57 -0
- package/data/stacks/flutter.csv +53 -0
- package/data/stacks/html-tailwind.csv +60 -0
- package/data/stacks/javafx.csv +76 -0
- package/data/stacks/jetpack-compose.csv +53 -0
- package/data/stacks/laravel.csv +51 -0
- package/data/stacks/nextjs.csv +62 -0
- package/data/stacks/nuxt-ui.csv +77 -0
- package/data/stacks/nuxtjs.csv +68 -0
- package/data/stacks/react-native.csv +52 -0
- package/data/stacks/react.csv +67 -0
- package/data/stacks/shadcn.csv +69 -0
- package/data/stacks/svelte.csv +56 -0
- package/data/stacks/swiftui.csv +51 -0
- package/data/stacks/threejs.csv +54 -0
- package/data/stacks/uno.csv +60 -0
- package/data/stacks/uwp.csv +56 -0
- package/data/stacks/vue.csv +50 -0
- package/data/stacks/winui.csv +60 -0
- package/data/stacks/wpf.csv +57 -0
- package/data/styles.csv +89 -0
- package/data/typography.csv +75 -0
- package/data/ui-reasoning.csv +193 -0
- package/data/ux-guidelines.csv +120 -0
- package/evals/catalog_eval.py +56 -0
- package/icons/annotations/loop-arrow.tsx +61 -0
- package/icons/brands/anthropic.tsx +26 -0
- package/icons/brands/apple.tsx +26 -0
- package/icons/brands/canva.tsx +26 -0
- package/icons/brands/claude-ai.tsx +26 -0
- package/icons/brands/discord.tsx +26 -0
- package/icons/brands/github.tsx +26 -0
- package/icons/brands/gmail.tsx +26 -0
- package/icons/brands/google.tsx +26 -0
- package/icons/brands/linkedin.tsx +29 -0
- package/icons/brands/microsoft.tsx +26 -0
- package/icons/brands/next-js.tsx +26 -0
- package/icons/brands/producthunt.tsx +26 -0
- package/icons/brands/react-js.tsx +29 -0
- package/icons/brands/shadcn-ui.tsx +26 -0
- package/icons/brands/tailwind-css.tsx +26 -0
- package/icons/brands/twitter.tsx +30 -0
- package/icons/brands/typescript.tsx +26 -0
- package/icons/brands/unsplash.tsx +27 -0
- package/icons/brands/vercel.tsx +26 -0
- package/icons/brands/whatsapp.tsx +26 -0
- package/package.json +9 -3
- package/prompts/install-motion-ui.md +17 -0
- package/references/agents/thinking-states.md +56 -0
- package/references/craft/aqua-button.md +53 -0
- package/references/craft/ash-burst-button.md +55 -0
- package/references/craft/brutal-button.md +52 -0
- package/references/craft/chrome-button.md +53 -0
- package/references/craft/click-powerup.md +53 -0
- package/references/craft/command-button.md +53 -0
- package/references/craft/confetti-button.md +54 -0
- package/references/craft/cooldown-button.md +54 -0
- package/references/craft/demonic-button.md +53 -0
- package/references/craft/dither-button.md +52 -0
- package/references/craft/doubt-button.md +53 -0
- package/references/craft/evil-eye-button.md +52 -0
- package/references/craft/frame-button.md +54 -0
- package/references/craft/glitch-button.md +52 -0
- package/references/craft/highlight-button.md +53 -0
- package/references/craft/hold-button.md +53 -0
- package/references/craft/minecraft-button.md +53 -0
- package/references/craft/minimal-button.md +52 -0
- package/references/craft/morph-status-button.md +53 -0
- package/references/craft/movie-pass-button.md +53 -0
- package/references/craft/realistic-switch.md +54 -0
- package/references/craft/reveal-button.md +53 -0
- package/references/craft/shiny-button.md +52 -0
- package/references/craft/slide-to-detonate.md +53 -0
- package/references/craft/sticky-button.md +54 -0
- package/references/craft/thruster-button.md +53 -0
- package/references/craft/troll-button.md +54 -0
- package/references/guides/design-intelligence.md +125 -0
- package/references/guides/interaction-transitions.md +56 -38
- package/references/guides/motion-polish-rules.md +75 -0
- package/references/guides/stack-best-practices.md +38 -0
- package/references/motion/banner-stacking.md +67 -0
- package/references/motion/delete-with-smoky-dissolve.md +60 -0
- package/references/motion/donut-chart.md +79 -0
- package/references/motion/drag-drop-with-physics.md +61 -0
- package/references/motion/dropdown-menu-morph.md +55 -0
- package/references/motion/get-pro-button.md +56 -0
- package/references/motion/image-open-tilt.md +60 -0
- package/references/motion/input-clear-with-dissolve.md +58 -0
- package/references/motion/learn-more-hover.md +56 -0
- package/references/motion/matrix-dot-loader.md +58 -0
- package/references/motion/organic-shimmer.md +63 -0
- package/references/motion/pro-gradient-text.md +57 -0
- package/references/motion/skeleton-loader-and-reveal.md +67 -0
- package/references/motion/spinner-to-check-morph.md +67 -0
- package/references/motion/spinning-counter.md +74 -0
- package/references/motion/text-morph.md +64 -0
- package/references/motion/texts-reveal.md +56 -0
- package/scripts/build_docs.py +39 -4
- package/scripts/core.py +993 -0
- package/scripts/design_system.py +1668 -0
- package/scripts/reasoning_contract.py +123 -0
- package/scripts/search.py +177 -0
- package/scripts/test_release.py +12 -0
- package/scripts/verify_skill.py +4 -4
- package/test/test_installer.mjs +133 -0
|
@@ -0,0 +1,264 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { AnimatePresence, motion, useReducedMotion } from "motion/react";
|
|
5
|
+
import { cn } from "@/lib/utils";
|
|
6
|
+
|
|
7
|
+
export type MorphStatus = "idle" | "loading" | "success" | "error";
|
|
8
|
+
|
|
9
|
+
export interface MorphStatusButtonProps
|
|
10
|
+
extends Omit<React.ButtonHTMLAttributes<HTMLButtonElement>, "onClick"> {
|
|
11
|
+
/** Idle label. Falls back to `label`. */
|
|
12
|
+
children?: React.ReactNode;
|
|
13
|
+
/** Idle label used when no children are provided. */
|
|
14
|
+
label?: React.ReactNode;
|
|
15
|
+
/** Label shown while the action is in flight. */
|
|
16
|
+
loadingLabel?: React.ReactNode;
|
|
17
|
+
/** Label shown after the action resolves. */
|
|
18
|
+
successLabel?: React.ReactNode;
|
|
19
|
+
/** Label shown after the action rejects. */
|
|
20
|
+
errorLabel?: React.ReactNode;
|
|
21
|
+
/**
|
|
22
|
+
* Click handler. If it returns a promise, the button auto-transitions
|
|
23
|
+
* through loading and into success or error based on the outcome.
|
|
24
|
+
*/
|
|
25
|
+
onClick?: (e: React.MouseEvent<HTMLButtonElement>) => void | Promise<unknown>;
|
|
26
|
+
/**
|
|
27
|
+
* Controlled status. When provided, the button reflects this value and the
|
|
28
|
+
* promise-based auto-transitions are ignored.
|
|
29
|
+
*/
|
|
30
|
+
status?: MorphStatus;
|
|
31
|
+
/** Milliseconds to stay in success/error before resetting. Set to 0 to stay. */
|
|
32
|
+
resetAfter?: number;
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
const Spinner = () => (
|
|
36
|
+
<svg
|
|
37
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
38
|
+
viewBox="0 0 24 24"
|
|
39
|
+
fill="none"
|
|
40
|
+
stroke="currentColor"
|
|
41
|
+
strokeWidth="2.5"
|
|
42
|
+
strokeLinecap="round"
|
|
43
|
+
className="size-4 shrink-0 animate-spin"
|
|
44
|
+
aria-hidden
|
|
45
|
+
>
|
|
46
|
+
<path d="M21 12a9 9 0 1 1-6.219-8.56" />
|
|
47
|
+
</svg>
|
|
48
|
+
);
|
|
49
|
+
|
|
50
|
+
const CheckIcon = () => (
|
|
51
|
+
<svg
|
|
52
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
53
|
+
viewBox="0 0 24 24"
|
|
54
|
+
fill="none"
|
|
55
|
+
stroke="currentColor"
|
|
56
|
+
strokeWidth="2.5"
|
|
57
|
+
strokeLinecap="round"
|
|
58
|
+
strokeLinejoin="round"
|
|
59
|
+
className="size-4 shrink-0"
|
|
60
|
+
aria-hidden
|
|
61
|
+
>
|
|
62
|
+
<path d="M20 6 9 17l-5-5" />
|
|
63
|
+
</svg>
|
|
64
|
+
);
|
|
65
|
+
|
|
66
|
+
const XIcon = () => (
|
|
67
|
+
<svg
|
|
68
|
+
xmlns="http://www.w3.org/2000/svg"
|
|
69
|
+
viewBox="0 0 24 24"
|
|
70
|
+
fill="none"
|
|
71
|
+
stroke="currentColor"
|
|
72
|
+
strokeWidth="2.5"
|
|
73
|
+
strokeLinecap="round"
|
|
74
|
+
strokeLinejoin="round"
|
|
75
|
+
className="size-4 shrink-0"
|
|
76
|
+
aria-hidden
|
|
77
|
+
>
|
|
78
|
+
<path d="M18 6 6 18" />
|
|
79
|
+
<path d="m6 6 12 12" />
|
|
80
|
+
</svg>
|
|
81
|
+
);
|
|
82
|
+
|
|
83
|
+
function textOf(node: React.ReactNode): string {
|
|
84
|
+
if (node === null || node === undefined || typeof node === "boolean") {
|
|
85
|
+
return "";
|
|
86
|
+
}
|
|
87
|
+
if (typeof node === "string" || typeof node === "number") {
|
|
88
|
+
return String(node);
|
|
89
|
+
}
|
|
90
|
+
if (Array.isArray(node)) return node.map(textOf).join("");
|
|
91
|
+
if (React.isValidElement<{ children?: React.ReactNode }>(node)) {
|
|
92
|
+
return textOf(node.props.children);
|
|
93
|
+
}
|
|
94
|
+
return "";
|
|
95
|
+
}
|
|
96
|
+
|
|
97
|
+
export const MorphStatusButton = React.forwardRef<
|
|
98
|
+
HTMLButtonElement,
|
|
99
|
+
MorphStatusButtonProps
|
|
100
|
+
>(
|
|
101
|
+
(
|
|
102
|
+
{
|
|
103
|
+
children,
|
|
104
|
+
label = "Save changes",
|
|
105
|
+
loadingLabel = "Working…",
|
|
106
|
+
successLabel = "Done",
|
|
107
|
+
errorLabel = "It broke. Your fault.",
|
|
108
|
+
onClick,
|
|
109
|
+
status: controlledStatus,
|
|
110
|
+
resetAfter = 1800,
|
|
111
|
+
className,
|
|
112
|
+
disabled,
|
|
113
|
+
...props
|
|
114
|
+
},
|
|
115
|
+
ref,
|
|
116
|
+
) => {
|
|
117
|
+
const reduceMotion = useReducedMotion();
|
|
118
|
+
const [internal, setInternal] = React.useState<MorphStatus>("idle");
|
|
119
|
+
const resetTimeoutRef = React.useRef<number | null>(null);
|
|
120
|
+
|
|
121
|
+
const isControlled = controlledStatus !== undefined;
|
|
122
|
+
const status = isControlled ? controlledStatus : internal;
|
|
123
|
+
|
|
124
|
+
const clearReset = () => {
|
|
125
|
+
if (resetTimeoutRef.current !== null) {
|
|
126
|
+
window.clearTimeout(resetTimeoutRef.current);
|
|
127
|
+
resetTimeoutRef.current = null;
|
|
128
|
+
}
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
React.useEffect(() => () => clearReset(), []);
|
|
132
|
+
|
|
133
|
+
const scheduleReset = () => {
|
|
134
|
+
if (isControlled || resetAfter <= 0) return;
|
|
135
|
+
clearReset();
|
|
136
|
+
resetTimeoutRef.current = window.setTimeout(() => {
|
|
137
|
+
setInternal("idle");
|
|
138
|
+
}, resetAfter);
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const handleClick = (e: React.MouseEvent<HTMLButtonElement>) => {
|
|
142
|
+
if (status === "loading") return;
|
|
143
|
+
const result = onClick?.(e);
|
|
144
|
+
|
|
145
|
+
if (isControlled || !(result instanceof Promise)) return;
|
|
146
|
+
|
|
147
|
+
clearReset();
|
|
148
|
+
setInternal("loading");
|
|
149
|
+
result
|
|
150
|
+
.then(() => {
|
|
151
|
+
setInternal("success");
|
|
152
|
+
scheduleReset();
|
|
153
|
+
})
|
|
154
|
+
.catch(() => {
|
|
155
|
+
setInternal("error");
|
|
156
|
+
scheduleReset();
|
|
157
|
+
});
|
|
158
|
+
};
|
|
159
|
+
|
|
160
|
+
const idleLabel = children ?? label;
|
|
161
|
+
const currentLabel: React.ReactNode =
|
|
162
|
+
status === "loading"
|
|
163
|
+
? loadingLabel
|
|
164
|
+
: status === "success"
|
|
165
|
+
? successLabel
|
|
166
|
+
: status === "error"
|
|
167
|
+
? errorLabel
|
|
168
|
+
: idleLabel;
|
|
169
|
+
|
|
170
|
+
const icon =
|
|
171
|
+
status === "loading" ? (
|
|
172
|
+
<Spinner />
|
|
173
|
+
) : status === "success" ? (
|
|
174
|
+
<CheckIcon />
|
|
175
|
+
) : status === "error" ? (
|
|
176
|
+
<XIcon />
|
|
177
|
+
) : null;
|
|
178
|
+
|
|
179
|
+
// Widest possible label reserves width so the button never reflows.
|
|
180
|
+
const widest = [
|
|
181
|
+
idleLabel,
|
|
182
|
+
loadingLabel,
|
|
183
|
+
successLabel,
|
|
184
|
+
errorLabel,
|
|
185
|
+
].reduce<React.ReactNode>(
|
|
186
|
+
(widestNode, candidate) =>
|
|
187
|
+
textOf(candidate).length > textOf(widestNode).length
|
|
188
|
+
? candidate
|
|
189
|
+
: widestNode,
|
|
190
|
+
"",
|
|
191
|
+
);
|
|
192
|
+
|
|
193
|
+
return (
|
|
194
|
+
<button
|
|
195
|
+
ref={ref}
|
|
196
|
+
type="button"
|
|
197
|
+
onClick={handleClick}
|
|
198
|
+
disabled={disabled || status === "loading"}
|
|
199
|
+
aria-live="polite"
|
|
200
|
+
aria-busy={status === "loading"}
|
|
201
|
+
data-state={status}
|
|
202
|
+
className={cn(
|
|
203
|
+
"relative inline-flex h-9 cursor-pointer items-center justify-center overflow-hidden rounded-[10px] px-4 text-sm font-medium text-neutral-50 outline-none select-none",
|
|
204
|
+
// Graded dark surface matching MinimalButton: dark outer hairline, faint inner ring, top highlight, soft drop.
|
|
205
|
+
"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)]",
|
|
206
|
+
"transition-[scale,filter,box-shadow,color] duration-300 ease-[cubic-bezier(0.34,1.35,0.64,1)] hover:brightness-110",
|
|
207
|
+
"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",
|
|
208
|
+
"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",
|
|
209
|
+
// In flight, not disabled: stay solid with a dimmed label.
|
|
210
|
+
status === "loading" &&
|
|
211
|
+
"text-neutral-50/70 hover:brightness-100 disabled:opacity-100",
|
|
212
|
+
// Error keeps the dark face; a red label and inner ring carry the blame.
|
|
213
|
+
status === "error" &&
|
|
214
|
+
"text-red-300 shadow-[0_0_0_1px_rgb(0_0_0/0.9),inset_0_0_0_1px_rgb(248_113_113/0.35),inset_0_1px_0_rgb(255_255_255/0.1),0_1px_2px_rgb(0_0_0/0.25),0_4px_12px_-4px_rgb(185_28_28/0.45)]",
|
|
215
|
+
className,
|
|
216
|
+
)}
|
|
217
|
+
{...props}
|
|
218
|
+
>
|
|
219
|
+
{/* Invisible widest label reserves a stable width. */}
|
|
220
|
+
<span aria-hidden className="invisible inline-flex items-center gap-2">
|
|
221
|
+
<span className="size-4" />
|
|
222
|
+
{widest}
|
|
223
|
+
</span>
|
|
224
|
+
|
|
225
|
+
<span className="absolute inset-0 flex items-center justify-center gap-2">
|
|
226
|
+
{icon ? (
|
|
227
|
+
<span className="relative inline-flex size-4 items-center justify-center">
|
|
228
|
+
<AnimatePresence initial={false} mode="wait">
|
|
229
|
+
<motion.span
|
|
230
|
+
key={status}
|
|
231
|
+
initial={reduceMotion ? false : { scale: 0.4, opacity: 0 }}
|
|
232
|
+
animate={{ scale: 1, opacity: 1 }}
|
|
233
|
+
exit={reduceMotion ? undefined : { scale: 0.4, opacity: 0 }}
|
|
234
|
+
transition={{ type: "spring", stiffness: 380, damping: 22 }}
|
|
235
|
+
className="inline-flex"
|
|
236
|
+
>
|
|
237
|
+
{icon}
|
|
238
|
+
</motion.span>
|
|
239
|
+
</AnimatePresence>
|
|
240
|
+
</span>
|
|
241
|
+
) : null}
|
|
242
|
+
<span className="relative inline-block">
|
|
243
|
+
<AnimatePresence initial={false} mode="wait">
|
|
244
|
+
<motion.span
|
|
245
|
+
key={status}
|
|
246
|
+
initial={reduceMotion ? false : { y: 8, opacity: 0 }}
|
|
247
|
+
animate={{ y: 0, opacity: 1 }}
|
|
248
|
+
exit={reduceMotion ? undefined : { y: -8, opacity: 0 }}
|
|
249
|
+
transition={{ duration: 0.16 }}
|
|
250
|
+
className="inline-block whitespace-nowrap"
|
|
251
|
+
>
|
|
252
|
+
{currentLabel}
|
|
253
|
+
</motion.span>
|
|
254
|
+
</AnimatePresence>
|
|
255
|
+
</span>
|
|
256
|
+
</span>
|
|
257
|
+
</button>
|
|
258
|
+
);
|
|
259
|
+
},
|
|
260
|
+
);
|
|
261
|
+
|
|
262
|
+
MorphStatusButton.displayName = "MorphStatusButton";
|
|
263
|
+
|
|
264
|
+
export default MorphStatusButton;
|
|
@@ -0,0 +1,205 @@
|
|
|
1
|
+
"use client";
|
|
2
|
+
|
|
3
|
+
import * as React from "react";
|
|
4
|
+
import { motion, useReducedMotion, type Transition } from "motion/react";
|
|
5
|
+
import { cn } from "@/lib/utils";
|
|
6
|
+
|
|
7
|
+
export type MoviePassVariant = "tilt" | "snap";
|
|
8
|
+
|
|
9
|
+
export interface MoviePassButtonProps
|
|
10
|
+
extends Omit<
|
|
11
|
+
React.ButtonHTMLAttributes<HTMLButtonElement>,
|
|
12
|
+
| "children"
|
|
13
|
+
| "onAnimationStart"
|
|
14
|
+
| "onDrag"
|
|
15
|
+
| "onDragEnd"
|
|
16
|
+
| "onDragStart"
|
|
17
|
+
> {
|
|
18
|
+
/** Label printed on the main part of the ticket. */
|
|
19
|
+
children?: React.ReactNode;
|
|
20
|
+
/** Content of the tear-off stub. */
|
|
21
|
+
stub?: React.ReactNode;
|
|
22
|
+
/**
|
|
23
|
+
* How the ticket tears on click.
|
|
24
|
+
* - `tilt`: both halves hinge outward from the bottom of the perforation.
|
|
25
|
+
* - `snap`: the stub splits off in a straight line, leaving a small gap.
|
|
26
|
+
* @default "tilt"
|
|
27
|
+
*/
|
|
28
|
+
variant?: MoviePassVariant;
|
|
29
|
+
/**
|
|
30
|
+
* Milliseconds before the ticket mends itself. Pass `null` to stay torn
|
|
31
|
+
* until the next click.
|
|
32
|
+
* @default 1800
|
|
33
|
+
*/
|
|
34
|
+
resetDelay?: number | null;
|
|
35
|
+
/** Fired each time the ticket tears. */
|
|
36
|
+
onTear?: () => void;
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Notch radius for the corner cutouts. Each half is notched on all four
|
|
41
|
+
* corners, so the two halves together form half-circle punches at the
|
|
42
|
+
* perforation. Masks keep the shape correct on any page background.
|
|
43
|
+
*/
|
|
44
|
+
const NOTCH = 6;
|
|
45
|
+
|
|
46
|
+
const cornerNotchMask = [
|
|
47
|
+
`radial-gradient(circle ${NOTCH}px at 0 0, transparent ${NOTCH}px, black ${NOTCH + 0.5}px)`,
|
|
48
|
+
`radial-gradient(circle ${NOTCH}px at 100% 0, transparent ${NOTCH}px, black ${NOTCH + 0.5}px)`,
|
|
49
|
+
`radial-gradient(circle ${NOTCH}px at 0 100%, transparent ${NOTCH}px, black ${NOTCH + 0.5}px)`,
|
|
50
|
+
`radial-gradient(circle ${NOTCH}px at 100% 100%, transparent ${NOTCH}px, black ${NOTCH + 0.5}px)`,
|
|
51
|
+
].join(", ");
|
|
52
|
+
|
|
53
|
+
const notchStyle: React.CSSProperties = {
|
|
54
|
+
WebkitMaskImage: cornerNotchMask,
|
|
55
|
+
maskImage: cornerNotchMask,
|
|
56
|
+
WebkitMaskRepeat: "no-repeat",
|
|
57
|
+
maskRepeat: "no-repeat",
|
|
58
|
+
// Intersect the four masks so only the corner circles are cut out.
|
|
59
|
+
WebkitMaskComposite: "source-in",
|
|
60
|
+
maskComposite: "intersect",
|
|
61
|
+
};
|
|
62
|
+
|
|
63
|
+
const TEAR = {
|
|
64
|
+
snap: {
|
|
65
|
+
main: { x: -3, rotate: 0 },
|
|
66
|
+
stub: { x: 3, rotate: 0 },
|
|
67
|
+
},
|
|
68
|
+
// Rotating around the shared bottom corners keeps the halves touching at
|
|
69
|
+
// the bottom while a V opens along the perforation.
|
|
70
|
+
tilt: {
|
|
71
|
+
main: { x: 0, rotate: -6 },
|
|
72
|
+
stub: { x: 0, rotate: 10 },
|
|
73
|
+
},
|
|
74
|
+
} as const;
|
|
75
|
+
|
|
76
|
+
const REST = { x: 0, rotate: 0 };
|
|
77
|
+
|
|
78
|
+
const TRANSITIONS: Record<MoviePassVariant, Transition> = {
|
|
79
|
+
snap: { type: "spring", stiffness: 700, damping: 22, mass: 0.6 },
|
|
80
|
+
tilt: { type: "spring", stiffness: 320, damping: 13, mass: 0.8 },
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
const MEND: Transition = { type: "spring", stiffness: 420, damping: 30 };
|
|
84
|
+
|
|
85
|
+
function DefaultStub() {
|
|
86
|
+
return (
|
|
87
|
+
<span className="flex flex-col items-center leading-none">
|
|
88
|
+
<span className="text-[8px] tracking-[0.2em] opacity-60">NO.</span>
|
|
89
|
+
<span className="mt-0.5 font-mono text-xs font-semibold">01</span>
|
|
90
|
+
</span>
|
|
91
|
+
);
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
export const MoviePassButton = React.forwardRef<
|
|
95
|
+
HTMLButtonElement,
|
|
96
|
+
MoviePassButtonProps
|
|
97
|
+
>(
|
|
98
|
+
(
|
|
99
|
+
{
|
|
100
|
+
children,
|
|
101
|
+
stub = <DefaultStub />,
|
|
102
|
+
variant = "tilt",
|
|
103
|
+
resetDelay = 1800,
|
|
104
|
+
onTear,
|
|
105
|
+
onClick,
|
|
106
|
+
className,
|
|
107
|
+
style,
|
|
108
|
+
type = "button",
|
|
109
|
+
...props
|
|
110
|
+
},
|
|
111
|
+
ref,
|
|
112
|
+
) => {
|
|
113
|
+
const reduceMotion = useReducedMotion();
|
|
114
|
+
const [torn, setTorn] = React.useState(false);
|
|
115
|
+
const timeoutRef = React.useRef<number | null>(null);
|
|
116
|
+
|
|
117
|
+
const clearTimer = React.useCallback(() => {
|
|
118
|
+
if (timeoutRef.current !== null) {
|
|
119
|
+
window.clearTimeout(timeoutRef.current);
|
|
120
|
+
timeoutRef.current = null;
|
|
121
|
+
}
|
|
122
|
+
}, []);
|
|
123
|
+
|
|
124
|
+
React.useEffect(() => clearTimer, [clearTimer]);
|
|
125
|
+
|
|
126
|
+
const handleClick = (event: React.MouseEvent<HTMLButtonElement>) => {
|
|
127
|
+
onClick?.(event);
|
|
128
|
+
if (event.defaultPrevented) return;
|
|
129
|
+
|
|
130
|
+
clearTimer();
|
|
131
|
+
|
|
132
|
+
if (torn) {
|
|
133
|
+
setTorn(false);
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
setTorn(true);
|
|
138
|
+
onTear?.();
|
|
139
|
+
|
|
140
|
+
if (resetDelay !== null) {
|
|
141
|
+
timeoutRef.current = window.setTimeout(() => {
|
|
142
|
+
timeoutRef.current = null;
|
|
143
|
+
setTorn(false);
|
|
144
|
+
}, resetDelay);
|
|
145
|
+
}
|
|
146
|
+
};
|
|
147
|
+
|
|
148
|
+
const pose = torn ? TEAR[variant] : { main: REST, stub: REST };
|
|
149
|
+
const transition: Transition = reduceMotion
|
|
150
|
+
? { duration: 0 }
|
|
151
|
+
: torn
|
|
152
|
+
? TRANSITIONS[variant]
|
|
153
|
+
: MEND;
|
|
154
|
+
|
|
155
|
+
return (
|
|
156
|
+
<button
|
|
157
|
+
ref={ref}
|
|
158
|
+
type={type}
|
|
159
|
+
onClick={handleClick}
|
|
160
|
+
data-state={torn ? "torn" : "intact"}
|
|
161
|
+
data-variant={variant}
|
|
162
|
+
aria-pressed={resetDelay === null ? torn : undefined}
|
|
163
|
+
style={style}
|
|
164
|
+
className={cn(
|
|
165
|
+
"group relative inline-flex h-11 cursor-pointer items-stretch bg-transparent p-0 text-sm font-medium text-neutral-50 outline-none select-none",
|
|
166
|
+
// The halves are masked for the notches, which clips box-shadow, so the hairline ring and soft drop are drop-shadows that follow the ticket's outline.
|
|
167
|
+
"[filter:drop-shadow(0_0_0.5px_rgb(0_0_0/0.9))_drop-shadow(0_0_0.5px_rgb(0_0_0/0.9))_drop-shadow(0_1px_1px_rgb(0_0_0/0.25))_drop-shadow(0_4px_5px_rgb(0_0_0/0.25))]",
|
|
168
|
+
"transition-[scale,filter] duration-300 ease-[cubic-bezier(0.34,1.35,0.64,1)]",
|
|
169
|
+
// Press eases in fast and settles the drop; release springs back on the slower base curve.
|
|
170
|
+
"active:scale-[0.97] active:duration-100 active:ease-out active:[filter:drop-shadow(0_0_0.5px_rgb(0_0_0/0.9))_drop-shadow(0_0_0.5px_rgb(0_0_0/0.9))_drop-shadow(0_0_1px_rgb(0_0_0/0.2))_drop-shadow(0_1px_1.5px_rgb(0_0_0/0.2))] motion-reduce:active:scale-100",
|
|
171
|
+
"focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background",
|
|
172
|
+
"disabled:pointer-events-none disabled:opacity-50",
|
|
173
|
+
className,
|
|
174
|
+
)}
|
|
175
|
+
{...props}
|
|
176
|
+
>
|
|
177
|
+
<motion.span
|
|
178
|
+
initial={false}
|
|
179
|
+
animate={pose.main}
|
|
180
|
+
transition={transition}
|
|
181
|
+
style={{ ...notchStyle, transformOrigin: "100% 100%" }}
|
|
182
|
+
className="flex items-center px-6 bg-linear-to-b from-[#353535] to-[#272727] shadow-[inset_0_1px_0_rgb(255_255_255/0.14)] transition-[filter] duration-300 group-hover:brightness-110 group-active:brightness-95"
|
|
183
|
+
>
|
|
184
|
+
{children}
|
|
185
|
+
</motion.span>
|
|
186
|
+
<motion.span
|
|
187
|
+
aria-hidden
|
|
188
|
+
initial={false}
|
|
189
|
+
animate={pose.stub}
|
|
190
|
+
transition={transition}
|
|
191
|
+
style={{ ...notchStyle, transformOrigin: "0% 100%" }}
|
|
192
|
+
className="relative flex min-w-12 items-center justify-center px-3 font-mono text-xs text-neutral-50/70 bg-linear-to-b from-[#353535] to-[#272727] shadow-[inset_0_1px_0_rgb(255_255_255/0.14)] transition-[filter] duration-300 group-hover:brightness-110 group-active:brightness-95"
|
|
193
|
+
>
|
|
194
|
+
{/* Perforation along the tear line. */}
|
|
195
|
+
<span className="absolute inset-y-2 left-0 w-px bg-[linear-gradient(to_bottom,currentColor_50%,transparent_50%)] bg-size-[1px_5px] opacity-40" />
|
|
196
|
+
{stub}
|
|
197
|
+
</motion.span>
|
|
198
|
+
</button>
|
|
199
|
+
);
|
|
200
|
+
},
|
|
201
|
+
);
|
|
202
|
+
|
|
203
|
+
MoviePassButton.displayName = "MoviePassButton";
|
|
204
|
+
|
|
205
|
+
export default MoviePassButton;
|