| 1 |
# Badges, Buttons & Icons {octicon}`rocket` |
| 2 |
|
| 3 |
(badges)= |
| 4 |
|
| 5 |
## Badges |
| 6 |
|
| 7 |
Inline badges can be used as a labelling component. |
| 8 |
Badges are available in each semantic color, with filled and outline variants: |
| 9 |
|
| 10 |
- {bdg}`plain badge` |
| 11 |
- {bdg-primary}`primary`, {bdg-primary-line}`primary-line` |
| 12 |
- {bdg-secondary}`secondary`, {bdg-secondary-line}`secondary-line` |
| 13 |
- {bdg-success}`success`, {bdg-success-line}`success-line` |
| 14 |
- {bdg-info}`info`, {bdg-info-line}`info-line` |
| 15 |
- {bdg-warning}`warning`, {bdg-warning-line}`warning-line` |
| 16 |
- {bdg-danger}`danger`, {bdg-danger-line}`danger-line` |
| 17 |
- {bdg-light}`light`, {bdg-light-line}`light-line` |
| 18 |
- {bdg-muted}`muted`, {bdg-muted-line}`muted-line` |
| 19 |
- {bdg-dark}`dark`, {bdg-dark-line}`dark-line` |
| 20 |
- {bdg-white}`white`, {bdg-white-line}`white-line` |
| 21 |
- {bdg-black}`black`, {bdg-black-line}`black-line` |
| 22 |
|
| 23 |
`````{dropdown-syntax} |
| 24 |
|
| 25 |
````{tab-set-code} |
| 26 |
```{literalinclude} ./snippets/myst/badge-basic.txt |
| 27 |
:language: markdown |
| 28 |
``` |
| 29 |
```{literalinclude} ./snippets/rst/badge-basic.txt |
| 30 |
:language: rst |
| 31 |
``` |
| 32 |
```` |
| 33 |
````` |
| 34 |
|
| 35 |
`bdg-link-` and `bdg-ref-` variants are also available for use with links and references. |
| 36 |
The syntax is the same as for the `ref` role. |
| 37 |
|
| 38 |
{bdg-link-primary}`https://example.com` |
| 39 |
|
| 40 |
{bdg-link-primary-line}`explicit title <https://example.com>` |
| 41 |
|
| 42 |
{bdg-ref-primary}`badges` |
| 43 |
|
| 44 |
`````{dropdown-syntax} |
| 45 |
|
| 46 |
````{tab-set-code} |
| 47 |
```{literalinclude} ./snippets/myst/badge-link.txt |
| 48 |
:language: markdown |
| 49 |
``` |
| 50 |
```{literalinclude} ./snippets/rst/badge-link.txt |
| 51 |
:language: rst |
| 52 |
``` |
| 53 |
```` |
| 54 |
````` |
| 55 |
|
| 56 |
See [Bootstrap badges](https://getbootstrap.com/docs/5.0/components/badge/) for more information, and related [Material Design chips](https://material.io/components/chip). |
| 57 |
|
| 58 |
(buttons)= |
| 59 |
|
| 60 |
## Buttons |
| 61 |
|
| 62 |
Buttons allow users to navigate to external (`button-link`) / internal (`button-ref`) links with a single tap. |
| 63 |
|
| 64 |
```{button-link} https://example.com |
| 65 |
``` |
| 66 |
|
| 67 |
```{button-link} https://example.com |
| 68 |
Button text |
| 69 |
``` |
| 70 |
|
| 71 |
```{button-link} https://example.com |
| 72 |
:color: primary |
| 73 |
:shadow: |
| 74 |
``` |
| 75 |
|
| 76 |
```{button-link} https://example.com |
| 77 |
:color: primary |
| 78 |
:outline: |
| 79 |
``` |
| 80 |
|
| 81 |
```{button-link} https://example.com |
| 82 |
:color: secondary |
| 83 |
:expand: |
| 84 |
``` |
| 85 |
|
| 86 |
```{button-ref} buttons |
| 87 |
:color: info |
| 88 |
``` |
| 89 |
|
| 90 |
```{button-ref} buttons |
| 91 |
:color: info |
| 92 |
|
| 93 |
Reference Button text |
| 94 |
``` |
| 95 |
|
| 96 |
`````{dropdown-syntax} |
| 97 |
|
| 98 |
````{tab-set-code} |
| 99 |
```{literalinclude} ./snippets/myst/button-link.txt |
| 100 |
:language: markdown |
| 101 |
``` |
| 102 |
```{literalinclude} ./snippets/rst/button-link.txt |
| 103 |
:language: rst |
| 104 |
``` |
| 105 |
```` |
| 106 |
````` |
| 107 |
|
| 108 |
Note that by default sphinx converts the content of references to raw text. |
| 109 |
For example `**Bold text**` with `ref-type` set to `ref` will be rendered without bold: |
| 110 |
|
| 111 |
```{button-ref} buttons |
| 112 |
:ref-type: ref |
| 113 |
:color: primary |
| 114 |
|
| 115 |
**Bold text** |
| 116 |
``` |
| 117 |
|
| 118 |
However, if using [myst-parser](https://myst-parser.readthedocs.io/), you can set the `ref-type` to `myst`, and the content will be properly rendered: |
| 119 |
|
| 120 |
```{button-ref} buttons |
| 121 |
:ref-type: myst |
| 122 |
:color: primary |
| 123 |
|
| 124 |
**Bold text** |
| 125 |
``` |
| 126 |
|
| 127 |
Use the `click-parent` option to make the button's parent container also clickable. |
| 128 |
|
| 129 |
:::{card} Card with an expanded button |
| 130 |
|
| 131 |
```{button-link} https://example.com |
| 132 |
:color: info |
| 133 |
:expand: |
| 134 |
:click-parent: |
| 135 |
``` |
| 136 |
|
| 137 |
::: |
| 138 |
|
| 139 |
See the [Material Design](https://material.io/components/buttons) and [Bootstrap](https://getbootstrap.com/docs/5.0/components/buttons/) descriptions for further details. |
| 140 |
|
| 141 |
### `button-link` and `button-ref` options |
| 142 |
|
| 143 |
ref-type (`button-ref` only) |
| 144 |
: Type of reference to use; `any` (default), `ref`, `doc`, or `myst` |
| 145 |
|
| 146 |
color |
| 147 |
: Set the color of the button (background and font). |
| 148 |
One of the semantic color names: `primary`, `secondary`, `success`, `danger`, `warning`, `info`, `light`, `dark`, `muted`. |
| 149 |
|
| 150 |
outline |
| 151 |
: Outline color variant |
| 152 |
|
| 153 |
align |
| 154 |
: Align the button on the page; `left`, `right`, `center` or `justify` |
| 155 |
|
| 156 |
expand |
| 157 |
: Expand to fit parent width |
| 158 |
|
| 159 |
click-parent |
| 160 |
: Make parent container also clickable |
| 161 |
|
| 162 |
tooltip |
| 163 |
: Add tooltip on hover |
| 164 |
|
| 165 |
shadow |
| 166 |
: Add shadow CSS |
| 167 |
|
| 168 |
class |
| 169 |
: Additional CSS classes |
| 170 |
|
| 171 |
(icons)= |
| 172 |
|
| 173 |
## Inline Icons |
| 174 |
|
| 175 |
Inline icon roles are available for the [GitHub octicon](https://primer.style/octicons/), [Google Material Design Icons](https://github.com/google/material-design-icons), or [FontAwesome](https://fontawesome.com/icons?d=gallery&m=free) libraries. |
| 176 |
|
| 177 |
Octicon icons and Material icons are added as SVG's directly into the page with the `octicon` and `material-<flavor>` roles. See below for the different flavors of Material Design Icons. |
| 178 |
|
| 179 |
By default the icon will be of height `1em` (i.e. the height of the font). |
| 180 |
A specific height can be set after a semi-colon (`;`) with units of either `px`, `em` or `rem`. |
| 181 |
Additional CSS classes can also be added to the SVG after a second semi-colon (`;`) delimiter. |
| 182 |
|
| 183 |
### Octicon Icons |
| 184 |
|
| 185 |
A coloured icon: {octicon}`report;1em;sd-text-info`, some more text. |
| 186 |
|
| 187 |
````{tab-set-code} |
| 188 |
```{literalinclude} ./snippets/myst/icon-octicon.txt |
| 189 |
:language: markdown |
| 190 |
``` |
| 191 |
```{literalinclude} ./snippets/rst/icon-octicon.txt |
| 192 |
:language: rst |
| 193 |
``` |
| 194 |
```` |
| 195 |
|
| 196 |
````{dropdown} All Octicons |
| 197 |
:open: |
| 198 |
|
| 199 |
```{_all-octicon} |
| 200 |
``` |
| 201 |
```` |
| 202 |
|
| 203 |
### Material Design Icons |
| 204 |
|
| 205 |
Material Design icons come as several flavors. Each flavor represents a different role used in sphinx-design. These flavors are: |
| 206 |
|
| 207 |
- `material-regular` |
| 208 |
- `material-outlined` |
| 209 |
- `material-round` |
| 210 |
- `material-sharp` |
| 211 |
- `material-twotone` |
| 212 |
|
| 213 |
Not all icons are available for each flavor, but most are. Instead of displaying the 10660+ icons here, you are encouraged to browse the available icons from the [Material Design Icons' showcase](https://fonts.google.com/icons) hosted by Google. |
| 214 |
|
| 215 |
- A regular icon: {material-regular}`data_exploration;2em`, some more text |
| 216 |
- A coloured regular icon: {material-regular}`settings;3em;sd-text-success`, some more text. |
| 217 |
- A coloured outline icon: {material-outlined}`settings;3em;sd-text-success`, some more text. |
| 218 |
- A coloured sharp icon: {material-sharp}`settings;3em;sd-text-success`, some more text. |
| 219 |
- A coloured round icon: {material-round}`settings;3em;sd-text-success`, some more text. |
| 220 |
- A coloured two-tone icon: {material-twotone}`settings;3em;sd-text-success`, some more text. |
| 221 |
|
| 222 |
````{tab-set-code} |
| 223 |
```{literalinclude} ./snippets/myst/icon-material-design.txt |
| 224 |
:language: markdown |
| 225 |
``` |
| 226 |
```{literalinclude} ./snippets/rst/icon-material-design.txt |
| 227 |
:language: rst |
| 228 |
``` |
| 229 |
```` |
| 230 |
|
| 231 |
### FontAwesome Icons |
| 232 |
|
| 233 |
FontAwesome icons are added via the Fontawesome CSS classes. |
| 234 |
If the theme you are using does not already include the FontAwesome CSS, it should be loaded in your configuration from a [font-awesome CDN](https://cdnjs.com/libraries/font-awesome), with the [html_css_files](https://www.sphinx-doc.org/en/master/usage/configuration.html#confval-html_css_files) option, e.g.: |
| 235 |
|
| 236 |
```python |
| 237 |
html_css_files = [ |
| 238 |
"https://cdnjs.cloudflare.com/ajax/libs/font-awesome/6.1.1/css/all.min.css" |
| 239 |
] |
| 240 |
``` |
| 241 |
|
| 242 |
Use either `fa` (deprecated in font-awesome v5), `fas`, `fab` or `far` for the role name. |
| 243 |
Note that not all regular style icons are free, `far` role only works with free ones. |
| 244 |
|
| 245 |
````{warning} |
| 246 |
Since the FontAwesome icons are fetched directly from their distributed CSS, specifying a height/size to the `fa*` roles is not supported. |
| 247 |
However, you can always add your custom CSS class that controls the `font-size` property. |
| 248 |
|
| 249 |
If a height/size is supplied to a `fa*` role, then it will be interpreted as a CSS class. |
| 250 |
There can only be a maximum of 1 `;` in the `fa*` roles' arguments |
| 251 |
```` |
| 252 |
|
| 253 |
````{tab-set-code} |
| 254 |
```markdown |
| 255 |
- An icon {fas}`spinner;sd-text-primary`, some more text. |
| 256 |
- An icon {fab}`github`, some more text. |
| 257 |
- An icon {fab}`gitkraken;sd-text-success fa-xl`, some more text. |
| 258 |
- An icon {fas}`skull;sd-text-danger`, some more text. |
| 259 |
``` |
| 260 |
```rst |
| 261 |
- An icon :fas:`spinner;sd-text-primary`, some more text. |
| 262 |
- An icon :fab:`github`, some more text. |
| 263 |
- An icon :fab:`gitkraken;sd-text-success fa-xl`, some more text. |
| 264 |
- An icon :fas:`skull;sd-text-danger`, some more text. |
| 265 |
``` |
| 266 |
```` |
| 267 |
|
| 268 |
- An icon {fas}`spinner;sd-text-primary`, some more text. |
| 269 |
- An icon {fab}`github`, some more text. |
| 270 |
- An icon {fab}`gitkraken;sd-text-success fa-xl`, some more text. |
| 271 |
- An icon {fas}`skull;sd-text-danger`, some more text. |
| 272 |
|
| 273 |
By default, icons will only be output in HTML formats. But if you want FontAwesome icons to be output on LaTeX, using the [fontawesome package](https://ctan.org/pkg/fontawesome), you can add to your configuration: |
| 274 |
|
| 275 |
```python |
| 276 |
sd_fontawesome_latex = True |
| 277 |
``` |