# Button

A powerful and composable button component for your application.

```tsx
import { Button } from '@fluxui-dev/react';

<Button>Button</Button>
```

## Variants

Use the `variant` prop to change the visual style of the button.

```tsx
<Button>Default</Button>
<Button variant="primary">Primary</Button>
<Button variant="filled">Filled</Button>
<Button variant="danger">Danger</Button>
<Button variant="ghost">Ghost</Button>
<Button variant="subtle">Subtle</Button>
```

## Colors

Use standard Tailwind color names with the `color` prop. Color works independently with primary, filled, outline, ghost, and subtle buttons.

> [!TIP]
> Neutral colors use the default styling for filled, outline, ghost, and subtle buttons.

```tsx
<Button variant="primary" color="blue">Primary</Button>
<Button variant="filled" color="blue">Filled</Button>
<Button variant="outline" color="blue">Outline</Button>
<Button variant="ghost" color="blue">Ghost</Button>
<Button variant="subtle" color="blue">Subtle</Button>
```

## Outline colors

Colored outline buttons keep the default surface and shadow while softly mixing the selected color into the label, border, and hover state.

```tsx
<Button variant="outline" color="blue">Blue</Button>
<Button variant="outline" color="green">Green</Button>
<Button variant="outline" color="red">Red</Button>
```

## Sizes

The default button size works great for most cases, but here are some additional size options for unique situations.

```tsx
<Button>Base</Button>
<Button size="sm">Small</Button>
<Button size="xs">Extra small</Button>
```

## Icons

Automatically sized and styled icons for your buttons, passed as components via `icon` and `iconTrailing`.

```tsx
import { ArrowDownTrayIcon, ChevronDownIcon, EllipsisHorizontalIcon, XMarkIcon } from '@fluxui-dev/react/icons';

<Button icon={EllipsisHorizontalIcon} />
<Button icon={ArrowDownTrayIcon}>Export</Button>
<Button iconTrailing={ChevronDownIcon}>Open</Button>
<Button icon={XMarkIcon} variant="subtle" />
```

## Loading

Buttons with `type="submit"` inside an Inertia `<Form>` will automatically show a loading indicator and disable pointer events while the form processes. See the [Inertia guide](https://fluxui.dev/react/docs/inertia).

Pass the `loading` prop to show the spinner yourself, such as with `useForm`; a button with `loading` no longer follows its form.

```tsx
<Button type="submit" loading={processing}>
    Save changes
</Button>
```

## Full width

A button that spans the full width of the container.

```tsx
<Button variant="primary" className="w-full">Send invite</Button>
```

## As a link

Display an HTML `a` tag as a button by passing the `href` prop.

```tsx
import { ArrowUpRightIcon } from '@fluxui-dev/react/icons';

<Button
    href="https://google.com"
    iconTrailing={ArrowUpRightIcon}
>
    Visit Google
</Button>
```

## Square

Make the height and width of a button equal. Flux does this automatically for icon-only buttons.

```tsx
<Button square>...</Button>
```

## Inset

When using `ghost` or `subtle` button variants, you can use the `inset` prop to negate any invisible padding for better alignment.

```tsx
import { Heading } from '@fluxui-dev/react';

<div className="flex justify-between">
    <Heading>Post successfully created.</Heading>

    <Button size="sm" icon={XMarkIcon} variant="ghost" inset aria-label="Dismiss" />
</div>
```

## Reference

### Button

**Prop:**

- `href` - The URL to link to. When set, the button renders as an `a` tag. An in-app URL navigates through the link registered in `FluxProvider`.
- `render` - Element to render instead of the button (such as a router link with props `href` can't carry), with the button's props merged in. Also accepts a function that receives the props and returns an element.
- `type` - The HTML `type` attribute of the button. Options: `button` (default), `submit`, `reset`.
- `variant` - Visual style of the button. Options: `outline`, `primary`, `filled`, `danger`, `ghost`, `subtle`. Default: `outline`.
- `color` - Color of the button. Accepts standard Tailwind color names. Chromatic colors work with `primary`, `filled`, `outline`, `ghost`, and `subtle`; neutral colors use the default styling outside of `primary`.
- `size` - Size of the button. Options: `base` (default), `sm`, `xs`.
- `icon` - Icon to display at the start of the button: a component, such as `ArrowDownTrayIcon` from `@fluxui-dev/react/icons` or an icon from `lucide-react`, or an element, such as `<img />`, rendered as is.
- `iconVariant` - Visual style of the button's icons. Options: `outline`, `solid`, `mini`, `micro`. Default: `micro`, or `mini` for square buttons other than `xs`.
- `iconTrailing` - Icon to display at the end of the button: a component or an element.
- `iconTrailingVariant` - Visual style of the trailing icon. Default: the value of `iconVariant`.
- `square` - If `true`, makes the button square. (Useful for icon-only buttons.)
- `align` - Alignment of the button content. Options: `start`, `center`, `end`. Default: `center`.
- `inset` - Add negative margins to all or specific sides. Options: `true` (all sides), `top`, `bottom`, `left`, `right`, or a space-separated combination such as `"top left"`.
- `loading` - If `true`, shows a loading spinner in place of the button's content and ignores clicks, from the keyboard too. A submit button inside an Inertia `<Form>` follows the form's processing state when `FluxProvider` has `processing`, unless `loading` is passed.
- `tooltip` - Text to display in a tooltip when hovering over or focusing the button. Pass a `Tooltip` element without children, such as `<Tooltip content="Sort" position="bottom" />`, to set its options.
- `kbd` - Keyboard shortcut hint shown at the end of the button, such as `⌘S`.

**CSS:**

- `className` - Additional CSS classes applied to the button. Common use: `w-full` for full width.

**Attribute:**

- `data-flux-button` - Applied to the root element for styling and identification.
