|
| 1 | +from chartlets import Component, Input, Output |
| 2 | +from chartlets.components import Box, Button, Dialog, Typography |
| 3 | + |
| 4 | +from server.context import Context |
| 5 | +from server.panel import Panel |
| 6 | + |
| 7 | +panel = Panel(__name__, title="Panel E") |
| 8 | + |
| 9 | + |
| 10 | +# noinspection PyUnusedLocal |
| 11 | +@panel.layout() |
| 12 | +def render_panel( |
| 13 | + ctx: Context, |
| 14 | +) -> Component: |
| 15 | + open_button = Button(id="open_button", text="Open Dialog") |
| 16 | + okay_button = Button(id="okay_button", text="Okay") |
| 17 | + not_okay_button = Button(id="not_okay_button", text="Not okay") |
| 18 | + dialog = Dialog( |
| 19 | + id="dialog", |
| 20 | + title="This is a modal dialog", |
| 21 | + titleProps={ |
| 22 | + "id": "dialog-title", |
| 23 | + "variant": "h6", |
| 24 | + "style": {"fontWeight": "bold", "color": "darkblue"}, |
| 25 | + }, |
| 26 | + content="You can add your content here in the dialog.", |
| 27 | + contentProps={ |
| 28 | + "id": "dialog-description", |
| 29 | + "variant": "body1", |
| 30 | + "style": {"padding": "16px", "color": "gray"}, |
| 31 | + }, |
| 32 | + children=[okay_button, not_okay_button], |
| 33 | + disableEscapeKeyDown=True, |
| 34 | + fullScreen=False, |
| 35 | + fullWidth=True, |
| 36 | + maxWidth="sm", |
| 37 | + scroll="paper", |
| 38 | + ariaLabel="dialog-title", |
| 39 | + ariaDescribedBy="dialog-description", |
| 40 | + ) |
| 41 | + |
| 42 | + info_text = Typography(id="info_text") |
| 43 | + |
| 44 | + return Box( |
| 45 | + style={ |
| 46 | + "display": "flex", |
| 47 | + "flexDirection": "column", |
| 48 | + "width": "100%", |
| 49 | + "height": "100%", |
| 50 | + "gap": "6px", |
| 51 | + }, |
| 52 | + children=[open_button, dialog, info_text], |
| 53 | + ) |
| 54 | + |
| 55 | + |
| 56 | +# noinspection PyUnusedLocal |
| 57 | +@panel.callback(Input("open_button", "clicked"), Output("dialog", "open")) |
| 58 | +def dialog_on_open(ctx: Context, button) -> bool: |
| 59 | + return True |
| 60 | + |
| 61 | + |
| 62 | +# noinspection PyUnusedLocal |
| 63 | +@panel.callback( |
| 64 | + Input("okay_button", "clicked"), |
| 65 | + Output("dialog", "open"), |
| 66 | + Output("info_text", "children"), |
| 67 | +) |
| 68 | +def dialog_on_close(ctx: Context, button) -> tuple[bool, list[str]]: |
| 69 | + return False, ["Okay button was clicked!"] |
| 70 | + |
| 71 | + |
| 72 | +# noinspection PyUnusedLocal |
| 73 | +@panel.callback( |
| 74 | + Input("not_okay_button", "clicked"), |
| 75 | + Output("dialog", "open"), |
| 76 | + Output("info_text", "children"), |
| 77 | +) |
| 78 | +def dialog_on_close(ctx: Context, button) -> tuple[bool, list[str]]: |
| 79 | + return False, ["Not okay button was clicked!"] |
0 commit comments