The Modal component is a dialog box that is displayed on top of all site content. When a Modal is present, the rest of the site is inactive and covered by a mask. Use a Modal when you need the user to make a choice, or you need to present important information based on an action they took, or when you need to indicate something is happening. Modals are triggered by an action, usually, a form submit.
A Choice Modal poses a question to the user and allows them to take an action.
The Modal component in spark-core-angular consists of two Angular components:
This is some content that is in a modal. It explains what the modal is for. There will also be a way to close the modal.
<button class="sprk-c-Button" data-sprk-modal-trigger="exampleChoiceModal" type="button">
Open Choice Modal
</button>
<div class="sprk-c-Modal sprk-u-Display--none" role="dialog" tabindex="-1" aria-labelledby="modalChoiceHeading" aria-modal="true" aria-describedby="modalChoiceContent" data-sprk-modal="exampleChoiceModal">
<header class="sprk-c-Modal__header">
<h2 class="sprk-c-Modal__heading sprk-b-TypeDisplayFive" id="modalChoiceHeading">
Are you sure?
</h2>
<button class="sprk-c-Modal__icon" data-sprk-modal-cancel="exampleChoiceModal" type="button" aria-label="Close Modal">
<svg class="sprk-c-Icon sprk-c-Icon--l" viewBox="0 0 384 512" aria-hidden="true" focusable="false">
<use xlink:href="#times"></use>
</svg>
</button>
</header>
<div class="sprk-c-Modal__body">
<p class="sprk-b-TypeBodyTwo" id="modalChoiceContent">
This is some content that is in a modal. It explains what the modal is for. There will also be a way to close the modal.
</p>
</div>
<footer class="sprk-c-Modal__footer">
<button class="sprk-c-Button sprk-u-mrm">
Confirm
</button>
<a href="" class="sprk-b-Link sprk-b-Link--standalone" data-sprk-modal-cancel="exampleChoiceModal">
Cancel
</a>
</footer>
</div>
<div data-sprk-modal-mask="true" class="sprk-c-ModalMask sprk-u-Display--none" tabindex="-1"></div>
<sprk-button (click)="toggleChoiceModal($event)" additionalClasses="choice-button">
Choice Modal
</sprk-button>
<sprk-modal [(isVisible)]="false" title="Are you sure?" (hide)="toggleChoiceModal($event)" modalType="choice">
This is some content that is in a modal. It explains what the modal is for. There will also be a way to close the modal.
</sprk-modal>
See below for available customization options:
Input | Type | Description |
---|---|---|
modaltype | string | This determines the variation of the Modal that is rendered. Can be 'choice', 'info', or 'wait'. |
confirmText | string | The value supplied will be rendered as the text for the confirm button. |
cancelText | string | The value supplied will be rendered as the text for the cancel link. |
confirmAnalyticsString | string | The value supplied will be assigned to the 'data-analytics' attribute on the confirm button. Intended for an outside library to capture data. |
isVisible | boolean | If true, the modal will be shown. If false, the modal will not be shown. |
hide | function | When the modal is closed the hide event is emitted and a callback function can be triggered if supplied to hide. |
confirmClick | function | Available when the modal type is 'choice'. The modal will emit a confirm click event when the confirmation button is clicked. A callback function can be triggered if supplied to confirmClick. |
cancelClick | function | Available when the modal type is 'choice'. The modal will emit a cancel click event when the cancel link is clicked. A callback function can be triggered if supplied to cancelClick. |
An Info Modal shows information to the user.
To use the info modal set modalType to 'info'.
This is some content that is in a Modal. It explains what the Modal is for. There will also be a way to close the modal.
<button class="sprk-c-Button" data-sprk-modal-trigger="exampleInfoModal" type="button">
Open Info Modal
</button>
<div class="sprk-c-Modal sprk-u-Display--none" role="dialog" tabindex="-1" aria-labelledby="modalInfoHeading" aria-modal="true" aria-describedby="modalInfoContent" data-sprk-modal="exampleInfoModal">
<header class="sprk-c-Modal__header">
<h2 class="sprk-c-Modal__heading sprk-b-TypeDisplayFive" id="modalInfoHeading">
Info Modal
</h2>
<button class="sprk-c-Modal__icon" data-sprk-modal-cancel="exampleInfoModal" type="button" aria-label="Close Modal">
<svg class="sprk-c-Icon sprk-c-Icon--l" viewBox="0 0 384 512" aria-hidden="true" focusable="false">
<use xlink:href="#times"></use>
</svg>
</button>
</header>
<div class="sprk-c-Modal__body">
<p class="sprk-b-TypeBodyTwo" id="modalInfoContent">
This is some content that is in a Modal. It explains what the Modal is for. There will also be a way to close the modal.
</p>
</div>
</div>
<div data-sprk-modal-mask="true" class="sprk-c-ModalMask sprk-u-Display--none" tabindex="-1"></div>
<sprk-button (click)="toggleInfoModal($event)" additionalClasses="info-button">Info Modal</sprk-button>
<sprk-modal [(isVisible)]="false" title="For Your Information" (hide)="toggleInfoModal($event)" modalType="info">
This is some content that is in a Modal. It explains what the Modal is for. There will also be a way to close the modal.
</sprk-modal>
Wait Modals contain a spinner to indicate something is happening and can not be closed by the user. Wait Modal containers need the additional 'data-sprk-modal-type="wait"' HTML attribute.
To use the info modal set modalType to 'wait'.
This type of modal can't be closed by the user but will close shortly for demonstration purposes.
<button class="sprk-c-Button" data-sprk-modal-trigger="exampleWaitModal" type="button">
Open Wait Modal
</button>
<div class="sprk-c-Modal sprk-u-Display--none" role="dialog" tabindex="-1" aria-labelledby="modalWaitHeading" aria-modal="true" aria-describedby="modalWaitContent" data-sprk-modal="exampleWaitModal" data-sprk-modal-type="wait">
<header class="sprk-c-Modal__header">
<h2 class="sprk-c-Modal__heading sprk-b-TypeDisplayFive" id="modalWaitHeading">
Please Wait...
</h2>
<div class="sprk-c-Modal__icon">
<div class="sprk-c-Spinner sprk-c-Spinner--circle sprk-c-Spinner--large"></div>
</div>
</header>
<div class="sprk-c-Modal__body">
<p class="sprk-b-TypeBodyTwo" id="modalWaitContent">
This type of modal can't be closed by the user but will close shortly for demonstration purposes.
</p>
</div>
</div>
<div data-sprk-modal-mask="true" class="sprk-c-ModalMask sprk-u-Display--none" tabindex="-1"></div>
<sprk-button (click)="toggleWaitModal($event)" additionalClasses="wait-button">Wait Modal</sprk-button>
<sprk-modal [(isVisible)]="false" title="Please wait..." (hide)="toggleWaitModal($event)" modalType="wait">
This type of modal can't be closed by the user but will close shortly for demonstration purposes.
</sprk-modal>