This commit is contained in:
oneao committed 2025-09-12 17:32:27 +08:00
1 parent 14f9844430
commit 785bce1907
27 files changed
+1051 -175

No files matched your search

@@ -9,13 +9,14 @@ type Placement
| 'bottom-start'
| 'bottom-end'
type NotificationType = 'info' | 'success' | 'warning' | 'error' | 'loading' | 'question'
type NotificationType = 'default' | 'info' | 'success' | 'warning' | 'danger' | 'loading' | 'question'
type NotificationTheme = 'normal' | 'light'
interface NotificationOptions {
message: string | VNode | (() => VNode)
title: string
subTitle?: string
theme?: NotificationTheme
type?: NotificationType
placement?: Placement
duration?: number
@@ -28,10 +29,11 @@ interface NotificationHandle {
interface MessageFn {
(msg: NotificationOptions): NotificationHandle
open: (msg: NotificationOptions) => NotificationHandle
info: (msg: NotificationOptions) => NotificationHandle
success: (msg: NotificationOptions) => NotificationHandle
warning: (msg: NotificationOptions) => NotificationHandle
error: (msg: NotificationOptions) => NotificationHandle
danger: (msg: NotificationOptions) => NotificationHandle
closeAll: () => void
}
@@ -65,9 +67,9 @@ function getTransform(placement: Placement, hidden: boolean) {
export function useNotification(): MessageFn {
const createNotification = (
opts: NotificationOptions,
defaultType: NotificationType = 'info',
defaultType: NotificationType = 'default',
): NotificationHandle => {
const { message, title, subTitle, type = defaultType, placement = 'top-end', duration = 3000, showClose } = opts
const { message, title, subTitle, type = defaultType, theme, placement = 'top-end', duration = 3000, showClose } = opts
const container = getContainer(placement)
let timer: number | undefined
@@ -77,6 +79,7 @@ export function useNotification(): MessageFn {
render() {
return h(MessageItem, {
type,
theme,
title,
subTitle,
message,
@@ -136,10 +139,11 @@ export function useNotification(): MessageFn {
}
const api = ((msg: NotificationOptions) => createNotification(msg)) as MessageFn
api.open = msg => createNotification(msg, 'default')
api.info = msg => createNotification(msg, 'info')
api.success = msg => createNotification(msg, 'success')
api.warning = msg => createNotification(msg, 'warning')
api.error = msg => createNotification(msg, 'error')
api.danger = msg => createNotification(msg, 'danger')
api.closeAll = () => {
instances.slice().forEach(instance => instance.close())
}