Button

Buttons trigger actions. They communicate what will happen when users interact with them.

When to use

  • To trigger an action or event
  • To submit or reset a form
  • To navigate to another page or section
  • To open a dialog or menu

Key features

  • Multiple variants - Primary, secondary, outline, ghost, destructive, and link
  • Three sizes - Small, medium (default), and large
  • Icon support - Add icons before or after text, or use icon-only buttons
  • Full width option - Buttons can span the full width of their container
  • Button groups - Group related actions together
  • Accessible - Full keyboard navigation and screen reader support

Anatomy

A button consists of:

  • Container - The clickable area
  • Label - Text that describes the action
  • Icon - Optional visual indicator
  • State - Visual feedback (hover, active, disabled)

Installation

npm install @pm7/core

CSS Classes

Class Description
Base Classes
.pm7-button Base button class (required)
Variants
.pm7-button--primary Primary button variant (includes 6stars effect)
.pm7-button--default Alias for pm7-button--primary (includes 6stars effect)
.pm7-button--secondary Secondary button variant
.pm7-button--outline Outline button variant
.pm7-button--ghost Ghost button variant (transparent background)
.pm7-button--destructive Destructive button variant (for dangerous actions)
.pm7-button--link Link button variant (styled as text link)
.pm7-button--slider Slider button variant (swipe-to-confirm)
Size Modifiers
.pm7-button--sm Small size (36px height)
.pm7-button--md Medium size (40px height, default)
.pm7-button--lg Large size (48px height)
Layout Modifiers
.pm7-button--full Full width button (100% width)
.pm7-button--icon Icon-only button (square shape, no padding)
.pm7-button--on-dark For outline/ghost buttons on dark backgrounds (light mode only)
Structure Classes
.pm7-button-group Container for grouped buttons
.pm7-button--slider-text Text element inside slider button
.pm7-button--slider-handle Draggable handle element for slider button
.pm7-button__6stars Container for 6stars hover effect (auto-added via JS)

Data Attributes

Buttons do not use any special data attributes. They rely on standard HTML attributes and CSS classes for functionality.

Basic Usage

<button class="pm7-button pm7-button--primary">
  Click me
</button>

Variants

<!-- Primary: Main actions -->
<button class="pm7-button pm7-button--primary">Primary</button>

<!-- Secondary: Alternative actions -->
<button class="pm7-button pm7-button--secondary">Secondary</button>

<!-- Outline: Less prominent actions -->
<button class="pm7-button pm7-button--outline">Outline</button>

<!-- Ghost: Minimal styling -->
<button class="pm7-button pm7-button--ghost">Ghost</button>

<!-- Destructive: Dangerous actions -->
<button class="pm7-button pm7-button--destructive">Delete</button>

<!-- Link: Navigation styled as button -->
<button class="pm7-button pm7-button--link">Link</button>

<!-- Slider: Swipe-to-confirm button -->
<button class="pm7-button pm7-button--slider">
  <span class="pm7-button--slider-text">Slide to confirm</span>
  <span class="pm7-button--slider-handle"></span>
</button>

Sizes

<!-- Small (36px height) -->
<button class="pm7-button pm7-button--primary pm7-button--sm">Small</button>

<!-- Medium (40px height, default - no size class needed) -->
<button class="pm7-button pm7-button--primary">Medium</button>

<!-- Large (48px height) -->
<button class="pm7-button pm7-button--primary pm7-button--lg">Large</button>

PM7 Special Features

  • 6Stars Hover Effect: Primary buttons feature a unique "6stars" hover animation that creates a subtle sparkle effect
  • Interactive Feedback: Buttons transform 1px down on click for tactile feedback

CSS Customization

PM7 buttons can be customized using CSS custom properties:

:root {
  /* Border radius */
  --pm7-button-radius: 0.375rem;
  
  /* Typography */
  --pm7-button-font-size: 0.875rem;
  --pm7-button-font-weight: 500;
  --pm7-button-line-height: 1.25rem;
  
  /* Spacing */
  --pm7-button-padding-y: 0.5rem;
  --pm7-button-padding-x: 1rem;
  
  /* Shadows */
  --pm7-button-shadow: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --pm7-button-shadow-hover: 0 4px 6px -1px rgb(0 0 0 / 0.1);
  --pm7-button-shadow-active: 0 1px 2px 0 rgb(0 0 0 / 0.05);
  --pm7-button-focus-shadow: 0 0 0 3px rgb(28 134 239 / 0.2);
}

JavaScript API

import { PM7Button, initButtons } from '@pm7/core';

    import '/packages/core/src/scripts/index.js';
// Auto-initialization (happens automatically on DOMContentLoaded)
// Adds 6stars effect to all primary/default buttons

// Manual initialization for dynamically added buttons
const button = document.querySelector('.pm7-button--primary');
const pm7Button = new PM7Button(button);

// Or initialize all buttons manually
initButtons();

// Standard event handling
document.querySelector('.pm7-button').addEventListener('click', (e) => {
  console.log('Button clicked');
});

Note: The PM7Button class automatically adds the "6stars" hover effect to primary and default button variants. This effect creates floating star animations on hover, reinforcing the PM7 brand identity.

Button Groups

<!-- Horizontal button group -->
<div class="pm7-button-group">
  <button class="pm7-button pm7-button--outline">First</button>
  <button class="pm7-button pm7-button--outline">Second</button>
  <button class="pm7-button pm7-button--outline">Third</button>
