Motion

21 small animation components that every Yoink component is built with. When we rebuild a site's marquee, headline reveal or glowing backdrop, it uses these. They're also yours to use on their own. Each is one file with no dependencies besides React. They take their colours from your theme, and they stay still for people who've turned on reduced motion.

Preview

Reveal

Scroll reveals

Content fades and slides in as it scrolls into view.

<Reveal from="up" delay={0} duration={700} distance={24} once as="div" className="">…</Reveal>  // from: up|down|left|right|scale|blur|none
npx shadcn@latest add https://yoink-app.fly.dev/r/motion/reveal.json
Source
"use client";

import { useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type ElementType, type ReactNode, type RefObject } from "react";

const YK_EASE = "cubic-bezier(0.16, 1, 0.3, 1)";

const useYkLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;

function ykReducedMotion(): boolean {
  return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
}

// "idle": untouched (visible) · "hidden": waiting below the fold · "shown": play the entrance.
// Content is only hidden once we know we can show it again (IntersectionObserver exists, motion allowed,
// and there is a box to watch), and a safety net reveals anything on screen that is still hidden.
type YkRevealState = "idle" | "hidden" | "shown";

function useYkReveal(ref: RefObject<Element | null>, once = true): YkRevealState {
  const [state, setState] = useState<YkRevealState>("idle");
  useYkLayoutEffect(() => {
    const el = ref.current;
    if (!el || ykReducedMotion() || typeof IntersectionObserver === "undefined") return;
    // watch the element's own box, or its children when it has none (display: contents)
    const boxes = () => (getComputedStyle(el).display === "contents" ? Array.from(el.children) : [el]);
    const onScreen = (t: Element) => {
      const r = t.getBoundingClientRect();
      return (r.width > 0 || r.height > 0) && r.bottom > 0 && r.right > 0 && r.top < window.innerHeight && r.left < window.innerWidth;
    };
    if (!boxes().some((t) => t.getBoundingClientRect().width > 0 || t.getBoundingClientRect().height > 0)) return; // e.g. hidden at mount: leave it visible
    let shown = false;
    const show = (v: boolean) => {
      if (v !== shown) (shown = v), setState(v ? "shown" : "hidden");
    };
    setState("hidden");
    const inView = new Set<Element>();
    const io = new IntersectionObserver((entries) => {
      for (const e of entries) {
        if (e.isIntersecting) inView.add(e.target);
        else inView.delete(e.target);
      }
      if (inView.size) {
        show(true);
        if (once) io.disconnect();
      } else if (!once) show(false);
    });
    const watched = new Set<Element>();
    const watch = () => boxes().forEach((t) => !watched.has(t) && (watched.add(t), io.observe(t)));
    watch();
    // safety net: styles that land after mount (display: contents) get watched too, and nothing
    // stays hidden for more than a moment while it is actually on screen
    const start = Date.now();
    const net = setInterval(() => {
      if (shown) return once && clearInterval(net);
      watch();
      if (Date.now() - start > 2400 && boxes().some(onScreen)) show(true);
    }, 600);
    return () => {
      io.disconnect();
      clearInterval(net);
    };
  }, [once]);
  return state;
}

type YkRevealFrom = "up" | "down" | "left" | "right" | "scale" | "blur" | "none";

/** Fades content in as it scrolls into view. */
export function Reveal({
  children,
  from = "up",
  delay = 0,
  duration = 700,
  distance = 24,
  once = true,
  as = "div",
  className,
  style,
}: {
  children?: ReactNode;
  from?: YkRevealFrom;
  delay?: number;
  duration?: number;
  distance?: number;
  once?: boolean;
  as?: ElementType;
  className?: string;
  style?: CSSProperties;
}) {
  const Tag = as;
  const ref = useRef<HTMLElement>(null);
  const state = useYkReveal(ref, once);
  const hidden = state === "hidden";
  const offset = {
    up: `translate3d(0, ${distance}px, 0)`,
    down: `translate3d(0, ${-distance}px, 0)`,
    left: `translate3d(${-distance}px, 0, 0)`,
    right: `translate3d(${distance}px, 0, 0)`,
    scale: "scale(0.94)",
    blur: `translate3d(0, ${distance / 2}px, 0)`,
    none: "none",
  }[from];
  const t = `${duration}ms ${YK_EASE} ${delay}ms`;
  return (
    <Tag
      ref={ref}
      className={className}
      style={{
        ...style,
        ...(hidden && { opacity: 0, transform: offset, filter: from === "blur" ? "blur(12px)" : undefined }),
        ...(state === "shown" && { transition: `opacity ${t}, transform ${t}, filter ${t}` }),
      }}
    >
      {children}
    </Tag>
  );
}

Stagger

Scroll reveals

A group whose items arrive one after another.

<Stagger step={90} from="up" distance={20} duration={650} delay={0} once as="div" className="grid gap-4 md:grid-cols-3">{cards}</Stagger>  // from: up|down|left|right|scale|fade
npx shadcn@latest add https://yoink-app.fly.dev/r/motion/stagger.json
Source
"use client";

import { useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type ElementType, type ReactNode, type RefObject } from "react";

const YK_EASE = "cubic-bezier(0.16, 1, 0.3, 1)";

const useYkLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;

function ykReducedMotion(): boolean {
  return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
}

// "idle": untouched (visible) · "hidden": waiting below the fold · "shown": play the entrance.
// Content is only hidden once we know we can show it again (IntersectionObserver exists, motion allowed,
// and there is a box to watch), and a safety net reveals anything on screen that is still hidden.
type YkRevealState = "idle" | "hidden" | "shown";

function useYkReveal(ref: RefObject<Element | null>, once = true): YkRevealState {
  const [state, setState] = useState<YkRevealState>("idle");
  useYkLayoutEffect(() => {
    const el = ref.current;
    if (!el || ykReducedMotion() || typeof IntersectionObserver === "undefined") return;
    // watch the element's own box, or its children when it has none (display: contents)
    const boxes = () => (getComputedStyle(el).display === "contents" ? Array.from(el.children) : [el]);
    const onScreen = (t: Element) => {
      const r = t.getBoundingClientRect();
      return (r.width > 0 || r.height > 0) && r.bottom > 0 && r.right > 0 && r.top < window.innerHeight && r.left < window.innerWidth;
    };
    if (!boxes().some((t) => t.getBoundingClientRect().width > 0 || t.getBoundingClientRect().height > 0)) return; // e.g. hidden at mount: leave it visible
    let shown = false;
    const show = (v: boolean) => {
      if (v !== shown) (shown = v), setState(v ? "shown" : "hidden");
    };
    setState("hidden");
    const inView = new Set<Element>();
    const io = new IntersectionObserver((entries) => {
      for (const e of entries) {
        if (e.isIntersecting) inView.add(e.target);
        else inView.delete(e.target);
      }
      if (inView.size) {
        show(true);
        if (once) io.disconnect();
      } else if (!once) show(false);
    });
    const watched = new Set<Element>();
    const watch = () => boxes().forEach((t) => !watched.has(t) && (watched.add(t), io.observe(t)));
    watch();
    // safety net: styles that land after mount (display: contents) get watched too, and nothing
    // stays hidden for more than a moment while it is actually on screen
    const start = Date.now();
    const net = setInterval(() => {
      if (shown) return once && clearInterval(net);
      watch();
      if (Date.now() - start > 2400 && boxes().some(onScreen)) show(true);
    }, 600);
    return () => {
      io.disconnect();
      clearInterval(net);
    };
  }, [once]);
  return state;
}

/** Reveals each direct child one after another when the group scrolls into view. */
export function Stagger({
  children,
  step = 90,
  from = "up",
  distance = 20,
  duration = 650,
  delay = 0,
  once = true,
  as = "div",
  className,
  style,
}: {
  children?: ReactNode;
  step?: number;
  from?: "up" | "down" | "left" | "right" | "scale" | "fade";
  distance?: number;
  duration?: number;
  delay?: number;
  once?: boolean;
  as?: ElementType;
  className?: string;
  style?: CSSProperties;
}) {
  const Tag = as;
  const ref = useRef<HTMLElement>(null);
  const state = useYkReveal(ref, once);
  useYkLayoutEffect(() => {
    const items = Array.from(ref.current?.children ?? []) as HTMLElement[];
    if (state === "idle") return;
    const offset = {
      up: `translate3d(0, ${distance}px, 0)`,
      down: `translate3d(0, ${-distance}px, 0)`,
      left: `translate3d(${-distance}px, 0, 0)`,
      right: `translate3d(${distance}px, 0, 0)`,
      scale: "scale(0.92)",
      fade: "none",
    }[from];
    if (state === "hidden") {
      for (const el of items) Object.assign(el.style, { transition: "none", opacity: "0", transform: offset });
      return;
    }
    items.forEach((el, i) => {
      const t = `${duration}ms ${YK_EASE} ${delay + i * step}ms`;
      Object.assign(el.style, { transition: `opacity ${t}, transform ${t}`, opacity: "", transform: "" });
    });
    // hand the children their own transitions back once everything has landed
    const done = setTimeout(() => items.forEach((el) => (el.style.transition = "")), delay + items.length * step + duration + 50);
    return () => clearTimeout(done);
  }, [state]);
  return (
    <Tag ref={ref} className={className} style={style}>
      {children}
    </Tag>
  );
}

Text reveal

Text effects

Headlines that rise in word by word or letter by letter.

<TextReveal as="h1" text="Headline here" by="word" effect="rise" step={70} duration={800} delay={0} className="" />  // by: word|letter; effect: rise|blur|fade
npx shadcn@latest add https://yoink-app.fly.dev/r/motion/text-reveal.json
Source
"use client";

import { useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type ElementType, type RefObject } from "react";

const YK_EASE = "cubic-bezier(0.16, 1, 0.3, 1)";

const useYkLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;

function ykReducedMotion(): boolean {
  return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
}

