Skip to content

Commit 5e0a433

Browse files
authored
Add inline icons roles (opticon and fontawesome) (#26)
1 parent 737a674 commit 5e0a433

9 files changed

Lines changed: 311 additions & 53 deletions

File tree

docs/index.rst

Lines changed: 55 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -2,11 +2,6 @@
22
sphinx-panels
33
=============
44

5-
.. contents::
6-
:local:
7-
:depth: 2
8-
9-
105
A sphinx extension for creating panels in a grid layout or as drop-downs.
116

127
- The ``panels`` directive creates panels of content in a grid layout, utilising both the bootstrap 4
@@ -15,6 +10,7 @@ A sphinx extension for creating panels in a grid layout or as drop-downs.
1510
- The ``link-button`` directive creates a click-able button, linking to a URL or reference,
1611
and can also be used to make an entire panel click-able.
1712
- The ``dropdown`` directive creates toggle-able content.
13+
- ``opticon`` and ``fa`` roles allow for inline icons to be added.
1814

1915
.. code-block:: rst
2016
@@ -28,7 +24,7 @@ A sphinx extension for creating panels in a grid layout or as drop-downs.
2824
2925
---
3026
31-
.. dropdown:: Bottom-left panel
27+
.. dropdown:: :fa:`eye,mr-1` Bottom-left panel
3228
3329
Hidden content
3430
@@ -48,7 +44,7 @@ A sphinx extension for creating panels in a grid layout or as drop-downs.
4844

4945
---
5046

51-
.. dropdown:: Bottom-left panel
47+
.. dropdown:: :fa:`eye,mr-1` Bottom-left panel
5248

5349
Hidden content
5450

@@ -58,8 +54,8 @@ A sphinx extension for creating panels in a grid layout or as drop-downs.
5854
:text: Clickable Panel
5955
:classes: stretched-link
6056

61-
.. dropdown:: See this documentation in other themes...
62-
:title: bg-info text-white
57+
.. dropdown:: :fa:`eye,mr-1` See this documentation in other themes
58+
:title: text-info font-weight-bold
6359

6460
Click the links to see the documentation built with:
6561

@@ -69,11 +65,20 @@ A sphinx extension for creating panels in a grid layout or as drop-downs.
6965
- `sphinx-book-theme <https://sphinx-panels.readthedocs.io/en/sphinx-book-theme/>`_
7066

7167

72-
.. tip::
68+
.. panels::
69+
:column: col-lg-12 p-0
70+
:header: text-secondary font-weight-bold
71+
72+
:fa:`arrows-alt,mr-1` Adaptive Sizing
73+
74+
^^^
7375

7476
Try shrinking the size of this window,
75-
to see how the panels realign to compensate for small screens.
77+
to see how the panels above realign to compensate for small screens.
7678

79+
.. contents::
80+
:local:
81+
:depth: 2
7782

7883
Installation
7984
============
@@ -564,6 +569,45 @@ Adding the ``animate`` option will trigger an animation when the content of the
564569

565570
Current available inputs: ``fade-in``, ``fade-in-slide-down``
566571

572+
Inline Icons
573+
============
574+
575+
Inline icons can be added to your text from either the
576+
`GitHub octicon <https://octicons-git-v2.primer.now.sh/octicons/>`_ or
577+
`FontAwesome <https://fontawesome.com/icons?d=gallery&m=free>`_ libraries.
578+
579+
====================================================== ===============================================
580+
rST Output
581+
====================================================== ===============================================
582+
``:opticon:`report``` :opticon:`report`
583+
``:opticon:`x-circle,text-white bg-danger,size=24``` :opticon:`x-circle,text-white bg-danger,size=24`
584+
``:fa:`save``` :fa:`save`
585+
``:fa:`spinner,text-white bg-primary fa-2x,style=fa``` :fa:`spinner,text-white bg-primary fa-2x,style=fa`
586+
====================================================== ===============================================
587+
588+
Note that the theme you are using does not already include the FontAwesome CSS,
589+
it should be loaded in your ``conf.py``,
590+
with the `html_css_files <https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_css_files>`_ option, e.g.:
591+
592+
.. code-block:: python
593+
594+
html_css_files = ["https://cdnjs.cloudflare.com/ajax/libs/font-awesome/4.7.0/css/font-awesome.min.css"]
595+
596+
By default, icons will only be output in HTML formats.
597+
But if you want fontawesome icons to be output on LaTeX, using the `fontawesome package <https://ctan.org/pkg/fontawesome>`_,
598+
you can add to your ``conf.py``:
599+
600+
.. code-block:: python
601+
602+
panels_add_fontawesome_latex = True
603+
604+
Additional classes can be added after a comma delimiter.
605+
Also the size (16px or 24px) can be set for opticons, and the style/prefix for fontawesome (version 5).
606+
607+
.. seealso::
608+
609+
https://www.w3schools.com/icons/fontawesome_icons_intro.asp
610+
567611
Div Directive
568612
=============
569613

setup.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
"css/bs-buttons.css",
3232
"css/panels-bootstrap.min.css",
3333
"css/sphinx-dropdown.css",
34+
"data/opticons.json",
3435
]
3536
},
3637
install_requires=["docutils", "sphinx"],

