diff --git a/_sass/code.scss b/_sass/code.scss index 96b4988..34cad4e 100644 --- a/_sass/code.scss +++ b/_sass/code.scss @@ -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; @@ -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: "✔️"; + } } } diff --git a/_sass/index.scss b/_sass/index.scss index b8d3331..a4187be 100644 --- a/_sass/index.scss +++ b/_sass/index.scss @@ -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: "✔️"; - } - } -} diff --git a/assets/images/copy-icon.svg b/assets/images/copy-icon.svg new file mode 100644 index 0000000..49a8c9b --- /dev/null +++ b/assets/images/copy-icon.svg @@ -0,0 +1,77 @@ + + + + + + + + + + image/svg+xml + + + + + + + + + + diff --git a/assets/scripts/copy-code.js b/assets/scripts/copy-code.js index 9095177..c3857e7 100644 --- a/assets/scripts/copy-code.js +++ b/assets/scripts/copy-code.js @@ -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);