source: chapterx-frontend/src/components/ui/Modal.tsx@ a6e33d1

main
Last change on this file since a6e33d1 was b62cefc, checked in by kikisrbinoska <srbinoskakristina07@…>, 4 months ago

Added frontend and imporoved AI Suggestions service

  • Property mode set to 100644
File size: 1.9 KB
Line 
1import React, { useEffect } from 'react'
2import { X } from 'lucide-react'
3
4interface ModalProps {
5 isOpen: boolean
6 onClose: () => void
7 title?: string
8 children: React.ReactNode
9 size?: 'sm' | 'md' | 'lg' | 'xl'
10}
11
12const sizeMap = {
13 sm: 'max-w-sm',
14 md: 'max-w-md',
15 lg: 'max-w-lg',
16 xl: 'max-w-2xl',
17}
18
19export const Modal: React.FC<ModalProps> = ({
20 isOpen,
21 onClose,
22 title,
23 children,
24 size = 'md',
25}) => {
26 useEffect(() => {
27 const handler = (e: KeyboardEvent) => {
28 if (e.key === 'Escape') onClose()
29 }
30 if (isOpen) document.addEventListener('keydown', handler)
31 return () => document.removeEventListener('keydown', handler)
32 }, [isOpen, onClose])
33
34 if (!isOpen) return null
35
36 return (
37 <div className="fixed inset-0 z-50 flex items-center justify-center p-4">
38 <div
39 className="absolute inset-0 bg-black/70 backdrop-blur-sm"
40 onClick={onClose}
41 />
42 <div
43 className={`relative w-full ${sizeMap[size]} bg-slate-900 border border-slate-700 rounded-2xl shadow-2xl z-10 max-h-[90vh] overflow-y-auto`}
44 >
45 {title && (
46 <div className="flex items-center justify-between p-6 border-b border-slate-700">
47 <h2 className="text-lg font-semibold text-white font-serif">{title}</h2>
48 <button
49 onClick={onClose}
50 className="p-1.5 text-slate-400 hover:text-white hover:bg-slate-700 rounded-lg transition-colors"
51 >
52 <X size={18} />
53 </button>
54 </div>
55 )}
56 {!title && (
57 <button
58 onClick={onClose}
59 className="absolute top-4 right-4 p-1.5 text-slate-400 hover:text-white hover:bg-slate-700 rounded-lg transition-colors z-10"
60 >
61 <X size={18} />
62 </button>
63 )}
64 <div className="p-6">{children}</div>
65 </div>
66 </div>
67 )
68}
Note: See TracBrowser for help on using the repository browser.