Skip to content

fix: fix code copy behaviour and change the aspect of it #54

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

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
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
33 changes: 14 additions & 19 deletions _sass/code.scss
Original file line number Diff line number Diff line change
Expand Up @@ -20,9 +20,15 @@ code {
.code-header {
display: flex;
justify-content: flex-end;
position: relative;
}

.copy-code-button {
position: absolute;
top: 5px;
right: 5px;
width: 30px;
height: 30px;
display: grid;
grid-auto-flow: column;
align-items: center;
Expand All @@ -32,29 +38,18 @@ code {
font-size: 1rem;
padding: 4px 8px;
background-color: $code-background;
border-radius: $code-border-radius $code-border-radius 0 0;
color: $code-color;
border-bottom: 1px solid #666666;

&::before {
content: "Copier";
}

&::after {
content: "📋";
display: block;
}
background-image: url('/assets/images/copy-icon.svg');
background-position: center;
background-size: contain;
background-repeat: no-repeat;

// This class will be toggled via JavaScript
&.copied {
background-color: #dddddd;
background-image: none;
color: black;
&::before {
content: "Copié!";
}

&::after {
content: "✔️";
}
&:after {
content: "✔️";
}
}
}
42 changes: 0 additions & 42 deletions _sass/index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -10,45 +10,3 @@ div.highlighter-rouge {
margin: 0;
}
}

.code-header {
display: flex;
justify-content: flex-end;
}

.copy-code-button {
display: grid;
grid-auto-flow: column;
align-items: center;
grid-column-gap: 4px;
border: none;
cursor: pointer;
font-size: 1rem;
padding: 4px 8px;
background-color: $code-background;
border-radius: $code-border-radius $code-border-radius 0 0;
color: $code-color;
border-bottom: 1px solid #666666;

&::before {
content: "Copier";
}

&::after {
content: "📋";
display: block;
}

// This class will be toggled via JavaScript
&.copied {
background-color: #dddddd;
color: black;
&::before {
content: "Copié!";
}

&::after {
content: "✔️";
}
}
}
77 changes: 77 additions & 0 deletions assets/images/copy-icon.svg
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
2 changes: 1 addition & 1 deletion assets/scripts/copy-code.js
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,7 @@ const codeBlocks = document.querySelectorAll('.code-header + .highlighter-rouge'
const copyCodeButtons = document.querySelectorAll('.copy-code-button');

copyCodeButtons.forEach((copyCodeButton, index) => {
const code = codeBlocks[index].innerText;
const code = codeBlocks[index].querySelector('.rouge-code')?.innerText;

copyCodeButton.addEventListener('click', () => {
window.navigator.clipboard.writeText(code);
Expand Down