import * as React from "react"; import { Modal } from "../controls/Modal"; import { Input } from "../controls/Input"; import { Button } from "../controls/Button"; export interface ShareLinkDialogProps { visible: boolean; shareUrl?: string; title?: string; ariaLabel?: string; linkAriaLabel?: string; className?: string; children?: React.ReactNode; onClose: () => void; } export const ShareLinkDialog: React.FC = props => { const { visible, shareUrl, title, ariaLabel, linkAriaLabel, className, children, onClose, } = props; const [copySuccessful, setCopySuccessful] = React.useState(false); const inputRef = React.useRef(null); React.useEffect(() => { if (visible) setCopySuccessful(false); }, [visible, shareUrl]); const handleCopyClick = () => { if (!shareUrl) return; if (pxt.BrowserUtils.isIpcRenderer()) { setCopySuccessful(!!inputRef.current && pxt.BrowserUtils.legacyCopyText(inputRef.current)); return; } navigator.clipboard.writeText(shareUrl); setCopySuccessful(true); }; const handleCopyBlur = () => { setCopySuccessful(false); }; if (!visible) return <>; const modalClassName = ["sharedialog", "share-link-dialog", className].filter(Boolean).join(" "); return
{!!children &&
{children}
}
inputRef.current = ref} initialValue={shareUrl} readOnly={true} selectOnClick={true} />
; };