Skip to content

Dialog Component

A modal dialog Web Component wrapping the native <dialog> element.

Live Preview

Import: @bnotk/dsx/components/dialog.js

PropertyTypeDefaultDescription
headingstring''Dialog title
size'sm' | 'md' | 'lg''md'Dialog width
status'warning' | 'error' | 'success' | ''''Header color accent
draggablebooleanfalseAllow dragging the dialog
openboolean (read-only)falseWhether the dialog is open
MethodDescription
show()Open the dialog as a modal
close(returnValue?)Close the dialog
SlotDescription
bodyMain dialog content
footerFooter with action buttons
EventDetailDescription
dsx-close&#123; returnValue: string &#125;Dialog was closed
<script type="module">
import '@bnotk/dsx/components/dialog.js';
</script>
<button class="dsx-btn dsx-btn--primary"
onclick="document.querySelector('#my-dialog').show()">
Open Dialog
</button>
<dsx-dialog id="my-dialog" heading="Confirm Action" size="md" status="warning">
<p slot="body">Are you sure you want to proceed?</p>
<div slot="footer">
<button class="dsx-btn dsx-btn--secondary"
onclick="document.querySelector('#my-dialog').close()">Cancel</button>
<button class="dsx-btn dsx-btn--primary"
onclick="document.querySelector('#my-dialog').close('confirm')">Confirm</button>
</div>
</dsx-dialog>
  • sm — max-width 24rem (384px)
  • md — max-width 32rem (512px)
  • lg — max-width 48rem (768px)

The status property adds a colored accent to the dialog header:

  • warning — Orange accent
  • error — Red accent
  • success — Green accent