import { HiOutlineInformationCircle, HiOutlineCheckCircle, HiOutlineExclamation, HiOutlineShieldExclamation, } from 'react-icons/hi'; import { ToastContainer, toast as reactToast, ToastOptions, } from 'react-toastify'; import styled, { useTheme } from 'styled-components'; import { Colors } from '../../hooks/theme'; import { Badge } from '../Badge'; import { Button } from '../Button'; import { Flex } from '../Flex'; export const StyledToastContainer = styled(ToastContainer)` .Toastify__toast-container { z-index: 9999; } .Toastify__toast { background-color: ${({ theme }) => theme.colors.cardBackground}; } .Toastify__toast-icon { display: none; } .Toastify__close-button { color: ${({ theme }) => theme.colors.gray[11]}; } .Toastify__progress-bar { height: 4px; } .Toastify__progress-bar--info { background-color: ${({ theme }) => theme.colors.blue[11]}; } .Toastify__progress-bar--success { background-color: ${({ theme }) => theme.colors.green[11]}; } .Toastify__progress-bar--warning { background-color: ${({ theme }) => theme.colors.amber[11]}; } .Toastify__progress-bar--error { background-color: ${({ theme }) => theme.colors.red[11]}; } `; const ToastTitle = styled.strong` font-size: 16px; font-weight: 600; color: ${({ theme }) => theme.colors.gray[12]}; `; const ToastText = styled.p` font-size: 14px; font-weight: 400; color: ${({ theme }) => theme.colors.gray[11]}; `; type Action = { label: string; action: string; backend: boolean; }; type CustomToastData = { title: string; message: string; type: 'INFO' | 'SUCCESS' | 'WARNING' | 'ERROR'; timeout: number; urgent: boolean; actions: Action[]; }; type Type = 'info' | 'success' | 'warning' | 'danger'; type RenderIconTitleAndTextProps = { type: Type; title: string; text: string; urgent?: boolean; actions?: Action[]; }; function RenderIconTitleAndText({ type, title, text, urgent, actions, }: RenderIconTitleAndTextProps): JSX.Element { const theme = useTheme(); function buttonColorScheme(): Colors { if (urgent) { return 'gray'; } if (type === 'success') { return 'green'; } if (type === 'warning') { return 'amber'; } if (type === 'danger') { return 'red'; } return 'blue'; } return ( {urgent ? ( urgente ) : ( <> {type === 'info' && ( )} {type === 'success' && ( )} {type === 'warning' && ( )} {type === 'danger' && ( )} )} {title} {text} {!!actions?.length && ( {actions?.map((action) => ( ))} )} ); } type ToastData = { title: string; text: string; options?: ToastOptions; }; export const toast = { info({ title, text, options }: ToastData): void { reactToast.info( , options, ); }, success({ title, text, options }: ToastData): void { reactToast.success( , options, ); }, warning({ title, text, options }: ToastData): void { reactToast.warning( , options, ); }, danger({ title, text, options }: ToastData): void { reactToast.error( , options, ); }, custom(data: CustomToastData): void { reactToast( , { type: data.type.toLowerCase() as any, autoClose: data.timeout === 0 ? false : data.timeout, }, ); }, };