@v-c/notification 2.0.0-beta.1 → 2.0.0-rc.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (51) hide show
  1. package/dist/Notification.d.ts +7 -234
  2. package/dist/Notification.js +199 -135
  3. package/dist/NotificationList/Content.d.ts +3 -80
  4. package/dist/NotificationList/Content.js +33 -47
  5. package/dist/NotificationList/index.d.ts +7 -128
  6. package/dist/NotificationList/index.js +139 -122
  7. package/dist/NotificationProvider.d.ts +1 -20
  8. package/dist/NotificationProvider.js +2 -13
  9. package/dist/Notifications.d.ts +10 -132
  10. package/dist/Notifications.js +123 -108
  11. package/dist/Progress.d.ts +3 -3
  12. package/dist/Progress.js +24 -11
  13. package/dist/hooks/useClosable.d.ts +6 -11
  14. package/dist/hooks/useClosable.js +7 -6
  15. package/dist/hooks/useListPosition/index.d.ts +14 -13
  16. package/dist/hooks/useListPosition/index.js +16 -23
  17. package/dist/hooks/useListPosition/useSizes.d.ts +3 -6
  18. package/dist/hooks/useListPosition/useSizes.js +12 -10
  19. package/dist/hooks/useNoticeTimer.d.ts +5 -4
  20. package/dist/hooks/useNoticeTimer.js +33 -41
  21. package/dist/hooks/useNotification.d.ts +25 -7
  22. package/dist/hooks/useNotification.js +20 -25
  23. package/dist/hooks/useStack.d.ts +9 -8
  24. package/dist/hooks/useStack.js +17 -11
  25. package/dist/index.d.ts +9 -8
  26. package/dist/index.js +2 -2
  27. package/dist/interface.d.ts +30 -0
  28. package/dist/interface.js +0 -0
  29. package/docs/context.vue +1 -1
  30. package/docs/hooks.vue +4 -4
  31. package/docs/index.less +143 -62
  32. package/docs/maxCount.vue +1 -1
  33. package/docs/showProgress.vue +2 -2
  34. package/docs/stack.vue +1 -1
  35. package/package.json +2 -3
  36. package/src/Notification.tsx +128 -165
  37. package/src/NotificationList/Content.tsx +36 -54
  38. package/src/NotificationList/index.tsx +131 -135
  39. package/src/NotificationProvider.tsx +3 -23
  40. package/src/Notifications.tsx +62 -84
  41. package/src/Progress.tsx +19 -15
  42. package/src/hooks/useClosable.ts +15 -16
  43. package/src/hooks/useListPosition/index.ts +24 -40
  44. package/src/hooks/useListPosition/useSizes.ts +16 -15
  45. package/src/hooks/useNoticeTimer.ts +34 -45
  46. package/src/hooks/useNotification.tsx +71 -43
  47. package/src/hooks/useStack.ts +20 -24
  48. package/src/index.ts +28 -13
  49. package/src/interface.ts +45 -0
  50. package/vitest.config.ts +1 -3
  51. package/tests/index.spec.tsx +0 -200
@@ -1,88 +1,11 @@
1
- import { CSSProperties, PropType, TransitionGroupProps } from 'vue';
1
+ import { CSSProperties } from 'vue';
2
2
  export interface ContentProps {
3
3
  listPrefixCls: string;
4
4
  height: number;
5
5
  topNoticeHeight?: number;
6
6
  topNoticeWidth?: number;
7
- class?: string;
7
+ className?: string;
8
8
  style?: CSSProperties;
9
- motionProps?: TransitionGroupProps;
10
- onAfterLeave?: () => void;
11
9
  }
