Not found
An error code in slanted pixels, with a way out.
Demo
Usage
import { Button, NotFound } from '@tuttn/slant'
// The defaults: the code 404, "Page not found" (messages.notFound) and a
// link home (messages.goHome).
<NotFound />
// Your own words and destination. Inside a page that already has an h1,
// lower the heading.
<NotFound
code="500"
title="Something broke on our side"
description="It isn’t you. We’ve been told, and this page should be back shortly."
href="/status"
actionLabel="See the status page"
headingLevel={2}
/>
// A router's link, or several actions: replace the default one (null for none).
<NotFound action={<Button asChild variant="primary"><Link to="/">Go home</Link></Button>} />
// Hold the shimmer and the pointer's push. Off screen they stop on their own.
<NotFound running={false} />Props
| Prop | Type | Default | Description |
|---|---|---|---|
code | string | '404' | The code drawn in slanted pixels, and read first in the heading. Digits and the letters A–Z draw (lowercase as capitals); any other character leaves a gap. |
title | ReactNode | messages.notFound | The heading, after the code: screen readers hear "404: Page not found". |
description | ReactNode | — | A line under the heading: what happened, or what to try next. |
action | ReactNode | — | Replaces the default link: a router's Link inside a Button, or a row of buttons. `null` leaves no action. |
href | string | '/' | Where the default action, a primary Button rendered as a link, goes. |
actionLabel | string | messages.goHome | The default action's text. |
headingLevel | 1 | 2 | 3 | 1 | The heading's level: 1 for a page of its own, 2 or 3 inside a page that already has a heading above it. |
running | boolean | true | False holds the shimmer and stops pixels moving from the pointer. Off screen, in a hidden tab and under reduced motion they stop on their own. |
…rest | HTMLAttributes<HTMLElement> | — | className, style, other attributes and the ref go on the section. |
Accessibility
The root is a section named by its heading, so it is a region landmark. The heading reads the code first, from visually hidden text: screen readers hear “404: Page not found”. The pixel drawing itself is aria-hidden. Pick headingLevel to fit the page: 1 when the error is the page, 2 or 3 when it sits under a heading of yours. The default action is a real link, a primary Button rendered with asChild.
The code
The code is set in Slant’s own pixel font, five by seven cells a character: the digits and A to Z, with lowercase drawn as capitals. Any other character leaves a gap. Every cell keeps a faint socket, and the lit ones are slanted pixels in the accent colour. The code always reads left to right, under dir="rtl" too. Its pixels shrink to fit the width the code is given, up to 14px; set --sl-not-found-pixel-size for another largest size.
Motion
With a mouse or trackpad, pixels near the pointer move out of its way, further the closer they are, and settle back into their sockets when it leaves. Every few seconds a soft band of light crosses the code. Both stop off screen, in a hidden tab and with running={false}. Under reduced motion, and on a touch screen, the code stands still and whole. Pixel field is the same idea as a whole surface.