forked from boos/BoosAPI
feat: add mobile drawer shell
This commit is contained in:
@@ -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>
|
||||
);
|
||||
}
|
||||
@@ -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);
|
||||
});
|
||||
});
|
||||
Reference in New Issue
Block a user