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:
<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:
<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
| Element | Description |
|---|---|
| Icon | A leading icon that reinforces the label, like a trash icon on a Delete button. |
| Label | The visible text describing the action. Also used as the accessible name. |
| End content | A trailing badge or icon after the label, like a notification count or dropdown arrow. |
| Spinner | Replaces the icon during loading to show the action is in progress. |
Best practices #
| Guidance | Practices |
|---|---|
| Do | Reserve primary for the single most important action in the view. Use secondary or ghost for everything else based on emphasis. |
| Do | Write labels that describe the action ("Save changes", "Delete account", "Send invite"), not vague labels like "OK" or "Click here". |
| Do | Show a loading state for actions that take time, like saving or submitting, so the user knows it is working. |
| Do | Always provide a label for icon-only buttons so screen readers can announce what the button does. Add a tooltip for sighted users. |
| Do | For 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't | Place more than one primary button in the same view; this dilutes the visual hierarchy. |
| Don't | Use the destructive variant without a confirmation step for irreversible actions like deleting data. |
| Don't | Use 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't | Restyle 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
A floating action button raised with elevation="med". Use elevation for buttons that hover above content, like a FAB.
Button — Sizes
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
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
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
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.