Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

✨ ENH: Update icon to use GitHub style #133

Merged
merged 3 commits into from
Jul 3, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
1 change: 1 addition & 0 deletions docs/conf.py
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@
html_theme = "sphinx_book_theme"
# html_theme = "alabaster"
# html_theme = "sphinx_rtd_theme"
# html_theme = "furo"

# Theme options are theme-specific and customize the look and feel of a theme
# further. For a list of options available for each theme, see the
Expand Down
5 changes: 5 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -61,5 +61,10 @@
install_requires=["sphinx>=1.8"],
extras_require={
"code_style": ["pre-commit==2.12.1"],
"rtd": [
"sphinx",
"ipython",
"sphinx-book-theme",
],
},
)
2 changes: 1 addition & 1 deletion sphinx_copybutton/_static/check-solid.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
6 changes: 3 additions & 3 deletions sphinx_copybutton/_static/copy-button.svg
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
28 changes: 20 additions & 8 deletions sphinx_copybutton/_static/copybutton.css
Original file line number Diff line number Diff line change
@@ -1,32 +1,45 @@
/* Copy buttons */
button.copybtn {
position: absolute;
display: flex;
top: .3em;
right: .5em;
width: 1.7rem;
height: 1.7rem;
width: 1.7em;
height: 1.7em;
opacity: 0;
transition: opacity 0.3s, border .3s;
transition: opacity 0.3s, border .3s, background-color .3s;
user-select: none;
padding: 0;
border: none;
outline: none;
border-radius: 0.4em;
border: #e1e1e1 1px solid;
background-color: rgb(245, 245, 245);
}

button.copybtn.success {
border-color: #22863a;
}

button.copybtn img {
width: 100%;
padding: .2em;
}

div.highlight {
position: relative;
}

.highlight:hover button.copybtn {
opacity: .7;
opacity: 1;
}

.highlight button.copybtn:hover {
opacity: 1;
background-color: rgb(235, 235, 235);
}

.highlight button.copybtn:active {
background-color: rgb(187, 187, 187);
}

/**
Expand All @@ -46,11 +59,10 @@ div.highlight {
visibility: hidden;
position: absolute;
content: attr(data-tooltip);
padding: 2px;
top: 0;
padding: .2em;
font-size: .8em;
left: -.2em;
background: grey;
font-size: 1rem;
color: white;
white-space: nowrap;
z-index: 2;
Expand Down
5 changes: 3 additions & 2 deletions sphinx_copybutton/_static/copybutton.js_t
Original file line number Diff line number Diff line change
Expand Up @@ -81,7 +81,9 @@ const clearSelection = () => {
// Changes tooltip text for two seconds, then changes it back
const temporarilyChangeTooltip = (el, oldText, newText) => {
el.setAttribute('data-tooltip', newText)
el.classList.add('success')
setTimeout(() => el.setAttribute('data-tooltip', oldText), 2000)
setTimeout(() => el.classList.remove('success'), 2000)
}

// Changes the copy button icon for two seconds, then changes it back
Expand All @@ -104,10 +106,9 @@ const addCopyButtonToCodeCells = () => {
codeCells.forEach((codeCell, index) => {
const id = codeCellId(index)
codeCell.setAttribute('id', id)
const pre_bg = getComputedStyle(codeCell).backgroundColor;

const clipboardButton = id =>
`<button class="copybtn o-tooltip--left" style="background-color: ${pre_bg}" data-tooltip="${messages[locale]['copy']}" data-clipboard-target="#${id}">
`<button class="copybtn o-tooltip--left" data-tooltip="${messages[locale]['copy']}" data-clipboard-target="#${id}">
<img src="${path_static}{{ copybutton_image_path }}" alt="${messages[locale]['copy_to_clipboard']}">
</button>`
codeCell.insertAdjacentHTML('afterend', clipboardButton(id))
Expand Down
42 changes: 42 additions & 0 deletions tox.ini
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
# To use tox, see https://tox.readthedocs.io
# Simply pip or conda install tox
# If you use conda, you may also want to install tox-conda
# then run `tox` or `tox -- {pytest args}`
# To run in parallel using `tox -p` (this does not appear to work for this repo)

# To rebuild the tox environment, for example when dependencies change, use
# `tox -r`

# Note: if the following error is encountered: `ImportError while loading conftest`
# then then deleting compiled files has been found to fix it: `find . -name \*.pyc -delete`

[tox]
envlist = py37-sphinx3

[testenv]
# only recreate the environment when we use `tox -r`
recreate = false

[testenv:docs-build]
description = Build the documentation and launch browser
extras =
rtd
commands =
sphinx-build \
-n -b {posargs:html} docs/ docs/_build/{posargs:html}

[testenv:docs-live]
description = Build the documentation and launch browser
deps =
sphinx-autobuild
sphinx-rtd-theme
alabaster
furo
extras =
rtd
commands =
sphinx-autobuild \
--re-ignore _build/.* \
--watch sphinx_copybutton \
--port 0 --open-browser \
-n -b {posargs:html} docs/ docs/_build/{posargs:html}