Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ui v2: clipboard button #834

Merged
merged 1 commit into from
Dec 30, 2020
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
21 changes: 9 additions & 12 deletions frontend/packages/core/src/button.tsx
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
import * as React from "react";
import styled from "@emotion/styled";
import type { ButtonProps as MuiButtonProps, GridJustification } from "@material-ui/core";
import { Button as MuiButton, Grid, IconButton } from "@material-ui/core";
import { Button as MuiButton, Grid, IconButton as MuiIconButton } from "@material-ui/core";
import CheckCircleOutlinedIcon from "@material-ui/icons/CheckCircleOutlined";
import FileCopyOutlinedIcon from "@material-ui/icons/FileCopyOutlined";

Expand Down Expand Up @@ -121,21 +121,21 @@ const ButtonGroup = ({ children, justify = "flex-end", border = "top" }: ButtonG
</ButtonGroupContainer>
);

const IconButton = styled(MuiIconButton)({
color: "#000000",
":hover": {
backgroundColor: "transparent",
},
});

export interface ClipboardButtonProps {
primary?: boolean;
size?: "small" | "medium";
text: string;
}

// ClipboardButton is a button that copies text to the clipboard and briefly displays a checkmark
// after being clicked to let the user know that clicking actually did something and sent the
// provided value to the clipboard.
const ClipboardButton: React.FC<ClipboardButtonProps> = ({
text,
primary = false,
size = "small",
...props
}) => {
const ClipboardButton: React.FC<ClipboardButtonProps> = ({ text }) => {
const [clicked, setClicked] = React.useState(false);
React.useEffect(() => {
if (clicked) {
Expand All @@ -150,13 +150,10 @@ const ClipboardButton: React.FC<ClipboardButtonProps> = ({

return (
<IconButton
color={primary ? "primary" : "secondary"}
onClick={() => {
setClicked(true);
navigator.clipboard.writeText(text);
}}
size={size}
{...props}
>
{clicked ? <CheckCircleOutlinedIcon /> : <FileCopyOutlinedIcon />}
</IconButton>
Expand Down