Skip to content

Commit ba71139

Browse files
committed
feat: add copy button feedback
1 parent 28be635 commit ba71139

3 files changed

Lines changed: 39 additions & 18 deletions

File tree

static/css/v3/downloads_table_card.css

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -109,6 +109,15 @@
109109
padding: 0;
110110
border-radius: var(--border-radius-s);
111111
flex-shrink: 0;
112+
transition: color 0.3s ease;
113+
}
114+
115+
.downloads-table-card__copy-btn.is-copied {
116+
color: var(--color-text-link-accent);
117+
}
118+
119+
.downloads-table-card__copy-btn.is-error {
120+
color: var(--color-text-error);
112121
}
113122

114123
.js-copy-enabled .downloads-table-card__copy-btn {

templates/v3/includes/_downloads_table_card.html

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,3 +55,33 @@
5555
</table>
5656
</div>
5757
{% endif %}
58+
59+
{% block footer_js %}
60+
<script>
61+
(function () {
62+
document.querySelectorAll('.downloads-table-card__wrapper').forEach(function (wrapper) {
63+
wrapper.classList.add('js-copy-enabled');
64+
});
65+
document.querySelectorAll('.downloads-table-card__copy-btn').forEach(function (btn) {
66+
btn.addEventListener('click', function () {
67+
const text = btn.getAttribute('data-copy-text');
68+
if (!text) return;
69+
70+
function showFeedback(className) {
71+
btn.classList.add(className);
72+
setTimeout(function () {
73+
btn.classList.remove(className);
74+
}, 2000);
75+
}
76+
77+
if (navigator.clipboard && navigator.clipboard.writeText) {
78+
navigator.clipboard.writeText(text).then(
79+
function () { showFeedback('is-copied'); },
80+
function () { showFeedback('is-error'); }
81+
);
82+
}
83+
});
84+
});
85+
})();
86+
</script>
87+
{% endblock %}

templates/v3/release_detail.html

Lines changed: 0 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -44,21 +44,3 @@
4444
</div>
4545
{% endif %}
4646
{% endblock %}
47-
48-
{% block footer_js %}
49-
<script>
50-
(function () {
51-
document.querySelectorAll('.downloads-table-card__wrapper').forEach(function (wrapper) {
52-
wrapper.classList.add('js-copy-enabled');
53-
});
54-
document.querySelectorAll('.downloads-table-card__copy-btn').forEach(function (btn) {
55-
btn.addEventListener('click', function () {
56-
var text = btn.getAttribute('data-copy-text');
57-
if (text && navigator.clipboard) {
58-
navigator.clipboard.writeText(text);
59-
}
60-
});
61-
});
62-
})();
63-
</script>
64-
{% endblock %}

0 commit comments

Comments
 (0)