Skip to content

Button

The Button component is a versatile and commonly used element in user interfaces, designed to trigger actions or events when clicked. It can be customized in various ways, including size, tone, and variant, to suit different design needs. The button can also include icons for enhanced visual communication and can be disabled to prevent user interaction when necessary.

Basic Usage

vue
<spr-button>Button</spr-button>

Tone

vue
<spr-button>Neutral/Default</spr-button>
<spr-button tone="success">Success</spr-button>
<spr-button tone="danger">Danger</spr-button>

Sizes

vue
<spr-button size="small">Small</spr-button>
<spr-button>Medium/Default</spr-button>
<spr-button size="large">Large</spr-button>

Variant

vue
// Primary/Default
<spr-button>Primary/Default</spr-button>
<spr-button variant="secondary">Secondary</spr-button>
<spr-button variant="tertiary">Tertiary</spr-button>

// Succees
<spr-button tone="success">Primary/Default</spr-button>
<spr-button tone="success" variant="secondary">Secondary</spr-button>
<spr-button tone="success" variant="tertiary">Tertiary</spr-button>

// Danger
<spr-button tone="danger">Primary/Default</spr-button>
<spr-button tone="danger" variant="secondary">Secondary</spr-button>
<spr-button tone="danger" variant="tertiary">Tertiary</spr-button>

Disabled

vue
<spr-button disabled ize="small">Small</spr-button>
<spr-button disabled>Medium/Default</spr-button>
<spr-button disabled size="large">Large</spr-button>

Icon

Icon With Text

Icon Only

vue
<template>
  <spr-button hasIcon>
    <Icon icon="ph:trash" />
    <span>Button</span>
  </spr-button>

  <spr-button iconOnly>
    <Icon icon="ph:trash" />
    <span>Button</span>
  </spr-button>
</template>

<script lang="ts" setup>
import { Icon } from '@iconify/vue';
</script>

Fullwidth

vue
<spr-button fullwidth>Button</spr-button>

API Reference

Props

NameDescriptionTypeDefault
toneControls the button's color theme. Use neutral for standard actions, success for positive actions, and danger for destructive actions.'neutral' | 'success' | 'danger''neutral'
sizeDefines the button's size, affecting padding, font size, and overall dimensions.'small' | 'medium' | 'large''medium'
variantControls the button's visual style. primary provides the strongest emphasis, secondary has medium emphasis with an outline, and tertiary offers the subtlest styling.'primary' | 'secondary' | 'tertiary''primary'
typeSpecifies the native HTML button type attribute.'button' | 'submit' | 'reset''button'
stateDefines the visual state of the button. Mostly used internally.'base' | 'hover' | 'pressed' | 'focus''base'
disabledWhen set to true, prevents user interaction and applies a visual disabled state.booleanfalse
hasIconIndicates that the button contains an icon, which affects spacing and layout.booleanfalse
fullwidthWhen set to true, the button will expand to fill the width of its container.booleanfalse

Events

NameDescriptionParameters
clickEmitted when the button is clicked and not disabled.(event: MouseEvent)

Slots

NameDescription
defaultContent to be displayed inside the button. This can include text, icons, or other elements.

Accessibility

The button component follows accessibility best practices:

  • Uses native <button> element for proper keyboard navigation and screen reader support
  • Sets aria-disabled="true" when the button is disabled
  • Preserves hover and focus states for keyboard users
  • Maintains sufficient color contrast in all states and variants
  • Supports autofocus when the state prop is set to 'focus'

Product Uses

Sprout HR
Sprout Payroll
Sprout Ecosystem
Sprout Sidekick