Skip to content

Commit

Permalink
fixed some issues, started adding docstring
Browse files Browse the repository at this point in the history
  • Loading branch information
hansnowak committed Sep 14, 2023
1 parent aff9a20 commit 5e5b1cf
Showing 1 changed file with 40 additions and 13 deletions.
53 changes: 40 additions & 13 deletions solara/lab/components/confirmation_dialog.py
Original file line number Diff line number Diff line change
@@ -1,35 +1,62 @@
from typing import cast, Callable, List, Union, Optional
from typing import Callable, List, Union

import solara
import reacton.ipyvuetify as v

import solara


@solara.component
def ConfirmationDialog(
is_open_rv: solara.Reactive[bool],
action: Callable[[], None],
is_open: Union[solara.Reactive[bool], bool],
on_ok: Callable[[], None],
on_close: Callable[[], None] = lambda: None,
content: Union[str, solara.Element] = "",
title: str = "Confirm action",
on_close: Callable[[], None] = lambda: None,
ok: Union[str, solara.Element] = "OK",
cancel: Union[str, solara.Element] = "Cancel",
children: List[solara.Element] = [],
max_width: Union[int, str] = 500,
persistent: bool = True,
):
"""A dialog used to confirm a user action. By default, has a title, a text explaining the
decision to be made, and two buttons "OK" and "Cancel".
## Basic examples
```solara
import solara
is_open = solara.reactive(False)
def delete_user():
...
solara.ConfirmationDialog(is_open, delete_user, content="Are you sure you want to delete this user?")
```
## Arguments
...to be added...
"""

is_open_reactive = solara.use_reactive(is_open)
del is_open

def perform_action():
action()
on_ok()
close()

def close():
on_close() # possible additional actions when closing
is_open_rv.set(False)
is_open_reactive.set(False)

if is_open_rv.value:
if is_open_reactive.value:
with v.Dialog(
#children=children,
v_model=is_open_rv.value,
on_v_model=is_open_rv.set,
permanent=True,
max_width=500,
v_model=is_open_reactive.value,
on_v_model=is_open_reactive.set,
persistent=True,
max_width=max_width,
):
with solara.Card(title=title):
if isinstance(content, str):
Expand Down

0 comments on commit 5e5b1cf

Please sign in to comment.