# IconButton

> Cherry IconButton component - a circular icon-only button with three sizes, an error variant, and an active toggle state.

Source: https://cherry.al/code/icon-button

> For the complete documentation index, see [llms.txt](https://cherry.al/llms.txt).

# IconButton

<iframe className="light-only" src="https://demo.cherry.al/preview/icon-button?theme=light" title="Icon button" loading="lazy" style={{ width: "100%", height: "320px", border: "1px solid var(--color-grayLight)", borderRadius: "12px" }} />
<iframe className="dark-only" src="https://demo.cherry.al/preview/icon-button?theme=dark" title="Icon button" loading="lazy" style={{ width: "100%", height: "320px", border: "1px solid var(--color-grayLight)", borderRadius: "12px" }} />

The IconButton component is a circular, icon-only button for compact actions like edit, delete, or settings.

Keep in mind that the `<button>` element inherently includes native browser properties like `onClick`. Cherry UI components introduce custom properties that always begin with a `$` to distinguish them from native props.

Because the button has no visible text, the `aria-label` property is required.

For design guidelines and all interactive states, see the [Buttons](/buttons) design page.

```jsx
import React from "react";
import { Icon, IconButton } from "cherry-styled-components";

export default function Page() {
  return (
    <IconButton aria-label="Settings">
      <Icon name="Settings" />
    </IconButton>
  );
}
```

With sizes:

```html
<IconButton $size="small" aria-label="Edit">
  <Icon name="Pencil" />
</IconButton>
<IconButton $size="big" aria-label="Add">
  <Icon name="Plus" />
</IconButton>
```

For destructive actions, use the error variant:

```html
<IconButton $error aria-label="Delete">
  <Icon name="Trash2" />
</IconButton>
```

For toggle-like actions that stay "on" (a dropzone that is open, a preview
that is active), use `$active`. The button keeps its primary border with a
subtle tint, and the state is exposed to assistive technology via
`aria-pressed` automatically:

```html
<IconButton $active={isPreviewOpen} aria-label="Toggle preview">
  <Icon name="Eye" />
</IconButton>
```

## Properties

<Field value="children" type="React.ReactNode">
  The icon to render, typically a Cherry `Icon`. It is sized automatically per
  `$size` (12px, 14px, or 16px).
</Field>

<Field value="aria-label" type="string" required>
  Accessible label describing the action. Required because the button has no
  visible text.
</Field>

<Field value="type" type='"button" | "submit" | "reset"'>
  Defaults to `"button"` (instead of the native `"submit"`) so the button does
  not accidentally submit a surrounding form. Pass `type="submit"` to override.
</Field>

<Field value="$size" type='"default" | "big" | "small"'>
  Size of the button: 24px (small), 28px (default), or 32px (big).
</Field>

<Field value="$error" type="boolean">
  Renders the button in the theme's error color for destructive actions.
</Field>

<Field value="$active" type="boolean">
  Marks the button as being in an "on" state: primary border, tinted
  background, and primary icon color. When set (true or false), the value is
  also reflected as `aria-pressed` so screen readers announce the toggle
  state. The active styling is ignored while `disabled`, but `aria-pressed`
  is still emitted.
</Field>

## iconButtonStyles

The css helper behind the component is also exported as
`iconButtonStyles(theme, $size, $error, disabled, $active)`. Use it to apply
the exact IconButton look to a custom styled component:

```tsx
import styled from "styled-components";
import { iconButtonStyles } from "cherry-styled-components";

const RoundLink = styled.a`
  ${({ theme }) => iconButtonStyles(theme, "big")};
`;
```

<Button href="https://github.com/cherry-design-system/styled-components/blob/main/src/lib/icon-button.tsx" icon="code" iconPosition="left">
  View Source
</Button>
