From add117efd2b0c84c3ac3554f3b3b5777668b8e3b Mon Sep 17 00:00:00 2001 From: Pavel Klibani Date: Thu, 16 May 2024 16:04:15 +0200 Subject: [PATCH] Feat(web-twig): Add autoclose feature to Toast component --- .../assets/scripts/toast-dynamic.ts | 8 +++--- .../Toast/stories/ToastDynamicToastQueue.twig | 26 +++++++++++++++++++ 2 files changed, 31 insertions(+), 3 deletions(-) diff --git a/apps/web-twig-demo/assets/scripts/toast-dynamic.ts b/apps/web-twig-demo/assets/scripts/toast-dynamic.ts index 1bc1f984bb..27de520d49 100644 --- a/apps/web-twig-demo/assets/scripts/toast-dynamic.ts +++ b/apps/web-twig-demo/assets/scripts/toast-dynamic.ts @@ -3,9 +3,11 @@ import { Toast } from '@lmc-eu/spirit-web/src/js/index.esm'; const addDynamicToast = (event, containerId) => { const formElement = event.target.closest('form'); const config = { + autoCloseInterval: formElement.querySelector('#toast-auto-close-interval').value, color: formElement.querySelector('#toast-color').value, containerId, content: formElement.querySelector('#toast-content').value, + enableAutoClose: formElement.querySelector('#toast-enable-auto-close').checked, hasIcon: formElement.querySelector('#toast-has-icon').checked, id: `my-dynamic-toast-${Date.now()}`, isDismissible: formElement.querySelector('#toast-is-dismissible').checked, @@ -27,7 +29,7 @@ export const clearQueue = (event, containerId) => { if (instance instanceof Toast && instance?.isShown) { instance?.hide(); - cleared++; + cleared += 1; } }); @@ -39,7 +41,7 @@ export const clearQueue = (event, containerId) => { }; // Make functions available in the global scope -window.addDynamicToast = addDynamicToast; -window.clearQueue = clearQueue; +(window as any).addDynamicToast = addDynamicToast; +(window as any).clearQueue = clearQueue; export default addDynamicToast; diff --git a/packages/web-twig/src/Resources/components/Toast/stories/ToastDynamicToastQueue.twig b/packages/web-twig/src/Resources/components/Toast/stories/ToastDynamicToastQueue.twig index 886485d01b..b231a84a12 100644 --- a/packages/web-twig/src/Resources/components/Toast/stories/ToastDynamicToastQueue.twig +++ b/packages/web-twig/src/Resources/components/Toast/stories/ToastDynamicToastQueue.twig @@ -21,6 +21,20 @@ }; + + +
@@ -58,6 +72,18 @@ + +