sphinx_panels/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@
77
from .button import setup_link_button
88
from .dropdown import setup_dropdown
99
from .panels import setup_panels
10+
from .icons import setup_icons
1011

1112
__version__ = "0.4.0"
1213

@@ -77,6 +78,7 @@ def setup(app):
7778
setup_panels(app)
7879
setup_link_button(app)
7980
setup_dropdown(app)
81+
setup_icons(app)
8082

8183
return {
8284
"version": __version__,

sphinx_panels/css/sphinx-dropdown.css

Lines changed: 17 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
.octicon {
2+
display: inline-block;
3+
vertical-align: text-top;
4+
fill: currentColor;
5+
}
16
details.dropdown .summary-title {
27
-webkit-user-select: none;
38
-moz-user-select: none;
@@ -24,39 +29,39 @@ details.dropdown summary::-webkit-details-marker {
2429
details.dropdown summary:focus {
2530
outline: none;
2631
}
27-
details.dropdown summary:hover .summary-chevron-up svg,
28-
details.dropdown summary:hover .summary-chevron-down svg {
32+
details.dropdown summary:hover .summary-up svg,
33+
details.dropdown summary:hover .summary-down svg {
2934
opacity: 1;
3035
}
31-
details.dropdown .summary-chevron-up svg,
32-
details.dropdown .summary-chevron-down svg {
36+
details.dropdown .summary-up svg,
37+
details.dropdown .summary-down svg {
3338
opacity: 0.6;
3439
}
35-
details.dropdown .summary-chevron-up,
36-
details.dropdown .summary-chevron-down {
40+
details.dropdown .summary-up,
41+
details.dropdown .summary-down {
3742
pointer-events: none;
3843
position: absolute;
3944
top: 0.75em;
4045
right: 1em;
4146
}
42-
details.dropdown .summary-chevron-up svg,
43-
details.dropdown .summary-chevron-down svg {
47+
details.dropdown .summary-up svg,
48+
details.dropdown .summary-down svg {
4449
display: block;
4550
}
46-
details.dropdown[open] .summary-chevron-up{
51+
details.dropdown[open] .summary-down{
4752
visibility: hidden;
4853
/* z-index: -1; */
4954
}
50-
details.dropdown:not([open]) .summary-chevron-down{
55+
details.dropdown:not([open]) .summary-up{
5156
visibility: hidden;
5257
/* z-index: -1; */
5358
}
5459

5560
/* Ellipsis added when no title */
56-
details.dropdown summary .ellipsis {
61+
details.dropdown summary .octicon.no-title {
5762
vertical-align: middle;
5863
}
59-
details.dropdown[open] summary .ellipsis{
64+
details.dropdown[open] summary .octicon.no-title{
6065
visibility: hidden;
6166
}
6267

sphinx_panels/data/LICENSE

Lines changed: 21 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,21 @@
1+
MIT License
2+
3+
Copyright (c) 2020 GitHub Inc.
4+
5+
Permission is hereby granted, free of charge, to any person obtaining a copy
6+
of this software and associated documentation files (the "Software"), to deal
7+
in the Software without restriction, including without limitation the rights
8+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9+
copies of the Software, and to permit persons to whom the Software is
10+
furnished to do so, subject to the following conditions:
11+
12+
The above copyright notice and this permission notice shall be included in all
13+
copies or substantial portions of the Software.
14+
15+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
21+
SOFTWARE.

sphinx_panels/data/opticons.json

Lines changed: 1 addition & 0 deletions
Large diffs are not rendered by default.

sphinx_panels/dropdown.py

Lines changed: 21 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,6 +6,8 @@
66
from sphinx.transforms.post_transforms import SphinxPostTransform
77
from sphinx.util.nodes import NodeMatcher
88

9+
from .icons import get_opticon
10+
911

1012
def setup_dropdown(app):
1113
app.add_node(dropdown_main, html=(visit_dropdown_main, depart_dropdown_main))
@@ -50,7 +52,6 @@ class DropdownDirective(SphinxDirective):
5052
"title": directives.unchanged,
5153
"body": directives.unchanged,
5254
"open": directives.flag,
53-
"marker-color": directives.unchanged,
5455
"name": directives.unchanged,
5556
"animate": lambda a: directives.choice(a, ("fade-in", "fade-in-slide-down")),
5657
}
@@ -83,7 +84,6 @@ def run(self):
8384

8485
container = nodes.container(
8586
"",
86-
marker_color=self.options.get("marker-color", "currentColor"),
8787
opened="open" in self.options,
8888
type="dropdown",
8989
has_title=len(self.arguments) > 0,
@@ -98,18 +98,10 @@ def run(self):
9898
return [container]
9999

100100

101-
CHEVRON = """\
102-
<svg xmlns="http://www.w3.org/2000/svg" width="24" height="24"
103-
viewBox="0 0 24 24" fill="none"
104-
stroke="{color}" stroke-width="2"stroke-linecap="round" stroke-linejoin="round"
105-
>
106-
<polyline points="{points}"></polyline>
107-
</svg>"""
108-
109-
ELLIPSIS = """\
101+
KEBAB = """\
110102
<svg viewBox="0 0 36 24" width="36" height="16" xmlns="http://www.w3.org/2000/svg"
111-
data-icon="ui-components:ellipses" class="ellipsis">
112-
<g xmlns="http://www.w3.org/2000/svg" class="jp-icon3" fill="currentColor">
103+
class="octicon no-title" aria-hidden="true">
104+
<g xmlns="http://www.w3.org/2000/svg" class="jp-icon3">
113105
<circle cx="0" cy="12" r="6"></circle>
114106
<circle cx="18" cy="12" r="6"></circle>
115107
<circle cx="36" cy="12" r="6"></circle>
@@ -128,30 +120,18 @@ def run(self):
128120
open_marker = nodes.container(
129121
"",
130122
nodes.raw(
131-
"",
132-
nodes.Text(
133-
CHEVRON.format(
134-
color=node["marker_color"], points="18 15 12 9 6 15"
135-
)
136-
),
137-
format="html",
123+
"", nodes.Text(get_opticon("chevron-up", size=24)), format="html"
138124
),
139125
is_div=True,
140-
classes=["summary-chevron-down"],
126+
classes=["summary-up"],
141127
)
142128
closed_marker = nodes.container(
143129
"",
144130
nodes.raw(
145-
"",
146-
nodes.Text(
147-
CHEVRON.format(
148-
color=node["marker_color"], points="6 9 12 15 18 9"
149-
)
150-
),
151-
format="html",
131+
"", nodes.Text(get_opticon("chevron-down", size=24)), format="html"
152132
),
153133
is_div=True,
154-
classes=["summary-chevron-up"],
134+
classes=["summary-down"],
155135
)
156136

157137
newnode = dropdown_main(
@@ -163,7 +143,18 @@ def run(self):
163143
title_children = node[0]
164144
body_children = node[1:]
165145
else:
166-
title_children = [nodes.raw("...", nodes.Text(ELLIPSIS), format="html")]
146+
title_children = [
147+
nodes.raw(
148+
"...",
149+
nodes.Text(
150+
KEBAB
151+
# Note the custom opticon here has thicker dots
152+
# get_opticon("kebab-horizontal", classes="no-title",
153+
# size=24)
154+
),
155+
format="html",
156+
)
157+
]
167158
body_children = node
168159

169160
newnode += dropdown_title(

0 commit comments

Comments
 (0)