Loaders
Slant / Loaders
Nine CSS 3D loaders built from the slanted pixel, with pause and reduced-motion behaviour.
Demo
Usage
import { Loader, loaderVariants } from '@tuttn/slant'
// A loader fills its parent, so give the parent a size.
<div style={{ height: 260 }}>
<Loader variant="pixel-cube" />
</div>
// loaderVariants lists the nine, from 'pixel-cube' to 'squash-bounce'.
{loaderVariants.map(variant => <Loader key={variant} variant={variant} />)}
// running={false} freezes every animation at its current frame. The ref is
// the stage div, e.g. for an IntersectionObserver that pauses it off screen.
<Loader ref={stage} variant="scan-grid" running={visible && !paused} />
// A label makes it an image for screen readers; without one it is decorative.
<Loader variant="helix" label="Loading your workspace" />
// Without a variant it is a bare stage for a figure of your own.
<Loader><MyFigure /></Loader>Props
| Prop | Type | Default | Description |
|---|---|---|---|
variant | LoaderVariant | — | Which of the nine figures to draw (`loaderVariants` lists them, from `pixel-cube` to `squash-bounce`); the stage then carries `data-variant`. Omitted, the stage is bare and shows only its children. |
running | boolean | true | False pauses every CSS animation inside at its current frame (the stage then carries `data-paused`). Pass false while the loader is off screen. |
label | string | — | Names the loader for screen readers (`role="img"` with this label). Omitted, the loader is decorative and `aria-hidden`. |
…rest | HTMLAttributes<HTMLDivElement> | — | className, style, the ref and other attributes reach the stage div, which the figure is drawn inside; children render after the figure. |
Accessibility
- Decorative by default: the stage is
aria-hidden, so say what is loading in text nearby. - With
labelthe stage isrole="img"with that name. Give a label only when the loader is the one sign that something is happening. - It is not a live region and announces nothing when it appears or stops; put the status text in one if it should be heard.
- Pass
running={false}while the loader is off screen or the tab is hidden: every animation pauses at its frame (the stage carriesdata-paused). - Inside a
<Slant>root,prefers-reduced-motionstops every animation, and each figure rests in a composed still frame whateverrunningsays.
The figures are pure CSS 3D built from rounded, slanted pixels: no canvas, no WebGL, no images. They take their colours from the theme, so they change with it, and cost almost nothing while paused.
The nine figures' own exports (PixelCube, WaveGrid, PixelOrbit, Helix, StackFlip, PixelRing, StackDrop, ScanGrid and SquashBounce) still work and render <Loader variant>, but they are deprecated and will go in a later release. Replace <Helix /> with <Loader variant="helix" />.
In SwiftUI, SlantLoader(variant: .helix) draws the same figures with Canvas and TimelineView; SlantLoaderVariant has the same nine cases.