# Integrate `MetallicText` from Motion Garden

You are helping me add the **MetallicText** component to an existing project.
Everything you need is below — full source, dependencies, props and the
behavioural contract. Read it all before writing anything.

- **Component:** MetallicText
- **Category:** Text Animations
- **Summary:** Chrome poured into a headline. A metal ramp clipped to real glyphs, a specular travelling across them, and a tinted wake following a beat behind.
- **Reference:** https://motion-garden.netlify.app/components/metallic-text
- **Full catalog (for you, the agent):** https://motion-garden.netlify.app/llms.txt

## Stack this source assumes

- React 19 with the Next.js App Router (never the `pages/` directory)
- TypeScript, strict
- Tailwind CSS v4, CSS-first config (utilities are inline; no `tailwind.config` needed)

If my project differs, adapt the integration — but do not rewrite the animation math to suit a different stack. Ask me first.

## Dependencies

```bash
bun add clsx tailwind-merge
```

## Design tokens this source uses

Some classes in the source are Motion Garden theme tokens, not stock Tailwind (`text-ink`, `bg-panel`, `font-display` and the like). Without them, parts of the component render unstyled. Add this to my global CSS, after the Tailwind import:

```css
@theme inline {
  --color-accent: var(--sg-accent);
}

:root {
  --sg-accent: #7e22ce;
}

.dark {
  --sg-accent: #a855f7;
}
```

The values are Motion Garden's own light and dark themes. If my project already has tokens for these roles, point the `--sg-*` variables at mine instead and tell me which you mapped. `.dark` assumes class-based dark mode — adapt the selector to how my project switches themes.

## Files to create

2 files — all of them are required. Paths are as shipped; the component may live anywhere in my project, but keep every peer file at the exact path shown so the import aliases resolve.

### 1. `components/registry/metallic-text/metallic-text.tsx`

```tsx
"use client";

import { useId, type CSSProperties } from "react";
import { cn } from "@/lib/utils";

export interface MetallicTextProps {
  text?: string;
  sweepSpeed?: number;
  sweepWidth?: number;
  sweepAngle?: number;
  contrast?: number;
  specular?: number;
  lag?: number;
  sweep?: "alternate" | "loop";
  grain?: number;
  baseColor?: string;
  highlightColor?: string;
  accentColor?: string;
  paused?: boolean;
  reducedMotion?: boolean;
  className?: string;
}

function sheet(ns: string): string {
  return `
.${ns} {
  display: inline-block;
  color: var(--mt-base);
}

.${ns} > .${ns}-core {
  display: block;
  color: inherit;
}

@supports ((background-clip: text) or (-webkit-background-clip: text)) {
  .${ns},
  .${ns} > .${ns}-core {
    -webkit-background-clip: text;
    background-clip: text;
    color: transparent;
    -webkit-text-fill-color: transparent;
    animation-duration: var(--mt-dur);
    animation-iteration-count: infinite;
    animation-direction: var(--mt-dir);
    animation-play-state: var(--mt-play);
  }

  .${ns} {
    background-image:
      linear-gradient(
        var(--mt-angle),
        transparent 0 var(--mt-w0),
        color-mix(in srgb, var(--mt-accent) var(--mt-halo), transparent) 50%,
        transparent var(--mt-w2) 100%
      ),
      repeating-linear-gradient(
        var(--mt-angle),
        rgb(255 255 255 / var(--mt-grain)) 0 1px,
        rgb(0 0 0 / var(--mt-grain)) 1px 2px,
        transparent 2px 4px
      ),
      linear-gradient(
        180deg,
        color-mix(in oklab, var(--mt-base) var(--mt-dark), black) 0%,
        color-mix(in oklab, var(--mt-base) var(--mt-lite), var(--mt-hi)) 26%,
        var(--mt-base) 44%,
        color-mix(in oklab, var(--mt-base) var(--mt-dark), black) 56%,
        color-mix(in oklab, var(--mt-base) var(--mt-lite), var(--mt-hi)) 80%,
        color-mix(in oklab, var(--mt-base) 88%, black) 100%
      );
    background-size: 300% 300%, auto, 100% 100%;
    background-position: var(--mt-park) 50%, 0 0, 0 0;
    background-repeat: no-repeat, repeat, no-repeat;
    background-blend-mode: screen, overlay, normal;
    animation-name: ${ns}-wake;
    animation-timing-function: var(--mt-ease-wake);
    animation-delay: var(--mt-delay);
    animation-fill-mode: backwards;
  }

  .${ns} > .${ns}-core {
    background-image: linear-gradient(
      var(--mt-angle),
      transparent 0 var(--mt-s0),
      color-mix(in srgb, var(--mt-hi) var(--mt-spec), transparent) 50%,
      transparent var(--mt-s2) 100%
    );
    background-size: 300% 300%;
    background-position: var(--mt-park) 50%;
    background-repeat: no-repeat;
    animation-name: ${ns}-core;
    animation-timing-function: var(--mt-ease-core);
  }
}

