跳到主要內容

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 不自動關閉number4500
position彈出位置'top-right' | 'top-left' | 'bottom-right' | 'bottom-left''top-right'
showClose是否顯示關閉按鈕booleantrue
closeLabel關閉按鈕的 aria-labelstring語言包(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'