Skip to content

Commit 0de67c2

Browse files
committed
Make values one-clip copyable
1 parent 5b5981b commit 0de67c2

File tree

1 file changed

+20
-0
lines changed

1 file changed

+20
-0
lines changed

_posts/2024-11-18-core-web-vitals-colours.md

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@ slides and presentations, here you go:
3030
.c-cwv-colours__colour {
3131
flex: 1;
3232
padding: 1.5rem;
33+
cursor: copy;
3334
}
3435

3536
.c-cwv-colours__title {
@@ -70,6 +71,25 @@ slides and presentations, here you go:
7071

7172
</ul>
7273

74+
<script>
75+
(() => {
76+
document.querySelectorAll('.c-cwv-colours__colour').forEach(colourElement => {
77+
colourElement.title = 'Click to copy hex code';
78+
colourElement.addEventListener('click', () => {
79+
const valueElement = colourElement.querySelector('.c-cwv-colours__value');
80+
const value = valueElement.textContent;
81+
82+
// Copy the value to the clipboard
83+
navigator.clipboard.writeText(value).then(() => {
84+
console.log(`Copied to clipboard: ${value}`);
85+
}).catch(err => {
86+
console.error('Failed to copy text: ', err);
87+
});
88+
});
89+
});
90+
})();
91+
</script>
92+
7393
## More Colour Formats?
7494

7595
<strong style="color: #09ce6b;">Good</strong>

0 commit comments

Comments
 (0)