Py.Cafe

amward/

dmc-PR-419-Notification-Position

demo of dmc.Notification position prop from pr 419

DocsPricing
  • app.py
  • requirements.txt
app.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40

from dash import Dash, html, callback, Output, Input, _dash_renderer
import dash_mantine_components as dmc
_dash_renderer._set_react_version("18.2.0")

app = Dash(external_stylesheets=dmc.styles.ALL)

positions = ['top-left', 'top-right', 'bottom-left', 'bottom-right', 'top-center', 'bottom-center']

app.layout = dmc.MantineProvider(html.Div(
    [
        dmc.NotificationProvider(withinPortal=True),
        dmc.Center(
            dmc.Select(label="Notification Position", data=positions, value="top-right", id="notify-position", w=400),
            style={"height": 300, "width": "100%"},
        ),
        html.Div(id="notify-container")
    ]
))

@callback(
    Output("notify-container", "children"),
    Input("notify-position", "value"),
    prevent_initial_call=True,
)
def notify(value):
    return dmc.Notification(
            title=f"Notification {value}",
            autoClose=False,
            action="show",
            message="Hello World",
            position=value
        )


if __name__ == "__main__":
    app.run(debug=True)