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

[Poc] Implement collapsible container as a custom component #1042

Open
wants to merge 43 commits into
base: main
Choose a base branch
from

Conversation

nadijagraca
Copy link
Contributor

Description

This PR is meant to create collapsible container as a custom component.
CollapsibleContainer component (for now) needs to be used within FlexContainer component (component that mimics flex layout).

Discussion points:

  • should we use background color in the collapsible container
  • is the "open/close" arrow prominent enough in the layout

Notice

  • I acknowledge and agree that, by checking this box and clicking "Submit Pull Request":

    • I submit this contribution under the Apache 2.0 license and represent that I am entitled to do so on behalf of myself, my employer, or relevant third parties, as applicable.
    • I certify that (a) this contribution is my original creation and / or (b) to the extent it is not my original creation, I am authorized to submit this contribution on behalf of the original creator(s) or their licensees.
    • I certify that the use of this contribution as authorized by the Apache 2.0 license does not violate the intellectual property rights of anyone else.
    • I have not referenced individuals, products or companies in any commits, directly or indirectly.
    • I have not added data or restricted code in any commits, directly or indirectly.

huong-li-nguyen and others added 30 commits February 10, 2025 10:20
Copy link
Contributor

github-actions bot commented Feb 28, 2025

View the example dashboards of the current commit live on PyCafe ☕ 🚀

Updated on: 2025-02-28 13:40:18 UTC
Commit: 9511ce1

Compare the examples using the commit's wheel file vs the latest released version:

vizro-core/examples/scratch_dev

View with commit's wheel vs View with latest release

vizro-core/examples/dev/

View with commit's wheel vs View with latest release

vizro-core/examples/visual-vocabulary/

View with commit's wheel vs View with latest release

vizro-ai/examples/dashboard_ui/

View with commit's wheel vs View with latest release

@petar-qb petar-qb changed the title [Po] Implement collapsible container as a custom component [Poc] Implement collapsible container as a custom component Feb 28, 2025
Copy link
Contributor

@huong-li-nguyen huong-li-nguyen left a comment

Choose a reason for hiding this comment

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

I just took a quick look—this works really well inside the FlexLayout! 🚀

I made some refactors in this PR: #1002, which also impacts your PR. It might be worth rebasing your branch on that one instead.

Regarding your question about coloring, I believe this should be controlled by setting theme="XX". However, we could check with J. if we want a different default for collapsible containers compared to regular containers (currently, the default is no styling). However, I agree with you, that collapsible containers should probably come pre-styled (I don't have a preference here whether it should be outlined or filled) as otherwise it's a bit difficult to visually distinguish where the collapsible container starts / ends.

Comment on lines 73 to 95
return html.Div(
children=[
html.Div(
id=f"{self.id}_title",
children=[
html.H3(self.title, className="container-title"),
html.Span("keyboard_arrow_up", className="material-symbols-outlined", id=f"{self.id}_icon"),
],
className="collapsible-container-header",
),
dbc.Collapse(
id=self.id,
children=components_container,
is_open=True,
),
],
className="bg-container",
)
Copy link
Contributor

Choose a reason for hiding this comment

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

Might be good to base this PR on this PR first: #1002

I refactored this part so it uses dbc.Container instead of html.Div. Hopefully it will work the same then 🤞

#old-line-height p {
line-height: 1;
margin-bottom: 0.5rem;
.bg-container {
Copy link
Contributor

Choose a reason for hiding this comment

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

I've changed some of the CSS here in #1002

display: flex;
flex-direction: row;
justify-content: space-between;
padding-right: 12px;
Copy link
Contributor

Choose a reason for hiding this comment

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

Suggested change
padding-right: 12px;

Would remove so it's equal space on the left and right

],
layout=vm.Layout(grid=[[0, 0, 0, 0], [1, 1, 1, 1]]),
),
]
)
],
Copy link
Contributor

Choose a reason for hiding this comment

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

