Icon button
A square button that shows only an icon. Its accessible name is required by the type.
Use an icon button for frequent, well-known actions where a label would crowd the layout: closing a dialog, editing a row, formatting text. If the icon could be read more than one way, use a Button with a label instead.
import { IconButton } from "@aloxe/react";
import { Pencil, Trash2 } from "lucide-react";
export default function IconButtonVariants() {
return (
<div className="flex flex-wrap items-center gap-3">
<IconButton variant="secondary" aria-label="Edit">
<Pencil />
</IconButton>
<IconButton variant="ghost" aria-label="Delete">
<Trash2 />
</IconButton>
</div>
);
}Installation
npm i @aloxe/react @aloxe/tokensThen add the CSS imports from Installation.
Usage
import { IconButton } from "@aloxe/react";
import { Pencil } from "lucide-react";
<IconButton aria-label="Edit">
<Pencil />
</IconButton>aria-label is required: leaving it out is a TypeScript error. Pass any 24 px icon, such as one from lucide-react; the button sizes it.
Examples
Sizes
32, 40 and 48 px square, matching the Button heights so they line up in a row.
import { IconButton } from "@aloxe/react";
import { Settings } from "lucide-react";
export default function IconButtonSizes() {
return (
<div className="flex flex-wrap items-center gap-3">
<IconButton variant="secondary" size="sm" aria-label="Settings">
<Settings />
</IconButton>
<IconButton variant="secondary" size="md" aria-label="Settings">
<Settings />
</IconButton>
<IconButton variant="secondary" size="lg" aria-label="Settings">
<Settings />
</IconButton>
</div>
);
}With a tooltip
Repeat the label in a Tooltip so sighted mouse and keyboard users can read it too.
import { IconButton, Tooltip } from "@aloxe/react";
import { Bold, Italic, Underline } from "lucide-react";
export default function IconButtonWithTooltip() {
return (
<div role="toolbar" aria-label="Text formatting" className="flex items-center gap-1">
<Tooltip content="Bold">
<IconButton aria-label="Bold">
<Bold />
</IconButton>
</Tooltip>
<Tooltip content="Italic">
<IconButton aria-label="Italic">
<Italic />
</IconButton>
</Tooltip>
<Tooltip content="Underline">
<IconButton aria-label="Underline">
<Underline />
</IconButton>
</Tooltip>
</div>
);
}States
Loading replaces the icon with a spinner and keeps the button focusable. Change the label while loading so screen readers hear what is happening.
import { IconButton } from "@aloxe/react";
import { RefreshCw } from "lucide-react";
export default function IconButtonStates() {
return (
<div className="flex flex-wrap items-center gap-3">
<IconButton variant="secondary" aria-label="Refresh">
<RefreshCw />
</IconButton>
<IconButton variant="secondary" aria-label="Refreshing" loading>
<RefreshCw />
</IconButton>
<IconButton variant="secondary" aria-label="Refresh" disabled>
<RefreshCw />
</IconButton>
</div>
);
}Accessibility
| Key | Action |
|---|---|
| Tab | Moves focus to the button. |
| Enter or Space | Activates the button. |
aria-labelis the only name a screen reader gets. Name the action ("Delete invoice"), not the icon ("Trash").- The icon is hidden from assistive technology.
- Every size is at least 32 × 32 px, above the 24 px minimum target size.
API reference
Every part accepts className and renders a data-aloxe attribute you can target in CSS, such as [data-aloxe="icon-button"].
IconButton
Extends Base UI Button.
| Prop | Type | Default | Description |
|---|---|---|---|
| aria-label (required) | string | The accessible name. Required by the type because the button has no visible text. | |
| children (required) | ReactElement | One icon, e.g. a lucide-react icon. It is hidden from assistive technology. | |
| variant | "secondary" | "ghost" | "ghost" | Secondary has a border and surface; ghost is transparent until hovered. |
| size | "sm" | "md" | "lg" | "md" | 32, 40 or 48 px square. The icon is 16 px (sm, md) or 20 px (lg). |
| loading | boolean | false | Replaces the icon with a spinner and blocks clicks; the button stays focusable. |
| disabled | boolean | false | Disables the button. |
| className | string | Merged with the default classes. |
Figma
Matches the Icon button component set. Figma Variant (Secondary, Ghost) maps to variant and Size to size. The Figma Icon swap property is the children icon.
See Figma for where to get the file and how its names map to code.