Skip to content

Commit

Permalink
fixup! fixup! Feat(web-react): Add autoclose feature to Toast component
Browse files Browse the repository at this point in the history
  • Loading branch information
pavelklibani committed May 21, 2024
1 parent 754bdcd commit fdc5f37
Show file tree
Hide file tree
Showing 3 changed files with 29 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,9 @@ const meta: Meta<typeof ToastBar> = {
},
closeLabel: {
control: 'text',
table: {
defaultValue: { summary: 'Close' },
},
},
color: {
control: 'select',
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -40,12 +40,21 @@ const meta: Meta<UncontrolledToastPlaygroundProps> = {
},
closeLabel: {
control: 'text',
table: {
defaultValue: { summary: 'Close' },
},
},
hasIcon: {
control: 'boolean',
table: {
defaultValue: { summary: false },
},
},
isDismissible: {
control: 'boolean',
table: {
defaultValue: { summary: false },
},
},
color: {
control: 'select',
Expand All @@ -59,12 +68,21 @@ const meta: Meta<UncontrolledToastPlaygroundProps> = {
},
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: {
Expand Down
8 changes: 8 additions & 0 deletions packages/web-react/src/components/Toast/withAutoClose.ts
Original file line number Diff line number Diff line change
@@ -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);
};

0 comments on commit fdc5f37

Please sign in to comment.