Settings

Sidebar
Display
Profile Panel
👤

John Doe

Administrator
  • 📊 Dashboard
  • 📝 Forms
  • 📋 Tables
Commands
🚀
Go to Page
Navigate to a page
/go
🌓
Toggle Theme
Switch between light and dark mode
/theme
📐
Toggle Sidebar
Show or hide the sidebar
/sidebar
⚙️
Open Settings
Open the settings panel
/settings
Search In
📄
Pages
Search pages
:p
🧩
Components
Search component pages
:c
dialogService is for simple text-only dialogs
The message property only accepts a plain string rendered as a <Paragraph>. For complex body content — forms, formatted text, grids, tables, or any Svelte components — use a <Modal> component directly instead. See the Modals page for examples.

Basic Usage

All dialog functions return Promises, so you can use async/await for clean, synchronous-looking code:

// Confirm dialog
const confirmed = await dialogService.confirm({
  title: 'Delete Item?',
  message: 'This action cannot be undone.',
  variant: 'danger'
});

if (confirmed) {
  // User clicked OK
}

// Alert dialog
await dialogService.alert({
  title: 'Success!',
  message: 'Your changes have been saved.',
  variant: 'success'
});

// Prompt dialog
const name = await dialogService.prompt({
  title: 'Enter Name',
  message: 'Please enter your name:',
  defaultValue: 'John Doe'
});

if (name !== null) {
  console.log('User entered:', name);
}

Confirm Dialogs

Two-button dialogs that return true (confirmed) or false (cancelled).

Position Options

Dialogs can be positioned in the center (default) or at the top of the viewport.

// Center position (default)
await dialogService.alert({
  title: 'Centered',
  message: 'This dialog is centered.',
  position: 'center'  // default
});

// Top position
await dialogService.prompt({
  title: 'Top Position',
  message: 'This dialog appears near the top.',
  position: 'top'
});

Alert Dialogs

Single-button dialogs for notifications. Just wait for the user to acknowledge.

Prompt Dialogs

Text input dialogs that return the entered value (or null if cancelled).

Sequential Dialogs

Chain multiple dialogs together using async/await:

async function sequentialDialogs() {
  const name = await dialogService.prompt({
    title: 'Step 1 of 3',
    message: 'Enter your name:'
  });

  if (name === null) return;

  const email = await dialogService.prompt({
    title: 'Step 2 of 3',
    message: 'Enter your email:'
  });

  if (email === null) return;

  const confirmed = await dialogService.confirm({
    title: 'Step 3 of 3',
    message: `Confirm: ${name} <${email}>`,
    variant: 'success'
  });

  if (confirmed) {
    await dialogService.alert({
      title: 'Complete!',
      message: 'Registration successful.',
      variant: 'success'
    });
  }
}

Custom Dialogs

Define your own buttons with typed return values using dialogService.custom().

// Custom dialog with typed return values
const result = await dialogService.custom<'save' | 'discard' | 'cancel'>({
  title: 'Unsaved Changes',
  message: 'You have unsaved changes.',
  variant: 'warning',
  dismissValue: 'cancel',  // Returned on Escape/backdrop click
  buttons: [
    { label: 'Cancel', value: 'cancel', variant: 'secondary' },
    { label: 'Discard', value: 'discard', variant: 'danger', isOutline: true },
    { label: 'Save', value: 'save', variant: 'success' }
  ]
});

switch (result) {
  case 'save':
    await saveDocument();
    break;
  case 'discard':
    discardChanges();
    break;
  case 'cancel':
    // User cancelled
    break;
}

API Reference

dialogService.confirm(options)

Returns Promise<boolean>

OptionTypeDefaultDescription
titlestring'Confirm'Dialog title
messagestring'Are you sure?'Dialog message
confirmTextstring'OK'Confirm button text
cancelTextstring'Cancel'Cancel button text
variantstring'primary'Header theme: primary, success, warning, danger
confirmVariantstring(same as variant)Confirm button style
sizestring'sm'Modal size: sm, md, lg, xl
positionstring'center'Vertical position: center, top
closeOnBackdropbooleantrueClose when clicking outside

dialogService.alert(options)

Returns Promise<void>

OptionTypeDefaultDescription
titlestring'Alert'Dialog title
messagestring''Dialog message
okTextstring'OK'Button text
variantstring'primary'Header and button theme
sizestring'sm'Modal size
positionstring'center'Vertical position: center, top

dialogService.prompt(options)

Returns Promise<string | null>

OptionTypeDefaultDescription
titlestring'Input'Dialog title
messagestring'Enter value:'Dialog message
defaultValuestring''Initial input value
placeholderstring''Input placeholder
confirmTextstring'OK'Confirm button text
cancelTextstring'Cancel'Cancel button text
validatorfunctionnullValidation function: (value) => true | string
variantstring'primary'Header theme
sizestring'sm'Modal size
positionstring'center'Vertical position: center, top

dialogService.custom<T>(options)

Returns Promise<T> - the value of the clicked button

OptionTypeDefaultDescription
titlestring'Dialog'Dialog title
messagestring''Dialog message
buttonsDialogButton[](required)Array of button definitions
dismissValueTundefinedValue returned on Escape/backdrop click
variantstring'primary'Header theme
sizestring'sm'Modal size: sm, md, lg, xl
positionstring'center'Vertical position: center, top
classstring''Additional modal class
bodyClassstring''Additional body class
footerClassstring''Additional footer class

DialogButton<T>

Button definition for custom dialogs

PropertyTypeDefaultDescription
labelstring(required)Button text
valueT(required)Value returned when clicked
variantstring'secondary'Button style variant
outlinebooleanfalseUse isOutline button style
classstring''Additional button class
disabledbooleanfalseDisable the button

Keyboard Shortcuts

No shortcuts registered.