Skip to content

Commit

Permalink
Adding check mark on successful copy
Browse files Browse the repository at this point in the history
  • Loading branch information
lukeorth committed Sep 29, 2023
1 parent b89ebba commit 4901e2c
Show file tree
Hide file tree
Showing 3 changed files with 24 additions and 3 deletions.
18 changes: 17 additions & 1 deletion assets/css/codeblock.css
Original file line number Diff line number Diff line change
@@ -1,6 +1,22 @@
/* Styling for the copy button displayed in code blocks */
.copy-success {
background: none;
border: none;

background-image: url("/icons/copy_success.svg");
width: 24px;
height: 24px;
background-size: contain;
background-repeat: no-repeat;
background-position: center;

position: absolute;
top: 0px;
right: 0px;
z-index: 10;
}

.copy-button {
color: white;
background: none;
border: none;

Expand Down
8 changes: 6 additions & 2 deletions assets/js/codeblock.js
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,11 @@ document.addEventListener("DOMContentLoaded", function() {
container.className = "code-container";

// Copy clicked closure
copyButton.addEventListener("click", () => {
copyButton.addEventListener("click", (e) => {
e.target.className = "copy-success";
setTimeout(() => {
e.target.className = "copy-button";
}, 1000);
const code = codeblock.textContent;
navigator.clipboard.writeText(code);
});
Expand All @@ -23,4 +27,4 @@ document.addEventListener("DOMContentLoaded", function() {
// Add the copy button to the container
container.appendChild(copyButton);
})
});
});
1 change: 1 addition & 0 deletions static/icons/copy_success.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

0 comments on commit 4901e2c

Please sign in to comment.