-
Notifications
You must be signed in to change notification settings - Fork 101
Expand file tree
/
Copy pathcopy-button.js
More file actions
36 lines (33 loc) · 1.11 KB
/
copy-button.js
File metadata and controls
36 lines (33 loc) · 1.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
const { default: Icons } = require("@stackoverflow/stacks-icons");
module.exports = {
configFunction(eleventyConfig) {
eleventyConfig.addPairedShortcode("copybutton", function(content, classes, btnClasses) {
var tooltipId = "tooltip-" + Math.floor(Math.random() * 1000);
var output = `
<div class="stacks-clipboard-content ps-relative ${classes}" data-controller="clipboard">
<button
class="stacks-copy-btn s-btn s-btn__muted s-btn__icon ps-absolute p4 ${btnClasses}"
data-action="clipboard#copy"
data-s-tooltip-placement="top"
data-controller="s-tooltip"
aria-describedby="${tooltipId}">
<span class="d-none" data-show-on-copy>${Icons["Checkmark"]}</span>
<span data-hide-on-copy>${Icons["Copy"]}</span>
</button>
<div class="s-popover s-popover__tooltip"
id="${tooltipId}"
role="tooltip"
aria-hidden="true">
<div class="s-popover--arrow"></div>
<span class="d-none" data-show-on-copy>Copied</span>
<span data-hide-on-copy>Copy</span>
</div>
<div data-clipboard-target="source">
${content}
</div>
</div>
`;
return output;
});
}
}