-
-
Notifications
You must be signed in to change notification settings - Fork 67
/
toast.tsx
84 lines (80 loc) · 3.68 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
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
import * as ToastPrimitive from "@radix-ui/react-toast";
import { clsx } from "clsx";
import React from "react";
import { useMediaQuery } from "../hooks/use-media-query";
import Button from "./shared/button";
const Toast = () => {
const [open, setOpen] = React.useState(false);
const isMd = useMediaQuery("(min-width: 768px)");
return (
<ToastPrimitive.Provider swipeDirection={isMd ? "right" : "down"}>
<Button
onClick={() => {
if (open) {
setOpen(false);
setTimeout(() => {
setOpen(true);
}, 400);
} else {
setOpen(true);
}
}}
>
Click
</Button>
<ToastPrimitive.Root
open={open}
onOpenChange={setOpen}
className={clsx(
"z-50 fixed bottom-4 inset-x-4 w-auto md:top-4 md:right-4 md:left-auto md:bottom-auto md:w-full md:max-w-sm shadow-lg rounded-lg",
"bg-white dark:bg-gray-800",
"radix-state-open:animate-toast-slide-in-bottom md:radix-state-open:animate-toast-slide-in-right",
"radix-state-closed:animate-toast-hide",
"radix-swipe-direction-right:radix-swipe-end:animate-toast-swipe-out-x",
"radix-swipe-direction-right:translate-x-radix-toast-swipe-move-x",
"radix-swipe-direction-down:radix-swipe-end:animate-toast-swipe-out-y",
"radix-swipe-direction-down:translate-y-radix-toast-swipe-move-y",
"radix-swipe-cancel:translate-x-0 radix-swipe-cancel:duration-200 radix-swipe-cancel:ease-[ease]",
"focus:outline-none focus-visible:ring focus-visible:ring-purple-500 focus-visible:ring-opacity-75"
)}
>
<div className="flex">
<div className="w-0 flex-1 flex items-center pl-5 py-4">
<div className="w-full radix">
<ToastPrimitive.Title className="text-sm font-medium text-gray-900 dark:text-gray-100">
Pull Request Review
</ToastPrimitive.Title>
<ToastPrimitive.Description className="mt-1 text-sm text-gray-700 dark:text-gray-400">
Someone requested your review on{" "}
<span className="font-medium">repository/branch</span>
</ToastPrimitive.Description>
</div>
</div>
<div className="flex">
<div className="flex flex-col px-3 py-2 space-y-1">
<div className="h-0 flex-1 flex">
<ToastPrimitive.Action
altText="view now"
className="w-full border border-transparent rounded-lg px-3 py-2 flex items-center justify-center text-sm font-medium text-purple-600 dark:text-purple-500 hover:bg-gray-50 dark:hover:bg-gray-900 focus:z-10 focus:outline-none focus-visible:ring focus-visible:ring-purple-500 focus-visible:ring-opacity-75"
onClick={(e) => {
e.preventDefault();
window.open("https://github.com");
}}
>
Review
</ToastPrimitive.Action>
</div>
<div className="h-0 flex-1 flex">
<ToastPrimitive.Close className="w-full border border-transparent rounded-lg px-3 py-2 flex items-center justify-center text-sm font-medium text-gray-700 dark:text-gray-100 hover:bg-gray-50 dark:hover:bg-gray-900 focus:z-10 focus:outline-none focus-visible:ring focus-visible:ring-purple-500 focus-visible:ring-opacity-75">
Dismiss
</ToastPrimitive.Close>
</div>
</div>
</div>
</div>
</ToastPrimitive.Root>
<ToastPrimitive.Viewport />
</ToastPrimitive.Provider>
);
};
export { Toast };