Specification
- Catalogue
- No. 65 of 110
- Section
- Buttons and toggles
- Interaction
- Hover
- Element
- Icon
- Preview
- Live component
- Imports
- react 19.3.1
- Added
Notes
Point at a link and its icon does what it shows: the pencil scribbles, the lock rattles.
A hover effect that explains instead of decorating. Each plays once, under a second, and always to the end.
0.45-1s, once, plays to the end. One page-wide pointer listener. Springy ones overshoot with cubic-bezier(.34, 1.56, .64, 1).
Code
React and plain CSS"use client";
import { ReactNode } from "react";
import type { LivePreviewProps } from "@/components/live/types";
import { onPointerOver, playIcon } from "@/components/pieces/kit/icon-player";
import { PieceStage } from "@/components/pieces/stage/PieceStage";
import type { Tour } from "@/components/pieces/stage/tour";
import "@/components/pieces/kit/icon-plays.css";
import "./hover-icons.css";
// Each icon names the motion it plays (icon-plays.css) and draws the parts
// that motion moves (.minute, .hour, .flap, .arrow).
const S = { fill: "none", stroke: "currentColor", strokeWidth: 1.8, strokeLinecap: "round", strokeLinejoin: "round" } as const;
const ICONS: { label: string; motion: string; svg: ReactNode }[] = [
{
label: "Write",
motion: "scribble",
svg: (
<svg viewBox="0 0 24 24" {...S}>
<path d="M4 20h4L19 9l-4-4L4 16z" />
<path d="M13.5 6.5l4 4" />
</svg>
),
},
{
label: "Privacy",
motion: "rattle",
svg: (
<svg viewBox="0 0 24 24" {...S}>
<rect x="5" y="11" width="14" height="9" rx="2" />
<path d="M8 11V8a4 4 0 0 1 8 0v3" />
</svg>
),
},
{
label: "Settings",
motion: "spin",
svg: (
<svg viewBox="0 0 24 24" {...S}>
<circle cx="12" cy="12" r="3" />
<circle cx="12" cy="12" r="7" />
{Array.from({ length: 8 }, (_, i) => {
const a = (i * Math.PI) / 4;
return <path key={i} d={`M${12 + 7 * Math.cos(a)} ${12 + 7 * Math.sin(a)}L${12 + 9.5 * Math.cos(a)} ${12 + 9.5 * Math.sin(a)}`} />;
})}
</svg>
),
},
{
label: "History",
motion: "rewind",
svg: (
<svg viewBox="0 0 24 24" {...S}>
<circle cx="12" cy="12" r="9" />
<path className="hour" d="M12 12V8" />
<path className="minute" d="M12 12h4.5" />
</svg>
),
},
{
label: "Inbox",
motion: "flutter",
svg: (
<svg viewBox="0 0 24 24" {...S}>
<rect x="3" y="6" width="18" height="13" rx="2" />
<path className="flap" d="M3.5 7l8.5 6 8.5-6" />
</svg>
),
},
{
label: "Usage",
motion: "zap",
svg: (
<svg viewBox="0 0 24 24" {...S}>
<path d="M13 2L4 14h7l-1 8 9-12h-7z" />
</svg>
),
},
{
label: "Reviews",
motion: "star-turn",
svg: (
<svg viewBox="0 0 24 24" {...S}>
<path d="M12 2.8l2.8 5.8 6.3.9-4.6 4.4 1.1 6.3L12 17.2l-5.6 3 1.1-6.3-4.6-4.4 6.3-.9z" />
</svg>
),
},
{
label: "Upload",
motion: "upload",
svg: (
<svg viewBox="0 0 24 24" {...S}>
<path className="arrow" d="M12 15V4M7.5 8.5L12 4l4.5 4.5" />
<path d="M4 15v3a2 2 0 0 0 2 2h12a2 2 0 0 0 2-2v-3" />
</svg>
),
},
];
function HoverIconsDemo() {
return (
<div className="dm">
{/* The player listens on this row only, not the whole page. */}
<div className="dm-icons" onPointerOver={(e) => onPointerOver(e.nativeEvent)}>
{ICONS.map((i) => (
<button key={i.label} type="button" className="dm-icon-btn">
<span data-icon={i.motion} style={{ display: "contents" }}>
{i.svg}
</span>
{i.label}
</button>
))}
</div>
<p className="dm-hint">Point at each one</p>
</div>
);
}
// In a card each icon plays in turn, as if the pointer passed over the row.
const TOUR: Tour = ICONS.map((_, k) => ({
run: (root: HTMLElement) => {
const icon = root.querySelectorAll<HTMLElement>("[data-icon]")[k];
if (icon) playIcon(icon);
},
wait: 650,
}));
export default function HoverIconsEntry(props: LivePreviewProps) {
return (
<PieceStage {...props} label="Icons that act out their meaning" tour={TOUR}>
<HoverIconsDemo />
</PieceStage>
);
}