From 143e5c968a6e6d3a849625b3ea1ab54b6bb43563 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Cl=C3=A9ment=20Bernard?= Date: Mon, 3 Jul 2023 14:35:37 +0200 Subject: [PATCH] toast: add remove method to clear a single message --- components/lib/toast/Toast.vue | 5 +++++ components/lib/toastservice/ToastService.d.ts | 5 +++++ components/lib/toastservice/ToastService.js | 3 +++ doc/common/apidoc/index.json | 13 +++++++++++++ 4 files changed, 26 insertions(+) diff --git a/components/lib/toast/Toast.vue b/components/lib/toast/Toast.vue index 705a6ef8ff..88b9adf9e9 100755 --- a/components/lib/toast/Toast.vue +++ b/components/lib/toast/Toast.vue @@ -44,6 +44,7 @@ export default { styleElement: null, mounted() { ToastEventBus.on('add', this.onAdd); + ToastEventBus.on('remove', this.onRemove); ToastEventBus.on('remove-group', this.onRemoveGroup); ToastEventBus.on('remove-all-groups', this.onRemoveAllGroups); @@ -59,6 +60,7 @@ export default { } ToastEventBus.off('add', this.onAdd); + ToastEventBus.off('remove', this.onRemove); ToastEventBus.off('remove-group', this.onRemoveGroup); ToastEventBus.off('remove-all-groups', this.onRemoveAllGroups); }, @@ -88,6 +90,9 @@ export default { this.add(message); } }, + onRemove(message) { + this.remove({ message, type: 'close' }); + }, onRemoveGroup(group) { if (this.group === group) { this.messages = []; diff --git a/components/lib/toastservice/ToastService.d.ts b/components/lib/toastservice/ToastService.d.ts index a742fe4168..c1a1f3b41d 100755 --- a/components/lib/toastservice/ToastService.d.ts +++ b/components/lib/toastservice/ToastService.d.ts @@ -23,6 +23,11 @@ export interface ToastServiceMethods { * @param {ToastMessageOptions} message - Message instance. */ add(message: ToastMessageOptions): void; + /** + * Clears the message. + * @param {ToastMessageOptions} message - Message instance. + */ + remove(message: ToastMessageOptions): void; /** * Clears the messages that belongs to the group. * @param {string} group - Name of the message group. diff --git a/components/lib/toastservice/ToastService.js b/components/lib/toastservice/ToastService.js index 9890fd6d27..84cffc74e5 100755 --- a/components/lib/toastservice/ToastService.js +++ b/components/lib/toastservice/ToastService.js @@ -7,6 +7,9 @@ export default { add: (message) => { ToastEventBus.emit('add', message); }, + remove: (message) => { + ToastEventBus.emit('remove', message); + }, removeGroup: (group) => { ToastEventBus.emit('remove-group', group); }, diff --git a/doc/common/apidoc/index.json b/doc/common/apidoc/index.json index dd9b5fe63d..b4b1b1d75a 100644 --- a/doc/common/apidoc/index.json +++ b/doc/common/apidoc/index.json @@ -38170,6 +38170,19 @@ "returnType": "void", "description": "Displays the message in a suitable Toast component." }, + { + "name": "remove", + "parameters": [ + { + "name": "message", + "optional": false, + "type": "ToastMessageOptions", + "description": "Message instance." + } + ], + "returnType": "void", + "description": "Clears the message." + }, { "name": "removeGroup", "parameters": [