Notification
Display a notification message globally.
Examples
Basic
A basic example of a notification.
Custom Duration
The duration
can be used to specify how long the notification stays open. After the duration time elapses, the notification closes automatically. If not specified, the default duration is 4.5 seconds. If the duration is set to 0, the notification box will never close automatically.
Status Icon
A status icon can be included on the left side of the notification.
Custom Icon
A custom icon can also be added. Use the iconColor
option to set it's color. Using status methods (notification.success) will color the icon according to the status color.
Customized Styling
The Notification has options for style
and className
so it's style can be customized.
Placement
A notification box can appear from the topRight
, bottomRight
, bottomLeft
or topLeft
of the viewport.
Updating a Notification
A notification can be updated by using a unique key
.
API
This component provides the following methods:
notification.open(options)
notification.success(options)
notification.error(options)
notification.info(options)
notification.warning(options)
notification.warn(options) // alias of warning
notification.close(key: String)
notification.destroyAll()
Notification Options
Property | Description | Type | Default |
---|---|---|---|
message | The title of notification box (required) | String | |
description | The text content of notification box (required) | String | |
className | Customized CSS class | String | |
duration | Time in milliseconds before Notification is closed. When set to 0 or null, it will never be closed automatically | Number | |
button | Object of Button props along with onClick and text options. Will add a button to the bottom of the notification | Object | |
icon | Customized icon | SvelteComponent | |
iconColor | Color for the customized icon | String (CSS color property) | |
closeIcon | Custom close icon | SvelteComponent | |
key | The unique identifier of the Notification | String | |
onClose | Specify a function that will be called when the close button is clicked | Function | |
onClick | Specify a function that will be called when the notification is clicked | Function | |
placement | Position of Notification, can be one of `topLeft` `topRight` `bottomLeft` `bottomRight` | String | `topRight` |
style | Customized inline style | Object|String |
Global Configuration
A notification.config
method is also provided. These can be overridden on an individual basis.
notification.config({
placement: 'bottomRight',
bottom: 50,
duration: 3000,
rtl: true,
});
Global Config Options
Property | Description | Type | Default |
---|---|---|---|
bottom | Distance from the bottom of the viewport, when placement is bottomRight or bottomLeft (unit: pixels). | Number | 24 |
top | Distance from the top of the viewport, when placement is topRight or topLeft (unit: pixels). | Number | 24 |
closeIcon | Global close icon | SvelteComponent | |
duration | Time in milliseconds before Notification is closed. When set to 0 or null, it will never be closed automatically | Number | |
placement | Position of Notification, can be one of `topLeft` `topRight` `bottomLeft` `bottomRight` | String | `topRight` |
rtl | Whether to enable RTL mode | Boolean | false |