Spaces:
Sleeping
Sleeping
Naufal Arhab
Feat: implement full mobile-friendly UX with slide-over drawer, responsive cards, and touch-optimized layout
a45d518 Download frontend/src/components/ui/Modal.tsx from agus1111/Perps-Terminal: direct link, hf CLI and curl.
- Browser
- Download file 2.25 kB
-
https://huggingface.co/spaces/agus1111/Perps-Terminal/resolve/main/frontend/src/components/ui/Modal.tsx
- Command line
-
hf download hf://spaces/agus1111/Perps-Terminal/frontend/src/components/ui/Modal.tsx
-
curl -L -o Modal.tsx https://huggingface.co/spaces/agus1111/Perps-Terminal/resolve/main/frontend/src/components/ui/Modal.tsx
2.25 kB
| import React, { useEffect, useCallback } from 'react'; | |
| import { X } from 'lucide-react'; | |
| import { clsx } from 'clsx'; | |
| import { twMerge } from 'tailwind-merge'; | |
| function cn(...inputs: Parameters<typeof clsx>) { | |
| return twMerge(clsx(inputs)); | |
| } | |
| interface ModalProps { | |
| isOpen: boolean; | |
| onClose: () => void; | |
| title: string; | |
| children: React.ReactNode; | |
| size?: 'sm' | 'md' | 'lg' | 'xl'; | |
| } | |
| const sizeStyles = { | |
| sm: 'max-w-sm', | |
| md: 'max-w-md', | |
| lg: 'max-w-2xl', | |
| xl: 'max-w-4xl', | |
| }; | |
| export function Modal({ isOpen, onClose, title, children, size = 'md' }: ModalProps) { | |
| const handleKeyDown = useCallback( | |
| (e: KeyboardEvent) => { | |
| if (e.key === 'Escape') onClose(); | |
| }, | |
| [onClose] | |
| ); | |
| useEffect(() => { | |
| if (isOpen) { | |
| document.addEventListener('keydown', handleKeyDown); | |
| document.body.style.overflow = 'hidden'; | |
| } | |
| return () => { | |
| document.removeEventListener('keydown', handleKeyDown); | |
| document.body.style.overflow = ''; | |
| }; | |
| }, [isOpen, handleKeyDown]); | |
| if (!isOpen) return null; | |
| return ( | |
| <div className="fixed inset-0 z-50 flex items-center justify-center p-3 sm:p-4"> | |
| {/* Backdrop */} | |
| <div | |
| className="absolute inset-0 bg-black/80 backdrop-blur-sm" | |
| onClick={onClose} | |
| /> | |
| {/* Panel */} | |
| <div | |
| className={cn( | |
| 'relative w-full max-h-[92vh] flex flex-col card shadow-2xl animate-fade-in my-auto', | |
| sizeStyles[size] | |
| )} | |
| onClick={(e) => e.stopPropagation()} | |
| > | |
| {/* Header */} | |
| <div className="shrink-0 flex items-center justify-between px-4 sm:px-6 py-3.5 sm:py-4 border-b border-border"> | |
| <h2 className="text-sm sm:text-base font-semibold text-text-primary truncate">{title}</h2> | |
| <button | |
| onClick={onClose} | |
| className="p-1.5 rounded-lg text-text-secondary hover:text-text-primary hover:bg-bg-elevated transition-colors ml-2 shrink-0" | |
| > | |
| <X size={16} /> | |
| </button> | |
| </div> | |
| {/* Body (Scrollable for mobile keyboards and small screens) */} | |
| <div className="flex-1 overflow-y-auto px-4 sm:px-6 py-4 sm:py-5 custom-scrollbar">{children}</div> | |
| </div> | |
| </div> | |
| ); | |
| } | |