1
+ import { Fragment , useState } from 'react'
2
+ import { Dialog , Transition } from '@headlessui/react'
3
+
4
+ interface AddLinkDialogProps {
5
+ open : boolean
6
+ close ( ) : void
7
+ save ( url : string ) : void
8
+ }
9
+
10
+ export function AddLinkDialog ( { open, close, save } : AddLinkDialogProps ) {
11
+ const [ url , setUrl ] = useState < string > ( )
12
+
13
+ return (
14
+ < >
15
+ < Transition
16
+ show = { open }
17
+ enter = "transition duration-100 ease-out"
18
+ enterFrom = "transform scale-95 opacity-0"
19
+ enterTo = "transform scale-100 opacity-100"
20
+ leave = "transition duration-75 ease-out"
21
+ leaveFrom = "transform scale-100 opacity-100"
22
+ leaveTo = "transform scale-95 opacity-0"
23
+ >
24
+ < Dialog
25
+ as = "div"
26
+ className = "fixed inset-0 z-10 overflow-y-auto"
27
+ onClose = { close }
28
+ >
29
+ < div className = "min-h-screen px-4 text-center" >
30
+ < Transition . Child
31
+ as = { Fragment }
32
+ enter = "ease-out duration-300"
33
+ enterFrom = "opacity-0"
34
+ enterTo = "opacity-100"
35
+ leave = "ease-in duration-200"
36
+ leaveFrom = "opacity-100"
37
+ leaveTo = "opacity-0"
38
+ >
39
+ < Dialog . Overlay className = "fixed inset-0 bg-grey-100" />
40
+ </ Transition . Child >
41
+
42
+ { /* This element is to trick the browser into centering the modal contents. */ }
43
+ < span
44
+ className = "inline-block h-screen align-middle"
45
+ aria-hidden = "true"
46
+ >
47
+ ​
48
+ </ span >
49
+ < Transition . Child
50
+ as = { Fragment }
51
+ enter = "ease-out duration-300"
52
+ enterFrom = "opacity-0 scale-95"
53
+ enterTo = "opacity-100 scale-100"
54
+ leave = "ease-in duration-200"
55
+ leaveFrom = "opacity-100 scale-100"
56
+ leaveTo = "opacity-0 scale-95"
57
+ >
58
+ < div className = "inline-block w-full max-w-md p-6 my-8 overflow-hidden text-left align-middle transition-all transform bg-white shadow-xl rounded-2xl" >
59
+ < Dialog . Title
60
+ as = "h3"
61
+ className = "text-lg font-medium leading-6 text-gray-900"
62
+ >
63
+ Provider a Link
64
+ </ Dialog . Title >
65
+ < div className = "mt-2" >
66
+ < input
67
+ onChange = { e => setUrl ( e . target . value ) }
68
+ type = 'text'
69
+ placeholder = "Link"
70
+ className = "w-full bg-white rounded border border-gray-300 focus:border-indigo-500 focus:ring-2 focus:ring-indigo-200 text-base outline-none text-gray-700 py-1 px-3 leading-8 transition-colors duration-200 ease-in-out"
71
+ />
72
+ </ div >
73
+ < div className = "mt-4" >
74
+ < button
75
+ type = "button"
76
+ className = "inline-flex justify-center px-4 py-2 text-sm font-medium text-blue-900 bg-blue-100 border border-transparent rounded-md hover:bg-blue-200 focus:outline-none focus-visible:ring-2 focus-visible:ring-offset-2 focus-visible:ring-blue-500"
77
+ onClick = { ( ) => save ( url ) }
78
+ >
79
+ Save
80
+ </ button >
81
+ </ div >
82
+ </ div >
83
+ </ Transition . Child >
84
+ </ div >
85
+ </ Dialog >
86
+ </ Transition >
87
+ </ >
88
+ )
89
+ }
0 commit comments