import { Button } from "@repo/shadcn-ui/components/button"; import { Dialog, DialogClose, DialogContent, DialogFooter, DialogHeader, DialogTitle, } from "@repo/shadcn-ui/components/dialog"; import { type ReactNode, createContext, useContext } from "react"; const FormLayoutContext = createContext<"content" | "picker">("content"); const FormCancelContext = createContext(undefined); export function FormDialog({ open, onOpenChange, title, cancelLabel, children, wide = false, size, formActions = false, layout = "content", }: { open: boolean; onOpenChange: (open: boolean) => void; title: ReactNode; cancelLabel: string; children: ReactNode; wide?: boolean; size?: "small" | "medium" | "large"; formActions?: boolean; layout?: "content" | "picker"; }) { const width = size ?? (wide ? "large" : "small"); const widths = { small: "sm:max-w-xl", medium: "sm:max-w-3xl", large: "sm:w-[90vw] sm:max-w-[1200px]", }; const height = layout === "picker" ? "h-[calc(100dvh-2rem)] sm:h-[min(85dvh,900px)]" : ""; return ( {title}
{children}
{!formActions && ( }> {cancelLabel} )}
); } export function FormActions({ children, leadingActions, cancelDisabled = false, }: { children: ReactNode; leadingActions?: ReactNode; cancelDisabled?: boolean; }) { const cancelLabel = useContext(FormCancelContext); return ( {leadingActions &&
{leadingActions}
} {cancelLabel && ( }> {cancelLabel} )} {children}
); } /** El cuerpo reserva espacio simétrico para que el scroll no recorte el anillo de foco. */ export function FormBody({ children }: { children: ReactNode }) { const layout = useContext(FormLayoutContext); return (
*]:shrink-0" : "@container min-h-0 flex-1 space-y-5 overflow-y-auto px-1 pt-1 pb-5" } data-slot="form-body" > {children}
); }