"use client"; import { Button } from "@suphark/ui/components/shared/button/button"; import { Dialog, DialogClose, DialogContent, DialogDescription, DialogFooter, DialogHeader, DialogTitle, DialogTrigger, } from "@suphark/ui/components/ui/dialog"; import { Sheet, SheetClose, SheetContent, SheetDescription, SheetFooter, SheetHeader, SheetTitle, SheetTrigger, } from "@suphark/ui/components/ui/sheet"; import { useLazyDrawer } from "@suphark/ui/hooks/use-lazy-drawer"; import { cn } from "@suphark/ui/lib/utils"; import { XIcon } from "lucide-react"; import { type ReactElement, type ReactNode, useState } from "react"; import { useUiText } from "./ui-text"; const DIALOG_SIZE = { sm: "sm:max-w-sm", md: "sm:max-w-md", lg: "sm:max-w-lg", xl: "sm:max-w-2xl", full: "sm:max-w-[min(64rem,calc(100%-2rem))]", } as const; interface SimpleOverlayProps { /** ปุ่มเปิด (เช่น `} title="ใบสั่งซื้อ PO-001" size="lg"> * …เนื้อหา… * */ export function SimpleDialog({ trigger, title, description, children, footer, open, onOpenChange, hideClose = false, size = "md", className, }: SimpleOverlayProps & { /** ความกว้างบนจอ ≥ sm (มือถือเต็มจอลบขอบเสมอ) */ size?: keyof typeof DIALOG_SIZE; }) { const text = useUiText(); const [isOpen, setOpen] = useOpenState(open, onOpenChange); const close = () => setOpen(false); return ( {trigger && } {title} {description && {description}} {children !== undefined && (
{children}
)} {footer && ( {typeof footer === "function" ? footer(close) : footer} )} {!hideClose && ( } > {text.close ?? "ปิด"} )}
); } /** * แผงเลื่อนจากขอบจอสำเร็จรูป (ตัวกรองขั้นสูง, รายละเอียดแถว, ฟอร์มยาว) — props เดียวกับ SimpleDialog + `side` * เนื้อหาเลื่อนได้ หัว/ท้ายตรึง */ export function SimpleSheet({ trigger, title, description, children, footer, open, onOpenChange, hideClose = false, side = "right", size, className, }: SimpleOverlayProps & { side?: "right" | "left" | "top" | "bottom"; /** ความกว้างของแผงซ้าย/ขวาบนจอ ≥ sm (ไม่ส่ง = sm 384px) — ขนาดเดียวกับ SimpleDialog `size` */ size?: keyof typeof DIALOG_SIZE; }) { const text = useUiText(); const [isOpen, setOpen] = useOpenState(open, onOpenChange); const close = () => setOpen(false); return ( {trigger && } {title} {description && {description}}
{children}
{footer && ( {typeof footer === "function" ? footer(close) : footer} )} {!hideClose && ( } > {text.close ?? "ปิด"} )}
); } /** * แผ่นล่างปัดปิดได้สำเร็จรูป (เมนูและฟอร์มสั้นบนมือถือ) — props เดียวกับ SimpleDialog ปัดลง/กดนอกแผ่น = ปิด * Drawer โหลดเมื่อใช้ (`useLazyDrawer`) ระหว่างโหลดแสดง `SimpleSheet side="bottom"` หน้าตาเดียวกัน * ไม่ต้องปัด (จอกว้าง/แผงข้าง) ใช้ `SimpleSheet` */ export function SimpleDrawer({ trigger, title, description, children, footer, open, onOpenChange, className, }: Omit) { const [isOpen, setOpen] = useOpenState(open, onOpenChange); const parts = useLazyDrawer(true); const close = () => setOpen(false); if (!parts) { return ( {children} ); } const { Drawer, DrawerContent, DrawerDescription, DrawerFooter, DrawerHeader, DrawerTitle, DrawerTrigger, } = parts; return ( {trigger && } {title} {description && {description}} {children !== undefined && (
{children}
)} {footer && ( {typeof footer === "function" ? footer(close) : footer} )}
); }