Notification 通知
比 Message 更重的反饋:帶標題 / 正文 / 類型圖示,從四角彈出,適合內容較長的系統通知。
基礎用法
基礎用法
import { notification } from '@lh-ui/react'
import '@lh-ui/react/style/notification'
notification.success({ title: '保存成功', content: '作品已发布到画廊。' })
// 字串簡寫:只渲染標題行
notification.info('系统通知')
notification 方法
| 方法 | 說明 | 傳回值 |
|---|---|---|
| info / success / warning / error / danger | 顯示通知 | { close } |
| close | 關閉指定通知(先播退場動畫) | void |
| closeAll | 關閉全部通知並卸載容器 | void |
const handle = notification.warning({ title: '存储空间不足' })
handle.close()
LhNotificationOptions
| 屬性 | 說明 | 型別 | 預設值 |
|---|---|---|---|
| title | 標題(未傳時取 content) | string | — |
| content | 正文(與 title 同值時只渲染標題行) | string | — |
| duration | 自動關閉毫秒數,0 不自動關閉 | number | 4500 |
| position | 彈出位置 | 'top-right' | 'top-left' | 'bottom-right' | 'bottom-left' | 'top-right' |
| showClose | 是否顯示關閉按鈕 | boolean | true |
| closeLabel | 關閉按鈕的 aria-label | string | 語言包(zh-CN:关闭通知) |
| onClick | 點選回呼(傳入後卡片可點選) | () => void | — |
| onClose | 關閉時回呼 | () => void | — |
| sx | 快速版面配置屬性 | SxProps | — |
退場動畫
React 無 transition-group,條目自管退場:關閉時先播 lh-notification-slide-leave-*
(280ms)再移除記錄。FLIP 讓位動畫未實作:佇列增刪時兄弟卡片瞬時跳位,
堆疊間距由容器的 flex gap 承接。
無障礙
warning / danger 為 role="alert"(立即播報),info / success 為
role="status"(排隊播報);容器為 role="region" + aria-live="polite"。
樣式
import '@lh-ui/react/style/notification'