Files

165 lines
6.8 KiB
TypeScript

"use client";
/* ═══════════════════════════════════════════════════════════════════════
DemoButton — Gelber Wave-Button mit Dark Charcoal Wave, Shimmer, Scale
Basiert auf der freigegebenen Medium-Throw-Variante (0,8 s)
Rendert standardmäßig einen <Link> (Navigation). Mit `type` ("submit" |
"button") rendert er stattdessen einen <button> — für Formular-Buttons
(Lead-Formular, Newsletter) mit derselben Animation.
═══════════════════════════════════════════════════════════════════════ */
import Link from "next/link";
import { useRef, useCallback } from "react";
import { gsap } from "gsap/dist/gsap";
const WAVE_CSS = `
.demo-btn .demo-wl{transform:translateX(-50%) translateY(100%);border-radius:999px 999px 0 0;transition:none}
.demo-btn:hover .demo-wl{transform:translateX(-50%) translateY(10px);border-radius:60% 60% 0 0}
.demo-btn:hover .demo-wl-1{transition:transform .55s cubic-bezier(.19,1,.22,1) 80ms,border-radius .15s cubic-bezier(.19,1,.22,1) 100ms}
.demo-btn:hover .demo-wl-2{transition:transform .55s cubic-bezier(.19,1,.22,1) 150ms,border-radius .15s cubic-bezier(.19,1,.22,1) 200ms}
.demo-btn:hover .demo-wl-3{transition:transform .55s cubic-bezier(.19,1,.22,1) 220ms,border-radius .15s cubic-bezier(.19,1,.22,1) 300ms}
.demo-btn .demo-txt-out{transform:translateY(0);opacity:1;transition:none}
.demo-btn:hover .demo-txt-out{transform:translateY(-80%);opacity:0;transition:transform .8s cubic-bezier(.32,.99,.49,.99),opacity .3s ease}
.demo-btn .demo-txt-in{transform:translateY(80%);opacity:0;transition:none}
.demo-btn:hover .demo-txt-in{transform:translateY(0);opacity:1;transition:all .8s cubic-bezier(.32,.99,.49,.99)}
`;
const SHIMMER_CSS = `
@keyframes demo-shimmer{0%,75%{transform:translateX(-120%)}85%{transform:translateX(220%)}100%{transform:translateX(220%)}}
`;
const sizes = {
default: { padding: "14px 28px", fontSize: "16px", border: "1.5px solid transparent" },
sm: { padding: "10px 14px", fontSize: "14px", border: "none" },
} as const;
type SizeKey = keyof typeof sizes;
// Colour variants — same wave/shimmer/text-swap mechanics, different palette.
// "amber" is the default hero button; "neutral" waves from a light grey base to
// dark charcoal (for subdued CTAs that should share the effect without stealing
// the amber hero's prominence).
const variants = {
amber: {
base: "var(--accent-yellow)",
w1: "#0F1A2E", w2: "var(--accent-yellow-dark)", w3: "var(--accent-yellow)",
textOut: "var(--text-primary)", textIn: "var(--text-primary)",
},
neutral: {
base: "var(--bg-muted)",
w1: "#1A1A1A", w2: "var(--dark-bg)", w3: "var(--dark-bg)",
textOut: "var(--text-primary)", textIn: "#FFFFFF",
},
} as const;
type VariantKey = keyof typeof variants;
export default function DemoButton({
href = "/waitlist",
children = "Auf die Warteliste",
size = "default",
className = "",
onClick,
type,
disabled = false,
fullWidth = false,
variant = "amber",
}: {
href?: string;
children?: React.ReactNode;
size?: SizeKey;
className?: string;
onClick?: () => void;
/** When set, renders a <button type=…> (form submit) instead of a <Link>. */
type?: "submit" | "button";
disabled?: boolean;
/** Stretch the button to fill its container (e.g. a card CTA). */
fullWidth?: boolean;
/** Colour palette — "amber" (hero) or "neutral" (subdued grey→charcoal). */
variant?: VariantKey;
}) {
const scaleRef = useRef<HTMLDivElement>(null);
const s = sizes[size];
const v = variants[variant];
const onEnter = useCallback(() => {
if (scaleRef.current) gsap.to(scaleRef.current, { scale: 1.04, duration: 0.3, ease: "power2.out" });
}, []);
const onLeave = useCallback(() => {
if (scaleRef.current) gsap.to(scaleRef.current, { scale: 1, duration: 0.4, ease: "power2.inOut" });
}, []);
// Shared inner content (wave layers + text swap) for both Link and button.
const inner = (
<>
{/* Background + wave layers */}
<div
className="absolute inset-0 overflow-hidden transition-transform duration-[1500ms] group-hover:scale-[0.94]"
style={{
background: v.base,
borderRadius: "var(--radius-button)",
transitionTimingFunction: "cubic-bezier(.19,1,.22,1)",
}}
>
<span className="demo-wl demo-wl-1 absolute bottom-0 left-1/2 z-[2] block" style={{ width: "120%", height: "200%", background: v.w1 }} />
<span className="demo-wl demo-wl-2 absolute bottom-0 left-1/2 z-[3] block" style={{ width: "120%", height: "200%", background: v.w2 }} />
<span className="demo-wl demo-wl-3 absolute bottom-0 left-1/2 z-[4] block" style={{ width: "120%", height: "200%", background: v.w3 }} />
</div>
{/* Text out */}
<span className="demo-txt-out relative z-10" style={{ color: v.textOut }}>{children}</span>
{/* Text in */}
<span className="demo-txt-in absolute inset-0 z-10 flex items-center justify-center" style={{ color: v.textIn }}>{children}</span>
</>
);
const contentClass = `demo-btn group relative ${fullWidth ? "flex w-full" : "inline-flex"} items-center justify-center overflow-hidden font-semibold text-[var(--text-primary)]`;
const contentStyle = {
padding: s.padding,
fontSize: s.fontSize,
border: s.border,
borderRadius: "var(--radius-button)",
opacity: disabled ? 0.6 : undefined,
} as const;
return (
<>
<style dangerouslySetInnerHTML={{ __html: WAVE_CSS + SHIMMER_CSS }} />
<div
ref={scaleRef}
onMouseEnter={onEnter}
onMouseLeave={onLeave}
className={`${fullWidth ? "flex w-full" : "inline-flex"} ${className}`}
>
<div className={`relative ${fullWidth ? "flex w-full" : "inline-flex"} overflow-hidden rounded-[var(--radius-button)]`}>
{type ? (
<button
type={type}
disabled={disabled}
onClick={onClick}
className={contentClass}
style={contentStyle}
>
{inner}
</button>
) : (
<Link href={href} onClick={onClick} className={contentClass} style={contentStyle}>
{inner}
</Link>
)}
{/* Shimmer overlay */}
<div
className="pointer-events-none absolute inset-y-0 z-20 w-[40%]"
style={{
background: "linear-gradient(90deg, transparent, rgba(255,255,255,0.25), transparent)",
animation: "demo-shimmer 4s ease-in-out infinite",
}}
/>
</div>
</div>
</>
);
}