v2.0.0-rc.4
Theme

Button

The Button component provides an interactive button with multiple variants, sizes, and states.

Installation

npm install @duskmoon-dev/el-button

Usage

import '@duskmoon-dev/el-button/register';
<el-dm-button variant="primary">Click me</el-dm-button>

Use type="submit" or type="reset" inside a form, or set form to an external form’s ID. Buttons can be removed and reinserted without duplicating submissions or resets.

Live Demo

Button Variants

PrimarySecondaryTertiaryOutlineGhost

Semantic Colors

SuccessWarningErrorInfo

Properties

PropertyTypeDefaultDescription
variant'primary' | 'secondary' | 'tertiary' | 'outline' | 'ghost' | 'success' | 'warning' | 'error' | 'info''primary'Visual style of the button
size'sm' | 'md' | 'lg''md'Size of the button
shape'circle' | 'square'—Optional shape; omitted keeps the default rectangle
disabledbooleanfalseDisables the button
loadingbooleanfalseShows loading state
type'button' | 'submit' | 'reset''button'Button type attribute

Variants

Primary

The primary variant is used for main actions.

<el-dm-button variant="primary">Primary</el-dm-button>

Secondary

The secondary variant is used for less prominent actions.

<el-dm-button variant="secondary">Secondary</el-dm-button>

Outline

The outline variant has a transparent background with a border.

<el-dm-button variant="outline">Outline</el-dm-button>

Ghost

The ghost variant is minimal, with no background or border.

<el-dm-button variant="ghost">Ghost</el-dm-button>

Tertiary

The tertiary variant provides an alternative accent color.

<el-dm-button variant="tertiary">Tertiary</el-dm-button>

Semantic Colors

Semantic color variants communicate status or intent.

Success

<el-dm-button variant="success">Success</el-dm-button>

Warning

<el-dm-button variant="warning">Warning</el-dm-button>

Error

<el-dm-button variant="error">Error</el-dm-button>

Info

<el-dm-button variant="info">Info</el-dm-button>

Sizes

Button Sizes

SmallMediumLarge
<el-dm-button size="sm">Small</el-dm-button>
<el-dm-button size="md">Medium</el-dm-button>
<el-dm-button size="lg">Large</el-dm-button>

Shapes

Use shape="circle" or shape="square" for icon buttons, together with an accessible label. Omit shape for the default rectangular button.

<el-dm-button variant="outline" size="xs" shape="circle" aria-label="Add">
  <svg aria-hidden="true" width="16" height="16" viewBox="0 0 16 16">
    <path d="M8 2v12M2 8h12" stroke="currentColor" />
  </svg>
</el-dm-button>
<el-dm-button variant="outline" size="xs" shape="square" aria-label="Add">
  <svg aria-hidden="true" width="16" height="16" viewBox="0 0 16 16">
    <path d="M8 2v12M2 8h12" stroke="currentColor" />
  </svg>
</el-dm-button>

States

Disabled

Disabled State

Disabled
<el-dm-button disabled>Disabled</el-dm-button>

Loading

Loading State

Loading
<el-dm-button loading>Loading</el-dm-button>

Events

The button component emits standard DOM events:

EventDescription
clickFired when the button is clicked
focusFired when the button receives focus
blurFired when the button loses focus

Event Handling

const button = document.querySelector('el-dm-button');
button.addEventListener('click', (event) => {
  console.log('Button clicked!');
});

CSS Custom Properties

PropertyDefaultDescription
--btn-padding-x1remHorizontal padding
--btn-padding-y0.5remVertical padding
--btn-border-radius0.375remBorder radius
--btn-font-weight500Font weight

Accessibility

  • The button uses native <button> element semantics
  • Host aria-label and aria-labelledby name the native button and stay synchronized
  • Keyboard navigation is fully supported
  • Focus states are clearly visible
  • Disabled state is properly announced to screen readers

Use aria-label for an icon-only button, or reference label elements with aria-labelledby:

<el-dm-button aria-label="Remove email">
  <svg aria-hidden="true" viewBox="0 0 24 24">
    <path d="M5 5L19 19M19 5L5 19" />
  </svg>
</el-dm-button>

<span id="remove-email-label">Remove email</span>
<el-dm-button aria-labelledby="remove-email-label">×</el-dm-button>

Label IDs resolve in the host’s document or containing shadow root. When a label target exists, aria-labelledby takes precedence over aria-label. Label text and target replacements stay synchronized. Modern browsers use ARIA element references across the shadow boundary; older browsers use the targets’ text content or aria-label. Without either attribute, the slotted content supplies the accessible name.