const ykSrOnly: CSSProperties = { position: "absolute", width: 1, height: 1, padding: 0, margin: -1, overflow: "hidden", clip: "rect(0 0 0 0)", whiteSpace: "nowrap", border: 0 };

// "idle": untouched (visible) · "hidden": waiting below the fold · "shown": play the entrance.
// Content is only hidden once we know we can show it again (IntersectionObserver exists, motion allowed,
// and there is a box to watch), and a safety net reveals anything on screen that is still hidden.
type YkRevealState = "idle" | "hidden" | "shown";

function useYkReveal(ref: RefObject<Element | null>, once = true): YkRevealState {
  const [state, setState] = useState<YkRevealState>("idle");
  useYkLayoutEffect(() => {
    const el = ref.current;
    if (!el || ykReducedMotion() || typeof IntersectionObserver === "undefined") return;
    // watch the element's own box, or its children when it has none (display: contents)
    const boxes = () => (getComputedStyle(el).display === "contents" ? Array.from(el.children) : [el]);
    const onScreen = (t: Element) => {
      const r = t.getBoundingClientRect();
      return (r.width > 0 || r.height > 0) && r.bottom > 0 && r.right > 0 && r.top < window.innerHeight && r.left < window.innerWidth;
    };
    if (!boxes().some((t) => t.getBoundingClientRect().width > 0 || t.getBoundingClientRect().height > 0)) return; // e.g. hidden at mount: leave it visible
    let shown = false;
    const show = (v: boolean) => {
      if (v !== shown) (shown = v), setState(v ? "shown" : "hidden");
    };
    setState("hidden");
    const inView = new Set<Element>();
    const io = new IntersectionObserver((entries) => {
      for (const e of entries) {
        if (e.isIntersecting) inView.add(e.target);
        else inView.delete(e.target);
      }
      if (inView.size) {
        show(true);
        if (once) io.disconnect();
      } else if (!once) show(false);
    });
    const watched = new Set<Element>();
    const watch = () => boxes().forEach((t) => !watched.has(t) && (watched.add(t), io.observe(t)));
    watch();
    // safety net: styles that land after mount (display: contents) get watched too, and nothing
    // stays hidden for more than a moment while it is actually on screen
    const start = Date.now();
    const net = setInterval(() => {
      if (shown) return once && clearInterval(net);
      watch();
      if (Date.now() - start > 2400 && boxes().some(onScreen)) show(true);
    }, 600);
    return () => {
      io.disconnect();
      clearInterval(net);
    };
  }, [once]);
  return state;
}

/** Animates a headline in word by word (or letter by letter) when it scrolls into view. */
export function TextReveal({
  text = "Make something people remember",
  by = "word",
  effect = "rise",
  step,
  duration = 800,
  delay = 0,
  once = true,
  as = "span",
  className,
  style,
}: {
  text?: string;
  by?: "word" | "letter";
  effect?: "rise" | "blur" | "fade";
  step?: number;
  duration?: number;
  delay?: number;
  once?: boolean;
  as?: ElementType;
  className?: string;
  style?: CSSProperties;
}) {
  const Tag = as;
  const ref = useRef<HTMLElement>(null);
  const state = useYkReveal(ref, once);
  const gap = step ?? (by === "word" ? 70 : 24);
  let i = 0;
  const piece = (s: string, key: string) => {
    const n = i++;
    const hidden = state === "hidden";
    const t = `${duration}ms ${YK_EASE} ${delay + n * gap}ms`;
    const inner: CSSProperties = {
      display: "inline-block",
      whiteSpace: "pre",
      ...(hidden && {
        opacity: effect === "rise" ? 1 : 0,
        transform: effect === "rise" ? "translate3d(0, 110%, 0)" : effect === "blur" ? "translate3d(0, 0.25em, 0)" : "none",
        filter: effect === "blur" ? "blur(10px)" : undefined,
      }),
      ...(state === "shown" && { transition: `opacity ${t}, transform ${t}, filter ${t}` }),
    };
    // "rise" slides each piece up from behind a mask; a little padding keeps descenders unclipped
    return effect === "rise" ? (
      <span key={key} style={{ display: "inline-block", overflow: "hidden", verticalAlign: "top", paddingBottom: "0.12em", marginBottom: "-0.12em" }}>
        <span style={inner}>{s}</span>
      </span>
    ) : (
      <span key={key} style={inner}>
        {s}
      </span>
    );
  };
  const words = text.split(/(\s+)/);
  return (
    <Tag ref={ref} className={className} style={style}>
      <span style={ykSrOnly}>{text}</span>
      <span aria-hidden="true">
        {words.map((w, wi) =>
          /^\s+$/.test(w) ? (
            " "
          ) : by === "word" ? (
            piece(w, `w${wi}`)
          ) : (
            <span key={`w${wi}`} style={{ display: "inline-block", whiteSpace: "nowrap" }}>
              {Array.from(w).map((ch, ci) => piece(ch, `c${ci}`))}
            </span>
          ),
        )}
      </span>
    </Tag>
  );
}

Marquee

Marquees & tickers

An endless, seamless scrolling row of logos, quotes or tags.

<Marquee speed={40} reverse={false} vertical={false} pauseOnHover fade gap={48} className="">{items}</Marquee>  // speed in px/s
npx shadcn@latest add https://yoink-app.fly.dev/r/motion/marquee.json
Source
"use client";

import { useEffect, useRef, useState, type CSSProperties, type ReactNode } from "react";

const YK_MARQUEE_CSS = `@keyframes yk-marquee-x{to{transform:translate3d(calc(-1 * var(--yk-shift)),0,0)}}
@keyframes yk-marquee-y{to{transform:translate3d(0,calc(-1 * var(--yk-shift)),0)}}
[data-yk-marquee][data-pause]:hover [data-yk-track]{animation-play-state:paused}
@media (prefers-reduced-motion:reduce){[data-yk-track]{animation:none!important}}`;

/** An endless, seamless scrolling row (or column) of items: logos, quotes, tags. */
export function Marquee({
  children,
  speed = 40,
  reverse = false,
  vertical = false,
  pauseOnHover = true,
  fade = true,
  gap = 48,
  className,
  style,
}: {
  children?: ReactNode;
  /** pixels per second */
  speed?: number;
  reverse?: boolean;
  vertical?: boolean;
  pauseOnHover?: boolean;
  fade?: boolean;
  gap?: number;
  className?: string;
  style?: CSSProperties;
}) {
  const box = useRef<HTMLDivElement>(null);
  const group = useRef<HTMLDivElement>(null);
  const [m, setM] = useState({ copies: 2, size: 0 });
  useEffect(() => {
    const measure = () => {
      const b = box.current, g = group.current;
      if (!b || !g) return;
      const size = vertical ? g.offsetHeight : g.offsetWidth;
      const room = vertical ? b.offsetHeight : b.offsetWidth;
      if (size > 0) setM({ size, copies: Math.max(2, Math.ceil(room / size) + 1) });
    };
    measure();
    const ro = typeof ResizeObserver !== "undefined" ? new ResizeObserver(measure) : null;
    if (box.current) ro?.observe(box.current);
    if (group.current) ro?.observe(group.current);
    return () => ro?.disconnect();
  }, [vertical]);
  // the copies are only there to fill the loop: hide them from screen readers and keyboards
  useEffect(() => {
    box.current?.querySelectorAll("[data-yk-copy]").forEach((el) => el.setAttribute("inert", ""));
  }, [m.copies]);
  const edge = vertical ? "to bottom" : "to right";
  const mask = fade ? `linear-gradient(${edge}, transparent, black 10%, black 90%, transparent)` : undefined;
  const dir = vertical ? "column" : "row";
  const items = (copy: number) => (
    <div
      key={copy}
      ref={copy === 0 ? group : undefined}
      data-yk-copy={copy > 0 ? "" : undefined}
      aria-hidden={copy > 0 || undefined}
      style={{ display: "flex", flexDirection: dir, flexShrink: 0, alignItems: "center", gap, [vertical ? "paddingBottom" : "paddingRight"]: gap }}
    >
      {children}
    </div>
  );
  return (
    <div
      ref={box}
      data-yk-marquee=""
      data-pause={pauseOnHover ? "" : undefined}
      className={className}
      style={{ overflow: "hidden", maskImage: mask, WebkitMaskImage: mask, ...style }}
    >
      <style>{YK_MARQUEE_CSS}</style>
      <div
        data-yk-track=""
        style={{
          display: "flex",
          flexDirection: dir,
          width: vertical ? "100%" : "max-content",
          ["--yk-shift" as string]: `${m.size}px`,
          animation: m.size ? `yk-marquee-${vertical ? "y" : "x"} ${m.size / Math.max(speed, 1)}s linear infinite${reverse ? " reverse" : ""}` : undefined,
        }}
      >
        {Array.from({ length: m.copies }, (_, i) => items(i))}
      </div>
    </div>
  );
}

Count up

Text effects

Numbers that count up when they come into view.

<CountUp to={12840} from={0} duration={1800} decimals={0} prefix="" suffix="+" className="" />
npx shadcn@latest add https://yoink-app.fly.dev/r/motion/count-up.json
Source
"use client";

import { useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type RefObject } from "react";

const useYkLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;

function ykReducedMotion(): boolean {
  return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
}

const ykSrOnly: CSSProperties = { position: "absolute", width: 1, height: 1, padding: 0, margin: -1, overflow: "hidden", clip: "rect(0 0 0 0)", whiteSpace: "nowrap", border: 0 };

// "idle": untouched (visible) · "hidden": waiting below the fold · "shown": play the entrance.
// Content is only hidden once we know we can show it again (IntersectionObserver exists, motion allowed,
// and there is a box to watch), and a safety net reveals anything on screen that is still hidden.
type YkRevealState = "idle" | "hidden" | "shown";

