feat(web): add Modal + EmptyState primitives and a11y hooks
- Modal: shared backdrop/panel with ESC-close, backdrop-click-close, focus trap, body scroll lock; supports center + drawer-right variants, matrix/violet accents, default/wide widths. - EmptyState: icon + title + hint + optional CTA; compact variant for tight rails. - useEscapeKey, useFocusTrap: reusable hooks powering Modal; will also be adopted by CommandPalette and ContextMenu in follow-up commits. No retrofits yet — primitives only. tsc clean.
This commit is contained in:
24
decnet_web/src/components/Modal/Modal.css
Normal file
24
decnet_web/src/components/Modal/Modal.css
Normal file
@@ -0,0 +1,24 @@
|
||||
/* Drawer-right variant: reuses .modal-backdrop + .modal base from DeckyFleet.css
|
||||
and shifts the panel to the right edge as a full-height side panel. */
|
||||
|
||||
.modal-backdrop.drawer {
|
||||
justify-content: flex-end;
|
||||
align-items: stretch;
|
||||
}
|
||||
|
||||
.modal.modal-drawer-right {
|
||||
width: 520px;
|
||||
max-width: 96vw;
|
||||
max-height: 100vh;
|
||||
height: 100vh;
|
||||
border-left: 1px solid var(--matrix);
|
||||
border-top: none;
|
||||
border-right: none;
|
||||
border-bottom: none;
|
||||
box-shadow: -8px 0 30px rgba(0, 0, 0, 0.6);
|
||||
}
|
||||
|
||||
.modal.modal-drawer-right.violet {
|
||||
border-left-color: var(--violet);
|
||||
box-shadow: -8px 0 30px rgba(238, 130, 238, 0.25);
|
||||
}
|
||||
85
decnet_web/src/components/Modal/Modal.tsx
Normal file
85
decnet_web/src/components/Modal/Modal.tsx
Normal file
@@ -0,0 +1,85 @@
|
||||
import React, { useEffect, useRef } from 'react';
|
||||
import { X, type LucideIcon } from 'lucide-react';
|
||||
import { useEscapeKey } from '../../hooks/useEscapeKey';
|
||||
import { useFocusTrap } from '../../hooks/useFocusTrap';
|
||||
import './Modal.css';
|
||||
|
||||
interface Props {
|
||||
open: boolean;
|
||||
onClose: () => void;
|
||||
title?: string;
|
||||
icon?: LucideIcon;
|
||||
footer?: React.ReactNode;
|
||||
accent?: 'matrix' | 'violet';
|
||||
width?: 'default' | 'wide';
|
||||
variant?: 'center' | 'drawer-right';
|
||||
children: React.ReactNode;
|
||||
className?: string;
|
||||
}
|
||||
|
||||
const Modal: React.FC<Props> = ({
|
||||
open,
|
||||
onClose,
|
||||
title,
|
||||
icon: Icon,
|
||||
footer,
|
||||
accent = 'matrix',
|
||||
width = 'default',
|
||||
variant = 'center',
|
||||
children,
|
||||
className = '',
|
||||
}) => {
|
||||
const panelRef = useRef<HTMLDivElement | null>(null);
|
||||
|
||||
useEscapeKey(onClose, open);
|
||||
useFocusTrap(panelRef, open);
|
||||
|
||||
useEffect(() => {
|
||||
if (!open) return;
|
||||
const prev = document.body.style.overflow;
|
||||
document.body.style.overflow = 'hidden';
|
||||
return () => {
|
||||
document.body.style.overflow = prev;
|
||||
};
|
||||
}, [open]);
|
||||
|
||||
if (!open) return null;
|
||||
|
||||
const panelClasses = [
|
||||
'modal',
|
||||
accent === 'violet' ? 'violet' : '',
|
||||
width === 'wide' ? 'wide' : '',
|
||||
variant === 'drawer-right' ? 'modal-drawer-right' : '',
|
||||
className,
|
||||
].filter(Boolean).join(' ');
|
||||
|
||||
const backdropClass = variant === 'drawer-right' ? 'modal-backdrop drawer' : 'modal-backdrop';
|
||||
|
||||
return (
|
||||
<div className={backdropClass} onClick={onClose}>
|
||||
<div
|
||||
ref={panelRef}
|
||||
className={panelClasses}
|
||||
onClick={(e) => e.stopPropagation()}
|
||||
role="dialog"
|
||||
aria-modal="true"
|
||||
>
|
||||
{title && (
|
||||
<div className="modal-head">
|
||||
<h3>
|
||||
{Icon && <Icon size={14} />}
|
||||
{title}
|
||||
</h3>
|
||||
<button className="close-btn" onClick={onClose} aria-label="Close">
|
||||
<X size={16} />
|
||||
</button>
|
||||
</div>
|
||||
)}
|
||||
{children}
|
||||
{footer && <div className="modal-foot">{footer}</div>}
|
||||
</div>
|
||||
</div>
|
||||
);
|
||||
};
|
||||
|
||||
export default Modal;
|
||||
Reference in New Issue
Block a user