Preact
pulsoicon-preact — animated Preact icons with the same JSX, ref and props as pulsoicon-react.
Try every example live on the Preact demo page.
Installation
npm install pulsoicon-preact
Preact 10.11 or newer. Motion 12 or newer plays the icons and is installed with the package. It is built for Preact itself, so no preact/compat alias is needed.
Quick start
import { Bell, Calendar, Trash2 } from "pulsoicon-preact";
export function Toolbar() {
return (
<>
<button><Bell size={20} /> Notifications</button>
<button><Calendar /> Schedule</button>
<button><Trash2 color="crimson" strokeWidth={1.5} /> Delete</button>
</>
);
}
Props
size (24), color (currentColor), strokeWidth (2), absoluteStrokeWidth (false), solid (false), animated (true), autoAnimated (true) and play, as in React. Any other attribute (class, style, aria-label) goes on the <svg>.
Outline, solid and static
<Heart />
<Heart solid />
<Heart animated={false} />
<Heart solid animated={false} />
Play from code
ref gives startAnimation() and stopAnimation(); both return a promise that resolves when the motion has finished.
import { useRef } from "preact/hooks";
import { Check, type IconHandle } from "pulsoicon-preact";
export function SaveButton() {
const check = useRef<IconHandle>(null);
return (
<button onClick={() => check.current?.startAnimation()}>
<Check ref={check} autoAnimated={false} /> Save
</button>
);
}
Driven by state
<Bell autoAnimated={false} play={hasNewMessage} />
Loading icons on demand
pulsoicon-preact/all exports every icon by kebab-case name (all of them). pulsoicon-preact/names lists the names without loading any icon, and pulsoicon-preact/icons/<name> loads one:
import { ICON_NAMES, type IconName } from "pulsoicon-preact/names";
const load = (name: IconName) => import(`pulsoicon-preact/icons/${name}`);
Accessibility
Icons render with aria-hidden="true"; label the button or link they sit in. Nothing moves when the system asks for reduced motion.