File size: 3,001 Bytes
909007e
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
import { Dialog, DialogPanel, DialogTitle, Transition, TransitionChild } from "@headlessui/react";
import { Fragment, ReactNode } from "react";
import { X } from "lucide-react";

interface FormDrawerProps {
  isOpen: boolean;
  onClose: () => void;
  title: string;
  subtitle?: string;
  children: ReactNode;
  maxWidth?: string;
}

export default function FormDrawer({

  isOpen,

  onClose,

  title,

  subtitle,

  children,

  maxWidth = "max-w-xl",

}: FormDrawerProps) {
  return (
    <Transition show={isOpen} as={Fragment}>

      <Dialog as="div" className="relative z-50" onClose={onClose}>

        <TransitionChild

          as={Fragment}

          enter="ease-in-out duration-300"

          enterFrom="opacity-0"

          enterTo="opacity-100"

          leave="ease-in-out duration-300"

          leaveFrom="opacity-100"

          leaveTo="opacity-0"

        >

          <div className="fixed inset-0 bg-black/70 backdrop-blur-xs transition-opacity" />

        </TransitionChild>



        <div className="fixed inset-0 overflow-hidden">

          <div className="absolute inset-0 overflow-hidden">

            <div className="pointer-events-none fixed inset-y-0 right-0 flex max-w-full pl-10">

              <TransitionChild

                as={Fragment}

                enter="transform transition ease-in-out duration-300 sm:duration-400"

                enterFrom="translate-x-full"

                enterTo="translate-x-0"

                leave="transform transition ease-in-out duration-300 sm:duration-400"

                leaveFrom="translate-x-0"

                leaveTo="translate-x-full"

              >

                <DialogPanel className={`pointer-events-auto w-screen ${maxWidth}`}>

                  <div className="flex h-full flex-col overflow-y-auto bg-zinc-950 border-l border-zinc-800 shadow-2xl">

                    <div className="px-6 py-5 border-b border-zinc-800 bg-zinc-900/50 flex items-center justify-between sticky top-0 z-10">

                      <div>

                        <DialogTitle className="text-lg font-semibold text-zinc-100">

                          {title}

                        </DialogTitle>

                        {subtitle && (

                          <p className="text-xs text-zinc-400 mt-0.5">{subtitle}</p>

                        )}

                      </div>

                      <button

                        onClick={onClose}

                        className="rounded-lg p-2 text-zinc-400 hover:text-zinc-100 hover:bg-zinc-800 transition-colors"

                      >

                        <X className="w-5 h-5" />

                      </button>

                    </div>



                    <div className="flex-1 px-6 py-6 space-y-6">{children}</div>

                  </div>

                </DialogPanel>

              </TransitionChild>

            </div>

          </div>

        </div>

      </Dialog>

    </Transition>
  );
}