Notice
A component for highlighting messages to the user.
A component for highlighting messages to the user.
npm install @vrembem/notice@use "@vrembem/notice";Notice uses design token CSS variables in a reference and fallback pattern. Variables are referenced in the component's styles but are not directly defined; instead, they are provided with sensible fallbacks.
Notice uses design token CSS variables in a reference and fallback pattern. Variables are referenced in the component's styles but are not directly defined; instead, they are provided with sensible fallbacks.
| Variable | Fallback |
|---|---|
Copied! | Copied! |
Copied! | Copied! |
Copied! | Copied! |
Copied! | Copied! |
Copied! | Copied! |
Copied! | Copied! |
Copied! | Copied! |
Copied! | Copied! |
Copied! | Copied! |
Copied! | Copied! |
There are no variables that match your search.
The most basic implementation component consists of the notice container element wrapping text content.
This is an example notice.
<div class="notice">
<p>...</p>
</div>Add a title to your notice using the notice__title element.
This is an example notice with a title. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus libero est, fermentum ac risus et.
<div class="notice">
<h2 class="notice__title">...</h2>
<p>...</p>
</div>For cases where a notice message should be displayed alongside an icon or image, try combining it with the flex layout component.
This is an example notice using the flex component for layout.
This is an example notice using the flex component for layout.
<div class="notice">
<div class="flex flex--wrap-no">
<div class="flex-item-none">
...
</div>
<div class="flex-item-auto">
...
</div>
</div>
</div>It's a common pattern to allow users to dismiss notices. This can be accomplished using the button component along with some simple vanilla JavaScript.
This is an example notice with a dismiss button.
<div class="notice">
<div class="flex justify-content-between">
<p>...</p>
<button
class="button button--icon button--size-sm"
aria-label="Dismiss this notice"
data-dismiss=".notice"
>
...
</button>
</div>
</div>// Get the button elements
const btns = document.querySelectorAll("[data-dismiss]");
// Loop through them and add click event listeners
btns.forEach((btn) => {
btn.addEventListener("click", (event) => {
// Get the value of data-dismiss and select the nearest matching element
const selector = btn.getAttribute("data-dismiss");
const result = event.target.closest(selector);
// Hide the notice if it exists
if (result) result.classList.add("display-none");
});
});Applies a color theme to the notice, useful for conveying different states such as success, info, or error. These modifiers are generated using the palette theme tokens.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus libero est, fermentum ac risus et.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus libero est, fermentum ac risus et.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus libero est, fermentum ac risus et.
Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus libero est, fermentum ac risus et.
<div class="notice notice--color-important">
<p>An error has occurred!</p>
</div>Available variants
notice--color-primarynotice--color-secondarynotice--color-neutralnotice--color-important