|
| 1 | +--- |
| 2 | +title: Icons |
| 3 | +--- |
| 4 | + |
| 5 | +# Icons |
| 6 | + |
| 7 | +<p class="lead">Add icons to enhance your application.</p> |
| 8 | + |
| 9 | +As with the [CSS stylesheets](/docs/themes), _dash-bootstrap-components_ doesn't come pre-bundled with icons. This is to give you the freedom to use any icon library of your choice. |
| 10 | + |
| 11 | +There are a number of different icon libraries available, which you can link to via CDN, or serve locally depending on your needs. Details on how to link css can be found in the [themes](/docs/themes) documentation. |
| 12 | + |
| 13 | +## Packaged CDN links |
| 14 | + |
| 15 | +_dash-bootstrap-components_ contains CDN links for [Bootstrap Icons](https://icons.getbootstrap.com/) and [Font Awesome](https://fontawesome.com/), two libraries of icons you can use in your apps. You can use either of them by adding them to `external_stylesheets` when instantiating your app. |
| 16 | + |
| 17 | +Bootstrap Icons was developed by the Bootstrap team specifically for use with Bootstrap. There is excellent documentation on how to use them on the [Bootstrap website](https://icons.getbootstrap.com/#usage), and a small example below. |
| 18 | + |
| 19 | +Font Awesome is perhaps the most widely used icon library and is very commonly used with Bootstrap. Usage is similar to Bootstrap Icons, check [their documentation](https://fontawesome.com/v5.15/how-to-use/on-the-web/referencing-icons/basic-use) for more details. |
| 20 | + |
| 21 | +~~~bootstrap-tabs |
| 22 | +Python |
| 23 | +
|
| 24 | +Links are available in the `dash_bootstrap_components.icons` submodule. |
| 25 | +
|
| 26 | +```python |
| 27 | +import dash |
| 28 | +import dash_bootstrap_components as dbc |
| 29 | +
|
| 30 | +# For Bootstrap Icons... |
| 31 | +app = dash.Dash( |
| 32 | + external_stylesheets=[dbc.themes.BOOTSTRAP, dbc.icons.BOOTSTRAP] |
| 33 | +) |
| 34 | +# Or for Font Awesome Icons... |
| 35 | +app = dash.Dash( |
| 36 | + external_stylesheets=[dbc.themes.BOOTSTRAP, dbc.icons.FONT_AWESOME] |
| 37 | +) |
| 38 | +
|
| 39 | +``` |
| 40 | +----- |
| 41 | +R |
| 42 | +
|
| 43 | +Links are available in the `dbcIcons` list which is added to your namespace when you import `dashBootstrapComponents`. |
| 44 | +
|
| 45 | +```r |
| 46 | +library(dash) |
| 47 | +library(dashBootstrapComponents) |
| 48 | +
|
| 49 | +# For Bootstrap Icons... |
| 50 | +app <- Dash$new( |
| 51 | + external_stylesheets = list(dbcThemes$BOOTSTRAP, dbcIcons$BOOTSTRAP) |
| 52 | +) |
| 53 | +# Or for Font Awesome Icons... |
| 54 | +app <- Dash$new( |
| 55 | + external_stylesheets = list(dbcThemes$BOOTSTRAP, dbcIcons$FONT_AWESOME) |
| 56 | +) |
| 57 | +``` |
| 58 | +
|
| 59 | +----- |
| 60 | +Julia |
| 61 | +
|
| 62 | +Links are available as part of the `dbc_icons` named tuple available in `DashBootstrapComponents`. |
| 63 | +
|
| 64 | +```julia |
| 65 | +using Dash, DashBootstrapComponents |
| 66 | +
|
| 67 | +# For Bootstrap Icons... |
| 68 | +app = dash( |
| 69 | + external_stylesheets=[dbc_themes.BOOTSTRAP, dbc_icons.BOOTSTRAP] |
| 70 | +) |
| 71 | +# Or for Font Awesome Icons... |
| 72 | +app = dash( |
| 73 | + external_stylesheets=[dbc_themes.BOOTSTRAP, dbc_icons.FONT_AWESOME] |
| 74 | +) |
| 75 | +``` |
| 76 | +~~~ |
| 77 | + |
| 78 | +## Example |
| 79 | + |
| 80 | +This simple example adds Bootstrap Icons to some alerts. |
| 81 | + |
| 82 | +~~~bootstrap-example-tabs |
| 83 | +<div> |
| 84 | + <div class="alert alert-info d-flex align-items-center"> |
| 85 | + <i class="bi bi-info-circle-fill me-2"></i> |
| 86 | + An example info alert with an icon |
| 87 | + </div> |
| 88 | + <div class="alert alert-success d-flex align-items-center"> |
| 89 | + <i class="bi bi-check-circle-fill me-2"></i> |
| 90 | + An example success alert with an icon |
| 91 | + </div> |
| 92 | + <div class="alert alert-warning d-flex align-items-center"> |
| 93 | + <i class="bi bi-exclamation-triangle-fill me-2"></i> |
| 94 | + An example warning alert with an icon |
| 95 | + </div> |
| 96 | + <div class="alert alert-danger d-flex align-items-center"> |
| 97 | + <i class="bi bi-x-octagon-fill me-2"></i> |
| 98 | + An example danger alert with an icon |
| 99 | + </div> |
| 100 | +</div> |
| 101 | +----- |
| 102 | +Python |
| 103 | +
|
| 104 | +```python |
| 105 | +import dash_bootstrap_components as dbc |
| 106 | +import dash_html_components as html |
| 107 | +
|
| 108 | +alerts = html.Div( |
| 109 | + [ |
| 110 | + dbc.Alert( |
| 111 | + [ |
| 112 | + html.I(class_name="bi bi-info-circle-fill me-2"), |
| 113 | + "An example info alert with an icon", |
| 114 | + ], |
| 115 | + color="info", |
| 116 | + class_name="d-flex align-items-center", |
| 117 | + ), |
| 118 | + dbc.Alert( |
| 119 | + [ |
| 120 | + html.I(class_name="bi bi-check-circle-fill me-2"), |
| 121 | + "An example success alert with an icon", |
| 122 | + ], |
| 123 | + color="success", |
| 124 | + class_name="d-flex align-items-center", |
| 125 | + ), |
| 126 | + dbc.Alert( |
| 127 | + [ |
| 128 | + html.I(class_name="bi bi-exclamation-triangle-fill me-2"), |
| 129 | + "An example warning alert with an icon", |
| 130 | + ], |
| 131 | + color="warning", |
| 132 | + class_name="d-flex align-items-center", |
| 133 | + ), |
| 134 | + dbc.Alert( |
| 135 | + [ |
| 136 | + html.I(class_name="bi bi-x-octagon-fill me-2"), |
| 137 | + "An example danger alert with an icon", |
| 138 | + ], |
| 139 | + color="danger", |
| 140 | + class_name="d-flex align-items-center", |
| 141 | + ), |
| 142 | + ] |
| 143 | +) |
| 144 | +``` |
| 145 | +----- |
| 146 | +R |
| 147 | +
|
| 148 | +```r |
| 149 | +library(dashBootstrapComponents) |
| 150 | +library(dashHtmlComponents) |
| 151 | +
|
| 152 | +alerts <- htmlDiv( |
| 153 | + list( |
| 154 | + dbcAlert( |
| 155 | + list( |
| 156 | + htmlI(class_name = "bi bi-info-circle-fill me-2"), |
| 157 | + "An example info alert with an icon" |
| 158 | + ), |
| 159 | + color = "info", |
| 160 | + class_name = "d-flex align-items-center" |
| 161 | + ), |
| 162 | + dbcAlert( |
| 163 | + list( |
| 164 | + htmlI(class_name = "bi bi-check-circle-fill me-2"), |
| 165 | + "An example success alert with an icon" |
| 166 | + ), |
| 167 | + color = "success", |
| 168 | + class_name = "d-flex align-items-center" |
| 169 | + ), |
| 170 | + dbcAlert( |
| 171 | + list( |
| 172 | + htmlI(class_name = "bi bi-exclamation-triangle-fill me-2"), |
| 173 | + "An example warning alert with an icon" |
| 174 | + ), |
| 175 | + color = "warning", |
| 176 | + class_name = "d-flex align-items-center" |
| 177 | + ), |
| 178 | + dbcAlert( |
| 179 | + list( |
| 180 | + htmlI(class_name = "bi bi-x-octagon-fill me-2"), |
| 181 | + "An example danger alert with an icon" |
| 182 | + ), |
| 183 | + color = "danger", |
| 184 | + class_name = "d-flex align-items-center" |
| 185 | + ) |
| 186 | + ) |
| 187 | +) |
| 188 | +``` |
| 189 | +
|
| 190 | +----- |
| 191 | +Julia |
| 192 | +
|
| 193 | +```julia |
| 194 | +using DashBootstrapComponents, DashHtmlComponents |
| 195 | +
|
| 196 | +alerts = html_div([ |
| 197 | + dbc_alert( |
| 198 | + [ |
| 199 | + html_i(class_name = "bi bi-info-circle-fill me-2"), |
| 200 | + "An example info alert with an icon", |
| 201 | + ], |
| 202 | + color = "info", |
| 203 | + class_name = "d-flex align-items-center", |
| 204 | + ), |
| 205 | + dbc_alert( |
| 206 | + [ |
| 207 | + html_i(class_name = "bi bi-check-circle-fill me-2"), |
| 208 | + "An example success alert with an icon", |
| 209 | + ], |
| 210 | + color = "success", |
| 211 | + class_name = "d-flex align-items-center", |
| 212 | + ), |
| 213 | + dbc_alert( |
| 214 | + [ |
| 215 | + html_i(class_name = "bi bi-exclamation-triangle-fill me-2"), |
| 216 | + "An example warning alert with an icon", |
| 217 | + ], |
| 218 | + color = "warning", |
| 219 | + class_name = "d-flex align-items-center", |
| 220 | + ), |
| 221 | + dbc_alert( |
| 222 | + [ |
| 223 | + html_i(class_name = "bi bi-x-octagon-fill me-2"), |
| 224 | + "An example danger alert with an icon", |
| 225 | + ], |
| 226 | + color = "danger", |
| 227 | + class_name = "d-flex align-items-center", |
| 228 | + ), |
| 229 | +]) |
| 230 | +``` |
| 231 | +~~~ |
0 commit comments