Files
booksorter/src/web/components/Panel.tsx
T

21 lines
900 B
TypeScript
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
import { useRef } from 'preact/hooks';
import type { ComponentChildren } from 'preact';
import { useDialog } from '../dialog.ts';
/** A side panel on wide windows and a full-width sheet on narrow ones, over a dimmed page. */
export function Panel({ title, onClose, children }: { title: string; onClose: () => void; children: ComponentChildren }) {
const ref = useRef<HTMLDivElement>(null);
useDialog(ref, onClose, true);
return (
<div class="backdrop" onMouseDown={e => { if (e.target === e.currentTarget) onClose(); }}>
<div class="panel" role="dialog" aria-modal="true" aria-label={title} ref={ref} tabIndex={-1}>
<div class="panel-head">
<h2>{title}</h2>
<button type="button" class="btn-icon" onClick={onClose} aria-label="Close" title="Close">×</button>
</div>
<div class="panel-body">{children}</div>
</div>
</div>
);
}