# Button

> The foundational push-button: six variants, three sizes, a loading state, and a polymorphic href/anchor mode.

- Package: `fancy-ui-react` (React 18/19 + Tailwind CSS v4)
- Category: Actions
- Tags: button, cta, actions, form, link, loading, icon
- Types: `ButtonProps`, `ButtonVariant`, `ButtonSize`
- Docs: https://fancy-ui.rama.app/docs/components/button
- Source: https://github.com/RamaHerbin/fancy-ui/tree/main/react/src/components/button

## Import

```tsx
import { Button } 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 |
| --- | --- | --- | --- |
| `variant` | `"primary" \| "secondary" \| "outline" \| "ghost" \| "accent" \| "destructive"` | `"primary"` | Visual treatment |
| `size` | `"sm" \| "md" \| "lg"` | `"md"` | Padding / font-size / radius scale |
| `type` | `"button" \| "submit" \| "reset"` | `"button"` | Native type; ignored once href renders an anchor instead |
| `disabled` | `boolean` | `false` | Greys the button out and blocks activation |
| `loading` | `boolean` | `false` | Spinner in place of iconStart, aria-busy, inert to activation on both the button and anchor branch — does not dim the button |
| `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" |
| `fullWidth` | `boolean` | `false` | Stretches the button to its container's width |
| `label` | `string` | — | Accessible name for a button whose content is icon-only |
| `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 button's label / content |
| `iconStart` | Rendered before the label; replaced by the spinner while loading |
| `iconEnd` | Rendered after the label |

## Example

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

export function ButtonExample() {
	const [count, setCount] = useState(0);

	return (
		<Button sound onClick={() => setCount((n) => n + 1)}>
			Clicked {count} {count === 1 ? "time" : "times"}
		</Button>
	);
}
```