Could you add the example of how this looks inside a grid? Is it completely unusable? 😄

),
FlexContainer(
components=[
CollapsibleContainer(
Copy link
Contributor

Choose a reason for hiding this comment

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

Did you try to control the scroll bar? e.g. is it possible that it expands to the available space only such that no scroll bar appears? 🤔 I think this can eventually get a bit tricky, but there should be a way how users could eventually control it

@antonymilne
Copy link
Contributor

antonymilne commented Mar 3, 2025

This is looking great, nice work @nadijagraca!

Just a few questions for now, for @huong-li-nguyen and/or @nadijagraca:

  1. What is the plan for this component compared to vm.Container? Will every single vm.Container now be inside a dbc.Collapse? Or is there a new argument collapsible=True/False to turn on/off this behaviour? Do we want to make it possible for users to specify whether the container should be open or closed by default?
  2. How is this approach better/worse/different from dbc.Accordion? At a glance I guess:
  • dbc.Collapse is better than dbc.Accordion because an accordion really expects multiple items whereas we just want to apply this to a single container
  • dbc.Accordion comes with the rotating arrow built in, while here you needed to provide the clientside callback to do that
  1. Should our nav/controls side panel collapse in the same way as we do here? This would mean we don't need extra custom code for rotating the arrow like I think we have now.

[pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

more clientside callback to component build
@nadijagraca nadijagraca self-assigned this Mar 4, 2025
@huong-li-nguyen
Copy link
Contributor

huong-li-nguyen commented Mar 4, 2025

  1. What is the plan for this component compared to vm.Container? Will every single vm.Container now be inside a dbc.Collapse? Or is there a new argument collapsible=True/False to turn on/off this behaviour? Do we want to make it possible for users to specify whether the container should be open or closed by default?

We can go into more detail later, but for now, my understanding is that this should remain a custom component. It doesn't work well within a grid and only functions properly inside a FlexContainer. To incorporate this into vizro-core, we would need to:

  • Properly enable FlexLayout first.
  • Either set the default to FlexLayout (which you and I previously discussed and decided against) or find a way for it to programmatically switch to FlexLayout if a collapsible container is detected. This part is still unclear.

However, I don't think we need to wait for publishing this custom component as it's ready to use as long as you put it inside a FlexLayout or you have the grid and no other component on screen 😄 And in the meantime we can work on the missing points above.

  1. How is this approach better/worse/different from dbc.Accordion? At a glance I guess:
  • dbc.Collapse is better than dbc.Accordion because an accordion really expects multiple items whereas we just want to apply this to a single container
  • dbc.Accordion comes with the rotating arrow built in, while here you needed to provide the clientside callback to do that

Everything you mentioned above and:

  • With dbc.Collapse, we have more flexibility in terms of collapse behavior. dbc.Accordion only collapses vertically, while dbc.Collapse can collapse both vertically and horizontally: https://dash-bootstrap-components.opensource.faculty.ai/docs/components/collapse/
  • dbc.Accordion comes pre-styled, so you'd need to disable styles for hover, focus, and normal modes. On the other hand, dbc.Collapse comes unstyled, which is easier to work with if you just want to wrap components inside.
  1. Should our nav/controls side panel collapse in the same way as we do here? This would mean we don't need extra custom code for rotating the arrow like I think we have now.

The side panel collapse is actually similarly implemented (@nadijagraca did that one as well, and there is custom JS code that also rotates the icons - correct me here if I am wrong @nadijagraca ). Our side panel however collapses side ways, so the starting position is different. But I think both need to rotate 180 degrees, so if we can consolidate code there, then that sounds great, but I'll leave that to @nadijagraca who knows best 👍

Found it: https://github.com/mckinsey/vizro/blob/main/vizro-core/src/vizro/static/js/models/dashboard.js#L32-L66

@nadijagraca nadijagraca force-pushed the poc/collapsible-container-component branch from c2c6995 to 66aefb6 Compare March 5, 2025 13:05
@nadijagraca nadijagraca requested a review from stichbury as a code owner March 5, 2025 13:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants