<!-- NOTE: All inline styles should be removed prior to implimentation -->

<h3 style="margin-bottom: 25px;">Types of notifications:</h3>

<div class="notification notification--success" role="notification">
    <span>This is a dismissible success notification</span>
    <button class="notification__close" aria-label="close notification" data-notification-close>
          x
        </button>
</div>
<div class="notification notification--info" role="notification">
    <span>This is a dismissible info notification</span>
    <button class="notification__close" aria-label="close notification" data-notification-close>
          x
        </button>
</div>
<div class="notification notification--warning" role="notification">
    <span>This is a dismissible warning notification</span>
    <button class="notification__close" aria-label="close notification" data-notification-close>
          x
        </button>
</div>
<div class="notification notification--error" role="notification">
    <span>This is a dismissible error notification</span>
    <button class="notification__close" aria-label="close notification" data-notification-close>
          x
        </button>
</div>

<h3 style="margin-top: 50px; margin-bottom: 25px;">Notification triggers:</h3>
<div data-notification-type="success" data-notification-text="This was successfull" data-is-dismissible>
    <button data-notification-trigger>Click me to add a notification with a dismiss button</button>
</div>
<!-- NOTE: All inline styles should be removed prior to implimentation -->

<h3 style="margin-bottom: 25px;">Types of notifications:</h3>

{% for notification in notifications %}
  <div class="notification notification--{{ notification.type }}" role="notification">
      <span>{{ notification.text }}</span>
      {% if notification.dismissButton %}
        <button class="notification__close" aria-label="close notification" data-notification-close>
          x
        </button>
      {% endif %}
  </div>
{% endfor %}

<h3 style="margin-top: 50px; margin-bottom: 25px;">Notification triggers:</h3>
<div data-notification-type="success" data-notification-text="This was successfull" data-is-dismissible>
  <button data-notification-trigger>Click me to add a notification with a dismiss button</button>
</div>
{
  "notifications": [
    {
      "type": "success",
      "text": "This is a dismissible success notification",
      "dismissButton": true
    },
    {
      "type": "info",
      "text": "This is a dismissible info notification",
      "dismissButton": true
    },
    {
      "type": "warning",
      "text": "This is a dismissible warning notification",
      "dismissButton": true
    },
    {
      "type": "error",
      "text": "This is a dismissible error notification",
      "dismissButton": true
    }
  ]
}
  • Content:
    .notification {
      position: relative;
      display: flex;
      flex-direction: row;
      align-items: center;
      justify-content: space-between;
      border: 1px solid color(neutral, lighter);
      padding: 12px;
      width: 100%;
    
      &__close {
        cursor: pointer;
      }
    
      &--success {
        background-color: rgba(color(success, base), .4);
      }
    
      &--info {
        background-color: rgba(color(secondary, base), .4);
      }
    
      &--warning {
        background-color: rgba(color(warning, base), .4);
      }
    
      &--error {
        background-color: rgba(color(primary, base), .4);
      }
    }
    
  • URL: /components/raw/notifications/_notifications.scss
  • Filesystem Path: components/notifications/_notifications.scss
  • Size: 546 Bytes
  • Content:
    <!-- NOTE: All inline styles should be removed prior to implimentation -->
    
    <h3 style="margin-bottom: 25px;">Types of notifications:</h3>
    <div class="notification notification--success" role="notification">
      <span>This is a dismissible success notification</span>
      <button class="notification__close" aria-label="close notification" data-notification-close>x</button>
    </div>
    
    <div class="notification notification--info" role="notification">
      <span>This is a dismissible info notification</span>
      <button class="notification__close" aria-label="close notification" data-notification-close>x</button>
    </div>
    
    <div class="notification notification--warning" role="notification">
      <span>This is a dismissible warning notification</span>
      <button class="notification__close" aria-label="close notification" data-notification-close>x</button>
    </div>
    
    <div class="notification notification--error" role="notification">
      <span>This is an error notification</span>
    </div>
    
    <h3 style="margin-top: 50px; margin-bottom: 25px;">Notification triggers:</h3>
    <div data-notification-type="success" data-notification-text="This was successfull" data-is-dismissible>
      <button data-notification-trigger>Click me to add a notification with a dismiss button</button>
    </div>
    
    <div data-notification-type="error" data-notification-text="This is an error">
      <button data-notification-trigger>Click me to add a notification without a dismiss button</button>
    </div>
  • URL: /components/raw/notifications/notifications.html
  • Filesystem Path: components/notifications/notifications.html
  • Size: 1.4 KB
  • Content:
    // Polyfills
    if (!Array.prototype.forEach) {
    	Array.prototype.forEach = function (callback, thisArg) {
    		thisArg = thisArg || window;
    		for (var i = 0; i < this.length; i++) {
    			callback.call(thisArg, this[i], i, this);
    		}
    	};
    }
    
    // Notifications Functionality
    let notificationTriggers = document.querySelectorAll('[data-notification-trigger]');
    let notificationCloseButtons = document.querySelectorAll('[data-notification-close]');
    
    for (let i = 0; i < notificationCloseButtons.length; i++) {
      notificationCloseButtons[i].addEventListener("click", () => {
        closeNotification(notificationCloseButtons[i]);
      })
    };
    
    for (let i = 0; i < notificationTriggers.length; i++) {
      notificationTriggers[i].addEventListener("click", () => {
        addNotification(notificationTriggers[i]);
      });
    };
    
    let addNotification = (e) => {
      let container = e.parentNode;
      let isDismissible = container.dataset.isDismissible;
      let text = container.dataset.notificationText;
      let type = container.dataset.notificationType;
      let template = '';
      let buttonString = '<button class="notification__close" aria-label="close notification" data-notification-close>x</button>';
    
      if (isDismissible === '') {
        template = '<div class="notification notification--' + type + ' notification--dismissible" role="notification"><span>' + text + '</span>' + buttonString +'</div>';
        container.innerHTML += template;
    
        let closeButton = container.querySelector('[data-notification-close]');
    
        closeButton.addEventListener("click", () => {
          closeNotification(closeButton);
        })
      } else {
        template = '<div class="notification notification--' + type + '" role=notification"><span>' + text + '</span></div>';
        container.innerHTML += template;
      }
    }
    
    let closeNotification = (e) => {
      let notification = e.parentNode;
      notification.parentNode.removeChild(notification);
    }
    
  • URL: /components/raw/notifications/notifications.js
  • Filesystem Path: components/notifications/notifications.js
  • Size: 1.9 KB

Usage

Notifications provide information or feedback to users depending on the situation.

This notification component comes with several configuration attributes. Use the data-notification-type attribute to select the notification type from the following options: succes, info, warning, error. Use the optional data-notification-text attribute to assign text that will be shown in the notification.

For notification triggers, the data-is-dismissible attribute determines whether or not the notification is dismissable. Lastly, the data-notification-trigger and data-notification-close attributes function as a trigger points for the notification to be opened or closed.

Labelling Expectations

  • If a notification includes a close button it should have an aria-label to describe the context of the button

Focus Expectations

  • Notification buttons should have visible keyboard focus state

Keyboard Expectations

  • Tab = Move to next focusable element
  • Space = Activate/close notifications