- Run record
- loading
Loading this Run…
Loading the Revisions of this Run…
A published source file of Revision 0 of Boardly — Website Relaunch 1.1.0, shown as text in the browser.
import { useEffect, useRef } from "react";
import type { KeyboardEvent as ReactKeyboardEvent } from "react";
import { focusElement, trapTabKey, useModalScrollLock } from "../focus";
interface ConfirmDialogProps {
title: string;
body: string;
confirmLabel: string;
cancelLabel: string;
onConfirm: () => void;
onCancel: () => void;
}
export function ConfirmDialog(props: ConfirmDialogProps) {
const { title, body, confirmLabel, cancelLabel, onConfirm, onCancel } = props;
const panelRef = useRef<HTMLElement | null>(null);
const cancelRef = useRef<HTMLButtonElement | null>(null);
useModalScrollLock();
useEffect(() => {
focusElement(cancelRef.current);
}, []);
const onKeyDown = (e: ReactKeyboardEvent) => {
if (e.key === "Escape") {
e.stopPropagation();
onCancel();
return;
}
if (e.key === "Tab") trapTabKey(e, panelRef.current);
};
return (
<div
className="overlay"
onPointerDown={(e) => {
if (e.target === e.currentTarget) onCancel();
}}
>
<section
ref={panelRef}
className="confirm"
role="alertdialog"
aria-modal="true"
aria-labelledby="confirm-heading"
aria-describedby="confirm-body"
onKeyDown={onKeyDown}
>
<h2 id="confirm-heading">{title}</h2>
<p id="confirm-body">{body}</p>
<div className="confirm__row">
<button ref={cancelRef} type="button" className="btn btn--ghost" onClick={onCancel}>
{cancelLabel}
</button>
<button type="button" className="btn btn--danger" onClick={onConfirm}>
{confirmLabel}
</button>
</div>
</section>
</div>
);
}Source is browser-viewable only. There is no download or archive endpoint, and no additional license is granted beyond inspection and research.