12
- declare const Content: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
13
- listPrefixCls: {
14
- type: StringConstructor;
15
- required: true;
16
- };
17
- height: {
18
- type: NumberConstructor;
19
- required: true;
20
- };
21
- topNoticeHeight: {
22
- type: NumberConstructor;
23
- default: number;
24
- };
25
- topNoticeWidth: {
26
- type: NumberConstructor;
27
- default: number;
28
- };
29
- class: {
30
- type: StringConstructor;
31
- default: undefined;
32
- };
33
- style: {
34
- type: PropType<CSSProperties>;
35
- default: undefined;
36
- };
37
- motionProps: {
38
- type: PropType<TransitionGroupProps>;
39
- default: undefined;
40
- };
41
- onAfterLeave: {
42
- type: PropType<() => void>;
43
- default: undefined;
44
- };
45
- }>, () => import('vue').VNode<import('vue').RendererNode, import('vue').RendererElement, {
46
- [key: string]: any;
47
- }>, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
48
- listPrefixCls: {
49
- type: StringConstructor;
50
- required: true;
51
- };
52
- height: {
53
- type: NumberConstructor;
54
- required: true;
55
- };
56
- topNoticeHeight: {
57
- type: NumberConstructor;
58
- default: number;
59
- };
60
- topNoticeWidth: {
61
- type: NumberConstructor;
62
- default: number;
63
- };
64
- class: {
65
- type: StringConstructor;
66
- default: undefined;
67
- };
68
- style: {
69
- type: PropType<CSSProperties>;
70
- default: undefined;
71
- };
72
- motionProps: {
73
- type: PropType<TransitionGroupProps>;
74
- default: undefined;
75
- };
76
- onAfterLeave: {
77
- type: PropType<() => void>;
78
- default: undefined;
79
- };
80
- }>> & Readonly<{}>, {
81
- class: string;
82
- style: CSSProperties;
83
- onAfterLeave: () => void;
84
- topNoticeHeight: number;
85
- topNoticeWidth: number;
86
- motionProps: TransitionGroupProps;
87
- }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
10
+ declare const Content: import('vue').DefineSetupFnComponent<ContentProps, {}, {}, ContentProps & {}, import('vue').PublicProps>;
88
11
  export default Content;
@@ -1,9 +1,28 @@
1
- import { TransitionGroup, defineComponent, h, shallowRef } from "vue";
2
- import { classNames } from "@v-c/util";
1
+ import { createVNode, defineComponent, ref } from "vue";
2
+ import { clsx } from "@v-c/util";
3
3
  //#region src/NotificationList/Content.tsx
