Open History to see the last commit
1import { Info, Lightbulb, TriangleAlert } from "lucide-react";
2import type { ReactNode } from "react";
3
4import { cn } from "@/lib/utils";
5
6const VARIANTS = {
7 note: {
8 icon: Info,
9 title: "Note",
10 className:
11 "border-sky-200 bg-sky-50 text-sky-950 dark:border-sky-900/60 dark:bg-sky-950/30 dark:text-sky-100",
12 iconClassName: "text-sky-600 dark:text-sky-400",
13 },
14 tip: {
15 icon: Lightbulb,
16 title: "Try it",
17 className:
18 "border-emerald-200 bg-emerald-50 text-emerald-950 dark:border-emerald-900/60 dark:bg-emerald-950/30 dark:text-emerald-100",
19 iconClassName: "text-emerald-600 dark:text-emerald-400",
20 },
21 warning: {
22 icon: TriangleAlert,
23 title: "Watch out",
24 className:
25 "border-amber-200 bg-amber-50 text-amber-950 dark:border-amber-900/60 dark:bg-amber-950/30 dark:text-amber-100",
26 iconClassName: "text-amber-600 dark:text-amber-400",
27 },
28} as const;
29
30interface CalloutProps {
31 variant?: keyof typeof VARIANTS;
32 title?: string;
33 children: ReactNode;
34}
35
36export function Callout({ variant = "note", title, children }: CalloutProps) {
37 const { icon: Icon, className, iconClassName, title: defaultTitle } = VARIANTS[variant];
38 return (
39 <aside className={cn("my-5 flex gap-3 rounded-xl border px-4 py-3 text-sm", className)}>
40 <Icon className={cn("mt-0.5 size-4 shrink-0", iconClassName)} aria-hidden />
41 <div className="space-y-1 leading-relaxed">
42 <p className="font-semibold">{title ?? defaultTitle}</p>
43 <div className="[&_code]:rounded [&_code]:bg-black/5 [&_code]:px-1 [&_code]:py-0.5 [&_code]:font-mono [&_code]:text-[0.85em] dark:[&_code]:bg-white/10">
44 {children}
45 </div>
46 </div>
47 </aside>
48 );
49}