function useYkReveal(ref: RefObject<Element | null>, once = true): YkRevealState {
  const [state, setState] = useState<YkRevealState>("idle");
  useYkLayoutEffect(() => {
    const el = ref.current;
    if (!el || ykReducedMotion() || typeof IntersectionObserver === "undefined") return;
    // watch the element's own box, or its children when it has none (display: contents)
    const boxes = () => (getComputedStyle(el).display === "contents" ? Array.from(el.children) : [el]);
    const onScreen = (t: Element) => {
      const r = t.getBoundingClientRect();
      return (r.width > 0 || r.height > 0) && r.bottom > 0 && r.right > 0 && r.top < window.innerHeight && r.left < window.innerWidth;
    };
    if (!boxes().some((t) => t.getBoundingClientRect().width > 0 || t.getBoundingClientRect().height > 0)) return; // e.g. hidden at mount: leave it visible
    let shown = false;
    const show = (v: boolean) => {
      if (v !== shown) (shown = v), setState(v ? "shown" : "hidden");
    };
    setState("hidden");
    const inView = new Set<Element>();
    const io = new IntersectionObserver((entries) => {
      for (const e of entries) {
        if (e.isIntersecting) inView.add(e.target);
        else inView.delete(e.target);
      }
      if (inView.size) {
        show(true);
        if (once) io.disconnect();
      } else if (!once) show(false);
    });
    const watched = new Set<Element>();
    const watch = () => boxes().forEach((t) => !watched.has(t) && (watched.add(t), io.observe(t)));
    watch();
    // safety net: styles that land after mount (display: contents) get watched too, and nothing
    // stays hidden for more than a moment while it is actually on screen
    const start = Date.now();
    const net = setInterval(() => {
      if (shown) return once && clearInterval(net);
      watch();
      if (Date.now() - start > 2400 && boxes().some(onScreen)) show(true);
    }, 600);
    return () => {
      io.disconnect();
      clearInterval(net);
    };
  }, [once]);
  return state;
}

/** A number that counts up when it scrolls into view. */
export function CountUp({
  to = 100,
  from = 0,
  duration = 1800,
  decimals = 0,
  prefix = "",
  suffix = "",
  locale,
  className,
  style,
}: {
  to?: number;
  from?: number;
  duration?: number;
  decimals?: number;
  prefix?: string;
  suffix?: string;
  locale?: string;
  className?: string;
  style?: CSSProperties;
}) {
  const ref = useRef<HTMLSpanElement>(null);
  const state = useYkReveal(ref);
  const [value, setValue] = useState(to);
  const fmt = (n: number) => `${prefix}${n.toLocaleString(locale, { minimumFractionDigits: decimals, maximumFractionDigits: decimals })}${suffix}`;
  useYkLayoutEffect(() => {
    if (state === "hidden") setValue(from);
  }, [state]);
  useEffect(() => {
    if (state !== "shown") return;
    let raf = 0;
    const start = performance.now();
    const tick = (now: number) => {
      const p = Math.min(1, (now - start) / duration);
      const eased = p === 1 ? 1 : 1 - Math.pow(2, -10 * p);
      setValue(from + (to - from) * eased);
      if (p < 1) raf = requestAnimationFrame(tick);
    };
    raf = requestAnimationFrame(tick);
    return () => cancelAnimationFrame(raf);
  }, [state, to, from, duration]);
  return (
    <span ref={ref} className={className} style={{ fontVariantNumeric: "tabular-nums", ...style }}>
      <span aria-hidden="true">{fmt(value)}</span>
      <span style={ykSrOnly}>{fmt(to)}</span>
    </span>
  );
}

Rotating words

Text effects

One word in a sentence keeps changing, resizing smoothly.

<RotatingWords words={["designers", "developers"]} interval={2400} duration={600} className="text-primary" />
npx shadcn@latest add https://yoink-app.fly.dev/r/motion/rotating-words.json
Source
"use client";

import { useEffect, useLayoutEffect, useRef, useState, type CSSProperties } from "react";

const YK_EASE = "cubic-bezier(0.16, 1, 0.3, 1)";

const useYkLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;

function ykReducedMotion(): boolean {
  return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
}

const ykSrOnly: CSSProperties = { position: "absolute", width: 1, height: 1, padding: 0, margin: -1, overflow: "hidden", clip: "rect(0 0 0 0)", whiteSpace: "nowrap", border: 0 };

/** Swaps one word in a sentence for the next every few seconds, resizing smoothly. */
export function RotatingWords({
  words = ["designers", "developers", "founders"],
  interval = 2400,
  duration = 600,
  className,
  style,
}: {
  words?: string[];
  interval?: number;
  duration?: number;
  className?: string;
  style?: CSSProperties;
}) {
  const refs = useRef<(HTMLSpanElement | null)[]>([]);
  const [i, setI] = useState(0);
  const [width, setWidth] = useState<number | null>(null);
  useEffect(() => {
    if (ykReducedMotion() || words.length < 2) return;
    const id = setInterval(() => setI((n) => (n + 1) % words.length), interval);
    return () => clearInterval(id);
  }, [words.length, interval]);
  useYkLayoutEffect(() => {
    const w = refs.current[i]?.offsetWidth;
    if (w) setWidth(w);
  }, [i, words.join("|")]);
  const measured = width !== null;
  return (
    <span className={className} style={{ display: "inline-block", position: "relative", verticalAlign: "bottom", whiteSpace: "nowrap", ...style }}>
      <span style={ykSrOnly}>{words.join(", ")}</span>
      <span
        aria-hidden="true"
        style={{ display: "inline-block", position: "relative", width: measured ? width : undefined, transition: `width ${duration}ms ${YK_EASE}` }}
      >
        {/* keeps the line height (and the width before measuring) */}
        <span style={{ visibility: "hidden" }}>{measured ? " " : words[0]}</span>
        {words.map((w, n) => {
          const state = n === i ? 0 : n === (i - 1 + words.length) % words.length ? -1 : 1;
          return (
            <span
              key={w + n}
              ref={(el) => {
                refs.current[n] = el;
              }}
              style={{
                position: "absolute",
                left: 0,
                top: 0,
                opacity: state === 0 ? 1 : 0,
                transform: `translate3d(0, ${state * 0.6}em, 0)`,
                filter: state === 0 ? "none" : "blur(6px)",
                transition: `opacity ${duration}ms ${YK_EASE}, transform ${duration}ms ${YK_EASE}, filter ${duration}ms ${YK_EASE}`,
              }}
            >
              {w}
            </span>
          );
        })}
      </span>
    </span>
  );
}

Typewriter

Text effects

Text typed out character by character with a blinking caret.

<Typewriter phrases={["First phrase", "Second phrase"]} typeSpeed={55} deleteSpeed={30} pause={1600} loop caret className="" />
npx shadcn@latest add https://yoink-app.fly.dev/r/motion/typewriter.json
Source
"use client";

import { useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type RefObject } from "react";

const useYkLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;

function ykReducedMotion(): boolean {
  return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
}

const ykSrOnly: CSSProperties = { position: "absolute", width: 1, height: 1, padding: 0, margin: -1, overflow: "hidden", clip: "rect(0 0 0 0)", whiteSpace: "nowrap", border: 0 };

// "idle": untouched (visible) · "hidden": waiting below the fold · "shown": play the entrance.
// Content is only hidden once we know we can show it again (IntersectionObserver exists, motion allowed,
// and there is a box to watch), and a safety net reveals anything on screen that is still hidden.
type YkRevealState = "idle" | "hidden" | "shown";

function useYkReveal(ref: RefObject<Element | null>, once = true): YkRevealState {
  const [state, setState] = useState<YkRevealState>("idle");
  useYkLayoutEffect(() => {
    const el = ref.current;
    if (!el || ykReducedMotion() || typeof IntersectionObserver === "undefined") return;
    // watch the element's own box, or its children when it has none (display: contents)
    const boxes = () => (getComputedStyle(el).display === "contents" ? Array.from(el.children) : [el]);
    const onScreen = (t: Element) => {
      const r = t.getBoundingClientRect();
      return (r.width > 0 || r.height > 0) && r.bottom > 0 && r.right > 0 && r.top < window.innerHeight && r.left < window.innerWidth;
    };
    if (!boxes().some((t) => t.getBoundingClientRect().width > 0 || t.getBoundingClientRect().height > 0)) return; // e.g. hidden at mount: leave it visible
    let shown = false;
    const show = (v: boolean) => {
      if (v !== shown) (shown = v), setState(v ? "shown" : "hidden");
    };
    setState("hidden");
    const inView = new Set<Element>();
    const io = new IntersectionObserver((entries) => {
      for (const e of entries) {
        if (e.isIntersecting) inView.add(e.target);
        else inView.delete(e.target);
      }
      if (inView.size) {
        show(true);
        if (once) io.disconnect();
      } else if (!once) show(false);
    });
    const watched = new Set<Element>();
    const watch = () => boxes().forEach((t) => !watched.has(t) && (watched.add(t), io.observe(t)));
    watch();
    // safety net: styles that land after mount (display: contents) get watched too, and nothing
    // stays hidden for more than a moment while it is actually on screen
    const start = Date.now();
    const net = setInterval(() => {
      if (shown) return once && clearInterval(net);
      watch();
      if (Date.now() - start > 2400 && boxes().some(onScreen)) show(true);
    }, 600);
    return () => {
      io.disconnect();
      clearInterval(net);
    };
  }, [once]);
  return state;
}

const YK_CARET_CSS = `@keyframes yk-caret{50%{opacity:0}}@media (prefers-reduced-motion:reduce){[data-yk-caret]{animation:none!important}}`;

