> Leaf UI 0.17.3 · Package: @ifhover/leaf-ui · Source: c3221834f84f2f48481a2054026b713456f8e5dc
> Browser documentation: https://ifhover.github.io/leaf-ui/en/components/button.html

> For AI agents: the complete documentation index is available at https://ifhover.github.io/leaf-ui/en/llms.txt, the full documentation bundle is available at https://ifhover.github.io/leaf-ui/en/llms-full.txt.

# Button

Trigger actions such as saving, submitting or deleting.


## Basic usage

Use button text that clearly describes the action and handle clicks through `onClick`.


Save

basic.tsx

Copy code

```tsx lineNumbers file="../../../src/examples/en/button/basic.tsx"
import { Button } from '@ifhover/leaf-ui';

export function ButtonBasic() {
  return <Button>Save</Button>;
}
```

Expand code

`type` defaults to `button`, which does not submit a form. Set `type="submit"` for form submission.


## Examples

### Appearance

Use `variant` for outline (the default), solid, text or inline link appearance. Inline links use the theme color by default, brighten on hover and darken when pressed, with a default color transition of 200ms.


Outline

Save

Solid

Save

Text

Save

Link

Save

variants.tsx

Copy code

```tsx lineNumbers file="../../../src/examples/en/button/variants.tsx"
import { Button, Flex, Grid, Text } from '@ifhover/leaf-ui';
import { Fragment } from 'react';

const options = [
  { value: 'outline', label: 'Outline' },
  { value: 'solid', label: 'Solid' },
  { value: 'text', label: 'Text' },
  { value: 'link', label: 'Link' },
] as const;

export function ButtonVariants() {
  return (
    <Grid columns={{ xs: 1, sm: 2 }} gap={16} align="center">
      {options.map(({ value, label }) => (
        <Fragment key={value}>
          <Text tone="muted">{label}</Text>
          <Flex align="center" wrap>
            <Button variant={value}>Save</Button>
          </Flex>
        </Fragment>
      ))}
    </Grid>
  );
}
```

Expand code

### Sizes

Set the size with `size`; the default is `md`.


Small

Save

Medium

Save

Large

Save

sizes.tsx

Copy code

```tsx lineNumbers file="../../../src/examples/en/button/sizes.tsx"
import { Button, Flex, Grid, Text } from '@ifhover/leaf-ui';
import { Fragment } from 'react';

const options = [
  { value: 'sm', label: 'Small' },
  { value: 'md', label: 'Medium' },
  { value: 'lg', label: 'Large' },
] as const;

export function ButtonSizes() {
  return (
    <Grid gap={16} align="center" style={{ gridTemplateColumns: 'max-content minmax(0, 1fr)' }}>
      {options.map(({ value, label }) => (
        <Fragment key={value}>
          <Text tone="muted">{label}</Text>
          <Flex align="center" wrap>
            <Button size={value}>Save</Button>
          </Flex>
        </Fragment>
      ))}
    </Grid>
  );
}
```

Expand code

### Danger actions

Set `danger` for destructive actions such as deleting or clearing. It works with every appearance.


Outline

Delete

Solid

Delete

Text

Delete

Link

Delete

danger.tsx

Copy code

```tsx lineNumbers file="../../../src/examples/en/button/danger.tsx"
import { Button, Flex, Grid, Text } from '@ifhover/leaf-ui';
import { Fragment } from 'react';

const options = [
  { value: 'outline', label: 'Outline' },
  { value: 'solid', label: 'Solid' },
  { value: 'text', label: 'Text' },
  { value: 'link', label: 'Link' },
] as const;

export function ButtonDanger() {
  return (
    <Grid columns={{ xs: 1, sm: 2 }} gap={16} align="center">
      {options.map(({ value, label }) => (
        <Fragment key={value}>
          <Text tone="muted">{label}</Text>
          <Flex align="center" wrap>
            <Button danger variant={value}>
              Delete
            </Button>
          </Flex>
        </Fragment>
      ))}
    </Grid>
  );
}
```

Expand code

### Disabled and loading

`disabled` disables the button. `loading` shows a spinner and prevents repeated clicks.


Disabled

Save

Loading

