import dash_mantine_components as dmc
from dash import Dash, _dash_renderer, html, Input, Output, State, callback, ctx
_dash_renderer._set_react_version("18.2.0")
app = Dash(external_stylesheets=dmc.styles.ALL)
min_step = 0
max_step = 3
active = 1
stepper = html.Div(
[
dmc.Stepper(
id="stepper-basic-usage",
active=active,
children=[
dmc.StepperStep(
label="First step",
description="Create an account",
children=dmc.Text("Step 1 content: Create an account", ta="center"),
),
dmc.StepperStep(
label="Second step",
description="Verify email",
children=dmc.Text("Step 2 content: Verify email", ta="center"),
),
dmc.StepperStep(
label="Final step",
description="Get full access",
children=dmc.Text("Step 3 content: Get full access", ta="center"),
),
dmc.StepperCompleted(
children=dmc.Text(
"Completed, click back button to get to previous step",
ta="center",
)
),
],
),
dmc.Group(
justify="center",
mt="xl",
children=[
dmc.Button("Back", id="back-basic-usage", variant="default"),
dmc.Button("Next step", id="next-basic-usage"),
],
),
]
)
@callback(
Output("stepper-basic-usage", "active"),
Input("back-basic-usage", "n_clicks"),
Input("next-basic-usage", "n_clicks"),
State("stepper-basic-usage", "active"),
prevent_initial_call=True,
)
def update(back, next_, current):
button_id = ctx.triggered_id
step = current if current is not None else active
if button_id == "back-basic-usage":
step = step - 1 if step > min_step else step
else:
step = step + 1 if step < max_step else step
return step
@callback(
Output("container","children"),
Input("stepper-basic-usage", "active")
)
def update(active):
return f"You are on step {active}"
app.layout = dmc.MantineProvider([
stepper,
html.Div(id="container")
])
if __name__ == "__main__":
app.run(debug=True)