diff --git a/src/components/toast.tsx b/src/components/toast.tsx index 8a0d50f..caf4cc1 100644 --- a/src/components/toast.tsx +++ b/src/components/toast.tsx @@ -1,6 +1,7 @@ import styled from '@emotion/styled'; import React, { CSSProperties, HTMLAttributes } from 'react'; import { ReactChildren } from '../core/types'; +import { keyframes } from '@emotion/react'; interface ToastViewportProps { position: 'left' | 'center' | 'right'; @@ -51,6 +52,7 @@ function calculatePosition( } interface ToastProps { + visible?: boolean; collapsed?: string; idx?: number; style?: CSSProperties; @@ -58,6 +60,14 @@ interface ToastProps { children: ReactChildren; } +const fadeOut = keyframes` + 0% { opacity: 1; } + 100% { opacity: 0; } +`; +const fadeIn = keyframes` + 0% { opacity: 0; } + 100% { opacity: 1; } +`; const StyledToast = styled('li')` display: flex; position: relative; @@ -71,19 +81,29 @@ const StyledToast = styled('li')` line-height: 1.3; padding: 16px; margin-bottom: 8px; + animation: ${(props: ToastProps) => (props.visible ? fadeIn : fadeOut)} 0.4s + forwards cubic-bezier(0.06, 0.71, 0.55, 1); `; const Toast: React.FC = (props) => { - const { collapsed, idx, style = {}, children, className = '' } = props; + const { + collapsed, + idx, + style = {}, + children, + className = '', + visible, + } = props; const animationStyle = calculateAnimationStyle(idx!, collapsed!); return ( {children} diff --git a/src/components/toaster.tsx b/src/components/toaster.tsx index 9259970..a15330a 100644 --- a/src/components/toaster.tsx +++ b/src/components/toaster.tsx @@ -41,12 +41,16 @@ export const Toaster: React.FC = (props) => { className={viewportClassName} > {toasts.map( - ({ id, title, description, type, icon, style, className }, index) => ( + ( + { id, title, description, type, icon, visible, style, className }, + index + ) => (