ASCII Loading and Reveal Effects for React – ascii-reveal

Description:

ascii-reveal is a React animation library that reveals text, images, and cards through an ASCII character grid.

It keeps content in the DOM and draws the scrambling effect above it, with a loading prop for asynchronous updates and a companion skeleton component.

Preview

ascii-reveal

Install

Use React and React DOM 17 or newer:

npm install ascii-reveal

Add a reveal on mount

Wrap the content that should animate. Mark controls with data-ascii="fade" and card backgrounds with data-ascii="surface":

import { AsciiReveal } from 'ascii-reveal';
export function ArticleCard() {
  return (
    <AsciiReveal preset="decode">
      <article data-ascii="surface">
        <h2>Release notes</h2>
        <p>The latest changes to your workspace.</p>
        <a href="/releases" data-ascii="fade">View releases</a>
      </article>
    </AsciiReveal>
  );
}

Reveal loaded content

Set loading while a request is pending. During refreshes, content scrambles out and a shimmer occupies its place. When loading ends, replacement content decodes in. Skeletons remain outside the reveal animation.

Choose skeleton dimensions that match the expected content area:

import { AsciiReveal, AsciiSkeleton } from 'ascii-reveal';
type Profile = { name: string; role: string };
export function ProfileCard({ data, isLoading }: {
  data: Profile | null;
  isLoading: boolean;
}) {
  return (
    <AsciiReveal loading={isLoading} revealOnMount={false}>
      {data ? (
        <article>
          <h2>{data.name}</h2>
          <p>{data.role}</p>
        </article>
      ) : (
        <AsciiSkeleton variant="braille" lines={3} />
      )}
    </AsciiReveal>
  );
}

AsciiReveal props

PropDefaultBehavior
presetdecodedecode, dither, terminal, blueprint, or a custom preset object
durationfastfast or the longer cinematic treatment
speed1Playback multiplier
loadingUnsetScrambles out while true, then reveals content when false
shimmertrueGlyph shimmer while loading
mascotUnsetBuilt-in mascot name, SVG URL or markup, or canvas draw callback
origincentercenter, top-left, pointer, or viewport { x, y } coordinates
selectorUnsetLimits animation to descendants that match a selector
revealOnMounttrueStarts a reveal after mounting
lazytrueReveals lower sections as they enter view
revealOnHydratefalseOpts server-rendered content into hydration animation
fallbacktrueChanges later reveals to a fade after slow frames
onRevealCompleteUnsetCallback after a mount reveal or a loading reveal finishes
asdivWrapper element type
childrenUnsetContent to animate

Element attributes

AttributeBehavior
data-ascii="surface"Card or panel background treatment
data-ascii="fade"Fades the marked control on the reveal wave
data-ascii="media"Treats an element as media for glyph rendering
data-ascii="skip"Leaves the subtree outside the effect
data-ascii-digitsUses digits for scrambling

AsciiSkeleton props

Use lines and widths for paragraphs. Set rows for an image or avatar block; it overrides lines. For long lists, pass animate={false} to skip the shimmer.

PropDefaultPurpose
variantditherdither, scan, braille, or terminal
lines3Number of text lines
widthsParagraph-shaped widthsArray of CSS lengths or pixel numbers
rowsUnsetGlyph rows for a block placeholder
width, heightUnsetBlock dimensions as CSS lengths or pixel numbers
circlefalseRound block placeholder
seed1Seed for deterministic glyph patterns
animatetrueAnimated shimmer
asspanWrapper element type

Loading mascots and colors

For a mascot during loading, set mascot to spider, ghost, pumpkin, or bat. Custom SVG URLs, SVG markup, and canvas drawing functions are accepted too.

Pass className="profile-reveal" to AsciiReveal and set CSS custom properties on that wrapper:

.profile-reveal {
  --ascii-accent: #5b8cff;
  --ascii-skeleton: #888;
  --ascii-glyph: #888;
  --ascii-font: ui-monospace, monospace;
}

Related resources

Add Comment