|
| 1 | +import React, { useState, Fragment } from 'react' |
| 2 | +import { Dialog, Transition } from '@headlessui/react' |
| 3 | + |
| 4 | +export default function Home() { |
| 5 | + let [isOpen, setIsOpen] = useState(false) |
| 6 | + |
| 7 | + return ( |
| 8 | + <> |
| 9 | + {Array(5) |
| 10 | + .fill(null) |
| 11 | + .map((_, i) => ( |
| 12 | + <p key={i} className="m-4"> |
| 13 | + Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam numquam beatae, |
| 14 | + maiores sint est perferendis molestiae deleniti dolorem, illum vel, quam atque facilis! |
| 15 | + Necessitatibus nostrum recusandae nemo corrupti, odio eius? |
| 16 | + </p> |
| 17 | + ))} |
| 18 | + |
| 19 | + <button |
| 20 | + type="button" |
| 21 | + onClick={() => setIsOpen((v) => !v)} |
| 22 | + className="focus:shadow-outline-blue m-12 rounded-md border border-gray-300 bg-white px-4 py-2 text-base font-medium leading-6 text-gray-700 shadow-sm transition duration-150 ease-in-out hover:text-gray-500 focus:border-blue-300 focus:outline-none sm:text-sm sm:leading-5" |
| 23 | + > |
| 24 | + Toggle! |
| 25 | + </button> |
| 26 | + |
| 27 | + {Array(20) |
| 28 | + .fill(null) |
| 29 | + .map((_, i) => ( |
| 30 | + <p key={i} className="m-4"> |
| 31 | + Lorem ipsum dolor sit amet consectetur adipisicing elit. Quisquam numquam beatae, |
| 32 | + maiores sint est perferendis molestiae deleniti dolorem, illum vel, quam atque facilis! |
| 33 | + Necessitatibus nostrum recusandae nemo corrupti, odio eius? |
| 34 | + </p> |
| 35 | + ))} |
| 36 | + |
| 37 | + <Transition |
| 38 | + data-debug="Dialog" |
| 39 | + show={isOpen} |
| 40 | + as={Fragment} |
| 41 | + beforeEnter={() => console.log('[Transition] Before enter')} |
| 42 | + afterEnter={() => console.log('[Transition] After enter')} |
| 43 | + beforeLeave={() => console.log('[Transition] Before leave')} |
| 44 | + afterLeave={() => console.log('[Transition] After leave')} |
| 45 | + > |
| 46 | + <Dialog |
| 47 | + onClose={() => { |
| 48 | + console.log('close') |
| 49 | + setIsOpen(false) |
| 50 | + }} |
| 51 | + > |
| 52 | + <div className="fixed inset-0 z-10 overflow-y-auto"> |
| 53 | + <div className="flex min-h-screen items-end justify-center px-4 pt-4 pb-20 text-center sm:block sm:p-0"> |
| 54 | + <Transition.Child |
| 55 | + as={Fragment} |
| 56 | + enter="ease-out duration-300" |
| 57 | + enterFrom="opacity-0" |
| 58 | + enterTo="opacity-75" |
| 59 | + leave="ease-in duration-200" |
| 60 | + leaveFrom="opacity-75" |
| 61 | + leaveTo="opacity-0" |
| 62 | + entered="opacity-75" |
| 63 | + beforeEnter={() => console.log('[Transition.Child] [Overlay] Before enter')} |
| 64 | + afterEnter={() => console.log('[Transition.Child] [Overlay] After enter')} |
| 65 | + beforeLeave={() => console.log('[Transition.Child] [Overlay] Before leave')} |
| 66 | + afterLeave={() => console.log('[Transition.Child] [Overlay] After leave')} |
| 67 | + > |
| 68 | + <div className="fixed inset-0 bg-gray-500 transition-opacity" /> |
| 69 | + </Transition.Child> |
| 70 | + |
| 71 | + <Transition.Child |
| 72 | + enter="ease-out transform duration-300" |
| 73 | + enterFrom="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95" |
| 74 | + enterTo="opacity-100 translate-y-0 sm:scale-100" |
| 75 | + leave="ease-in transform duration-200" |
| 76 | + leaveFrom="opacity-100 translate-y-0 sm:scale-100" |
| 77 | + leaveTo="opacity-0 translate-y-4 sm:translate-y-0 sm:scale-95" |
| 78 | + beforeEnter={() => console.log('[Transition.Child] [Panel] Before enter')} |
| 79 | + afterEnter={() => console.log('[Transition.Child] [Panel] After enter')} |
| 80 | + beforeLeave={() => console.log('[Transition.Child] [Panel] Before leave')} |
| 81 | + afterLeave={() => console.log('[Transition.Child] [Panel] After leave')} |
| 82 | + > |
| 83 | + {/* This element is to trick the browser into centering the modal contents. */} |
| 84 | + <span |
| 85 | + className="hidden sm:inline-block sm:h-screen sm:align-middle" |
| 86 | + aria-hidden="true" |
| 87 | + > |
| 88 | + ​ |
| 89 | + </span> |
| 90 | + <Dialog.Panel className="inline-block transform overflow-hidden rounded-lg bg-white text-left align-bottom shadow-xl transition-all sm:my-8 sm:w-full sm:max-w-lg sm:align-middle"> |
| 91 | + <div className="bg-white px-4 pt-5 pb-4 sm:p-6 sm:pb-4"> |
| 92 | + <div className="sm:flex sm:items-start"> |
| 93 | + <div className="mx-auto flex h-12 w-12 flex-shrink-0 items-center justify-center rounded-full bg-red-100 sm:mx-0 sm:h-10 sm:w-10"> |
| 94 | + {/* Heroicon name: exclamation */} |
| 95 | + <svg |
| 96 | + className="h-6 w-6 text-red-600" |
| 97 | + xmlns="http://www.w3.org/2000/svg" |
| 98 | + fill="none" |
| 99 | + viewBox="0 0 24 24" |
| 100 | + stroke="currentColor" |
| 101 | + aria-hidden="true" |
| 102 | + > |
| 103 | + <path |
| 104 | + strokeLinecap="round" |
| 105 | + strokeLinejoin="round" |
| 106 | + strokeWidth={2} |
| 107 | + d="M12 9v2m0 4h.01m-6.938 4h13.856c1.54 0 2.502-1.667 1.732-3L13.732 4c-.77-1.333-2.694-1.333-3.464 0L3.34 16c-.77 1.333.192 3 1.732 3z" |
| 108 | + /> |
| 109 | + </svg> |
| 110 | + </div> |
| 111 | + <div className="mt-3 text-center sm:mt-0 sm:ml-4 sm:text-left"> |
| 112 | + <Dialog.Title |
| 113 | + as="h3" |
| 114 | + className="text-lg font-medium leading-6 text-gray-900" |
| 115 | + > |
| 116 | + Deactivate account |
| 117 | + </Dialog.Title> |
| 118 | + <div className="mt-2"> |
| 119 | + <p className="text-sm text-gray-500"> |
| 120 | + Are you sure you want to deactivate your account? All of your data will |
| 121 | + be permanently removed. This action cannot be undone. |
| 122 | + </p> |
| 123 | + </div> |
| 124 | + <input type="text" /> |
| 125 | + </div> |
| 126 | + </div> |
| 127 | + </div> |
| 128 | + <div className="bg-gray-50 px-4 py-3 sm:flex sm:flex-row-reverse sm:px-6"> |
| 129 | + <button |
| 130 | + type="button" |
| 131 | + onClick={() => setIsOpen(false)} |
| 132 | + className="focus:shadow-outline-red inline-flex w-full justify-center rounded-md border border-transparent bg-red-600 px-4 py-2 text-base font-medium text-white shadow-sm hover:bg-red-700 focus:outline-none sm:ml-3 sm:w-auto sm:text-sm" |
| 133 | + > |
| 134 | + Deactivate |
| 135 | + </button> |
| 136 | + <button |
| 137 | + type="button" |
| 138 | + onClick={() => setIsOpen(false)} |
| 139 | + className="focus:shadow-outline-indigo mt-3 inline-flex w-full justify-center rounded-md border border-gray-300 bg-white px-4 py-2 text-base font-medium text-gray-700 shadow-sm hover:text-gray-500 focus:outline-none sm:mt-0 sm:w-auto sm:text-sm" |
| 140 | + > |
| 141 | + Cancel |
| 142 | + </button> |
| 143 | + </div> |
| 144 | + </Dialog.Panel> |
| 145 | + </Transition.Child> |
| 146 | + </div> |
| 147 | + </div> |
| 148 | + </Dialog> |
| 149 | + </Transition> |
| 150 | + </> |
| 151 | + ) |
| 152 | +} |
0 commit comments