Save

states.tsx

Copy code

```tsx lineNumbers file="../../../src/examples/en/button/states.tsx"
import { Button, Flex, Grid, Text } from '@ifhover/leaf-ui';

export function ButtonStates() {
  return (
    <Grid columns={{ xs: 1, sm: 2 }} gap={16} align="center">
      <Text tone="muted">Disabled</Text>
      <Flex align="center" wrap>
        <Button disabled>Save</Button>
      </Flex>
      <Text tone="muted">Loading</Text>
      <Flex align="center" wrap>
        <Button loading>Save</Button>
      </Flex>
    </Grid>
  );
}
```

Expand code

### Icons

Add icons with `startIcon` and `endIcon`. An icon-only button needs an `aria-label`.


Small

New projectContinue

Medium

New projectContinue

Large

New projectContinue

icons.tsx

Copy code

```tsx lineNumbers file="../../../src/examples/en/button/icons.tsx"
import { Button, Flex, Grid, Text } from '@ifhover/leaf-ui';
import { ArrowRight, Plus, Trash2 } from 'lucide-react';
import { Fragment } from 'react';

const options = [
  { value: 'sm', label: 'Small' },
  { value: 'md', label: 'Medium' },
  { value: 'lg', label: 'Large' },
] as const;

export function ButtonIcons() {
  return (
    <Grid gap={16} align="center" style={{ gridTemplateColumns: 'max-content minmax(0, 1fr)' }}>
      {options.map(({ value, label }) => (
        <Fragment key={value}>
          <Text tone="muted">{label}</Text>
          <Flex align="center" gap={8} wrap>
            <Button size={value} startIcon={<Plus />}>
              New project
            </Button>
            <Button size={value} variant="outline" endIcon={<ArrowRight />}>
              Continue
            </Button>
            <Button size={value} variant="outline" aria-label="Add project" startIcon={<Plus />} />
            <Button
              size={value}
              danger
              variant="outline"
              aria-label="Delete project"
              startIcon={<Trash2 />}
            />
          </Flex>
        </Fragment>
      ))}
    </Grid>
  );
}
```

Expand code

### Full width

Set `fullWidth` to fill the parent container.


Continue

full-width.tsx

Copy code

```tsx lineNumbers file="../../../src/examples/en/button/full-width.tsx"
import { Button } from '@ifhover/leaf-ui';

export function ButtonFullWidth() {
  return <Button fullWidth>Continue</Button>;
}
```

Expand code

### Async saving

