Toast
scificn/toastFreeComponent
Toast notifications with useToast hook. STATUS, WARNING, CRITICAL, 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/toast.jsonSource
1import * as React from 'react'2import * as ToastPrimitive from '@radix-ui/react-toast'3import { cn } from '@/lib/utils'4import type { ToastVariant } from './use-toast'56const ToastProvider = ToastPrimitive.Provider7const ToastViewport = React.forwardRef<8 React.ElementRef<typeof ToastPrimitive.Viewport>,9 React.ComponentPropsWithoutRef<typeof ToastPrimitive.Viewport>10>(({ className, ...props }, ref) => (11 <ToastPrimitive.Viewport12 ref={ref}13 className={cn('fixed bottom-4 right-4 z-[9999] flex flex-col gap-2 w-80', className)}14 {...props}15 />16))17ToastViewport.displayName = ToastPrimitive.Viewport.displayName1819const variantStyles: Record<ToastVariant, { borderColor: string; symbol: string; glow: string }> = {20 STATUS: { borderColor: 'var(--color-green)', symbol: '◈', glow: 'var(--glow-green)' },21 WARNING: { borderColor: 'var(--color-amber)', symbol: '⚠', glow: 'var(--glow-amber)' },22 CRITICAL: { borderColor: 'var(--color-red)', symbol: '✕', glow: 'var(--glow-red)' },23 INFO: { borderColor: 'var(--color-blue)', symbol: 'ℹ', glow: 'var(--glow-blue)' },24}2526export interface ToastProps27 extends React.ComponentPropsWithoutRef<typeof ToastPrimitive.Root> {28 variant?: ToastVariant29}3031const Toast = React.forwardRef<32 React.ElementRef<typeof ToastPrimitive.Root>,33 ToastProps34>(({ className, variant = 'STATUS', children, ...props }, ref) => {35 const vs = variantStyles[variant]36 return (37 <ToastPrimitive.Root38 ref={ref}39 className={cn(40 'relative flex items-start gap-3',41 'border border-l-[3px] rounded-none',42 'bg-[var(--surface-raised)]',43 'p-3',44 'font-mono',45 'data-[state=open]:animate-in data-[state=open]:slide-in-from-right-full',46 'data-[state=closed]:animate-out data-[state=closed]:slide-out-to-right-full',47 className48 )}49 style={{50 borderColor: 'var(--border)',51 borderLeftColor: vs.borderColor,52 boxShadow: vs.glow,53 }}54 {...props}55 >56 <span57 style={{58 color: vs.borderColor,59 fontSize: '0.8rem',60 lineHeight: 1.5,61 flexShrink: 0,62 }}63 >64 {vs.symbol}65 </span>66 <div style={{ flex: 1, minWidth: 0 }}>{children}</div>67 <ToastPrimitive.Close68 style={{69 background: 'transparent',70 border: 'none',71 color: 'var(--text-muted)',72 cursor: 'pointer',73// … truncated
What it pulls in
npm packages
More from scificn
All 33 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Alertalert | scificn | Components | Free | 1 dep | |
| 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 |
