# Button

The button triggers an action in response to a press.

Button is documented for `@woodger/antd` 0.1.5 and Svelte 5. [Getting started](/ant-design/development/index.md) · [Interactive documentation](/ant-design/components/button)

## When to use {#button-usage}

Button triggers an action: saves data, opens a window, adds a record, or submits a form. The caption should explain the result of the click: “Save changes” is clearer than “OK”.

- Primary button highlights the main action. In one action group, one main button is usually sufficient.
- Regular buttons are suitable for equivalent actions; text - for secondary ones.
- The dotted button is convenient to use to add an element.
- To go to another page, pass `href`: the component will create a real link. If the user selects one of the values, consider [Radio](/ant-design/components/radio) or [Select](/ant-design/components/select).


[Button CSS Prefixes](#button-demo-prefix) show global [ConfigProvider.prefixCls](/ant-design/components/config-provider#config-provider-prefix) and local `prefixCls` without resetting state. Local `prefixCls` is the full prefix of the button, without automatically adding `-btn`. The button container and internal variables use the shared provider prefix.

## How to choose the design {#button-appearance}

Start with the action role, then choose a design. `type` specifies a ready-made option; `color` and `variant` allow you to customize the color and display method separately.

| Problem | Setting | Working example |
| --- | --- | --- |
| Main action | `type="primary"` | [Types of buttons](#button-demo-basic) |
| Equivalent action | `type="default"` | [Multiple buttons](#button-demo-multiple) |
| Add element | `type="dashed"` | [Types of buttons](#button-demo-basic) |
| Secondary Action | `type="text"` | [Types of buttons](#button-demo-basic) |
| Custom color and fill | `color` and `variant` | [Color and option](#button-demo-color-variant) |

`type="primary"` corresponds to the combination `color="primary" variant="solid"`. Explicit `color` and `variant` take precedence. For removal and other risky actions, use `danger`; If you specify `color` at the same time, consider its priority.

`ghost` changes the design of the button on a complex background, and `block` stretches it to the width of the container. The size is set via `size` or general settings [ConfigProvider](/ant-design/components/config-provider). These properties do not change the meaning of the action or the way the event is processed.

The icon is transmitted via `icon` as Svelte snippet; `iconPlacement` sets the side. For an icon-only button, provide an accessible name via `aria-label`. [Example of icons](#button-demo-icon) contains both tracks and their source code.

## Actions, links and expectations {#button-interaction}

Without `href`, the component creates a native `button`. Its `htmlType` defaults to `button`, so it doesn't submit the surrounding form accidentally. To send [Form](/ant-design/components/form) use `htmlType="submit"`, to reset use `htmlType="reset"`.

With `href` a native `a` is created: opening in a new tab, copying the address, `target` and `rel` work. The `type="link"` design itself without `href` remains an action button. [Example states](#button-demo-features) shows the transition and click handler.

The `onclick` handler receives a native event. To cancel the link transition, call `event.preventDefault()`. `bind:nativeElement` provides a button or link after mount; with SSR there is no DOM element yet.

The `loading` state belongs to the application: enable it before the request and disable it after completion. The `loading` object allows you to delay the appearance of the indicator through `delay` so that the short operation does not flash. The component does not fire the request and does not track the `Promise` handler. [Loading](#button-demo-loading) shows switching and delay.

On a button without an icon, the default loading indicator animates in and out. Both `theme.token.motion=false` and `prefers-reduced-motion` disable that transition. Buttons and links keep focus through hydration.

For individual theme customization use [design tokens](/ant-design/design#design-tokens) [for Button](#button-design-token) and for specific button part use supported `classNames` and `styles` from [Semantic DOM](#button-semantic-dom). CSS strings are passed to `styles`; A JavaScript object with CSS properties is not used here.

## FAQ {#button-faq}

### Why does loading make the button unavailable?

In the current `@woodger/antd` native `button` receives `disabled` and `aria-busy` when the loading indicator is turned on. It stops accepting clicks and is excluded from the Tab order. For the link with `href`, loading cancels the transition. This is a feature of the behavior of our implementation; Don't use downloading as a substitute for checking if you're allowed to perform an action.

### How to properly disable the action?

Pass `disabled` if the action is not available. For a button with `href`, the library blocks the transition and excludes the link from the Tab order. Color and appearance alone do not prohibit clicking. [Unavailable states](#button-demo-disabled) can be compared to ordinary buttons.

### Why doesn't the main color change via `type`?

Check whether `color` and `variant` are set at the same time, including the [ConfigProvider.button](/ant-design/components/config-provider#config-provider-settings) settings. For non-standard design, use an explicit property pair and [example of color and option](#button-demo-color-variant). Individual button tokens and the general theme palette solve different problems.

### How to remove the space between two Chinese characters?

Set `autoInsertSpace={false}` to Button or [ConfigProvider.button](/ant-design/components/config-provider#config-provider-settings). This setting refers to the automatic spacing in a short Chinese signature; It does not remove spaces within your text.

### How to disable or replace the wave when pressed?

Pass `wave={{ disabled: true }}` to [ConfigProvider](/ant-design/components/config-provider). Its effect is set via `wave.showEffect`; animations and created DOM nodes are released by the owner of the callback. [Example of your own wave](#button-demo-wave) shows both options and takes reduced motion into account.

The buttons below allow you to compare the equivalent `type` and `color + variant`, as well as pressing without a wave.

## Examples {#button-examples}

### Button types {#button-demo-basic}

Basic, normal, dotted, text button and link. Highlight the main action with your main style.

```svelte
<script lang="ts">
  import { Button } from '@woodger/antd';

  let action = $state(("Press the button to check the action."));
  const buttons = [
    { type: 'primary', label: "Main", message: "The main button is pressed." },
    { type: 'default', label: "Regular", message: "A normal button is pressed." },
    { type: 'dashed', label: "Dotted", message: "The dotted button is pressed." },
    { type: 'text', label: "Text", message: "Text button pressed." },
    { type: 'link', label: "Link", message: "Link button pressed." }
  ] as const;
</script>

<style>
  .row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
  }
  .status-line {
    margin-top: 16px;
    color: var(--ant-color-text-secondary);
    font-size: 12px;
  }
</style>

<div class="row">
  {#each buttons as button (button.type)}
    <Button type={button.type} onclick={() => { action = button.message; }}>{(button.label)}</Button>
  {/each}
</div>
<div class="status-line" role="status">{action}</div>
```

### Colors and options {#button-demo-color-variant}

The `color` and `variant` are set independently: fill, frame, dotted line, text or link.

```svelte
<script lang="ts">
  import { onMount } from 'svelte';
  import { Button, ConfigProvider } from '@woodger/antd';

  let isWide = $state(false);
  const colors = ['default', 'primary', 'danger', 'pink', 'purple', 'cyan'] as const;
  const variants = ['solid', 'outlined', 'dashed', 'filled', 'text', 'link'] as const;

  onMount(() => {
    const query = window.matchMedia('(min-width: 1600px)');
    const updateSize = () => { isWide = query.matches; };
    updateSize();
    query.addEventListener('change', updateSize);

    return () => query.removeEventListener('change', updateSize);
  });
</script>

<style>
  .matrix {
    display: grid;
    gap: 16px;
  }
  .row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
  }
</style>

<ConfigProvider componentSize={isWide ? 'medium' : 'small'}>
  <div class="matrix">
    {#each colors as color (color)}
      <div class="row" role="group" aria-label={("Color " + String((color)) + "")}>
        {#each variants as variant (variant)}
          <Button
            {color}
            {variant}
            aria-label={("" + String((color)) + ": " + String((variant)) + "")}
          >{(variant)}</Button>
        {/each}
      </div>
    {/each}
  </div>
</ConfigProvider>
```

### Icons {#button-demo-icon}

Pass the icon via `snippet` `icon`. For a button without text, give it an accessible name using `aria-label`.

```svelte
<script lang="ts">
  import { Button, Tooltip } from '@woodger/antd';
</script>

<style>
  .stack {
    display: grid;
    gap: 16px;
  }
  .row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
  }
</style>

{#snippet searchIcon()}
  <svg width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor"
    stroke-width="1.75" aria-hidden="true" focusable="false" style="display:block">
    <circle cx="10.5" cy="10.5" r="7" /><path d="m16 16 5 5" />
  </svg>
{/snippet}

<div class="stack">
  <div class="row">
    <Tooltip title={("Search")}><Button type="primary" shape="circle" icon={searchIcon}
      aria-label={("Search, main round")} /></Tooltip>
    <Button type="primary" shape="circle">A</Button>
    <Button type="primary" icon={searchIcon}>{("Search")}</Button>
    <Tooltip title={("Search")}><Button shape="circle" icon={searchIcon}
      aria-label={("Search, round")} /></Tooltip>
    <Button icon={searchIcon}>{("Search")}</Button>
  </div>
  <div class="row">
    <Tooltip title={("Search")}><Button shape="circle" icon={searchIcon}
      aria-label={("Search, additional round")} /></Tooltip>
    <Button icon={searchIcon}>{("Search")}</Button>
    <Tooltip title={("Search")}><Button type="dashed" shape="circle" icon={searchIcon}
      aria-label={("Search, dotted round")} /></Tooltip>
    <Button type="dashed" icon={searchIcon}>{("Search")}</Button>
    <Button href={("/ant-design#overview")} icon={searchIcon} aria-label={("Go to review with icon")} />
  </div>
</div>
```

### Icon location {#button-demo-icon-placement}

`iconPlacement` places an icon before or after the caption. The position of the loading indicator changes along with it.

```svelte
<script lang="ts">
  import { Button, Divider, RadioGroup, Tooltip } from '@woodger/antd';

  let position = $state<'start' | 'end'>('end');
</script>

<style>
  .stack {
    display: grid;
    gap: 16px;
  }
  .row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
  }
</style>

{#snippet searchIcon()}
  <svg width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor"
    stroke-width="1.75" aria-hidden="true" focusable="false" style="display:block">
    <circle cx="10.5" cy="10.5" r="7" /><path d="m16 16 5 5" />
  </svg>
{/snippet}

<div class="stack">
  <RadioGroup
    aria-label={("Icon location")}
    optionType="button"
    value={position}
    options={([{ value: 'start', label: "At the beginning" }, {
      value: 'end',
      label: "At the end"
    }])}
    onValueChange={value => { if (value === 'start' || value === 'end') position = value; }}
  />
  <Divider titlePlacement="start" plain>{("Preview")}</Divider>
  <div class="row">
    <Tooltip title={("Search")}><Button type="primary" shape="circle" icon={searchIcon}
      aria-label={("Search, main round")} /></Tooltip>
    <Button type="primary" shape="circle">A</Button>
    <Button
      type="primary"
      icon={searchIcon}
      iconPlacement={position}
    >{("Search")}</Button>
    <Tooltip title={("Search")}><Button shape="circle" icon={searchIcon}
      aria-label={("Search, round")} /></Tooltip>
    <Button icon={searchIcon} iconPlacement={position}>{("Search")}</Button>
  </div>
  <div class="row">
    <Tooltip title={("Search")}><Button shape="circle" icon={searchIcon}
      aria-label={("Search, additional round")} /></Tooltip>
    <Button type="text" icon={searchIcon} iconPlacement={position}>{("Search")}</Button>
    <Tooltip title={("Search")}><Button type="dashed" shape="circle" icon={searchIcon}
      aria-label={("Search, dotted round")} /></Tooltip>
    <Button
      type="dashed"
      icon={searchIcon}
      iconPlacement={position}
    >{("Search")}</Button>
    <Button href={("/ant-design#overview")} icon={searchIcon} iconPlacement={position}
      aria-label={("Go to review with icon")} />
    <Button type="primary" loading iconPlacement={position}>{("Loading")}</Button>
  </div>
</div>
```

### Dimensions {#button-demo-size}

Three button sizes: `large`, `medium` and `small`. The size can be set individually or via [ConfigProvider](/ant-design/components/config-provider).

```svelte
<script lang="ts">
  import { Button, Divider, RadioGroup } from '@woodger/antd';

  let size = $state<'large' | 'medium' | 'small'>('large');
</script>

<style>
  .stack {
    display: grid;
    gap: 16px;
  }
  .row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
  }
</style>

{#snippet downloadIcon()}
  <svg width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor"
    stroke-width="1.75" aria-hidden="true" focusable="false" style="display:block">
    <path d="M12 3v12m-4-4 4 4 4-4M5 17v4h14v-4" />
  </svg>
{/snippet}

<div class="stack">
  <RadioGroup
    aria-label={("Button size in example")}
    optionType="button"
    value={size}
    options={([
      { value: 'large', label: "Large" },
      { value: 'medium', label: "Medium" },
      { value: 'small', label: "Small" }
    ])}
    onValueChange={value => {
      if (value === 'large' || value === 'medium' || value === 'small') size = value;
    }}
  />
  <Divider titlePlacement="start" plain>{("Preview")}</Divider>
  <div class="row">
    <Button type="primary" {size}>{("Main")}</Button>
    <Button {size}>{("Regular")}</Button>
    <Button type="dashed" {size}>{("Dotted")}</Button>
  </div>
  <div><Button type="link" {size}>{("Link")}</Button></div>
  <div class="row">
    <Button type="primary" {size} icon={downloadIcon} aria-label={("Download, without label")} />
    <Button type="primary" shape="circle" {size} icon={downloadIcon} aria-label={("Download, round")} />
    <Button type="primary" shape="round" {size} icon={downloadIcon} aria-label={("Download, rounded")} />
    <Button
      type="primary"
      shape="round"
      {size}
      icon={downloadIcon}
    >{("Download")}</Button>
    <Button type="primary" {size} icon={downloadIcon}>{("Download")}</Button>
  </div>
</div>
```

### Inaccessible buttons {#button-demo-disabled}

`disabled` disables the action for every button type, including a link button.

```svelte
<script lang="ts">
  import { Button } from '@woodger/antd';

  const types = [
    { value: 'primary', label: "Main" },
    { value: 'default', label: "Regular" },
    { value: 'dashed', label: "Dotted" },
    { value: 'text', label: "Text" },
    { value: 'link', label: "Link" }
  ] as const;
</script>

<style>
  .stack {
    display: grid;
    gap: 16px;
  }
  .row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
  }
  .row :global(button), .row :global(a) {
    max-inline-size: 100%;
    min-block-size: min-content;
    white-space: normal;
  }
  .ghost-row {
    padding: 16px;
    border-radius: 6px;
    background: rgb(190, 200, 200);
  }
</style>

<div class="stack">
  {#each types as type (type.value)}
    <div class="row">
      <Button type={type.value}>{(type.label)}</Button>
      <Button
        type={type.value}
        disabled
      >{(type.label)}{(" (not available)")}</Button>
    </div>
  {/each}
  <div class="row">
    <Button type="primary" href={("/ant-design#overview")}>
      {("Link with href")}
    </Button>
    <Button type="primary" href={("/ant-design#overview")} disabled>
      {("Link with href (not available)")}
    </Button>
  </div>
  <div class="row">
    <Button danger>{("Dangerous action")}</Button>
    <Button danger disabled>{("Hazardous action (not available)")}</Button>
  </div>
  <div class="row">
    <Button danger type="text">{("Dangerous text")}</Button>
    <Button danger type="text" disabled>{("Dangerous text (not available)")}</Button>
  </div>
  <div class="row">
    <Button danger type="link">{("Dangerous link")}</Button>
    <Button danger type="link" disabled>{("Dangerous link (unavailable)")}</Button>
  </div>
  <div class="row ghost-row">
    <Button ghost>{("Transparent")}</Button>
    <Button ghost disabled>{("Transparent (not available)")}</Button>
  </div>
</div>
```

### Loading {#button-demo-loading}

Initial versions of the indicator and an additional example with a delay. Its snippet is replaced by a spinner; in v1 the button is not available during loading.

```svelte
<script lang="ts">
  import { onDestroy } from 'svelte';
  import { Button } from '@woodger/antd';

  let active = $state([false, false, false, false, false]);
  const timers = new Map<number, ReturnType<typeof setTimeout>>();

  function startLoading(index: number) {
    if (active[index]) {
      return;
    }

    active[index] = true;
    timers.set(index, setTimeout(() => {
      active[index] = false;
      timers.delete(index);
    }, 3000));
  }

  onDestroy(() => {
    for (const timer of timers.values()) clearTimeout(timer);

    timers.clear();
  });
</script>

<style>
  .stack {
    display: grid;
    gap: 16px;
  }
  .row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
  }
  .row :global(button) {
    max-inline-size: 100%;
    min-block-size: min-content;
    white-space: normal;
  }
  .spinner {
    display: block;
    animation: spin 1s linear infinite;
  }
  @keyframes spin { to { transform: rotate(360deg); } }
  @media (prefers-reduced-motion: reduce) { .spinner { animation: none; } }
</style>

{#snippet powerIcon()}
  <svg width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor"
    stroke-width="1.75" aria-hidden="true" focusable="false" style="display:block">
    <path d="M12 2v10m-6.4-6.4a9 9 0 1 0 12.8 0" />
  </svg>
{/snippet}
{#snippet customSpinner()}
  <svg class="spinner" width="1em" height="1em" viewBox="0 0 24 24" fill="none"
    stroke="currentColor" stroke-width="1.75" aria-hidden="true" focusable="false">
    <path d="M20 12a8 8 0 1 1-2.3-5.7M18 2v5h-5" />
  </svg>
{/snippet}

<div class="stack">
  <div class="row">
    <Button type="primary" loading>{("Loading")}</Button>
    <Button type="primary" size="small" loading>{("Loading")}</Button>
    <Button type="primary" loading icon={powerIcon} aria-label={("Loading without label")} />
    <Button
      type="primary"
      loading={{ icon: customSpinner }}
    >{("Your own indicator")}</Button>
  </div>
  <div class="row">
    <Button type="primary" loading={active[0]} onclick={() => startLoading(0)}>
      {("\n      Start download\n    ")}
    </Button>
    <Button
      type="primary"
      loading={active[1]}
      iconPlacement="end"
      onclick={() => startLoading(1)}
    >{("\n      Right indicator\n    ")}</Button>
    <Button
      type="primary"
      loading={active[2]}
      icon={powerIcon}
      onclick={() => startLoading(2)}
    >{("\n      Replace icon\n    ")}</Button>
    <Button
      type="primary"
      loading={active[3]}
      icon={powerIcon}
      aria-label={("Start download without label")}
      onclick={() => startLoading(3)}
    />
    <Button type="primary" loading={active[3] ? { icon: customSpinner } : false} icon={powerIcon}
      onclick={() => startLoading(3)}>{("Custom indicator when pressed")}</Button>
  </div>
  <div class="row">
    <Button type="primary" loading={active[4] ? { delay: 500 } : false}
      onclick={() => startLoading(4)}>{("Delayed")}</Button>
  </div>
</div>
```

### Multiple actions {#button-demo-multiple}

Leave the main action visible, and combine additional ones into [Dropdown](/ant-design/components/dropdown). [SpaceCompact](/ant-design/components/space#space-compact) connects adjacent buttons.

```svelte
<script lang="ts">
  import { Button, Dropdown, SpaceCompact } from '@woodger/antd';

  let action = $state(("Select an action from the menu."));
  const items = [
    { key: 'first', label: "First action" },
    { key: 'second', label: "Second act" },
    { key: 'third', label: "Third action" }
  ];
</script>

<style>
  .row {
    display: flex;
    flex-direction: column;
    align-items: flex-start;
    gap: 8px;
  }
  output {
    display: block;
    margin-top: 16px;
    color: var(--ant-color-text-secondary);
    font-size: 12px;
  }
</style>

{#snippet moreIcon()}
  <svg width="1em" height="1em" viewBox="0 0 24 24" fill="currentColor"
    aria-hidden="true" focusable="false" style="display:block">
    <circle cx="5" cy="12" r="1.6" /><circle cx="12" cy="12" r="1.6" />
    <circle cx="19" cy="12" r="1.6" />
  </svg>
{/snippet}
{#snippet actionButton()}<Button onclick={() => {
  action = ("Main action completed.");
}}>{("Actions")}</Button>{/snippet}
{#snippet moreButton()}
  <Dropdown trigger={['click']} placement="bottomRight" menu={({
    items,
    onClick: ({ key }) => {
      const item = items.find(item => item.key === key);
      const label = item?.label ?? key;
      action = ("Selected: " + String((label)) + "");
    }
  })}>
    <Button icon={moreIcon} aria-label={("Additional actions")} />
  </Dropdown>
{/snippet}

<div class="row">
  <Button type="primary">{("Main")}</Button>
  <Button>{("Additional")}</Button>
  <SpaceCompact items={([actionButton, moreButton])} />
</div>
<output aria-label={("Selected action")}>{action}</output>
```

### Transparent buttons {#button-demo-ghost}

`ghost` removes fill. This option is suitable for colored or other complex backgrounds.

```svelte
<script lang="ts">
  import { Button } from '@woodger/antd';
</script>

<style>
  .preview {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
    padding: 16px;
    border-radius: 6px;
    background: rgb(190, 200, 200);
  }
</style>

<div class="preview">
  <Button type="primary" ghost>{("Main")}</Button>
  <Button ghost>{("Regular")}</Button>
  <Button type="dashed" ghost>{("Dotted")}</Button>
  <Button danger ghost>{("Dangerous action")}</Button>
</div>
```

### Dangerous actions {#button-demo-danger}

`danger` highlights actions that require attention, such as deleting data.

```svelte
<script lang="ts">
  import { Button } from '@woodger/antd';
</script>

<style>
  .row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
  }
</style>

<div class="row">
  <Button type="primary" danger>{("Main")}</Button>
  <Button danger>{("Regular")}</Button>
  <Button type="dashed" danger>{("Dotted")}</Button>
  <Button type="text" danger>{("Text")}</Button>
  <Button type="link" danger>{("Link")}</Button>
</div>
```

### Full width {#button-demo-block}

`block` stretches the button to the width of the parent container.

```svelte
<script lang="ts">
  import { Button } from '@woodger/antd';
</script>

<style>
  .stack {
    display: grid;
    gap: 8px;
  }
</style>

<div class="stack">
  <Button type="primary" block>{("Main")}</Button>
  <Button block>{("Regular")}</Button>
  <Button type="dashed" block>{("Dotted")}</Button>
  <Button disabled block>{("Not available")}</Button>
  <Button type="text" block>{("Text")}</Button>
  <Button type="link" block>{("Link")}</Button>
</div>
```

### Gradient {#button-demo-linear-gradient}

Custom main button styling via [ConfigProvider.button.class](/ant-design/components/config-provider#config-provider-settings) and CSS, including hover state.

```svelte
<script lang="ts">
  import { Button, ConfigProvider } from '@woodger/antd';
</script>

<style>
  .preview {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
  }
  .preview :global(.gradient-button.ant-btn-primary:not([disabled])) { position: relative; }
  .preview :global(.gradient-button.ant-btn-primary:not([disabled]) > span) { position: relative; }
  .preview :global(.gradient-button.ant-btn-primary:not([disabled])::before) {
    content: '';
    position: absolute;
    inset: -1px;
    border-radius: inherit;
    background: linear-gradient(135deg, #6253e1, #04befe);
    opacity: 1;
    transition: opacity var(--ant-motion-duration-slow);
  }
  .preview :global(.gradient-button.ant-btn-primary:not([disabled]):hover::before) { opacity: 0; }
  @media (prefers-reduced-motion: reduce) {
    .preview :global(.gradient-button::before) { transition: none; }
  }
</style>

{#snippet downloadIcon()}
  <svg width="1em" height="1em" viewBox="0 0 24 24" fill="none" stroke="currentColor"
    stroke-width="1.75" aria-hidden="true" focusable="false" style="display:block">
    <path d="M12 3v12m-4-4 4 4 4-4M5 17v4h14v-4" />
  </svg>
{/snippet}

<div class="preview">
  <ConfigProvider button={{ class: 'gradient-button' }}>
    <div class="preview">
      <Button type="primary" icon={downloadIcon}>{("Gradient")}</Button>
      <Button>{("Regular")}</Button>
    </div>
  </ConfigProvider>
</div>
```

### Own wave {#button-demo-wave}

[ConfigProvider.wave](/ant-design/components/config-provider#config-provider-demo-wave) disables the standard wave or replaces it with its own effect. The example takes into account reduced motion.

```svelte
<script lang="ts">
  import { onDestroy } from 'svelte';
  import { Button, ConfigProvider, type ShowWaveEffect } from '@woodger/antd';

  let effect = $state(("Click the button to compare effects."));
  const animations = new Set<Animation>();
  const holders = new Set<HTMLElement>();

  function playAnimation(node: HTMLElement, frames: Keyframe[], cleanup = () => {}) {
    const animation = node.animate(frames, { duration: 500, easing: 'ease-out' });
    animations.add(animation);

    const finish = () => {
      animations.delete(animation);
      cleanup();
    };

    void animation.finished.then(finish, finish);
  }

  const showInsetEffect: ShowWaveEffect = (node, { component, event }) => {
    if (component !== 'Button') {
      return;
    }

    effect = ("Internal wave");

    if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
      return;
    }

    const rect = node.getBoundingClientRect();
    const x = event.detail === 0 ? rect.width / 2 : event.clientX - rect.left;
    const y = event.detail === 0 ? rect.height / 2 : event.clientY - rect.top;
    const diameter = Math.hypot(rect.width, rect.height) * 2;
    const holder = document.createElement('span');
    holder.setAttribute('aria-hidden', 'true');
    holder.style.cssText = `
      position: absolute;
      inset: 0;
      overflow: hidden;
      border-radius: inherit;
      pointer-events: none;
      z-index: 1;
    `;
    const dot = document.createElement('span');
    dot.style.cssText = `
      position: absolute;
      left: ${x}px;
      top: ${y}px;
      width: ${diameter}px;
      height: ${diameter}px;
      border-radius: 50%;
      background: rgba(255,255,255,0.65);
      pointer-events: none;
    `;
    holder.append(dot);
    node.append(holder);
    holders.add(holder);

    playAnimation(dot, [
      {
        transform: 'translate(-50%, -50%) scale(0)',
        opacity: 1
      },
      {
        transform: 'translate(-50%, -50%) scale(1)',
        opacity: 0
      }
    ], () => {
      holder.remove();
      holders.delete(holder);
    });
  };

  const showShakeEffect: ShowWaveEffect = (node, { component }) => {
    if (component !== 'Button') {
      return;
    }

    effect = ("Shaking");

    if (window.matchMedia('(prefers-reduced-motion: reduce)').matches) {
      return;
    }

    for (const animation of node.getAnimations()) {
      if (animations.has(animation)) animation.cancel();
    }

    playAnimation(node, [0, -12, 12, -5, 5, 0].map(angle => ({
      transform: `rotate(${angle}deg)`
    })));
  };

  onDestroy(() => {
    for (const animation of animations) animation.cancel();

    for (const holder of holders) holder.remove();

    animations.clear();
    holders.clear();
  });
</script>

<style>
  .row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 16px;
  }
  output {
    display: block;
    margin-top: 16px;
    color: var(--ant-color-text-secondary);
    font-size: 12px;
  }
</style>

<div class="row">
  <ConfigProvider wave={{ disabled: true }}>
    <Button type="primary" onclick={() => { effect = ("Wave disabled"); }}>
      {("Without wave")}
    </Button>
  </ConfigProvider>
  <ConfigProvider>
    <Button
      type="primary"
      onclick={() => { effect = ("Standard wave"); }}
    >{("Standard")}</Button>
  </ConfigProvider>
  <ConfigProvider wave={{ showEffect: showInsetEffect }}>
    <Button type="primary">{("Internal wave")}</Button>
  </ConfigProvider>
  <ConfigProvider wave={{ showEffect: showShakeEffect }}>
    <Button type="primary">{("Shaking")}</Button>
  </ConfigProvider>
</div>
<output aria-label={("Wave effect")}>{effect}</output>
```

### Background of inaccessible buttons {#button-demo-custom-disabled-bg}

The `defaultBgDisabled` and `dashedBgDisabled` tokens change the background of inaccessible buttons via the [ConfigProvider](/ant-design/components/config-provider) theme.

```svelte
<script lang="ts">
  import { Button, ConfigProvider } from '@woodger/antd';
</script>

<style>
  .row {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
  }
</style>

<ConfigProvider theme={{
  cssVar: {},
  components: {
    Button: {
      defaultBgDisabled: 'rgba(0,0,0,0.1)',
      dashedBgDisabled: 'rgba(0,0,0,0.4)'
    }
  }
}}>
  <div class="row">
    <Button type="primary" disabled>{("Main")}</Button>
    <Button disabled>{("Regular")}</Button>
    <Button type="dashed" disabled>{("Dotted")}</Button>
  </div>
</ConfigProvider>
```

### Semantic styles {#button-demo-style-class}

`classNames` and `styles` style `root` and `content`. `styles` takes an object or function from the button's properties.

```svelte
<script lang="ts">
  import { Button, type ButtonProps } from '@woodger/antd';

  const classNames = { root: 'semantic-root', content: 'semantic-content' };
  const styles: ButtonProps['styles'] = info => info.props.type === 'primary'
    ? {
      root: `
        background: #171717;
        border-color: #171717;
      `,
      content: 'color:#fff'
    }
    : {};
</script>

<style>
  .preview {
    display: flex;
    align-items: center;
    flex-wrap: wrap;
    gap: 8px;
  }
  .preview :global(.semantic-root) {
    height: auto;
    padding: 8px 16px;
    border-radius: var(--ant-border-radius);
  }
  .preview :global(.semantic-content) { font-weight: 500; }
</style>

<div class="preview">
  <Button {classNames} styles={{ root: 'box-shadow:0 1px 2px rgba(0,0,0,0.05)' }}>
    {("Object")}
  </Button>
  <Button type="primary" {classNames} {styles}>{("Function")}</Button>
</div>
```

### Color action and button group {#button-demo-features}

A colored action, a link and counter buttons in [Flex](/ant-design/components/flex). [ConfigProvider](/ant-design/components/config-provider) sets the size and appearance of the counter buttons.

```svelte
<script lang="ts">
  import { Button, ConfigProvider, Flex } from '@woodger/antd';

  let clicks = $state(0);
</script>

<Flex gap={8} align="center" wrap>
  <Button color="purple" variant="filled" iconPlacement="end" onclick={() => { clicks++; }}>
    {#snippet icon()}
      <span aria-hidden="true">★</span>
    {/snippet}{("\n    Color action (")}{clicks})
  </Button>
  <Button href={("/ant-design#overview")}>{("Go to review")}</Button>
  <ConfigProvider componentSize="small" button={{ color: 'green', variant: 'outlined' }}>
    <Flex gap={8}>
      <Button onclick={() => { clicks--; }}>−</Button>
      <Button onclick={() => { clicks++; }}>+</Button>
    </Flex>
  </ConfigProvider>
</Flex>
```

### Button CSS prefixes {#button-demo-prefix}

Common namespace [ConfigProvider](/ant-design/components/config-provider) and local `prefixCls`; the state of the component is preserved when the name is changed.

```svelte
<script lang="ts">
  import { Button, Checkbox, ConfigProvider, Flex } from '@woodger/antd';

  let custom = $state(true);
  let local = $state(true);
  const prefix = $derived(custom ? 'suite' : 'ant');
  const localPrefix = $derived(local ? 'project-btn' : '');
  let clicks = $state(0);
</script>

<style>
  .example,
  .prefix-stage {
    display: grid;
    grid-template-columns: minmax(0, 1fr);
    gap: 16px;
    min-width: 0;
  }
  .controls {
    display: flex;
    flex-wrap: wrap;
    gap: 12px;
  }
  p { margin: 0; }
  output { overflow-wrap: anywhere; }
</style>

<div class="example">
  <div class="controls">
    <Checkbox bind:checked={custom}>{("Common prefix Button suite")}</Checkbox>
    <Checkbox bind:checked={local}>{("Local prefix Button")}</Checkbox>
  </div>
  <ConfigProvider prefixCls={prefix} theme={{ cssVar: { prefix: 'button-theme' } }}>
    <div class="prefix-stage">
      <Flex gap={8} wrap>
        <Button prefixCls={localPrefix} type="primary" onclick={() => clicks++}>
          {("Save with prefix")}
        </Button>
        <Button prefixCls={localPrefix} onclick={() => clicks = 0}>
          {("Reset counter")}
        </Button>
      </Flex>
      <output
        aria-label={("Button actions with prefix")}
      >{("Actions: ")}{clicks}</output>
    </div>
  </ConfigProvider>
  <output
    aria-label={("Button CSS prefix")}
  >{("General: ")}{prefix}{("; local: ")}{(localPrefix
    || ("from the provider"))}</output>
  <p>
    <code>prefixCls</code> {("sets the full button prefix without appending the suffix")} <code>-btn</code>.
    {("The button container and internal variables use the shared provider prefix.")}
  </p>
</div>
```

## API {#button-api}

| Property | Description | Type | Default |
| --- | --- | --- | --- |
| `prefixCls` | Full CSS prefix of the component and its parts. A non-empty local prop takes precedence; empty string and `undefined` inherit [ConfigProvider](/ant-design/components/config-provider). The namespace of the topic is set separately. | `ButtonProps['prefixCls']` | `ant-btn` |
| `type` | Ready-made design: `primary`, `default`, `dashed`, `text` or `link`. | `ButtonProps['type']` | `default` |
| `color` | Button color: `default`, `primary`, `danger` or one of the preset colors. | `ButtonProps['color']` | `default` |
| `variant` | Design option: `solid`, `outlined`, `dashed`, `filled`, `text` or `link`. | `ButtonProps['variant']` | `outlined` |
| `danger` | Highlights a dangerous action. The explicit `color` + `variant` pair takes precedence. | `ButtonProps['danger']` | `false` |
| `ghost` | Transparent background for complex substrate; Applies to buttons with a border or fill. | `ButtonProps['ghost']` | `false` |
| `block` | Stretches the button to the width of the parent container. | `ButtonProps['block']` | `false` |
| `size` | `small`, `medium` or `large`. Without local `size`, inherits [ConfigProvider](/ant-design/components/config-provider). | `ButtonProps['size']` | `medium` |
| `shape` | `default`, `circle`, `round` or `square`. | `ButtonProps['shape']` | `default` |
| `children` | Label or Svelte snippet with button content. | `ButtonProps['children']` | `—` |
| `icon` | Icon as snippet or other `ButtonContent`. | `ButtonProps['icon']` | `—` |
| `iconPlacement` | Icon position: `start` or `end`. | `ButtonProps['iconPlacement']` | `start` |
| `loading` | `boolean` or object with `delay` in milliseconds and its own `icon`. For v1, active loading makes the native `button` unavailable. | `ButtonProps['loading']` | `false` |
| `disabled` | Disables the action. For `href`, removes the transition and excludes the link from the Tab order. | `ButtonProps['disabled']` | `false` |
| `href` | Creates a native link instead of a `button`. Without `href`, `type="link"` remains an action button. | `ButtonLinkProps['href']` | `—` |
| `target` | Link navigation target; `rel`, `download` and `referrerpolicy` are also passed to the native element. | `ButtonProps['target']` | `—` |
| `htmlType` | Native button type: `button`, `submit` or `reset`. By default button. | `ButtonProps['htmlType']` | `button` |
| `onclick` | Native Svelte event. For a link, the handler type is determined by `ButtonLinkProps`. | `ButtonProps['onclick']` | `—` |
| `classNames` | Classes semantic slots `root`, `icon` and `content`: object or callback from { props }. | `ButtonProps['classNames']` | `—` |
| `styles` | CSS strings for semantic slots: object or callback from { props }. | `ButtonProps['styles']` | `—` |
| `autoInsertSpace` | Automatic spacing between two Chinese characters; enabled by default. | `ButtonProps['autoInsertSpace']` | `true` |
| `nativeElement` | `bind:nativeElement` gets the native button or link after mount; unmount clears the link. | `ButtonProps['nativeElement']` | `—` |

### Preset colors

`blue`, `purple`, `cyan`, `green`, `magenta`, `pink`, `red`, `orange`, `yellow`, `volcano`, `geekblue`, `lime`, `gold`

### ConfigProvider.button

`autoInsertSpace`, `color`, `variant`, `shape`, `loadingIcon`, `class`, `style`, `classNames`, `styles`

## Semantic DOM {#button-semantic-dom}

Use the slot names in `classNames` and `styles`.

| Slot | Description |
| --- | --- |
| `root` | Native `button` or `a`: background, border, size and states. |
| `icon` | Wrapper for icon or loading indicator. |
| `content` | Label wrapper and its typography. |

## Design tokens {#button-design-token}

Set component tokens in `ConfigProvider.theme.components.Button`.

```svelte
<script lang="ts">
  import { Button, ConfigProvider } from '@woodger/antd';
</script>

<ConfigProvider theme={{
  cssVar: {},
  components: {
    Button: {
      defaultBg: '#f6ffed',
      defaultColor: '#389e0d',
      defaultBorderColor: '#b7eb8f',
      contentFontSize: 16
    }
  }
}}>
  <Button>{("Custom Button theme")}</Button>
</ConfigProvider>
```

### Component tokens

| Token | Description |
| --- | --- |
| `fontWeight` | Text saturation. |
| `iconGap` | Distance between the icon and the label. |
| `defaultShadow` | Shadow of a regular button. |
| `primaryShadow` | Shadow of the main button. |
| `dangerShadow` | Shadow of a dangerous button. |
| `primaryColor` | Main button text color. |
| `defaultColor` | Text color of a regular button. |
| `defaultBg` | Background of a regular button. |
| `defaultBorderColor` | Frame of a regular button. |
| `dangerColor` | Danger button text color. |
| `defaultHoverBg` | Background when hovering. |
| `defaultHoverColor` | Text color when hovering. |
| `defaultHoverBorderColor` | Hover frame. |
| `defaultActiveBg` | Background when pressed. |
| `defaultActiveColor` | Text color when pressed. |
| `defaultActiveBorderColor` | Frame when pressed. |
| `defaultGhostColor` | Transparent button text color. |
| `ghostBg` | Transparent button background. |
| `defaultGhostBorderColor` | Transparent button frame. |
| `solidTextColor` | Button text color with fill. |
| `textTextColor` | Text color of the text button. |
| `textTextHoverColor` | Text color of the text button when hovered. |
| `textTextActiveColor` | The text color of the text button when pressed. |
| `paddingInline` | Normal size horizontal space. |
| `paddingInlineLG` | Large horizontal space. |
| `paddingInlineSM` | Small horizontal indent. |
| `onlyIconSize` | Icon size in a button without a label. |
| `onlyIconSizeLG` | Icon size in a large button without a label. |
| `onlyIconSizeSM` | Icon size in a small button without a label. |
| `linkHoverBg` | `link` background on hover. |
| `textHoverBg` | Text background when hovering. |
| `contentFontSize` | The font size of a regular button. |
| `contentFontSizeLG` | Large button font size. |
| `contentFontSizeSM` | Small button font size. |
| `defaultBgDisabled` | Background of an inaccessible regular button. |
| `dashedBgDisabled` | Background of the inaccessible dotted button. |

### Global tokens

| Token | Description |
| --- | --- |
| `controlHeight` | Height of a regular button, px. |
| `controlHeightLG` | Height of the large button, px. |
| `controlHeightSM` | Small button height, px. |
| `fontSize` | Main font size, px. |
| `fontSizeLG` | Large font size, px. |
| `borderRadius` | Basic fillet, px. |
| `colorPrimary` | Primary theme color. |
| `colorBgContainer` | Container background. |
| `colorBgContainerDisabled` | Background of inaccessible control. |
| `colorTextDisabled` | Color of inaccessible text. |
| `opacityLoading` | Loading opacity. |