[](#)
Control `loading` with application state. The timer simulates a request; replace it with your async operation.


Save changesNot saved yet

loading.tsx

Copy code

```tsx lineNumbers file="../../../src/examples/en/button/loading.tsx"
import { Button, Flex, Text } from '@ifhover/leaf-ui';
import { useEffect, useRef, useState } from 'react';

export function ButtonLoading() {
  const [status, setStatus] = useState<'idle' | 'loading' | 'saved'>('idle');
  const timer = useRef<ReturnType<typeof setTimeout> | undefined>(undefined);

  useEffect(() => () => clearTimeout(timer.current), []);

  function save() {
    clearTimeout(timer.current);
    setStatus('loading');
    // This example simulates a request; replace it with your application request.
    timer.current = setTimeout(() => setStatus('saved'), 1200);
  }

  return (
    <Flex direction="column" gap="md" align="start">
      <Button loading={status === 'loading'} onClick={save}>
        {status === 'saved' ? 'Save again' : 'Save changes'}
      </Button>
      <Text tone="muted" role="status">
        {status === 'saved' ? 'Changes saved' : 'Not saved yet'}
      </Text>
    </Flex>
  );
}
```

Expand code

### Button group

Use `ButtonGroup` to join adjacent actions and share a size or disabled state.


PreviousNext

button-group.tsx

Copy code

```tsx lineNumbers file="../../../src/examples/en/button/button-group.tsx"
import { Button, ButtonGroup } from '@ifhover/leaf-ui';

export function ButtonGroupDemo() {
  return (
    <ButtonGroup aria-label="Step actions">
      <Button>Previous</Button>
      <Button>Next</Button>
    </ButtonGroup>
  );
}
```

Expand code

### Split button

`SplitButton` pairs a primary action with related menu actions. Use `onClick` for the primary button and an action for each menu item.


Save

split-button.tsx

Copy code

```tsx lineNumbers file="../../../src/examples/en/button/split-button.tsx"
import { Flex, SplitButton, Text } from '@ifhover/leaf-ui';
import { useState } from 'react';

export function SplitButtonDemo() {
  const [result, setResult] = useState('');

  return (
    <Flex direction="column" gap="md" align="start">
      <SplitButton
        variant="solid"
        onClick={() => setResult('Saved')}
        menuLabel="More save options"
        items={[
          { key: 'copy', label: 'Save a copy', onClick: () => setResult('Copy saved') },
          { key: 'draft', label: 'Save draft', onClick: () => setResult('Draft saved') },
        ]}
      >
        Save
      </SplitButton>
      <Text tone="muted" role="status">
        {result}
      </Text>
    </Flex>
  );
}
```

Expand code


## API

### Button API

Supports native `button` attributes such as `onClick`, `name`, `form`, `aria-*` and `data-*`.

| Property    | Type                                       | Default     | Description                                          |
| ----------- | ------------------------------------------ | ----------- | ---------------------------------------------------- |
| `variant`   | `'solid' \| 'outline' \| 'text' \| 'link'` | `'outline'` | Visual style                                         |
| `size`      | `'sm' \| 'md' \| 'lg'`                     | `'md'`      | Control size                                         |
| `danger`    | `boolean`                                  | `false`     | Danger colors; works with every variant              |
| `loading`   | `boolean`                                  | `false`     | Show loading and disable interaction                 |
| `fullWidth` | `boolean`                                  | `false`     | Fill the parent width                                |
| `startIcon` | `ReactNode`                                | —           | Leading icon; replaced by the spinner during loading |
| `endIcon`   | `ReactNode`                                | —           | Trailing icon                                        |
| `disabled`  | `boolean`                                  | `false`     | Disable interaction.                                 |
| `type`      | `'button' \| 'submit' \| 'reset'`          | `'button'`  | Native button type                                   |
| `ref`       | `Ref<HTMLButtonElement>`                   | —           | DOM reference                                        |

### ButtonGroupProps API

Props for grouping related buttons.

| Property   | Type                   | Default | Description           |
| ---------- | ---------------------- | ------- | --------------------- |
| `size`     | `'sm' \| 'md' \| 'lg'` | —       | Button size.          |
| `disabled` | `boolean`              | —       | Disable interaction.  |
| `attached` | `boolean`              | `true`  | Join adjacent buttons |

### SplitButtonProps API

Props for a button combining a primary action with dropdown actions.

| Property        | Type                                                                                                                                       | Default     | Description                        |
| --------------- | ------------------------------------------------------------------------------------------------------------------------------------------ | ----------- | ---------------------------------- |
| `variant`       | `'solid' \| 'outline' \| 'text' \| 'link'`                                                                                                 | `'outline'` | Button appearance                  |
| `size`          | `'sm' \| 'md' \| 'lg'`                                                                                                                     | `'md'`      | Button size.                       |
| `danger`        | `boolean`                                                                                                                                  | `false`     | Danger colors                      |
| `loading`       | `boolean`                                                                                                                                  | `false`     | Loading state                      |
| `fullWidth`     | `boolean`                                                                                                                                  | `false`     | Fill available width               |
| `startIcon`     | `ReactNode`                                                                                                                                | —           | Leading icon                       |
| `endIcon`       | `ReactNode`                                                                                                                                | —           | Trailing icon                      |
| `items`         | `readonly `[`DropdownItem`](https://ifhover.github.io/leaf-ui/en/components/dropdown.md#dropdownitem)`[]`                                  | Required    | Items; keep keys unique and stable |
| `menuLabel`     | `string`                                                                                                                                   | —           | Accessible menu button label       |
| `dropdownProps` | `Omit<`[`DropdownProps`](https://ifhover.github.io/leaf-ui/en/components/dropdown.md#dropdown-api)`, 'items' \| 'children' \| 'disabled'>` | —           | Action menu props                  |
