Skip to content
Snippets Groups Projects
Commit eb60bf02 authored by Robbie Luijben's avatar Robbie Luijben
Browse files

Merge branch 'hotfix/add-missing-expire-callback' into 'main'

parents 2d0a224c f036395e
No related branches found
No related tags found
1 merge request!46feat: onExpire callback for alerts, to do state changes
Pipeline #78611 passed
...@@ -10,6 +10,7 @@ type AlertProps = { ...@@ -10,6 +10,7 @@ type AlertProps = {
message: string; message: string;
alertType?: baseColorType; alertType?: baseColorType;
expireAfter?: number; expireAfter?: number;
onExpire?: () => void;
}; };
/** /**
...@@ -20,8 +21,9 @@ type AlertProps = { ...@@ -20,8 +21,9 @@ type AlertProps = {
* @param message: string * @param message: string
* @param alertType: "default" | "warning" | "positive" | "negative" * @param alertType: "default" | "warning" | "positive" | "negative"
* @param expireAfter: number * @param expireAfter: number
* @param onExpire: () => void
*/ */
const Alert = ({ title, message, alertType = "primary", expireAfter }: AlertProps) => { const Alert = ({ title, message, alertType = "primary", expireAfter, onExpire }: AlertProps) => {
const [hasExpired, setHasExpired] = useState(false); const [hasExpired, setHasExpired] = useState(false);
const [shouldRemoveElement, setShouldRemoveElement] = useState(false); const [shouldRemoveElement, setShouldRemoveElement] = useState(false);
...@@ -36,6 +38,7 @@ const Alert = ({ title, message, alertType = "primary", expireAfter }: AlertProp ...@@ -36,6 +38,7 @@ const Alert = ({ title, message, alertType = "primary", expireAfter }: AlertProp
setHasExpired(true); setHasExpired(true);
setTimeout(() => { setTimeout(() => {
setShouldRemoveElement(true); setShouldRemoveElement(true);
onExpire && onExpire();
}, 1000); }, 1000);
}, expireAfter); }, expireAfter);
} }
......
...@@ -26,5 +26,6 @@ export const Toast: StoryObj = { ...@@ -26,5 +26,6 @@ export const Toast: StoryObj = {
title: "I will fade away in 5 seconds", title: "I will fade away in 5 seconds",
message: "Bye bye", message: "Bye bye",
expireAfter: 5000, expireAfter: 5000,
onExpire: () => console.log("Alert expired, do some state changes now"),
} }
} }
\ No newline at end of file
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Please register or to comment