第4项:对页面、表单及两版共享规则启用严格类型检查
This commit is contained in:
1 parent
389952f31c
commit
f570929cfe
77 files changed
+7629
-2981
No files matched your search
@@ -0,0 +1,39 @@
|
||||
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>
|
||||
);
|
||||
}
|
||||
Reference in new issue
Block a user