Skip to content

Commit a741f7f

Browse files
committed
✨ ENHANCE: Update SVG button with checkmark
1 parent b4ce7b8 commit a741f7f

7 files changed

Lines changed: 48 additions & 22 deletions

File tree

docs/_static/custom.css

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
img.logo {
2+
height: 200px !important;
3+
}

docs/conf.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -72,9 +72,9 @@
7272
# The theme to use for HTML and HTML Help pages. See the documentation for
7373
# a list of builtin themes.
7474
#
75+
html_theme = "sphinx_book_theme"
7576
# html_theme = "alabaster"
7677
# html_theme = "sphinx_rtd_theme"
77-
html_theme = "sphinx_book_theme"
7878

7979
# Theme options are theme-specific and customize the look and feel of a theme
8080
# further. For a list of options available for each theme, see the
@@ -86,6 +86,8 @@
8686
# relative to this directory. They are copied after the builtin static files,
8787
# so a file named "default.css" will overwrite the builtin "default.css".
8888
html_static_path = ["_static"]
89+
html_logo = "../sphinx_copybutton/_static/copy-button.svg"
90+
html_title = "Sphinx Copybutton"
8991

9092
# Custom sidebar templates, must be a dictionary that maps document names
9193
# to template names.
@@ -171,3 +173,7 @@
171173
"Miscellaneous",
172174
)
173175
]
176+
177+
178+
def setup(app):
179+
app.add_css_file("custom.css")

docs/second/second_page.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
=============
2-
A deeper page
3-
=============
1+
===========================
2+
A nested page for reference
3+
===========================
44

55
To make sure that the images / svg still works!
66

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,7 @@
4444
"_static/copybutton_funcs.js",
4545
"_static/copybutton.js_t",
4646
"_static/copy-button.svg",
47+
"_static/check-solid.svg",
4748
"_static/clipboard.min.js",
4849
]
4950
},
Lines changed: 4 additions & 0 deletions
Loading

sphinx_copybutton/_static/copybutton.css

Lines changed: 17 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,31 @@
11
/* Copy buttons */
2-
a.copybtn {
2+
button.copybtn {
33
position: absolute;
4-
top: .2em;
5-
right: .2em;
6-
width: 1.3em;
7-
height: 1.3em;
8-
opacity: .3;
9-
transition: opacity 0.5s;
10-
border: none;
4+
top: .3em;
5+
right: .5em;
6+
width: 1.7rem;
7+
height: 1.7rem;
8+
opacity: 0;
9+
transition: opacity 0.3s, border .3s;
1110
user-select: none;
11+
padding: 0;
12+
border: none;
13+
outline: none;
14+
}
15+
16+
button.copybtn img {
17+
width: 100%;
1218
}
1319

1420
div.highlight {
1521
position: relative;
1622
}
1723

18-
a.copybtn > img {
19-
vertical-align: top;
20-
margin: 0;
21-
top: 0;
22-
right: 0;
23-
position: absolute;
24+
.highlight:hover button.copybtn {
25+
opacity: .7;
2426
}
2527

26-
.highlight:hover .copybtn {
28+
.highlight button.copybtn:hover {
2729
opacity: 1;
2830
}
2931

sphinx_copybutton/_static/copybutton.js_t

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,8 @@ if( document.documentElement.lang !== undefined
4444
locale = document.documentElement.lang
4545
}
4646

47+
const path_static = `${DOCUMENTATION_OPTIONS.URL_ROOT}_static/`;
48+
4749
/**
4850
* Set up copy/paste for code blocks
4951
*/
@@ -77,6 +79,13 @@ const temporarilyChangeTooltip = (el, oldText, newText) => {
7779
setTimeout(() => el.setAttribute('data-tooltip', oldText), 2000)
7880
}
7981

82+
// Changes the copy button icon for two seconds, then changes it back
83+
const temporarilyChangeIcon = (el) => {
84+
img = el.querySelector("img");
85+
img.setAttribute('src', `${path_static}check-solid.svg`)
86+
setTimeout(() => img.setAttribute('src', `${path_static}{{ copybutton_image_path }}`), 2000)
87+
}
88+
8089
const addCopyButtonToCodeCells = () => {
8190
// If ClipboardJS hasn't loaded, wait a bit and try again. This
8291
// happens because we load ClipboardJS asynchronously.
@@ -93,9 +102,9 @@ const addCopyButtonToCodeCells = () => {
93102
const pre_bg = getComputedStyle(codeCell).backgroundColor;
94103

95104
const clipboardButton = id =>
96-
`<a class="copybtn o-tooltip--left" style="background-color: ${pre_bg}" data-tooltip="${messages[locale]['copy']}" data-clipboard-target="#${id}">
97-
<img src="${DOCUMENTATION_OPTIONS.URL_ROOT}_static/{{ copybutton_image_path }}" alt="${messages[locale]['copy_to_clipboard']}">
98-
</a>`
105+
`<button class="copybtn o-tooltip--left" style="background-color: ${pre_bg}" data-tooltip="${messages[locale]['copy']}" data-clipboard-target="#${id}">
106+
<img src="${path_static}{{ copybutton_image_path }}" alt="${messages[locale]['copy_to_clipboard']}">
107+
</button>`
99108
codeCell.insertAdjacentHTML('afterend', clipboardButton(id))
100109
})
101110

@@ -113,6 +122,7 @@ var copyTargetText = (trigger) => {
113122
clipboard.on('success', event => {
114123
clearSelection()
115124
temporarilyChangeTooltip(event.trigger, messages[locale]['copy'], messages[locale]['copy_success'])
125+
temporarilyChangeIcon(event.trigger)
116126
})
117127

118128
clipboard.on('error', event => {

0 commit comments

Comments
 (0)