From e7416bf2365db72ccd31ab187fd842ba730bb6ff Mon Sep 17 00:00:00 2001 From: weeihan Date: Wed, 30 Sep 2026 19:04:43 +0800 Subject: [PATCH] feat(design): restyle Modal as a flat Modernist dialog Co-Authored-By: Claude Haiku 4.5 --- components/ui/modal.tsx | 18 ++++++----- tests/components/ui/modal.test.tsx | 52 ++++++++++++++++++++++++++++++ 2 files changed, 62 insertions(+), 8 deletions(-) create mode 100644 tests/components/ui/modal.test.tsx diff --git a/components/ui/modal.tsx b/components/ui/modal.tsx index 635cfbc..61d98b7 100644 --- a/components/ui/modal.tsx +++ b/components/ui/modal.tsx @@ -1,6 +1,7 @@ 'use client' import { useEffect } from 'react' +import { X } from 'lucide-react' interface ModalProps { open: boolean @@ -25,15 +26,16 @@ export function Modal({ open, onClose, title, children, footer, width = 'md' }: return (
-
+
-
-

{title}

-
{children}
diff --git a/tests/components/ui/modal.test.tsx b/tests/components/ui/modal.test.tsx new file mode 100644 index 0000000..9b628e5 --- /dev/null +++ b/tests/components/ui/modal.test.tsx @@ -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( + {}} title="T"> + body + , + ) + expect(container.firstChild).toBeNull() + }) + + it('renders a dialog with title, body and footer on the surface fill', () => { + render( + {}} title="Confirm" footer={actions}> + body text + , + ) + 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( + {}} title="T"> + x + , + ) + 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( + + x + , + ) + fireEvent.click(screen.getByRole('button', { name: 'Close' })) + fireEvent.keyDown(document, { key: 'Escape' }) + expect(onClose).toHaveBeenCalledTimes(2) + }) +})