.${ns}.${ns}-still,
.${ns}.${ns}-still > .${ns}-core {
  animation-name: none;
}

@keyframes ${ns}-core {
  from { background-position: 100% 50%; }
  to { background-position: 0% 50%; }
}

@keyframes ${ns}-wake {
  from { background-position: 100% 50%, 0 0, 0 0; }
  to { background-position: 0% 50%, 0 0, 0 0; }
}
`;
}

const PARK = "62%";

export default function MetallicText({
  text = "METALLIC",
  sweepSpeed = 3.2,
  sweepWidth = 0.28,
  sweepAngle = 18,
  contrast = 0.7,
  specular = 0.85,
  lag = 0.35,
  sweep = "alternate",
  grain = 0.12,
  baseColor = "#8f94a3",
  highlightColor = "#ffffff",
  accentColor = "#a855f7",
  paused = false,
  reducedMotion = false,
  className,
}: MetallicTextProps) {
  const ns = `sg${useId().replace(/[^a-zA-Z0-9]/g, "")}`;

  const half = (Math.max(0.02, sweepWidth) * 100) / 6;
  const wakeHalf = Math.min(26, half * 2.6);

  return (
    <>
      <style>{sheet(ns)}</style>
      <span
        className={cn(ns, reducedMotion && `${ns}-still`, className)}
        style={
          {
            "--mt-base": baseColor,
            "--mt-hi": highlightColor,
            "--mt-accent": accentColor,
            "--mt-angle": `${90 + sweepAngle}deg`,
            "--mt-dur": `${sweepSpeed}s`,
            "--mt-delay": `${(lag * 0.3 * sweepSpeed).toFixed(3)}s`,
            "--mt-dir": sweep === "alternate" ? "alternate" : "normal",
            "--mt-play": paused ? "paused" : "running",
            "--mt-park": PARK,
            "--mt-grain": `${grain}`,
            "--mt-dark": `${Math.max(20, 100 - contrast * 45).toFixed(1)}%`,
            "--mt-lite": `${Math.max(15, 100 - contrast * 55).toFixed(1)}%`,
            "--mt-spec": `${Math.round(Math.min(1, specular) * 100)}%`,
            "--mt-halo": `${Math.round(Math.min(0.6, specular * 0.4) * 100)}%`,
            "--mt-s0": `${(50 - half).toFixed(2)}%`,
            "--mt-s2": `${(50 + half).toFixed(2)}%`,
            "--mt-w0": `${(50 - wakeHalf).toFixed(2)}%`,
            "--mt-w2": `${(50 + wakeHalf).toFixed(2)}%`,
            "--mt-ease-core": "cubic-bezier(0.45, 0, 0.55, 1)",
            "--mt-ease-wake": "cubic-bezier(0.34, 1.56, 0.64, 1)",
          } as CSSProperties
        }
      >
        <span className={`${ns}-core`}>{text}</span>
      </span>
    </>
  );
}
```

