|
| 1 | +import { |
| 2 | + CheckCircleIcon, |
| 3 | + InfoIcon, |
| 4 | + LightbulbIcon, |
| 5 | + WarningCircleIcon, |
| 6 | + XCircleIcon, |
| 7 | +} from '@phosphor-icons/react/ssr'; |
| 8 | +import { cva, type VariantProps } from 'class-variance-authority'; |
| 9 | +import type * as React from 'react'; |
| 10 | + |
| 11 | +import { cn } from '@/lib/utils'; |
| 12 | + |
| 13 | +const calloutVariants = cva( |
| 14 | + 'group relative my-4 w-full rounded border backdrop-blur-sm transition-all duration-300', |
| 15 | + { |
| 16 | + variants: { |
| 17 | + type: { |
| 18 | + info: 'border-blue-200 bg-blue-50/80 hover:bg-blue-50/90 dark:border-blue-800/50 dark:bg-blue-950/20 dark:hover:bg-blue-950/30', |
| 19 | + success: |
| 20 | + 'border-green-200 bg-green-50/80 hover:bg-green-50/90 dark:border-green-800/50 dark:bg-green-950/20 dark:hover:bg-green-950/30', |
| 21 | + warn: 'border-yellow-200 bg-yellow-50/80 hover:bg-yellow-50/90 dark:border-yellow-800/50 dark:bg-yellow-950/20 dark:hover:bg-yellow-950/30', |
| 22 | + error: |
| 23 | + 'border-red-200 bg-red-50/80 hover:bg-red-50/90 dark:border-red-800/50 dark:bg-red-950/20 dark:hover:bg-red-950/30', |
| 24 | + tip: 'border-purple-200 bg-purple-50/80 hover:bg-purple-50/90 dark:border-purple-800/50 dark:bg-purple-950/20 dark:hover:bg-purple-950/30', |
| 25 | + note: 'border-border bg-card/50 hover:bg-card/70', |
| 26 | + }, |
| 27 | + }, |
| 28 | + defaultVariants: { |
| 29 | + type: 'info', |
| 30 | + }, |
| 31 | + } |
| 32 | +); |
| 33 | + |
| 34 | +const iconVariants = cva('size-5 shrink-0', { |
| 35 | + variants: { |
| 36 | + type: { |
| 37 | + info: 'text-blue-500 dark:text-blue-400', |
| 38 | + success: 'text-green-500 dark:text-green-400', |
| 39 | + warn: 'text-yellow-500 dark:text-yellow-400', |
| 40 | + error: 'text-red-500 dark:text-red-400', |
| 41 | + tip: 'text-purple-500 dark:text-purple-400', |
| 42 | + note: 'text-muted-foreground', |
| 43 | + }, |
| 44 | + }, |
| 45 | + defaultVariants: { |
| 46 | + type: 'info', |
| 47 | + }, |
| 48 | +}); |
| 49 | + |
| 50 | +const iconMap = { |
| 51 | + info: InfoIcon, |
| 52 | + success: CheckCircleIcon, |
| 53 | + warn: WarningCircleIcon, |
| 54 | + error: XCircleIcon, |
| 55 | + tip: LightbulbIcon, |
| 56 | + note: InfoIcon, |
| 57 | +}; |
| 58 | + |
| 59 | +interface CalloutProps |
| 60 | + extends React.ComponentProps<'div'>, |
| 61 | + VariantProps<typeof calloutVariants> { |
| 62 | + title?: string; |
| 63 | +} |
| 64 | + |
| 65 | +function Callout({ |
| 66 | + className, |
| 67 | + type = 'info', |
| 68 | + title, |
| 69 | + children, |
| 70 | + ...props |
| 71 | +}: CalloutProps) { |
| 72 | + const Icon = iconMap[type as keyof typeof iconMap]; |
| 73 | + |
| 74 | + return ( |
| 75 | + <div |
| 76 | + className={cn(calloutVariants({ type }), className)} |
| 77 | + role="alert" |
| 78 | + {...props} |
| 79 | + > |
| 80 | + <div className="flex items-start gap-4 p-4"> |
| 81 | + <Icon |
| 82 | + className={cn(iconVariants({ type }), 'mt-0.5')} |
| 83 | + weight="duotone" |
| 84 | + /> |
| 85 | + <div className="min-w-0 flex-1 space-y-2"> |
| 86 | + {title && ( |
| 87 | + <div className="font-semibold text-foreground tracking-tight"> |
| 88 | + {title} |
| 89 | + </div> |
| 90 | + )} |
| 91 | + <div className="text-foreground text-sm leading-relaxed [&_p]:text-foreground [&_p]:leading-relaxed"> |
| 92 | + {children} |
| 93 | + </div> |
| 94 | + </div> |
| 95 | + </div> |
| 96 | + |
| 97 | + {/* Sci-fi corners */} |
| 98 | + <div className="pointer-events-none absolute inset-0"> |
| 99 | + <div className="absolute top-0 left-0 h-2 w-2 group-hover:animate-[cornerGlitch_0.6s_ease-in-out]"> |
| 100 | + <div className="absolute top-0 left-0.5 h-0.5 w-1.5 origin-left bg-foreground/20" /> |
| 101 | + <div className="absolute top-0 left-0 h-2 w-0.5 origin-top bg-foreground/20" /> |
| 102 | + </div> |
| 103 | + <div className="-scale-x-[1] absolute top-0 right-0 h-2 w-2 group-hover:animate-[cornerGlitch_0.6s_ease-in-out]"> |
| 104 | + <div className="absolute top-0 left-0.5 h-0.5 w-1.5 origin-left bg-foreground/20" /> |
| 105 | + <div className="absolute top-0 left-0 h-2 w-0.5 origin-top bg-foreground/20" /> |
| 106 | + </div> |
| 107 | + <div className="-scale-y-[1] absolute bottom-0 left-0 h-2 w-2 group-hover:animate-[cornerGlitch_0.6s_ease-in-out]"> |
| 108 | + <div className="absolute top-0 left-0.5 h-0.5 w-1.5 origin-left bg-foreground/20" /> |
| 109 | + <div className="absolute top-0 left-0 h-2 w-0.5 origin-top bg-foreground/20" /> |
| 110 | + </div> |
| 111 | + <div className="-scale-[1] absolute right-0 bottom-0 h-2 w-2 group-hover:animate-[cornerGlitch_0.6s_ease-in-out]"> |
| 112 | + <div className="absolute top-0 left-0.5 h-0.5 w-1.5 origin-left bg-foreground/20" /> |
| 113 | + <div className="absolute top-0 left-0 h-2 w-0.5 origin-top bg-foreground/20" /> |
| 114 | + </div> |
| 115 | + </div> |
| 116 | + </div> |
| 117 | + ); |
| 118 | +} |
| 119 | + |
| 120 | +export { Callout }; |
0 commit comments