PromucFlow_constructor/app/client/src/components/editorComponents/ToastComponent.tsx

53 lines
1.4 KiB
TypeScript
Raw Normal View History

2020-02-18 10:41:52 +00:00
import React from "react";
import { toast, ToastOptions, TypeOptions, ToastType } from "react-toastify";
import "react-toastify/dist/ReactToastify.css";
import styled from "styled-components";
import { theme } from "constants/DefaultTheme";
import { AlertIcons } from "icons/AlertIcons";
2019-10-07 12:29:38 +00:00
2020-02-18 10:41:52 +00:00
const ToastBody = styled.div<{ type: TypeOptions }>`
height: 100%;
border-left: 4px solid ${({ type }) => theme.alert[type].color};
border-radius: 4px;
background-color: white;
color: black;
display: flex;
align-items: center;
padding-left: 5px;
`;
const ToastMessage = styled.span`
2020-02-21 12:16:49 +00:00
font-size: ${props => props.theme.fontSizes[2]}px;
2020-02-18 10:41:52 +00:00
margin: 0 5px;
`;
const ToastIcon = {
info: AlertIcons.INFO,
success: AlertIcons.SUCCESS,
error: AlertIcons.ERROR,
warning: AlertIcons.WARNING,
default: AlertIcons.INFO,
};
type Props = ToastOptions & { message: string; closeToast?: () => void };
const ToastComponent = (props: Props) => {
const alertType = props.type || ToastType.INFO;
const Icon = ToastIcon[alertType];
return (
<ToastBody type={alertType}>
<Icon color={theme.alert[alertType].color} width={20} height={20} />
<ToastMessage>{props.message}</ToastMessage>
</ToastBody>
);
};
const Toaster = {
show: (config: ToastOptions & { message: string }) => {
toast(<ToastComponent {...config} />);
},
clear: () => toast.dismiss(),
};
export const AppToaster = Toaster;