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

[Tidy] Replace dmc.Tabs with dbc.Tabs #895

Merged
merged 69 commits into from
Nov 26, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
69 commits
Select commit Hold shift + click to select a range
81eeb60
Add changes
huong-li-nguyen Nov 18, 2024
5f0e020
Update latest CSS file
huong-li-nguyen Nov 19, 2024
fff42a1
Remove CSS for tooltip
huong-li-nguyen Nov 19, 2024
07d8929
Update vizro-bootstrap.min.css
huong-li-nguyen Nov 19, 2024
0a7ff33
Create 20241119_155853_huong_li_nguyen_add_bs_tooltip_styling.md
huong-li-nguyen Nov 19, 2024
7abbbbf
Merge branch 'main' into tidy/add-bs-tooltip-styling
huong-li-nguyen Nov 19, 2024
480914d
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 19, 2024
4a598a2
Remove all CSS variables
huong-li-nguyen Nov 19, 2024
39032be
Rename variables with vizro-bs equivalent
huong-li-nguyen Nov 19, 2024
1ca73f8
Replace with rem units
huong-li-nguyen Nov 19, 2024
610a188
Hardcode values where suitable
huong-li-nguyen Nov 19, 2024
96464d6
Add back selected variables
huong-li-nguyen Nov 19, 2024
e35fe36
Replace matched values
huong-li-nguyen Nov 19, 2024
3404355
Replace remaining values
huong-li-nguyen Nov 19, 2024
4d07ec0
Create 20241119_173819_huong_li_nguyen_remove_variables.md
huong-li-nguyen Nov 19, 2024
5a47f97
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 19, 2024
e7cdc9b
Merge branch 'tidy/add-bs-tooltip-styling' into tidy/remove-variables
huong-li-nguyen Nov 19, 2024
1277f11
Merge branch 'tidy/remove-variables' of https://github.com/mckinsey/v…
huong-li-nguyen Nov 19, 2024
b52fb72
Fix collapse bg color
huong-li-nguyen Nov 20, 2024
42bdb3a
Update color
huong-li-nguyen Nov 20, 2024
0742dc8
Fix renaming of border
huong-li-nguyen Nov 20, 2024
ba273f7
Replace remaining variable mentions
huong-li-nguyen Nov 20, 2024
307ce5c
Merge branch 'main' into tidy/remove-variables
huong-li-nguyen Nov 20, 2024
84d5d73
Update CSS variables outside of static folder
huong-li-nguyen Nov 21, 2024
2ec7c6e
Revert demo changes
huong-li-nguyen Nov 21, 2024
4fac651
Update changelog
huong-li-nguyen Nov 21, 2024
c77fd12
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 21, 2024
f9bba27
Update table
huong-li-nguyen Nov 21, 2024
bf90f2c
Merge branch 'main' into tidy/remove-variables
huong-li-nguyen Nov 21, 2024
e0c9f20
Fix tabs
huong-li-nguyen Nov 21, 2024
96fcd96
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 21, 2024
790ccb4
Replace dash-mantine with dbc
huong-li-nguyen Nov 21, 2024
5ddd50a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 21, 2024
43eca2f
Tidy
huong-li-nguyen Nov 21, 2024
33cef8a
Merge branch 'tidy/replace-tabs' of https://github.com/mckinsey/vizro…
huong-li-nguyen Nov 21, 2024
31fb84b
Add preliminary bootstrap css
huong-li-nguyen Nov 21, 2024
2d911ad
Update CSS
huong-li-nguyen Nov 21, 2024
42b67b8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 21, 2024
4600223
Merge branch 'main' into tidy/remove-variables
huong-li-nguyen Nov 25, 2024
de7781e
Clarify comment
huong-li-nguyen Nov 25, 2024
bfb64ff
Update vizro-bootstrap.min.css
huong-li-nguyen Nov 25, 2024
303f9e4
Update vizro-bootstrap.min.css
huong-li-nguyen Nov 25, 2024
085f64a
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 25, 2024
3a6f665
Tidy
huong-li-nguyen Nov 25, 2024
0a720c3
Merge branch 'tidy/replace-tabs' of https://github.com/mckinsey/vizro…
huong-li-nguyen Nov 25, 2024
367f396
Add new bootstrap file and fix scrolling issue
huong-li-nguyen Nov 25, 2024
6373542
Merge branch 'tidy/remove-variables' into tidy/replace-tabs
huong-li-nguyen Nov 25, 2024
21010a8
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 25, 2024
84036b3
Merge branch 'tidy/replace-tabs' of https://github.com/mckinsey/vizro…
huong-li-nguyen Nov 25, 2024
f77fb2f
Tidy
huong-li-nguyen Nov 25, 2024
e21d2ee
Add changelog entry
huong-li-nguyen Nov 25, 2024
e14a080
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 25, 2024
7b3e2e3
Add comment
huong-li-nguyen Nov 25, 2024
3fd9728
Merge branch 'tidy/remove-variables' into tidy/replace-tabs
huong-li-nguyen Nov 25, 2024
b9e25c6
Add comment
huong-li-nguyen Nov 26, 2024
9358742
Update docs
huong-li-nguyen Nov 26, 2024
e9be97e
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 26, 2024
c18f942
Lint
huong-li-nguyen Nov 26, 2024
a9dd04d
Merge branch 'tidy/remove-variables' of https://github.com/mckinsey/v…
huong-li-nguyen Nov 26, 2024
aaf8426
Merge branch 'tidy/remove-variables' into tidy/replace-tabs
huong-li-nguyen Nov 26, 2024
26046be
Update
huong-li-nguyen Nov 26, 2024
e30bf6c
Merge branch 'tidy/remove-variables' into tidy/replace-tabs
huong-li-nguyen Nov 26, 2024
bf1a006
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 26, 2024
aaf36a3
Fix typo
huong-li-nguyen Nov 26, 2024
09ae02b
Merge branch 'tidy/remove-variables' into tidy/replace-tabs
huong-li-nguyen Nov 26, 2024
bb3a9ee
Merge branch 'main' into tidy/replace-tabs
huong-li-nguyen Nov 26, 2024
06cd5fc
Revert change
huong-li-nguyen Nov 26, 2024
2a89c16
Simplify unit tests
huong-li-nguyen Nov 26, 2024
5665ff4
[pre-commit.ci] auto fixes from pre-commit.com hooks
pre-commit-ci[bot] Nov 26, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.Tabs` with `dbc.Tabs` and change CSS selectors accordingly. ([#895](https://github.com/mckinsey/vizro/pull/895))

<!--
### 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))

-->
77 changes: 43 additions & 34 deletions vizro-core/examples/scratch_dev/app.py
Original file line number Diff line number Diff line change
@@ -1,46 +1,55 @@
"""Dev app to try things out."""

import pandas as pd
import vizro.models as vm
import vizro.plotly.express as px
from vizro import Vizro
from vizro._themes._color_values import COLORS
import dash_bootstrap_components as dbc
from dash import html

from typing import Literal

from dash import html

import vizro.models as vm
from vizro import Vizro


class Tooltip(vm.VizroBaseModel):
type: Literal["tooltip"] = "tooltip"
text: str = "This is a tooltip"

def build(self):
return html.Div(
[
dbc.Button("Button", id=f"{self.id}-tooltip-target"),
dbc.Tooltip(
self.text,
target=f"{self.id}-tooltip-target",
is_open=True,
),
]
)


vm.Page.add_type("components", Tooltip)
gapminder_2007 = px.data.gapminder().query("year == 2007")

page = vm.Page(
title="Custom Component",
title="Tabs",
components=[
Tooltip(text="Tooltip label"),
Tooltip(
text="Max. width of tooltip should not exceed 180px - this instance should be used for multiple lines of text for increased legibility."
vm.Tabs(
tabs=[
vm.Container(
title="Tab I",
components=[
vm.Graph(
title="Graph I",
figure=px.bar(
gapminder_2007,
x="continent",
y="lifeExp",
color="continent",
),
),
vm.Graph(
title="Graph II",
figure=px.box(
gapminder_2007,
x="continent",
y="lifeExp",
color="continent",
),
),
],
),
vm.Container(
title="Tab II",
components=[
vm.Graph(
title="Graph III",
figure=px.scatter(
gapminder_2007,
x="gdpPercap",
y="lifeExp",
size="pop",
color="continent",
),
),
],
),
],
),
],
)
Expand Down
19 changes: 3 additions & 16 deletions vizro-core/src/vizro/models/_components/tabs.py
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,7 @@

from typing import TYPE_CHECKING, Literal

import dash_mantine_components as dmc
from dash import html
import dash_bootstrap_components as dbc

try:
from pydantic.v1 import validator
Expand Down Expand Up @@ -33,21 +32,9 @@ class Tabs(VizroBaseModel):

@_log_call
def build(self):
tabs_list = dmc.TabsList(
[dmc.Tab(tab.title, value=tab.id, className="tab-title") for tab in self.tabs],
className="tabs-list",
)

tabs_panels = [
dmc.TabsPanel(html.Div([tab.build()], className="tab-content"), value=tab.id, className="tabs-panel")
for tab in self.tabs
]

return dmc.Tabs(
return dbc.Tabs(
id=self.id,
value=self.tabs[0].id,
children=[tabs_list, *tabs_panels],
children=[dbc.Tab(tab.build(), label=tab.title) for tab in self.tabs],
persistence=True,
persistence_type="session",
className="tabs",
)
23 changes: 23 additions & 0 deletions vizro-core/src/vizro/static/css/bootstrap_overwrites.css
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ All the HEX values starting with --text-code are taken from the Github code high
--collapse-icon-bg: var(--primary-300);
}

/* CARDS */
.card .nav-link {
height: 100%;
}
Expand All @@ -36,10 +37,32 @@ All the HEX values starting with --text-code are taken from the Github code high
margin-bottom: 0;
}

/* ACCORDION */
.accordion-item .nav-link {
padding: 0.5rem 1rem;
}

.accordion-item .nav-link.active {
border-left: 2px solid var(--border-enabled);
}

/* TABS */
.nav-tabs {
margin-bottom: 1.25rem;
}

.tab-content {
height: calc(100% - 3.25rem); /* 3.25rem: nav-tabs margin + height */
}

/* The dbc component adds an additional div element to which we cannot assign a className.
To ensure the dynamic height adjustment and prevent scrolling, the height must be specified for that div as below. */
.tab-pane,
.tab-pane > div:first-child {
height: 100%;
}

/* Hides title of the first container given the title is already reflected in the tab title */
.tab-content .container-title:first-of-type {
display: none;
}
huong-li-nguyen marked this conversation as resolved.
Show resolved Hide resolved
60 changes: 0 additions & 60 deletions vizro-core/src/vizro/static/css/tabs.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.

34 changes: 6 additions & 28 deletions vizro-core/tests/unit/vizro/models/_components/test_tabs.py
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
"""Unit tests for vizro.models.Container."""

import dash_mantine_components as dmc
import dash_bootstrap_components as dbc
import pytest
from asserts import assert_component_equal
from dash import html
Expand Down Expand Up @@ -41,42 +41,20 @@ def test_tabs_build(self, containers):
# We want to test the component itself but not all its children
assert_component_equal(
result,
dmc.Tabs(id="tabs-id", value="container-1", persistence=True, persistence_type="session", className="tabs"),
dbc.Tabs(id="tabs-id", persistence=True, persistence_type="session"),
keys_to_strip={"children"},
)
# We want to test the children created in the Tabs.build but not e.g. the
# vm.Container.build() as it's tested elsewhere already
assert_component_equal(
result.children,
[dmc.TabsList(), dmc.TabsPanel(value="container-1"), dmc.TabsPanel(value="container-2")],
keys_to_strip={"children", "className"},
)
# So we go down the tree and ignore the children selectively
assert_component_equal(
result.children[0],
dmc.TabsList(
children=[
dmc.Tab(value="container-1", children="Title-1", className="tab-title"),
dmc.Tab(value="container-2", children="Title-2", className="tab-title"),
],
className="tabs-list",
),
)
# This one removes the need for duplication of tests as the output is similar
assert_component_equal(
result.children[1:],
[
dmc.TabsPanel(className="tabs-panel", value="container-1"),
dmc.TabsPanel(className="tabs-panel", value="container-2"),
],
keys_to_strip={"children"},
result.children, [dbc.Tab(label="Title-1"), dbc.Tab(label="Title-2")], keys_to_strip={"children"}
)
# We still check that the html.Div for the Containers are created, but we don't need to check its content
assert_component_equal(
[tab.children.children for tab in result.children[1:]],
[tab.children for tab in result.children],
[
[html.Div(id="container-1", className="page-component-container")],
[html.Div(id="container-2", className="page-component-container")],
html.Div(id="container-1", className="page-component-container"),
html.Div(id="container-2", className="page-component-container"),
],
keys_to_strip={"children"},
)