Skip to content

Commit

Permalink
Add renderToast option to Toatser
Browse files Browse the repository at this point in the history
- Allows you to replace default toast with custom component (Closes #13)
  • Loading branch information
timolins committed Mar 21, 2021
1 parent 641369f commit 207bf66
Showing 1 changed file with 8 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/components/toaster.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ import CSS from 'csstype';

import { useToaster } from '../core/use-toaster';
import { ToastBar } from './toast-bar';
import { ToastPosition, DefaultToastOptions } from '../core/types';
import { ToastPosition, DefaultToastOptions, Toast } from '../core/types';
import { createRectRef } from '../core/utils';

setup(React.createElement);
Expand Down Expand Up @@ -45,13 +45,15 @@ interface ToasterProps {
containerStyle?: CSS.Properties;

toastOptions?: DefaultToastOptions;
renderToast?: (toast: Toast) => JSX.Element;
}

export const Toaster: React.FC<ToasterProps> = ({
reverseOrder,
position = 'top-center',
containerStyle,
toastOptions,
renderToast,
}) => {
const { toasts, handlers } = useToaster(toastOptions);

Expand Down Expand Up @@ -91,7 +93,11 @@ export const Toaster: React.FC<ToasterProps> = ({
...positionStyle,
}}
>
<ToastBar toast={t} position={position} />
{renderToast ? (
renderToast(t)
) : (
<ToastBar toast={t} position={position} />
)}
</div>
);
})}
Expand Down

0 comments on commit 207bf66

Please sign in to comment.