Create toggleable notifications that fade out automatically.
The notification will not fade out but remain visible when you hover the message until you stop hovering. You can also close the notification by clicking it. To show notifications, the component provides a simple JavaScript API. The following code snippet gets you started.
UIkit.notification({
message: 'my-message!',
status: 'primary',
pos: 'top-right',
timeout: 5000
});
// Shortcuts
UIkit.notification('My message');
UIkit.notification('My message', status);
UIkit.notification('My message', { /* options */ });
<button class="demo uk-button uk-button-default" type="button" onclick="UIkit.notification({message: 'Notification message'})">Click me</button>
You can use HTML inside your notification message, like an icon from the Icon component.
UIkit.notification("<span uk-icon='icon: check'></span> Message");
<button class="uk-button uk-button-default demo" type="button" onclick="UIkit.notification({message: '<span uk-icon=\'icon: check\'></span> Message with an icon'})">With icon</button>
Add one of the following parameters to adjust the notification's position to different corners.
UIkit.notification("…", {pos: 'top-right'})
Position | Code |
---|---|
top-left |
UIkit.notification("…", {pos: 'top-left'}) |
top-center |
UIkit.notification("…", {pos: 'top-center'}) |
top-right |
UIkit.notification("…", {pos: 'top-right'}) |
bottom-left |
UIkit.notification("…", {pos: 'bottom-left'}) |
bottom-center |
UIkit.notification("…", {pos: 'bottom-center'}) |
bottom-right |
UIkit.notification("…", {pos: 'bottom-right'}) |
<p uk-margin>
<button class="uk-button uk-button-default" type="button" onclick="UIkit.notification({message: 'Top Left…', pos: 'top-left'})">Top Left</button>
<button class="uk-button uk-button-default" type="button" onclick="UIkit.notification({message: 'Top Center…', pos: 'top-center'})">Top Center</button>
<button class="uk-button uk-button-default" type="button" onclick="UIkit.notification({message: 'Top Right…', pos: 'top-right'})">Top Right</button>
<button class="uk-button uk-button-default" type="button" onclick="UIkit.notification({message: 'Bottom Left…', pos: 'bottom-left'})">Bottom Left</button>
<button class="uk-button uk-button-default" type="button" onclick="UIkit.notification({message: 'Bottom Center…', pos: 'bottom-center'})">Bottom Center</button>
<button class="uk-button uk-button-default" type="button" onclick="UIkit.notification({message: 'Bottom Right…', pos: 'bottom-right'})">Bottom Right</button>
</p>
A notification can be styled by adding a status to the message to indicate a primary, success, warning or danger status.
UIkit.notification("…", {status: 'primary'})
Style | Code |
---|---|
primary |
UIkit.notification("…", {status:'primary'}) |
success |
UIkit.notification("…", {status:'success'}) |
warning |
UIkit.notification("…", {status:'warning'}) |
danger |
UIkit.notification("…", {status:'danger'}) |
<p uk-margin>
<button class="uk-button uk-button-default demo" type="button" onclick="UIkit.notification({message: 'Primary message…', status: 'primary'})">Primary</button>
<button class="uk-button uk-button-default demo" type="button" onclick="UIkit.notification({message: 'Success message…', status: 'success'})">Success</button>
<button class="uk-button uk-button-default demo" type="button" onclick="UIkit.notification({message: 'Warning message…', status: 'warning'})">Warning</button>
<button class="uk-button uk-button-default demo" type="button" onclick="UIkit.notification({message: 'Danger message…', status: 'danger'})">Danger</button>
</p>
You can close all open notifications by calling UIkit.notification.closeAll()
.
<button class="uk-button uk-button-default close" onclick="UIkit.notification.closeAll()">Close All</button>
Any of these options can be applied to the component attribute. Separate multiple options with a semicolon. Learn more
Option | Value | Default | Description |
---|---|---|---|
message |
String | false |
Notification message to show. |
status |
String | null |
Notification status color. |
timeout |
Number | 5000 |
Visibility duration until a notification disappears. If set to 0 , notification will not hide automatically. |
group |
String | Useful, if you want to close all notifications in a specific group. | |
pos |
String | top-center |
Display corner. |
Learn more about JavaScript components.
This is a Functional Component
and may omit the element argument.
UIkit.notification(options);
UIkit.notification(message, status);
The following events will be triggered on elements with this component attached:
Name | Description |
---|---|
close |
Fires after the notification has been closed. |
The following methods are available for the component:
UIkit.notification(element).close(immediate);
Closes the notification.
Name | Type | Default | Description |
---|---|---|---|
immediate |
Boolean | true | Transition the notification out. |
The Notification component automatically sets the appropriate WAI-ARIA role, states and properties.
alert
role.