Skip to content

Commit

Permalink
toast: add remove method to clear a single message (#4101)
Browse files Browse the repository at this point in the history
Co-authored-by: Clément Bernard <[email protected]>
  • Loading branch information
clemvnt and Clément Bernard authored Oct 5, 2023
1 parent 4bcb9bd commit cee9688
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 0 deletions.
5 changes: 5 additions & 0 deletions components/lib/toast/Toast.vue
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,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);
Expand All @@ -58,6 +59,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);
},
Expand Down Expand Up @@ -87,6 +89,9 @@ export default {
this.add(message);
}
},
onRemove(message) {
this.remove({ message, type: 'close' });
},
onRemoveGroup(group) {
if (this.group === group) {
this.messages = [];
Expand Down
5 changes: 5 additions & 0 deletions components/lib/toastservice/ToastService.d.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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.
Expand Down
3 changes: 3 additions & 0 deletions components/lib/toastservice/ToastService.js
Original file line number Diff line number Diff line change
Expand Up @@ -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);
},
Expand Down
13 changes: 13 additions & 0 deletions doc/common/apidoc/index.json
Original file line number Diff line number Diff line change
Expand Up @@ -49887,6 +49887,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": [
Expand Down

0 comments on commit cee9688

Please sign in to comment.