mckinsey / vizro

Vizro is a toolkit for creating modular data visualization applications.
https://vizro.readthedocs.io/en/stable/
Apache License 2.0
2.65k stars 136 forks source link

Add default Bootstrap theme and overwrite CSS #311

Closed huong-li-nguyen closed 7 months ago

huong-li-nguyen commented 7 months ago

Description

This is also just a temporary POC fix to an issue we will solve differently long-term, changes included in this PR:

The current approach is not as different as our previous one, but has a few advantages:

Remains the same:

Improvement to previous version:

Screenshot

When plugging in a dbc.theme before: Screenshot 2024-02-14 at 20 46 34 Screenshot 2024-02-14 at 20 46 39

Now: Screenshot 2024-02-14 at 20 47 10

Screenshot 2024-02-14 at 20 47 02

Notice

huong-li-nguyen commented 7 months ago

@antonymilne - this was initially supposed to be just a POC but shall we go ahead with this PR change now? Main advantages for me are:

huong-li-nguyen commented 7 months ago

This seems like a big step in the right direction to me and I think we should go ahead with it 👍

If we can now remove the "Adding a dash-bootstrap component" from the docs then let's do so. The "Dash Bootstrap Themes" warning is still relevant but could maybe be modified a bit now we know the direction of travel:

    Please note that Vizro is not yet compatible with [Dash Bootstrap Themes](https://dash-bootstrap-components.opensource.faculty.ai/docs/themes/).
    Adding a Bootstrap stylesheet will not have any effect on your Vizro app.

I've modified to below, but I think the warning is still relevant. However, I've removed the other warning as functionality should be automatically shipped now via the default dbc.theme included, and styling is required for any custom component that gets added by the user 👍

Please note that Vizro is currently not compatible with [Dash Bootstrap Themes](https://dash-bootstrap-components.opensource.faculty.ai/docs/themes/).
    Adding a Bootstrap stylesheet will have no visual effect on the [components](https://vizro.readthedocs.io/en/stable/pages/user_guides/components/) included in Vizro.
huong-li-nguyen commented 7 months ago

@AnnMarieW - would you mind taking a look at this PR? I would love to get your opinion on it!

This is by no means our final solution to our Bootstrap issue. We are still not compatible with dbc.themes, but at least when someone tries to plug it in, it will have no visual effect on the currently existing components. So, I still kept the warning inside.

However, what did improve is that a dbc.theme is automatically attached right now, so at least anyone creating a custom component on dbc, doesn't have to figure out the custom CSS required to make the component functional.

AnnMarieW commented 7 months ago

@huong-li-nguyen Nice work! This is awesome!

In dashboard.js if you update this callback function, it will will use the correct light/dark color mode for the Boootstrap theme:

export function _update_dashboard_theme(checked) {
  document.documentElement.setAttribute('data-bs-theme', checked ? 'light' : 'dark');
  return checked ? "vizro_light" : "vizro_dark";
}
huong-li-nguyen commented 7 months ago

@huong-li-nguyen Nice work! This is awesome!

In dashboard.js if you update this callback function, it will will use the correct light/dark color mode for the Boootstrap theme:

export function _update_dashboard_theme(checked) {
  document.documentElement.setAttribute('data-bs-theme', checked ? 'light' : 'dark');
  return checked ? "vizro_light" : "vizro_dark";
}

Ahh, super smart! Thank you!!! 🚀 💯 Hope we can get a better long-term solution in place soon!