forked from skillrecordings/egghead-next
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathDialog.tsx
More file actions
62 lines (59 loc) · 1.56 KB
/
Copy pathDialog.tsx
File metadata and controls
62 lines (59 loc) · 1.56 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import React, {FunctionComponent} from 'react'
import {DialogOverlay, DialogContent} from '@reach/dialog'
type DialogProps = {
children: React.ReactNode
ariaLabel: string
title: string
buttonText: string
buttonStyles: string
}
const Dialog: FunctionComponent<DialogProps> = ({
children,
ariaLabel,
title,
buttonText,
buttonStyles = '',
}) => {
const [showDialog, setShowDialog] = React.useState(false)
const open = () => setShowDialog(true)
const close = () => setShowDialog(false)
return (
<div>
<button onClick={open} className={buttonStyles}>
{buttonText}
</button>
<DialogOverlay isOpen={showDialog} onDismiss={close}>
<DialogContent
aria-label={ariaLabel}
className="bg-white rounded-md border-gray-400"
css={{padding: '2rem'}}
>
<div className="flex justify-center relative mb-6">
{title && <h3 className="text-xl font-medium">{title}</h3>}
<button onClick={close} className="absolute right-0 top-0">
<IconX className="w-5" />
</button>
</div>
{children}
</DialogContent>
</DialogOverlay>
</div>
)
}
export default Dialog
const IconX: FunctionComponent<{className?: string}> = ({className = ''}) => (
<svg
xmlns="http://www.w3.org/2000/svg"
fill="none"
viewBox="0 0 24 24"
stroke="currentColor"
className={className}
>
<path
strokeLinecap="round"
strokeLinejoin="round"
strokeWidth={2}
d="M6 18L18 6M6 6l12 12"
/>
</svg>
)