-
Notifications
You must be signed in to change notification settings - Fork 4.1k
/
Copy pathtoast.tsx
44 lines (38 loc) · 1.15 KB
/
toast.tsx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
'use client';
import React, { ReactNode } from 'react';
import { toast as sonnerToast } from 'sonner';
import { CheckCircleFillIcon, WarningIcon } from './icons';
const iconsByType: Record<'success' | 'error', ReactNode> = {
success: <CheckCircleFillIcon />,
error: <WarningIcon />,
};
export function toast(props: Omit<ToastProps, 'id'>) {
return sonnerToast.custom((id) => (
<Toast id={id} type={props.type} description={props.description} />
));
}
function Toast(props: ToastProps) {
const { id, type, description } = props;
return (
<div className="flex w-full toast-mobile:w-[356px] justify-center">
<div
data-testid="toast"
key={id}
className="bg-zinc-100 p-3 rounded-lg w-full toast-mobile:w-fit flex flex-row gap-2 items-center"
>
<div
data-type={type}
className="data-[type=error]:text-red-600 data-[type=success]:text-green-600"
>
{iconsByType[type]}
</div>
<div className="text-zinc-950 text-sm">{description}</div>
</div>
</div>
);
}
interface ToastProps {
id: string | number;
type: 'success' | 'error';
description: string;
}