Files
dt-design-system/packages/react/src/components/DTModal.tsx
michael e74c285b70 Add storefront component migration: cards, badges, progress bars, animations, and React wrapper package
Major feature migration from dt-shopify-storefront into the design system:

- Card system: per-card color modes (normal/emphasis/warning/success/other),
  progress bars, full-bleed card body (card-body-flush), image bevel clip-paths,
  and visible structural borders at bevel corners
- Badge system: dt-card-badge with position-aware offsets for cards vs media frames
- Media frames: dt-bevel-media with inner surface fill, image clipping, and
  "MISSING MEDIA" placeholder for empty containers
- Interactive bevel buttons: dt-btn with hover/selected states and pulse animation
- Menu items: dt-menu-item with active states and level indentation
- Animations: scale-in, fade-in, slide-up, pulse, ping, spin keyframes
- Feature legend: CSS grid for product feature icons with state colors
- Scrollbar styling for DT brand
- New @dangerousthings/react package wrapping web CSS components
- New @dangerousthings/tailwind-preset package
- New @dangerousthings/hex-background package
- Desktop showcase rewritten in React with Tailwind CSS
- Mobile showcase updated with new screens (animations, filters, advanced cards)
- Tokens: added mode color tokens, RGB variants, and selected-state tokens

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
2026-03-06 10:18:39 -08:00

97 lines
2.3 KiB
TypeScript

/**
* DTModal — Portal-based modal with beveled card content.
*
* CSS reference: bevels.css .dt-bevel-modal, .card, .mode-*
*/
import { useEffect, useCallback, type ReactNode, type CSSProperties } from 'react';
import { createPortal } from 'react-dom';
import type { DTVariant } from '@dangerousthings/tokens';
import { cx } from '../utils/cx';
import { getVariantClass } from '../utils/variantClasses';
interface DTModalProps {
visible: boolean;
onDismiss: () => void;
title?: string;
/** Color variant @default 'normal' */
variant?: DTVariant;
children: ReactNode;
/** Whether clicking backdrop dismisses @default true */
dismissable?: boolean;
className?: string;
style?: CSSProperties;
}
export function DTModal({
visible,
onDismiss,
title,
variant = 'normal',
children,
dismissable = true,
className,
style,
}: DTModalProps) {
const handleKeyDown = useCallback(
(e: KeyboardEvent) => {
if (e.key === 'Escape' && dismissable) onDismiss();
},
[onDismiss, dismissable],
);
useEffect(() => {
if (visible) {
document.addEventListener('keydown', handleKeyDown);
return () => document.removeEventListener('keydown', handleKeyDown);
}
}, [visible, handleKeyDown]);
if (!visible) return null;
return createPortal(
<div
className="dt-modal-overlay"
style={{
position: 'fixed',
inset: 0,
display: 'flex',
alignItems: 'center',
justifyContent: 'center',
zIndex: 1000,
}}>
<div
className="dt-modal-backdrop"
style={{
position: 'absolute',
inset: 0,
background: 'rgba(0, 0, 0, 0.5)',
backdropFilter: 'blur(4px)',
}}
onClick={dismissable ? onDismiss : undefined}
/>
<div
className={cx(
'card',
'dt-bevel-modal',
getVariantClass(variant),
'dt-animate-scale-in',
className,
)}
style={{
position: 'relative',
maxWidth: '90vw',
maxHeight: '85vh',
overflow: 'auto',
...style,
}}
role="dialog"
aria-modal="true">
{title && <div className="card-title">{title}</div>}
<div style={{ padding: 'var(--space-6, 24px)' }}>{children}</div>
</div>
</div>,
document.body,
);
}