Feedback · Notification
Notification
Notifications are used to actively send message notifications to users.
Demos
How to import
Basic Usage
Close after 3 seconds.
Position
Use
position
to set pop up position, supporting one of: top
、bottom
、topLeft
、topRight
(default)、bottomLeft
、bottomRight
。With Icons
Use different methods to show Notification with icons or you can pass in
icon
for customized icon.Colored Background
You could use
theme
for a colored background style. Default is normal
.Custom Children with Link
Use with Typography to create operation links for more complicated situations.
Delay
Use
duration
to set up time delay. By default it closes after 3 seconds.Manual Close
Set
duration
to 0 if you do not want the Notification to close by itself. In this case, it could only be closed manually.Update content
You can use id to update notification content. >=2.45.0
API Reference
The static methods provided are as follows:
Display: You can pass in options object directly. Methods return the value of
id
: const id = Notification.open({ /*...options*/ })
Notification.open({content: 'message', duration: 3})
Notification.info({content: 'message', duration: 3})
Notification.error({content: 'message', duration: 3})
Notification.warning({content: 'message', duration: 3})
Notification.success({content: 'message', duration: 3})
Close Manually (
id
is the return value of the display methods)Notification.close(id)
Properties | Instructions | type | Default | version |
---|---|---|---|---|
content | Content | ReactNode | '' | |
duration | Automatic close delay, no auto-close when set to 0 | number | 3 | |
getPopupContainer | Specifies the parent DOM, and the bullet layer will be rendered to the DOM, you need to set 'position: relative` This will change the DOM tree position, but not the view's rendering position. | () => HTMLElement | () => document.body | 0.34.0 |
icon | Topleft icon | ReactNode | ||
position | Pop-up position, one of top 、bottom 、topLeft 、topRight 、bottomLeft 、bottomRight | string | topRight | |
showClose | Toggle Whether show close button | boolean | true | 0.25.0 |
theme | Style of background fill, one of light , normal | string | normal | 1.0.0 |
title | Title | string | ReactNode | '' |
zIndex | Z-index value. Only take effect for the first time. | number | 1010 | |
onClick | Callback function when clicking the notification | (e: event) => void | 0.27 .0 | |
onClose | Callback function when closing notification, triggered for either auto-close or manually close | () => void | ||
onCloseClick | Callback function when actively clicking on the close button | (id: string | number) => void |
The global configuration is set before any method call, and takes effect only once (>= 0.25.0):
Notification.config(config)
Properties | Instructions | type | Default | version |
---|---|---|---|---|
bottom | Bottom, absolute position | number | string | - | 0.25.0 |
duration | Automatic close delay, no auto-close when set to 0 | number(second) | 3 | 0.25.0 |
left | Left, absolute position | number | string | - | 0.25.0 |
position | Pop-up position, one of top 、bottom 、topLeft 、topRight 、bottomLeft 、bottomRight | string | topRight | 0.25.0 |
right | Right, absolute position | number | string | - | 0.25.0 |
top | Top, absolute position | number | string | - | 0.25.0 |
zIndex | Z-index | number | 1010 | 0.25.0 |
Globally Destroy (>= 0.25.0):
Notification.destroyAll()
( >= 0.25.0 )
Hook Notification ( >= 1.2.0 )
Notification.useNotification
When you need access Context, you could use `
Notification.useNotification
to create a contextHolder
and insert to corresponding DOM tree. Notification created by hooks will be able to access the context where contextHolder
is inserted. Hook Notification has following methods: info
, success
, warning
, error
, open
, close
. For more usage demo, refer to useToastAccessibility
ARIA
- The
role
of the component is'alert' - The notification's
aria-labelledby
is marked as the corresponding notification title
Content Guidelines
- Title
- Explain in clear and concise language
- Avoid punctuation such as commas, periods, etc.
- Text
- On the premise of complete information transmission, try to compress the text to 1-2 sentences
- A detailed description or explanation of the title, rather than a repetition of the title
- Use correct punctuation, commas within sentences and periods between sentences
- Operate
- The copy needs to show the specific meaning of the operation