Page Notification

Examples

*Note: For the below examples, select the button to see the referenced page notification window.*

With Titles

        <vega-flex direction="col" gap="size-20" id="basicTemplate" key={new Date().getTime()}>
			<div>
				<vega-flex gap="size-20">
					<vega-button id="with-title">With title</vega-button>
					<vega-button id="no-title" variant="secondary">
						No title
					</vega-button>
				</vega-flex>
			</div>
		</vega-flex>
    setTimeout(() => {
        document.querySelector('#basicTemplate #with-title').addEventListener('vegaClick', () => {
			window.VegaNotify.open({
				title: 'Title',
				message:
					'This is the content of notification. This is the content of notification.This is the content of notification.This is the content of notification.',
			});
		});
  		document.querySelector('#basicTemplate #no-title').addEventListener('vegaClick', () => {
			window.VegaNotify.open({
				message: 'No title notification',
			});
		});


    }, 100);

With Actions


        <vega-flex direction="col" gap="size-20" id="basicTemplate" key={new Date().getTime()}>
			<div>
				<vega-flex gap="size-20">
					<vega-button id="with-action">With action</vega-button>
					<vega-button id="with-actions" variant="secondary">
						With actions
					</vega-button>
				</vega-flex>
			</div>
		</vega-flex>


    setTimeout(() => {
        document.querySelector('#basicTemplate #with-action').addEventListener('vegaClick', async () => {
			const id = await window.VegaNotify.open({
				title: 'Title',
				duration: 0,
				message: 'This notification will not be closed, because the duration is set 0',
				actionButtons: [
					{
						label: 'Confirm',
						onVegaClick: () => {
							window.VegaNotify.close(id);
						},
					},
				],
			});
		});

		document.querySelector('#basicTemplate #with-actions').addEventListener('vegaClick', async () => {
			const id = await window.VegaNotify.open({
				title: 'Title',
				duration: 10000,
				message: `This notification will close after 10s`,
				actionButtons: [
					{
						label: 'Cancel',
						onVegaClick: () => {
							window.VegaNotify.close(id);
						},
					},
					{
						label: 'OK',
						onVegaClick: () => {
							window.VegaNotify.close(id);
						},
					},
				],
			});
		});
   }, 100);

Notification Types

    <vega-flex gap="size-20" id="types-examples">
        <vega-button id="warning" variant="secondary">
            Warning
        </vega-button>
        <vega-button id="success" variant="secondary">
            Success
        </vega-button>
        <vega-button id="error" variant="secondary">
            Error
        </vega-button>
        <vega-button id="info" variant="secondary">
            Info
        </vega-button>
    </vega-flex>

setTimeout(() => {
		document.querySelector('#types-examples').direction = {
			default: 'row',
			S: 'col',
			M: 'row',
		};
		document.querySelectorAll('#types-examples vega-button').forEach(item => {
			item.addEventListener('vegaClick', async e => {
				const target = e.target;
				const id = await window.VegaNotify.open({
					type: target.id,
					message: `${e.target.textContent.toUpperCase()}`,
				});
			});
		});


}, 100);

Usage

Page notifications are banners which appear on a page designed to convey information to the user about an action or state. They typically appear as a response to an action, however may be used for other purposes.

Typically these use color and icons to convey the type of message. The message is displayed within the banner, which is displayed near the top of the page, or near the action or state to which it is associated.

Types

There are four types of page notifications:

  • Errors - information on the page is in an error state which needs to be corrected to move forward.
  • Warnings - like errors, but less serious. The user will still be able to continue.
  • Success - indications of a successful completion of an action
  • Information/Notifications - callouts for information to a user relevant to material on the page. .

Properties

Name Description Default
title The title of the page notification
string
-
message The message appearing on the page notification
string
-
duration The duration before closing in milliseconds. It will not automatically close if set to 0
number
5000
type The type of page notification
success,info, warning, error
info
show-close-button Indicates whether to show the close button
boolean
true
actionButtons The config array of the action buttons.
VegaPageNotificationActionButtonConfig[]
-

Public API

The following methods are available through the public API.

VegaNotify.open

Call this method to open a vega-page-notification within a page. It returns a notification id.

VegaNotify.open(options: VegaNotifyOption): Promise<string>

VegaNotify.close

This method will close a vega-page-notification when called by id.

VegaNotify.close(id: string): Promise<void>

VegaNotify.closeAll

This method will close all vega-page-notifications within a page.

VegaNotify.closeAll(): Promise<void>

Types

VegaNotifyOption

type VegaNotifyOption = {
    title?: string;
    message: string;
    type?: 'success' | 'info' | 'warning' | 'error';
    duration?: number;
    showCloseButton?: boolean;
    actionButtons?: VegaPageNotificationActionButtonConfig[];
};

VegaPageNotificationActionButtonConfig

type VegaPageNotificationActionButtonConfig = {
    label: string;
    onVegaClick?: (e: CustomEvent) => void;
};

For more details, view in Storybook.

Accessibility

  • Elements must only use allowed ARIA attributes
  • ARIA attributes must conform to valid values
  • ARIA attributes must conform to valid names
  • Buttons must have discernible text
  • Elements must have sufficient color contrast
  • id attribute value must be unique
  • Interactive controls must not be nested

Best Practices

While color is a primary factor for identifying different types of alerts, for accessibility reasons, it should not be the sole indicator.

Each page notification type should use a different but consistent icon which can help those who have trouble distinguishing between colors.

Each message also needs to be accompanied with clearly understandable text which conveys the purpose and meaning of the notification.

While “information” and “notification” messages may use the same color, they use different icons and text to identify their purpose.