Button

Material Design 3 button component with multiple variants and sizes

Button

Buttons allow users to take actions with a single tap. @duskmoon-dev/core provides a complete set of Material Design 3 button variants.

Basic Usage

Basic Button

Variants

Filled Buttons

Filled buttons have the most visual impact and should be used for primary actions.

Filled Buttons

Outlined Buttons

Outlined buttons are medium-emphasis buttons. They’re used for important but not primary actions.

Outlined Buttons

Text Buttons

Text buttons are used for low-priority actions, such as “Cancel” or “Learn More”.

Text Buttons

Tonal Buttons

Tonal buttons use the theme’s container colors for a subtle but noticeable effect.

Tonal Buttons

Semantic Colors

Use semantic colors for user feedback:

Semantic Color Buttons

Semantic colors work with all variants:

Semantic Colors with Variants

Sizes

Three sizes are available:

Button Sizes

Icon Buttons

Buttons with Icons

Add icons alongside text:

Buttons with Icons

Icon-Only Buttons

For compact interfaces, use icon-only buttons:

Icon-Only Buttons

States

Disabled State

Disabled buttons are non-interactive:

Disabled Buttons

Loading State

Use the btn-loading class to show a loading spinner. The text is hidden and a spinner appears in its place:

Loading Buttons

The loading state can be combined with any button variant and size:

Loading Button Sizes

Block Buttons

Full-width buttons:

Block Button

Button Groups

Group related buttons together:

Button Group

Composing action components

Button remains the visual foundation for action triggers. Dropdown triggers and FAB / Speed Dial actions compose .btn with their component-specific classes rather than copying button colors, focus, loading, or disabled behavior.

When using individual imports for a FAB, import both styles:

@import "@duskmoon-dev/core/components/button";
@import "@duskmoon-dev/core/components/fab";

Best Practices

Visual Hierarchy

Use button variants to create clear visual hierarchy:

  1. Primary action: btn-primary (filled)
  2. Secondary action: btn-outlined or btn-tonal
  3. Tertiary action: btn-text

Visual Hierarchy Example

Accessibility

  • Always provide meaningful button text or aria-label for icon buttons
  • Use semantic HTML <button> elements
  • Ensure sufficient color contrast
  • Support keyboard navigation (built-in)

Accessible Icon Button

Touch Targets

Ensure buttons are large enough for touch interfaces (minimum 44×44px):

Responsive Button for Touch

Framework Examples

React

interface ButtonProps {
  variant?: 'primary' | 'outlined' | 'text' | 'tonal';
  size?: 'sm' | 'md' | 'lg';
  children: React.ReactNode;
  onClick?: () => void;
}

export function Button({ variant = 'primary', size = 'md', children, ...props }: ButtonProps) {
  return (
    <button className={`btn btn-${variant} btn-${size}`} {...props}>
      {children}
    </button>
  );
}

// Usage
<Button variant="primary" onClick={() => console.log('clicked')}>
  Click Me
</Button>

Vue

<template>
  <button :class="`btn btn-${variant} btn-${size}`" v-bind="$attrs">
    <slot />
  </button>
</template>

<script setup>
defineProps({
  variant: {
    type: String,
    default: 'primary'
  },
  size: {
    type: String,
    default: 'md'
  }
})
</script>

<!-- Usage -->
<Button variant="primary" @click="handleClick">
  Click Me
</Button>

API Reference

Class Names

Class Description
.btn Base button styles (required)
.btn-primary Primary filled button (default)
.btn-secondary Secondary filled button
.btn-tertiary Tertiary filled button
.btn-accent Accent color
.btn-neutral Neutral color
.btn-base Theme base color
.btn-outlined Outlined button variant
.btn-text Text button variant
.btn-tonal Tonal button variant
.btn-success Success semantic color
.btn-error Error semantic color
.btn-warning Warning semantic color
.btn-info Info semantic color
.btn-sm Small size
.btn-md Medium size (default)
.btn-lg Large size
.btn-icon Icon-only button
.btn-icon-sm Small icon button
.btn-icon-lg Large icon button
.btn-block Full-width button
.btn-loading Loading state with spinner
.btn-circle Circular button (1:1 aspect ratio)
.btn-square Square button (1:1 aspect ratio)

Combinations

You can combine classes for different effects:

Class Combinations

  • Dropdown - Button-triggered disclosures
  • FAB / Speed Dial - Floating actions composed with Button
  • Swap - State indicators that can compose with a button
  • Badge - Notification indicators
  • Card - Container with actions
  • Input - Form inputs

See Also