import { CenteredRow } from "@/base/components/containers"; import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator"; 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 { /** * The code (an arbitrary string) to show. * * If not present, then an activity indicator will be shown. */ code: string | undefined; } /** * A component that shows a "code" (e.g. the user's recovery key, or a 2FA setup * code), alongwith a button to copy it. */ export const CodeBlock: React.FC = ({ code }) => { if (!code) { return ( ); } return ( {code} ); }; interface CopyButtonProps { /** * The code to copy when the button is clicked. */ code: string; } export const CopyButton: React.FC = ({ 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 ( ); };