- Add ListForm component for creating and editing lists with color picker - Add Modal component for reusable dialog functionality - Add DeleteListButton with confirmation dialog - Add NewListButton for creating new lists - Update ListCard to show edit/delete buttons on hover - Update home page to use new list creation flow - All components include proper error handling and loading states Requirements: 2.1, 2.2, 2.4, 2.5
72 lines
1.7 KiB
TypeScript
72 lines
1.7 KiB
TypeScript
'use client'
|
|
|
|
import { useEffect } from 'react'
|
|
import { X } from 'lucide-react'
|
|
|
|
interface ModalProps {
|
|
isOpen: boolean
|
|
onClose: () => void
|
|
title: string
|
|
children: React.ReactNode
|
|
}
|
|
|
|
export default function Modal({ isOpen, onClose, title, children }: ModalProps) {
|
|
useEffect(() => {
|
|
if (isOpen) {
|
|
document.body.style.overflow = 'hidden'
|
|
} else {
|
|
document.body.style.overflow = 'unset'
|
|
}
|
|
|
|
return () => {
|
|
document.body.style.overflow = 'unset'
|
|
}
|
|
}, [isOpen])
|
|
|
|
useEffect(() => {
|
|
const handleEscape = (e: KeyboardEvent) => {
|
|
if (e.key === 'Escape') {
|
|
onClose()
|
|
}
|
|
}
|
|
|
|
if (isOpen) {
|
|
document.addEventListener('keydown', handleEscape)
|
|
}
|
|
|
|
return () => {
|
|
document.removeEventListener('keydown', handleEscape)
|
|
}
|
|
}, [isOpen, onClose])
|
|
|
|
if (!isOpen) return null
|
|
|
|
return (
|
|
<div className="fixed inset-0 z-50 flex items-center justify-center">
|
|
{/* Backdrop */}
|
|
<div
|
|
className="absolute inset-0 bg-black bg-opacity-50"
|
|
onClick={onClose}
|
|
/>
|
|
|
|
{/* Modal */}
|
|
<div className="relative bg-white rounded-lg shadow-xl max-w-md w-full mx-4 max-h-[90vh] overflow-y-auto">
|
|
<div className="flex items-center justify-between p-4 border-b border-gray-200">
|
|
<h2 className="text-xl font-semibold text-gray-900">{title}</h2>
|
|
<button
|
|
onClick={onClose}
|
|
className="text-gray-400 hover:text-gray-600 transition-colors"
|
|
aria-label="Close modal"
|
|
>
|
|
<X size={24} />
|
|
</button>
|
|
</div>
|
|
|
|
<div className="p-4">
|
|
{children}
|
|
</div>
|
|
</div>
|
|
</div>
|
|
)
|
|
}
|