dxbh-uiGitHub

Reveal

Fades content up 12px as it scrolls into view. Runs on a CSS view timeline where supported, falls back to an IntersectionObserver, staggers groups 50ms apart, and stays still under reduced motion.

Preview
Scroll down

Content that arrives, not appears

Each block rises 12px and fades in as it enters the scroll area, then stays.

  • Visible by default
  • Scroll-driven first
  • Observer fallback
  • Still under reduced motion
  • Stagger 50ms
  • 12px, never more

Turn on Reduce motion: everything is simply there.

Install

npx shadcn@latest add @dxbh-ui/reveal

Add the @dxbh-ui registry to components.json once:

{
  "registries": {
    "@dxbh-ui": "https://ui.dxbh.dev/r/{name}.json"
  }
}

Usage

demo.tsx
"use client";

import { Reveal, RevealGroup } from "@/components/ui/reveal/reveal";

const notes = ["Visible by default", "Scroll-driven first", "Observer fallback", "Still under reduced motion", "Stagger 50ms", "12px, never more"];

export default function RevealDemo() {
  return (
    // Its own scroll box so the view timeline has something to track inside
    // the preview. On a page, the document scroller does this job.
    <div className="h-96 w-full max-w-md overflow-y-auto rounded-xl border bg-background">
      <div className="flex h-72 items-end justify-center pb-6 text-sm text-muted-foreground">Scroll down</div>
      <div className="space-y-10 px-5 pb-24">
        <Reveal className="space-y-2">
          <h3 className="text-lg font-semibold tracking-[-0.01em]">Content that arrives, not appears</h3>
          <p className="text-sm text-muted-foreground">
            Each block rises 12px and fades in as it enters the scroll area, then stays.
          </p>
        </Reveal>
        <RevealGroup as="ul" itemAs="li" className="grid grid-cols-2 gap-3" itemClassName="rounded-lg border bg-card p-3 text-sm">
          {notes.map((note) => (
            <span key={note}>{note}</span>
          ))}
        </RevealGroup>
        <Reveal as="p" className="text-sm text-muted-foreground">
          Turn on Reduce motion: everything is simply there.
        </Reveal>
      </div>
    </div>
  );
}

Props

PropTypeDefault
as

Element to render.

ElementType"div"
index

Position in a staggered sequence. RevealGroup sets it.

number—
stagger

Delay between items in ms.

number50
distance

Rise distance in px.

number12
RevealGroup.as / itemAs

Container and per-child wrapper elements, e.g. ul and li.

ElementType"div"
RevealGroup.itemClassName

Class for each child wrapper.

string—

Polish

  • Three reveals consolidated into one: the CSS scroll-driven version, a motion/react whileInView and a GSAP stagger grid. Zero npm dependencies.
  • Visible by default. Without JS, or before hydration, content is simply there; motion is progressive enhancement.
  • View timeline first, so supporting browsers run it on the compositor with no JS. Others get a one-shot IntersectionObserver.
  • Anything already on screen at hydration is left alone instead of being hidden and re-shown.
  • Travel cut from 40–44px with 10px blur to a 12px rise with opacity, on the dxbh-ui ease-out curve. Blur is gone: it's expensive while scrolling.
  • RevealGroup staggers children 50ms apart (stagger prop, 40–60ms reads as one gesture) and stops adding delay after six items so long lists never wait.
  • Reduced motion means none: no fade, no rise. The OS setting and data-reduce-motion on <html> both count.
  • The stylesheet is a React 19 hoisted <style>, rendered once however many Reveals mount. No global CSS to install.
  • Brand easing and copy removed.

Source

reveal.tsx
"use client";

import {
  Children,
  useEffect,
  useRef,
  type CSSProperties,
  type ElementType,
  type HTMLAttributes,
  type ReactNode,
} from "react";
import { cn } from "@/lib/utils";
import { prefersReducedMotion } from "@/hooks/use-reduced-motion";

