Skip to content

Commit

Permalink
fix: Replaced copy text with ClipBoard icon (#1647)
Browse files Browse the repository at this point in the history
Co-authored-by: Mohd Zaid <[email protected]>
  • Loading branch information
Xaid-vfx and Mohd Zaid authored Jul 9, 2023
1 parent d219efa commit 27750d0
Showing 1 changed file with 6 additions and 8 deletions.
14 changes: 6 additions & 8 deletions app/docs/page.tsx
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
"use client";
import { GitBranch, FileText, UploadCloud } from "react-feather";
import { GitBranch, FileText, UploadCloud, Clipboard, CheckCircle } from "react-feather";
import { useEffect, ReactNode, useState } from "react";
import SyntaxHighlighter from "react-syntax-highlighter";
import { anOldHope } from "react-syntax-highlighter/dist/esm/styles/hljs";
Expand Down Expand Up @@ -139,15 +139,12 @@ const option2Steps = [
];

function Step({ icon, text, code, image }: StepProps): JSX.Element {
const [copyCodeButton, setcopyCodeButton] = useState(true)
const copyCode = (e: React.MouseEvent<HTMLButtonElement, MouseEvent>): void => {
const button = e.currentTarget as HTMLButtonElement;
const initialText = button.innerText;

setcopyCodeButton(false)
navigator.clipboard.writeText(code);
button.innerText = "Copied!";

setTimeout(() => {
button.innerText = initialText;
setcopyCodeButton(true)
}, 3000);
};

Expand All @@ -167,7 +164,8 @@ function Step({ icon, text, code, image }: StepProps): JSX.Element {
onClick={copyCode}
className="cursor-pointer text-indigo-600"
>
Copy
{copyCodeButton && <Clipboard size='18' color="white"/>}
{!copyCodeButton && <CheckCircle size='18' color="green"/>}
</button>
</div>
)}
Expand Down

0 comments on commit 27750d0

Please sign in to comment.