Skip to main content
VelinStyle v0.8.0
⌂ Home
  1. Docs
  2. Components
  3. Dialog

Dialog

The <velin-dialog> Web Component wraps the native <dialog> element and provides a promise-based JavaScript API for alert, confirm, and prompt interactions.

Basic Example

<velin-dialog id="myDialog"></velin-dialog>

<script>
  const dlg = document.getElementById('myDialog');

  // Alert — returns Promise<true>
  await dlg.alert('Hello!');

  // Confirm — returns Promise<boolean>
  const ok = await dlg.confirm('Delete this item?', {
    title: 'Confirm delete',
    danger: true
  });

  // Prompt — returns Promise<string | null>
  const name = await dlg.prompt('What is your name?', {
    placeholder: 'Enter name…',
    defaultValue: 'World'
  });
</script>

Accessibility

CSS Variables

VariableDescription
--velin-radius-lgDialog border radius
--velin-shadow-xlDialog shadow
--velin-color-surface-brightDialog background
--velin-color-borderHeader/footer borders
--velin-color-primaryPrimary button & focus ring
--velin-color-dangerDanger confirm button

JavaScript API

Methods

MethodReturnsDescription
alert(message, options?)Promise<true>Show an alert dialog
confirm(message, options?)Promise<boolean>Show a confirm dialog
prompt(message, options?)Promise<string|null>Show a prompt dialog (null if cancelled)

Options

OptionDefaultDescription
titlevariesDialog title text
confirmText"OK" / "Confirm"Confirm button label
cancelText"Cancel"Cancel button label
dangerfalseUse danger-styled confirm button
placeholder""Prompt input placeholder
defaultValue""Prompt input default value

Events

EventDetailDescription
velin-dialog-close{ value }Fired when the dialog closes with the resolved value

Theme wählen