|
| 1 | +import type * as React from 'react' |
| 2 | +import { cva, type VariantProps } from 'class-variance-authority' |
| 3 | +import { AlertTriangle, CheckCircle2, Info } from 'lucide-react' |
| 4 | +import { cn } from '@/lib/core/utils/cn' |
| 5 | + |
| 6 | +const calloutVariants = cva('flex items-center gap-2 rounded-lg border p-2.5 text-[12px]', { |
| 7 | + variants: { |
| 8 | + variant: { |
| 9 | + default: 'border-[var(--border)] bg-[var(--surface-2)] text-[var(--text-muted)]', |
| 10 | + info: 'border-[var(--border)] bg-[var(--surface-2)] text-[var(--text-muted)]', |
| 11 | + success: |
| 12 | + 'border-[color-mix(in_srgb,var(--badge-success-text)_30%,transparent)] bg-[var(--badge-success-bg)] text-[var(--badge-success-text)]', |
| 13 | + warning: |
| 14 | + 'border-[color-mix(in_srgb,var(--badge-amber-text)_30%,transparent)] bg-[var(--badge-amber-bg)] text-[var(--badge-amber-text)]', |
| 15 | + destructive: |
| 16 | + 'border-[color-mix(in_srgb,var(--text-error)_40%,transparent)] bg-[color-mix(in_srgb,var(--text-error)_10%,transparent)] text-[var(--text-error)]', |
| 17 | + }, |
| 18 | + }, |
| 19 | + defaultVariants: { |
| 20 | + variant: 'default', |
| 21 | + }, |
| 22 | +}) |
| 23 | + |
| 24 | +const DEFAULT_ICONS = { |
| 25 | + default: Info, |
| 26 | + info: Info, |
| 27 | + success: CheckCircle2, |
| 28 | + warning: AlertTriangle, |
| 29 | + destructive: AlertTriangle, |
| 30 | +} as const |
| 31 | + |
| 32 | +export interface CalloutProps |
| 33 | + extends React.HTMLAttributes<HTMLDivElement>, |
| 34 | + VariantProps<typeof calloutVariants> { |
| 35 | + /** Icon component shown before the content. Pass `null` to hide. Defaults per variant. */ |
| 36 | + icon?: React.ComponentType<{ className?: string }> | null |
| 37 | +} |
| 38 | + |
| 39 | +/** |
| 40 | + * Inline note used to highlight short pieces of context inside a page or section. |
| 41 | + * |
| 42 | + * @example |
| 43 | + * ```tsx |
| 44 | + * <Callout>Applies organization-wide</Callout> |
| 45 | + * <Callout variant='warning'>This action is irreversible</Callout> |
| 46 | + * ``` |
| 47 | + */ |
| 48 | +function Callout({ className, variant, icon, children, role = 'note', ...props }: CalloutProps) { |
| 49 | + const variantKey = (variant ?? 'default') as keyof typeof DEFAULT_ICONS |
| 50 | + const Icon = icon === null ? null : (icon ?? DEFAULT_ICONS[variantKey]) |
| 51 | + |
| 52 | + return ( |
| 53 | + <div role={role} className={cn(calloutVariants({ variant }), className)} {...props}> |
| 54 | + {Icon && <Icon className='h-[14px] w-[14px] shrink-0' />} |
| 55 | + <span>{children}</span> |
| 56 | + </div> |
| 57 | + ) |
| 58 | +} |
| 59 | + |
| 60 | +export { Callout, calloutVariants } |
0 commit comments