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

Ignoring revisions in .git-blame-ignore-revs. Click here to bypass and see the normal blame view.

39 lines
795 B
TypeScript
Raw Normal View History

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>
);
}