|
| 1 | +import * as ToastPrimitive from "@radix-ui/react-toast"; |
| 2 | +import cx from "~/utilities/classnames"; |
| 3 | +import React from "react"; |
| 4 | +import { Body } from "../Primitives/Body"; |
| 5 | +import { Title } from "../Primitives/Title"; |
| 6 | + |
| 7 | +type Props = {}; |
| 8 | + |
| 9 | +const Toast = (props: Props) => { |
| 10 | + const [open, setOpen] = React.useState(false); |
| 11 | + |
| 12 | + return ( |
| 13 | + <ToastPrimitive.Provider> |
| 14 | + <button |
| 15 | + onClick={() => { |
| 16 | + if (open) { |
| 17 | + setOpen(false); |
| 18 | + setTimeout(() => { |
| 19 | + setOpen(true); |
| 20 | + }, 500); |
| 21 | + } else { |
| 22 | + setOpen(true); |
| 23 | + } |
| 24 | + }} |
| 25 | + > |
| 26 | + Click |
| 27 | + </button> |
| 28 | + <ToastPrimitive.Root |
| 29 | + open={open} |
| 30 | + onOpenChange={setOpen} |
| 31 | + className={cx( |
| 32 | + "z-50 fixed bottom-4 inset-x-4 w-auto md:top-4 md:right-2 md:left-auto md:bottom-auto md:w-full md:max-w-sm shadow-lg rounded-md", |
| 33 | + "bg-slate-100 dark:bg-slate-900 border-[1px] border-slate-200 dark:border-black", |
| 34 | + "radix-state-open:animate-toast-slide-in-bottom md:radix-state-open:animate-toast-slide-in-right", |
| 35 | + "radix-state-closed:animate-toast-hide", |
| 36 | + "radix-swipe-end:animate-toast-swipe-out", |
| 37 | + "translate-x-radix-toast-swipe-move-x", |
| 38 | + "radix-swipe-cancel:translate-x-0 radix-swipe-cancel:duration-200 radix-swipe-cancel:ease-[ease]", |
| 39 | + "focus:outline-none focus-visible:ring focus-visible:ring-indigo-500 focus-visible:ring-opacity-75" |
| 40 | + )} |
| 41 | + > |
| 42 | + <div className="flex"> |
| 43 | + <div className="w-0 flex-1 flex items-center pl-5 py-4"> |
| 44 | + <div className="w-full radix"> |
| 45 | + <Title className="dark:text-slate-200">Invalid JSON</Title> |
| 46 | + <Body className="mt-0.5 dark:text-slate-400"> |
| 47 | + Check your JSON is valid and try again. |
| 48 | + </Body> |
| 49 | + </div> |
| 50 | + </div> |
| 51 | + <div className="flex"> |
| 52 | + <div className="flex flex-col pl-3 pr-2 py-2 space-y-1"> |
| 53 | + <div className="h-0 flex-1 flex items-center"> |
| 54 | + <ToastPrimitive.Action |
| 55 | + altText="close" |
| 56 | + className="w-full max-h-10 border border-transparent rounded-sm px-3 py-2 flex items-center justify-center text-md font-medium text-white bg-indigo-600 hover:bg-indigo-600/90 focus:z-10 focus:outline-none focus-visible:ring focus-visible:ring-indigo-500 focus-visible:ring-opacity-75" |
| 57 | + onClick={(e) => { |
| 58 | + e.preventDefault(); |
| 59 | + window.open("https://github.com"); |
| 60 | + }} |
| 61 | + > |
| 62 | + Primary |
| 63 | + </ToastPrimitive.Action> |
| 64 | + </div> |
| 65 | + <div className="h-0 flex-1 flex"> |
| 66 | + <ToastPrimitive.Close className="w-full max-h-10 border border-transparent rounded-sm px-3 py-2 flex items-center justify-center text-md font-medium text-slate-700 dark:text-slate-100 bg-slate-300 hover:bg-slate-300/80 dark:bg-slate-700 hover:dark:bg-slate-700/80 dark:hover:bg-slate-900 focus:z-10 focus:outline-none focus-visible:ring focus-visible:ring-indigo-500 focus-visible:ring-opacity-75"> |
| 67 | + Secondary |
| 68 | + </ToastPrimitive.Close> |
| 69 | + </div> |
| 70 | + </div> |
| 71 | + </div> |
| 72 | + </div> |
| 73 | + </ToastPrimitive.Root> |
| 74 | + |
| 75 | + <ToastPrimitive.Viewport /> |
| 76 | + </ToastPrimitive.Provider> |
| 77 | + ); |
| 78 | +}; |
| 79 | + |
| 80 | +export default Toast; |
0 commit comments