feat(design): restyle Modal as a flat Modernist dialog
Co-Authored-By: Claude Haiku 4.5 <noreply@anthropic.com>
This commit is contained in:
+10
-8
@@ -1,6 +1,7 @@
|
|||||||
'use client'
|
'use client'
|
||||||
|
|
||||||
import { useEffect } from 'react'
|
import { useEffect } from 'react'
|
||||||
|
import { X } from 'lucide-react'
|
||||||
|
|
||||||
interface ModalProps {
|
interface ModalProps {
|
||||||
open: boolean
|
open: boolean
|
||||||
@@ -25,15 +26,16 @@ export function Modal({ open, onClose, title, children, footer, width = 'md' }:
|
|||||||
|
|
||||||
return (
|
return (
|
||||||
<div className="fixed inset-0 z-50 flex items-center justify-center p-4" role="dialog" aria-modal="true">
|
<div className="fixed inset-0 z-50 flex items-center justify-center p-4" role="dialog" aria-modal="true">
|
||||||
<div className="absolute inset-0 bg-gray-900/50" onClick={onClose} />
|
<div className="absolute inset-0 bg-neutral-900/50" onClick={onClose} />
|
||||||
<div className={`relative w-full ${maxW} bg-surface shadow-lg`}>
|
<div className={`relative w-full ${maxW} bg-surface shadow-lg`}>
|
||||||
<div className="flex items-center justify-between px-6 py-4 border-b border-divider">
|
<div className="flex items-center justify-between px-6 py-4 border-b-2 border-divider">
|
||||||
<h2 className="text-sm font-semibold text-gray-900">{title}</h2>
|
<h2 className="text-xl font-extrabold text-ink">{title}</h2>
|
||||||
<button onClick={onClose} aria-label="Close"
|
<button
|
||||||
className="text-gray-400 hover:text-gray-600 p-1 hover:bg-gray-100 transition-colors cursor-pointer">
|
onClick={onClose}
|
||||||
<svg className="w-4 h-4" fill="none" viewBox="0 0 24 24" stroke="currentColor" strokeWidth={2.5}>
|
aria-label="Close"
|
||||||
<path strokeLinecap="round" strokeLinejoin="round" d="M6 18 18 6M6 6l12 12" />
|
className="inline-flex w-9 h-9 items-center justify-center text-ink cursor-pointer transition-colors hover:bg-ink/7 active:bg-ink/15"
|
||||||
</svg>
|
>
|
||||||
|
<X size={18} strokeWidth={2} aria-hidden />
|
||||||
</button>
|
</button>
|
||||||
</div>
|
</div>
|
||||||
<div className="px-6 py-5">{children}</div>
|
<div className="px-6 py-5">{children}</div>
|
||||||
|
|||||||
@@ -0,0 +1,52 @@
|
|||||||
|
import { describe, it, expect, vi } from 'vitest'
|
||||||
|
import { render, screen, fireEvent } from '@testing-library/react'
|
||||||
|
import { Modal } from '@/components/ui/modal'
|
||||||
|
|
||||||
|
describe('Modal (Modernist dialog)', () => {
|
||||||
|
it('renders nothing when closed', () => {
|
||||||
|
const { container } = render(
|
||||||
|
<Modal open={false} onClose={() => {}} title="T">
|
||||||
|
body
|
||||||
|
</Modal>,
|
||||||
|
)
|
||||||
|
expect(container.firstChild).toBeNull()
|
||||||
|
})
|
||||||
|
|
||||||
|
it('renders a dialog with title, body and footer on the surface fill', () => {
|
||||||
|
render(
|
||||||
|
<Modal open onClose={() => {}} title="Confirm" footer={<span>actions</span>}>
|
||||||
|
body text
|
||||||
|
</Modal>,
|
||||||
|
)
|
||||||
|
const dialog = screen.getByRole('dialog')
|
||||||
|
expect(dialog).toBeTruthy()
|
||||||
|
expect(screen.getByText('Confirm')).toBeTruthy()
|
||||||
|
expect(screen.getByText('body text')).toBeTruthy()
|
||||||
|
expect(screen.getByText('actions')).toBeTruthy()
|
||||||
|
expect(dialog.innerHTML).toContain('bg-surface')
|
||||||
|
expect(dialog.innerHTML).toContain('shadow-lg')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('has no rounded corners and uses a 2px title rule', () => {
|
||||||
|
render(
|
||||||
|
<Modal open onClose={() => {}} title="T">
|
||||||
|
x
|
||||||
|
</Modal>,
|
||||||
|
)
|
||||||
|
const html = screen.getByRole('dialog').innerHTML
|
||||||
|
expect(html).not.toMatch(/rounded/)
|
||||||
|
expect(html).toContain('border-b-2')
|
||||||
|
})
|
||||||
|
|
||||||
|
it('closes from the X button and on Escape', () => {
|
||||||
|
const onClose = vi.fn()
|
||||||
|
render(
|
||||||
|
<Modal open onClose={onClose} title="T">
|
||||||
|
x
|
||||||
|
</Modal>,
|
||||||
|
)
|
||||||
|
fireEvent.click(screen.getByRole('button', { name: 'Close' }))
|
||||||
|
fireEvent.keyDown(document, { key: 'Escape' })
|
||||||
|
expect(onClose).toHaveBeenCalledTimes(2)
|
||||||
|
})
|
||||||
|
})
|
||||||
Reference in New Issue
Block a user