Skip to content

Commit b51ee8b

Browse files
authored
Update button for more minimal style inspired by jupyterlab (#47)
* Update button for jupyter style * Simplifying design further * More CSS improvements * Fix CSS * Fix index * Lighten CSS elements * Cleaning up CSS for more reliable behavior
1 parent 7fd95fc commit b51ee8b

File tree

8 files changed

+175
-205
lines changed

8 files changed

+175
-205
lines changed

Diff for: docs/conf.py

+4-141
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,7 @@
1-
# -*- coding: utf-8 -*-
2-
#
3-
# Configuration file for the Sphinx documentation builder.
4-
#
5-
# This file does only contain a selection of the most common options. For a
6-
# full list see the documentation:
7-
# http://www.sphinx-doc.org/en/master/config
8-
9-
# -- Path setup --------------------------------------------------------------
10-
11-
# If extensions (or modules to document with autodoc) are in another directory,
12-
# add these directories to sys.path here. If the directory is relative to the
13-
# documentation root, use os.path.abspath to make it absolute, like shown here.
14-
#
15-
# import os
16-
# import sys
17-
# sys.path.insert(0, os.path.abspath('.'))
18-
19-
201
# -- Project information -----------------------------------------------------
212

223
project = "Sphinx Toggle Button"
23-
copyright = "2018, Chris Holdgraf"
4+
copyright = "2022, Executable Books Community"
245
author = "Chris Holdgraf"
256

267
# The short X.Y version
@@ -30,51 +11,17 @@
3011

3112

3213
# -- General configuration ---------------------------------------------------
33-
34-
# If your documentation needs a minimal Sphinx version, state it here.
35-
#
36-
# needs_sphinx = '1.0'
37-
38-
# Add any Sphinx extension module names here, as strings. They can be
39-
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
40-
# ones.
41-
extensions = ["myst_parser", "sphinx_design", "sphinx_togglebutton"]
42-
43-
# Add any paths that contain templates here, relative to this directory.
14+
extensions = ["myst_nb", "sphinx_examples", "sphinx_design", "sphinx_togglebutton"]
4415
templates_path = ["_templates"]
45-
46-
# The suffix(es) of source filenames.
47-
# You can specify multiple suffix as a list of string:
48-
#
49-
# source_suffix = ['.rst', '.md']
5016
source_suffix = ".rst"
51-
52-
# The master toctree document.
53-
master_doc = "index"
54-
55-
# The language for content autogenerated by Sphinx. Refer to documentation
56-
# for a list of supported languages.
57-
#
58-
# This is also used if you do content translation via gettext catalogs.
59-
# Usually you set "language" from the command line for these cases.
17+
main_doc = "index"
6018
language = None
61-
62-
# List of patterns, relative to source directory, that match files and
63-
# directories to ignore when looking for source files.
64-
# This pattern also affects html_static_path and html_extra_path .
6519
exclude_patterns = ["_build", "Thumbs.db", ".DS_Store"]
6620

67-
# The name of the Pygments (syntax highlighting) style to use.
68-
#pygments_style = "sphinx"
69-
70-
7121
# -- Options for HTML output -------------------------------------------------
72-
73-
# The theme to use for HTML and HTML Help pages. See the documentation for
74-
# a list of builtin themes.
75-
#
7622
html_theme = "sphinx_book_theme"
7723
# html_theme = "sphinx_rtd_theme" # These are just for testing
24+
# html_theme = "pydata_sphinx_theme"
7825
# html_theme = "alabaster"
7926
# html_theme = "furo"
8027

@@ -92,87 +39,3 @@
9239
# togglebutton_hint = "test show"
9340
# togglebutton_hint_hide = "test hide"
9441
# togglebutton_open_on_print = False
95-
96-
# Add any paths that contain custom static files (such as style sheets) here,
97-
# relative to this directory. They are copied after the builtin static files,
98-
# so a file named "default.css" will overwrite the builtin "default.css".
99-
# html_static_path = ["_static"]
100-
101-
# Custom sidebar templates, must be a dictionary that maps document names
102-
# to template names.
103-
#
104-
# The default sidebars (for documents that don't match any pattern) are
105-
# defined by theme itself. Builtin themes are using these templates by
106-
# default: ``['localtoc.html', 'relations.html', 'sourcelink.html',
107-
# 'searchbox.html']``.
108-
#
109-
# html_sidebars = {}
110-
111-
# -- Options for HTMLHelp output ---------------------------------------------
112-
113-
# Output file base name for HTML help builder.
114-
htmlhelp_basename = "SphinxCollapseAdmonitionsdoc"
115-
116-
117-
# -- Options for LaTeX output ------------------------------------------------
118-
119-
latex_elements = {
120-
# The paper size ('letterpaper' or 'a4paper').
121-
#
122-
# 'papersize': 'letterpaper',
123-
# The font size ('10pt', '11pt' or '12pt').
124-
#
125-
# 'pointsize': '10pt',
126-
# Additional stuff for the LaTeX preamble.
127-
#
128-
# 'preamble': '',
129-
# Latex figure (float) alignment
130-
#
131-
# 'figure_align': 'htbp',
132-
}
133-
134-
# Grouping the document tree into LaTeX files. List of tuples
135-
# (source start file, target name, title,
136-
# author, documentclass [howto, manual, or own class]).
137-
latex_documents = [
138-
(
139-
master_doc,
140-
"SphinxCollapseAdmonitions.tex",
141-
"Sphinx Collapse Admonitions Documentation",
142-
"Chris Holdgraf",
143-
"manual",
144-
)
145-
]
146-
147-
148-
# -- Options for manual page output ------------------------------------------
149-
150-
# One entry per manual page. List of tuples
151-
# (source start file, name, description, authors, manual section).
152-
man_pages = [
153-
(
154-
master_doc,
155-
"SphinxCollapseAdmonitions",
156-
"Sphinx Collapse Admonitions Documentation",
157-
[author],
158-
1,
159-
)
160-
]
161-
162-
163-
# -- Options for Texinfo output ----------------------------------------------
164-
165-
# Grouping the document tree into Texinfo files. List of tuples
166-
# (source start file, target name, title, author,
167-
# dir menu entry, description, category)
168-
texinfo_documents = [
169-
(
170-
master_doc,
171-
"SphinxCollapseAdmonitions",
172-
"Sphinx Collapse Admonitions Documentation",
173-
author,
174-
"SphinxCollapseAdmonitions",
175-
"One line description of project.",
176-
"Miscellaneous",
177-
)
178-
]

Diff for: docs/index.md

+7-16
Original file line numberDiff line numberDiff line change
@@ -7,19 +7,15 @@ For example:
77

88
You can collapse admonitions (notes, warnings, etc) so that their content is hidden until users click the admonition title.
99

10-
:::{admonition} Example: click this title to toggle the content
11-
:class: dropdown
12-
You can toggle any admonition to hide its content behind a user click!
13-
Do so by adding a `dropdown` class to the admonition, like this:
10+
````{example} An example admonition toggle
11+
:reverse:
1412
15-
````
16-
```{note}
13+
:::{admonition} Click the title to toggle
1714
:class: dropdown
1815
19-
Some content
20-
```
21-
````
16+
This title was made into a dropdown admonition by adding `:class: dropdown` to it.
2217
:::
18+
````
2319

2420
See {ref}`dropdown-admonitions` for more information.
2521

@@ -29,19 +25,14 @@ You can also hide arbitrary content behind a toggle button.
2925
When users press the button, they will see the content.
3026
For example:
3127

32-
::::{toggle}
28+
````{example} An example toggle directive
29+
:reverse:
3330
34-
This is a toggled content block!
35-
It was added like this:
36-
37-
````
3831
```{toggle}
3932
This is a toggled content block!
4033
```
4134
````
4235

43-
::::
44-
4536
You can either do this with a `{toggle}` directive, or by adding a `toggle` CSS class to any elements you'd like hidden behind a toggle button.
4637

4738
See [](use:css-selector) for more details.

Diff for: docs/reference/index.md

+4
Original file line numberDiff line numberDiff line change
@@ -3,6 +3,10 @@
33
This page shows the most common ways that `sphinx-togglebutton` is used as a reference.
44
This is a benchmark for styling, and also helps demonstrate the behavior of this extension.
55

6+
```{toctree}
7+
notebooks
8+
```
9+
610
## Use amongst text
711

812
Here's a paragraph, it's just here to provide some text context for the togglebuttons in this section.

Diff for: docs/reference/notebooks.md

+98
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,98 @@
1+
---
2+
jupytext:
3+
formats: ipynb,md:myst
4+
text_representation:
5+
extension: .md
6+
format_name: myst
7+
format_version: 0.12
8+
jupytext_version: 1.8.2
9+
kernelspec:
10+
display_name: Python 3
11+
language: python
12+
name: python3
13+
---
14+
15+
# Jupyter notebooks
16+
17+
Sphinx Togglebutton has support within MyST-NB.
18+
This page shows off showing / hiding inputs, outputs, and entire cells.
19+
20+
```{code-cell} ipython3
21+
:tags: [hide-cell]
22+
23+
from matplotlib import rcParams, cycler
24+
import matplotlib.pyplot as plt
25+
import numpy as np
26+
```
27+
28+
## Hiding the cell
29+
30+
```{code-cell} ipython3
31+
:tags: [hide-cell]
32+
# Fixing random state for reproducibility
33+
np.random.seed(19680801)
34+
35+
N = 10
36+
data = [np.logspace(0, 1, 100) + np.random.randn(100) + ii for ii in range(N)]
37+
data = np.array(data).T
38+
cmap = plt.cm.coolwarm
39+
rcParams['axes.prop_cycle'] = cycler(color=cmap(np.linspace(0, 1, N)))
40+
41+
42+
from matplotlib.lines import Line2D
43+
custom_lines = [Line2D([0], [0], color=cmap(0.), lw=4),
44+
Line2D([0], [0], color=cmap(.5), lw=4),
45+
Line2D([0], [0], color=cmap(1.), lw=4)]
46+
47+
fig, ax = plt.subplots(figsize=(10, 5))
48+
lines = ax.plot(data)
49+
ax.legend(custom_lines, ['Cold', 'Medium', 'Hot']);
50+
```
51+
52+
## Hiding input
53+
54+
```{code-cell} ipython3
55+
:tags: [hide-input]
56+
# Fixing random state for reproducibility
57+
np.random.seed(19680801)
58+
59+
N = 10
60+
data = [np.logspace(0, 1, 100) + np.random.randn(100) + ii for ii in range(N)]
61+
data = np.array(data).T
62+
cmap = plt.cm.coolwarm
63+
rcParams['axes.prop_cycle'] = cycler(color=cmap(np.linspace(0, 1, N)))
64+
65+
66+
from matplotlib.lines import Line2D
67+
custom_lines = [Line2D([0], [0], color=cmap(0.), lw=4),
68+
Line2D([0], [0], color=cmap(.5), lw=4),
69+
Line2D([0], [0], color=cmap(1.), lw=4)]
70+
71+
fig, ax = plt.subplots(figsize=(10, 5))
72+
lines = ax.plot(data)
73+
ax.legend(custom_lines, ['Cold', 'Medium', 'Hot']);
74+
```
75+
76+
## Hiding output
77+
78+
```{code-cell} ipython3
79+
:tags: [hide-output]
80+
# Fixing random state for reproducibility
81+
np.random.seed(19680801)
82+
83+
N = 10
84+
data = [np.logspace(0, 1, 100) + np.random.randn(100) + ii for ii in range(N)]
85+
data = np.array(data).T
86+
cmap = plt.cm.coolwarm
87+
rcParams['axes.prop_cycle'] = cycler(color=cmap(np.linspace(0, 1, N)))
88+
89+
90+
from matplotlib.lines import Line2D
91+
custom_lines = [Line2D([0], [0], color=cmap(0.), lw=4),
92+
Line2D([0], [0], color=cmap(.5), lw=4),
93+
Line2D([0], [0], color=cmap(1.), lw=4)]
94+
95+
fig, ax = plt.subplots(figsize=(10, 5))
96+
lines = ax.plot(data)
97+
ax.legend(custom_lines, ['Cold', 'Medium', 'Hot']);
98+
```

Diff for: docs/use.md

+2-19
Original file line numberDiff line numberDiff line change
@@ -24,20 +24,11 @@ You can hide any content and display a toggle button to show it by using certain
2424
</details>
2525
```
2626

27-
:::{admonition} example
28-
:class: tip
29-
This MyST Markdown:
30-
31-
````md
27+
````{example}
3228
```{image} https://media.giphy.com/media/FaKV1cVKlVRxC/giphy.gif
3329
:class: toggle
3430
```
3531
````
36-
results in:
37-
```{image} https://media.giphy.com/media/FaKV1cVKlVRxC/giphy.gif
38-
:class: toggle
39-
```
40-
:::
4132

4233
### Configure the CSS selector used to insert toggle buttons
4334

@@ -65,20 +56,12 @@ sphinx_togglebutton_selector = ".toggle-this-element, #my-special-id"
6556
`sphinx-togglebutton` treats admonitions as a special case if they are selected.
6657
If a Sphinx admonition matches the toggle button selector, then its title will be displayed with a button to reveal its content.
6758

68-
:::{admonition} example
69-
:class: tip
70-
````md
59+
````{example}
7160
```{admonition} This will be shown
7261
:class: dropdown
7362
And this will be hidden!
7463
```
7564
````
76-
results in
77-
```{admonition} This will be shown
78-
:class: dropdown
79-
And this will be hidden!
80-
```
81-
:::
8265

8366
This works for any kind of Sphinx admoniton:
8467

Diff for: setup.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,6 @@
2727
"sphinx_togglebutton": ["_static/togglebutton.css", "_static/togglebutton.js", "_static/togglebutton-chevron.svg"]
2828
},
2929
install_requires=["setuptools", "wheel", "sphinx", "docutils"],
30-
extras_require={"sphinx": ["myst_parser", "sphinx_book_theme", "sphinx_design"]},
30+
extras_require={"sphinx": ["matplotlib", "numpy", "myst_nb", "sphinx_book_theme", "sphinx_design", "sphinx_examples"]},
3131
classifiers=["License :: OSI Approved :: MIT License"],
3232
)

0 commit comments

Comments
 (0)