-
Notifications
You must be signed in to change notification settings - Fork 138
/
types.ts
100 lines (89 loc) · 3.96 KB
/
types.ts
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
/**
* @license
*
* Use of this source code is governed by an MIT-style license that can be
* found in the LICENSE file at https://github.com/IDuxFE/idux/blob/main/LICENSE
*/
import type { PortalTargetType } from '@idux/cdk/portal'
import type { ExtractInnerPropTypes, ExtractPublicPropTypes, MaybeArray, VKey } from '@idux/cdk/utils'
import type { ButtonProps } from '@idux/components/button'
import type { DefineComponent, HTMLAttributes, PropType, VNode, VNodeProps } from 'vue'
export interface NotificationButtonProps<K = VKey> extends ButtonProps {
key?: K
text?: string | VNode
onClick?: (evt: Event) => void
}
export interface SlotProps {
visible?: boolean
close?: () => void
}
export const notificationType = ['info', 'success', 'warning', 'error'] as const
export const notificationPlacement = ['topStart', 'topEnd', 'bottomStart', 'bottomEnd'] as const
export const notificationProps = {
visible: {
type: Boolean,
default: undefined,
},
destroyOnHover: {
type: Boolean,
default: undefined,
},
duration: Number,
icon: [String, Object] as PropType<string | VNode>,
closeIcon: [String, Object] as PropType<string | VNode>,
type: String as PropType<NotificationType>,
title: [String, Object] as PropType<string | VNode>,
content: [String, Object] as PropType<string | VNode>,
footer: [String, Array, Object] as PropType<string | NotificationButtonProps[] | VNode>,
placement: String as PropType<NotificationPlacement>,
// event
'onUpdate:visible': [Function, Array] as PropType<MaybeArray<(visible: boolean) => void>>,
onClose: [Function, Array] as PropType<MaybeArray<(evt?: Event) => void>>,
} as const
export const notificationProviderProps = {
container: {
type: [String, HTMLElement, Function] as PropType<PortalTargetType>,
default: undefined,
},
maxCount: Number,
offset: [String, Number, Array] as PropType<string | number | (number | string)[]>,
} as const
export type NotificationType = (typeof notificationType)[number]
export type NotificationPlacement = (typeof notificationPlacement)[number]
export type NotificationNodePropKey = 'title' | 'content' | 'footer'
export type NotificationProps = ExtractInnerPropTypes<typeof notificationProps>
export type NotificationPublicProps = ExtractPublicPropTypes<typeof notificationProps>
export type NotificationComponent = DefineComponent<
Omit<HTMLAttributes, keyof NotificationPublicProps> & NotificationPublicProps
>
export type NotificationInstance = InstanceType<DefineComponent<NotificationProps>>
// 通过useNotification的配置
export interface NotificationOptions<K = VKey> extends NotificationProps {
key?: K
contentProps?: Record<string, unknown> | VNodeProps
onDestroy?: (key: K) => void
}
export type NotificationPlacementMap = Record<NotificationPlacement, NotificationOptions[]>
export interface NotificationProviderRef<K = VKey> {
open: (options: NotificationOptions<K>) => NotificationRef<K>
info: (options: Omit<NotificationOptions<K>, 'type'>) => NotificationRef<K>
success: (options: Omit<NotificationOptions<K>, 'type'>) => NotificationRef<K>
warning: (options: Omit<NotificationOptions<K>, 'type'>) => NotificationRef<K>
error: (options: Omit<NotificationOptions<K>, 'type'>) => NotificationRef<K>
update: (key: K, options: Partial<Omit<NotificationOptions<K>, 'key'>>) => void
destroy: (key: K | K[]) => void
destroyAll: () => void
}
export interface NotificationRef<K = VKey> {
key: K
update: (options: Partial<NotificationOptions<K>>) => void
destroy: () => void
}
export type NotificationProviderProps = ExtractInnerPropTypes<typeof notificationProviderProps>
export type NotificationProviderPublicProps = ExtractPublicPropTypes<typeof notificationProviderProps>
export type NotificationProviderComponent = DefineComponent<
Omit<HTMLAttributes, keyof NotificationProviderPublicProps> & NotificationProviderPublicProps
>
export type NotificationProviderInstance = InstanceType<
DefineComponent<NotificationProviderProps, NotificationProviderRef>
>