Fix the button to work in light mode

This commit is contained in:
Manav Rathi
2025-01-17 20:26:02 +05:30
parent 8705d878f4
commit 67398ea9e4
5 changed files with 71 additions and 50 deletions

View File

@@ -1,3 +1,4 @@
import { CopyButton } from "@/base/components/CopyButton";
import { LinkButtonUndecorated } from "@/base/components/LinkButton";
import { TitledMiniDialog } from "@/base/components/MiniDialog";
import { type ButtonishProps } from "@/base/components/mui";
@@ -41,7 +42,6 @@ import { updateMapEnabled } from "@/new/photos/services/settings";
import { AppContext } from "@/new/photos/types/context";
import { formattedByteSize } from "@/new/photos/utils/units";
import { FlexWrapper } from "@ente/shared/components/Container";
import CopyButton from "@ente/shared/components/CopyButton";
import SingleInputForm, {
type SingleInputFormProps,
} from "@ente/shared/components/SingleInputForm";

View File

@@ -1,6 +1,6 @@
import { CenteredFlex } from "@/base/components/containers";
import { CopyButton } from "@/base/components/CopyButton";
import { ActivityIndicator } from "@/base/components/mui/ActivityIndicator";
import CopyButton from "@ente/shared/components/CopyButton";
import { Box, Typography } from "@mui/material";
import React from "react";
@@ -36,7 +36,7 @@ export const CodeBlock: React.FC<CodeBlockProps> = ({ code }) => {
>
<Typography
sx={{
padding: "16px 36px 16px 16px",
padding: "16px 44px 16px 16px",
wordBreak: "break-word",
color: "accent.contrastText",
// Increase the line height from the body default.
@@ -46,7 +46,7 @@ export const CodeBlock: React.FC<CodeBlockProps> = ({ code }) => {
{code}
</Typography>
<Box sx={{ position: "absolute", top: 0, right: 0, mt: 1 }}>
<CopyButton code={code} />
<CopyButton color="accentContrastText" code={code} />
</Box>
</Box>
);

View File

@@ -87,7 +87,8 @@ const Page: React.FC = () => {
const ContentsPaper = styled(Paper)(({ theme }) => ({
marginBlock: theme.spacing(2),
padding: theme.spacing(4, 2),
width: "min(420px, 95vw)",
// Wide enough to fit the QR code secret in one line under default settings.
width: "min(440px, 95vw)",
display: "flex",
flexDirection: "column",
gap: theme.spacing(4),

View File

@@ -0,0 +1,65 @@
import ContentCopyIcon from "@mui/icons-material/ContentCopy";
import DoneIcon from "@mui/icons-material/Done";
import { IconButton, Tooltip, type SvgIconProps } from "@mui/material";
import { t } from "i18next";
import { useCallback, useState } from "react";
interface CopyButtonProps {
/**
* The code to copy when the button is clicked.
*/
code: string;
/**
* The button color.
*
* - "secondary" maps to the normal "secondary" for icon buttons.
* - "accentContrastText" is for use over an accented background.
*/
color: "secondary" | "accentContrastText";
/**
* The size of the icon.
*
* Default: "small"
*/
size?: SvgIconProps["fontSize"];
}
export const CopyButton: React.FC<CopyButtonProps> = ({
code,
color,
size = "small",
}) => {
const [copied, setCopied] = useState(false);
const handleClick = useCallback(() => {
void navigator.clipboard.writeText(code).then(() => {
setCopied(true);
setTimeout(() => setCopied(false), 1000);
});
}, [code]);
const Icon = copied ? DoneIcon : ContentCopyIcon;
return (
<Tooltip
arrow
open={copied}
title={t("copied")}
slotProps={{ popper: { sx: { zIndex: 2000 } } }}
>
<IconButton
onClick={handleClick}
{...(color == "secondary" ? { color } : {})}
>
<Icon
sx={[
color == "accentContrastText" && {
color: "accent.contrastText",
},
]}
fontSize={size}
/>
</IconButton>
</Tooltip>
);
};

View File

@@ -1,45 +0,0 @@
import ContentCopyIcon from "@mui/icons-material/ContentCopy";
import DoneIcon from "@mui/icons-material/Done";
import {
IconButton,
Tooltip,
type IconButtonProps,
type SvgIconProps,
} from "@mui/material";
import { t } from "i18next";
import { useCallback, useState } from "react";
export default function CopyButton({
code,
color,
size,
}: {
code: string;
color?: IconButtonProps["color"];
size?: SvgIconProps["fontSize"];
}) {
const [copied, setCopied] = useState(false);
const handleClick = useCallback(() => {
navigator.clipboard.writeText(code);
setCopied(true);
setTimeout(() => setCopied(false), 1000);
}, [code]);
return (
<Tooltip
arrow
open={copied}
title={t("copied")}
slotProps={{ popper: { sx: { zIndex: 2000 } } }}
>
<IconButton onClick={handleClick} color={color}>
{copied ? (
<DoneIcon fontSize={size ?? "small"} />
) : (
<ContentCopyIcon fontSize={size ?? "small"} />
)}
</IconButton>
</Tooltip>
);
}