IconButton
import { IconButton } from "@cherry-design-system/react";
import { Search } from "lucide-react";
export function SearchButton() {
return <IconButton aria-label="Search" icon={<Search />} />;
}A square button that shows only an icon, for toolbars, close buttons and compact actions. It requires an aria-label. Use Button when the action has a visible text label.
IconButton ships no client JavaScript, so it renders in React Server Components.
Examples
Variants
import { IconButton } from "@cherry-design-system/react";
import { Settings } from "lucide-react";
export function Variants() {
return (
<>
<IconButton aria-label="Settings" icon={<Settings />} variant="ghost" />
<IconButton aria-label="Settings" icon={<Settings />} variant="outline" />
<IconButton aria-label="Settings" icon={<Settings />} variant="solid" />
</>
);
}Sizes
import { IconButton } from "@cherry-design-system/react";
import { X } from "lucide-react";
export function Sizes() {
return (
<>
<IconButton aria-label="Close" icon={<X />} size="sm" />
<IconButton aria-label="Close" icon={<X />} size="md" />
<IconButton aria-label="Close" icon={<X />} size="lg" />
</>
);
}As a toggle
Pass aria-pressed to make it a toggle button.
"use client";
import { useState } from "react";
import { IconButton } from "@cherry-design-system/react";
import { Bold } from "lucide-react";
export function BoldToggle() {
const [on, setOn] = useState(false);
return (
<IconButton
aria-label="Bold"
aria-pressed={on}
icon={<Bold />}
variant="outline"
onClick={() => setOn((v) => !v)}
/>
);
}Properties
Accessible name. Required: icon-only buttons need one.
The icon element, for example <X />.
Visual style. Defaults to "ghost".
Button size. Defaults to "md".
Renders a <button> and forwards its ref to it. All native <button> attributes pass through except children (use icon). type defaults to "button".
Styling
Root class cherry-icon-button with data-variant (ghost, outline, solid) and data-size (sm, md, lg). States: disabled, aria-pressed, :hover, :active, :focus-visible.
Reads --cherry-ghost-hover, --cherry-primary-* (solid), --cherry-border-default (outline) and --cherry-ring.
Accessibility
aria-label is required because the glyph carries no text for screen readers. As a toggle, pass aria-pressed so the on/off state is announced.