Skip to content

Build your own AI office with Univer Office SDK. Bring editing, calculation, collaboration, and file processing into your product for people and AI agents. Built on an extensible open-source core.

feat(ui): not auto removing when duration is 0 (#2366)

Wenzhao Hua98e8abd6675
diff --git a/packages/design/src/components/message/Message.tsx b/packages/design/src/components/message/Message.tsx
index 08cde6ce76..c740736d18 100644
--- a/packages/design/src/components/message/Message.tsx
+++ b/packages/design/src/components/message/Message.tsx
@@ -44,6 +44,11 @@ export interface IMessageProps {
export interface IMessageOptions extends
Partial<Pick<IMessageProps, 'key' | 'type' >>,
Pick<IMessageProps, 'content'> {
+
+ /**
+ * After `duration` milliseconds, the message would be removed automatically. However, if `duration` is set to 0,
+ * the message would not be removed automatically.
+ */
duration?: number;
}
@@ -117,7 +122,10 @@ export class Message {
this.render();
- setTimeout(() => this.teardown(key), duration);
+ if (duration !== 0) {
+ setTimeout(() => this.teardown(key), duration);
+ }
+
return { dispose: () => this.teardown(key) };
}
diff --git a/packages/ui/src/services/message/desktop-message.service.ts b/packages/ui/src/services/message/desktop-message.service.ts
index 2a51c0a569..55617de908 100644
--- a/packages/ui/src/services/message/desktop-message.service.ts
+++ b/packages/ui/src/services/message/desktop-message.service.ts
@@ -21,20 +21,20 @@ import type { IDisposable } from '@wendellhu/redi';
import type { IMessageService } from './message.service';
export class DesktopMessageService implements IMessageService {
- portalContainer: HTMLElement = document.body;
- message?: Message;
+ protected _portalContainer: HTMLElement = document.body;
+ protected _message?: Message;
setContainer(container: HTMLElement): void {
- this.portalContainer = container;
- this.message = new Message(container);
+ this._portalContainer = container;
+ this._message = new Message(container);
}
show(options: IMessageOptions & Omit<IMessageProps, 'key'>): IDisposable {
- if (!this.message) {
+ if (!this._message) {
throw new Error('[DesktopMessageService]: no message implementation!');
}
const { type, ...rest } = options;
- return this.message[type](rest);
+ return this._message[type](rest);
}
}