// One stylesheet for every Reveal on the page. React 19 hoists a <style> with
// `href` + `precedence` into <head> and renders it once, however many Reveals
// mount, so the item ships no global CSS.
//
// Content is visible by default. Motion is progressive enhancement:
//   1. Browsers with scroll-driven animations scrub opacity and a 12px rise
//      against the element's own view timeline. No JS runs.
//   2. Others get an IntersectionObserver that flips data-reveal from
//      "hidden" to "shown" once, behind a transition.
//   3. Reduced motion (OS setting or data-reduce-motion on <html>) gets the
//      content as-is. Nothing moves, nothing fades.
const STYLES = `
@keyframes dxbh-ui-reveal {
  from { opacity: 0; transform: translateY(calc(var(--reveal-distance, 12px) * var(--motion-distance, 1))); }
}
@media (prefers-reduced-motion: no-preference) {
  @supports (animation-timeline: view()) {
    :root:not([data-reduce-motion]) [data-reveal] {
      animation-name: dxbh-ui-reveal;
      animation-duration: auto;
      animation-fill-mode: both;
      animation-timing-function: var(--ease-out, cubic-bezier(0.23, 1, 0.32, 1));
      animation-timeline: view();
      animation-range:
        entry calc(var(--reveal-start, 10%) + var(--i, 0) * var(--reveal-step, 5%))
        entry calc(var(--reveal-end, 60%) + var(--i, 0) * var(--reveal-step, 5%));
    }
  }
  :root:not([data-reduce-motion]) [data-reveal="hidden"],
  :root:not([data-reduce-motion]) [data-reveal="shown"] {
    transition-property: opacity, transform;
    transition-duration: var(--reveal-duration, 400ms);
    transition-timing-function: var(--ease-out, cubic-bezier(0.23, 1, 0.32, 1));
    transition-delay: calc(var(--i, 0) * var(--reveal-stagger, 50ms));
  }
  :root:not([data-reduce-motion]) [data-reveal="hidden"] {
    opacity: 0;
    transform: translateY(calc(var(--reveal-distance, 12px) * var(--motion-distance, 1)));
  }
}
`;

/** Stagger steps stop growing after this many items so long lists never wait. */
const MAX_STEPS = 6;

const supportsViewTimeline = () =>
  typeof CSS !== "undefined" && typeof CSS.supports === "function" && CSS.supports("animation-timeline: view()");

export type RevealProps = HTMLAttributes<HTMLElement> & {
  /** Element to render. Defaults to `div`. */
  as?: ElementType;
  /** Position in a staggered group. RevealGroup sets this for you. */
  index?: number;
  /** Delay between items in the fallback path, in ms (40–60 reads as one gesture). */
  stagger?: number;
  /** Rise distance in px before reduced-motion scaling. */
  distance?: number;
};

/**
 * Fades and lifts its content 12px as it scrolls into view. Visible without JS,
 * static under reduced motion.
 */
export function Reveal({ as: Tag = "div", index, stagger, distance, className, style, ...props }: RevealProps) {
  const ref = useRef<HTMLElement>(null);

  useEffect(() => {
    const el = ref.current;
    if (!el || supportsViewTimeline() || prefersReducedMotion()) return;
    if (typeof IntersectionObserver === "undefined") return;

    // The first callback says where the element starts. Anything already on
    // screen stays put; hiding it now would flash content someone is reading.
    let first = true;
    const observer = new IntersectionObserver((records) => {
      const visible = records.some((r) => r.isIntersecting);
      if (first) {
        first = false;
        if (visible) return observer.disconnect();
        el.dataset.reveal = "hidden";
        return;
      }
      if (!visible) return;
      el.dataset.reveal = "shown";
      observer.disconnect();
    });
    observer.observe(el);
    return () => {
      observer.disconnect();
      el.dataset.reveal = "";
    };
  }, []);

  const vars: Record<string, string | number> = {};
  if (index !== undefined) vars["--i"] = Math.min(Math.max(index, 0), MAX_STEPS);
  if (stagger !== undefined) {
    vars["--reveal-stagger"] = `${stagger}ms`;
    // Scroll-driven mode staggers in scroll space: 50ms ≈ 5% of the entry range.
    vars["--reveal-step"] = `${stagger / 10}%`;
  }
  if (distance !== undefined) vars["--reveal-distance"] = `${distance}px`;

  return (
    <>
      <style href="dxbh-ui-reveal" precedence="default">
        {STYLES}
      </style>
      <Tag ref={ref} data-reveal="" className={className} style={{ ...vars, ...style } as CSSProperties} {...props} />
    </>
  );
}

export type RevealGroupProps = HTMLAttributes<HTMLElement> & {
  /** Container element. Defaults to `div`. */
  as?: ElementType;
  /** Element wrapping each child. Use `li` inside a `ul`. Defaults to `div`. */
  itemAs?: ElementType;
  /** Class applied to each item wrapper. */
  itemClassName?: string;
  /** Delay between items, in ms. Defaults to 50. */
  stagger?: number;
  /** Rise distance in px. */
  distance?: number;
  children?: ReactNode;
};

/** Reveals each child in turn, 50ms apart by default. */
export function RevealGroup({
  as: Tag = "div",
  itemAs = "div",
  itemClassName,
  stagger = 50,
  distance,
  children,
  className,
  ...props
}: RevealGroupProps) {
  return (
    <Tag className={cn(className)} {...props}>
      {Children.toArray(children).map((child, i) => (
        <Reveal
          key={(child as { key?: string | null })?.key ?? i}
          as={itemAs}
          index={i}
          stagger={stagger}
          distance={distance}
          className={itemClassName}
        >
          {child}
        </Reveal>
      ))}
    </Tag>
  );
}

Extracted from moments-website/components/marketing/scroll-reveal.tsx at f1d46a9, aurora/components/main/reveal.tsx at b587f66, auptera-nuxt/src/components/RevealGrid.tsx at eebdbfe.