1
- "use client"
1
+ "use client" ;
2
2
3
- import * as React from "react"
4
- import * as ToastPrimitives from "@radix-ui/react-toast"
5
- import { cva , type VariantProps } from "class-variance-authority"
6
- import { X } from "lucide-react"
3
+ import * as React from "react" ;
4
+ import * as ToastPrimitives from "@radix-ui/react-toast" ;
5
+ import { cva , type VariantProps } from "class-variance-authority" ;
6
+ import { X } from "lucide-react" ;
7
+ import { CircleAlert , CircleCheck } from "lucide-react" ;
8
+ import { cn } from "@/lib/utils" ;
7
9
8
- import { cn } from "@/lib/utils"
9
-
10
- const ToastProvider = ToastPrimitives . Provider
10
+ const ToastProvider = ToastPrimitives . Provider ;
11
11
12
12
const ToastViewport = React . forwardRef <
13
13
React . ElementRef < typeof ToastPrimitives . Viewport > ,
@@ -17,29 +17,41 @@ const ToastViewport = React.forwardRef<
17
17
ref = { ref }
18
18
className = { cn (
19
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
20
+ className ,
21
21
) }
22
22
{ ...props }
23
23
/>
24
- ) )
25
- ToastViewport . displayName = ToastPrimitives . Viewport . displayName
24
+ ) ) ;
25
+ ToastViewport . displayName = ToastPrimitives . Viewport . displayName ;
26
26
27
27
const toastVariants = cva (
28
28
"group pointer-events-auto relative flex w-full items-center justify-between space-x-4 overflow-hidden rounded-md border p-6 pr-8 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
29
{
30
30
variants : {
31
31
variant : {
32
32
default : "border bg-background text-foreground" ,
33
- success : "success bg-green text-green-foreground" ,
33
+ success :
34
+ "success group border-success bg-success text-success-foreground" ,
35
+ error : "error group border-error bg-error text-error-foreground" ,
34
36
destructive :
35
37
"destructive group border-destructive bg-destructive text-destructive-foreground" ,
36
38
} ,
37
39
} ,
38
40
defaultVariants : {
39
41
variant : "default" ,
40
42
} ,
43
+ } ,
44
+ ) ;
45
+
46
+ const ToastLogo = ( { variant } : VariantProps < typeof toastVariants > ) => {
47
+ switch ( variant ) {
48
+ case "success" :
49
+ return < CircleCheck className = "w-4 h-4" /> ;
50
+ case "error" :
51
+ return < CircleAlert className = "w-4 h-4" /> ;
41
52
}
42
- )
53
+ return < > </ > ;
54
+ } ;
43
55
44
56
const Toast = React . forwardRef <
45
57
React . ElementRef < typeof ToastPrimitives . Root > ,
@@ -52,9 +64,9 @@ const Toast = React.forwardRef<
52
64
className = { cn ( toastVariants ( { variant } ) , className ) }
53
65
{ ...props }
54
66
/>
55
- )
56
- } )
57
- Toast . displayName = ToastPrimitives . Root . displayName
67
+ ) ;
68
+ } ) ;
69
+ Toast . displayName = ToastPrimitives . Root . displayName ;
58
70
59
71
const ToastAction = React . forwardRef <
60
72
React . ElementRef < typeof ToastPrimitives . Action > ,
@@ -64,12 +76,12 @@ const ToastAction = React.forwardRef<
64
76
ref = { ref }
65
77
className = { cn (
66
78
"inline-flex h-8 shrink-0 items-center justify-center rounded-md border bg-transparent px-3 text-sm font-medium ring-offset-background transition-colors hover:bg-secondary focus:outline-none focus:ring-2 focus:ring-ring focus:ring-offset-2 disabled:pointer-events-none disabled:opacity-50 group-[.destructive]:border-muted/40 group-[.destructive]:hover:border-destructive/30 group-[.destructive]:hover:bg-destructive group-[.destructive]:hover:text-destructive-foreground group-[.destructive]:focus:ring-destructive" ,
67
- className
79
+ className ,
68
80
) }
69
81
{ ...props }
70
82
/>
71
- ) )
72
- ToastAction . displayName = ToastPrimitives . Action . displayName
83
+ ) ) ;
84
+ ToastAction . displayName = ToastPrimitives . Action . displayName ;
73
85
74
86
const ToastClose = React . forwardRef <
75
87
React . ElementRef < typeof ToastPrimitives . Close > ,
@@ -79,15 +91,15 @@ const ToastClose = React.forwardRef<
79
91
ref = { ref }
80
92
className = { cn (
81
93
"absolute right-2 top-2 rounded-md p-1 text-foreground/50 opacity-0 transition-opacity hover:text-foreground focus:opacity-100 focus:outline-none focus:ring-2 group-hover:opacity-100 group-[.destructive]:text-red-300 group-[.destructive]:hover:text-red-50 group-[.destructive]:focus:ring-red-400 group-[.destructive]:focus:ring-offset-red-600" ,
82
- className
94
+ className ,
83
95
) }
84
96
toast-close = ""
85
97
{ ...props }
86
98
>
87
- < X className = "h -4 w -4" />
99
+ < X className = "w -4 h -4" />
88
100
</ ToastPrimitives . Close >
89
- ) )
90
- ToastClose . displayName = ToastPrimitives . Close . displayName
101
+ ) ) ;
102
+ ToastClose . displayName = ToastPrimitives . Close . displayName ;
91
103
92
104
const ToastTitle = React . forwardRef <
93
105
React . ElementRef < typeof ToastPrimitives . Title > ,
@@ -98,8 +110,8 @@ const ToastTitle = React.forwardRef<
98
110
className = { cn ( "text-sm font-semibold" , className ) }
99
111
{ ...props }
100
112
/>
101
- ) )
102
- ToastTitle . displayName = ToastPrimitives . Title . displayName
113
+ ) ) ;
114
+ ToastTitle . displayName = ToastPrimitives . Title . displayName ;
103
115
104
116
const ToastDescription = React . forwardRef <
105
117
React . ElementRef < typeof ToastPrimitives . Description > ,
@@ -110,12 +122,13 @@ const ToastDescription = React.forwardRef<
110
122
className = { cn ( "text-sm opacity-90" , className ) }
111
123
{ ...props }
112
124
/>
113
- ) )
114
- ToastDescription . displayName = ToastPrimitives . Description . displayName
125
+ ) ) ;
126
+
127
+ ToastDescription . displayName = ToastPrimitives . Description . displayName ;
115
128
116
- type ToastProps = React . ComponentPropsWithoutRef < typeof Toast >
129
+ type ToastProps = React . ComponentPropsWithoutRef < typeof Toast > ;
117
130
118
- type ToastActionElement = React . ReactElement < typeof ToastAction >
131
+ type ToastActionElement = React . ReactElement < typeof ToastAction > ;
119
132
120
133
export {
121
134
type ToastProps ,
@@ -127,4 +140,5 @@ export {
127
140
ToastDescription ,
128
141
ToastClose ,
129
142
ToastAction ,
130
- }
143
+ ToastLogo ,
144
+ } ;
0 commit comments