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

Color mode #984

Merged
merged 13 commits into from
Oct 27, 2023
2 changes: 2 additions & 0 deletions docs/components_page/components/form.md
Original file line number Diff line number Diff line change
Expand Up @@ -49,6 +49,8 @@ The `FormFeedback` component should be added to a `html.Div` containing the `Inp

`Form` and other components can also be used with _dash-core-components_.

Note that Bootstrap themes are not automatically applied to components such as _dash-core-components, dash-ag-grid_, or _DataTable_. For more information on styling other Dash components with a Bootstrap theme see the [Dash Bootstrap Theme Explorer](https://hellodash.pythonanywhere.com/) site.
AnnMarieW marked this conversation as resolved.
Show resolved Hide resolved

{{example:components/form/dash_core.py:form}}

{{apidoc:src/components/form/Form.js}}
Expand Down
4 changes: 2 additions & 2 deletions docs/components_page/components/jumbotron/custom.py
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
),
dbc.Button("Example Button", color="light", outline=True),
],
className="h-100 p-5 text-white bg-dark rounded-3",
className="h-100 p-5 text-white bg-primary rounded-3",
),
md=6,
)
Expand All @@ -28,7 +28,7 @@
),
dbc.Button("Example Button", color="secondary", outline=True),
],
className="h-100 p-5 bg-light border rounded-3",
className="h-100 p-5 bg-light text-dark border rounded-3",
),
md=6,
)
Expand Down
2 changes: 1 addition & 1 deletion docs/components_page/components/jumbotron/simple.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,5 +22,5 @@
fluid=True,
className="py-3",
),
className="p-3 bg-light rounded-3",
className="p-3 bg-body-secondary rounded-3",
)
16 changes: 8 additions & 8 deletions docs/components_page/components/layout/horizontal_stack.py
tcbegley marked this conversation as resolved.
Show resolved Hide resolved
tcbegley marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -5,20 +5,20 @@
[
dbc.Stack(
[
html.Div("Horizontal", className="bg-light border"),
html.Div("Stack", className="bg-light border"),
html.Div("Without", className="bg-light border"),
html.Div("Gaps", className="bg-light border"),
html.Div("Horizontal", className="text-bg-light border"),
html.Div("Stack", className="text-bg-light border"),
html.Div("Without", className="text-bg-light border"),
html.Div("Gaps", className="text-bg-light border"),
],
direction="horizontal",
),
html.Hr(),
dbc.Stack(
[
html.Div("Horizontal", className="bg-light border"),
html.Div("Stack", className="bg-light border"),
html.Div("With", className="bg-light border"),
html.Div("Gaps", className="bg-light border"),
html.Div("Horizontal", className="text-bg-light border"),
html.Div("Stack", className="text-bg-light border"),
html.Div("With", className="text-bg-light border"),
html.Div("Gaps", className="text-bg-light border"),
],
direction="horizontal",
gap=3,
Expand Down
14 changes: 8 additions & 6 deletions docs/components_page/components/layout/simple_stack.py
Original file line number Diff line number Diff line change
Expand Up @@ -6,18 +6,20 @@
dbc.Stack(
[
html.Div(
"This stack has no gaps", className="bg-light border"
"This stack has no gaps", className="text-bg-light border"
),
html.Div("Next item", className="bg-light border"),
html.Div("Last item", className="bg-light border"),
html.Div("Next item", className="text-bg-light border"),
html.Div("Last item", className="text-bg-light border"),
]
),
html.Hr(),
dbc.Stack(
[
html.Div("This stack has gaps", className="bg-light border"),
html.Div("Next item", className="bg-light border"),
html.Div("Last item", className="bg-light border"),
html.Div(
"This stack has gaps", className="text-bg-light border"
),
html.Div("Next item", className="text-bg-light border"),
html.Div("Last item", className="text-bg-light border"),
],
gap=3,
),
Expand Down
14 changes: 8 additions & 6 deletions docs/components_page/components/layout/stack_spacers.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,23 +5,25 @@
[
dbc.Stack(
[
html.Div("Start", className="bg-light border"),
html.Div("Start", className="text-bg-light border"),
html.Div(
"Middle (ms-auto)", className="ms-auto bg-light border"
"Middle (ms-auto)",
className="ms-auto text-bg-light border",
),
html.Div("End", className="bg-light border"),
html.Div("End", className="text-bg-light border"),
],
direction="horizontal",
gap=3,
),
html.Hr(),
dbc.Stack(
[
html.Div("Start", className="bg-light border"),
html.Div("Start", className="text-bg-light border"),
html.Div(
"Middle (mx-auto)", className="mx-auto bg-light border"
"Middle (mx-auto)",
className="mx-auto text-bg-light border",
),
html.Div("End", className="bg-light border"),
html.Div("End", className="text-bg-light border"),
],
direction="horizontal",
gap=3,
Expand Down
39 changes: 39 additions & 0 deletions docs/content/docs/themes.md
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,45 @@ To start with, we recommend experimenting with some of the Bootswatch themes ava

Check out the [theme explorer](/docs/themes/explorer/) for a live demo of dash-bootstrap-components using all of the different available themes. You may also like to check out the [dash-bootstrap-css](https://github.com/tcbegley/dash-bootstrap-css) project which contains Bootstrap stylesheets that apply consistent styling to various components from dash-core-components.

## Light and Dark Color Modes

_Available in dash-bootstrap-components>=1.5.0_

To toggle between a light and dark mode in your app, create a component to switch the theme. For example, add a component like this to the layout:

```python
app = Dash(__name__, external_stylesheets=[dbc.themes.BOOTSTRAP, dbc.icons.FONT_AWESOME])

