1
0
forked from boos/BoosAPI

feat: add mobile drawer shell

This commit is contained in:
cita
2026-03-10 14:55:21 +08:00
parent ed830563d2
commit 2d8e1b9019
2 changed files with 50 additions and 0 deletions
+25
View File
@@ -0,0 +1,25 @@
import React from 'react';
type MobileDrawerProps = {
open: boolean;
onClose: () => void;
children: React.ReactNode;
};
export default function MobileDrawer({ open, onClose, children }: MobileDrawerProps) {
if (!open) return null;
return (
<div className="mobile-drawer-root">
<button
type="button"
className="mobile-drawer-backdrop"
onClick={onClose}
aria-label="Close navigation"
/>
<div className="mobile-drawer-panel" role="dialog" aria-modal="true">
{children}
</div>
</div>
);
}
+25
View File
@@ -0,0 +1,25 @@
import { describe, expect, it, vi } from 'vitest';
import { create } from 'react-test-renderer';
import MobileDrawer from './MobileDrawer.js';
describe('MobileDrawer', () => {
it('renders content when open and closes on backdrop click', () => {
const onClose = vi.fn();
const root = create(
<MobileDrawer open onClose={onClose}>
<div>DrawerContent</div>
</MobileDrawer>,
);
const text = root.root.findAll(() => true)
.flatMap((instance) => instance.children)
.filter((child): child is string => typeof child === 'string')
.join('');
expect(text).toContain('DrawerContent');
const backdrop = root.root.find((node) => node.props?.className === 'mobile-drawer-backdrop');
backdrop.props.onClick();
expect(onClose).toHaveBeenCalledTimes(1);
});
});