-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathBrutalistModal.jsx
More file actions
77 lines (69 loc) · 2.5 KB
/
BrutalistModal.jsx
File metadata and controls
77 lines (69 loc) · 2.5 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
64
65
66
67
68
69
70
71
72
73
74
75
76
77
import React, { useEffect } from 'react';
import { motion, AnimatePresence } from 'framer-motion';
import { XIcon } from '@phosphor-icons/react';
const BrutalistModal = ({
isOpen,
onClose,
title,
children,
maxWidth = 'max-w-xl',
}) => {
useEffect(() => {
const handleKeyDown = (event) => {
if (event.key === 'Escape' && isOpen) {
onClose();
}
};
if (isOpen) {
document.addEventListener('keydown', handleKeyDown);
document.body.style.overflow = 'hidden';
} else {
document.removeEventListener('keydown', handleKeyDown);
document.body.style.overflow = '';
}
return () => {
document.removeEventListener('keydown', handleKeyDown);
document.body.style.overflow = '';
};
}, [isOpen, onClose]);
return (
<AnimatePresence>
{isOpen && (
<div className="fixed inset-0 z-[1000] flex items-center justify-center p-4">
<motion.div
initial={{ opacity: 0 }}
animate={{ opacity: 1 }}
exit={{ opacity: 0 }}
onClick={onClose}
className="absolute inset-0 bg-black/80 backdrop-blur-sm"
/>
<motion.div
initial={{ opacity: 0, scale: 0.95, y: 20 }}
animate={{ opacity: 1, scale: 1, y: 0 }}
exit={{ opacity: 0, scale: 0.95, y: 20 }}
transition={{ duration: 0.3, ease: [0.23, 1, 0.32, 1] }}
className={`relative w-full ${maxWidth} bg-[#050505] border border-white/10 rounded-sm shadow-2xl overflow-hidden flex flex-col`}
onClick={(e) => e.stopPropagation()}
>
<div className="flex items-center justify-between p-6 border-b border-white/10 bg-white/[0.02]">
<h2 className="text-2xl font-black uppercase tracking-tighter text-white">
{title}
</h2>
<button
onClick={onClose}
className="p-2 text-gray-500 hover:text-emerald-500 hover:bg-white/5 rounded-sm transition-all"
>
<XIcon size={24} weight="bold" />
</button>
</div>
<div className="p-8 max-h-[70vh] overflow-y-auto scrollbar-hide text-gray-300 font-mono text-sm leading-relaxed">
{children}
</div>
<div className="h-1 w-full bg-gradient-to-r from-emerald-500/0 via-emerald-500/50 to-emerald-500/0 opacity-30" />
</motion.div>
</div>
)}
</AnimatePresence>
);
};
export default BrutalistModal;