Dialog

Dialogs are modal overlays that require user interaction. They're used for critical information, confirmation, or complex tasks that require focus.

When to use

  • To confirm destructive actions (delete, remove, etc.)
  • To collect information through forms
  • To display important information that requires acknowledgment
  • For focused tasks that shouldn't be interrupted
  • When you need to prevent interaction with the rest of the page

Key features

  • Modal behavior - Blocks interaction with the rest of the page
  • Multiple sizes - Small, medium, large, and full-screen options
  • Focus management - Traps focus within the dialog
  • Keyboard support - ESC to close, Tab to navigate
  • Customizable content - Header, body, and footer sections
  • Accessible - Full ARIA support and screen reader friendly

Anatomy

A dialog consists of the following structure:

Main Structure

  • Container (.pm7-dialog) - Main wrapper with behavior attributes
  • Overlay (.pm7-dialog-overlay) - Semi-transparent backdrop
  • Content (.pm7-dialog-content) - The dialog box container

Content Markers (Input)

These attributes are used on the root pm7-dialog element or its direct children to define content and behavior:

  • data-pm7-dialog="id" - Unique identifier for the dialog
  • pm7-dialog-size - Dialog size: sm, md, lg, xl, full
  • pm7-dialog-icon - Icon type: info, warning, error, success
  • pm7-show-close - Shows the X close button in header
  • pm7-header-separator - Add line separator under header
  • pm7-no-escape - Prevents closing dialog with ESC key
  • pm7-no-overlay-close - Prevents closing dialog when clicking backdrop
  • pm7-header - Marks the header section. Content within this element becomes the header.
  • pm7-dialog-title - Text for the main dialog title (used with pm7-header)
  • pm7-dialog-subtitle - Text for the dialog subtitle/description (used with pm7-header)
  • pm7-body - Marks the main content area
  • pm7-footer - Marks the footer section for actions

Generated Elements (Output)

Based on the content markers, the following HTML elements and classes are generated:

  • Header Container (.pm7-dialog-header)
  • Header Text Container (.pm7-dialog-header-text) - Wraps title and description
  • Icon (.pm7-dialog-icon) - SVG icon based on pm7-dialog-icon
  • Title (.pm7-dialog-title) - H2 element for pm7-dialog-title
  • Description (.pm7-dialog-description) - P element for pm7-dialog-subtitle
  • Close Button (.pm7-dialog-close) - Button with X icon when pm7-show-close is set
  • Header Separator (.pm7-dialog-header-separator) - Line when pm7-header-separator is set
  • Body Container (.pm7-dialog-body)
  • Footer Container (.pm7-dialog-footer)

Size Variants

  • .pm7-dialog-content--sm - Small (400px max-width)
  • .pm7-dialog-content--md - Medium (600px max-width, default)
  • .pm7-dialog-content--lg - Large (800px max-width)
  • .pm7-dialog-content--xl - Extra large (1000px max-width)
  • .pm7-dialog-content--full - Full screen

Style Variants

  • .pm7-dialog--alert - Error/warning style
  • .pm7-dialog--success - Success style
  • .pm7-dialog--loading - Loading state with spinner

Basic Dialog

Dialog Sizes

Alert Dialog

Form Dialog

Scrollable Content

Confirmation Dialog

Multi-Step Dialog

Dialog with Icon

Dialog with Description

Loading Dialog (Body Only)

Cookie Bar (Footer Only)

Custom Header with Avatar

Mixed Header (Generated + Custom)

Dialog Section Combinations

Installation

npm install @pm7/core

CSS Classes

