PluginProbe
Extendify / 0.3.0
Extendify v0.3.0
3.2.1 3.2.0 3.1.6 3.1.5 3.1.4 3.1.3 3.1.2 3.1.1 3.1.0 3.0.6 3.0.5 3.0.4 trunk 0.1.0 0.10.0 0.10.1 0.10.2 0.11.0 0.11.1 0.2.0 0.3.0 0.3.1 0.4.0 0.5.0 0.6.0 All 127 releases
extendify / src / components / modals / Modal.js

Modal.js in Extendify 0.3.0, at src/components/modals/Modal.js

76 lines 3.4 KB
No matching file
Up and down to move Enter to open Esc to close
Raw Download Zip
1 import { Dialog, Transition } from '@headlessui/react'
2 import { Fragment, useRef, forwardRef } from '@wordpress/element'
3 import { __ } from '@wordpress/i18n'
4 import { Icon, close } from '@wordpress/icons'
5 import { Button } from '@wordpress/components'
6 import { useGlobalStore } from '../../state/GlobalState'
7
8 export const Modal = forwardRef(
9 ({ isOpen, heading, onClose, children }, initialFocus) => {
10 const focusBackup = useRef(null)
11 const defaultClose = useGlobalStore((state) => state.removeAllModals)
12 onClose = onClose ?? defaultClose
13
14 return (
15 <Transition
16 appear
17 show={isOpen}
18 as={Fragment}
19 className="extendify">
20 <Dialog
21 initialFocus={initialFocus ?? focusBackup}
22 onClose={onClose}>
23 <div className="fixed z-high inset-0 flex">
24 <Transition.Child
25 as={Fragment}
26 enter="ease-out duration-200 transition"
27 enterFrom="opacity-0"
28 enterTo="opacity-100">
29 <Dialog.Overlay className="fixed inset-0 bg-white bg-opacity-40" />
30 </Transition.Child>
31 <Transition.Child
32 as={Fragment}
33 enter="ease-out duration-300 translate transform"
34 enterFrom="opacity-0 translate-y-4 sm:translate-y-5"
35 enterTo="opacity-100 translate-y-0">
36 <div className="m-auto relative w-full">
37 <div className="bg-white shadow-modal items-center justify-center m-auto max-w-lg relative rounded-sm w-full">
38 {heading ? (
39 <div className="border-b flex justify-between items-center leading-none pl-8 py-2 pr-3">
40 <span className="text-base text-extendify-black whitespace-nowrap">
41 {heading}
42 </span>
43 <CloseButton onClick={onClose} />
44 </div>
45 ) : (
46 <div className="absolute block px-4 py-4 top-0 right-0 ">
47 <CloseButton
48 ref={focusBackup}
49 onClick={onClose}
50 />
51 </div>
52 )}
53 <div>{children}</div>
54 </div>
55 </div>
56 </Transition.Child>
57 </div>
58 </Dialog>
59 </Transition>
60 )
61 },
62 )
63
64 const CloseButton = forwardRef((props, focusRef) => {
65 return (
66 <Button
67 {...props}
68 icon={<Icon icon={close} />}
69 ref={focusRef}
70 className="text-extendify-black opacity-75 hover:opacity-100"
71 showTooltip={false}
72 label={__('Close dialog', 'extendify')}
73 />
74 )
75 })
76