IconButton
A button with an icon and no word. Its label is both the accessible name and the tooltip.
import { IconButton } from '@adecore/ui';import { ButtonGroup, IconButton, Separator, shortcut } from '@adecore/ui';
import { Bold, ChevronRight, Italic, RefreshCw, Settings, Trash } from 'lucide-react';
import { useState } from 'react';
const REFRESH = shortcut('Mod+R');
export default function IconButtonDemo() {
const [bold, setBold] = useState(true);
const [italic, setItalic] = useState(false);
const [refreshing, setRefreshing] = useState(false);
const [open, setOpen] = useState(false);
const refresh = (): void => {
setRefreshing(true);
window.setTimeout(() => setRefreshing(false), 1200);
};
return (
<div className="flex items-center gap-2">
<ButtonGroup>
<IconButton icon={Bold} label="Bold" aria-pressed={bold} onClick={() => setBold(!bold)} />
<IconButton icon={Italic} label="Italic" aria-pressed={italic} onClick={() => setItalic(!italic)} />
</ButtonGroup>
<Separator />
<IconButton icon={RefreshCw} label="Refresh" kbd={REFRESH} busy={refreshing} onClick={refresh} />
<IconButton
icon={ChevronRight}
label={open ? 'Collapse' : 'Expand'}
aria-expanded={open}
iconClassName={open ? 'rotate-90 transition-transform' : 'transition-transform'}
onClick={() => setOpen(!open)}
/>
<IconButton icon={Settings} label="Settings" tooltipSide="bottom" />
<IconButton icon={Trash} label="Delete" tooltip="Nothing is selected" aria-disabled />
</div>
);
}Sizes
The size sets the square, radius and icon: a 16 pixel icon in the default 32 pixel square, 14 in 28 (sm), and 12 in 24 (xs) and 20 (2xs). Never set a height, width or radius. To widen it for a word passed as children, use w-auto.
import { IconButton } from '@adecore/ui';
import { Plus } from 'lucide-react';
export default function IconButtonSizes() {
return (
<div className="flex items-center gap-3">
<IconButton icon={Plus} label="Add (32, icon 16)" />
<IconButton icon={Plus} label="Add (28, icon 14)" size="sm" />
<IconButton icon={Plus} label="Add (24, icon 12)" size="xs" />
<IconButton icon={Plus} label="Add (20, icon 12)" size="2xs" />
<IconButton icon={Plus} label="Add a file" className="w-auto gap-1.5 px-2 text-xs">
Add
</IconButton>
</div>
);
}State
active draws a pressed key, for a toggle that is on. For a real toggle, set aria-pressed instead; both look the same. busy replaces the icon with a Spinner.
iconClassName goes to the icon or spinner: a rotating chevron, a status tone, fill-current. For an icon of another size, pass it as children without icon.
disabled blocks the pointer, so the tooltip never opens. aria-disabled looks the same but keeps focus and the tooltip, which can say why. It does not stop onClick.
As another element
render merges the button into another element, such as a menu trigger:
<Menu.Root>
<IconButton icon={Ellipsis} label="More" render={<Menu.Trigger />} />
<Menu.Popup>...</Menu.Popup>
</Menu.Root>Props
IconButton takes every prop of a <button>, plus:
| Prop | Type | Default | |
|---|---|---|---|
label | string | Required. The accessible name, and the tooltip unless tooltip says otherwise. | |
icon | LucideIcon | ||
tooltip | ReactNode | false | label | A tooltip that says more than the name, or false for none. |
kbd | Shortcut | string | Printed in the tooltip. A Shortcut also shows under the button while the modifier is held (ShortcutHints). | |
tooltipSide | TooltipSide | 'top' | |
size | IconButtonSize | 'md' | 'md' | 'sm' | 'xs' | '2xs' |
active | boolean | false | Draws a pressed key. |
busy | boolean | false | A Spinner in place of the icon. |
iconClassName | string | Classes for the icon. | |
children | ReactNode | Drawn after the icon: a count, or a word with w-auto. | |
render | RenderProp | <button type="button" /> | Another element to be the button. |
IconButtonProps and IconButtonSize are exported types.