Class Description
Base Classes
.pm7-dialog Root dialog container (hidden by default, controlled by `data-state` attribute)
.pm7-dialog-open Applied to <body> when any dialog is open to prevent scrolling
.pm7-dialog-overlay Semi-transparent backdrop that covers the page when dialog is open
.pm7-dialog-content Container for the dialog box itself (header, body, footer)
Size Modifiers
.pm7-dialog-content--sm Small dialog (max-width: 400px)
.pm7-dialog-content--md Medium dialog (max-width: 600px, default)
.pm7-dialog-content--lg Large dialog (max-width: 800px)
.pm7-dialog-content--xl Extra large dialog (max-width: 1000px)
.pm7-dialog-content--full Full screen dialog
Dialog Variants
.pm7-dialog--alert Alert variant (red header)
.pm7-dialog--success Success variant (green header)
.pm7-dialog--loading Loading variant with spinner
.pm7-dialog--shake Shake animation effect
Structure Classes
.pm7-dialog-header Dialog header section (generated by `data-pm7-header` attribute)
.pm7-dialog-header-text Container for dialog title and description within the header
.pm7-dialog-header-actions Container for icon and close button within the header
.pm7-dialog-header-separator Horizontal line separator below the header
.pm7-dialog-title Main title of the dialog (generated by `data-pm7-dialog-title` attribute)
.pm7-dialog-description Subtitle or description of the dialog (generated by `data-pm7-dialog-subtitle` attribute)
.pm7-dialog-icon Container for the dialog icon (generated by `data-pm7-dialog-icon` attribute)
.pm7-dialog-close Close button (generated by `data-pm7-show-close` attribute)
.pm7-dialog-body Main content area of the dialog (generated by `data-pm7-body` attribute)
.pm7-dialog-footer Footer section for actions (generated by `data-pm7-footer` attribute)
.pm7-dialog-spinner Loading spinner element

Data Attributes

PM7 Dialog supports two approaches: Traditional HTML structure and the new Content Marker system that automatically generates dialog structure.

Root Dialog Attributes

Attribute Type Default Description
data-pm7-dialog="id" String Required Unique identifier for the dialog
data-pm7-dialog-size String "md" Dialog size: sm (400px), md (600px), lg (800px), xl (1000px), full
data-pm7-show-close Boolean false Shows the X close button in header
data-pm7-no-escape Boolean false Prevents closing dialog with ESC key
data-pm7-no-overlay-close Boolean false Prevents closing dialog when clicking backdrop
data-state String "closed" Dialog state: "open", "closing", or "closed" (managed automatically)

Content Marker Attributes (for sections)

Attribute Description Generated Structure
data-pm7-header Marks element as header section Generates .pm7-dialog-header with title, subtitle, icon, and close button
data-pm7-dialog-title Title text for the dialog header Creates .pm7-dialog-title element
data-pm7-dialog-subtitle Subtitle/description text for the dialog header Creates .pm7-dialog-description element
data-pm7-dialog-icon Icon type: info, warning, error, success Creates .pm7-dialog-icon with SVG
data-pm7-header-separator Add horizontal line separator under header Creates .pm7-dialog-header-separator element
data-pm7-body Marks element as body section Wraps content in .pm7-dialog-body
data-pm7-footer Marks element as footer section Wraps content in .pm7-dialog-footer

Legacy Content Marker Attributes

Note: These attributes (without data- prefix) are deprecated but still supported for backward compatibility.

Attribute Description
pm7-header Same as data-pm7-header
pm7-subtitle Same as data-pm7-subtitle
pm7-body Same as data-pm7-body
pm7-footer Same as data-pm7-footer

Basic Usage

<!-- Content Marker System (Recommended) -->
<div class="pm7-dialog" 
     data-pm7-dialog="my-dialog" 
     data-pm7-dialog-size="md" 
     data-pm7-show-close>
  <div data-pm7-header
       data-pm7-dialog-title="Dialog Title"
       data-pm7-dialog-subtitle="Optional subtitle text"
       data-pm7-header-separator>
  </div>
  
  <div data-pm7-body>
    <p>Your dialog content goes here.</p>
  </div>
  
  <div data-pm7-footer>
    <button class="pm7-button pm7-button--outline" onclick="closeDialog('my-dialog')">
      Cancel
    </button>
    <button class="pm7-button pm7-button--primary">
      Confirm
    </button>
  </div>
</div>

