*Note: For the below examples, select the button to see the referenced page notification window.*
<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);
<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);
<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);
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.
There are four types of page notifications:
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 notificationsuccess ,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[] |
- |
The following methods are available through the public API.
Call this method to open a vega-page-notification
within a page. It returns a notification id
.
VegaNotify.open(options: VegaNotifyOption): Promise<string>
This method will close a vega-page-notification
when called by id
.
VegaNotify.close(id: string): Promise<void>
This method will close all vega-page-notification
s within a page.
VegaNotify.closeAll(): Promise<void>
type VegaNotifyOption = {
title?: string;
message: string;
type?: 'success' | 'info' | 'warning' | 'error';
duration?: number;
showCloseButton?: boolean;
actionButtons?: VegaPageNotificationActionButtonConfig[];
};
type VegaPageNotificationActionButtonConfig = {
label: string;
onVegaClick?: (e: CustomEvent) => void;
};
For more details, view in Storybook.
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.