forge
Explore
Log in

Don't you dare go Hollow

hezarfen_frontend

Clone
★ 0

0 watching0 forksTypeScript5.5 MiBdcf123aBurak Boduroğlu2 months ago674 commits

form-dialog.tsx47 lines, 1.4 KiBHistoryRawDownload
1import type { JSX } from "solid-js";
2import {
3 Dialog,
4 DialogBody,
5 DialogContent,
6 DialogDescription,
7 DialogHeader,
8 DialogTitle,
9} from "@/components/ui/dialog";
10
11/**
12 * Form surface in a dialog. Closes only via the header X (or an in-body
13 * Cancel that calls onOpenChange(false)) — backdrop/ESC are off so a
14 * dismiss gesture cannot fall through onto the trigger and reopen the
15 * same dialog on mobile.
16 */
17export function FormDialog(props: {
18 open: boolean;
19 onOpenChange: (open: boolean) => void;
20 title: string;
21 description?: string;
22 children: JSX.Element;
23 class?: string;
24}) {
25 const handleOpenChange = (open: boolean) => {
26 if (open) {
27 props.onOpenChange(true);
28 return;
29 }
30 // Defer the close until after the current pointer/click finishes. Otherwise
31 // removing the dialog mid-gesture lets the same tap land on the trigger
32 // underneath (e.g. "From bank") and the dialog pops straight back open.
33 setTimeout(() => props.onOpenChange(false), 0);
34 };
35
36 return (
37 <Dialog open={props.open} onOpenChange={handleOpenChange}>
38 <DialogContent dismissable={false} class={props.class}>
39 <DialogHeader>
40 <DialogTitle>{props.title}</DialogTitle>
41 {props.description && <DialogDescription>{props.description}</DialogDescription>}
42 </DialogHeader>
43 <DialogBody class="side-panel-body">{props.children}</DialogBody>
44 </DialogContent>
45 </Dialog>
46 );
47}