Skip to content

Commit

Permalink
[Tidy] Replace dmc.Switch with dbc.Switch (#907)
Browse files Browse the repository at this point in the history
  • Loading branch information
huong-li-nguyen authored Dec 2, 2024
1 parent dfafd88 commit 57faa1e
Show file tree
Hide file tree
Showing 8 changed files with 65 additions and 61 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,47 @@
<!--
A new scriv changelog fragment.
Uncomment the section that is right (remove the HTML comment wrapper).
-->

<!--
### Highlights ✨
- A bullet item for the Highlights ✨ category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Removed
- A bullet item for the Removed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Added
- A bullet item for the Added category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))
-->

### Changed

- Replace `dmc.Switch` with `dbc.Switch` and change CSS selectors accordingly. ([#907](https://github.com/mckinsey/vizro/pull/907))

<!--
### Deprecated
- A bullet item for the Deprecated category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Fixed
- A bullet item for the Fixed category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
<!--
### Security
- A bullet item for the Security category with a link to the relevant PR at the end of your entry, e.g. Enable feature XXX. ([#1](https://github.com/mckinsey/vizro/pull/1))
-->
2 changes: 1 addition & 1 deletion vizro-core/src/vizro/models/_components/ag_grid.py
Original file line number Diff line number Diff line change
Expand Up @@ -119,7 +119,7 @@ def build(self):
clientside_callback(
ClientsideFunction(namespace="dashboard", function_name="update_ag_grid_theme"),
Output(self._input_component_id, "className"),
Input("theme_selector", "checked"),
Input("theme-selector", "value"),
)

return dcc.Loading(
Expand Down
2 changes: 1 addition & 1 deletion vizro-core/src/vizro/models/_components/graph.py
Original file line number Diff line number Diff line change
Expand Up @@ -168,7 +168,7 @@ def build(self):
output=[Output(self.id, "figure"), Output(self.id, "style")],
inputs=[
Input(self.id, "figure"),
Input("theme_selector", "checked"),
Input("theme-selector", "value"),
State("vizro_themes", "data"),
],
prevent_initial_call=True,
Expand Down
17 changes: 7 additions & 10 deletions vizro-core/src/vizro/models/_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,6 @@

import dash
import dash_bootstrap_components as dbc
import dash_mantine_components as dmc
import plotly.io as pio
from dash import (
ClientsideFunction,
Expand Down Expand Up @@ -142,7 +141,7 @@ def build(self):
ClientsideFunction(namespace="dashboard", function_name="update_dashboard_theme"),
# This currently doesn't do anything, but we need to define an Output such that the callback is triggered.
Output("dashboard-container", "className"),
Input("theme_selector", "checked"),
Input("theme-selector", "value"),
)
left_side_div_present = any([len(self.pages) > 1, self.pages[0].controls])
if left_side_div_present:
Expand Down Expand Up @@ -197,12 +196,11 @@ def _get_page_divs(self, page: Page) -> _PageDivsType:
else html.H2(id="dashboard-title", hidden=True)
)
settings = html.Div(
children=dmc.Switch(
id="theme_selector",
checked=self.theme == "vizro_light",
children=dbc.Switch(
id="theme-selector",
value=self.theme == "vizro_light",
persistence=True,
persistence_type="session",
className="toggle-switch",
),
id="settings",
)
Expand Down Expand Up @@ -311,12 +309,11 @@ def _make_page_404_layout(self):
[
# Theme switch is added such that the 404 page has the same theme as the user-selected one.
html.Div(
children=dmc.Switch(
id="theme_selector",
checked=self.theme == "vizro_light",
children=dbc.Switch(
id="theme-selector",
value=self.theme == "vizro_light",
persistence=True,
persistence_type="session",
className="toggle-switch",
),
id="settings",
),
Expand Down
5 changes: 5 additions & 0 deletions vizro-core/src/vizro/static/css/bootstrap_overwrites.css
Original file line number Diff line number Diff line change
Expand Up @@ -66,3 +66,8 @@ To ensure the dynamic height adjustment and prevent scrolling, the height must b
.tab-content .container-title:first-of-type {
display: none;
}

/* Remove label that automatically gets added when calling `dbc.Switch` to remove gap. */
label[for="theme-selector"] {
display: none;
}
43 changes: 0 additions & 43 deletions vizro-core/src/vizro/static/css/toggle.css

This file was deleted.

2 changes: 1 addition & 1 deletion vizro-core/src/vizro/static/css/vizro-bootstrap.min.css

Large diffs are not rendered by default.

8 changes: 3 additions & 5 deletions vizro-core/tests/unit/vizro/models/test_dashboard.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,7 +2,6 @@

import dash
import dash_bootstrap_components as dbc
import dash_mantine_components as dmc
import plotly.io as pio
import pytest
from asserts import assert_component_equal
Expand Down Expand Up @@ -245,12 +244,11 @@ def test_make_page_404_layout(self, page_1, vizro_app):
expected = html.Div(
[
html.Div(
children=dmc.Switch(
id="theme_selector",
checked=False,
children=dbc.Switch(
id="theme-selector",
value=False,
persistence=True,
persistence_type="session",
className="toggle-switch",
),
id="settings",
),
Expand Down

0 comments on commit 57faa1e

Please sign in to comment.