/** Types out phrases one character at a time, deletes them, and moves on to the next. */
export function Typewriter({
  phrases = ["Ship faster.", "Look sharper.", "Sleep better."],
  typeSpeed = 55,
  deleteSpeed = 30,
  pause = 1600,
  loop = true,
  caret = true,
  className,
  style,
}: {
  phrases?: string[];
  typeSpeed?: number;
  deleteSpeed?: number;
  pause?: number;
  loop?: boolean;
  caret?: boolean;
  className?: string;
  style?: CSSProperties;
}) {
  const ref = useRef<HTMLSpanElement>(null);
  const state = useYkReveal(ref);
  const [text, setText] = useState(phrases[0] ?? "");
  useYkLayoutEffect(() => {
    if (state === "hidden") setText("");
  }, [state]);
  useEffect(() => {
    if (state !== "shown" || !phrases.length) return;
    let p = 0, n = 0, deleting = false, timer: ReturnType<typeof setTimeout>;
    const tick = () => {
      const full = phrases[p];
      if (!deleting) {
        n++;
        setText(full.slice(0, n));
        if (n < full.length) return (timer = setTimeout(tick, typeSpeed));
        if (!loop && p === phrases.length - 1) return;
        deleting = true;
        return (timer = setTimeout(tick, pause));
      }
      n--;
      setText(full.slice(0, n));
      if (n > 0) return (timer = setTimeout(tick, deleteSpeed));
      deleting = false;
      p = (p + 1) % phrases.length;
      timer = setTimeout(tick, typeSpeed * 4);
    };
    timer = setTimeout(tick, typeSpeed * 4);
    return () => clearTimeout(timer);
  }, [state, phrases.join("|"), typeSpeed, deleteSpeed, pause, loop]);
  return (
    <span ref={ref} className={className} style={style}>
      <span style={ykSrOnly}>{phrases.join(" ")}</span>
      <span aria-hidden="true">
        {text}
        {caret && (
          <>
            <style>{YK_CARET_CSS}</style>
            <span
              data-yk-caret=""
              style={{ display: "inline-block", width: "0.08em", height: "1em", marginLeft: "0.06em", verticalAlign: "-0.12em", background: "currentColor", animation: "yk-caret 1s steps(1) infinite" }}
            />
          </>
        )}
      </span>
    </span>
  );
}

Spotlight

Hover effects

A soft glow that follows the pointer across a card.

<Spotlight color="color-mix(in oklab, currentColor 16%, transparent)" size={420} as="div" className="rounded-2xl border bg-card p-6">…</Spotlight>
npx shadcn@latest add https://yoink-app.fly.dev/r/motion/spotlight.json
Source
"use client";

import { useRef, type CSSProperties, type ElementType, type PointerEvent, type ReactNode } from "react";

function ykReducedMotion(): boolean {
  return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
}

/** A soft glow that follows the pointer across a card or section. */
export function Spotlight({
  children,
  color = "color-mix(in oklab, currentColor 16%, transparent)",
  size = 420,
  as = "div",
  className,
  style,
}: {
  children?: ReactNode;
  color?: string;
  size?: number;
  as?: ElementType;
  className?: string;
  style?: CSSProperties;
}) {
  const Tag = as;
  const ref = useRef<HTMLElement>(null);
  const glow = useRef<HTMLSpanElement>(null);
  const raf = useRef(0);
  const move = (e: PointerEvent) => {
    if (e.pointerType === "touch" || ykReducedMotion()) return;
    const el = ref.current, g = glow.current;
    if (!el || !g) return;
    const { clientX, clientY } = e;
    cancelAnimationFrame(raf.current);
    raf.current = requestAnimationFrame(() => {
      const r = el.getBoundingClientRect();
      g.style.background = `radial-gradient(${size}px circle at ${clientX - r.left}px ${clientY - r.top}px, ${color}, transparent 70%)`;
      g.style.opacity = "1";
    });
  };
  const leave = () => {
    cancelAnimationFrame(raf.current);
    if (glow.current) glow.current.style.opacity = "0";
  };
  return (
    <Tag ref={ref} onPointerMove={move} onPointerLeave={leave} className={className} style={{ position: "relative", isolation: "isolate", ...style }}>
      <span
        ref={glow}
        aria-hidden="true"
        style={{ position: "absolute", inset: 0, zIndex: -1, borderRadius: "inherit", pointerEvents: "none", opacity: 0, transition: "opacity 400ms ease" }}
      />
      {children}
    </Tag>
  );
}

Tilt

Hover effects

Cards that tilt in 3D toward the pointer, with optional glare.

<Tilt max={10} scale={1.02} perspective={900} glare={false} className="rounded-2xl">…</Tilt>
npx shadcn@latest add https://yoink-app.fly.dev/r/motion/tilt.json
Source
"use client";

import { useRef, type CSSProperties, type PointerEvent, type ReactNode } from "react";

const YK_EASE = "cubic-bezier(0.16, 1, 0.3, 1)";

function ykReducedMotion(): boolean {
  return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
}

/** Tilts a card in 3D toward the pointer, with an optional light glare. */
export function Tilt({
  children,
  max = 10,
  scale = 1.02,
  perspective = 900,
  glare = false,
  className,
  style,
}: {
  children?: ReactNode;
  max?: number;
  scale?: number;
  perspective?: number;
  glare?: boolean;
  className?: string;
  style?: CSSProperties;
}) {
  const ref = useRef<HTMLDivElement>(null);
  const card = useRef<HTMLDivElement>(null);
  const shine = useRef<HTMLSpanElement>(null);
  const raf = useRef(0);
  const move = (e: PointerEvent) => {
    if (e.pointerType === "touch" || ykReducedMotion()) return;
    const box = ref.current, el = card.current;
    if (!box || !el) return;
    const { clientX, clientY } = e;
    cancelAnimationFrame(raf.current);
    raf.current = requestAnimationFrame(() => {
      // measured on the untilted wrapper, so the tilt never feeds back into itself
      const r = box.getBoundingClientRect();
      const x = (clientX - r.left) / r.width, y = (clientY - r.top) / r.height;
      el.style.transition = "transform 120ms ease-out";
      el.style.transform = `rotateX(${(0.5 - y) * 2 * max}deg) rotateY(${(x - 0.5) * 2 * max}deg) scale(${scale})`;
      if (shine.current) {
        shine.current.style.opacity = "1";
        shine.current.style.background = `radial-gradient(circle at ${x * 100}% ${y * 100}%, color-mix(in srgb, white 35%, transparent), transparent 60%)`;
      }
    });
  };
  const leave = () => {
    cancelAnimationFrame(raf.current);
    const el = card.current;
    if (!el) return;
    el.style.transition = `transform 700ms ${YK_EASE}`;
    el.style.transform = "";
    if (shine.current) shine.current.style.opacity = "0";
  };
  return (
    <div ref={ref} onPointerMove={move} onPointerLeave={leave} style={{ perspective }}>
      <div ref={card} className={className} style={{ position: "relative", willChange: "transform", ...style }}>
        {children}
        {glare && (
          <span
            ref={shine}
            aria-hidden="true"
            style={{ position: "absolute", inset: 0, borderRadius: "inherit", pointerEvents: "none", opacity: 0, transition: "opacity 300ms ease", mixBlendMode: "soft-light" }}
          />
        )}
      </div>
    </div>
  );
}

Magnetic

Hover effects

Buttons that lean toward the pointer and spring back.

<Magnetic strength={0.3}><button>…</button></Magnetic>
npx shadcn@latest add https://yoink-app.fly.dev/r/motion/magnetic.json
Source
"use client";

import { useRef, type CSSProperties, type PointerEvent, type ReactNode } from "react";

function ykReducedMotion(): boolean {
  return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
}

/** Pulls its child (usually a button) toward the pointer, then springs back. */
export function Magnetic({
  children,
  strength = 0.3,
  className,
  style,
}: {
  children?: ReactNode;
  strength?: number;
  className?: string;
  style?: CSSProperties;
}) {
  const ref = useRef<HTMLSpanElement>(null);
  const inner = useRef<HTMLSpanElement>(null);
  const raf = useRef(0);
  const move = (e: PointerEvent) => {
    if (e.pointerType === "touch" || ykReducedMotion()) return;
    const box = ref.current, el = inner.current;
    if (!box || !el) return;
    const { clientX, clientY } = e;
    cancelAnimationFrame(raf.current);
    raf.current = requestAnimationFrame(() => {
      const r = box.getBoundingClientRect();
      const x = (clientX - (r.left + r.width / 2)) * strength, y = (clientY - (r.top + r.height / 2)) * strength;
      el.style.transition = "transform 150ms ease-out";
      el.style.transform = `translate3d(${x}px, ${y}px, 0)`;
    });
  };
  const leave = () => {
    cancelAnimationFrame(raf.current);
    const el = inner.current;
    if (!el) return;
    el.style.transition = "transform 650ms cubic-bezier(0.34, 1.56, 0.64, 1)";
    el.style.transform = "";
  };
  return (
    <span ref={ref} onPointerMove={move} onPointerLeave={leave} className={className} style={{ display: "inline-block", ...style }}>
      <span ref={inner} style={{ display: "inline-block" }}>
        {children}
      </span>
    </span>
  );
}

Aurora

Animated backgrounds

Slow-moving blurred colour light behind a section.

<Aurora colors={["var(--color-primary)", "var(--color-accent)"]} speed={1} blur={80} opacity={0.5} />  // first child of the section
npx shadcn@latest add https://yoink-app.fly.dev/r/motion/aurora.json
Source
"use client";

import { useEffect, useLayoutEffect, useRef, type CSSProperties } from "react";

const useYkLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;

// Background and overlay layers sit inside their parent: make sure it can hold them.
function ykPrepareParent(el: HTMLElement | null, isolate = false) {
  const p = el?.parentElement;
  if (!p) return;
  const cs = getComputedStyle(p);
  if (cs.position === "static") p.style.position = "relative";
  if (isolate && cs.isolation !== "isolate" && cs.zIndex === "auto") p.style.isolation = "isolate";
}