<!-- Dialog with Icon -->
<div class="pm7-dialog" 
     data-pm7-dialog="info-dialog" 
     data-pm7-dialog-size="sm">
  <div data-pm7-header
       data-pm7-dialog-title="Information"
       data-pm7-dialog-icon="info"
       data-pm7-header-separator>
  </div>
  <div data-pm7-body>
    <p>This is an informational message.</p>
  </div>
  <div data-pm7-footer>
    <button class="pm7-button pm7-button--primary" onclick="closeDialog('info-dialog')">
      Got it
    </button>
  </div>
</div>

<!-- Traditional HTML Structure -->
<div class="pm7-dialog" data-pm7-dialog="traditional-dialog">
  <div class="pm7-dialog-overlay"></div>
  <div class="pm7-dialog-content pm7-dialog-content--md">
    <div class="pm7-dialog-header">
      <h2 class="pm7-dialog-title">Dialog Title</h2>
      <button class="pm7-dialog-close" aria-label="Close">
        <svg width="24" height="24" viewBox="0 0 24 24" fill="none" stroke="currentColor" stroke-width="2">
          <line x1="18" y1="6" x2="6" y2="18"/>
          <line x1="6" y1="6" x2="18" y2="18"/>
        </svg>
      </button>
    </div>
    <div class="pm7-dialog-body">
      <p>Dialog content goes here.</p>
    </div>
    <div class="pm7-dialog-footer">
      <button class="pm7-button pm7-button--outline" onclick="closeDialog('traditional-dialog')">
        Cancel
      </button>
      <button class="pm7-button pm7-button--primary">
        Confirm
      </button>
    </div>
  </div>
</div>

<!-- Trigger Button -->
<button class="pm7-button" onclick="openDialog('my-dialog')">
  Open Dialog
</button>

JavaScript API

The following functions are globally available for convenience, but can also be imported from @pm7/core:

  • openDialog(id): Opens a dialog by its `pm7-dialog` ID.
  • closeDialog(id): Closes a dialog by its `pm7-dialog` ID.
  • pm7Alert(message, options): Shows a simple alert dialog.
  • pm7Confirm(message, callback, options): Shows a confirmation dialog.
import { PM7Dialog, createDialog, pm7Alert, pm7Confirm } from '@pm7/core';

// Initialize a dialog (for traditional structure)
const dialogElement = document.querySelector('[data-pm7-dialog="my-dialog"]');
const dialog = new PM7Dialog(dialogElement);

// Open/close programmatically
dialog.open();
dialog.close();

// Add shake animation
dialog.shake();

// Set loading state
dialog.setLoading(true);

// Listen for events
dialogElement.addEventListener('pm7-dialog-open', () => {
  console.log('Dialog opened');
});

dialogElement.addEventListener('pm7-dialog-close', () => {
  console.log('Dialog closed');
});

// Global functions (auto-loaded)
openDialog('my-dialog');
closeDialog('my-dialog');

// Programmatic dialog creation
const dialog = createDialog({
  id: 'dynamic-dialog',
  title: 'Dynamic Dialog',
  subtitle: 'Created programmatically',
  body: '<p>This dialog was created with JavaScript.</p>',
  footer: `
    <button class="pm7-button pm7-button--primary" onclick="closeDialog('dynamic-dialog')">
      Close
    </button>
  `,
  size: 'md',
  showClose: true,
  icon: 'info'
});

// Utility functions
pm7Alert('This is an alert message');
pm7Confirm('Are you sure?', (confirmed) => {
  if (confirmed) {
    console.log('User confirmed');
  }
});

CSS Customization

Dialogs support dark mode and can be customized with CSS variables:

:root {
  --pm7-dialog-bg: white;
  --pm7-dialog-overlay-bg: rgb(0 0 0 / 0.5);
}

[data-theme="dark"] {
  --pm7-dialog-bg: #1a1a1a;
  --pm7-dialog-overlay-bg: rgb(0 0 0 / 0.8);
}

React Usage

Note: The React wrapper will need to be updated to support the new structure. The vanilla JavaScript version uses the new content markers as shown above.

