Button

Alignment target:@astryxdesign/core v0.7.1 · Button

Usage #

Button triggers an action. Set label to name the action.

Without a default slot, the button displays label:

Vue
<script setup lang="ts">
import { Button } from '@astryx-vue/core/Button'
</script>

<template>
  <Button label="Save changes" variant="primary" />
</template>

Use the dedicated ButtonGroup and IconButton components when you need connected actions or an explicit icon-only button.

The icon slot sits in a sized box before the label, and the end slot mirrors it. Put an Icon there and leave its size unset; the slot already decides the box:

Vue
<script setup lang="ts">
import { Button } from '@astryx-vue/core/Button'
import { Icon } from '@astryx-vue/core/Icon'
</script>

<template>
  <Button label="Upload file">
    <template #icon>
      <Icon name="carbon:upload" />
    </template>
  </Button>
  <Button label="Continue" variant="secondary">
    <template #end>
      <Icon name="carbon:chevron-right" />
    </template>
  </Button>
</template>

A CSS icon class still works in the slot if you already generate one. UnoCSS is not required.

On a touch-first device such as a phone or tablet, a button's tap target grows toward 44 px while the button keeps its size. The growth stops halfway to the nearest interactive neighbor, so a tap between two controls always goes to the nearer one. A disabled or busy button does not grow, and a button in a group grows through its group. A mouse sees no change.

Anatomy

ElementDescription
IconA leading icon that reinforces the label, like a trash icon on a Delete button.
LabelThe visible text describing the action. Also used as the accessible name.
End contentA trailing badge or icon after the label, like a notification count or dropdown arrow.
SpinnerReplaces the icon during loading to show the action is in progress.

Best practices #

GuidancePractices
DoReserve primary for the single most important action in the view. Use secondary or ghost for everything else based on emphasis.
DoWrite labels that describe the action ("Save changes", "Delete account", "Send invite"), not vague labels like "OK" or "Click here".
DoShow a loading state for actions that take time, like saving or submitting, so the user knows it is working.
DoAlways provide a label for icon-only buttons so screen readers can announce what the button does. Add a tooltip for sighted users.
DoFor a dedicated icon-only button, use IconButton from '@astryx-vue/core/IconButton'. It is a separate component, not exported from '@astryx-vue/core/Button'.
Don'tPlace more than one primary button in the same view; this dilutes the visual hierarchy.
Don'tUse the destructive variant without a confirmation step for irreversible actions like deleting data.
Don'tUse a button for navigation. If it only takes the user to another page, use a link instead. Buttons are for actions like saving, deleting, or submitting.
Don'tRestyle Button's ::before and expect it to hold through a touch press: under a coarse primary pointer, while a press is on or fading, Button paints the press on that pseudo-element (z-index: -1, its opacity animated), so your styles merge into the press layer for that moment. At rest Button adds nothing there. Style a child element instead.

Examples #

Button — Floating

Floating action buttons — raised above content with `elevation="med"`
Open in Playground

A floating action button raised with elevation="med". Use elevation for buttons that hover above content, like a FAB.

Button — Sizes

Primary
Secondary
Open in Playground

Small, medium, and large buttons side by side. Use small in dense UIs like toolbars, medium for most cases, and large for prominent CTAs.

Button — Variants

Default
Disabled
Loading
Open in Playground

All 4 button variants in default, disabled, and loading states. Use primary for the main action, secondary for most others, ghost for low-emphasis, and destructive for dangerous actions.

Button — End slot

Trailing badges for counts or status
Open in Playground

Buttons with a trailing badge showing a count or status. Use for notification counts, unread messages, or any button that needs a visual indicator.

Button — Icon

Icons reinforce the action
Open in Playground

Buttons with a leading icon that reinforces the label. Use when the icon helps the user identify the action faster, like a plus for New or a trash can for Delete.