31 lines
853 B
TypeScript
31 lines
853 B
TypeScript
import { Dialog, DialogContent, DialogHeader, DialogTitle, DialogTrigger } from "@/components/ui/dialog";
|
|
import { Button } from "@/components/ui/button";
|
|
import { type ReactNode, useState } from "react";
|
|
|
|
interface FormDialogProps {
|
|
triggerLabel: string;
|
|
title: string;
|
|
children: (closeDialog: () => void) => ReactNode;
|
|
}
|
|
|
|
export function FormDialog({ triggerLabel, title, children }: FormDialogProps) {
|
|
const [isOpen, setIsOpen] = useState(false);
|
|
|
|
const closeDialog = () => setIsOpen(false);
|
|
|
|
return (
|
|
<Dialog open={isOpen} onOpenChange={setIsOpen}>
|
|
<DialogTrigger asChild>
|
|
<Button>{triggerLabel}</Button>
|
|
</DialogTrigger>
|
|
<DialogContent>
|
|
<DialogHeader>
|
|
<DialogTitle>{title}</DialogTitle>
|
|
</DialogHeader>
|
|
|
|
{children(closeDialog)}
|
|
</DialogContent>
|
|
</Dialog>
|
|
);
|
|
}
|