Alert
scificn/alertFreeComponent
Alert panel with STATUS, WARNING, CRITICAL, and INFO variants.
Live preview
live · rendered by the registry
Rendered by scificn on their own page — this is the component running, not a screenshot of it.Install it
npx shadcn@latest add https://www.scificn.dev/r/alert.jsonSource
1import * as React from 'react'2import { cva, type VariantProps } from 'class-variance-authority'3import { cn } from '@/lib/utils'45const alertVariants = cva(6 [7 'relative w-full',8 'border border-solid border-l-[3px]',9 'p-4',10 'font-mono',11 'rounded-none',12 ],13 {14 variants: {15 variant: {16 STATUS: [17 'border-[var(--border)]',18 'border-l-[var(--color-green)]',19 'bg-[var(--surface)]',20 ],21 WARNING: [22 'border-[var(--border)]',23 'border-l-[var(--color-amber)]',24 'bg-[var(--surface)]',25 ],26 CRITICAL: [27 'border-[var(--border)]',28 'border-l-[var(--color-red)]',29 'bg-[var(--surface)]',30 ],31 INFO: [32 'border-[var(--border)]',33 'border-l-[var(--color-blue)]',34 'bg-[var(--surface)]',35 ],36 },37 },38 defaultVariants: { variant: 'STATUS' },39 }40)4142const prefixMap = {43 STATUS: { symbol: '◈', color: 'var(--color-green)', glow: 'var(--text-glow-green)' },44 WARNING: { symbol: '⚠', color: 'var(--color-amber)', glow: 'var(--text-glow-amber)' },45 CRITICAL: { symbol: '✕', color: 'var(--color-red)', glow: 'var(--text-glow-red)' },46 INFO: { symbol: 'ℹ', color: 'var(--color-blue)', glow: 'var(--text-glow-blue)' },47}4849export interface AlertProps50 extends React.HTMLAttributes<HTMLDivElement>,51 VariantProps<typeof alertVariants> {}5253const Alert = React.forwardRef<HTMLDivElement, AlertProps>(54 ({ className, variant = 'STATUS', children, ...props }, ref) => {55 const v = variant ?? 'STATUS'56 const prefix = prefixMap[v]5758 return (59 <div ref={ref} className={cn(alertVariants({ variant }), className)} role="alert" {...props}>60 <div style={{ display: 'flex', gap: '0.5rem', alignItems: 'flex-start' }}>61 <span62 style={{63 color: prefix.color,64 textShadow: prefix.glow,65 fontSize: '0.85rem',66 lineHeight: 1.5,67 flexShrink: 0,68 }}69 >70 {prefix.symbol}71 </span>72 <div style={{ flex: 1 }}>{children}</div>73 </div>74 </div>75 )76 }77)78Alert.displayName = 'Alert'7980/* ── AlertTitle ── */81const AlertTitle = React.forwardRef<HTMLParagraphElement, React.HTMLAttributes<HTMLHeadingElement>>(82 ({ className, style, ...props }, ref) => (83 <h584 ref={ref}85 className={cn(className)}86 style={{87// … truncated
What it pulls in
npm packages
More from scificn
All 33 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Badgebadge | scificn | Components | Free | 1 dep | |
| Bar Chartbar-chart | scificn | Components | Free | no deps | |
| Breadcrumbbreadcrumb | scificn | Components | Free | no deps | |
| Buttonbutton | scificn | Components | Free | 2 deps | |
| Cardcard | scificn | Components | Free | no deps | |
| Checkboxcheckbox | scificn | Components | Free | 1 dep | |
| Dialogdialog | scificn | Components | Free | 1 dep | |
| Gridgrid | scificn | Components | Free | no deps |
