A very performant and light (2mb in memory) link shortener and tracker. Written in Rust and React and uses Postgres/SQLite.
at master 4.8 kB view raw
1"use client" 2 3import * as React from "react" 4import * as ToastPrimitives from "@radix-ui/react-toast" 5import { cva, type VariantProps } from "class-variance-authority" 6import { X } from "lucide-react" 7 8import { cn } from "@/lib/utils" 9 10const ToastProvider = ToastPrimitives.Provider 11 12const ToastViewport = React.forwardRef< 13 React.ElementRef<typeof ToastPrimitives.Viewport>, 14 React.ComponentPropsWithoutRef<typeof ToastPrimitives.Viewport> 15>(({ className, ...props }, ref) => ( 16 <ToastPrimitives.Viewport 17 ref={ref} 18 className={cn( 19 "fixed top-0 z-100 flex max-h-screen w-full flex-col-reverse p-4 sm:bottom-0 sm:right-0 sm:top-auto sm:flex-col md:max-w-[420px]", 20 className 21 )} 22 {...props} 23 /> 24)) 25ToastViewport.displayName = ToastPrimitives.Viewport.displayName 26 27const toastVariants = cva( 28 "group pointer-events-auto relative flex w-full items-center justify-between space-x-2 overflow-hidden rounded-md border p-4 pr-6 shadow-lg transition-all data-[swipe=cancel]:translate-x-0 data-[swipe=end]:translate-x-[var(--radix-toast-swipe-end-x)] data-[swipe=move]:translate-x-[var(--radix-toast-swipe-move-x)] data-[swipe=move]:transition-none data-[state=open]:animate-in data-[state=closed]:animate-out data-[swipe=end]:animate-out data-[state=closed]:fade-out-80 data-[state=closed]:slide-out-to-right-full data-[state=open]:slide-in-from-top-full data-[state=open]:sm:slide-in-from-bottom-full", 29 { 30 variants: { 31 variant: { 32 default: "border bg-background text-foreground", 33 destructive: 34 "destructive group border-destructive bg-destructive text-destructive-foreground", 35 }, 36 }, 37 defaultVariants: { 38 variant: "default", 39 }, 40 } 41) 42 43const Toast = React.forwardRef< 44 React.ElementRef<typeof ToastPrimitives.Root>, 45 React.ComponentPropsWithoutRef<typeof ToastPrimitives.Root> & 46 VariantProps<typeof toastVariants> 47>(({ className, variant, ...props }, ref) => { 48 return ( 49 <ToastPrimitives.Root 50 ref={ref} 51 className={cn(toastVariants({ variant }), className)} 52 {...props} 53 /> 54 ) 55}) 56Toast.displayName = ToastPrimitives.Root.displayName 57 58const ToastAction = React.forwardRef< 59 React.ElementRef<typeof ToastPrimitives.Action>, 60 React.ComponentPropsWithoutRef<typeof ToastPrimitives.Action> 61>(({ className, ...props }, ref) => ( 62 <ToastPrimitives.Action 63 ref={ref} 64 className={cn( 65 "inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium transition-colors hover:bg-secondary focus:outline-hidden focus:ring-1 focus:ring-ring disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 hover:group-[.destructive]:border-destructive/30 hover:group-[.destructive]:bg-destructive hover:group-[.destructive]:text-destructive-foreground focus:group-[.destructive]:ring-destructive", 66 className 67 )} 68 {...props} 69 /> 70)) 71ToastAction.displayName = ToastPrimitives.Action.displayName 72 73const ToastClose = React.forwardRef< 74 React.ElementRef<typeof ToastPrimitives.Close>, 75 React.ComponentPropsWithoutRef<typeof ToastPrimitives.Close> 76>(({ className, ...props }, ref) => ( 77 <ToastPrimitives.Close 78 ref={ref} 79 className={cn( 80 "absolute right-1 top-1 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-hidden focus:ring-1 group-hover:opacity-100 group-[.destructive]:text-red-300 hover:group-[.destructive]:text-red-50 focus:group-[.destructive]:ring-red-400 focus:group-[.destructive]:ring-offset-red-600", 81 className 82 )} 83 toast-close="" 84 {...props} 85 > 86 <X className="h-4 w-4" /> 87 </ToastPrimitives.Close> 88)) 89ToastClose.displayName = ToastPrimitives.Close.displayName 90 91const ToastTitle = React.forwardRef< 92 React.ElementRef<typeof ToastPrimitives.Title>, 93 React.ComponentPropsWithoutRef<typeof ToastPrimitives.Title> 94>(({ className, ...props }, ref) => ( 95 <ToastPrimitives.Title 96 ref={ref} 97 className={cn("text-sm font-semibold [&+div]:text-xs", className)} 98 {...props} 99 /> 100)) 101ToastTitle.displayName = ToastPrimitives.Title.displayName 102 103const ToastDescription = React.forwardRef< 104 React.ElementRef<typeof ToastPrimitives.Description>, 105 React.ComponentPropsWithoutRef<typeof ToastPrimitives.Description> 106>(({ className, ...props }, ref) => ( 107 <ToastPrimitives.Description 108 ref={ref} 109 className={cn("text-sm opacity-90", className)} 110 {...props} 111 /> 112)) 113ToastDescription.displayName = ToastPrimitives.Description.displayName 114 115type ToastProps = React.ComponentPropsWithoutRef<typeof Toast> 116 117type ToastActionElement = React.ReactElement<typeof ToastAction> 118 119export { 120 type ToastProps, 121 type ToastActionElement, 122 ToastProvider, 123 ToastViewport, 124 Toast, 125 ToastTitle, 126 ToastDescription, 127 ToastClose, 128 ToastAction, 129}