Skip to content

Commit aded164

Browse files
Unify copy to clipboard icon with docs.rs, rustdoc and crates.io
1 parent ec996d3 commit aded164

File tree

3 files changed

+54
-6
lines changed

3 files changed

+54
-6
lines changed

src/theme/book.js

+4-4
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@ function playground_text(playground, hidden = true) {
225225
}
226226

227227
var clipButton = document.createElement('button');
228-
clipButton.className = 'fa fa-copy clip-button';
228+
clipButton.className = 'clip-button';
229229
clipButton.title = 'Copy to clipboard';
230230
clipButton.setAttribute('aria-label', clipButton.title);
231231
clipButton.innerHTML = '<i class=\"tooltiptext\"></i>';
@@ -258,7 +258,7 @@ function playground_text(playground, hidden = true) {
258258

259259
if (window.playground_copyable) {
260260
var copyCodeClipboardButton = document.createElement('button');
261-
copyCodeClipboardButton.className = 'fa fa-copy clip-button';
261+
copyCodeClipboardButton.className = 'clip-button';
262262
copyCodeClipboardButton.innerHTML = '<i class="tooltiptext"></i>';
263263
copyCodeClipboardButton.title = 'Copy to clipboard';
264264
copyCodeClipboardButton.setAttribute('aria-label', copyCodeClipboardButton.title);
@@ -597,12 +597,12 @@ function playground_text(playground, hidden = true) {
597597

598598
function hideTooltip(elem) {
599599
elem.firstChild.innerText = "";
600-
elem.className = 'fa fa-copy clip-button';
600+
elem.className = 'clip-button';
601601
}
602602

603603
function showTooltip(elem, msg) {
604604
elem.firstChild.innerText = msg;
605-
elem.className = 'fa fa-copy tooltipped';
605+
elem.className = 'clip-button tooltipped';
606606
}
607607

608608
var clipboardSnippets = new ClipboardJS('.clip-button', {

src/theme/css/chrome.css

+21-1
Original file line numberDiff line numberDiff line change
@@ -251,7 +251,7 @@ pre > .buttons button {
251251
cursor: inherit;
252252
margin: 0px 5px;
253253
padding: 3px 5px;
254-
font-size: 14px;
254+
font-size: 25px;
255255

256256
border-style: solid;
257257
border-width: 1px;
@@ -262,6 +262,26 @@ pre > .buttons button {
262262
transition-property: color,border-color,background-color;
263263
color: var(--icons);
264264
}
265+
266+
pre > .buttons button.clip-button {
267+
padding: 0 5px 0 7px;
268+
}
269+
pre > .buttons button.clip-button::before {
270+
/* clipboard <https://github.com/rust-lang/crates.io/commits/main/public/assets/copy.svg> */
271+
content: url('data:image/svg+xml,<svg width="19" height="18" viewBox="0 0 24 25" \
272+
xmlns="http://www.w3.org/2000/svg" aria-label="Copy to clipboard">\
273+
<path d="M18 20h2v3c0 1-1 2-2 2H2c-.998 0-2-1-2-2V5c0-.911.755-1.667 1.667-1.667h5A3.323 3.323 0 \
274+
0110 0a3.323 3.323 0 013.333 3.333h5C19.245 3.333 20 4.09 20 5v8.333h-2V9H2v14h16v-3zM3 \
275+
7h14c0-.911-.793-1.667-1.75-1.667H13.5c-.957 0-1.75-.755-1.75-1.666C11.75 2.755 10.957 2 10 \
276+
2s-1.75.755-1.75 1.667c0 .911-.793 1.666-1.75 1.666H4.75C3.793 5.333 3 6.09 3 7z"/>\
277+
<path d="M4 19h6v2H4zM12 11H4v2h8zM4 17h4v-2H4zM15 15v-3l-4.5 4.5L15 21v-3l8.027-.032L23 15z"/>\
278+
</svg>');
279+
filter: var(--copy-button-filter);
280+
}
281+
pre > .buttons button.clip-button:hover::before {
282+
filter: var(--copy-button-filter-hover);
283+
}
284+
265285
@media (pointer: coarse) {
266286
pre > .buttons button {
267287
/* On mobile, make it easier to tap buttons. */

src/theme/css/variables.css

+29-1
Original file line numberDiff line numberDiff line change
@@ -56,6 +56,11 @@
5656
--search-mark-bg: #e3b171;
5757

5858
--color-scheme: dark;
59+
60+
/* Same as `--icons` */
61+
--copy-button-filter: invert(45%) sepia(6%) saturate(621%) hue-rotate(198deg) brightness(99%) contrast(85%);
62+
/* Same as `--sidebar-active` */
63+
--copy-button-filter-hover: invert(68%) sepia(55%) saturate(531%) hue-rotate(341deg) brightness(104%) contrast(101%);
5964
}
6065

6166
.coal {
@@ -100,6 +105,11 @@
100105
--search-mark-bg: #355c7d;
101106

102107
--color-scheme: dark;
108+
109+
/* Same as `--icons` */
110+
--copy-button-filter: invert(26%) sepia(8%) saturate(575%) hue-rotate(169deg) brightness(87%) contrast(82%);
111+
/* Same as `--sidebar-active` */
112+
--copy-button-filter-hover: invert(36%) sepia(70%) saturate(503%) hue-rotate(167deg) brightness(98%) contrast(89%);
103113
}
104114

105115
.light {
@@ -144,6 +154,11 @@
144154
--search-mark-bg: #a2cff5;
145155

146156
--color-scheme: light;
157+
158+
/* Same as `--icons` */
159+
--copy-button-filter: invert(45.49%);
160+
/* Same as `--sidebar-active` */
161+
--copy-button-filter-hover: invert(14%) sepia(93%) saturate(4250%) hue-rotate(243deg) brightness(99%) contrast(130%);
147162
}
148163

149164
.navy {
@@ -188,6 +203,11 @@
188203
--search-mark-bg: #a2cff5;
189204

190205
--color-scheme: dark;
206+
207+
/* Same as `--icons` */
208+
--copy-button-filter: invert(51%) sepia(10%) saturate(393%) hue-rotate(198deg) brightness(86%) contrast(87%);
209+
/* Same as `--sidebar-active` */
210+
--copy-button-filter-hover: invert(46%) sepia(20%) saturate(1537%) hue-rotate(156deg) brightness(85%) contrast(90%);
191211
}
192212

193213
.rust {
@@ -231,7 +251,10 @@
231251
--searchresults-li-bg: #dec2a2;
232252
--search-mark-bg: #e69f67;
233253

234-
--color-scheme: light;
254+
/* Same as `--icons` */
255+
--copy-button-filter: invert(51%) sepia(10%) saturate(393%) hue-rotate(198deg) brightness(86%) contrast(87%);
256+
/* Same as `--sidebar-active` */
257+
--copy-button-filter-hover: invert(77%) sepia(16%) saturate(1798%) hue-rotate(328deg) brightness(98%) contrast(83%);
235258
}
236259

237260
@media (prefers-color-scheme: dark) {
@@ -275,5 +298,10 @@
275298
--searchresults-border-color: #98a3ad;
276299
--searchresults-li-bg: #2b2b2f;
277300
--search-mark-bg: #355c7d;
301+
302+
/* Same as `--icons` */
303+
--copy-button-filter: invert(26%) sepia(8%) saturate(575%) hue-rotate(169deg) brightness(87%) contrast(82%);
304+
/* Same as `--sidebar-active` */
305+
--copy-button-filter-hover: invert(36%) sepia(70%) saturate(503%) hue-rotate(167deg) brightness(98%) contrast(89%);
278306
}
279307
}

0 commit comments

Comments
 (0)