Created
May 17, 2022 22:23
-
-
Save dangdennis/d0f0b5a6a4ab42581d3f63e271826ce3 to your computer and use it in GitHub Desktop.
Tailwind modal centered with wide buttons
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* This example requires Tailwind CSS v2.0+ */ | |
import { Fragment, useRef, useState } from 'react' | |
import { Dialog, Transition } from '@headlessui/react' | |
import { CheckIcon } from '@heroicons/react/outline' | |
export default function Example() { | |
const [open, setOpen] = useState(true) | |
const cancelButtonRef = useRef(null) | |
return ( | |
<Transition.Root show={open} as={Fragment}> | |
<Dialog as="div" className="relative z-10" initialFocus={cancelButtonRef} onClose={setOpen}> | |
<Transition.Child | |
as={Fragment} | |
enter="ease-out duration-300" | |
enterFrom="opacity-0" | |
enterTo="opacity-100" | |
leave="ease-in duration-200" | |
leaveFrom="opacity-100" | |
leaveTo="opacity-0" | |
> | |
<div className="fixed inset-0 bg-gray-500 bg-opacity-75 transition-opacity" /> | |
</Transition.Child> | |
<div className="fixed z-10 inset-0 overflow-y-auto"> | |
<div className="flex items-end sm:items-center justify-center min-h-full p-4 text-center sm:p-0"> | |
<Transition.Child | |
as={Fragment} | |
enter="ease-out duration-300" | |
enterFrom="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95" | |
enterTo="opacity-100 translate-y-0 sm:scale-100" | |
leave="ease-in duration-200" | |
leaveFrom="opacity-100 translate-y-0 sm:scale-100" | |
leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95" | |
> | |
<Dialog.Panel className="relative bg-white rounded-lg px-4 pt-5 pb-4 text-left overflow-hidden shadow-xl transform transition-all sm:my-8 sm:max-w-lg sm:w-full sm:p-6"> | |
<div> | |
<div className="mx-auto flex items-center justify-center h-12 w-12 rounded-full bg-green-100"> | |
<CheckIcon className="h-6 w-6 text-green-600" aria-hidden="true" /> | |
</div> | |
<div className="mt-3 text-center sm:mt-5"> | |
<Dialog.Title as="h3" className="text-lg leading-6 font-medium text-gray-900"> | |
Payment successful | |
</Dialog.Title> | |
<div className="mt-2"> | |
<p className="text-sm text-gray-500"> | |
Lorem ipsum, dolor sit amet consectetur adipisicing elit. Eius aliquam laudantium explicabo | |
pariatur iste dolorem animi vitae error totam. At sapiente aliquam accusamus facere veritatis. | |
</p> | |
</div> | |
</div> | |
</div> | |
<div className="mt-5 sm:mt-6 sm:grid sm:grid-cols-2 sm:gap-3 sm:grid-flow-row-dense"> | |
<button | |
type="button" | |
className="w-full inline-flex justify-center rounded-md border border-transparent shadow-sm px-4 py-2 bg-indigo-600 text-base font-medium text-white hover:bg-indigo-700 focus:outline-none focus:ring-2 focus:ring-offset-2 focus:ring-indigo-500 sm:col-start-2 sm:text-sm" | |
onClick={() => setOpen(false)} | |
> | |
Deactivate | |
</button> | |
<button | |
type="button" | |
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:col-start-1 sm:text-sm" | |
onClick={() => setOpen(false)} | |
ref={cancelButtonRef} | |
> | |
Cancel | |
</button> | |
</div> | |
</Dialog.Panel> | |
</Transition.Child> | |
</div> | |
</div> | |
</Dialog> | |
</Transition.Root> | |
) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment