diff options
| author | kj_sh604 | 2026-03-15 16:19:35 -0400 |
|---|---|---|
| committer | kj_sh604 | 2026-03-15 16:19:35 -0400 |
| commit | 6ec259a0e71174651bae95d4628138bf6fd68742 (patch) | |
| tree | 5e33c6a5ec091ecabfcb257fdc7b6a88ed8754ac /packages/excalidraw/components/ShareableLinkDialog.tsx | |
| parent | 16c8578b15c727f22921f8a80a56ee4d4e7f2272 (diff) | |
refactor: packages/
Diffstat (limited to 'packages/excalidraw/components/ShareableLinkDialog.tsx')
| -rw-r--r-- | packages/excalidraw/components/ShareableLinkDialog.tsx | 80 |
1 files changed, 80 insertions, 0 deletions
diff --git a/packages/excalidraw/components/ShareableLinkDialog.tsx b/packages/excalidraw/components/ShareableLinkDialog.tsx new file mode 100644 index 0000000..987c7bf --- /dev/null +++ b/packages/excalidraw/components/ShareableLinkDialog.tsx @@ -0,0 +1,80 @@ +import { useRef, useState } from "react"; + +import { copyTextToSystemClipboard } from "../clipboard"; +import { useI18n } from "../i18n"; + +import { Dialog } from "./Dialog"; +import { TextField } from "./TextField"; +import { FilledButton } from "./FilledButton"; +import { useCopyStatus } from "../hooks/useCopiedIndicator"; +import { copyIcon } from "./icons"; + +import "./ShareableLinkDialog.scss"; + +export type ShareableLinkDialogProps = { + link: string; + + onCloseRequest: () => void; + setErrorMessage: (error: string) => void; +}; + +export const ShareableLinkDialog = ({ + link, + onCloseRequest, + setErrorMessage, +}: ShareableLinkDialogProps) => { + const { t } = useI18n(); + const [, setJustCopied] = useState(false); + const timerRef = useRef<number>(0); + const ref = useRef<HTMLInputElement>(null); + + const copyRoomLink = async () => { + try { + await copyTextToSystemClipboard(link); + } catch (e) { + setErrorMessage(t("errors.copyToSystemClipboardFailed")); + } + setJustCopied(true); + + if (timerRef.current) { + window.clearTimeout(timerRef.current); + } + + timerRef.current = window.setTimeout(() => { + setJustCopied(false); + }, 3000); + + ref.current?.select(); + }; + const { onCopy, copyStatus } = useCopyStatus(); + return ( + <Dialog onCloseRequest={onCloseRequest} title={false} size="small"> + <div className="ShareableLinkDialog"> + <h3>Shareable link</h3> + <div className="ShareableLinkDialog__linkRow"> + <TextField + ref={ref} + label="Link" + readonly + fullWidth + value={link} + selectOnRender + /> + <FilledButton + size="large" + label={t("buttons.copyLink")} + icon={copyIcon} + status={copyStatus} + onClick={() => { + onCopy(); + copyRoomLink(); + }} + /> + </div> + <div className="ShareableLinkDialog__description"> + 🔒 {t("alerts.uploadedSecurly")} + </div> + </div> + </Dialog> + ); +}; |
