Skip to content

armgit / ente

Public Imported from GitHub
0

πŸ’š End-to-end encrypted cloud for everything.

bespoke

Manav Rathi50940067121b
diff --git a/web/packages/accounts/components/CodeBlock.tsx b/web/packages/accounts/components/CodeBlock.tsx
index 291503d073..2340ef0626 100644
--- a/web/packages/accounts/components/CodeBlock.tsx
+++ b/web/packages/accounts/components/CodeBlock.tsx
@@ -1,8 +1,10 @@
import { CenteredFlex } from "@/base/components/containers";
-import { CopyButton } from "@/base/components/CopyButton";
import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";
-import { Box, Typography } from "@mui/material";
-import React from "react";
+import ContentCopyIcon from "@mui/icons-material/ContentCopy";
+import DoneIcon from "@mui/icons-material/Done";
+import { Box, IconButton, Tooltip, Typography } from "@mui/material";
+import { t } from "i18next";
+import React, { useState } from "react";
interface CodeBlockProps {
/**
@@ -46,8 +48,35 @@ export const CodeBlock: React.FC<CodeBlockProps> = ({ code }) => {
{code}
</Typography>
<Box sx={{ position: "absolute", top: 0, right: 0, mt: 1 }}>
- <CopyButton color="accentContrastText" code={code} />
+ <CopyButton code={code} />
</Box>
</Box>
);
};
+
+interface CopyButtonProps {
+ /**
+ * The code to copy when the button is clicked.
+ */
+ code: string;
+}
+
+export const CopyButton: React.FC<CopyButtonProps> = ({ code }) => {
+ const [copied, setCopied] = useState(false);
+
+ const handleClick = () =>
+ void navigator.clipboard.writeText(code).then(() => {
+ setCopied(true);
+ setTimeout(() => setCopied(false), 1000);
+ });
+
+ const Icon = copied ? DoneIcon : ContentCopyIcon;
+
+ return (
+ <Tooltip arrow open={copied} title={t("copied")}>
+ <IconButton onClick={handleClick}>
+ <Icon sx={{ color: "accent.contrastText" }} fontSize="small" />
+ </IconButton>
+ </Tooltip>
+ );
+};