Composio powers 1000+ toolkits, tool search, context management, authentication, and a sandboxed workbench to help you build AI agents that turn intent into action.
| 1 | import type { ReactNode } from 'react'; |
| 2 | import { CircleCheck, CircleX, Lightbulb, TriangleAlert } from 'lucide-react'; |
| 3 | import { cn } from '@/lib/utils'; |
| 4 | |
| 5 | type CalloutType = 'info' | 'warn' | 'warning' | 'error' | 'success' | 'tip' | 'idea'; |
| 6 | |
| 7 | interface CalloutProps { |
| 8 | type?: CalloutType; |
| 9 | title?: ReactNode; |
| 10 | children?: ReactNode; |
| 11 | className?: string; |
| 12 | } |
| 13 | |
| 14 | type ResolvedType = 'info' | 'warning' | 'error' | 'success' | 'idea'; |
| 15 | |
| 16 | function resolveType(type: CalloutType = 'info'): ResolvedType { |
| 17 | if (type === 'warn') return 'warning'; |
| 18 | if (type === 'tip') return 'info'; |
| 19 | return type; |
| 20 | } |
| 21 | |
| 22 | const variants: Record< |
| 23 | ResolvedType, |
| 24 | { container: string; icon?: typeof TriangleAlert; iconClass?: string } |
| 25 | > = { |
| 26 | info: { |
| 27 | container: 'border-fd-border/40 bg-fd-muted/35 text-fd-muted-foreground', |
| 28 | }, |
| 29 | warning: { |
| 30 | container: 'border-amber-600/15 bg-amber-500/[0.04] text-fd-muted-foreground', |
| 31 | icon: TriangleAlert, |
| 32 | iconClass: 'text-amber-600/60', |
| 33 | }, |
| 34 | error: { |
| 35 | container: 'border-red-500/15 bg-red-500/[0.04] text-fd-muted-foreground', |
| 36 | icon: CircleX, |
| 37 | iconClass: 'text-red-500/60', |
| 38 | }, |
| 39 | success: { |
| 40 | container: 'border-emerald-600/15 bg-emerald-500/[0.04] text-fd-muted-foreground', |
| 41 | icon: CircleCheck, |
| 42 | iconClass: 'text-emerald-600/60', |
| 43 | }, |
| 44 | idea: { |
| 45 | container: 'border-fd-border/40 bg-fd-muted/35 text-fd-muted-foreground', |
| 46 | icon: Lightbulb, |
| 47 | iconClass: 'text-fd-muted-foreground/70', |
| 48 | }, |
| 49 | }; |
| 50 | |
| 51 | export function Callout({ type = 'info', title, children, className }: CalloutProps) { |
| 52 | const resolved = resolveType(type); |
| 53 | const variant = variants[resolved]; |
| 54 | const Icon = variant.icon; |
| 55 | |
| 56 | return ( |
| 57 | <div |
| 58 | data-callout="" |
| 59 | className={cn( |
| 60 | 'not-prose my-3 rounded-md border px-3 py-2 text-[0.8125rem] leading-relaxed', |
| 61 | variant.container, |
| 62 | className, |
| 63 | )} |
| 64 | > |
| 65 | <div className={cn('flex gap-2', Icon ? 'items-start' : '')}> |
| 66 | {Icon ? ( |
| 67 | <Icon className={cn('mt-0.5 size-3.5 shrink-0 stroke-[1.75]', variant.iconClass)} /> |
| 68 | ) : null} |
| 69 | <div className="min-w-0 flex-1"> |
| 70 | {title ? <p className="mb-1 font-medium text-fd-foreground">{title}</p> : null} |
| 71 | <div |
| 72 | className={cn( |
| 73 | 'prose-no-margin', |
| 74 | '[&_a]:text-fd-foreground [&_a]:underline [&_a]:decoration-fd-border [&_a]:underline-offset-2', |
| 75 | '[&_a]:hover:decoration-fd-muted-foreground', |
| 76 | '[&_code]:text-[0.8125rem] [&_code]:text-fd-foreground/80', |
| 77 | )} |
| 78 | > |
| 79 | {children} |
| 80 | </div> |
| 81 | </div> |
| 82 | </div> |
| 83 | </div> |
| 84 | ); |
| 85 | } |