Menu

Menu

On this page

On this page

Notice

A component for highlighting messages to the user.

npm install @vrembem/notice
Copied!
SCSS
@use "@vrembem/notice";
Copied!

Options

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.

Design tokens

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.

VariableFallback
--vb-notice-foreground
Copied!
--vb-notice-background
Copied!
--vb-notice-border
Copied!
none
Copied!
--vb-notice-border-radius
Copied!
var(--vb-border-radius)
Copied!
--vb-notice-box-shadow
Copied!
none
Copied!
--vb-notice-padding
Copied!
1em 1.25em
Copied!
--vb-notice-spacing
Copied!
0.5em
Copied!
--vb-notice-title-font-size
Copied!
var(--vb-font-size-lg)
Copied!
--vb-notice-title-line-height
Copied!
--vb-notice-title-font-weight
Copied!
inherit
Copied!

Basic usage

The most basic implementation component consists of the notice container element wrapping text content.

This is an example notice.

HTML
<div class="notice">
  <p>...</p>
</div>
Copied!

Add a title to your notice using the notice__title element.

Notice title

This is an example notice with a title. Lorem ipsum dolor sit amet, consectetur adipiscing elit. Vivamus libero est, fermentum ac risus et.

HTML
<div class="notice">
  <h2 class="notice__title">...</h2>
  <p>...</p>
</div>
Copied!

Using flex layout

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.

HTML
<div class="notice">
  <div class="flex flex--wrap-no">
    <div class="flex-item-none">
      ...
    </div>
    <div class="flex-item-auto">
      ...
    </div>
  </div>
</div>
Copied!

Dismissible

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>
Copied!
// 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");
  });
});
Copied!

notice--color-[key]

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.

HTML
<div class="notice notice--color-important">
  <p>An error has occurred!</p>
</div>
Copied!

Available variants

  • notice--color-primary
  • notice--color-secondary
  • notice--color-neutral
  • notice--color-important