const YK_AURORA_CSS = `@keyframes yk-aurora-a{0%{transform:translate3d(-10%,-6%,0) scale(1)}50%{transform:translate3d(12%,8%,0) scale(1.18)}100%{transform:translate3d(-4%,12%,0) scale(0.95)}}
@keyframes yk-aurora-b{0%{transform:translate3d(8%,10%,0) scale(1.1)}50%{transform:translate3d(-14%,-4%,0) scale(0.9)}100%{transform:translate3d(6%,-10%,0) scale(1.15)}}
@keyframes yk-aurora-c{0%{transform:translate3d(0,0,0) scale(0.9) rotate(0deg)}50%{transform:translate3d(-8%,10%,0) scale(1.2) rotate(40deg)}100%{transform:translate3d(10%,-6%,0) scale(1) rotate(80deg)}}
@media (prefers-reduced-motion:reduce){[data-yk-aurora] *{animation:none!important}}`;

/** Slow-moving blurred colour blobs behind a section: drop it in as the first child. */
export function Aurora({
  colors = ["var(--color-primary, currentColor)", "var(--color-accent, currentColor)", "var(--color-ring, currentColor)"],
  speed = 1,
  blur = 80,
  opacity = 0.5,
  className,
  style,
}: {
  colors?: string[];
  speed?: number;
  blur?: number;
  opacity?: number;
  className?: string;
  style?: CSSProperties;
}) {
  const ref = useRef<HTMLDivElement>(null);
  useYkLayoutEffect(() => ykPrepareParent(ref.current, true), []);
  const spots = [
    { left: "-10%", top: "-20%", size: "60%", anim: "a", dur: 18 },
    { left: "45%", top: "-10%", size: "55%", anim: "b", dur: 22 },
    { left: "15%", top: "35%", size: "65%", anim: "c", dur: 26 },
    { left: "60%", top: "40%", size: "45%", anim: "a", dur: 20 },
  ];
  return (
    <div
      ref={ref}
      aria-hidden="true"
      data-yk-aurora=""
      className={className}
      style={{ position: "absolute", inset: 0, zIndex: -1, overflow: "hidden", pointerEvents: "none", borderRadius: "inherit", opacity, ...style }}
    >
      <style>{YK_AURORA_CSS}</style>
      {spots.map((s, i) => (
        <div
          key={i}
          style={{
            position: "absolute",
            left: s.left,
            top: s.top,
            width: s.size,
            aspectRatio: "1",
            borderRadius: "50%",
            background: `radial-gradient(circle at center, ${colors[i % colors.length]}, transparent 68%)`,
            filter: `blur(${blur}px)`,
            animation: `yk-aurora-${s.anim} ${s.dur / Math.max(speed, 0.05)}s ease-in-out ${-i * 3}s infinite alternate`,
          }}
        />
      ))}
    </div>
  );
}

Grid pattern

Animated backgrounds

A faint grid or dot texture that fades out at the edges.

<GridPattern variant="grid" size={32} color="color-mix(in oklab, currentColor 12%, transparent)" fade="radial" shimmer={false} />  // variant: grid|dots; fade: radial|top|bottom|none
npx shadcn@latest add https://yoink-app.fly.dev/r/motion/grid-pattern.json
Source
"use client";

import { useEffect, useLayoutEffect, useRef, type CSSProperties } from "react";

const useYkLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;

// Background and overlay layers sit inside their parent: make sure it can hold them.
function ykPrepareParent(el: HTMLElement | null, isolate = false) {
  const p = el?.parentElement;
  if (!p) return;
  const cs = getComputedStyle(p);
  if (cs.position === "static") p.style.position = "relative";
  if (isolate && cs.isolation !== "isolate" && cs.zIndex === "auto") p.style.isolation = "isolate";
}

const YK_GRID_CSS = `@keyframes yk-grid-sweep{from{-webkit-mask-position:150% 0;mask-position:150% 0}to{-webkit-mask-position:-50% 0;mask-position:-50% 0}}
@media (prefers-reduced-motion:reduce){[data-yk-sweep]{display:none}}`;

/** A faint grid or dot pattern behind a section, fading out at the edges. */
export function GridPattern({
  variant = "grid",
  size = 32,
  color = "color-mix(in oklab, currentColor 12%, transparent)",
  fade = "radial",
  shimmer = false,
  className,
  style,
}: {
  variant?: "grid" | "dots";
  size?: number;
  color?: string;
  fade?: "radial" | "top" | "bottom" | "none";
  shimmer?: boolean;
  className?: string;
  style?: CSSProperties;
}) {
  const ref = useRef<HTMLDivElement>(null);
  useYkLayoutEffect(() => ykPrepareParent(ref.current, true), []);
  const paint = (c: string) =>
    variant === "dots"
      ? { backgroundImage: `radial-gradient(circle at center, ${c} 1.2px, transparent 1.6px)`, backgroundSize: `${size}px ${size}px` }
      : { backgroundImage: `linear-gradient(to right, ${c} 1px, transparent 1px), linear-gradient(to bottom, ${c} 1px, transparent 1px)`, backgroundSize: `${size}px ${size}px` };
  const mask = {
    radial: "radial-gradient(ellipse at center, black 30%, transparent 75%)",
    top: "linear-gradient(to bottom, black, transparent 85%)",
    bottom: "linear-gradient(to top, black, transparent 85%)",
    none: undefined,
  }[fade];
  const sweep = "linear-gradient(110deg, transparent 40%, black 50%, transparent 60%)";
  return (
    <div
      ref={ref}
      aria-hidden="true"
      data-yk-grid=""
      className={className}
      style={{ position: "absolute", inset: 0, zIndex: -1, pointerEvents: "none", maskImage: mask, WebkitMaskImage: mask, ...style }}
    >
      <div style={{ position: "absolute", inset: 0, ...paint(color) }} />
      {shimmer && (
        <>
          <style>{YK_GRID_CSS}</style>
          <div
            data-yk-sweep=""
            style={{
              position: "absolute",
              inset: 0,
              ...paint(`color-mix(in oklab, ${color} 100%, currentColor 30%)`),
              maskImage: sweep,
              WebkitMaskImage: sweep,
              maskSize: "250% 100%",
              WebkitMaskSize: "250% 100%",
              animation: "yk-grid-sweep 7s ease-in-out infinite",
            }}
          />
        </>
      )}
    </div>
  );
}

Border beam

Animated graphics

A small light that travels around a card's border.

<BorderBeam duration={6} width={1.5} length={80} color="var(--color-primary, currentColor)" />  // inside a rounded card
npx shadcn@latest add https://yoink-app.fly.dev/r/motion/border-beam.json
Source
"use client";

import { useEffect, useLayoutEffect, useRef, useState, type CSSProperties } from "react";

const useYkLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;

// Background and overlay layers sit inside their parent: make sure it can hold them.
function ykPrepareParent(el: HTMLElement | null, isolate = false) {
  const p = el?.parentElement;
  if (!p) return;
  const cs = getComputedStyle(p);
  if (cs.position === "static") p.style.position = "relative";
  if (isolate && cs.isolation !== "isolate" && cs.zIndex === "auto") p.style.isolation = "isolate";
}

const YK_BEAM_CSS = `@keyframes yk-beam{to{transform:translate(-50%,-50%) rotate(360deg)}}
@media (prefers-reduced-motion:reduce){[data-yk-beam] *{animation:none!important}}`;

/** A small light that travels around the border of its parent card. */
export function BorderBeam({
  duration = 6,
  width = 1.5,
  length = 80,
  color = "var(--color-primary, currentColor)",
  className,
  style,
}: {
  /** seconds per lap */
  duration?: number;
  width?: number;
  /** length of the beam, in degrees of the lap */
  length?: number;
  color?: string;
  className?: string;
  style?: CSSProperties;
}) {
  const ref = useRef<HTMLDivElement>(null);
  const [box, setBox] = useState({ span: 0, edge: 0 });
  useYkLayoutEffect(() => {
    ykPrepareParent(ref.current);
    const p = ref.current?.parentElement;
    if (!p) return;
    // sit right on top of the parent's own border
    const measure = () => setBox({ span: Math.ceil(Math.hypot(p.offsetWidth, p.offsetHeight)), edge: parseFloat(getComputedStyle(p).borderTopWidth) || 0 });
    measure();
    const ro = typeof ResizeObserver !== "undefined" ? new ResizeObserver(measure) : null;
    ro?.observe(p);
    return () => ro?.disconnect();
  }, []);
  // a ring as wide as `width`: the inner (content-box) layer is cut out of the outer one
  const ring = "linear-gradient(black, black), linear-gradient(black, black)";
  return (
    <div
      ref={ref}
      aria-hidden="true"
      data-yk-beam=""
      className={className}
      style={{
        position: "absolute",
        inset: -box.edge,
        padding: width,
        borderRadius: "inherit",
        pointerEvents: "none",
        overflow: "hidden",
        maskImage: ring,
        WebkitMaskImage: ring,
        maskClip: "content-box, border-box",
        WebkitMaskClip: "content-box, border-box",
        maskComposite: "exclude",
        WebkitMaskComposite: "xor",
        ...style,
      }}
    >
      <style>{YK_BEAM_CSS}</style>
      {box.span > 0 && (
        <div
          style={{
            position: "absolute",
            left: "50%",
            top: "50%",
            width: box.span,
            height: box.span,
            transform: "translate(-50%,-50%)",
            background: `conic-gradient(from 0deg, transparent 0deg, transparent ${360 - length}deg, ${color} 360deg)`,
            animation: `yk-beam ${duration}s linear infinite`,
          }}
        />
      )}
    </div>
  );
}

Shimmer text

Text effects

A band of light sweeping across text, badges and button labels.

<ShimmerText duration={2.8} className="">Text</ShimmerText>
npx shadcn@latest add https://yoink-app.fly.dev/r/motion/shimmer-text.json
Source
"use client";

import { type CSSProperties, type ReactNode } from "react";

const YK_SHIMMER_CSS = `@keyframes yk-shimmer{0%{background-position:100% 0}60%,100%{background-position:0% 0}}
@media (prefers-reduced-motion:reduce){[data-yk-shimmer]{animation:none!important;background:none!important;-webkit-text-fill-color:currentColor!important}}`;

/** A band of light that sweeps across text: headlines, badges, button labels. */
export function ShimmerText({
  children = "Now in early access",
  duration = 2.8,
  className,
  style,
}: {
  children?: ReactNode;
  /** seconds per sweep (including a short rest) */
  duration?: number;
  className?: string;
  style?: CSSProperties;
}) {
  // dimmed text with a full-strength band passing over it; follows the text colour in any theme
  const dim = "color-mix(in oklab, currentColor 55%, transparent)";
  return (
    <span className={className} style={style}>
      <style>{YK_SHIMMER_CSS}</style>
      <span
        data-yk-shimmer=""
        style={{
          backgroundImage: `linear-gradient(100deg, ${dim} 0%, ${dim} 40%, currentColor 50%, ${dim} 60%, ${dim} 100%)`,
          backgroundSize: "250% 100%",
          backgroundClip: "text",
          WebkitBackgroundClip: "text",
          WebkitTextFillColor: "transparent",
          animation: `yk-shimmer ${duration}s ease-in-out infinite`,
        }}
      >
        {children}
      </span>
    </span>
  );
}

Draw SVG

Animated graphics

Lines, charts and icons that draw themselves in.

<DrawSvg duration={1600} stagger={120} delay={0} fillAfter className=""><svg>…</svg></DrawSvg>
npx shadcn@latest add https://yoink-app.fly.dev/r/motion/draw-svg.json
Source
"use client";

import { useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type ReactNode, type RefObject } from "react";

const YK_EASE = "cubic-bezier(0.16, 1, 0.3, 1)";

const useYkLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;

function ykReducedMotion(): boolean {
  return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
}

// "idle": untouched (visible) · "hidden": waiting below the fold · "shown": play the entrance.
// Content is only hidden once we know we can show it again (IntersectionObserver exists, motion allowed,
// and there is a box to watch), and a safety net reveals anything on screen that is still hidden.
type YkRevealState = "idle" | "hidden" | "shown";

function useYkReveal(ref: RefObject<Element | null>, once = true): YkRevealState {
  const [state, setState] = useState<YkRevealState>("idle");
  useYkLayoutEffect(() => {
    const el = ref.current;
    if (!el || ykReducedMotion() || typeof IntersectionObserver === "undefined") return;
    // watch the element's own box, or its children when it has none (display: contents)
    const boxes = () => (getComputedStyle(el).display === "contents" ? Array.from(el.children) : [el]);
    const onScreen = (t: Element) => {
      const r = t.getBoundingClientRect();
      return (r.width > 0 || r.height > 0) && r.bottom > 0 && r.right > 0 && r.top < window.innerHeight && r.left < window.innerWidth;
    };
    if (!boxes().some((t) => t.getBoundingClientRect().width > 0 || t.getBoundingClientRect().height > 0)) return; // e.g. hidden at mount: leave it visible
    let shown = false;
    const show = (v: boolean) => {
      if (v !== shown) (shown = v), setState(v ? "shown" : "hidden");
    };
    setState("hidden");
    const inView = new Set<Element>();
    const io = new IntersectionObserver((entries) => {
      for (const e of entries) {
        if (e.isIntersecting) inView.add(e.target);
        else inView.delete(e.target);
      }
      if (inView.size) {
        show(true);
        if (once) io.disconnect();
      } else if (!once) show(false);
    });
    const watched = new Set<Element>();
    const watch = () => boxes().forEach((t) => !watched.has(t) && (watched.add(t), io.observe(t)));
    watch();
    // safety net: styles that land after mount (display: contents) get watched too, and nothing
    // stays hidden for more than a moment while it is actually on screen
    const start = Date.now();
    const net = setInterval(() => {
      if (shown) return once && clearInterval(net);
      watch();
      if (Date.now() - start > 2400 && boxes().some(onScreen)) show(true);
    }, 600);
    return () => {
      io.disconnect();
      clearInterval(net);
    };
  }, [once]);
  return state;
}

/** Draws the strokes of an inline SVG (lines, icons, diagrams) when it scrolls into view. */
export function DrawSvg({
  children,
  duration = 1600,
  stagger = 120,
  delay = 0,
  fillAfter = true,
  className,
  style,
}: {
  children?: ReactNode;
  duration?: number;
  stagger?: number;
  delay?: number;
  /** fade fills in once their outline is drawn */
  fillAfter?: boolean;
  className?: string;
  style?: CSSProperties;
}) {
  const ref = useRef<HTMLDivElement>(null);
  const state = useYkReveal(ref);
  useYkLayoutEffect(() => {
    if (state === "idle" || !ref.current) return;
    const shapes = Array.from(ref.current.querySelectorAll("path, line, polyline, polygon, circle, ellipse, rect")) as SVGGeometryElement[];
    shapes.forEach((el, i) => {
      if (typeof el.getTotalLength !== "function") return;
      const len = Math.ceil(el.getTotalLength() || 0);
      if (!len) return;
      if (state === "hidden") {
        Object.assign(el.style, { transition: "none", strokeDasharray: `${len}`, strokeDashoffset: `${len}`, fillOpacity: fillAfter ? "0" : "" });
        return;
      }
      const d = delay + i * stagger;
      Object.assign(el.style, {
        transition: `stroke-dashoffset ${duration}ms ${YK_EASE} ${d}ms, fill-opacity 600ms ease ${d + duration * 0.6}ms`,
        strokeDashoffset: "0",
        fillOpacity: "",
      });
    });
  }, [state]);
  return (
    <div ref={ref} className={className} style={style}>
      {children}
    </div>
  );
}

Build sequence

Animated graphics

A little cursor assembles the section, block by block.

<BuildSequence step={900} startDelay={400} cursorLabel="Placing" labels={["Header", "Chart"]} loop={false} color="var(--color-primary, currentColor)" className="grid gap-3">{blocks}</BuildSequence>
npx shadcn@latest add https://yoink-app.fly.dev/r/motion/build-sequence.json
Source
"use client";

import { useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type ElementType, type ReactNode, type RefObject } from "react";

const useYkLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;

function ykReducedMotion(): boolean {
  return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
}

// "idle": untouched (visible) · "hidden": waiting below the fold · "shown": play the entrance.
// Content is only hidden once we know we can show it again (IntersectionObserver exists, motion allowed,
// and there is a box to watch), and a safety net reveals anything on screen that is still hidden.
type YkRevealState = "idle" | "hidden" | "shown";

function useYkReveal(ref: RefObject<Element | null>, once = true): YkRevealState {
  const [state, setState] = useState<YkRevealState>("idle");
  useYkLayoutEffect(() => {
    const el = ref.current;
    if (!el || ykReducedMotion() || typeof IntersectionObserver === "undefined") return;
    // watch the element's own box, or its children when it has none (display: contents)
    const boxes = () => (getComputedStyle(el).display === "contents" ? Array.from(el.children) : [el]);
    const onScreen = (t: Element) => {
      const r = t.getBoundingClientRect();
      return (r.width > 0 || r.height > 0) && r.bottom > 0 && r.right > 0 && r.top < window.innerHeight && r.left < window.innerWidth;
    };
    if (!boxes().some((t) => t.getBoundingClientRect().width > 0 || t.getBoundingClientRect().height > 0)) return; // e.g. hidden at mount: leave it visible
    let shown = false;
    const show = (v: boolean) => {
      if (v !== shown) (shown = v), setState(v ? "shown" : "hidden");
    };
    setState("hidden");
    const inView = new Set<Element>();
    const io = new IntersectionObserver((entries) => {
      for (const e of entries) {
        if (e.isIntersecting) inView.add(e.target);
        else inView.delete(e.target);
      }
      if (inView.size) {
        show(true);
        if (once) io.disconnect();
      } else if (!once) show(false);
    });
    const watched = new Set<Element>();
    const watch = () => boxes().forEach((t) => !watched.has(t) && (watched.add(t), io.observe(t)));
    watch();
    // safety net: styles that land after mount (display: contents) get watched too, and nothing
    // stays hidden for more than a moment while it is actually on screen
    const start = Date.now();
    const net = setInterval(() => {
      if (shown) return once && clearInterval(net);
      watch();
      if (Date.now() - start > 2400 && boxes().some(onScreen)) show(true);
    }, 600);
    return () => {
      io.disconnect();
      clearInterval(net);
    };
  }, [once]);
  return state;
}

/**
 * A little cursor assembles the section: it glides to each child in turn, sketches its outline,
 * and drops it into place. Wrap any grid or stack; every direct child is one step.
 */