### 2. `lib/utils.ts` — peer util, required

```tsx
import { clsx, type ClassValue } from "clsx";
import { twMerge } from "tailwind-merge";

export function cn(...inputs: ClassValue[]) {
  return twMerge(clsx(inputs));
}
```


## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `sweepSpeed` | `number` | `3.2` | Time for the highlight to cross the line once. Range 0.5–12 s. |
| `sweepWidth` | `number` | `0.28` | Width of the specular band as a share of the text box. Narrow reads as polished chrome, wide as brushed steel — the band is the light source, so its size is the softness of the reflection. Range 0.05–1. |
| `sweepAngle` | `number` | `18` | Rake of the band off vertical. Stops short of ±90 on purpose: at a right angle the band lies parallel to its own travel and the sweep stops reading as movement at all. Range -60–60 °. |
| `contrast` | `number` | `0.7` | Separation between the dark and light bands of the metal. This is what decides whether the text reads as chrome or as a grey gradient — the horizon between the two is the reflection of a ground plane. Range 0–1.5. |
| `specular` | `number` | `0.85` | Brightness of the travelling highlight. Range 0–1.5. |
| `lag` | `number` | `0.35` | How far the wake trails the highlight. At zero the two move as one gradient; raise it and the light gains weight, because the trailing edge is still arriving when the leading edge has gone. Range 0–1. |
| `sweep` | `"alternate" | "loop"` | `"alternate"` | Whether the light returns the way it came or restarts from the same edge each pass. |
| `grain` | `number` | `0.12` | Brushed striations along the sweep axis. Directional rather than random — milled metal has a grain direction, and noise reads as dirt on the screen instead. Range 0–0.5. |
| `baseColor` | `string (hex)` | `"#8f94a3"` | The metal. Also the fallback colour: where background-clip on text is unsupported the element renders as plain text in this colour rather than as an invisible headline. |
| `highlightColor` | `string (hex)` | `"#ffffff"` | The specular. |
| `accentColor` | `string (hex)` | `"#a855f7"` | Tint of the wake. |

## Usage

```tsx
import MetallicText from "@/components/registry/metallic-text/metallic-text";

<MetallicText
  sweepSpeed={3.2}
  sweepWidth={0.28}
  sweepAngle={18}
  contrast={0.7}
  specular={0.85}
  lag={0.35}
  sweep="alternate"
  grain={0.12}
  baseColor="#8f94a3"
  highlightColor="#ffffff"
  accentColor="#a855f7"
/>
```

The import path matches the file path above; change it if you move the component. Every value shown is the documented default — pass only what you actually want to change. The snippet lists the tunable props only: if the component's props type in the source requires others (content, handlers, data), pass those too.

## Integration rules

- Keep the `"use client"` directive. This is a client component and will not render as a Server Component.
- It fills its parent. Give the wrapper an explicit height (or a definite grid area) — against a height-auto parent it collapses to nothing.
- It takes a `reducedMotion` prop and quiesces when true. Wire it to a `prefers-reduced-motion` listener rather than hardcoding `false`.
- It runs a free-running animation loop. Halt it when off-screen or backgrounded if you care about battery.
- `lib/utils.ts` is required, not optional. It exports the `cn` helper the component imports from `@/lib/utils` — keep it at that path, or rewrite every `cn` import to wherever you already keep yours. If your project is shadcn-based you almost certainly have this file already; keep yours and drop mine.

## Your task

1. Tell me where in my project this should live and why.
2. Create the files above verbatim.
3. Add the design tokens to my global CSS, or map them to tokens I already have.
4. Wire the component into the place I point you at, with sensible props for that context.
5. Flag anything in my setup that conflicts with the stack assumptions above.

Do not restyle the component or alter the animation math unless I ask.
