-
Notifications
You must be signed in to change notification settings - Fork 10
Expand file tree
/
Copy pathmodal.tsx
More file actions
63 lines (59 loc) · 1.42 KB
/
modal.tsx
File metadata and controls
63 lines (59 loc) · 1.42 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
63
import { Card, Heading, VisuallyHidden } from 'ui';
import { type ReactNode, useId } from 'react';
import { XMarkIcon } from '@heroicons/react/24/outline';
type ModalProps = {
title: string;
children: ReactNode;
isOpen: boolean;
closeHandler: () => void;
};
export const Modal = ({
title,
children,
isOpen,
closeHandler,
}: ModalProps) => {
const id = useId();
const onClickHandler = () => {
closeHandler();
};
if (!isOpen) {
return null;
}
return (
<div
id={id}
className="fixed top-0 left-0 z-20 flex h-screen w-screen items-center justify-center bg-white/80"
role="modal"
aria-modal
aria-labelledby={`${id}-title`}
>
<div
onClick={onClickHandler}
className="absolute top-0 left-0 z-10 h-full w-full"
></div>
<div className="z-40 mx-auto w-11/12 max-w-7xl bg-white">
<Card tag="div">
<div className="flex flex-col items-center justify-between border-b border-gray-200 pt-3 pb-6 md:flex-row">
<Heading
tag="h2"
size="large"
className="order-2 text-center text-4xl font-bold tracking-tight text-gray-900 md:order-1 md:pr-20 md:text-left"
id={`${id}-title`}
>
{title}
</Heading>
<button
className="absolute top-4 right-4 h-8 w-8"
onClick={onClickHandler}
>
<XMarkIcon />
<VisuallyHidden>zamknij modal</VisuallyHidden>
</button>
</div>
{children}
</Card>
</div>
</div>
);
};