Replies: 2 comments 3 replies
-
Hi guys, can someone share at least any link to guide me? |
Beta Was this translation helpful? Give feedback.
0 replies
-
Try something like this import reflex as rx
class State(rx.State):
which_dialog_open: str = ""
def delete(self):
print("Deleted item")
def save_settings(self):
print("Saved settings")
def delete_dialog():
return rx.alert_dialog.root(
rx.alert_dialog.content(
rx.alert_dialog.title("Are you Sure?"),
rx.alert_dialog.description(
rx.text(
"This action cannot be undone. Are you sure you want to delete this item?",
),
margin_bottom="20px",
),
rx.hstack(
rx.alert_dialog.action(
rx.button(
"Delete",
color_scheme="red",
on_click=State.delete,
),
),
rx.spacer(),
rx.alert_dialog.cancel(rx.button("Cancel")),
),
),
open=State.which_dialog_open == "delete",
on_open_change=State.set_which_dialog_open(""),
)
def settings_dialog():
return rx.dialog.root(
rx.dialog.content(
rx.dialog.title("Settings"),
rx.dialog.description(
rx.text("Set your settings in this settings dialog."),
margin_bottom="20px",
),
rx.dialog.close(
rx.button("Close", on_click=State.save_settings),
),
),
open=State.which_dialog_open == "settings",
on_open_change=State.set_which_dialog_open(""),
)
def index() -> rx.Component:
return rx.vstack(
rx.menu.root(
rx.menu.trigger(rx.icon("menu")),
rx.menu.content(
rx.menu.item(
"Delete",
on_click=State.set_which_dialog_open("delete"),
),
rx.menu.item(
"Settings",
on_click=State.set_which_dialog_open("settings"),
),
),
),
rx.cond(
State.which_dialog_open,
rx.heading(f"{State.which_dialog_open} dialog is open"),
),
delete_dialog(),
settings_dialog(),
height="100vh",
align="center",
)
app = rx.App()
app.add_page(index) You cannot use the triggers because the context menu items are ephemeral, so a dialog cannot be "inside" of them. To get around this, I use a state var to control whether or not the dialog is open. |
Beta Was this translation helpful? Give feedback.
3 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
-
I would like to open appropriate dialog boxes for items present in the Dropdown menu. Assume I have menus like share, delete, download, etc. On selecting these items should open its corresponding dialog box.
![Screenshot 2024-03-15 at 5 40 41 PM](https://private-user-images.githubusercontent.com/14220737/313188028-4cf17416-6df5-4124-9a04-981d01318966.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3Mzg4MTUwMTksIm5iZiI6MTczODgxNDcxOSwicGF0aCI6Ii8xNDIyMDczNy8zMTMxODgwMjgtNGNmMTc0MTYtNmRmNS00MTI0LTlhMDQtOTgxZDAxMzE4OTY2LnBuZz9YLUFtei1BbGdvcml0aG09QVdTNC1ITUFDLVNIQTI1NiZYLUFtei1DcmVkZW50aWFsPUFLSUFWQ09EWUxTQTUzUFFLNFpBJTJGMjAyNTAyMDYlMkZ1cy1lYXN0LTElMkZzMyUyRmF3czRfcmVxdWVzdCZYLUFtei1EYXRlPTIwMjUwMjA2VDA0MDUxOVomWC1BbXotRXhwaXJlcz0zMDAmWC1BbXotU2lnbmF0dXJlPWRiMzM4MzliNDQyMWU4N2RhN2UwMWQ1ZjAxN2VjYmRiMGE1OWIyZmE3ZTkwOWEzZmM4OGQ0NWQ0MGJiMTQ0YTMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.3GWRiIU11_YynDmtAscC2ZXeGJU54jzd-6lkxRnm3W0)
Please guide me on how to implement this
Thanks a ton.
Beta Was this translation helpful? Give feedback.
All reactions