Brand
Particles
Decorative dot figure of any shape with particles drifting off its left and right edges.
import { buildParticleFigure, Particles } from "@openperf/deft";
const figure = buildParticleFigure({
cells: 24,
isInside: (column, row) => Math.hypot(column - 11.5, row - 11.5) <= 10,
});
<Particles.Root className="h-44 w-full" figure={figure} />;When to use
| Need | Component |
|---|---|
| Large decorative graphic of your own shape | Particles |
| The same effect with the OpenPerf mark | Logo.Particles in Logo |
| Showing that something is loading | Spinner or Skeleton |
Particles is hidden from assistive technology, so it cannot carry meaning.
Size and color
Give the root a height and a width. The figure is drawn in the middle, in a square whose side is the smaller of 80% of the height and 60% of the width. The particles travel through the space to its left and right, so a wide element gives them more room.
Dots and particles take the text color of the root, the accent color by default. Pass another text color class to change it.
Build the figure once, outside the component: a new figure object restarts the animation.
Rendering and motion
The dots are part of the server HTML. The particles appear only in the browser, after the component mounts, and fade in over 0.8 seconds. buildParticleFigure is seeded, so the same cells and isInside give the same dots on the server and in the browser.
The animation does not run, and the particles are painted as a still frame, when either is true:
- The browser reports
prefers-reduced-motion: reduce. - An ancestor has the
data-reduce-motionattribute.
Both are re-checked, and the particle color refreshed, when the media query, an attribute of <html>, the system color scheme or the size of the element changes.
API
Particles.Root
Prop
Type
buildParticleFigure
Returns a ParticleFigure to pass to figure as is. A shape that sits off center in the grid is shifted back to the middle.
Prop
Type
The two outermost filled cells at each end of a row are thinned out to give the ragged outline the particles start from:
| Cell in a row | Kept | Dot size |
|---|---|---|
| Outermost | 70% chance | 70โ100% |
| Next to the outermost | 90% chance | 70โ100% |
| Deeper | Always | 100% |