swoosh text.md

Extruded Text

Zinc 3D extruded text lit by your pointer, with letters that press in like keycaps.

Source: https://kokonutui.com/docs/texts/swoosh-text

Installation

npx shadcn@latest add @kokonutui/swoosh-text

Props

Prop Type Default Description
text? string "Extruded"
as? "div" | "span" | "p" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6" "div" Element to render, e.g. "h1" for a heading.
depth? number 12 Stacked layers behind each letter (clamped to 6-16).
length? number 0.2 Total extrusion length, in em.
accent? string Optional color for the deepest layer only, e.g. "#f97316".

Also takes every prop of Omit<HTMLAttributes<HTMLElement>, "children">.

Source

"use client";

/**
 * @author: @dorianbaffier
 * @description: Extruded Text
 * @version: 2.0.0
 * @date: 2026-10-14
 * @license: MIT
 * @website: https://kokonutui.com
 * @github: https://github.com/kokonut-labs/kokonutui
 */

import { type HTMLAttributes, type RefObject, useEffect, useRef } from "react";
import { cn } from "@/lib/utils";

interface SwooshTextProps
  extends Omit<HTMLAttributes<HTMLElement>, "children"> {
  text?: string;
  /** Element to render, e.g. "h1" for a heading. */
  as?: "div" | "span" | "p" | "h1" | "h2" | "h3" | "h4" | "h5" | "h6";
  /** Stacked layers behind each letter (clamped to 6-16). */
  depth?: number;
  /** Total extrusion length, in em. */
  length?: number;
  /** Optional color for the deepest layer only, e.g. "#f97316". */
  accent?: string;
}

// Remaining code omitted for brevity, but includes functions defined here...

export default function SwooshText({
  text = "Extruded",
  as: Tag = "div",
  depth = 12,
  length = 0.2,
  accent,
  className,
  style,
  ...props
}: SwooshTextProps) {
  const rootRef = useRef<HTMLElement | null>(null);
  const layers = Math.round(Math.min(16, Math.max(6, depth)));
  const step = length / layers;
  useExtrusion(rootRef, text, layers, step);

const words = text.split(WHITESPACE).filter(Boolean);

return (
    <Tag
      className={cn(
        "relative touch-manipulation select-none font-bold text-5xl tracking-tight",
        "[--ex-face:var(--color-zinc-900)] [--ex-far:var(--color-zinc-600)] [--ex-near:var(--color-zinc-300)]",
        "dark:[--ex-face:var(--color-zinc-50)] dark:[--ex-far:var(--color-zinc-700)] dark:[--ex-near:var(--color-zinc-400)]",
        className
      )}
      ref={(node: HTMLElement | null) => {
        rootRef.current = node;
      }}
      style={style}
      {...props}
    >
      <span className="sr-only">{text}</span>
      <span aria-hidden="true">
        {words.map((word, w) => (
          <span key={w}>
            {w > 0 ? " " : null}
            <span className="inline-block whitespace-nowrap">
              {splitGraphemes(word).map((char, c) => (
                <Letter
                  accent={accent}
                  char={char}
                  depth={layers}
                  key={c}
                  step={step}
                />
              ))}
            </span>
          </span>
        ))}
      </span>
    </Tag>
  );
}