From fdc5f3707555a70ec76adae805896186af696a01 Mon Sep 17 00:00:00 2001 From: Pavel Klibani Date: Tue, 21 May 2024 10:47:32 +0200 Subject: [PATCH] fixup! fixup! Feat(web-react): Add autoclose feature to Toast component --- .../Toast/stories/ToastBar.stories.tsx | 3 +++ .../stories/UncontrolledToast.stories.tsx | 18 ++++++++++++++++++ .../src/components/Toast/withAutoClose.ts | 8 ++++++++ 3 files changed, 29 insertions(+) create mode 100644 packages/web-react/src/components/Toast/withAutoClose.ts diff --git a/packages/web-react/src/components/Toast/stories/ToastBar.stories.tsx b/packages/web-react/src/components/Toast/stories/ToastBar.stories.tsx index 35eeb86ffb..da2037b218 100644 --- a/packages/web-react/src/components/Toast/stories/ToastBar.stories.tsx +++ b/packages/web-react/src/components/Toast/stories/ToastBar.stories.tsx @@ -20,6 +20,9 @@ const meta: Meta = { }, closeLabel: { control: 'text', + table: { + defaultValue: { summary: 'Close' }, + }, }, color: { control: 'select', diff --git a/packages/web-react/src/components/Toast/stories/UncontrolledToast.stories.tsx b/packages/web-react/src/components/Toast/stories/UncontrolledToast.stories.tsx index 5f2a1843a0..f33b35eb7d 100644 --- a/packages/web-react/src/components/Toast/stories/UncontrolledToast.stories.tsx +++ b/packages/web-react/src/components/Toast/stories/UncontrolledToast.stories.tsx @@ -40,12 +40,21 @@ const meta: Meta = { }, closeLabel: { control: 'text', + table: { + defaultValue: { summary: 'Close' }, + }, }, hasIcon: { control: 'boolean', + table: { + defaultValue: { summary: false }, + }, }, isDismissible: { control: 'boolean', + table: { + defaultValue: { summary: false }, + }, }, color: { control: 'select', @@ -59,12 +68,21 @@ const meta: Meta = { }, isCollapsible: { control: 'boolean', + table: { + defaultValue: { summary: true }, + }, }, enableAutoClose: { control: 'boolean', + table: { + defaultValue: { summary: true }, + }, }, autoCloseInterval: { control: 'number', + table: { + defaultValue: { summary: TOAST_AUTO_CLOSE_INTERVAL }, + }, }, }, args: { diff --git a/packages/web-react/src/components/Toast/withAutoClose.ts b/packages/web-react/src/components/Toast/withAutoClose.ts new file mode 100644 index 0000000000..d62cf0f86b --- /dev/null +++ b/packages/web-react/src/components/Toast/withAutoClose.ts @@ -0,0 +1,8 @@ +import { TOAST_AUTOCLOSE_TIMEOUT } from './constants'; + +export const withAutoclose = (callback: () => void, interval: number = TOAST_AUTOCLOSE_TIMEOUT) => { + const timeoutId = setTimeout(() => { + callback(); + clearTimeout(timeoutId); + }, interval); +};