Skip to content
New issue

Have a question about this project? # for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “#”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? # to your account

[PLAY-255]-TS Conversion of Fixed Confirmation Toast #2007

Merged
merged 3 commits into from
Aug 26, 2022
Merged
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

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,80 @@
import React, { useEffect, useState } from "react";
import classnames from "classnames";

import { globalProps } from "../utilities/globalProps";

import Icon from "../pb_icon/_icon";
import Title from "../pb_title/_title";

const iconMap = {
success: "check",
error: "exclamation-triangle",
neutral: "info-circle",
tip: "info-circle",
};

type FixedConfirmationToastProps = {
className?: string;
closeable?: boolean;
data?: string;
horizontal?: "right" | "left" | "center";
id?: string;
multiLine?: boolean;
onClose?: () => void;
open?: boolean;
status?: "success" | "error" | "neutral" | "tip";
text: string;
vertical?: "top" | "bottom";
};

const FixedConfirmationToast = (props: FixedConfirmationToastProps) => {
const [showToast, toggleToast] = useState(true);
const {
className,
closeable = false,
horizontal,
multiLine = false,
onClose = () => {},
open = true,
status = "neutral",
text,
vertical,
} = props;
const css = classnames(
`pb_fixed_confirmation_toast_kit_${status}`,
{ _multi_line: multiLine },
{ [`positioned_toast ${vertical} ${horizontal}`]: vertical && horizontal },
globalProps(props),
className
);
const icon = iconMap[status];

useEffect(() => {
toggleToast(open);
}, [open]);

const handleClick = () => {
toggleToast(!closeable);
onClose();
};

return (
<>
{showToast && (
<div className={css} onClick={handleClick}>
{icon && <Icon className="pb_icon" fixedWidth icon={icon} />}
<Title
className="pb_fixed_confirmation_toast_text"
size={4}
text={text}
/>
{closeable && (
<Icon className="pb_icon" fixedWidth={false} icon="times" />
)}
</div>
)}
</>
);
};

export default FixedConfirmationToast;