21 lines
900 B
TypeScript
21 lines
900 B
TypeScript
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>
|
||
);
|
||
}
|