diff --git a/components/Markdown/CodeBlock.tsx b/components/Markdown/CodeBlock.tsx index a0e9a5c..d7a5652 100644 --- a/components/Markdown/CodeBlock.tsx +++ b/components/Markdown/CodeBlock.tsx @@ -1,5 +1,5 @@ import { generateRandomString, programmingLanguages } from "@/utils/app/codeblock"; -import { IconDownload } from "@tabler/icons-react"; +import { IconCheck, IconClipboard, IconDownload } from "@tabler/icons-react"; import { FC, useState } from "react"; import { Prism as SyntaxHighlighter } from "react-syntax-highlighter"; import { oneDark, oneLight } from "react-syntax-highlighter/dist/cjs/styles/prism"; @@ -11,7 +11,7 @@ interface Props { } export const CodeBlock: FC = ({ language, value, lightMode }) => { - const [buttonText, setButtonText] = useState("Copy code"); + const [isCopied, setIsCopied] = useState(false); const copyToClipboard = () => { if (!navigator.clipboard || !navigator.clipboard.writeText) { @@ -19,10 +19,10 @@ export const CodeBlock: FC = ({ language, value, lightMode }) => { } navigator.clipboard.writeText(value).then(() => { - setButtonText("Copied!"); + setIsCopied(true); setTimeout(() => { - setButtonText("Copy code"); + setIsCopied(false); }, 2000); }); }; @@ -48,21 +48,22 @@ export const CodeBlock: FC = ({ language, value, lightMode }) => { URL.revokeObjectURL(url); }; return ( -
-
- {language} +
+
+ {language}
@@ -70,6 +71,7 @@ export const CodeBlock: FC = ({ language, value, lightMode }) => { {value} diff --git a/styles/globals.css b/styles/globals.css index 4dfeeef..b45ed1c 100644 --- a/styles/globals.css +++ b/styles/globals.css @@ -31,3 +31,7 @@ html { background: #202123; } + +pre:has(div.codeblock) { + padding: 0; +} \ No newline at end of file