@rainbow-oh/yee-c 0.8.2 → 0.8.3
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.
- package/dist/cjs/Input/style/index.less +1 -0
- package/dist/cjs/Selector/style/index.less +1 -0
- package/dist/cjs/Table/icon/arrow-icon.js +1 -1
- package/dist/cjs/Table/theader/cell.js +6 -3
- package/dist/cjs/TextArea/style/index.less +1 -0
- package/dist/cjs/VerificationCode/style/index.less +1 -0
- package/dist/cjs/hooks/useCountdown.d.ts +2 -1
- package/dist/cjs/hooks/useCountdown.js +46 -23
- package/dist/cjs/locale/interface.d.ts +3 -0
- package/dist/cjs/locale/lang/en_US.js +4 -1
- package/dist/cjs/locale/lang/ja_JP.js +4 -1
- package/dist/cjs/locale/lang/zh_CN.js +4 -1
- package/dist/cjs/locale/lang/zh_TW.js +4 -1
- package/dist/cjs/message/demo/base.js +1 -1
- package/dist/cjs/message/index.d.ts +1 -1
- package/dist/cjs/message/interface.d.ts +16 -7
- package/dist/cjs/message/message-provider.d.ts +2 -1
- package/dist/cjs/message/message-provider.js +1 -1
- package/dist/cjs/message/message.js +14 -9
- package/dist/cjs/message/style/index.less +3 -1
- package/dist/cjs/message/use-message.d.ts +3 -12
- package/dist/cjs/message/use-message.js +103 -45
- package/dist/cjs/message/wrapper.d.ts +21 -27
- package/dist/cjs/message/wrapper.js +49 -19
- package/dist/cjs/notice/index.d.ts +1 -1
- package/dist/cjs/notice/interface.d.ts +17 -7
- package/dist/cjs/notice/notice-list.d.ts +3 -3
- package/dist/cjs/notice/notice-provider.d.ts +2 -1
- package/dist/cjs/notice/notice-provider.js +1 -1
- package/dist/cjs/notice/notice.js +63 -20
- package/dist/cjs/notice/style/index.less +13 -1
- package/dist/cjs/notice/use-notice.d.ts +2 -11
- package/dist/cjs/notice/use-notice.js +156 -71
- package/dist/cjs/notice/wrapper.d.ts +19 -15
- package/dist/cjs/notice/wrapper.js +122 -52
- package/dist/cjs/style/size.css +3 -3
- package/dist/cjs/style/themes.css +1 -1
- package/dist/cjs/style/variables.css +4 -4
- package/dist/cjs/version.d.ts +1 -1
- package/dist/cjs/version.js +1 -1
- package/dist/esm/Input/style/index.less +1 -0
- package/dist/esm/Selector/style/index.less +1 -0
- package/dist/esm/Table/icon/arrow-icon.js +1 -1
- package/dist/esm/Table/theader/cell.js +7 -3
- package/dist/esm/TextArea/style/index.less +1 -0
- package/dist/esm/VerificationCode/style/index.less +1 -0
- package/dist/esm/hooks/useCountdown.d.ts +2 -1
- package/dist/esm/hooks/useCountdown.js +44 -14
- package/dist/esm/locale/interface.d.ts +3 -0
- package/dist/esm/locale/lang/en_US.js +4 -1
- package/dist/esm/locale/lang/ja_JP.js +4 -1
- package/dist/esm/locale/lang/zh_CN.js +4 -1
- package/dist/esm/locale/lang/zh_TW.js +4 -1
- package/dist/esm/message/demo/base.js +4 -1
- package/dist/esm/message/index.d.ts +1 -1
- package/dist/esm/message/interface.d.ts +16 -7
- package/dist/esm/message/message-provider.d.ts +2 -1
- package/dist/esm/message/message-provider.js +1 -1
- package/dist/esm/message/message.js +22 -9
- package/dist/esm/message/style/index.less +3 -1
- package/dist/esm/message/use-message.d.ts +3 -12
- package/dist/esm/message/use-message.js +129 -79
- package/dist/esm/message/wrapper.d.ts +21 -27
- package/dist/esm/message/wrapper.js +60 -18
- package/dist/esm/notice/index.d.ts +1 -1
- package/dist/esm/notice/interface.d.ts +17 -7
- package/dist/esm/notice/notice-list.d.ts +3 -3
- package/dist/esm/notice/notice-provider.d.ts +2 -1
- package/dist/esm/notice/notice-provider.js +1 -1
- package/dist/esm/notice/notice.js +73 -21
- package/dist/esm/notice/style/index.less +13 -1
- package/dist/esm/notice/use-notice.d.ts +2 -11
- package/dist/esm/notice/use-notice.js +180 -100
- package/dist/esm/notice/wrapper.d.ts +19 -15
- package/dist/esm/notice/wrapper.js +144 -62
- package/dist/esm/style/size.css +3 -3
- package/dist/esm/style/themes.css +1 -1
- package/dist/esm/style/variables.css +4 -4
- package/dist/esm/version.d.ts +1 -1
- package/dist/esm/version.js +1 -1
- package/dist/umd/yee-c.min.css +2 -2
- package/dist/umd/yee-c.min.js +1 -1
- package/package.json +1 -1
- package/src/Input/style/index.less +1 -0
- package/src/Selector/style/index.less +1 -0
- package/src/Table/icon/arrow-icon.tsx +1 -1
- package/src/Table/theader/cell.tsx +6 -3
- package/src/TextArea/style/index.less +1 -0
- package/src/VerificationCode/style/index.less +1 -0
- package/src/hooks/useCountdown.ts +52 -21
- package/src/locale/interface.ts +3 -0
- package/src/locale/lang/en_US.ts +3 -0
- package/src/locale/lang/ja_JP.ts +3 -0
- package/src/locale/lang/zh_CN.ts +3 -0
- package/src/locale/lang/zh_TW.ts +3 -0
- package/src/message/demo/base.tsx +1 -1
- package/src/message/index.ts +1 -1
- package/src/message/interface.ts +22 -7
- package/src/message/message-provider.tsx +3 -2
- package/src/message/message.test.tsx +283 -0
- package/src/message/message.tsx +14 -9
- package/src/message/style/index.less +3 -1
- package/src/message/use-message.tsx +144 -67
- package/src/message/wrapper.tsx +62 -20
- package/src/notice/index.en-US.md +76 -75
- package/src/notice/index.ts +6 -1
- package/src/notice/index.zh-CN.md +3 -2
- package/src/notice/interface.ts +31 -14
- package/src/notice/notice-list.tsx +3 -9
- package/src/notice/notice-provider.tsx +3 -2
- package/src/notice/notice.test.tsx +450 -0
- package/src/notice/notice.tsx +69 -21
- package/src/notice/style/index.less +13 -1
- package/src/notice/use-notice.tsx +210 -94
- package/src/notice/wrapper.tsx +159 -71
- package/src/style/size.css +3 -3
- package/src/version.ts +1 -1
|
@@ -1,46 +1,40 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { Root } from 'react-dom/client';
|
|
3
|
-
import { MessageConfig, MessageType, WrapperedMessageConfig } from './interface';
|
|
3
|
+
import { MessageClose, MessageConfig, MessageType, WrapperedMessageConfig } from './interface';
|
|
4
4
|
declare class MessageWrapper {
|
|
5
5
|
root: Root | null;
|
|
6
6
|
messages: MessageType[];
|
|
7
7
|
container: HTMLElement | null;
|
|
8
|
+
generationByKey: Map<string | number, number>;
|
|
9
|
+
generation: number;
|
|
10
|
+
timerGeneration: number;
|
|
8
11
|
constructor();
|
|
9
12
|
private createContainer;
|
|
10
13
|
private cleanupContainer;
|
|
11
14
|
uuid(): string;
|
|
12
15
|
unmount(): void;
|
|
13
16
|
render(): void;
|
|
14
|
-
show(params: WrapperedMessageConfig):
|
|
15
|
-
destroy(key: string | number): void;
|
|
16
|
-
open(params: string | MessageConfig):
|
|
17
|
-
info(params: string | MessageConfig):
|
|
18
|
-
success(params: string | MessageConfig):
|
|
19
|
-
warning(params: string | MessageConfig):
|
|
20
|
-
error(params: string | MessageConfig):
|
|
21
|
-
loading(params: string | MessageConfig):
|
|
17
|
+
show(params: WrapperedMessageConfig): MessageClose;
|
|
18
|
+
destroy(key: string | number, expectedTimerGeneration?: number): void;
|
|
19
|
+
open(params: string | MessageConfig): MessageClose;
|
|
20
|
+
info(params: string | MessageConfig): MessageClose;
|
|
21
|
+
success(params: string | MessageConfig): MessageClose;
|
|
22
|
+
warning(params: string | MessageConfig): MessageClose;
|
|
23
|
+
error(params: string | MessageConfig): MessageClose;
|
|
24
|
+
loading(params: string | MessageConfig): MessageClose;
|
|
22
25
|
}
|
|
23
26
|
declare const messageWrapper: MessageWrapper;
|
|
24
27
|
export default messageWrapper;
|
|
25
28
|
export declare const message: {
|
|
26
|
-
open: (params: string | MessageConfig) =>
|
|
27
|
-
info: (params: string | MessageConfig) =>
|
|
28
|
-
success: (params: string | MessageConfig) =>
|
|
29
|
-
warning: (params: string | MessageConfig) =>
|
|
30
|
-
error: (params: string | MessageConfig) =>
|
|
31
|
-
loading: (params: string | MessageConfig) =>
|
|
32
|
-
destroy: (key: string | number) => void;
|
|
29
|
+
open: (params: string | MessageConfig) => MessageClose;
|
|
30
|
+
info: (params: string | MessageConfig) => MessageClose;
|
|
31
|
+
success: (params: string | MessageConfig) => MessageClose;
|
|
32
|
+
warning: (params: string | MessageConfig) => MessageClose;
|
|
33
|
+
error: (params: string | MessageConfig) => MessageClose;
|
|
34
|
+
loading: (params: string | MessageConfig) => MessageClose;
|
|
35
|
+
destroy: (key: string | number, expectedTimerGeneration?: number) => void;
|
|
33
36
|
useMessage: () => {
|
|
34
|
-
messageApi:
|
|
35
|
-
|
|
36
|
-
info: (props: string | MessageConfig) => () => void;
|
|
37
|
-
success: (props: string | MessageConfig) => () => void;
|
|
38
|
-
error: (props: string | MessageConfig) => () => void;
|
|
39
|
-
warning: (props: string | MessageConfig) => () => void;
|
|
40
|
-
loading: (props: string | MessageConfig) => () => void;
|
|
41
|
-
destroy: (key: string | number) => void;
|
|
42
|
-
clear: () => void;
|
|
43
|
-
};
|
|
44
|
-
messageHolder: React.ReactPortal;
|
|
37
|
+
messageApi: import("./interface").MessageApi;
|
|
38
|
+
messageHolder: React.ReactPortal | null;
|
|
45
39
|
};
|
|
46
40
|
};
|
|
@@ -54,11 +54,17 @@ var import_react = __toESM(require("react"));
|
|
|
54
54
|
var import_client = require("react-dom/client");
|
|
55
55
|
var import_message_list = __toESM(require("./message-list"));
|
|
56
56
|
var import_use_message = __toESM(require("./use-message"));
|
|
57
|
+
var noop = () => {
|
|
58
|
+
};
|
|
57
59
|
var MessageWrapper = class {
|
|
58
60
|
constructor() {
|
|
59
61
|
this.root = null;
|
|
60
62
|
this.messages = [];
|
|
61
63
|
this.container = null;
|
|
64
|
+
this.generationByKey = /* @__PURE__ */ new Map();
|
|
65
|
+
this.generation = 0;
|
|
66
|
+
this.timerGeneration = 0;
|
|
67
|
+
this.destroy = this.destroy.bind(this);
|
|
62
68
|
}
|
|
63
69
|
createContainer() {
|
|
64
70
|
if (!this.container) {
|
|
@@ -87,8 +93,12 @@ var MessageWrapper = class {
|
|
|
87
93
|
this.root = null;
|
|
88
94
|
this.cleanupContainer();
|
|
89
95
|
this.messages = [];
|
|
96
|
+
this.generationByKey.clear();
|
|
90
97
|
}
|
|
91
98
|
render() {
|
|
99
|
+
if (typeof document === "undefined") {
|
|
100
|
+
return;
|
|
101
|
+
}
|
|
92
102
|
if (this.messages.length === 0) {
|
|
93
103
|
if (this.root) {
|
|
94
104
|
this.root.unmount();
|
|
@@ -102,55 +112,75 @@ var MessageWrapper = class {
|
|
|
102
112
|
this.root = (0, import_client.createRoot)(container);
|
|
103
113
|
}
|
|
104
114
|
this.root.render(
|
|
105
|
-
/* @__PURE__ */ import_react.default.createElement(import_message_list.default, { items: this.messages, onDestroy: this.destroy
|
|
115
|
+
/* @__PURE__ */ import_react.default.createElement(import_message_list.default, { items: this.messages, onDestroy: this.destroy })
|
|
106
116
|
);
|
|
107
117
|
}
|
|
108
118
|
show(params) {
|
|
109
|
-
|
|
110
|
-
|
|
119
|
+
var _a, _b;
|
|
120
|
+
if (typeof document === "undefined") {
|
|
121
|
+
return noop;
|
|
111
122
|
}
|
|
112
|
-
const
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
123
|
+
const key = (_a = params.key) != null ? _a : this.uuid();
|
|
124
|
+
const keyGeneration = (_b = this.generationByKey.get(key)) != null ? _b : this.generation++;
|
|
125
|
+
this.generationByKey.set(key, keyGeneration);
|
|
126
|
+
const nextMessage = __spreadProps(__spreadValues({}, params), {
|
|
127
|
+
key,
|
|
128
|
+
timerGeneration: this.timerGeneration++
|
|
129
|
+
});
|
|
130
|
+
const exists = this.messages.some((item) => item.key === key);
|
|
131
|
+
if (exists) {
|
|
132
|
+
this.messages = this.messages.map(
|
|
133
|
+
(item) => item.key === key ? nextMessage : item
|
|
134
|
+
);
|
|
120
135
|
} else {
|
|
121
|
-
this.messages.
|
|
136
|
+
this.messages = [...this.messages, nextMessage];
|
|
122
137
|
}
|
|
123
138
|
this.render();
|
|
139
|
+
return () => {
|
|
140
|
+
if (this.generationByKey.get(key) === keyGeneration) {
|
|
141
|
+
this.destroy(key);
|
|
142
|
+
}
|
|
143
|
+
};
|
|
124
144
|
}
|
|
125
|
-
destroy(key) {
|
|
145
|
+
destroy(key, expectedTimerGeneration) {
|
|
146
|
+
var _a;
|
|
147
|
+
const target = this.messages.find((item) => item.key === key);
|
|
148
|
+
if (expectedTimerGeneration !== void 0 && (target == null ? void 0 : target.timerGeneration) !== expectedTimerGeneration) {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
if (!target) {
|
|
152
|
+
return;
|
|
153
|
+
}
|
|
154
|
+
this.generationByKey.delete(key);
|
|
126
155
|
this.messages = this.messages.filter((item) => item.key !== key);
|
|
127
156
|
this.render();
|
|
157
|
+
(_a = target.onClose) == null ? void 0 : _a.call(target);
|
|
128
158
|
}
|
|
129
159
|
open(params) {
|
|
130
|
-
this.show(typeof params === "string" ? { content: params } : params);
|
|
160
|
+
return this.show(typeof params === "string" ? { content: params } : params);
|
|
131
161
|
}
|
|
132
162
|
info(params) {
|
|
133
|
-
this.show(
|
|
163
|
+
return this.show(
|
|
134
164
|
typeof params === "string" ? { status: "info", content: params } : __spreadProps(__spreadValues({}, params), { status: "info" })
|
|
135
165
|
);
|
|
136
166
|
}
|
|
137
167
|
success(params) {
|
|
138
|
-
this.show(
|
|
168
|
+
return this.show(
|
|
139
169
|
typeof params === "string" ? { status: "success", content: params } : __spreadProps(__spreadValues({}, params), { status: "success" })
|
|
140
170
|
);
|
|
141
171
|
}
|
|
142
172
|
warning(params) {
|
|
143
|
-
this.show(
|
|
173
|
+
return this.show(
|
|
144
174
|
typeof params === "string" ? { status: "warning", content: params } : __spreadProps(__spreadValues({}, params), { status: "warning" })
|
|
145
175
|
);
|
|
146
176
|
}
|
|
147
177
|
error(params) {
|
|
148
|
-
this.show(
|
|
178
|
+
return this.show(
|
|
149
179
|
typeof params === "string" ? { status: "error", content: params } : __spreadProps(__spreadValues({}, params), { status: "error" })
|
|
150
180
|
);
|
|
151
181
|
}
|
|
152
182
|
loading(params) {
|
|
153
|
-
this.show(
|
|
183
|
+
return this.show(
|
|
154
184
|
typeof params === "string" ? { status: "loading", content: params } : __spreadProps(__spreadValues({}, params), { status: "loading" })
|
|
155
185
|
);
|
|
156
186
|
}
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import { notice } from './wrapper';
|
|
2
|
-
export type { NoticeConfig } from './interface';
|
|
2
|
+
export type { NoticeApi, NoticeClose, NoticeConfig, PlacementType, } from './interface';
|
|
3
3
|
export * from './notice-provider';
|
|
4
4
|
export { default as useNotice } from './use-notice';
|
|
5
5
|
export default notice;
|
|
@@ -1,9 +1,7 @@
|
|
|
1
1
|
/// <reference types="react" />
|
|
2
|
+
export type PlacementType = 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight' | 'top' | 'bottom';
|
|
2
3
|
export type NoticeConfig = {
|
|
3
|
-
|
|
4
|
-
* test identifier
|
|
5
|
-
*/
|
|
6
|
-
'data-testid'?: string;
|
|
4
|
+
[dataAttribute: `data-${string}`]: string | number | boolean | undefined;
|
|
7
5
|
/**
|
|
8
6
|
* Custom prefix class name
|
|
9
7
|
*/
|
|
@@ -25,7 +23,7 @@ export type NoticeConfig = {
|
|
|
25
23
|
*/
|
|
26
24
|
content: React.ReactNode;
|
|
27
25
|
/**
|
|
28
|
-
* Auto close time (
|
|
26
|
+
* Auto close time (milliseconds), 0 means no auto close
|
|
29
27
|
* @default 4500
|
|
30
28
|
*/
|
|
31
29
|
duration?: number;
|
|
@@ -41,7 +39,7 @@ export type NoticeConfig = {
|
|
|
41
39
|
* Display position
|
|
42
40
|
* @default 'topRight'
|
|
43
41
|
*/
|
|
44
|
-
placement?:
|
|
42
|
+
placement?: PlacementType;
|
|
45
43
|
/**
|
|
46
44
|
* Whether to show progress bar
|
|
47
45
|
*/
|
|
@@ -64,15 +62,27 @@ export type NoticeConfig = {
|
|
|
64
62
|
*/
|
|
65
63
|
closable?: boolean;
|
|
66
64
|
};
|
|
65
|
+
export type NoticeClose = () => void;
|
|
66
|
+
export interface NoticeApi {
|
|
67
|
+
open: (config: string | NoticeConfig) => NoticeClose;
|
|
68
|
+
info: (config: string | NoticeConfig) => NoticeClose;
|
|
69
|
+
success: (config: string | NoticeConfig) => NoticeClose;
|
|
70
|
+
warning: (config: string | NoticeConfig) => NoticeClose;
|
|
71
|
+
error: (config: string | NoticeConfig) => NoticeClose;
|
|
72
|
+
destroy: (key: string | number) => void;
|
|
73
|
+
clear: (placement?: PlacementType) => void;
|
|
74
|
+
}
|
|
67
75
|
export type WrapperedNoticeConfig = NoticeConfig & {
|
|
68
76
|
status?: 'info' | 'success' | 'warning' | 'error';
|
|
69
77
|
};
|
|
70
78
|
export type NoticeType = WrapperedNoticeConfig & {
|
|
71
79
|
key: string | number;
|
|
80
|
+
placement: PlacementType;
|
|
81
|
+
timerGeneration: number;
|
|
72
82
|
};
|
|
73
83
|
export interface NoticeProps extends NoticeType {
|
|
74
84
|
/**
|
|
75
85
|
* Destroy component callback
|
|
76
86
|
*/
|
|
77
|
-
onDestroy?: (key: string | number) => void;
|
|
87
|
+
onDestroy?: (key: string | number, timerGeneration?: number) => void;
|
|
78
88
|
}
|
|
@@ -1,9 +1,9 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import { NoticeProps } from './interface';
|
|
2
|
+
import type { NoticeProps, PlacementType } from './interface';
|
|
3
3
|
import './style/index.less';
|
|
4
4
|
declare const NoticeList: ({ items, placement, onDestroy, }: {
|
|
5
5
|
items: NoticeProps[];
|
|
6
|
-
placement?:
|
|
7
|
-
onDestroy: (key: string | number) => void;
|
|
6
|
+
placement?: PlacementType | undefined;
|
|
7
|
+
onDestroy: (key: string | number, timerGeneration?: number) => void;
|
|
8
8
|
}) => React.JSX.Element | null;
|
|
9
9
|
export default NoticeList;
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
+
import type { NoticeApi } from './interface';
|
|
2
3
|
export declare function NoticeProvider({ children }: {
|
|
3
4
|
children: React.ReactNode;
|
|
4
5
|
}): React.JSX.Element;
|
|
5
|
-
export declare function useGlobalNotice():
|
|
6
|
+
export declare function useGlobalNotice(): NoticeApi;
|
|
@@ -35,7 +35,7 @@ __export(notice_provider_exports, {
|
|
|
35
35
|
module.exports = __toCommonJS(notice_provider_exports);
|
|
36
36
|
var import_react = __toESM(require("react"));
|
|
37
37
|
var import_use_notice = __toESM(require("./use-notice"));
|
|
38
|
-
var NoticeContext = (0, import_react.createContext)(
|
|
38
|
+
var NoticeContext = (0, import_react.createContext)(void 0);
|
|
39
39
|
function NoticeProvider({ children }) {
|
|
40
40
|
const { noticeApi, noticeHolders } = (0, import_use_notice.default)();
|
|
41
41
|
return /* @__PURE__ */ import_react.default.createElement(NoticeContext.Provider, { value: noticeApi }, noticeHolders, children);
|
|
@@ -66,16 +66,19 @@ var import_lucide_react = require("lucide-react");
|
|
|
66
66
|
var import_react = __toESM(require("react"));
|
|
67
67
|
var import_Progress = __toESM(require("../Progress"));
|
|
68
68
|
var import_useCountdown = __toESM(require("../hooks/useCountdown"));
|
|
69
|
+
var import_Button = __toESM(require("../Button"));
|
|
69
70
|
var icons = {
|
|
70
|
-
info: /* @__PURE__ */ import_react.default.createElement(import_lucide_react.Info, { size:
|
|
71
|
-
success: /* @__PURE__ */ import_react.default.createElement(import_lucide_react.CircleCheck, { size:
|
|
72
|
-
warning: /* @__PURE__ */ import_react.default.createElement(import_lucide_react.CircleAlert, { size:
|
|
73
|
-
error: /* @__PURE__ */ import_react.default.createElement(import_lucide_react.CircleX, { size:
|
|
71
|
+
info: /* @__PURE__ */ import_react.default.createElement(import_lucide_react.Info, { size: 22, fill: "currentColor", stroke: "#FFF", strokeWidth: 2 }),
|
|
72
|
+
success: /* @__PURE__ */ import_react.default.createElement(import_lucide_react.CircleCheck, { size: 22, fill: "currentColor", stroke: "#FFF", strokeWidth: 2 }),
|
|
73
|
+
warning: /* @__PURE__ */ import_react.default.createElement(import_lucide_react.CircleAlert, { size: 22, fill: "currentColor", stroke: "#FFF", strokeWidth: 2 }),
|
|
74
|
+
error: /* @__PURE__ */ import_react.default.createElement(import_lucide_react.CircleX, { size: 22, fill: "currentColor", stroke: "#FFF", strokeWidth: 2 })
|
|
74
75
|
};
|
|
75
76
|
var Notice = (props) => {
|
|
76
77
|
const _a = props, {
|
|
77
78
|
prefixCls = "yee-notice",
|
|
78
79
|
id: key,
|
|
80
|
+
timerGeneration,
|
|
81
|
+
placement,
|
|
79
82
|
status,
|
|
80
83
|
title,
|
|
81
84
|
content,
|
|
@@ -93,6 +96,8 @@ var Notice = (props) => {
|
|
|
93
96
|
} = _a, rest = __objRest(_a, [
|
|
94
97
|
"prefixCls",
|
|
95
98
|
"id",
|
|
99
|
+
"timerGeneration",
|
|
100
|
+
"placement",
|
|
96
101
|
"status",
|
|
97
102
|
"title",
|
|
98
103
|
"content",
|
|
@@ -108,52 +113,90 @@ var Notice = (props) => {
|
|
|
108
113
|
"onDestroy",
|
|
109
114
|
"data-testid"
|
|
110
115
|
]);
|
|
111
|
-
const
|
|
116
|
+
const isHoveredRef = import_react.default.useRef(false);
|
|
117
|
+
const { remaining, isPaused, onPause, onResume } = (0, import_useCountdown.default)({
|
|
112
118
|
duration,
|
|
119
|
+
resetKey: timerGeneration,
|
|
113
120
|
onComplete: () => {
|
|
114
|
-
onDestroy == null ? void 0 : onDestroy(key);
|
|
115
|
-
onClose == null ? void 0 : onClose();
|
|
121
|
+
onDestroy == null ? void 0 : onDestroy(key, timerGeneration);
|
|
116
122
|
}
|
|
117
123
|
});
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
124
|
+
import_react.default.useEffect(() => {
|
|
125
|
+
if (pauseOnHover && isHoveredRef.current && !isPaused) {
|
|
126
|
+
onPause();
|
|
127
|
+
} else if ((!pauseOnHover || !isHoveredRef.current) && isPaused) {
|
|
128
|
+
onResume();
|
|
129
|
+
}
|
|
130
|
+
}, [isPaused, onPause, onResume, pauseOnHover]);
|
|
131
|
+
const handleMouseEnter = () => {
|
|
132
|
+
isHoveredRef.current = true;
|
|
133
|
+
if (pauseOnHover) {
|
|
134
|
+
onPause();
|
|
135
|
+
}
|
|
136
|
+
};
|
|
137
|
+
const handleMouseLeave = () => {
|
|
138
|
+
isHoveredRef.current = false;
|
|
139
|
+
if (isPaused) {
|
|
140
|
+
onResume();
|
|
141
|
+
}
|
|
142
|
+
};
|
|
143
|
+
const handleClose = (event) => {
|
|
144
|
+
event.stopPropagation();
|
|
145
|
+
onDestroy == null ? void 0 : onDestroy(key, timerGeneration);
|
|
146
|
+
};
|
|
147
|
+
const handleKeyDown = (event) => {
|
|
148
|
+
if (!onClick || event.key !== "Enter" && event.key !== " ") {
|
|
149
|
+
return;
|
|
150
|
+
}
|
|
151
|
+
event.preventDefault();
|
|
152
|
+
onClick();
|
|
122
153
|
};
|
|
123
154
|
const renderIcon = () => {
|
|
124
155
|
if (!icon && !status) {
|
|
125
156
|
return null;
|
|
126
157
|
}
|
|
127
|
-
return /* @__PURE__ */ import_react.default.createElement("span", { className: `${prefixCls}-icon` }, icon ? icon : status ? icons[status] : null);
|
|
158
|
+
return /* @__PURE__ */ import_react.default.createElement("span", { "aria-hidden": "true", className: `${prefixCls}-icon` }, icon ? icon : status ? icons[status] : null);
|
|
128
159
|
};
|
|
129
160
|
const renderCloseButton = () => {
|
|
130
161
|
if (!closable) {
|
|
131
162
|
return null;
|
|
132
163
|
}
|
|
133
164
|
return /* @__PURE__ */ import_react.default.createElement(
|
|
134
|
-
|
|
165
|
+
import_Button.default,
|
|
135
166
|
{
|
|
167
|
+
variant: "text",
|
|
168
|
+
size: "small",
|
|
136
169
|
className: `${prefixCls}-close`,
|
|
137
170
|
onClick: handleClose,
|
|
138
|
-
|
|
139
|
-
"aria-
|
|
140
|
-
}
|
|
141
|
-
/* @__PURE__ */ import_react.default.createElement(import_lucide_react.X, { size: 14, strokeWidth: 2 })
|
|
171
|
+
"aria-label": "Close notice",
|
|
172
|
+
icon: /* @__PURE__ */ import_react.default.createElement(import_lucide_react.X, { "aria-hidden": "true", size: 14, strokeWidth: 2 })
|
|
173
|
+
}
|
|
142
174
|
);
|
|
143
175
|
};
|
|
176
|
+
const isAssertive = status === "error" || status === "warning";
|
|
144
177
|
return /* @__PURE__ */ import_react.default.createElement(
|
|
145
178
|
"div",
|
|
146
179
|
__spreadProps(__spreadValues({}, rest), {
|
|
180
|
+
"aria-atomic": "true",
|
|
181
|
+
"aria-live": isAssertive ? "assertive" : "polite",
|
|
182
|
+
role: onClick ? "button" : isAssertive ? "alert" : "status",
|
|
183
|
+
tabIndex: onClick ? 0 : void 0,
|
|
184
|
+
"data-placement": placement,
|
|
147
185
|
"data-testid": dataTestId,
|
|
148
186
|
className: (0, import_clsx.default)(
|
|
149
187
|
prefixCls,
|
|
150
|
-
{
|
|
188
|
+
{
|
|
189
|
+
[`${prefixCls}-${status}`]: status,
|
|
190
|
+
[`${prefixCls}-clickable`]: onClick,
|
|
191
|
+
[`${prefixCls}-closable`]: closable
|
|
192
|
+
},
|
|
151
193
|
className
|
|
152
194
|
),
|
|
153
195
|
style,
|
|
154
196
|
onClick,
|
|
155
|
-
|
|
156
|
-
|
|
197
|
+
onKeyDown: handleKeyDown,
|
|
198
|
+
onMouseEnter: handleMouseEnter,
|
|
199
|
+
onMouseLeave: handleMouseLeave
|
|
157
200
|
}),
|
|
158
201
|
/* @__PURE__ */ import_react.default.createElement("div", { className: `${prefixCls}-content-wrapper` }, renderIcon(), /* @__PURE__ */ import_react.default.createElement("div", { className: `${prefixCls}-content` }, title && /* @__PURE__ */ import_react.default.createElement("div", { className: `${prefixCls}-title` }, title), /* @__PURE__ */ import_react.default.createElement("div", { className: `${prefixCls}-description` }, content))),
|
|
159
202
|
showProgress && duration > 0 && remaining > 0 && /* @__PURE__ */ import_react.default.createElement(
|
|
@@ -12,7 +12,7 @@
|
|
|
12
12
|
background-color: var(--yee-notice-bg-color);
|
|
13
13
|
border-radius: var(--yee-notice-border-radius);
|
|
14
14
|
box-shadow: var(--yee-notice-box-shadow);
|
|
15
|
-
cursor:
|
|
15
|
+
cursor: default;
|
|
16
16
|
transition: all 0.3s ease;
|
|
17
17
|
border: var(--yee-notice-border-width) solid transparent;
|
|
18
18
|
overflow: hidden;
|
|
@@ -21,6 +21,18 @@
|
|
|
21
21
|
box-shadow: var(--yee-notice-box-shadow-hover);
|
|
22
22
|
}
|
|
23
23
|
|
|
24
|
+
&-clickable {
|
|
25
|
+
cursor: pointer;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
&-closable {
|
|
29
|
+
@{pls}-content-wrapper {
|
|
30
|
+
padding-right: calc(
|
|
31
|
+
var(--yee-notice-close-size) + var(--yee-notice-close-right)
|
|
32
|
+
);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
|
|
24
36
|
&-content-wrapper {
|
|
25
37
|
display: flex;
|
|
26
38
|
align-items: flex-start;
|
|
@@ -1,16 +1,7 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
|
-
import {
|
|
3
|
-
type PlacementType = 'topLeft' | 'topRight' | 'bottomLeft' | 'bottomRight' | 'top' | 'bottom';
|
|
2
|
+
import { NoticeApi } from './interface';
|
|
4
3
|
declare const useNotice: () => {
|
|
5
|
-
noticeApi:
|
|
6
|
-
open: (props: string | NoticeConfig) => void;
|
|
7
|
-
success: (props: string | NoticeConfig) => void;
|
|
8
|
-
error: (props: string | NoticeConfig) => void;
|
|
9
|
-
warning: (props: string | NoticeConfig) => void;
|
|
10
|
-
info: (props: string | NoticeConfig) => void;
|
|
11
|
-
destroy: (key: string | number) => void;
|
|
12
|
-
clear: (placement?: PlacementType) => void;
|
|
13
|
-
};
|
|
4
|
+
noticeApi: NoticeApi;
|
|
14
5
|
noticeHolders: React.ReactPortal[];
|
|
15
6
|
};
|
|
16
7
|
export default useNotice;
|