Skip to content

Commit 1c3ada9

Browse files
committed
feat: add copy button to code block
1 parent dc0c32a commit 1c3ada9

2 files changed

Lines changed: 29 additions & 4 deletions

File tree

src/backend/views/pages/blocks/code.twig

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,12 @@
11
<div class="block-code">
2-
<div class="block-code__content">{{ code|escape }}</div>
2+
<div class="block-code__wrapper">
3+
<div class="block-code__content">{{ code | escape }}</div>
4+
</div>
5+
{%
6+
include 'components/copy-button.twig' with {
7+
ariaLabel: 'Copy Code to Clipboard',
8+
class: 'block-code__copy-button',
9+
textToCopy: code | escape,
10+
}
11+
%}
312
</div>
4-

src/frontend/styles/components/page.pcss

Lines changed: 19 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -149,8 +149,18 @@
149149
* ==================
150150
*/
151151
.block-code {
152-
@apply --text-code-block;
153-
@apply --squircle;
152+
position: relative;
153+
154+
&:hover {
155+
.block-code__copy-button {
156+
opacity: 1;
157+
}
158+
}
159+
160+
&__wrapper {
161+
@apply --text-code-block;
162+
@apply --squircle;
163+
}
154164

155165
&__content {
156166
display: inline-block !important;
@@ -169,6 +179,13 @@
169179
}
170180
}
171181

182+
&__copy-button {
183+
position: absolute;
184+
top: 10px;
185+
right: 10px;
186+
opacity: 0;
187+
}
188+
172189
.hljs-params {
173190
color: var(--color-code-params);
174191
}

0 commit comments

Comments
 (0)