# IconButton

> Square or circular icon-only button built on Button, with a required accessible label.

- Package: `fancy-ui-react` (React 18/19 + Tailwind CSS v4)
- Category: Actions
- Tags: button, icon, action, accessibility
- Dependencies: button
- Types: `IconButtonProps`, `IconButtonShape`
- Docs: https://fancy-ui.rama.app/docs/components/icon-button
- Source: https://github.com/RamaHerbin/fancy-ui/tree/main/react/src/components/icon-button

## Import

```tsx
import { IconButton } from 'fancy-ui-react';
```

Setup (once per project): `npm install fancy-ui-react`, then put these lines in your main CSS file (the stylesheet import goes right after `@import "tailwindcss";`):

```css
@import "tailwindcss";
@import "fancy-ui-react/tailwind.css";
```

and import the component styles once in the app entry: `import "fancy-ui-react/styles.css";`. Full guide: https://fancy-ui.rama.app/llms.txt

The names below are the ones to write in React; when one differs from the Svelte name, the Svelte name follows in parentheses. `class` becomes `className`, a callback takes the name the React port declares (`onclick` becomes `onClick`), snippets become `ReactNode` props (render functions when they take arguments) and the default snippet is `children`. Divergences: https://github.com/RamaHerbin/fancy-ui/tree/main/react#divergences-from-the-svelte-api

## Props

| Prop | Type | Default | Description |
| --- | --- | --- | --- |
| `label` (required) | `string` | — | Accessible name. Required — there is no visible text to fall back on |
| `variant` | `"primary" \| "secondary" \| "outline" \| "ghost" \| "accent" \| "destructive"` | `"outline"` | Visual treatment, forwarded to the underlying Button |
| `size` | `"sm" \| "md" \| "lg"` | `"md"` | Square footprint (30 / 36 / 42px) and resting radius |
| `shape` | `"square" \| "circle"` | `"square"` | Square keeps the size's own radius; circle rounds it fully |
| `type` | `"button" \| "submit" \| "reset"` | `"button"` | Native type; ignored once href renders an anchor instead |
| `disabled` | `boolean` | `false` | Greys the control out and blocks activation |
| `loading` | `boolean` | `false` | Spinner in place of the icon, aria-busy, blocks activation |
| `href` | `string` | — | Renders an <a> instead of a <button> when set |
| `target` | `string` | — | Anchor target. "_blank" forces a safe rel |
| `rel` | `string` | — | Anchor rel, widened rather than replaced when target="_blank" |
| `onClick` (Svelte `onclick`) | `(event: MouseEvent) => void` | — | Fires on activation; never called while disabled or loading |
| `className` (Svelte `class`) | `string` | — | Additional CSS classes |
| `ref` | `HTMLButtonElement \| HTMLAnchorElement \| null` | `null` | Bindable element reference |
| `sound` | `boolean` | `false` | Plays the press cue on activation, once the user has enabled sound |

## Node props

| Prop | Description |
| --- | --- |
| `children` | The icon, rendered centred |

## Example

```tsx
import { useState } from "react";
import { IconButton } from "fancy-ui-react";

export function IconButtonExample() {
	const [liked, setLiked] = useState(false);

	return (
		<IconButton
			sound
			label={liked ? "Unlike" : "Like"}
			variant={liked ? "accent" : "outline"}
			shape="circle"
			onClick={() => setLiked((value) => !value)}
		>
			<svg
				className="size-4"
				viewBox="0 0 24 24"
				fill={liked ? "currentColor" : "none"}
				stroke="currentColor"
				strokeWidth="2"
				strokeLinecap="round"
				strokeLinejoin="round"
				aria-hidden="true"
			>
				<path d="M12 20s-7-4.35-9.5-9A5.5 5.5 0 0 1 12 6a5.5 5.5 0 0 1 9.5 5c-2.5 4.65-9.5 9-9.5 9Z" />
			</svg>
		</IconButton>
	);
}
```
