← Back to Components

notification-tray Component Documentation

{{componentName}}

Notification Tray Component

A web component that displays a notification bell icon with a dropdown panel for displaying notifications. The component supports both light and dark themes, and provides methods for managing notifications.

Usage

<!-- Load the component -->
<script type="module" src="assets/components/notification-tray/qds-notification-tray.js"></script>

<!-- Use the component -->
<qds-notification-tray></qds-notification-tray>

Properties

Attributes

Methods

Notification Object Structure

interface Notification {
  id?: string;          // Optional: Unique identifier. If not provided, one will be generated
  text: string;         // Required: The notification text content
  time?: string;        // Optional: Timestamp or relative time
  icon?: string;        // Optional: HTML string for an icon
  url?: string;         // Optional: URL associated with the notification
}

Text Processing

The component processes notification text in the following ways:

  1. If the text starts with <, the entire string is treated as HTML and rendered as-is
  2. If the text contains HTML but doesn’t start with <, the HTML is escaped and displayed as plain text
  3. For plain text, URLs and email addresses are automatically converted to clickable links

Examples:

// Plain text with URL
addNotification({
  text: 'Check out https://example.com'
});

// HTML content
addNotification({
  text: '<div class="custom">HTML content</div>'
});

// Text containing HTML (will be escaped)
addNotification({
  text: 'This contains <b>HTML</b>'
});

CSS Customization

The component uses CSS custom properties for theming:

:root {
  --badge-bg-color: #e53935;
  --badge-text-color: white;
  --panel-bg-color: white;
  --panel-border-color: #ddd;
  --divider-color: #eee;
  --text-color: #333;
  --time-color: #666;
  --link-color: #0078d4;
}

CSS Parts

Events

The component fires a click event when the notification button is clicked.

Accessibility

Browser Support

The component uses modern web features and is compatible with browsers that support: