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 version is no longer actively maintained and has reached End-of-Life (EOL). For new and ongoing projects, please refer to the latest Design System version.

Display information that requires the user’s immediate attention.

The modal is an ng-bootstrap component.

This documentation gives only the specifics for a usage within Post project.
Read the complete information about the component's configuration in ng-bootstrap modal documentation.

Make sure the @ng-bootstrap/ng-bootstrap package is already present in your project or follow ng-bootstrap installation guidelines.

To import all ng-bootstrap components:

import { NgbModule } from '@ng-bootstrap/ng-bootstrap'; @NgModule({ imports: [NgbModule], }) export class YourAppModule { }

To import only this component:

import {NgbModalModule} from '@ng-bootstrap/ng-bootstrap'; @NgModule({ imports: [NgbModalModule], }) export class YourAppModule { }

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/index.scss';

To import only the styles required for this component:

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

Since the modal appears above the page, generally blocking interaction with the content below, it is important that the focus is move to an element within it.

By default, it is the first focusable element within the modal that receives focus upon opening. However, You can decide to focus any other element by adding an ngbAutofocus attribute to it.

Varying Content
import { Component, Input } from '@angular/core'; import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap'; @Component({ selector: 'ngb-modal-content', standalone: true, template: ` <div class="modal-header"> <h4 class="modal-title">Hi there!</h4> <button type="button" class="btn-close" aria-label="Close" (click)="activeModal.dismiss()" ></button> </div> <div class="modal-body"> <p>Hello, {{ name }}!</p> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" (click)="activeModal.close()">Close</button> </div> `, }) export class ModalComponent { @Input() name; constructor(public activeModal: NgbActiveModal) {} } @Component({ selector: 'ngb-modal-component', standalone: true, template: ` <button class="btn btn-secondary" (click)="open('foo')">Open with foo</button> <button class="btn btn-secondary" (click)="open('bar')">Open with bar</button> `, }) export class HostComponent { constructor(private modalService: NgbModal) {} open(name: string) { const modalRef = this.modalService.open(ModalComponent); modalRef.componentInstance.name = name; } }
Focused Content
import { Component } from '@angular/core'; import { FormsModule } from '@angular/forms'; import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap'; @Component({ selector: 'ngb-modal-content', standalone: true, imports: [FormsModule], template: ` <div class="modal-header"> <h4 id="modalTitle" class="modal-title">What is your name?</h4> <button type="button" class="btn-close" aria-label="Close" (click)="activeModal.dismiss()" ></button> </div> <div class="modal-body"> <input ngbAutofocus [(ngModel)]="name" type="text" class="form-control" aria-labelledby="modalTitle" /> </div> <div class="modal-footer"> <button type="button" class="btn btn-primary" (click)="activeModal.close(name)"> Validate </button> </div> `, }) export class ModalComponent { name = ''; constructor(public activeModal: NgbActiveModal) {} } @Component({ selector: 'ngb-modal-component', standalone: true, template: ` <button class="btn btn-secondary" (click)="open()">Open modal</button> `, }) export class HostComponent { constructor(private modalService: NgbModal) {} open() { const modalRef = this.modalService.open(ModalComponent); modalRef.result .catch(() => { console.error('Modal was dismissed.'); }) .then((name: string) => { console.info(`The name is: ${name}`); }); } }
Mandatory Confirmation
import { Component } from '@angular/core'; import { NgbActiveModal, NgbModal } from '@ng-bootstrap/ng-bootstrap'; @Component({ selector: 'ngb-modal-content', standalone: true, template: ` <div class="modal-header"> <h4 class="modal-title">Confirmation</h4> </div> <div class="modal-body"> <p>Do you confirm?</p> </div> <div class="modal-footer"> <button type="button" class="btn btn-secondary" (click)="activeModal.close(false)">No</button> <button type="button" class="btn btn-primary" (click)="activeModal.close(true)">Yes</button> </div> `, }) export class ModalComponent { constructor(public activeModal: NgbActiveModal) {} } @Component({ selector: 'ngb-modal-component', standalone: true, template: ` <button class="btn btn-secondary" (click)="open()">Open Modal</button> `, }) export class HostComponent { constructor(private modalService: NgbModal) {} open() { const modalRef = this.modalService.open(ModalComponent, { backdrop: 'static', keyboard: false, }); modalRef.result .catch(() => { console.error('Modal dismissal is actually not be possible.'); }) .then((isConfirmed: boolean) => { console.info(`Confirmed? ${isConfirmed}`); }); } }