Page not found
Drag the letters about, or put them back in one go.
'use client';
import { useState } from 'react';
import { Button, ScatterText } from '@brand-studio/ui';
export default function ScatterTextDemo() {
const [tidy, setTidy] = useState(false);
return (
<div style={{ display: 'grid', justifyItems: 'center', gap: 20, textAlign: 'center' }}>
<h2 style={{ margin: 0, fontSize: 'clamp(2.4rem, 9vw, 4.5rem)', fontWeight: 800 }}>
<ScatterText text="Page not found" tidy={tidy} />
</h2>
<p style={{ margin: 0, maxWidth: '30ch', color: 'var(--bs-muted)' }}>Drag the letters about, or put them back in one go.</p>
<Button tone="secondary" onClick={() => setTidy(value => !value)}>{tidy ? 'Knock it over' : 'Put it back'}</Button>
</div>
);
}Installation
pnpm add @brand-studio/uinpm install @brand-studio/uiyarn add @brand-studio/uibun add @brand-studio/uiInstall the peer dependencies
npm install react react-domImport the stylesheet once
import '@brand-studio/ui/styles.css';Wrap your app in a brand theme
import { BrandTheme, ScatterText } from '@brand-studio/ui'; import brand from './brand.json'; <BrandTheme palette={brand.tokens} mode="system"> {/* your app */} </BrandTheme>
Usage
import { ScatterText } from '@brand-studio/ui';<h1><ScatterText text="Page not found" tidy={tidy} /></h1>
<Button tone="secondary" onClick={() => setTidy(true)}>Put it back</Button>The letters scatter after the page loads and spring back when tidy turns on. spread scales how far they fall; the default keeps them clear of the line below. Words wrap as whole words.
Accessibility
- Screen readers hear the plain text once; the loose letters are hidden from them.
- The server renders the text in order, so it reads correctly before scripts run.
- Under reduced motion the letters stay in place.
API Reference
| Prop | Type | Default |
|---|---|---|
text | string | – |
tidy? | boolean | false |
spread? | number | 1 |
as? | React.ElementType | – |
className? | string | '' |