Toast
shadcn-lit-registry/toastFreeComponent
An opinionated toast notification component for displaying messages. Built with Lit and styled using Tailwind CSS. Supports success, error, info, warning, and loading states with icons. Features promise support, action buttons, and multiple visual variants.
Install it
npx shadcn@latest add https://lit-registry.lloydrichards.dev/r/toast.jsonSource
1import { cva, type VariantProps } from "class-variance-authority";2import { html, LitElement, nothing } from "lit";3import { customElement, state } from "lit/decorators.js";4import { repeat } from "lit/directives/repeat.js";5import { unsafeHTML } from "lit/directives/unsafe-html.js";6import {7 CircleCheck,8 Info,9 LoaderCircle,10 OctagonX,11 TriangleAlert,12 X,13} from "lucide-static";14import { TW } from "@/lib/tailwindMixin";15import "../button/button";1617export const toastVariants = cva(18 "group pointer-events-auto relative flex w-full items-center justify-between space-x-2 overflow-hidden rounded-md p-4 pr-6 shadow-lg transition-all",19 {20 variants: {21 variant: {22 default: "bg-popover text-popover-foreground border",23 outline: "bg-background text-foreground border",24 destructive:25 "bg-destructive text-destructive-foreground border-destructive",26 },27 state: {28 open: "animate-in fade-in-0 slide-in-from-top-full duration-300 sm:slide-in-from-bottom-full",29 closed: "animate-out fade-out-80 slide-out-to-right-full duration-300",30 },31 },32 defaultVariants: {33 variant: "default",34 },35 },36);3738type ToastVariants = VariantProps<typeof toastVariants>;3940export type ToastType = "success" | "error" | "info" | "warning" | "loading";4142export interface ToastOptions {43 description?: string;44 variant?: ToastVariants["variant"];45 type?: ToastType;46 duration?: number;47 action?: {48 label: string;49 onClick: () => void;50 };51 onDismiss?: () => void;52}5354interface ToastData extends ToastOptions {55 id: string;56 message: string;57 state: "open" | "closed";58}5960let toasterInstance: Toaster | null = null;61let toastIdCounter = 0;6263function ensureToaster(): Toaster {64 if (!toasterInstance) {65 toasterInstance = document.createElement("ui-toaster") as Toaster;66 document.body.appendChild(toasterInstance);67 }68 return toasterInstance;69}7071export function toast(message: string, options: ToastOptions = {}) {72 const toaster = ensureToaster();73 return toaster.addToast(message, options);74}7576toast.success = (message: string, options: ToastOptions = {}) =>77 toast(message, { ...options, type: "success" });7879toast.error = (message: string, options: ToastOptions = {}) =>80 toast(message, { ...options, type: "error" });8182toast.warning = (message: string, options: ToastOptions = {}) =>83 toast(message, { ...options, type: "warning" });8485// … truncated
What it pulls in
npm packages
Other registry items
Files it writes
More from shadcn-lit-registry
All 26 items| Component | Registry | Kind | Access | Installs | Command |
|---|---|---|---|---|---|
| Accordionaccordion | shadcn-lit-registry | Components | Free | 1 dep · 2 files | |
| Avataravatar | shadcn-lit-registry | Components | Free | no deps · 2 files | |
| Badgebadge | shadcn-lit-registry | Components | Free | no deps · 2 files | |
| Buttonbutton | shadcn-lit-registry | Components | Free | 1 dep · 2 files | |
| Cardcard | shadcn-lit-registry | Components | Free | no deps · 2 files | |
| Checkboxcheckbox | shadcn-lit-registry | Components | Free | 1 dep · 2 files | |
| Collapsiblecollapsible | shadcn-lit-registry | Components | Free | 1 dep · 2 files | |
| Commandcommand | shadcn-lit-registry | Components | Free | 1 dep · 2 files |
