Files
weiguang-jewelry-ledger/新账系统/web/src/pages/Orders/Dialog.tsx
T

40 lines
795 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, useEffect, type ReactNode } from 'react';
export function Dialog({
id,
label,
close,
children,
ownClose = false,
}: {
id: string;
label: string;
close: () => void;
children: ReactNode;
ownClose?: boolean;
}) {
const ref = useRef<HTMLDialogElement>(null);
useEffect(() => {
const node = ref.current!;
node.showModal();
return () => node.close();
}, []);
return (
<dialog
id={id}
ref={ref}
aria-label={label}
onCancel={event => {
event.preventDefault();
close();
}}
>
{!ownClose && (
<button type="button" className="dialog-close" data-action="close-dialog" aria-label={label} onClick={close}>
×
</button>
)}
{children}
</dialog>
);
}