export function BuildSequence({
  children,
  step = 900,
  startDelay = 400,
  cursorLabel = "Placing",
  labels,
  loop = false,
  color = "var(--color-primary, currentColor)",
  as = "div",
  className,
  style,
}: {
  children?: ReactNode;
  /** ms per child */
  step?: number;
  startDelay?: number;
  cursorLabel?: string;
  /** optional label per step, e.g. ["Heading", "Copy", "Button"] */
  labels?: string[];
  loop?: boolean;
  color?: string;
  as?: ElementType;
  className?: string;
  style?: CSSProperties;
}) {
  const Tag = as;
  const ref = useRef<HTMLElement>(null);
  const cursor = useRef<HTMLSpanElement>(null);
  const pill = useRef<HTMLSpanElement>(null);
  const ghost = useRef<HTMLSpanElement>(null);
  const state = useYkReveal(ref);
  const items = () => Array.from(ref.current?.children ?? []).filter((el) => !el.hasAttribute("data-yk-bs")) as HTMLElement[];
  const hide = (el: HTMLElement, fade = 0) =>
    Object.assign(el.style, { transition: fade ? `opacity ${fade}ms ease, transform ${fade}ms ease` : "none", opacity: "0", transform: "translate3d(0, 10px, 0) scale(0.97)" });

  useYkLayoutEffect(() => {
    if (state === "hidden") items().forEach((el) => hide(el));
  }, [state]);

  useEffect(() => {
    const box = ref.current, cur = cursor.current, gh = ghost.current;
    if (state !== "shown" || !box || !cur || !gh) return;
    let alive = true;
    const timers: ReturnType<typeof setTimeout>[] = [];
    const wait = (ms: number) => new Promise<void>((r) => timers.push(setTimeout(r, ms)));
    const move = Math.min(650, step * 0.6);
    const rectOf = (el: HTMLElement) => {
      if (el.offsetParent === box) return { x: el.offsetLeft, y: el.offsetTop, w: el.offsetWidth, h: el.offsetHeight };
      const a = el.getBoundingClientRect(), b = box.getBoundingClientRect();
      return { x: a.left - b.left - box.clientLeft, y: a.top - b.top - box.clientTop, w: a.width, h: a.height };
    };
    const goTo = (x: number, y: number, ms: number) => {
      cur.style.transition = `transform ${ms}ms cubic-bezier(0.45, 0, 0.2, 1), opacity 300ms ease`;
      cur.style.transform = `translate3d(${Math.max(0, Math.min(x, box.clientWidth - 140))}px, ${y}px, 0)`;
    };
    const run = async () => {
      const list = items();
      // lets tests and screenshots wait for the build: "playing" → "done" ("loop" never finishes)
      if (!loop) box.dataset.ykSequence = "playing";
      await wait(startDelay);
      goTo(box.clientWidth * 0.75, box.clientHeight * 0.85, 0);
      cur.style.opacity = "1";
      for (let i = 0; i < list.length && alive; i++) {
        const el = list[i], r = rectOf(el);
        if (pill.current) pill.current.textContent = labels?.[i] ?? cursorLabel;
        goTo(r.x + Math.min(r.w * 0.3, 120), r.y + Math.min(r.h * 0.4, 48), move);
        // the sketch outline takes the block's own shape
        Object.assign(gh.style, { left: `${r.x}px`, top: `${r.y}px`, width: `${r.w}px`, height: `${r.h}px`, borderRadius: getComputedStyle(el).borderRadius || "12px", opacity: "0", transition: "opacity 250ms ease" });
        await wait(move * 0.55);
        gh.style.opacity = "1";
        await wait(move * 0.45);
        if (!alive) return;
        cur.firstElementChild?.animate?.([{ transform: "scale(1)" }, { transform: "scale(0.82)" }, { transform: "scale(1)" }], { duration: 240, easing: "ease-out" });
        Object.assign(el.style, { transition: `opacity 450ms ease, transform 650ms cubic-bezier(0.34, 1.56, 0.64, 1)`, opacity: "", transform: "" });
        await wait(220);
        gh.style.opacity = "0";
        await wait(Math.max(0, step - move - 220));
      }
      if (!alive) return;
      cur.style.opacity = "0";
      await wait(700);
      list.forEach((el) => (el.style.transition = ""));
      if (!loop) box.dataset.ykSequence = "done";
      if (loop && alive) {
        await wait(2400);
        list.forEach((el) => hide(el, 400));
        await wait(600);
        if (alive) run();
      }
    };
    run();
    return () => {
      alive = false;
      timers.forEach(clearTimeout);
      if (!loop) box.dataset.ykSequence = "done";
      items().forEach((el) => Object.assign(el.style, { transition: "", opacity: "", transform: "" }));
    };
  }, [state]);

  return (
    <Tag ref={ref} data-yk-sequence={loop ? "loop" : undefined} className={className} style={{ position: "relative", ...style }}>
      {children}
      <span
        ref={ghost}
        data-yk-bs=""
        aria-hidden="true"
        style={{ position: "absolute", opacity: 0, pointerEvents: "none", borderRadius: 12, border: `1.5px dashed color-mix(in oklab, ${color} 70%, transparent)` }}
      />
      <span
        ref={cursor}
        data-yk-bs=""
        aria-hidden="true"
        style={{ position: "absolute", left: 0, top: 0, zIndex: 10, display: "flex", alignItems: "flex-start", opacity: 0, pointerEvents: "none" }}
      >
        <svg width="18" height="22" viewBox="0 0 16 20" style={{ fill: color, stroke: "Canvas", strokeWidth: 1.2, transformOrigin: "2px 2px", overflow: "visible" }}>
          <path d="M1.5 1.5 L1.5 16 L5.4 12.4 L8.2 18.4 L10.9 17.2 L8.2 11.4 L13.6 11.4 Z" />
        </svg>
        <span
          ref={pill}
          style={{
            marginTop: 17,
            marginLeft: 2,
            padding: "3px 9px",
            borderRadius: 999,
            fontSize: 11,
            fontWeight: 500,
            lineHeight: 1.4,
            whiteSpace: "nowrap",
            background: color,
            color: "var(--color-primary-foreground, Canvas)",
            boxShadow: `0 6px 16px -6px color-mix(in oklab, ${color} 60%, transparent)`,
          }}
        >
          {cursorLabel}
        </span>
      </span>
    </Tag>
  );
}

Image reveal

Scroll reveals

Photos that wipe into view with a slight zoom settle.

<ImageReveal src="…" alt="…" direction="up" duration={1200} delay={0} className="aspect-[4/3] rounded-2xl" imgClassName="" />  // direction: up|down|left|right
npx shadcn@latest add https://yoink-app.fly.dev/r/motion/image-reveal.json
Source
"use client";

import { useEffect, useLayoutEffect, useRef, useState, type CSSProperties, type RefObject } from "react";

const YK_EASE = "cubic-bezier(0.16, 1, 0.3, 1)";

const useYkLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;

function ykReducedMotion(): boolean {
  return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
}

// "idle": untouched (visible) · "hidden": waiting below the fold · "shown": play the entrance.
// Content is only hidden once we know we can show it again (IntersectionObserver exists, motion allowed,
// and there is a box to watch), and a safety net reveals anything on screen that is still hidden.
type YkRevealState = "idle" | "hidden" | "shown";

function useYkReveal(ref: RefObject<Element | null>, once = true): YkRevealState {
  const [state, setState] = useState<YkRevealState>("idle");
  useYkLayoutEffect(() => {
    const el = ref.current;
    if (!el || ykReducedMotion() || typeof IntersectionObserver === "undefined") return;
    // watch the element's own box, or its children when it has none (display: contents)
    const boxes = () => (getComputedStyle(el).display === "contents" ? Array.from(el.children) : [el]);
    const onScreen = (t: Element) => {
      const r = t.getBoundingClientRect();
      return (r.width > 0 || r.height > 0) && r.bottom > 0 && r.right > 0 && r.top < window.innerHeight && r.left < window.innerWidth;
    };
    if (!boxes().some((t) => t.getBoundingClientRect().width > 0 || t.getBoundingClientRect().height > 0)) return; // e.g. hidden at mount: leave it visible
    let shown = false;
    const show = (v: boolean) => {
      if (v !== shown) (shown = v), setState(v ? "shown" : "hidden");
    };
    setState("hidden");
    const inView = new Set<Element>();
    const io = new IntersectionObserver((entries) => {
      for (const e of entries) {
        if (e.isIntersecting) inView.add(e.target);
        else inView.delete(e.target);
      }
      if (inView.size) {
        show(true);
        if (once) io.disconnect();
      } else if (!once) show(false);
    });
    const watched = new Set<Element>();
    const watch = () => boxes().forEach((t) => !watched.has(t) && (watched.add(t), io.observe(t)));
    watch();
    // safety net: styles that land after mount (display: contents) get watched too, and nothing
    // stays hidden for more than a moment while it is actually on screen
    const start = Date.now();
    const net = setInterval(() => {
      if (shown) return once && clearInterval(net);
      watch();
      if (Date.now() - start > 2400 && boxes().some(onScreen)) show(true);
    }, 600);
    return () => {
      io.disconnect();
      clearInterval(net);
    };
  }, [once]);
  return state;
}

/** An image that wipes into view (with a slight zoom settle) as it scrolls in. */
export function ImageReveal({
  src = "https://yoink-app.fly.dev/stock/landscape-1.jpg",
  alt = "",
  direction = "up",
  duration = 1200,
  delay = 0,
  className,
  imgClassName,
  style,
}: {
  src?: string;
  alt?: string;
  direction?: "up" | "down" | "left" | "right";
  duration?: number;
  delay?: number;
  /** sizing/rounding for the frame, e.g. "aspect-[4/3] rounded-2xl" */
  className?: string;
  imgClassName?: string;
  style?: CSSProperties;
}) {
  const ref = useRef<HTMLDivElement>(null);
  const state = useYkReveal(ref);
  const hidden = state === "hidden";
  const clip = { up: "inset(100% 0 0 0)", down: "inset(0 0 100% 0)", left: "inset(0 0 0 100%)", right: "inset(0 100% 0 0)" }[direction];
  const t = `${duration}ms ${YK_EASE} ${delay}ms`;
  return (
    <div
      ref={ref}
      className={className}
      style={{
        overflow: "hidden",
        ...style,
        ...(hidden && { clipPath: clip }),
        ...(state === "shown" && { clipPath: "inset(0 0 0 0)", transition: `clip-path ${t}` }),
      }}
    >
      <img
        src={src}
        alt={alt}
        loading="lazy"
        decoding="async"
        className={imgClassName}
        style={{
          display: "block",
          width: "100%",
          height: "100%",
          objectFit: "cover",
          ...(hidden && { transform: "scale(1.15)" }),
          ...(state === "shown" && { transition: `transform ${duration * 1.4}ms ${YK_EASE} ${delay}ms` }),
        }}
      />
    </div>
  );
}

