|
| 1 | +import { cn } from '../lib/utils'; |
| 2 | + |
| 3 | +type CalloutType = 'note' | 'tip' | 'warning' | 'critical' | 'info' | 'success'; |
| 4 | + |
| 5 | +interface CalloutProps { |
| 6 | + type: CalloutType; |
| 7 | + children: React.ReactNode; |
| 8 | + title?: string; |
| 9 | +} |
| 10 | + |
| 11 | +const calloutConfig: Record< |
| 12 | + CalloutType, |
| 13 | + { |
| 14 | + title: string; |
| 15 | + bgColor: string; |
| 16 | + borderColor: string; |
| 17 | + titleColor: string; |
| 18 | + } |
| 19 | +> = { |
| 20 | + note: { |
| 21 | + title: 'Note', |
| 22 | + bgColor: 'bg-blue-950/30', |
| 23 | + borderColor: 'border-blue-400', |
| 24 | + titleColor: 'text-blue-400', |
| 25 | + }, |
| 26 | + tip: { |
| 27 | + title: 'Tip', |
| 28 | + bgColor: 'bg-purple-950/30', |
| 29 | + borderColor: 'border-purple-400', |
| 30 | + titleColor: 'text-purple-400', |
| 31 | + }, |
| 32 | + warning: { |
| 33 | + title: 'Warning', |
| 34 | + bgColor: 'bg-yellow-950/30', |
| 35 | + borderColor: 'border-yellow-400', |
| 36 | + titleColor: 'text-yellow-400', |
| 37 | + }, |
| 38 | + critical: { |
| 39 | + title: 'critical', |
| 40 | + bgColor: 'bg-red-950/30', |
| 41 | + borderColor: 'border-red-400', |
| 42 | + titleColor: 'text-red-400', |
| 43 | + }, |
| 44 | + info: { |
| 45 | + title: 'Info', |
| 46 | + bgColor: 'bg-cyan-950/30', |
| 47 | + borderColor: 'border-cyan-400', |
| 48 | + titleColor: 'text-cyan-400', |
| 49 | + }, |
| 50 | + success: { |
| 51 | + title: 'Success', |
| 52 | + bgColor: 'bg-green-950/30', |
| 53 | + borderColor: 'border-green-400', |
| 54 | + titleColor: 'text-green-400', |
| 55 | + }, |
| 56 | +}; |
| 57 | + |
| 58 | +export function Callout({ type, children, title }: CalloutProps) { |
| 59 | + const config = calloutConfig[type]; |
| 60 | + |
| 61 | + return ( |
| 62 | + <div className={cn(config.bgColor, config.borderColor, 'mt-6 border-l-2 p-4')}> |
| 63 | + <div className="min-w-0 flex-1 text-white"> |
| 64 | + <div |
| 65 | + className={cn('mb-2 font-mono text-sm font-medium uppercase', config.titleColor)} |
| 66 | + style={{ |
| 67 | + letterSpacing: '0.05em', |
| 68 | + }} |
| 69 | + > |
| 70 | + {title ?? config.title} |
| 71 | + </div> |
| 72 | + {/* I used [&_*]:!leading-[inherit] to override line-height forced by nextra */} |
| 73 | + <div className={cn('[&_*]:!leading-[inherit]')}>{children}</div> |
| 74 | + </div> |
| 75 | + </div> |
| 76 | + ); |
| 77 | +} |
0 commit comments