Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

2.4 KB
Raw Blame
import { Dialog as BaseDialog } from "@base-ui/react/dialog";
import type { ComponentProps } from "react";
import { cn } from "@/lib/utils";
import {
  getLayerRoot,
  LAYER_BACKDROP_CLASS,
  LAYER_SURFACE_CLASS,
  usePreserveHigherLayerAccess,
} from "./layer";

// ---- Root ----
const Dialog = BaseDialog.Root;

// ---- Trigger ----
const DialogTrigger = BaseDialog.Trigger;

// ---- Overlay / Backdrop ----
function DialogOverlay({
  className,
  ref,
  ...props
}: ComponentProps<typeof BaseDialog.Backdrop>) {
  return (
    <BaseDialog.Backdrop
      ref={ref}
      className={cn(
        `fixed inset-0 ${LAYER_BACKDROP_CLASS} bg-overlay/50`,
        className
      )}
      {...props}
    />
  );
}

// ---- Content / Popup ----
function DialogContent({
  className,
  children,
  ref,
  ...props
}: ComponentProps<typeof BaseDialog.Popup>) {
  usePreserveHigherLayerAccess("overlay");

  return (
    <BaseDialog.Portal container={getLayerRoot("overlay")}>
      <DialogOverlay />
      <BaseDialog.Popup
        ref={ref}
        className={cn(
          `fixed left-1/2 top-1/2 ${LAYER_SURFACE_CLASS} -translate-x-1/2 -translate-y-1/2`,
          // Single max-w utility (no responsive variant) so a caller's
          // max-w-* fully replaces it via tailwind-merge; a 2xl: variant
          // here would survive the merge and win the cascade on wide
          // screens, silently overriding the caller's width.
          "w-[calc(100vw-8rem)] max-w-[max(48rem,55vw)]",
          "max-h-[calc(100vh-10rem)] overflow-y-auto",
          "rounded-sm bg-background p-6 shadow-lg",
          className
        )}
        {...props}
      >
        {children}
      </BaseDialog.Popup>
    </BaseDialog.Portal>
  );
}

// ---- Title ----
function DialogTitle({
  className,
  ref,
  ...props
}: ComponentProps<typeof BaseDialog.Title>) {
  return (
    <BaseDialog.Title
      ref={ref}
      className={cn("text-lg font-semibold", className)}
      {...props}
    />
  );
}

// ---- Description ----
function DialogDescription({
  className,
  ref,
  ...props
}: ComponentProps<typeof BaseDialog.Description>) {
  return (
    <BaseDialog.Description
      ref={ref}
      className={cn("text-sm text-control-light", className)}
      {...props}
    />
  );
}

// ---- Close ----
const DialogClose = BaseDialog.Close;

export {
  Dialog,
  DialogClose,
  DialogContent,
  DialogDescription,
  DialogOverlay,
  DialogTitle,
  DialogTrigger,
};