No Preview

Sorry, but you either have no stories or none are selected somehow.

If the problem persists, check the browser console, or the terminal you've run Storybook from.

The component failed to render properly, likely due to a configuration issue in Storybook. Here are some common causes and how you can address them:

  1. Missing Context/Providers: You can use decorators to supply specific contexts or providers, which are sometimes necessary for components to render correctly. For detailed instructions on using decorators, please visit the Decorators documentation.
  2. Misconfigured Webpack or Vite: Verify that Storybook picks up all necessary settings for loaders, plugins, and other relevant parameters. You can find step-by-step guides for configuring Webpack or Vite with Storybook.
  3. Missing Environment Variables: Your Storybook may require specific environment variables to function as intended. You can set up custom environment variables as outlined in the Environment Variables documentation.

This is a pre-release version and is not production ready. For new and ongoing projects, please refer to the latest Design System version.

Dialog

Communicate crucial information and request user action.

For more information on the dialog element, please refer to the MDN documentation.

Dialog

This is a dialog
<dialog class="palette-default"> <form method="dialog" class="dialog-grid"> <h3 class="dialog-header"><h2>Dialog</h2></h3> <div class="dialog-body">This is a dialog</div> <div class="dialog-controls"> <button class="btn btn-primary">OK</button> <button class="btn btn-secondary">Cancel</button> </div> <button class="btn btn-close"> <span class="visually-hidden">Close</span> </button> </form> </dialog>
NameDescriptionDefaultControl
Content
Title
Optional title
string
-
Content
Dialog text
string
-
Icon
Display an icon in the dialog.
string
-
Close button
Show a close button to dismiss the dialog
boolean
-
Variant
Size
Max width of the dialog.
string
-
Position
Position of the dialog on the screen
string
-
Palette
The color scheme of the dialog
string
-
Animation
Choose an animation effect for showing and hidding the dialog.
string
-

Make sure the @swisspost/design-system-styles package is already present in your project or follow the installation guidelines.

To import all Design System styles:

@use '@swisspost/design-system-styles/post-compact.scss';

To import only the styles required for this component:

@use '@swisspost/design-system-styles/basics.scss'; @use '@swisspost/design-system-styles/components/dialog.scss';

Form example

Hintus textus elare volare cantare hendrerit in vulputate velit esse molestie consequat, vel illum dolore eu feugiat nulla facilisis.

Register a submit event listener on the form. In the event handler, you have access to all the form field values inside the dialog. The dialog box closes when the form gets submitted.

document.querySelector('#example-dialog-form')?.addEventListener('submit', event => { if (!event.target) return; const formData = Object.fromEntries(new FormData(event.target as HTMLFormElement)); // Object containing your form data console.log(formData); });

The dialog can also contain arbitrary content.

Custom content

This is some other content, just placed inside the dialog.