CTA Forge
Closing call-to-action: a molten-metal ember burns in a bottom strip with an amber hairline edge. Follows the site theme; the ember fades with --forge-glow on light themes. Token-only, works under any shadcn theme.
pnpm dlx shadcn@latest add @leo/cta-forgeProps
| Name | Type | Default | Description |
|---|---|---|---|
| accentColor | string | undefined | #d97706 | Ember tint, hex (3 or 6 digits, e.g. "#d97706"); molten-metal's three colours are derived from it, so any other value uses the default amber. |
| className | string | undefined | - | |
| contentClassName | string | undefined | - | Merged onto the content wrapper (eyebrow, heading, actions), e.g. `mx-auto max-w-6xl md:px-6` to line it up with the page container. |
| description | string | undefined | Tell us about your business. We reply within 24 hours with a plan and a quote. | |
| eyebrow | string | undefined | Start | |
| linkComponent | ElementType<{ href: string; className?: string | undefined; children?: ReactNode; }, keyof IntrinsicElements> | undefined | a | Link element for the actions, e.g. next/link. Receives href, className and children. |
| primaryAction | CtaForgeAction | null | undefined | { label: "Start a project", href: "#" } | `null` hides the button; omit for the sample action. |
| reducedMotion | undefined | "respect" | "ignore" | respect | "ignore" keeps the ember animating for visitors who prefer reduced motion. |
| secondaryAction | CtaForgeAction | null | undefined | - | Default `null`: a single button. |
| title | string | undefined | Ready to leave the template behind? | Heading. Empty string hides it. |
Source
"use client";
import { Component, lazy, Suspense, useRef } from "react";
import { useForgeGlow, useForgeMotion } from "@/hooks/use-forge-motion";
import { cn } from "@/lib/utils";
// The ember mounts only on the client, so loading it on demand keeps three.js out of the page's
// first-load chunk without changing the server markup.
const MoltenMetal = lazy(() => import("@/components/molten-metal"));
// The ember is decorative: a failed chunk load (stale deploy, offline) must not unmount the CTA.
class LayerBoundary extends Component<{ children: React.ReactNode }, { failed: boolean }> {
state = { failed: false };
static getDerivedStateFromError() {
return { failed: true };
}
render() {
return this.state.failed ? null : this.props.children;
}
}
export interface CtaForgeAction {
label: string;
href: string;
}
export interface CtaForgeProps {
eyebrow?: string;
/** Heading. Empty string hides it. */
title?: string;
description?: string;
/** `null` hides the button; omit for the sample action. */
primaryAction?: CtaForgeAction | null;
/** Default `null`: a single button. */
secondaryAction?: CtaForgeAction | null;
/** Link element for the actions, e.g. next/link. Receives href, className and children. */
linkComponent?: React.ElementType<{
href: string;
className?: string;
children?: React.ReactNode;
}>;
/** Ember tint, hex (3 or 6 digits, e.g. "#d97706"); molten-metal's three colours are derived from it, so any other value uses the default amber. */
accentColor?: string;
/** "ignore" keeps the ember animating for visitors who prefer reduced motion. */
reducedMotion?: "respect" | "ignore";
className?: string;
/** Merged onto the content wrapper (eyebrow, heading, actions), e.g. `mx-auto max-w-6xl md:px-6` to line it up with the page container. */
contentClassName?: string;
}
const DEFAULT_ACCENT = "#d97706";
const toRgb = (hex: string): [number, number, number] | null => {
const m = /^#([0-9a-f]{3}|[0-9a-f]{6})$/i.exec(hex.trim());
if (!m?.[1]) return null;
const h = m[1].length === 3 ? [...m[1]].map((c) => c + c).join("") : m[1];
return [0, 2, 4].map((i) => Number.parseInt(h.slice(i, i + 2), 16)) as [number, number, number];
};
/** Lowercase `#rrggbb`, or null when either input is not hex. */
export function mixHex(hex: string, target: string, amount: number): string | null {
const from = toRgb(hex);
const to = toRgb(target);
if (!from || !to) return null;
return `#${from
.map((c, i) =>
Math.round(c + ((to[i] ?? 0) - c) * amount)
.toString(16)
.padStart(2, "0"),
)
.join("")}`;
}
/** [deep, mid, hot] for molten-metal. Non-hex input uses the default accent. */
export function emberPalette(hex: string): [deep: string, mid: string, hot: string] {
const mid = mixHex(hex, hex, 0);
const deep = mixHex(hex, "#000000", 0.6);
const hot = mixHex(hex, "#ffffff", 0.6);
if (!mid || !deep || !hot) return emberPalette(DEFAULT_ACCENT);
return [deep, mid, hot];
}
const actionBase =
"inline-flex items-center px-6 py-3 font-mono text-xs uppercase tracking-widest focus-visible:outline-none focus-visible:ring-2 focus-visible:ring-ring focus-visible:ring-offset-2 focus-visible:ring-offset-background";
export default function CtaForge({
eyebrow = "Start",
title = "Ready to leave the template behind?",
description = "Tell us about your business. We reply within 24 hours with a plan and a quote.",
primaryAction = { label: "Start a project", href: "#" },
secondaryAction = null,
linkComponent: Link = "a",
accentColor = DEFAULT_ACCENT,
reducedMotion = "respect",
className,
contentClassName,
}: CtaForgeProps) {
const { animate } = useForgeMotion(reducedMotion);
const ref = useRef<HTMLElement>(null);
// The theme's --forge-glow (0 on light themes) scales the static ember and gates the shader, the
// same way projects-forge treats its rays.
const glow = useForgeGlow(ref);
const [color1, color2, color3] = emberPalette(accentColor);
// The static ember uses the palette's mid (the resolved accent), so a non-hex accentColor falls
// back to amber in both layers instead of the shader and the CSS gradient disagreeing.
return (
<section
ref={ref}
className={cn(
"relative isolate overflow-hidden border-t border-border bg-background text-foreground",
className,
)}
>
<div
aria-hidden="true"
className="absolute inset-x-0 bottom-0 h-[45%]"
style={{
maskImage: "linear-gradient(to bottom, transparent, black 70%)",
WebkitMaskImage: "linear-gradient(to bottom, transparent, black 70%)",
}}
>
<div
data-ember=""
aria-hidden="true"
className="absolute inset-0"
style={{
background: `radial-gradient(70% 100% at 50% 100%, color-mix(in srgb, ${color2} 45%, transparent), transparent 70%)`,
opacity: "var(--forge-glow, 1)",
}}
/>
{animate && glow > 0 && (
<LayerBoundary>
<Suspense fallback={null}>
<MoltenMetal
className="absolute inset-0"
backgroundColor="#0a0a0b"
color1={color1}
color2={color2}
color3={color3}
colorMode="ember"
mouseInteraction={false}
/>
</Suspense>
</LayerBoundary>
)}
</div>
<div
aria-hidden="true"
className="absolute inset-x-0 bottom-0 h-0.5 bg-primary"
style={{
maskImage: "linear-gradient(to right, transparent, black 20%, black 80%, transparent)",
WebkitMaskImage:
"linear-gradient(to right, transparent, black 20%, black 80%, transparent)",
}}
/>
<div
className={cn(
"relative px-6 pt-16 pb-28 md:flex md:items-end md:justify-between md:gap-12 md:px-12 md:pt-20 md:pb-36",
contentClassName,
)}
>
<div className="md:max-w-[60%]">
{eyebrow && (
<p className="font-mono text-xs uppercase tracking-widest text-primary">{eyebrow}</p>
)}
{title && (
<h2 className="mt-4 text-4xl leading-tight tracking-tight md:text-5xl">{title}</h2>
)}
{description && (
<p className="mt-6 max-w-xl text-base text-muted-foreground md:text-lg">
{description}
</p>
)}
</div>
{(primaryAction || secondaryAction) && (
<div className="mt-10 flex flex-wrap items-center gap-3 md:mt-0 md:shrink-0">
{primaryAction && (
<Link
href={primaryAction.href}
className={cn(actionBase, "bg-primary text-primary-foreground hover:bg-primary/90")}
>
{primaryAction.label}
</Link>
)}
{secondaryAction && (
<Link
href={secondaryAction.href}
className={cn(actionBase, "border border-border hover:bg-foreground/5")}
>
{secondaryAction.label}
</Link>
)}
</div>
)}
</div>
</section>
);
}