// Future React API (to be implemented)
import { Dialog } from '@pm7/react';

function MyComponent() {
  return (
    <div className="pm7-dialog" data-pm7-dialog="react-dialog">
      <div data-pm7-header data-pm7-dialog-title="Edit Profile"></div>
      <div data-pm7-body>
        <p>Dialog content goes here</p>
      </div>
      <div data-pm7-footer>
        <button className="pm7-button pm7-button--outline">
          Cancel
        </button>
        <button className="pm7-button pm7-button--primary">
          Save Changes
        </button>
      </div>
    </div>
  );
}

Accessibility

  • Focus trap: Focus stays within dialog while open
  • Escape key: Closes the dialog (unless pm7-no-escape is set)
  • Click outside: Closes dialog by clicking overlay (unless pm7-no-overlay-close is set)
  • Focus restoration: Focus returns to trigger element on close
  • ARIA attributes: Proper roles and labels for screen readers
  • Heading hierarchy: Semantic heading structure
  • Keyboard navigation: Tab through interactive elements

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/dialog/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 Dialog implementation guidance.

Perfect for ChatGPT, Claude, and other AI code assistants

This is the main content of the dialog. You can put any React node here.

Small dialogs are perfect for quick confirmations, simple messages, or compact forms. The narrow width (400px) keeps content focused and easy to read.

💡 Use for: Confirmations, alerts, simple inputs

Medium dialogs provide a comfortable reading width for most content. This is the default and recommended size for general purpose dialogs.

Example Form

💡 Use for: Forms, detailed messages, standard modals

Large dialogs offer generous space for complex content like multi-column layouts, data tables, or detailed forms.

Feature Status Progress
User Authentication ✓ Complete 100%
Dashboard Design In Progress 75%
API Integration Pending 0%

💡 Use for: Tables, multi-column forms, detailed content

This is a full screen dialog. It takes up the entire viewport and is useful for immersive experiences or complex workflows.

This action cannot be undone. Are you sure you want to delete this item?

This action cannot be undone. Are you sure you want to delete this item?

1. Terms

By accessing this website, you are agreeing to be bound by these website Terms and Conditions of Use, all applicable laws and regulations, and agree that you are responsible for compliance with any applicable local laws.

2. Use License

Permission is granted to temporarily download one copy of the materials (information or software) on our website for personal, non-commercial transitory viewing only.

3. Disclaimer

The materials on our website are provided "as is". We make no warranties, expressed or implied, and hereby disclaim and negate all other warranties.

4. Limitations

In no event shall our company or its suppliers be liable for any damages (including, without limitation, damages for loss of data or profit, or due to business interruption) arising out of the use or inability to use the materials on our website.

5. Revisions and Errata

The materials appearing on our website could include technical, typographical, or photographic errors. We do not warrant that any of the materials on its website are accurate, complete, or current.

6. Links

We have not reviewed all of the sites linked to our website and are not responsible for the contents of any such linked site.

7. Site Terms of Use Modifications

We may revise these terms of use for its website at any time without notice. By using this website, you are agreeing to be bound by the then current version of these Terms and Conditions of Use.

8. Governing Law

Any claim relating to our website shall be governed by the laws of the Netherlands without regard to its conflict of law provisions.

Delete Account?

This action cannot be undone. All your data will be permanently deleted.

Welcome to the Setup Wizard

This wizard will guide you through the initial setup process. Let's start with some basic information.

What's New

The update will be installed automatically when you restart the application.

Loading...

We use cookies to enhance your experience. By continuing to visit this site you agree to our use of cookies.
JD

John Doe

Active now

Hey! How can I help you today?

Hi! I have a question about my order.

Email Notifications

Push Notifications

This dialog only contains a body section with content. No header or footer is present.

This dialog only has a footer section.

This dialog has body content and a footer, but no header section.

Useful for simple confirmations or messages.

This dialog has a header and body section, but no footer with actions.

The user can close it using the X button or by clicking outside.