4
- var Content = /* @__PURE__ */ defineComponent({
5
- name: "NotificationListContent",
6
- inheritAttrs: false,
4
+ var Content = /* @__PURE__ */ defineComponent((props, { slots, expose }) => {
5
+ const contentRef = ref(null);
6
+ let prevHeight = props.height;
7
+ expose({ nativeElement: contentRef });
8
+ return () => {
9
+ const { listPrefixCls, height, topNoticeHeight = 0, topNoticeWidth = 0, className, style } = props;
10
+ const heightStatus = height < prevHeight ? "decrease" : "increase";
11
+ prevHeight = height;
12
+ const contentPrefixCls = `${listPrefixCls}-content`;
13
+ const contentStyle = {
14
+ ...style,
15
+ height,
16
+ "--top-notificiation-height": `${topNoticeHeight}px`,
17
+ "--top-notificiation-width": `${topNoticeWidth}px`
18
+ };
19
+ return createVNode("div", {
20
+ "ref": contentRef,
21
+ "class": clsx(contentPrefixCls, `${contentPrefixCls}-${heightStatus}`, className),
22
+ "style": contentStyle
23
+ }, [slots.default?.()]);
24
+ };
25
+ }, {
7
26
  props: {
8
27
  listPrefixCls: {
9
28
  type: String,
@@ -15,60 +34,27 @@ var Content = /* @__PURE__ */ defineComponent({
15
34
  },
16
35
  topNoticeHeight: {
17
36
  type: Number,
18
- default: 0
37
+ required: false,
38
+ default: void 0
19
39
  },
20
40
  topNoticeWidth: {
21
41
  type: Number,
22
- default: 0
42
+ required: false,
43
+ default: void 0
23
44
  },
24
- class: {
45
+ className: {
25
46
  type: String,
47
+ required: false,
26
48
  default: void 0
27
49
  },
28
50
  style: {
29
51
  type: Object,
30
- default: void 0
31
- },
32
- motionProps: {
33
- type: Object,
34
- default: void 0
35
- },
36
- onAfterLeave: {
37
- type: Function,
52
+ required: false,
38
53
  default: void 0
39
54
  }
40
55
  },
41
- setup(props, { slots, expose }) {
42
- let prevHeight = props.height;
43
- const innerRef = shallowRef(null);
44
- expose({ get nativeElement() {
45
- return innerRef.value;
46
- } });
47
- return () => {
48
- const { listPrefixCls, height, topNoticeHeight, topNoticeWidth, class: className, style, motionProps, onAfterLeave } = props;
49
- const heightStatus = height < prevHeight ? "decrease" : "increase";
50
- prevHeight = height;
51
- const contentPrefixCls = `${listPrefixCls}-content`;
52
- const contentStyle = {
53
- ...style,
54
- "height": `${height}px`,
55
- "--top-notificiation-height": `${topNoticeHeight ?? 0}px`,
56
- "--top-notificiation-width": `${topNoticeWidth ?? 0}px`
57
- };
58
- const contentClass = classNames(contentPrefixCls, `${contentPrefixCls}-${heightStatus}`, className);
59
- return h(TransitionGroup, {
60
- tag: "div",
61
- appear: true,
62
- ...motionProps,
63
- ref: (el) => {
64
- innerRef.value = el?.$el ?? el;
65
- },
66
- class: contentClass,
67
- style: contentStyle,
68
- onAfterLeave
69
- }, () => slots.default?.());
70
- };
71
- }
56
+ name: "NotificationListContent",
57
+ inheritAttrs: false
72
58
  });
73
59
  //#endregion
74
60
  export { Content as default };
@@ -1,10 +1,8 @@
1
- import { CSSProperties, PropType, TransitionGroupProps } from 'vue';
2
- import { StackInput } from '../hooks/useStack';
3
- import { ComponentsType, NotificationClassNames as NoticeClassNames, NotificationStyles as NoticeStyles, NotificationProps } from '../Notification';
4
- type Key = string | number | symbol;
1
+ import { CSSProperties, TransitionGroupProps } from 'vue';
2
+ import { Key, StackConfig } from '../interface';
3
+ import { ComponentsType, NotificationClassNames as NoticeClassNames, NotificationProps, NotificationStyles as NoticeStyles } from '../Notification';
5
4
  export type Placement = 'top' | 'topLeft' | 'topRight' | 'bottom' | 'bottomLeft' | 'bottomRight';
6
- export type { StackConfig, StackInput } from '../hooks/useStack';
7
- export type { ComponentsType } from '../Notification';
5
+ export type { StackConfig };
8
6
  export interface NotificationListConfig extends Omit<NotificationProps, 'prefixCls'> {
9
7
  key: Key;
10
8
  placement?: Placement;
@@ -26,131 +24,12 @@ export interface NotificationListProps {
26
24
  classNames?: NotificationClassNames;
27
25
  styles?: NotificationStyles;
28
26
  components?: ComponentsType;
29
- stack?: StackInput;
27
+ stack?: StackConfig;
30
28
  motion?: TransitionGroupProps | ((placement: Placement) => TransitionGroupProps);
31
- class?: string;
29
+ className?: string;
32
30
  style?: CSSProperties;
33
31
  onNoticeClose?: (key: Key) => void;
34
32
  onAllRemoved?: (placement: Placement) => void;
35
33
  }
36
- declare const NotificationList: import('vue').DefineComponent<import('vue').ExtractPropTypes<{
37
- configList: {
38
- type: PropType<NotificationListConfig[]>;
39
- default: () => never[];
40
- };
41
- prefixCls: {
42
- type: StringConstructor;
43
- default: string;
44
- };
45
- placement: {
46
- type: PropType<Placement>;
47
- required: true;
48
- };
49
- pauseOnHover: {
50
- type: BooleanConstructor;
51
- default: undefined;
52
- };
53
- classNames: {
54
- type: PropType<NotificationClassNames>;
55
- default: undefined;
56
- };
57
- styles: {
58
- type: PropType<NotificationStyles>;
59
- default: undefined;
60
- };
61
- components: {
62
- type: PropType<ComponentsType>;
63
- default: undefined;
64
- };
65
- stack: {
66
- type: PropType<StackInput>;
67
- default: undefined;
68
- };
69
- motion: {
70
- type: PropType<NotificationListProps["motion"]>;
71
- default: undefined;
72
- };
73
- class: {
74
- type: StringConstructor;
75
- default: undefined;
76
- };
77
- style: {
78
- type: PropType<CSSProperties>;
79
- default: undefined;
80
- };
81
- onNoticeClose: {
82
- type: PropType<(key: Key) => void>;
83
- default: undefined;
84
- };
85
- onAllRemoved: {
86
- type: PropType<(placement: Placement) => void>;
87
- default: undefined;
88
- };
89
- }>, () => import("vue/jsx-runtime").JSX.Element, {}, {}, {}, import('vue').ComponentOptionsMixin, import('vue').ComponentOptionsMixin, {}, string, import('vue').PublicProps, Readonly<import('vue').ExtractPropTypes<{
90
- configList: {
91
- type: PropType<NotificationListConfig[]>;
92
- default: () => never[];
93
- };
94
- prefixCls: {
95
- type: StringConstructor;
96
- default: string;
97
- };
98
- placement: {
99
- type: PropType<Placement>;
100
- required: true;
101
- };
102
- pauseOnHover: {
103
- type: BooleanConstructor;
104
- default: undefined;
105
- };
106
- classNames: {
107
- type: PropType<NotificationClassNames>;
108
- default: undefined;
109
- };
110
- styles: {
111
- type: PropType<NotificationStyles>;
112
- default: undefined;
113
- };
114
- components: {
115
- type: PropType<ComponentsType>;
116
- default: undefined;
117
- };
118
- stack: {
119
- type: PropType<StackInput>;
120
- default: undefined;
121
- };
122
- motion: {
123
- type: PropType<NotificationListProps["motion"]>;
124
- default: undefined;
125
- };
126
- class: {
127
- type: StringConstructor;
128
- default: undefined;
129
- };
130
- style: {
131
- type: PropType<CSSProperties>;
132
- default: undefined;
133
- };
134
- onNoticeClose: {
135
- type: PropType<(key: Key) => void>;
136
- default: undefined;
137
- };
138
- onAllRemoved: {
139
- type: PropType<(placement: Placement) => void>;
140
- default: undefined;
141
- };
142
- }>> & Readonly<{}>, {
143
- class: string;
144
- style: CSSProperties;
145
- prefixCls: string;
146
- classNames: NotificationClassNames;
147
- styles: NotificationStyles;
148
- components: ComponentsType;
149
- pauseOnHover: boolean;
150
- motion: TransitionGroupProps | ((placement: Placement) => TransitionGroupProps) | undefined;
151
- configList: NotificationListConfig[];
152
- stack: StackInput;
153
- onNoticeClose: (key: Key) => void;
154
- onAllRemoved: (placement: Placement) => void;
155
- }, {}, {}, {}, string, import('vue').ComponentProvideOptions, true, {}, any>;
34
+ declare const NotificationList: import('vue').DefineSetupFnComponent<NotificationListProps, {}, {}, NotificationListProps & {}, import('vue').PublicProps>;
156
35
  export default NotificationList;
@@ -1,11 +1,12 @@
1
1
  import Notification from "../Notification.js";
2
- import { NotificationContext } from "../NotificationProvider.js";
2
+ import { useNotificationContext } from "../NotificationProvider.js";
3
3
  import useListPosition from "../hooks/useListPosition/index.js";
4
4
  import useStack from "../hooks/useStack.js";
5
5
  import Content from "./Content.js";
6
- import { computed, createVNode, defineComponent, inject, isVNode, mergeProps, nextTick, onMounted, ref, shallowRef, toRef, watch } from "vue";
7
- import { classNames } from "@v-c/util";
6
+ import { TransitionGroup, computed, createVNode, defineComponent, isVNode, mergeProps, ref, shallowRef, toRef, watch, watchEffect } from "vue";
7
+ import { clsx } from "@v-c/util";
8
8
  import { getTransitionGroupProps } from "@v-c/util/dist/utils/transition";
9
+ import { unrefElement } from "@v-c/util/dist/vueuse/unref-element";
9
10
  //#region src/NotificationList/index.tsx
10
11
  function _isSlot(s) {
11
12
  return typeof s === "function" || Object.prototype.toString.call(s) === "[object Object]" && !isVNode(s);
@@ -21,29 +22,142 @@ var noticeSlotKeys = [
21
22
  "close",
22
23
  "progress"
23
24
  ];
24
- function fillClassNames(classNamesList) {
25
+ function fillClassNames(list) {
25
26
  return noticeSlotKeys.reduce((merged, key) => {
26
- merged[key] = classNames(...classNamesList.map((cn) => cn?.[key]));
27
+ merged[key] = clsx(...list.map((item) => item?.[key]));
27
28
  return merged;
28
29
  }, {});
29
30
  }
30
- function fillStyles(stylesList) {
31
+ function fillStyles(list) {
31
32
  return noticeSlotKeys.reduce((merged, key) => {
32
- merged[key] = Object.assign({}, ...stylesList.map((s) => s?.[key]));
33
+ merged[key] = Object.assign({}, ...list.map((item) => item?.[key]));
33
34
  return merged;
34
35
  }, {});
35
36
  }
36
- var NotificationList = /* @__PURE__ */ defineComponent({
37
- name: "NotificationList",
38
- inheritAttrs: false,
37
+ function getIndex(keys, key) {
38
+ const strKey = String(key);
39
+ const index = keys.findIndex((item) => String(item.key) === strKey);
40
+ if (index === -1) return;
41
+ return keys.length - index - 1;
42
+ }
43
+ var NotificationList = /* @__PURE__ */ defineComponent((props, { attrs }) => {
44
+ const ctx = useNotificationContext();
45
+ const configList = computed(() => props.configList ?? []);
46
+ const keys = computed(() => configList.value.map((config) => ({
47
+ ...config,
48
+ key: String(config.key)
49
+ })));
50
+ const [stackEnabled, stackParams] = useStack(toRef(props, "stack"));
51
+ const listHovering = shallowRef(false);
52
+ const expanded = computed(() => stackEnabled.value && (listHovering.value || keys.value.length <= (stackParams.threshold?.value ?? 0)));
53
+ const stackPosition = computed(() => {
54
+ if (!stackEnabled.value || expanded.value) return;
55
+ return {
56
+ offset: stackParams.offset?.value,
57
+ threshold: stackParams.threshold?.value
58
+ };
59
+ });
60
+ const gap = ref(0);
61
+ const contentRef = ref(null);
62
+ const [position, setNodeSize] = useListPosition(keys, stackPosition, gap);
63
+ const hasConfigList = computed(() => !!configList.value.length);
64
+ watchEffect(() => {
65
+ if (!hasConfigList.value) return;
66
+ const listNode = unrefElement(contentRef.value?.nativeElement);
67
+ if (!listNode) return;
68
+ const { gap: cssGap, rowGap } = window.getComputedStyle(listNode);
69
+ const nextGap = Number.parseFloat(rowGap || cssGap) || 0;
70
+ if (gap.value !== nextGap) gap.value = nextGap;
71
+ }, { flush: "post" });
72
+ const checkAllClosed = () => {
73
+ if (configList.value.length === 0) props.onAllRemoved?.(props.placement);
74
+ };
75
+ const placementMotion = computed(() => {
76
+ if (typeof props.motion === "function") return props.placement ? props.motion(props.placement) : void 0;
77
+ return props.motion;
78
+ });
79
+ watch(keys, (next, prev) => {
80
+ if (!prev) return;
81
+ const nextKeySet = new Set(next.map((item) => String(item.key)));
82
+ prev.forEach((item) => {
83
+ const key = String(item.key);
84
+ if (!nextKeySet.has(key)) setNodeSize(key, null);
85
+ });
86
+ });
87
+ return () => {
88
+ let _slot;
89
+ const { prefixCls = "vc-notification", pauseOnHover, classNames: ncs, styles: nss, components, placement, className, style, onNoticeClose } = props;
90
+ const listPrefixCls = `${prefixCls}-list`;
91
+ const positionResult = position.value;
92
+ let motionGroupProps = {};
93
+ if (placementMotion.value) motionGroupProps = getTransitionGroupProps(placementMotion.value.name, placementMotion.value);
94
+ const renderItems = () => keys.value.map((config) => {
95
+ const { key, placement: _itemPlacement, classNames: configClassNames, styles: configStyles, className: configClassName, style: configStyle, onClose: configOnClose, ...notificationConfig } = config;
96
+ const strKey = String(key);
97
+ const notificationIndex = getIndex(keys.value, key);
98
+ const stackInThreshold = stackEnabled.value && notificationIndex !== void 0 && notificationIndex < (stackParams.threshold?.value ?? 0);
99
+ return createVNode(Notification, mergeProps({ "key": strKey }, notificationConfig, {
100
+ "ref": (el) => {
101
+ setNodeSize(strKey, unrefElement(el?.nativeElement) ?? null);
102
+ },
103
+ "prefixCls": prefixCls,
104
+ "class": clsx(ctx.value?.classNames?.notice, configClassName),
105
+ "style": configStyle,
106
+ "classNames": fillClassNames([ncs, configClassNames]),
107
+ "styles": fillStyles([nss, configStyles]),
108
+ "components": {
109
+ ...components,
110
+ ...config.components
111
+ },
112
+ "hovering": stackEnabled.value && listHovering.value,
113
+ "pauseOnHover": config.pauseOnHover ?? pauseOnHover,
114
+ "offset": positionResult.notificationPosition.get(strKey),
115
+ "notificationIndex": notificationIndex,
116
+ "stackInThreshold": stackInThreshold,
117
+ "onClose": () => {
118
+ configOnClose?.();
119
+ onNoticeClose?.(key);
120
+ }
121
+ }), null);
122
+ });
123
+ return createVNode("div", {
124
+ "class": clsx(prefixCls, listPrefixCls, `${prefixCls}-${placement}`, ctx.value?.classNames?.list, className, ncs?.list, attrs.class, {
125
+ [`${prefixCls}-stack`]: stackEnabled.value,
126
+ [`${prefixCls}-stack-expanded`]: expanded.value,
127
+ [`${listPrefixCls}-hovered`]: listHovering.value
128
+ }),
129
+ "onMouseenter": () => {
130
+ listHovering.value = true;
131
+ },
132
+ "onMouseleave": () => {
133
+ listHovering.value = false;
134
+ },
135
+ "style": {
136
+ ...nss?.list,
137
+ ...style,
138
+ ...attrs.style ?? {}
139
+ }
140
+ }, [createVNode(Content, {
141
+ "ref": contentRef,
142
+ "listPrefixCls": listPrefixCls,
143
+ "height": positionResult.totalHeight,
144
+ "topNoticeHeight": positionResult.topNoticeHeight,
145
+ "topNoticeWidth": positionResult.topNoticeWidth,
146
+ "className": ncs?.listContent,
147
+ "style": nss?.listContent
148
+ }, { default: () => [createVNode(TransitionGroup, mergeProps({ "appear": true }, motionGroupProps, { "onAfterLeave": checkAllClosed }), _isSlot(_slot = renderItems()) ? _slot : { default: () => [_slot] })] })]);
149
+ };
150
+ }, {
39
151
  props: {
40
152
  configList: {
41
153
  type: Array,
42
- default: () => []
154
+ required: false,
155
+ default: void 0
43
156
  },
44
157
  prefixCls: {
45
158
  type: String,
46
- default: "vc-notification"
159
+ required: false,
160
+ default: void 0
47
161
  },
48
162
  placement: {
49
163
  type: String,
@@ -51,154 +165,57 @@ var NotificationList = /* @__PURE__ */ defineComponent({
51
165
  },
52
166
  pauseOnHover: {
53
167
  type: Boolean,
168
+ required: false,
54
169
  default: void 0
55
170
  },
56
171
  classNames: {
57
172
  type: Object,
173
+ required: false,
58
174
  default: void 0
59
175
  },
60
176
  styles: {
61
177
  type: Object,
178
+ required: false,
62
179
  default: void 0
63
180
  },
64
181
  components: {
65
182
  type: Object,
183
+ required: false,
66
184
  default: void 0
67
185
  },
68
186
  stack: {
69
187
  type: [Boolean, Object],
188
+ required: false,
70
189
  default: void 0
71
190
  },
72
191
  motion: {
73
192
  type: [Object, Function],
193
+ required: false,
74
194
  default: void 0
75
195
  },
76
- class: {
196
+ className: {
77
197
  type: String,
198
+ required: false,
78
199
  default: void 0
79
200
  },
80
201
  style: {
81
202
  type: Object,
203
+ required: false,
82
204
  default: void 0
83
205
  },
84
206
  onNoticeClose: {
85
207
  type: Function,
208
+ required: false,
86
209
  default: void 0
87
210
  },
88
211
  onAllRemoved: {
89
212
  type: Function,
213
+ required: false,
90
214
  default: void 0
91
215
  }
92
216
  },
93
- setup(props, { attrs }) {
94
- const ctx = inject(NotificationContext, ref({}));
95
- const keys = computed(() => props.configList.map((config) => ({
96
- config,
97
- key: String(config.key)
98
- })));
99
- const placementMotion = computed(() => {
100
- if (typeof props.motion === "function") return props.motion(props.placement);
101
- return props.motion;
102
- });
103
- const motionGroupProps = computed(() => {
104
- const motionVal = placementMotion.value;
105
- if (!motionVal) return {};
106
- if (motionVal.name) return getTransitionGroupProps(motionVal.name, motionVal);
107
- return { ...motionVal };
108
- });
109
- const [stackEnabled, stackParams] = useStack(toRef(props, "stack"));
110
- const listHovering = shallowRef(false);
111
- const expanded = computed(() => stackEnabled.value && (listHovering.value || keys.value.length <= stackParams.value.threshold));
112
- const stackPosition = computed(() => {
113
- if (!stackEnabled.value || expanded.value) return;
114
- return {
115
- offset: stackParams.value.offset,
116
- threshold: stackParams.value.threshold
117
- };
118
- });
119
- const gap = shallowRef(0);
120
- const contentRef = shallowRef(null);
121
- const [notificationPosition, setNodeSize, totalHeight, topNoticeHeight, topNoticeWidth] = useListPosition(computed(() => props.configList), stackPosition, gap);
122
- const hasConfigList = computed(() => keys.value.length > 0);
123
- function syncGap() {
124
- const node = contentRef.value?.nativeElement;
125
- if (!node) return;
126
- const { gap: cssGap, rowGap } = window.getComputedStyle(node);
127
- const next = Number.parseFloat(rowGap || cssGap) || 0;
128
- if (next !== gap.value) gap.value = next;
129
- }
130
- onMounted(syncGap);
131
- watch(hasConfigList, () => {
132
- nextTick(syncGap);
133
- });
134
- function checkAllClosed() {
135
- if (!props.placement) return;
136
- if (keys.value.length === 0) props.onAllRemoved?.(props.placement);
137
- }
138
- return () => {
139
- let _slot;
140
- const { prefixCls = "vc-notification", placement, classNames: classNames$1, styles, components, pauseOnHover, class: className, style, onNoticeClose } = props;
141
- const listPrefixCls = `${prefixCls}-list`;
142
- const ctxClassNames = ctx.value?.classNames;
143
- const renderItems = () => keys.value.map(({ config }) => {
144
- const { key, placement: itemPlacement, onClose: configOnClose, ...notificationConfig } = config;
145
- const strKey = String(key);
146
- const dataIndex = keys.value.findIndex((item) => item.key === strKey);
147
- const notificationIndex = dataIndex === -1 ? void 0 : keys.value.length - dataIndex - 1;
148
- const stackInThreshold = stackEnabled.value && notificationIndex !== void 0 && notificationIndex < stackParams.value.threshold;
149
- return createVNode(Notification, mergeProps(notificationConfig, {
150
- "key": strKey,
151
- "ref": (el) => {
152
- setNodeSize(strKey, el?.nativeElement ?? null);
153
- },
154
- "prefixCls": prefixCls,
155
- "class": classNames(ctxClassNames?.notice, config.class),
156
- "classNames": fillClassNames([classNames$1, config.classNames]),
157
- "styles": fillStyles([styles, config.styles]),
158
- "components": {
159
- ...components,
160
- ...config.components
161
- },
162
- "hovering": stackEnabled.value && listHovering.value,
163
- "pauseOnHover": config.pauseOnHover ?? pauseOnHover,
164
- "offset": notificationPosition.value.get(strKey),
165
- "notificationIndex": notificationIndex,
166
- "stackInThreshold": !!stackInThreshold,
167
- "onClose": () => {
168
- configOnClose?.();
169
- onNoticeClose?.(key);
170
- }
171
- }), null);
172
- });
173
- return createVNode("div", {
174
- "class": classNames(prefixCls, listPrefixCls, `${prefixCls}-${placement}`, ctxClassNames?.list, className, attrs.class, classNames$1?.list, {
175
- [`${prefixCls}-stack`]: stackEnabled.value,
176
- [`${prefixCls}-stack-expanded`]: expanded.value,
177
- [`${listPrefixCls}-hovered`]: listHovering.value
178
- }),
179
- "onMouseenter": () => {
180
- listHovering.value = true;
181
- },
182
- "onMouseleave": () => {
183
- listHovering.value = false;
184
- },
185
- "style": {
186
- ...styles?.list,
187
- ...style
188
- }
189
- }, [createVNode(Content, {
190
- "ref": contentRef,
191
- "listPrefixCls": listPrefixCls,
192
- "height": totalHeight.value,
193
- "topNoticeHeight": topNoticeHeight.value,
194
- "topNoticeWidth": topNoticeWidth.value,
195
- "class": classNames$1?.listContent,
196
- "style": styles?.listContent,
197
- "motionProps": motionGroupProps.value,
198
- "onAfterLeave": checkAllClosed
199
- }, _isSlot(_slot = renderItems()) ? _slot : { default: () => [_slot] })]);
200
- };
201
- }
217
+ name: "NotificationList",
218
+ inheritAttrs: false
202
219
  });
203
220
  //#endregion
204
221
  export { NotificationList as default };