</div>

<!-- Form actions with spacing -->
<div style="display: flex; gap: 1rem; justify-content: flex-end;">
  <button class="pm7-button pm7-button--ghost">Cancel</button>
  <button class="pm7-button pm7-button--primary">Save Changes</button>
</div>

Advanced Examples

<!-- Icon button with aria-label for accessibility -->
<button class="pm7-button pm7-button--ghost pm7-button--icon" aria-label="Settings">
  <svg width="28" height="28" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
    <circle cx="12" cy="12" r="3"></circle>
    <path d="M12 1v6m0 6v6m11-11h-6m-6 0H1"></path>
  </svg>
</button>

<!-- Loading state button -->
<button class="pm7-button pm7-button--primary" disabled>
  <svg class="pm7-spinner" width="16" height="16" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
    <path d="M21 12a9 9 0 11-6.219-8.56"/>
  </svg>
  Processing...
</button>

<!-- Button as link -->
<a href="/dashboard" class="pm7-button pm7-button--primary">
  Go to Dashboard
</a>

Accessibility

  • All buttons are keyboard accessible
  • Use descriptive text for screen readers
  • For icon-only buttons, add aria-label
  • Disabled buttons are properly announced
  • Focus states are clearly visible with customizable shadow

Terminology Guide

Term Definition Example
Ghost Button A button with minimal styling - transparent background, no border pm7-button--ghost
Destructive Button A button for dangerous actions like delete, remove, or cancel subscriptions pm7-button--destructive
Button Variant Different visual styles of buttons (primary, secondary, outline, etc.) pm7-button--primary
Button Modifier Classes that change button properties like size or width pm7-button--sm, pm7-button--full
Icon Button A button containing only an icon, no text (requires aria-label) pm7-button--icon
Button Group Multiple related buttons grouped together visually pm7-button-group
Loading State Button showing a spinner animation while processing Button with pm7-spinner and disabled
6Stars Effect PM7's signature hover animation on primary buttons Auto-applied to pm7-button--primary
CTA (Call to Action) Primary button that encourages user action Usually pm7-button--primary
Form Actions Button pattern for forms (Cancel + Submit) Secondary + Primary button combo

Copy this link that can be used as documentation for working with this component:

https://raw.githubusercontent.com/patrickmast/pm7-ui/main/packages/core/src/components/button/README.md

🤖 AI-Optimized Documentation

This link contains complete Markdown documentation that is perfectly readable by AI assistants, developers, and other automated systems. Directly accessible on GitHub - including all essential PM7 Button implementation guidance.

Perfect for ChatGPT, Claude, and other AI code assistants

Primary

Main actions (save, submit)

class="pm7-button pm7-button--primary"

Secondary

Alternative actions

class="pm7-button pm7-button--secondary"

Outline

Secondary actions with border

class="pm7-button pm7-button--outline"

Ghost

Minimal style for tertiary actions

class="pm7-button pm7-button--ghost"

Destructive

Dangerous actions (delete, remove)

class="pm7-button pm7-button--destructive"

Link

Styled as a link

class="pm7-button pm7-button--link"

Small

Compact size for dense UIs

class="pm7-button pm7-button--primary pm7-button--sm"

Medium (default)

Standard size

class="pm7-button pm7-button--primary"

Large

Prominent actions

class="pm7-button pm7-button--primary pm7-button--lg"

Size modifiers: --sm, --lg

Normal

Default interactive state

<button class="pm7-button pm7-button--primary">
  Normal
</button>

Disabled

Non-interactive state

<button class="pm7-button pm7-button--primary" disabled>
  Disabled
</button>

Loading

Shows spinner with disabled state

<button class="pm7-button pm7-button--primary" disabled>
  <svg class="pm7-spinner">...</svg>
  Loading...
</button>

Icon Left

Icon before text

<button class="pm7-button">
  <svg>...</svg>
  Text
</button>

Icon Right

Icon after text

<button class="pm7-button">
  Text
  <svg>...</svg>
</button>

Icon Only

Icon without text

<button class="pm7-button pm7-button--icon" aria-label="Action">
  <svg>...</svg>
</button>

Use case

Forms, mobile layouts, CTAs

class="pm7-button pm7-button--primary pm7-button--full"

Width modifier: --full

Usage

Use the --on-dark modifier for outline and ghost buttons on dark backgrounds in light mode

<button class="pm7-button pm7-button--outline pm7-button--on-dark">
  Outline on Dark
</button>

<button class="pm7-button pm7-button--ghost pm7-button--on-dark">
  Ghost on Dark
</button>

When to use

• Hero sections with dark backgrounds

• Dark cards or panels in light mode

• Marketing pages with dark sections

Note: This modifier is only needed in light mode. Dark mode automatically handles contrast.

Purpose

Prevents accidental clicks on critical actions by requiring a deliberate swipe gesture.

Features

  • Touch and mouse support
  • Visual feedback during drag
  • Success state animation
  • Programmatic reset capability
  • Automatic click event on completion

Example

<button class="pm7-button pm7-button--slider">
  <span class="pm7-button--slider-text">Slide to confirm</span>
  <span class="pm7-button--slider-handle"></span>
</button>

Variant: --slider | Sizes: --sm, --lg