import { cva } from 'class-variance-authority' import { forwardRef } from 'react' import { Alert_Shadcn_, AlertDescription_Shadcn_, AlertTitle_Shadcn_, cn } from 'ui' export interface AdmonitionProps { type: | 'note' | 'tip' | 'caution' | 'danger' | 'deprecation' | 'default' | 'destructive' | 'warning' label?: string title?: string description?: string | React.ReactNode showIcon?: boolean childProps?: { title?: React.ComponentProps description?: React.ComponentProps } } const admonitionToAlertMapping: Record< AdmonitionProps['type'], 'default' | 'destructive' | 'warning' > = { note: 'default', tip: 'default', caution: 'warning', danger: 'destructive', deprecation: 'warning', default: 'default', warning: 'warning', destructive: 'destructive', } const InfoIcon = () => ( ) const WarningIcon = () => ( ) const admonitionSVG = cva('', { variants: { type: { default: `[&>svg]:bg-foreground-muted`, warning: ``, destructive: ``, }, }, }) const admonitionBase = cva('', { variants: { type: { default: `bg-surface-200/25 border border-default`, warning: `bg-alternative border border-default`, destructive: `bg-alternative border border-default`, }, }, }) export const Admonition = forwardRef< React.ElementRef, React.ComponentPropsWithoutRef & AdmonitionProps >( ( { type = 'note', variant, showIcon = true, label, title, description, children, ...props }, ref ) => { const typeMapped = variant ? admonitionToAlertMapping[variant] : admonitionToAlertMapping[type] return ( {(showIcon && typeMapped === 'warning') || typeMapped === 'destructive' ? ( ) : showIcon ? ( ) : null} {label || title ? ( <> {label || title} {description && ( {description} )} {/* // children is to handle Docs and MDX issues with children and

elements */} {children && ( {children} )} ) : (

{children}
)}
) } )