-
-
Notifications
You must be signed in to change notification settings - Fork 69
Add ModalStack and DrawerStack #606
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
Add ModalStack and DrawerStack #606
Conversation
Here's the example from the Mantine docs for ModalStack from dash import Dash, Input, Output, ctx, no_update
import dash_mantine_components as dmc
app = Dash()
component = dmc.Center([
dmc.ModalStack(
id="modal-stack",
children=[
dmc.ManagedModal(
id={"index": "delete-page"},
# id="delete-page",
title="Delete this page?",
children=[
dmc.Text("Are you sure you want to delete this page? This action cannot be undone."),
dmc.Group(
mt="lg",
justify="flex-end",
children=[
dmc.Button("Cancel", id="cancel-1", variant="default"),
dmc.Button("Delete", id="delete", color="red"),
],
),
],
),
dmc.ManagedModal(
id="confirm-action",
title="Confirm action",
children=[
dmc.Text("Are you sure you want to perform this action? This action cannot be undone. If you are sure, press confirm button below."),
dmc.Group(
mt="lg",
justify="flex-end",
children=[
dmc.Button("Cancel", id="cancel-2", variant="default"),
dmc.Button("Confirm", id="confirm", color="red"),
],
),
],
),
dmc.ManagedModal(
id="really-confirm-action",
title="Really confirm action",
children=[
dmc.Text("Jokes aside. You have confirmed this action. This is your last chance to cancel it. After you press confirm button below, action will be performed and cannot be undone. For real this time. Are you sure you want to proceed?"),
dmc.Group(
mt="lg",
justify="flex-end",
children=[
dmc.Button("Cancel", id="cancel-3", variant="default"),
dmc.Button("Confirm", id="final-confirm", color="red"),
],
),
],
),
]
),
dmc.Button("Open modal", id="open")
])
app.layout = dmc.MantineProvider([component])
@app.callback(
Output("modal-stack", "open"),
Output("modal-stack", "closeAll"),
Input("open", "n_clicks"),
Input("cancel-1", "n_clicks"),
Input("cancel-2", "n_clicks"),
Input("cancel-3", "n_clicks"),
Input("delete", "n_clicks"),
Input("confirm", "n_clicks"),
Input("final-confirm", "n_clicks"),
prevent_initial_call=True,
)
def control_modals(*_):
match ctx.triggered_id:
case "open":
return {"index": "delete-page"}, False
case "cancel-1" | "cancel-2" | "cancel-3" | "final-confirm":
return None, True
case "delete":
return "confirm-action", False
case "confirm":
return "really-confirm-action", False
case _:
return no_update, no_update
if __name__ == "__main__":
app.run(debug=True)
|
@alexcjohnson The ModalStack (and soon DrawerStack) components are a little different — the children are managed by a Mantine hook, and I’m exposing the hook methods (like open, closeAll, etc.) as props on the parent. Not sure if that’s the best approach. I’ve got ModalStack working, and since DrawerStack will be similar, now’s a good time to make changes if needed. Appreciate any feedback! |
Makes sense! It's a little annoying to have a new component type If I were designing the API from the Mantine side I'm not sure why I'd want |
I'd also like to avoid adding an additional Great idea to support |
|
My dyslexic brain would never be able to keep I’m struggling with using the What do you think of just having one prop called |
Hmph I thought this just supported one open modal at a time but maybe it allows multiple, otherwise why would |
Here are some notes about the refactor @alexcjohnson suggested making this a wrapped component because Each one is wrapped in a typed component ( |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
💃 Very nice!
Closes #603
This PR adds Modal Stack and Drawer Stack
Todo