Pixel field
Slanted pixels with a light that follows the pointer.
Demo
Usage
import { PixelField } from '@tuttn/slant'
// TUTTN's home page hero: 12 × 12 slanted pixels on a tilted plane. The field
// fills its container's width; give it a height to frame it.
<PixelField style={{ height: 420 }} />
// A flat strip of crosses that ignores presses.
<PixelField variant="flat" shape="cross" columns={24} rows={6} ripple={false} />
// A wider light, and held still while a dialog is open.
<PixelField reach={0.35} running={!dialogOpen} />
// Named for screen readers; without a label it is decorative (aria-hidden).
<PixelField label="A field of slanted pixels that light up under the pointer" />
/* In your own colours: the field reads only tokens, so set them on the Slant
root around it. Rules outside a layer beat Slant's, so no !important. */
.hero-field { --sl-accent: var(--brand); --sl-text: var(--ink); --sl-bg: var(--page); }
/* How far a lit pixel rises off the plane (44px by default). */
.hero-field { --sl-pixel-field-depth: 32px; }Props
| Prop | Type | Default | Description |
|---|---|---|---|
columns | number | 12 | Cells across. |
rows | number | 12 | Cells down. |
shape | 'pixel' | 'line' | 'cross' | 'pixel' | The mark in each cell, all leaning back 9°: `pixel` is the slanted rounded square, `line` a short slanted stroke, `cross` a small plus. |
variant | 'plane' | 'flat' | 'plane' | `plane` lays the field on a plane tilted away from the viewer, as on TUTTN's home page; `flat` faces the viewer. |
reach | number | 0.22 | The pointer light's radius, as a fraction of the field's width. Cells inside it lift and take the accent, the nearest the most; 0 turns the light off. |
ripple | boolean | true | A press sends a ripple out across the field from where it lands. |
running | boolean | true | False holds the field still: the wave pauses where it is and the pointer light and ripple stop. The field also pauses by itself off screen and in a hidden tab. |
label | string | — | Names the field for screen readers (`role="img"` with this label). Omitted, the field is decorative and `aria-hidden`. |
…rest | HTMLAttributes<HTMLDivElement> | — | className, style, other attributes and the ref go on the root div. |
A slow wave runs through the field along its diagonals. Cells near the pointer lift and take the accent, the nearest the most, within reach (a fraction of the field's width); a press sends a ripple out from where it lands, and on a touch screen a tap does the same. Resting cells are the text colour mixed faintly into the background, so the field sits quietly on any of the four themes, Paper included.
Motion
The field animates only while it is on screen, the tab is visible and running is true; the root then carries data-running. Otherwise the wave pauses where it is and the light eases out. The pointer is measured once and measured again after a scroll or resize, and the light is repainted at most once a frame. Under prefers-reduced-motion there is no wave, no light and no ripple: the field rests in a composed frame, one soft band of partly lit pixels across its middle diagonal.
Accessibility
The field is decoration: it is aria-hidden, takes no focus and has no keyboard behaviour, and nothing in it carries information. Given a label it becomes role="img" with that name, for a page where the picture itself matters.
Sizing
The field fills its container's width and each cell is square, so the flat variant is as tall as its rows. The plane variant draws inside that same box, tilted, at 70% of the width; set a height on the root to frame it, and .sl-pixel-field-plane's width to scale the plane. For loading states, see the loaders.