React
Props, PopconsProvider and the play/stop ref for Popcons icons in React.
Every icon is a React component with the same props. React 18 or newer is required.
import { HeartIcon } from "@popcons/react";
<HeartIcon size={32} color="#6D5EF8" strokeWidth={2} trigger="hover" label="Like" />Props
| Prop | Type | Default | Description |
|---|---|---|---|
size | number | 24 | Width and height in pixels. |
color | string | currentColor | Stroke colour. Defaults to the surrounding text colour. |
strokeWidth | number | 2 | Stroke width on the 24px grid. |
corner | "round" | "sharp" | "round" | Line caps and joins. |
speed | number | 1 | Speed multiplier. 2 is twice as fast. |
intensity | number | 1 | Motion amplitude multiplier. 0 is static. |
trigger | "hover" | "click" | "loop" | "in-view" | "none" | "hover" | What starts the animation. Hover also fires on focus of the icon or its closest button or link. |
label | string | none | Accessible name. Without it the icon is decorative and hidden from assistive technology. |
mirrorInRtl | boolean | true for directional icons | Flips arrows, send, undo, redo, share and similar icons horizontally inside dir="rtl" layouts. Set false to opt out. |
PopconsProvider
Set defaults for every icon below it, including reduced-motion behaviour.
import { PopconsProvider } from "@popcons/react";
<PopconsProvider size={20} strokeWidth={1.75} speed={1.2} reducedMotion="respect">
<App />
</PopconsProvider>reducedMotion accepts respect (follow the OS setting, the default), always (animate regardless; use only for previews the user started) and never-animate. Props on an icon override the provider.
Play and stop from a ref
import { useRef } from "react";
import { BellIcon, type IconHandle } from "@popcons/react";
export function Demo() {
const bell = useRef<IconHandle>(null);
return (
<>
<BellIcon ref={bell} trigger="none" size={32} />
<button onClick={() => bell.current?.play()}>Ring</button>
<button onClick={() => bell.current?.stop()}>Stop</button>
</>
);
}The handle also exposes element, the underlying SVG. Calling play() still respects the reduced-motion mode.
Accessibility
Icons next to a text label should stay decorative. Icons alone inside a button need a name on the button, or a label on the icon. See accessibility.