Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 15 additions & 6 deletions packages/react/src/Alert.js
Original file line number Diff line number Diff line change
Expand Up @@ -17,14 +17,17 @@ library.add(
faXmark
);

function Alert({ message, style }) {
function Alert({style, variant, message, autohide, delay}) {
const [showAlert, setShowAlert] = useState(true);

autohide && typeof autohide === "boolean" ? autohide : false;
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can also set default props for autohide and delay to be false and 5000 respectively.

autohide && delay && typeof delay === "number" ? delay : 5000;

const dismissAlert = () => setShowAlert(!showAlert);

let variantClass, icon, col;

switch (message.type) {
switch (variant) {
case "success":
variantClass = "alert-success";
icon = (
Expand Down Expand Up @@ -80,7 +83,11 @@ function Alert({ message, style }) {

return (
<ToastContainer position="bottom-center">
<Toast onClose={() => setShowAlert(false)} className={`alert ${variantClass}`} show={showAlert} delay={3000} autohide>
<Toast onClose={() => setShowAlert(false)}
className={`alert ${variantClass}`}
show={showAlert}
delay={delay}
autohide={autohide}>
<Toast.Body>
<Row className="no-gutters g-0">
<Col className="col-1 d-flex align-items-center justify-content-end">
Expand All @@ -100,11 +107,13 @@ function Alert({ message, style }) {
Alert.displayName = "St.Jude Cloud Alert";
Alert.propTypes = {
style: PropTypes.oneOf(["oneline", "multiplelines"]),
variant: PropTypes.oneOf(["success", "warning", "error", "info"]),
message: {
type: PropTypes.oneOf(["success", "warning", "error", "info"]),
title: PropTypes.string,
body: PropTypes.string
}
body: PropTypes.string,
},
autohide: PropTypes.bool,
delay: PropTypes.number,
}

export default Alert;
100 changes: 89 additions & 11 deletions packages/react/stories/Alert.stories.js
Original file line number Diff line number Diff line change
Expand Up @@ -6,14 +6,92 @@ export default {
component: Alert,
};

export const DefaultOneline = () => <Alert message={{ type: "info", title: "Notification Title", body: "Here is the information or diections"}} style="oneline" />;
export const SuccessOneline = () => <Alert message={{ type: "success", title: "I am a title", body: " i am the body"}} style="oneline"/>;
export const WarningOneLine = () => <Alert message={{ type: "warning", title: "I am a title", body: " i am the body"}} style="oneline"/>;
export const ErrorOneline = () => <Alert message={{ type: "error", title: "I am a title", body: " i am the body"}} style="oneline"/>;
export const ExtraLongMessageOneLine = () => <Alert message={{ type: "error", title: "My name is Giovanni Giorgio", body: "but everybody calls me Giorgio"}} style="oneline"/>;

export const DefaultMultiplelines = () => <Alert message={{ type: "info", title: "Notification Title", body: "Here is the information or diections" }} style="multiplelines"/>;
export const SuccessMultiplelines = () => <Alert message={{ type: "success", title: "I am a title", body: " i am the body" }} style="multiplelines"/>;
export const WarningMultiplelines = () => <Alert message={{ type: "warning", title: "I am a title", body: " i am the body" }} style="multiplelines"/>;
export const ErrorMultiplelines = () => <Alert message={{ type: "error", title: "I am a title", body: " i am the body" }} style="multiplelines"/>;
export const ExtraLongMessageMultiplelines = () => <Alert message={{ type: "error", title: "My name is Giovanni Giorgio", body: "but everybody calls me Giorgio." }} style="multiplelines"/>;
export const DefaultOneline = () =>
<Alert
message={{ title: "Do you know?", body: "My cat can backflip"}}
style="oneline"
autohide={false}
delay={5000}
variant="info"
/>;

export const SuccessOneline = () =>
<Alert
message={{ title: "I am a title", body: " i am the body" }}
style="oneline"
autohide={true}
delay={6000}
variant="success"
/>;

export const WarningOneLine = () =>
<Alert
message={{title: "Warning", body: "Hungry kitten is approaching"}}
style="oneline"
autohide={false}
delay={5000}
variant="warning"
/>;

export const ErrorOneline = () =>
<Alert
message={{ type: "error", title: "My Cat is", body: "Broken"}}
style="oneline"
autohide={true}
delay={5000}
variant="error"
/>;

export const ExtraLongMessageOneLine = () =>
<Alert
message={{title: "My name is Giovanni Giorgio", body: "but everybody calls me Giorgio, Giorgio"}}
style="oneline"
autohide={true}
delay={5000}
variant="error"
/>;

export const DefaultMultiplelines = () =>
<Alert
message={{title: "Warning", body: "Hungry kitten is approaching"}}
style="multiplelines"
autohide={true}
delay={5000}
variant="info"
/>;

export const SuccessMultiplelines = () =>
<Alert
message={{title: "I am a title", body: " i am the body" }}
style="multiplelines"
autohide={false}
delay={5000}
variant="success"
/>;

export const WarningMultiplelines = () =>
<Alert
message={{title: "I am a title", body: " i am the body" }}
style="multiplelines"
autohide={false}
delay={5000}
variant="warning"
/>;

export const ErrorMultiplelines = () =>
<Alert
message={{title: "I am a title", body: " i am the body" }}
style="multiplelines"
variant="error"
autohide={true}
delay={2000}
/>;

export const ExtraLongMessageMultiplelines = () =>
<Alert
message={{title: "My name is Giovanni Giorgio", body: "but everybody calls me Giorgio." }}
style="multiplelines"
autohide={true}
delay={5000}
variant="error"
/>;