|
1 |
| -import { type Interpolation, type Theme, css } from "@emotion/react"; |
2 |
| -import IconButton from "@mui/material/Button"; |
3 |
| -import Tooltip from "@mui/material/Tooltip"; |
| 1 | +import { Button, type ButtonProps } from "components/Button/Button"; |
| 2 | +import { |
| 3 | + Tooltip, |
| 4 | + TooltipContent, |
| 5 | + TooltipProvider, |
| 6 | + TooltipTrigger, |
| 7 | +} from "components/Tooltip/Tooltip"; |
4 | 8 | import { useClipboard } from "hooks/useClipboard";
|
5 |
| -import { CheckIcon } from "lucide-react"; |
6 |
| -import { type ReactNode, forwardRef } from "react"; |
7 |
| -import { FileCopyIcon } from "../Icons/FileCopyIcon"; |
| 9 | +import { CheckIcon, CopyIcon } from "lucide-react"; |
| 10 | +import type { FC } from "react"; |
8 | 11 |
|
9 |
| -interface CopyButtonProps { |
10 |
| - children?: ReactNode; |
| 12 | +type CopyButtonProps = ButtonProps & { |
11 | 13 | text: string;
|
12 |
| - ctaCopy?: string; |
13 |
| - wrapperStyles?: Interpolation<Theme>; |
14 |
| - buttonStyles?: Interpolation<Theme>; |
15 |
| - tooltipTitle?: string; |
16 |
| -} |
17 |
| - |
18 |
| -const Language = { |
19 |
| - tooltipTitle: "Copy to clipboard", |
20 |
| - ariaLabel: "Copy to clipboard", |
| 14 | + label: string; |
21 | 15 | };
|
22 | 16 |
|
23 |
| -/** |
24 |
| - * Copy button used inside the CodeBlock component internally |
25 |
| - */ |
26 |
| -export const CopyButton = forwardRef<HTMLButtonElement, CopyButtonProps>( |
27 |
| - (props, ref) => { |
28 |
| - const { |
29 |
| - text, |
30 |
| - ctaCopy, |
31 |
| - wrapperStyles, |
32 |
| - buttonStyles, |
33 |
| - tooltipTitle = Language.tooltipTitle, |
34 |
| - } = props; |
35 |
| - const { showCopiedSuccess, copyToClipboard } = useClipboard({ |
36 |
| - textToCopy: text, |
37 |
| - }); |
| 17 | +export const CopyButton: FC<CopyButtonProps> = ({ |
| 18 | + text, |
| 19 | + label, |
| 20 | + ...buttonProps |
| 21 | +}) => { |
| 22 | + const { showCopiedSuccess, copyToClipboard } = useClipboard({ |
| 23 | + textToCopy: text, |
| 24 | + }); |
38 | 25 |
|
39 |
| - return ( |
40 |
| - <Tooltip title={tooltipTitle} placement="top"> |
41 |
| - <div css={[{ display: "flex" }, wrapperStyles]}> |
42 |
| - <IconButton |
43 |
| - ref={ref} |
44 |
| - css={[styles.button, buttonStyles]} |
45 |
| - size="small" |
46 |
| - aria-label={Language.ariaLabel} |
47 |
| - variant="text" |
| 26 | + return ( |
| 27 | + <TooltipProvider> |
| 28 | + <Tooltip> |
| 29 | + <TooltipTrigger asChild> |
| 30 | + <Button |
| 31 | + size="icon" |
| 32 | + variant="subtle" |
48 | 33 | onClick={copyToClipboard}
|
| 34 | + {...buttonProps} |
49 | 35 | >
|
50 |
| - {showCopiedSuccess ? ( |
51 |
| - <CheckIcon css={styles.copyIcon} /> |
52 |
| - ) : ( |
53 |
| - <FileCopyIcon css={styles.copyIcon} /> |
54 |
| - )} |
55 |
| - {ctaCopy && <div css={{ marginLeft: 8 }}>{ctaCopy}</div>} |
56 |
| - </IconButton> |
57 |
| - </div> |
| 36 | + {showCopiedSuccess ? <CheckIcon /> : <CopyIcon />} |
| 37 | + <span className="sr-only">{label}</span> |
| 38 | + </Button> |
| 39 | + </TooltipTrigger> |
| 40 | + <TooltipContent>{label}</TooltipContent> |
58 | 41 | </Tooltip>
|
59 |
| - ); |
60 |
| - }, |
61 |
| -); |
62 |
| - |
63 |
| -const styles = { |
64 |
| - button: (theme) => css` |
65 |
| - border-radius: 8px; |
66 |
| - padding: 8px; |
67 |
| - min-width: 32px; |
68 |
| -
|
69 |
| - &:hover { |
70 |
| - background: ${theme.palette.background.paper}; |
71 |
| - } |
72 |
| - `, |
73 |
| - copyIcon: css` |
74 |
| - width: 20px; |
75 |
| - height: 20px; |
76 |
| - `, |
77 |
| -} satisfies Record<string, Interpolation<Theme>>; |
| 42 | + </TooltipProvider> |
| 43 | + ); |
| 44 | +}; |
0 commit comments