1import {2 AlertDialog,3 AlertDialogContent,4 AlertDialogDescription,5 AlertDialogTitle,6 AlertDialogTrigger,7} from "~/components/ui/alert-dialog";8import { Button } from "~/components/ui/button";9
10export default function AlertDialogDemo() {11 return (12 <AlertDialog>13 <AlertDialogTrigger as={Button}>Show Dialog</AlertDialogTrigger>14 <AlertDialogContent>15 <div>16 <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>17 <AlertDialogDescription>18 This action cannot be undone. This will permanently delete your19 account.20 </AlertDialogDescription>21 </div>22 </AlertDialogContent>23 </AlertDialog>24 );25}
npx shadcn@latest add https://solid-ui-neobrutalism.vercel.app/r/alert-dialog.json
yarn shadcn@latest add https://solid-ui-neobrutalism.vercel.app/r/alert-dialog.json
pnpm dlx shadcn@latest add https://solid-ui-neobrutalism.vercel.app/r/alert-dialog.json
bunx --bun shadcn@latest add https://solid-ui-neobrutalism.vercel.app/r/alert-dialog.json
Install the following dependencies
npm install @kobalte/core
yarn add @kobalte/core
pnpm add @kobalte/core
bun add @kobalte/core
Install the following component dependencies
Copy and paste the following code into your project
1import type { PolymorphicProps } from "@kobalte/core/polymorphic";2import type { JSX, ValidComponent } from "solid-js";3
4import { splitProps } from "solid-js";5import * as AlertDialogPrimitive from "@kobalte/core/alert-dialog";6import XIcon from "lucide-solid/icons/x";7
8import { cn } from "~/lib/utils";9import { buttonVariants } from "./button";10
11type AlertDialogProps = AlertDialogPrimitive.AlertDialogRootProps;12
13const AlertDialog = (props: AlertDialogProps) => {14 return <AlertDialogPrimitive.Root data-slot="alert-dialog" {...props} />;15};16
17const AlertDialogTrigger = <T extends ValidComponent = "button">(18 props: PolymorphicProps<T, AlertDialogPrimitive.AlertDialogTriggerProps<T>>,19) => {20 return (21 <AlertDialogPrimitive.Trigger data-slot="alert-dialog-trigger" {...props} />22 );23};24
25type AlertDialogPortalProps = AlertDialogPrimitive.AlertDialogPortalProps;26
27const AlertDialogPortal = (props: AlertDialogPortalProps) => {28 return (29 <AlertDialogPrimitive.Portal data-slot="alert-dialog-portal" {...props} />30 );31};32
33type AlertDialogOverlayProps<T extends ValidComponent = "div"> =34 AlertDialogPrimitive.AlertDialogOverlayProps<T> & {35 class?: string | undefined;36 };37
38const AlertDialogOverlay = <T extends ValidComponent = "div">(39 props: PolymorphicProps<T, AlertDialogOverlayProps<T>>,40) => {41 const [local, others] = splitProps(props as AlertDialogOverlayProps, [42 "class",43 ]);44 return (45 <AlertDialogPrimitive.Overlay46 data-slot="alert-dialog-overlay"47 class={cn(48 "fixed inset-0 z-50 bg-overlay ui-expanded:animate-in ui-expanded:fade-in-0 ui-closed:animate-out ui-closed:fade-out-0",49 local.class,50 )}51 {...others}52 />53 );54};55
56type AlertDialogContentProps<T extends ValidComponent = "div"> =57 AlertDialogPrimitive.AlertDialogContentProps<T> & {58 class?: string | undefined;59 children?: JSX.Element;60 };61
62const AlertDialogContent = <T extends ValidComponent = "div">(63 props: PolymorphicProps<T, AlertDialogContentProps<T>>,64) => {65 const [local, others] = splitProps(props as AlertDialogContentProps, [66 "class",67 "children",68 ]);69 return (70 <AlertDialogPortal>71 <AlertDialogOverlay />72 <AlertDialogPrimitive.Content73 data-slot="alert-dialog-content"74 class={cn(75 "fixed top-[50%] left-[50%] z-50 grid w-full max-w-[calc(100%-2rem)] translate-x-[-50%] translate-y-[-50%] gap-4 rounded-base border-2 border-border bg-background p-6 shadow-shadow duration-200 sm:max-w-lg ui-expanded:animate-in ui-expanded:fade-in-0 ui-expanded:zoom-in-95 ui-closed:animate-out ui-closed:fade-out-0 ui-closed:zoom-out-95",76 local.class,77 )}78 {...others}79 >80 {local.children}81 <AlertDialogPrimitive.CloseButton82 data-slot="alert-dialog-close"83 class={cn(84 buttonVariants({ variant: "neutral", size: "icon" }),85 "absolute top-2 right-3 size-8",86 )}87 >88 <XIcon class="size-4" />89 <span class="sr-only">Close</span>90 </AlertDialogPrimitive.CloseButton>91 </AlertDialogPrimitive.Content>92 </AlertDialogPortal>93 );94};95
96type AlertDialogTitleProps<T extends ValidComponent = "h2"> =97 AlertDialogPrimitive.AlertDialogTitleProps<T> & {98 class?: string | undefined;99 };100
101const AlertDialogTitle = <T extends ValidComponent = "h2">(102 props: PolymorphicProps<T, AlertDialogTitleProps<T>>,103) => {104 const [local, others] = splitProps(props as AlertDialogTitleProps, ["class"]);105 return (106 <AlertDialogPrimitive.Title107 data-slot="alert-dialog-title"108 class={cn("text-lg font-semibold", local.class)}109 {...others}110 />111 );112};113
114type AlertDialogDescriptionProps<T extends ValidComponent = "p"> =115 AlertDialogPrimitive.AlertDialogDescriptionProps<T> & {116 class?: string | undefined;117 };118
119const AlertDialogDescription = <T extends ValidComponent = "p">(120 props: PolymorphicProps<T, AlertDialogDescriptionProps<T>>,121) => {122 const [local, others] = splitProps(props as AlertDialogDescriptionProps, [123 "class",124 ]);125 return (126 <AlertDialogPrimitive.Description127 data-slot="alert-dialog-description"128 class={cn("text-sm text-muted-foreground", local.class)}129 {...others}130 />131 );132};133
134export {135 AlertDialog,136 AlertDialogPortal,137 AlertDialogOverlay,138 AlertDialogTrigger,139 AlertDialogContent,140 AlertDialogTitle,141 AlertDialogDescription,142};
Update the import paths to match your project setup.
1import {2 AlertDialog,3 AlertDialogContent,4 AlertDialogDescription,5 AlertDialogTitle,6 AlertDialogTrigger,7} from "~/components/ui/alert-dialog";
1<AlertDialog>2 <AlertDialogTrigger>Open</AlertDialogTrigger>3 <AlertDialogContent>4 <AlertDialogTitle>Are you absolutely sure?</AlertDialogTitle>5 <AlertDialogDescription>6 This action cannot be undone. This will permanently delete your account7 and remove your data from our servers.8 </AlertDialogDescription>9 </AlertDialogContent>10</AlertDialog>