Components · Notifications

Modal

A modal is the most disruptive notification. It blocks the page until the user makes a decision, so use it only when the user must confirm or choose before going on.

How to open a modal from script and the CSS behind it. The files are eco-design-system/notifications.css and notifications.js.

Basic Usage

Link the shared files once per page. Never copy the rules into a page.

StepWhat to do
1. Link<link rel="stylesheet" href="/eco-design-system/notifications.css"> and <script src="/eco-design-system/notifications.js"></script>. Link button.css first.
2. OpenCall ECO_N.openModal({ size, title, body, cancel, confirm }). The script adds the overlay, the focus trap, the scroll lock and the three ways to close.
3. ReactonConfirm runs when the primary button is pressed; onClose(reason) runs on every close.


API

Settings of openModal

SettingUse
sizesmall (default) or large.
labelOptional uppercase label above the title.
title, bodyThe title and the body text.
cancel, confirmThe button labels. Defaults: Cancel, Confirm.
onConfirmRuns when the primary button is pressed.
onClose(reason)Reason: close, esc, overlay, cancel or confirm.

Custom properties

NameUse
--modal-in-ease, --modal-in-durationEnter. Defaults: ease-decelerate-emphasized, duration-fast-4.
--modal-out-ease, --modal-out-durationExit. Defaults: ease-accelerate-generic, duration-fast-3. Set on <html>.

Things to know

  • openModal returns { close, el }.
  • Page scroll is locked with body.has-modal. onClose and the focus return run at once; the dialog is removed after the fade out.
  • Buttons inside the modal are always 32px high, also when button.css is on the page.
  • Do not open a modal from a modal.

CSS / Tailwind

The component is one CSS file and one script, shared by every notification. Link them, never copy them. The code below is read from the files the page links, so it is always what you see.