Core@paxeer/core/dialogimplemented
Dialog
Modal dialog primitive. Registry id is dialog — never modal or sheet.
Install
$
pnpm exec designx add @paxeer/core/dialogPreview
Loading preview...
Source code
components/designx/core/dialog.tsxtsx
"use client";
import { type ComponentProps } from "react";
import { XIcon } from "lucide-react";
import { Dialog as DialogPrimitive } from "radix-ui";
import { cn } from "../lib/cn";
import { Button } from "./button";
/** Adapted from shadcn/ui Dialog. Registry id stays `dialog`. */
function Dialog({ ...props }: ComponentProps<typeof DialogPrimitive.Root>) {
return <DialogPrimitive.Root data-slot="dialog" {...props} />;
}
function DialogTrigger({ ...props }: ComponentProps<typeof DialogPrimitive.Trigger>) {
return <DialogPrimitive.Trigger data-slot="dialog-trigger" {...props} />;
}
function DialogPortal({ ...props }: ComponentProps<typeof DialogPrimitive.Portal>) {
return <DialogPrimitive.Portal data-slot="dialog-portal" {...props} />;
}
function DialogClose({ ...props }: ComponentProps<typeof DialogPrimitive.Close>) {
return <DialogPrimitive.Close data-slot="dialog-close" {...props} />;
}
function DialogOverlay({
className,
...props
}: ComponentProps<typeof DialogPrimitive.Overlay>) {
return (
<DialogPrimitive.Overlay
data-slot="dialog-overlay"
className={cn("fixed inset-0 z-50 bg-scrim/40", className)}
{...props}
/>
);
}
function DialogContent({
className,
children,
showCloseButton = true,
...props
}: ComponentProps<typeof DialogPrimitive.Content> & {
showCloseButton?: boolean;
}) {
return (
<DialogPortal>
<DialogOverlay />
<DialogPrimitive.Content
data-slot="dialog"
className={cn(
"dx-focus-ring fixed top-1/2 left-1/2 z-50 grid w-[min(100vw-2rem,40rem)] -translate-x-1/2 -translate-y-1/2 gap-4 rounded-[var(--md-sys-shape-corner-large)] border border-outline-variant bg-surface-container-high p-6 text-on-surface shadow-lg",
className,
)}
{...props}
>
{children}
{showCloseButton ? (
<DialogPrimitive.Close
data-slot="dialog-close"
className="dx-focus-ring absolute top-4 right-4 rounded-[var(--md-sys-shape-corner-extra-small)] text-on-surface-variant opacity-70 hover:opacity-100"
>
<XIcon />
<span className="sr-only">Close</span>
</DialogPrimitive.Close>
) : null}
</DialogPrimitive.Content>
</DialogPortal>
);
}
function DialogHeader({ className, ...props }: ComponentProps<"div">) {
return (
<div
data-slot="dialog-header"
className={cn("flex flex-col gap-2 text-center sm:text-left", className)}
{...props}
/>
);
}
function DialogFooter({
className,
showCloseButton = false,
children,
...props
}: ComponentProps<"div"> & { showCloseButton?: boolean }) {
return (
<div
data-slot="dialog-footer"
className={cn("flex flex-col-reverse gap-2 sm:flex-row sm:justify-end", className)}
{...props}
>
{children}
{showCloseButton ? (
<DialogPrimitive.Close asChild>
<Button variant="outlined">Close</Button>
</DialogPrimitive.Close>
) : null}
</div>
);
}
function DialogTitle({
className,
...props
}: ComponentProps<typeof DialogPrimitive.Title>) {
return (
<DialogPrimitive.Title
data-slot="dialog-title"
className={cn(
"text-[length:var(--md-sys-typescale-title-large-size)] leading-none font-medium",
className,
)}
{...props}
/>
);
}
function DialogDescription({
className,
...props
}: ComponentProps<typeof DialogPrimitive.Description>) {
return (
<DialogPrimitive.Description
data-slot="dialog-description"
className={cn(
"text-[length:var(--md-sys-typescale-body-medium-size)] text-on-surface-variant",
className,
)}
{...props}
/>
);
}
export {
Dialog,
DialogClose,
DialogContent,
DialogDescription,
DialogFooter,
DialogHeader,
DialogOverlay,
DialogPortal,
DialogTitle,
DialogTrigger,
};
Dependencies
npm packages
radix-uilucide-react
Registry dependencies