Ken Burns

Animated backgrounds

A slow zoom and pan on a still photo.

<KenBurns src="…" alt="" duration={24} zoom={1.18} pan="left" className="absolute inset-0 -z-10" />  // pan: left|right|up|down
npx shadcn@latest add https://yoink-app.fly.dev/r/motion/ken-burns.json
Source
"use client";

import { type CSSProperties } from "react";

const YK_KENBURNS_CSS = `@keyframes yk-kenburns{from{transform:scale(1.04) translate3d(0,0,0)}to{transform:scale(var(--yk-zoom)) translate3d(var(--yk-pan-x),var(--yk-pan-y),0)}}
@media (prefers-reduced-motion:reduce){[data-yk-kenburns]{animation:none!important}}`;

/** A slow zoom-and-pan on a still photo: a calm stand-in for a background video. */
export function KenBurns({
  src = "https://yoink-app.fly.dev/stock/landscape-1.jpg",
  alt = "",
  duration = 24,
  zoom = 1.18,
  pan = "left",
  className,
  style,
}: {
  src?: string;
  alt?: string;
  /** seconds for one drift (it then drifts back) */
  duration?: number;
  zoom?: number;
  pan?: "left" | "right" | "up" | "down";
  className?: string;
  style?: CSSProperties;
}) {
  const [x, y] = { left: ["-3%", "-1%"], right: ["3%", "1%"], up: ["0%", "-3%"], down: ["0%", "3%"] }[pan];
  return (
    <div className={className} style={{ overflow: "hidden", ...style }}>
      <style>{YK_KENBURNS_CSS}</style>
      <img
        src={src}
        alt={alt}
        decoding="async"
        data-yk-kenburns=""
        style={{
          display: "block",
          width: "100%",
          height: "100%",
          objectFit: "cover",
          transform: "scale(1.04)",
          animation: `yk-kenburns ${duration}s ease-in-out infinite alternate`,
          ...({ "--yk-zoom": zoom, "--yk-pan-x": x, "--yk-pan-y": y } as CSSProperties),
        }}
      />
    </div>
  );
}

Parallax

Scroll reveals

Layers that move at their own speed as you scroll.

<Parallax speed={0.15} className="">…</Parallax>  // negative speed moves ahead
npx shadcn@latest add https://yoink-app.fly.dev/r/motion/parallax.json
Source
"use client";

import { useEffect, useRef, type CSSProperties, type ReactNode } from "react";

function ykReducedMotion(): boolean {
  return typeof window !== "undefined" && !!window.matchMedia?.("(prefers-reduced-motion: reduce)").matches;
}

/** Moves its content a little slower (or faster) than the page as you scroll. */
export function Parallax({
  children,
  speed = 0.15,
  className,
  style,
}: {
  children?: ReactNode;
  /** 0 = scrolls normally; 0.2 = lags behind by 20%; negative values move ahead */
  speed?: number;
  className?: string;
  style?: CSSProperties;
}) {
  const ref = useRef<HTMLDivElement>(null);
  const inner = useRef<HTMLDivElement>(null);
  useEffect(() => {
    const box = ref.current, el = inner.current;
    if (!box || !el || ykReducedMotion()) return;
    let raf = 0, visible = true;
    const update = () => {
      raf = 0;
      const r = box.getBoundingClientRect();
      const offset = r.top + r.height / 2 - window.innerHeight / 2;
      el.style.transform = `translate3d(0, ${(-offset * speed).toFixed(1)}px, 0)`;
    };
    const onScroll = () => {
      if (visible && !raf) raf = requestAnimationFrame(update);
    };
    const io = typeof IntersectionObserver !== "undefined" ? new IntersectionObserver(([e]) => (visible = e.isIntersecting)) : null;
    io?.observe(box);
    // re-measure when the page's layout settles (fonts, images, late CSS)
    const ro = typeof ResizeObserver !== "undefined" ? new ResizeObserver(() => (raf ||= requestAnimationFrame(update))) : null;
    ro?.observe(document.documentElement);
    update();
    window.addEventListener("scroll", onScroll, { passive: true });
    window.addEventListener("resize", onScroll);
    return () => {
      cancelAnimationFrame(raf);
      io?.disconnect();
      ro?.disconnect();
      window.removeEventListener("scroll", onScroll);
      window.removeEventListener("resize", onScroll);
    };
  }, [speed]);
  return (
    <div ref={ref} className={className} style={style}>
      <div ref={inner} style={{ willChange: "transform" }}>
        {children}
      </div>
    </div>
  );
}

Progressive blur

Animated backgrounds

Content blurs out gradually toward one edge.

<ProgressiveBlur side="bottom" size="35%" blur={12} layers={6} />  // inside the element whose edge it blurs
npx shadcn@latest add https://yoink-app.fly.dev/r/motion/progressive-blur.json
Source
"use client";

import { useEffect, useLayoutEffect, useRef, type CSSProperties } from "react";

const useYkLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;

// Background and overlay layers sit inside their parent: make sure it can hold them.
function ykPrepareParent(el: HTMLElement | null, isolate = false) {
  const p = el?.parentElement;
  if (!p) return;
  const cs = getComputedStyle(p);
  if (cs.position === "static") p.style.position = "relative";
  if (isolate && cs.isolation !== "isolate" && cs.zIndex === "auto") p.style.isolation = "isolate";
}

/** Content gently blurs out toward one edge, like frosted glass that thickens. */
export function ProgressiveBlur({
  side = "bottom",
  size = "35%",
  blur = 12,
  layers = 6,
  className,
  style,
}: {
  side?: "top" | "bottom" | "left" | "right";
  size?: string | number;
  blur?: number;
  layers?: number;
  className?: string;
  style?: CSSProperties;
}) {
  const ref = useRef<HTMLDivElement>(null);
  useYkLayoutEffect(() => ykPrepareParent(ref.current), []);
  const vertical = side === "top" || side === "bottom";
  const toward = { top: "to top", bottom: "to bottom", left: "to left", right: "to right" }[side];
  const step = 100 / layers;
  return (
    <div
      ref={ref}
      aria-hidden="true"
      className={className}
      style={{ position: "absolute", [side]: 0, ...(vertical ? { left: 0, right: 0, height: size } : { top: 0, bottom: 0, width: size }), pointerEvents: "none", ...style }}
    >
      {Array.from({ length: layers }, (_, i) => {
        // each layer blurs twice as much as the last and only covers its own band
        const tail = i + 3 <= layers ? `black ${(i + 2) * step}%, transparent ${(i + 3) * step}%` : "black 100%";
        const mask = `linear-gradient(${toward}, transparent ${i * step}%, black ${(i + 1) * step}%, ${tail})`;
        const b = `blur(${(blur / 2 ** (layers - 1 - i)).toFixed(2)}px)`;
        return <div key={i} style={{ position: "absolute", inset: 0, backdropFilter: b, WebkitBackdropFilter: b, maskImage: mask, WebkitMaskImage: mask }} />;
      })}
    </div>
  );
}

Grain

Animated backgrounds

A film-grain texture that makes flat colour feel printed.

<Grain opacity={0.12} blend="overlay" animated={false} />  // inside the element it textures
npx shadcn@latest add https://yoink-app.fly.dev/r/motion/grain.json
Source
"use client";

import { useEffect, useLayoutEffect, useRef, type CSSProperties } from "react";

const useYkLayoutEffect = typeof window === "undefined" ? useEffect : useLayoutEffect;

// Background and overlay layers sit inside their parent: make sure it can hold them.
function ykPrepareParent(el: HTMLElement | null, isolate = false) {
  const p = el?.parentElement;
  if (!p) return;
  const cs = getComputedStyle(p);
  if (cs.position === "static") p.style.position = "relative";
  if (isolate && cs.isolation !== "isolate" && cs.zIndex === "auto") p.style.isolation = "isolate";
}

const YK_GRAIN_CSS = `@keyframes yk-grain{0%{transform:translate(0,0)}25%{transform:translate(-3%,2%)}50%{transform:translate(2%,-3%)}75%{transform:translate(-2%,-1%)}100%{transform:translate(1%,3%)}}
@media (prefers-reduced-motion:reduce){[data-yk-grain] *{animation:none!important}}`;
const YK_NOISE = `url("data:image/svg+xml,%3Csvg xmlns='http://www.w3.org/2000/svg' width='220' height='220'%3E%3Cfilter id='n'%3E%3CfeTurbulence type='fractalNoise' baseFrequency='0.85' numOctaves='3' stitchTiles='stitch'/%3E%3CfeColorMatrix values='0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 0 0.5 0 0 0 1.6 -0.3'/%3E%3C/filter%3E%3Crect width='100%25' height='100%25' filter='url(%23n)'/%3E%3C/svg%3E")`;

/** A film-grain texture over a section (adds tactile depth to flat colour or gradients). */
export function Grain({
  opacity = 0.12,
  blend = "overlay",
  animated = false,
  className,
  style,
}: {
  opacity?: number;
  blend?: CSSProperties["mixBlendMode"];
  animated?: boolean;
  className?: string;
  style?: CSSProperties;
}) {
  const ref = useRef<HTMLDivElement>(null);
  useYkLayoutEffect(() => ykPrepareParent(ref.current), []);
  return (
    <div
      ref={ref}
      aria-hidden="true"
      data-yk-grain=""
      className={className}
      style={{ position: "absolute", inset: 0, overflow: "hidden", pointerEvents: "none", borderRadius: "inherit", opacity, mixBlendMode: blend, ...style }}
    >
      {animated && <style>{YK_GRAIN_CSS}</style>}
      <div style={{ position: "absolute", inset: "-10%", backgroundImage: YK_NOISE, animation: animated ? "yk-grain 0.9s steps(4) infinite" : undefined }} />
    </div>
  );
}