color_mode_switch = html.Span(
[
dbc.Label(className="fa fa-moon", html_for="switch"),
dbc.Switch( id="switch", value=True, className="d-inline-block ms-1", persistence=True),
dbc.Label(className="fa fa-sun", html_for="switch"),
]
)
```

Here's a callback to change the theme:

```python
clientside_callback(
" " "
(switchOn) => {
switchOn
? document.documentElement.setAttribute('data-bs-theme', 'light')
: document.documentElement.setAttribute('data-bs-theme', 'dark')
return window.dash_clientside.no_update
}
" " ",
Output("switch", "id"),
Input("switch", "value"),
)
```

See this example live in the [Dash Bootstrap Theme Explorer](https://hellodash.pythonanywhere.com/adding-themes/color-modes)
See more information in the [Bootstrap Docs](https://getbootstrap.com/docs/5.3/customize/color-modes/)


[dash-docs-external]: https://dash.plotly.com/external-resources/
[bootstrap]:https://getbootstrap.com/
[bootstrap-download]: https://getbootstrap.com/docs/5.0/getting-started/download/
Expand Down
40 changes: 20 additions & 20 deletions docs/static/docs.css
tcbegley marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
Expand Up @@ -31,6 +31,11 @@ span.hljs-meta {
color: #66d9ef;
}

.highlight {
border: var(--bs-border-color) var(--bs-border-style) var(--bs-border-width);
border-radius: 6px;
}

.demo-layout-container {
height: 600px;
margin-right: 0rem;
Expand Down Expand Up @@ -60,18 +65,17 @@ span.hljs-meta {
}

.docs-sidebar .nav-link {
color: #888;
color: var(--bs-body-color)
padding: 0.3rem 0.5rem 0.3rem 1rem;
border-left: 2px solid transparent;
}

.docs-sidebar .nav-link:hover {
color: #777;
border-left: 2px solid #aaa;
}

.docs-sidebar .nav-link.active {
color: #666;
color: var(--bs-emphasis-color);
border-left: 2px solid #d9534f;
}

Expand All @@ -80,7 +84,7 @@ span.hljs-meta {
}

.example-container {
border: 1px solid #d8d8d8;
border: 1px solid var(--bs-border-color);
margin: 2rem 0 0;
border-radius: 6px;
}
Expand All @@ -96,6 +100,7 @@ span.hljs-meta {

.example-source-container pre {
margin-bottom: 0;
border: 1px solid var(--bs-border-color);
}

.source-container pre.hljs {
Expand All @@ -108,14 +113,7 @@ span.hljs-meta {

.layout-demo .row {
margin-bottom: 10px;
background: linear-gradient(
to right,
rgba(0, 0, 0, 0),
rgba(0, 0, 0, 0) calc(100% - 0.75rem),
#fff calc(100% - 0.75rem)
),
linear-gradient(to right, #fff, #fff 0.75rem, rgba(0, 0, 0, 0) 0.75rem),
linear-gradient(to right, #eeeeee, #eeeeee);
background: var(--bs-secondary-bg-subtle)
}

.layout-demo .row.g-0 {
Expand All @@ -129,8 +127,8 @@ span.hljs-meta {
.layout-demo .col > div,
.layout-demo [class*='col-'] > div {
padding: 0.75rem;
background-color: rgba(86, 61, 124, 0.15);
border: 1px solid rgba(86, 61, 124, 0.2);
background-color: var(--bs-primary-bg-subtle);
border: 1px solid var(--bs-primary-border-subtle);
}

._dash-undo-redo {
Expand Down Expand Up @@ -218,17 +216,18 @@ span.hljs-meta {
padding: 0.25rem 0rem;
font-weight: 500;
font-size: 1.25rem;
color: rgba(0, 0, 0, 0.65);
color: var(--bs-body-color);
text-decoration: none;
}

.dbcd-nav-link:hover {
color: rgba(0, 0, 0, 0.75);
text-decoration: none;
font-weight: bold;
}

.dbcd-nav-item.active > .dbcd-nav-link {
color: rgba(0, 0, 0, 0.85);
color: var(--bs-emphasis-color);
font-weight: bold;
}

.dbcd-nav-links ul > li {
Expand All @@ -237,16 +236,17 @@ span.hljs-meta {

.dbcd-nav-links ul > li > a {
padding: 0.25rem 0rem;
color: rgba(0, 0, 0, 0.65);
color: var(--bs-body-color);
text-decoration: none;
}

.dbcd-nav-links ul > li.active > a {
color: rgba(0, 0, 0, 0.85);
color: var(--bs-emphasis-color);
font-weight: bold;
}

.dbcd-nav-links ul > li > a:hover {
color: rgba(0, 0, 0, 0.75);
font-weight: bold;
text-decoration: none;
}

Expand Down
30 changes: 30 additions & 0 deletions docs/static/js/docs-theme-change.js
tcbegley marked this conversation as resolved.
Show resolved Hide resolved
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
const getStoredTheme = () => localStorage.getItem('theme')
const lightIcon = "bi bi-sun-fill"
const darkIcon = "bi bi-moon-fill"


const setIcon = theme => {
icon = theme == "light" ? lightIcon : darkIcon
document.getElementById('theme-icon').className = icon
}

const handleThemeChange = () => {
getStoredTheme() == 'dark' ? setTheme("light") : setTheme("dark")
}

const setTheme = theme => {
document.documentElement.setAttribute('data-bs-theme', theme)
localStorage.setItem('theme', theme)
setIcon(theme)
}

// icon needs to be set after page is loaded
const setInitialIcon = () => {
getStoredTheme() == 'dark' ? setIcon("dark") : setIcon("light")
}
window.onload = (event) => {
setInitialIcon()
};



4 changes: 2 additions & 2 deletions docs/templates/index.html
Original file line number Diff line number Diff line change
Expand Up @@ -55,8 +55,8 @@ <h2>Get started quickly</h2>
<a href="/docs/quickstart" class="btn btn-secondary">Quickstart »</a>
</div>
<div class="col-12 col-lg-6 mt-4 mt-lg-0">
<pre><code class="language-sh">pip install dash-bootstrap-components</code></pre>
<pre><code class="language-python">import dash
<pre><code class="language-sh border">pip install dash-bootstrap-components</code></pre>
<pre><code class="language-python border">import dash
tcbegley marked this conversation as resolved.
Show resolved Hide resolved
import dash_bootstrap_components as dbc

app = dash.Dash(
Expand Down
5 changes: 5 additions & 0 deletions docs/templates/macros/navbar.html
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can we right-align this one in the navbar? Just to create some distinction with the navigation links

Copy link
Contributor Author

@AnnMarieW AnnMarieW Oct 23, 2023

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, but the icon looked so lonely over there 🙂 . I changed the style to make it more visible, but it might be too much now.

image

Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Interesting, let's try adding a GitHub link to make it less lonely in a follow-up PR.

Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,11 @@
<a class="dropdown-item" href="https://faculty.ai">Faculty AI</a>
</div>
</li>
<li >
<button class="btn btn-link nav-link p-2" id="docs-theme" onclick="handleThemeChange()" >
<i class="bi bi-sun-fill" id="theme-icon"></i>
</button>
</li>
</ul>
</div>
</div>
Expand Down
6 changes: 6 additions & 0 deletions docs/templates/partials/head.html
Original file line number Diff line number Diff line change
Expand Up @@ -5,3 +5,9 @@
<link rel="stylesheet" href="/static/docs.css" />
<link rel="shortcut icon" type="image/png" href="/static/images/dbciconwhite16.png" />
<link rel="stylesheet" href="https://cdn.jsdelivr.net/npm/bootstrap-icons@1.10.3/font/bootstrap-icons.css" />

<!-- sets correct theme on page refresh -->
<script>
dbcdStoredTheme = localStorage.getItem('theme')
document.documentElement.setAttribute('data-bs-theme', dbcdStoredTheme)
</script>
1 change: 1 addition & 0 deletions docs/templates/partials/scripts.html
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<script src="https://cdn.jsdelivr.net/npm/bootstrap@5.3.1/dist/js/bootstrap.bundle.min.js" crossorigin="anonymous"></script>
<script src="/static/js/highlight.min.js"></script>
<script src="/static/js/docs-theme-change.js"></script>
<script>
hljs.configure({ignoreUnescapedHTML: true})
hljs.highlightAll()
Expand Down