Spaces:
Runtime error
Runtime error
File size: 1,198 Bytes
7362797 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
/*
* Copyright (c) Meta Platforms, Inc. and affiliates.
*
* This source code is licensed under the Chameleon License found in the
* LICENSE file in the root directory of this source tree.
*/
import { ReactNode, useRef, useEffect } from "react";
import { Close } from "@carbon/icons-react";
export interface DialogModalProps {
onHide?: () => void;
onShow?: () => void;
visible: boolean;
children: ReactNode;
}
export function DialogModal({
onShow,
onHide,
visible,
children,
}: DialogModalProps) {
const shareRef = useRef<HTMLDialogElement>(null);
useEffect(() => {
if (visible) {
shareRef.current?.showModal();
onShow && onShow();
} else {
shareRef.current?.close();
onHide && onHide();
}
}, [visible]);
return (
<dialog ref={shareRef} className="modal">
<div className="modal-box relative">
<div
className="absolute top-0 right-0 p-4 hover:text-primary cursor-pointer"
onClick={onHide}
>
<Close size={32} />
</div>
{children}
</div>
<form method="dialog" className="modal-backdrop">
<button>close</button>
</form>
</dialog>
);
}
|