Notifications system
Mantine notifications system
Source
Docs
Package
License
Installation
After installation import package styles at the root of your application:
Add Notifications
component anywhere in your application. Note that:
- It is required to render
Notifications
component inside MantineProvider - You do not need to wrap your application with
Notifications
component – it is not a provider, it is a regular component - You should not render multiple
Notifications
components – if you do that, your notifications will be duplicated
All set! You can now use all notifications system features.
Functions
@mantine/notifications
package exports notifications
object with the following functions:
notifications.show
– adds given notification to the notifications list or queue, depending on the current state andlimit
notifications.hide
– removes notification with givenid
from the notifications state and queuenotifications.update
– updates notification that was previously added to the state or queuenotifications.updateState
– executes given callback with current notifications state and queue as an argument and updates state with returned valuenotifications.clean
– removes all notifications from the notifications state and queuenotifications.cleanQueue
– removes all notifications from the queue
All functions can be imported from @mantine/notifications
package and can be used in any part of your application:
You can also import these functions separately:
Notification props
notifications.show
and notification.update
functions can be called with an object that has the following properties:
id
– notification id, it is used to update and remove notifications, by defaultid
is randomly generatedposition
– notification position, by default the value from theposition
prop of theNotifications
component is usedwithBorder
– determines whether notification should have a borderwithCloseButton
– determines whether the close button should be visibleonClose
– calls when notification is unmountedonOpen
– calls when notification is mountedautoClose
– defines timeout in ms on which notification will be automatically closed, usefalse
to disable auto closemessage
– required notification bodycolor, icon, title, radius, className, style, loading
– props passed down to the Notification component
All properties except message
are optional.
Notifications preview (message
prop used as children
):
Customize notification styles
You can use style
, className
or Styles API classNames
, styles
props to customize notification styles.
Usually, it is better to override Notification styles with classNames
prop in the theme object.
Notifications container position
You can define notification position in notifications.show
function. Possible position
values:
top-left
top-right
top-center
bottom-left
bottom-right
bottom-center
The position
can be defined on the Notifications
component.
In the following example, notifications will be displayed in the top right corner of the screen
if position
is not defined in notifications.show
function:
Limit and queue
You can limit maximum number of notifications that are displayed at a time by setting
limit
prop on Notifications
:
All notifications added after the limit
was reached are added to the queue
and displayed when notification from current state is hidden.
Remove notifications from state and queue
To remove specific notification from state or queue use notifications.hide
function:
Use notifications.cleanQueue
function to remove all notifications from the queue and
notifications.clean
to remove all notifications both from the state and queue:
Update notification
Auto close
You can configure auto close timeout with Notifications
:
Or per notification in notifications.show
/notifications.update
functions:
notifications.show
and notifications.update
functions autoClose
prop has higher priority.
Subscribe to notifications state
You can subscribe to notifications state changes with useNotifications
hook.
The hook returns an object with notifications
and queue
arrays. notifications
array contains all notifications that are currently displayed, queue
contains
notifications that are waiting to be displayed.
Notifications state
[]
Notifications queue
[]