组件 · 收件箱
NotificationCenter
The list that opens from the bell and holds the state of the whole server — a computer offline, a quota nearly full, an update — until it changes.
import { NotificationCenter } from "@botiverse/raft-ui";The NotificationCenter is the list that opens from the bell. It holds the state of the whole server (a computer offline, a quota nearly full, an update) and keeps each notice until the situation changes. An attention dot on the bell says that something is unread.
When to use
| Situation | Use |
|---|---|
| A problem or a change that affects the whole server | NotificationCenter |
| Something happened elsewhere that the person should see | Activity (ActivityInbox) |
| Something in one panel failed | PanelNotice under the panel header (Panel) |
| The result of an action the person took | Toast |
Errors by scope are in Feedback. Where a product puts the bell is on the product's own page.
Anatomy
NotificationCenter: the root. A non-modal popover.NotificationCenterTrigger: the bell. By default it draws the bell and the attention dot.NotificationCenterPopup: the list's popup, next to the bell.NotificationCenterHeader:NotificationCenterTitle(Notifications) andNotificationCenterCount.NotificationCenterScrollerandNotificationCenterList: the notices.NotificationCenterEmptyState: what the list says when it is empty (EmptyState).
NotificationCenterItem: one notice, in aNotificationCenterItemRow:NotificationCenterItemIcon: a tile with an icon. A notice from the system has no who, so a tile stands where an avatar would (InboxItem).NotificationCenterItemContent:NotificationCenterItemTitle,NotificationCenterItemBodyandNotificationCenterItemActionswithNotificationCenterActionButtons.
Variants
| Variant | Use for |
|---|---|
status="error" on the icon | Something stopped working: a computer offline, an agent that can't start. warning-soft tile, octagon-alert icon |
status="warning" | Something will stop working soon: a quota nearly full, a key about to expire. warning-soft tile, triangle-alert icon |
status="info" | News: an update. info-soft tile, info icon |
viewport="mobile" on the popup | The narrower popup on a phone |
size on the popup | The popup's height: sm, md or lg |
States
| State | Look |
|---|---|
| Unread (default) | The title in foreground at weight 700, and a pink attention dot on the right |
read | The title in foreground-muted at weight 600; no dot |
Behavior
- Sort notices by severity: errors first, then warnings, then information.
- When the person dismisses a notice, don't show it again until the situation changes.
- Show the attention dot on the bell only while a notice is unread. The default trigger always draws the dot, so pass the bell alone as the trigger's children when nothing is unread.
- Float the popup next to the bell; it doesn't take space in the layout (Elevation).
Content
- Write the notice in the same order as an inbox item: where (the computer, the server), then what happened, then at most 2 lines of detail (InboxItem).
Accessibility
NotificationCenterwraps the Base UIPopover, non-modal by default; the popup doesn't take focus when it opens.- The popup is named "Notification center" and the list "Notifications" unless you pass another
aria-label. - Give the trigger an accessible name, and include the unread state:
aria-label="Notifications, 2 unread". The bell and the dot are hidden from assistive technology. NotificationCenterItemIconis an image (role="img") named by its status (Error, Warning, Info).
Rules
API
NotificationCenter
| Prop | 类型 | 默认值 |
|---|---|---|
| A ref to imperative actions. - `unmount`: Manually unmounts the popover. Call this after any externally controlled closing animation finishes. - `close`: Closes the popover imperatively when called. | RefObject<PopoverRootActions | null> | |
| The content of the popover. This can be a regular React node or a render function that receives the `payload` of the active trigger. | ReactNode | PayloadChildRenderFunction<unknown> | |
| Whether the popover is initially open. | boolean | false |
| ID of the trigger that the popover is associated with. This is useful in conjunction with the `defaultOpen` prop to create an initially open popover. | string | |
| A handle to associate the popover with a trigger. If specified, allows external triggers to control the popover's open state. | BasePopover.Handle<unknown> | |
| Determines if the popover enters a modal state when open. - `true`: user interaction is limited to the popover: document page scroll is locked, and pointer interactions on outside elements are disabled. - `false`: user interaction with the rest of the document is allowed. - `'trap-focus'`: focus is trapped inside the popover, but document page scroll is not locked and pointer interactions outside of it remain enabled. | boolean | "trap-focus" | false |
| Event handler called when the popover is opened or closed. | (open: boolean, eventDetails: BasePopover.Root.ChangeEventDetails) => void | |
| Event handler called after any animations complete when the popover is opened or closed. | (open: boolean) => void | |
| Whether the popover is currently open. | boolean | |
| ID of the trigger that the popover is associated with. This is useful in conjunction with the `open` prop to create a controlled popover. There's no need to specify this prop when the popover is uncontrolled (that is, when the `open` prop is not set). | string |
NotificationCenterActionButton
| Prop | 类型 | 默认值 |
|---|---|---|
| boolean | ||
| string | ||
| Whether the button should be focusable when disabled. | boolean | false |
| Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`). | boolean | true |
| Allows you to replace the component's HTML element with a different tag, or compose it with another component. | ReactElement | ((props, state) => ReactElement) |
Also takes the attributes of its element.
NotificationCenterCount, NotificationCenterEmptyState, NotificationCenterHeader
| Prop | 类型 | 默认值 |
|---|---|---|
| Allows you to replace the component's HTML element with a different tag, or compose it with another component. | ReactElement | ((props, state) => ReactElement) |
Also takes the attributes of its element.
NotificationCenterItem
| Prop | 类型 | 默认值 |
|---|---|---|
| boolean | false | |
| Allows you to replace the component's HTML element with a different tag, or compose it with another component. | ReactElement | ((props, state) => ReactElement) |
Also takes the attributes of its element.
NotificationCenterItemActions, NotificationCenterItemBody, NotificationCenterItemContent
| Prop | 类型 | 默认值 |
|---|---|---|
| Allows you to replace the component's HTML element with a different tag, or compose it with another component. | ReactElement | ((props, state) => ReactElement) |
Also takes the attributes of its element.
NotificationCenterItemIcon
| Prop | 类型 | 默认值 |
|---|---|---|
| "warning" | "success" | "error" | "info" | "info" | |
| Allows you to replace the component's HTML element with a different tag, or compose it with another component. | ReactElement | ((props, state) => ReactElement) |
Also takes the attributes of its element.
NotificationCenterItemRow, NotificationCenterItemTitle, NotificationCenterList
| Prop | 类型 | 默认值 |
|---|---|---|
| Allows you to replace the component's HTML element with a different tag, or compose it with another component. | ReactElement | ((props, state) => ReactElement) |
Also takes the attributes of its element.
NotificationCenterPopup
| Prop | 类型 | 默认值 |
|---|---|---|
| PopoverPortalProps | ||
| "sm" | "md" | "lg" | "md" | |
| "desktop" | "mobile" | "desktop" | |
| How to align the popup relative to the specified side. | Align | "center" |
| Additional offset along the alignment axis in pixels. Also accepts a function that returns the offset to read the dimensions of the anchor and positioner elements, along with its side and alignment. | number | OffsetFunction | 0 |
| An element to position the popup against. By default, the popup will be positioned against the trigger. | Element | VirtualElement | RefObject<Element | null> | (() => Element | VirtualElement | null) | |
| Minimum distance to maintain between the arrow and the edges of the popup. | number | 5 |
| Determines how to handle collisions when positioning the popup. | CollisionAvoidance | |
| An element or a rectangle that delimits the area that the popup is confined to. | Boundary | 'clipping-ancestors' |
| Additional space to maintain from the edge of the collision boundary. | Padding | 5 |
| Whether to disable the popup from tracking any layout shift of its positioning anchor. | boolean | false |
| Determines the element to focus when the popover is closed. | boolean | RefObject<HTMLElement | null> | ((closeType: InteractionType) => void | boolean | HTMLElement | null) | |
| Determines the element to focus when the popover is opened. By default, focus moves to the first tabbable element inside the popup, except when the popover is opened by touch — then the popup itself is focused to avoid opening the virtual keyboard. | boolean | RefObject<HTMLElement | null> | ((openType: InteractionType) => void | boolean | HTMLElement | null) | false |
| Determines which CSS `position` property to use. | "fixed" | "absolute" | "fixed" |
| Allows you to replace the component's HTML element with a different tag, or compose it with another component. | ReactElement | ((props, state) => ReactElement) | |
| Which side of the anchor element to align the popup against. May automatically change to avoid collisions. | Side | "bottom" |
| Distance between the anchor and the popup in pixels. Also accepts a function that returns the distance to read the dimensions of the anchor and positioner elements, along with its side and alignment. | number | OffsetFunction | 4 |
| Whether to maintain the popup in the viewport after the anchor element was scrolled out of view. | boolean | false |
Also takes the attributes of its element.
NotificationCenterScroller, NotificationCenterTitle
| Prop | 类型 | 默认值 |
|---|---|---|
| Allows you to replace the component's HTML element with a different tag, or compose it with another component. | ReactElement | ((props, state) => ReactElement) |
Also takes the attributes of its element.
NotificationCenterTrigger
| Prop | 类型 | 默认值 |
|---|---|---|
| How long to wait before closing the popover that was opened on hover. Specified in milliseconds. | number | 0 |
| How long to wait before the popover may be opened on hover. Specified in milliseconds. | number | 300 |
| A handle to associate the trigger with a popover. | BasePopover.Handle<unknown> | |
| Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (for example, `<div>`). Whether the component renders a native `<button>` element when replacing it via the `render` prop. Set to `false` if the rendered element is not a button (e.g. `<div>`). | boolean | true |
| Whether the popover should also open when the trigger is hovered. | boolean | false |
| A payload to pass to the popover when it is opened. | {} | |
| Allows you to replace the component's HTML element with a different tag, or compose it with another component. | ReactElement | ((props, state) => ReactElement) |
Also takes the attributes of its element.
相关组件
改动
- 0.7.0 · Fixed
EmptyStateIconis hidden from assistive technology, andNotificationCenterItemIconis announced as an image named by its status. - 0.6.0 · Breaking ChangesProps that no longer change anything are removed:
Badgeuppercase;Checkboxsize,variant,color;Statuspulse,attention(status never animates);Switch/SwitchThumbsize;SidebarItemvariant;SidebarItemCount/SidebarItemIndicatorvariantandappearance(the count is always the pink sticker, the indicator the yellow @);NotificationCenterActionButtonvariant;DrawerContentwidth(one-go forms use the wideDialog);AppRailItemIndicatorattention;AppRailItemAttentionchildren;Stepssize,track,renderIndicator,renderTraveler;FilePreviewBadgetype,color. Remove them at call sites.