showing results for - "popup model in tailwind css"
Skylar
04 Mar 2020
1/* This example requires Tailwind CSS v2.0+ */
2import { Fragment, useRef, useState } from 'react'
3import { Dialog, Transition } from '@headlessui/react'
4import { ExclamationIcon } from '@heroicons/react/outline'
5
6export default function Example() {
7  const [open, setOpen] = useState(true)
8
9  const cancelButtonRef = useRef(null)
10
11  return (
12    <Transition.Root show={open} as={Fragment}>
13      <Dialog
14        as="div"
15        static
16        className="fixed z-10 inset-0 overflow-y-auto"
17        initialFocus={cancelButtonRef}
18        open={open}
19        onClose={setOpen}
20      >
21        <div className="flex items-end justify-center min-h-screen pt-4 px-4 pb-20 text-center sm:block sm:p-0">
22          <Transition.Child
23            as={Fragment}
24            enter="ease-out duration-300"
25            enterFrom="opacity-0"
26            enterTo="opacity-100"
27            leave="ease-in duration-200"
28            leaveFrom="opacity-100"
29            leaveTo="opacity-0"
30          >
31            <Dialog.Overlay className="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity" />
32          </Transition.Child>
33
34          {/* This element is to trick the browser into centering the modal contents. */}
35          <span className="hidden sm:inline-block sm:align-middle sm:h-screen" aria-hidden="true">
3637          </span>
38          <Transition.Child
39            as={Fragment}
40            enter="ease-out duration-300"
41            enterFrom="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
42            enterTo="opacity-100 translate-y-0 sm:scale-100"
43            leave="ease-in duration-200"
44            leaveFrom="opacity-100 translate-y-0 sm:scale-100"
45            leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95"
46          >
47            <div className="inline-block align-bottom bg-white rounded-lg text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:align-middle sm:max-w-lg sm:w-full">
48              <div className="bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4">
49                <div className="sm:flex sm:items-start">
50                  <div className="mx-auto flex-shrink-0 flex items-center justify-center h-12 w-12 rounded-full bg-red-100 sm:mx-0 sm:h-10 sm:w-10">
51                    <ExclamationIcon className="h-6 w-6 text-red-600" aria-hidden="true" />
52                  </div>
53                  <div className="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left">
54                    <Dialog.Title as="h3" className="text-lg leading-6 font-medium text-gray-900">
55                      Deactivate account
56                    </Dialog.Title>
57                    <div className="mt-2">
58                      <p className="text-sm text-gray-500">
59                        Are you sure you want to deactivate your account? All of your data will be permanently removed.
60                        This action cannot be undone.
61                      </p>
62                    </div>
63                  </div>
64                </div>
65              </div>
66              <div className="bg-gray-50 px-4 py-3 sm:px-6 sm:flex sm:flex-row-reverse">
67                <button
68                  type="button"
69                  className="w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-red-600 text-base font-medium text-white hover:bg-red-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-red-500 sm:ml-3 sm:w-auto sm:text-sm"
70                  onClick={() => setOpen(false)}
71                >
72                  Deactivate
73                </button>
74                <button
75                  type="button"
76                  className="mt-3 w-full inline-flex justify-center rounded-md border border-gray-300 shadow-sm px-4 py-2 bg-white text-base font-medium text-gray-700 hover:bg-gray-50 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 sm:mt-0 sm:ml-3 sm:w-auto sm:text-sm"
77                  onClick={() => setOpen(false)}
78                  ref={cancelButtonRef}
79                >
80                  Cancel
81                </button>
82              </div>
83            </div>
84          </Transition.Child>
85        </div>
86      </Dialog>
87    </Transition.Root>
88  )
89}
90
similar questions
queries leading to this page
popup model in tailwind css