-
Notifications
You must be signed in to change notification settings - Fork 18
/
Copy pathalert.tsx
74 lines (65 loc) · 1.73 KB
/
alert.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
'use client'
import type { VariantProps } from 'class-variance-authority'
import { cn } from '@/lib/utils'
import { cva } from 'class-variance-authority'
import * as React from 'react'
const alertVariants = cva(
'relative w-full rounded-lg border p-4 [&>svg~*]:pl-7 [&>svg+div]:translate-y-[-3px] [&>svg]:absolute [&>svg]:left-4 [&>svg]:top-4 [&>svg]:text-foreground',
{
variants: {
variant: {
default: 'bg-background text-foreground',
destructive:
'border-destructive/50 text-destructive dark:border-destructive [&>svg]:text-destructive',
},
},
defaultVariants: {
variant: 'default',
},
},
)
const Alert = ({
className,
variant,
...props
}: React.HTMLAttributes<HTMLDivElement> & VariantProps<typeof alertVariants>) => {
const itemRef = React.useRef<HTMLDivElement>(null)
return (
<div
ref={itemRef}
role="alert"
className={cn(alertVariants({ variant }), className)}
{...props}
/>
)
}
Alert.displayName = 'Alert'
const AlertTitle = ({
className,
...props
}: React.HTMLAttributes<HTMLHeadingElement>) => {
const itemRef = React.useRef<HTMLParagraphElement>(null)
return (
<h5
ref={itemRef}
className={cn('mb-1 font-medium leading-none tracking-tight', className)}
{...props}
/>
)
}
AlertTitle.displayName = 'AlertTitle'
const AlertDescription = ({
className,
...props
}: React.HTMLAttributes<HTMLParagraphElement>) => {
const itemRef = React.useRef<HTMLParagraphElement>(null)
return (
<div
ref={itemRef}
className={cn('text-sm [&_p]:leading-relaxed', className)}
{...props}
/>
)
}
AlertDescription.displayName = 'AlertDescription'
export { Alert, AlertDescription, AlertTitle }