ditherface
v0.2.3
Published
Tiny dependency-free React canvas dither component.
Maintainers
Readme
ditherface
Tiny, dependency-free React dither components.
- No runtime dependencies (React is a peer dependency)
- Keyboard + screen-reader accessible defaults
- Respects
prefers-reduced-motion
Install
npm i ditherfaceUsage
import DitherFace from "ditherface";
export function DemoFace() {
return (
<DitherFace
seed="ada-lovelace"
className="h-72 w-72"
animated
dotScale={3}
/>
);
}import { Dither, DitherBackground } from "ditherface";
export function DemoBackground() {
return (
<DitherBackground
className="h-72 w-full"
animated
dotScale={3}
seed="marketing-hero"
palette={["#3b82f6", "var(--brand-accent)", "--color-red-9"]}
>
<div style={{ position: "relative", zIndex: 1 }}>Content on top</div>
</DitherBackground>
);
}
export function DemoCanvas() {
return <Dither className="h-56 w-full" pixelSize={2} colorNum={5} />;
}Accessibility
Ditherdefaults torole="img"with an accessible label.- Keyboard controls when interaction is enabled: arrow keys move focus,
Homeresets. - Use
decorativefor purely visual usage.
Dither Props
seed?: string(default"ditherface")tones?: string | string[](explicit CSS tone steps)palette?: string | string[](select one deterministic base color from list)paletteandtonesaccept CSS color values, CSS custom properties like--brand-accent, andvar(--brand-accent, #3b82f6)fallbackswaveSpeed?: number(default0.05)waveFrequency?: number(default3)waveAmplitude?: number(default0.3)waveColor?: [number, number, number](default[0.5, 0.5, 0.5])colorNum?: number(default4)pixelSize?: number(default2)disableAnimation?: boolean(defaultfalse)enableMouseInteraction?: boolean(defaulttrue)mouseRadius?: number(default1)decorative?: boolean(defaultfalse)ariaLabel?: string
DitherBackground Props
animated?: boolean(defaulttrue)dotScale?: number(default2)seed?: string(default"ditherface")tones?: string | string[]palette?: string | string[]children?: ReactNodeditherProps?: Omit<DitherFaceProps, ...>for extra face-renderer options
DitherBackground uses the same renderer as DitherFace (without face features), so both components match visually.
All standard <canvas> or <div> props are forwarded on each component.
DitherFace Props
seed: string(required)animated?: boolean(defaulttrue)dotScale?: numbertones?: string | string[]palette?: string | string[]ariaLabel?: stringshowFeatures?: boolean(defaulttrue)showEyes?: boolean(defaulttrue)compact?: boolean(defaultfalse)children?: ReactNode(optional overlay)
DitherFace is the package default export.
