Actions
Icon Button
Compact square action for toolbars, topbars and table rows.
react-aria-components
Preview
"use client";
import { Bell, CircleHelp, MoreHorizontal, Plus } from "lucide-react";
import { IconButton } from "@/components/ui/icon-button";
export default function Example() {
return (
<div className="flex items-center gap-2">
<IconButton aria-label="Help"><CircleHelp /></IconButton>
<IconButton aria-label="Notifications"><Bell /></IconButton>
<IconButton variant="ghost" size="sm" aria-label="Add"><Plus /></IconButton>
<IconButton variant="ghost" size="sm" aria-label="More"><MoreHorizontal /></IconButton>
</div>
);
}Installation
Components are copied into your project — no runtime package.
Install the following dependencies:
terminalnpm install react-aria-componentsCreate a
icon-button.tsxfile and paste the following code into it.src/components/ui/icon-button.tsx"use client"; import type { ReactNode } from "react"; import { Button as AriaButton, type ButtonProps as AriaButtonProps } from "react-aria-components"; import { cx } from "@/utils/cx"; export interface IconButtonProps extends Omit<AriaButtonProps, "className" | "children"> { /** Accessible name — icon buttons have no visible text. */ "aria-label": string; variant?: "secondary" | "ghost"; size?: "xs" | "sm" | "md"; className?: string; children: ReactNode; } const sizes = { xs: "size-7 rounded-sm", sm: "size-8 rounded-sm", md: "size-9 rounded-[10px]" }; /** Compact square action used in toolbars, topbars and table rows. */ export function IconButton({ variant = "secondary", size = "md", className, children, ...props }: IconButtonProps) { return ( <AriaButton {...props} className={cx( "inline-flex shrink-0 cursor-default items-center justify-center text-fg-secondary outline-none transition-colors", "data-focus-visible:ring-3 data-focus-visible:ring-accent/25 data-disabled:text-fg-disabled [&_svg]:size-4", variant === "secondary" ? "bg-surface shadow-button data-hovered:bg-subtle data-hovered:text-fg data-pressed:bg-active" : "data-hovered:bg-muted data-hovered:text-fg data-pressed:bg-active", sizes[size], className, )} > {children} </AriaButton> ); }Add the theme tokens and the
cxhelper from Installation if you haven’t yet, then update the import paths to match your project setup.
Props
| Prop | Type | Default | Description |
|---|---|---|---|
| aria-label | string | — | Required accessible name. |
| variant | "secondary" | "ghost" | "secondary" | Raised or flat. |
| size | "xs" | "sm" | "md" | "md" | 28, 32 or 36px. |