Notifications system
Mantine notifications system
Source
LLM docs
Docs
PackageIcon
License
Installation
After installation import package styles at the root of your application:
Add the Notifications component anywhere in your application. Note that:
- It is required to render the
Notificationscomponent inside MantineProvider - You do not need to wrap your application with the
Notificationscomponent – it is not a provider, it is a regular component - You should not render multiple
Notificationscomponents – if you do that, your notifications will be duplicated
All set! You can now use all notification system features.
Do not forget to import styles
Have you followed the installation instructions above but something is not working
(position prop not working, notifications are stuck at the bottom)?
You've fallen into the trap of not importing notification styles!
To fix the issue, import notification styles at the root of your application:
Functions
The @mantine/notifications package exports a notifications object with the following functions:
notifications.show– adds a given notification to the notifications list or queue, depending on the current state andlimitnotifications.hide– removes a notification with the givenidfrom the notifications state and queuenotifications.update– updates a notification that was previously added to the state or queuenotifications.updateState– executes a given callback with current notifications state and queue as an argument and updates state with the 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 the @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 notifications.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 default,idis randomly generatedposition– notification position; by default, the value from thepositionprop of theNotificationscomponent is usedwithBorder– determines whether the notification should have a borderwithCloseButton– determines whether the close button should be visibleonClose– called when the notification is unmountedonOpen– called when the notification is mountedautoClose– defines timeout in ms after which the notification will be automatically closed; usefalseto 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 the notification position in the notifications.show function. Possible position values:
top-lefttop-righttop-centerbottom-leftbottom-rightbottom-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 the notifications.show function:
Limit and queue
You can limit the maximum number of notifications that are displayed at a time by setting
the limit prop on Notifications:
All notifications added after the limit was reached are added to the queue
and displayed when a notification from the current state is hidden.
Remove notifications from state and queue
To remove a specific notification from state or queue, use the notifications.hide function:
Use the 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 the auto close timeout with Notifications:
Or per notification in the notifications.show/notifications.update functions:
notifications.show and notifications.update functions' autoClose prop has higher priority.
Subscribe to notifications state
You can subscribe to notification state changes with the useNotifications hook.
The hook returns an object with notifications and queue arrays. The notifications
array contains all notifications that are currently displayed; queue contains
notifications that are waiting to be displayed.
Notifications state
[]
Notifications queue
[]