Dash Mantine Components (DMC) v2.4.0
Build modern Dash applications with 90+ Mantine UI components.
Quick Start
Minimal DMC app requiring MantineProvider wrapper:
from dash import Dash, callback, Input, Output
import dash_mantine_components as dmc
app = Dash(__name__)
app.layout = dmc.MantineProvider([
dmc.Container([
dmc.Title("My DMC App", order=1),
dmc.TextInput(label="Name", id="name-input", placeholder="Enter name"),
dmc.Button("Submit", id="submit-btn", mt="md"),
dmc.Text(id="output", mt="md"),
], size="sm", py="xl")
])
@callback(Output("output", "children"), Input("submit-btn", "n_clicks"), Input("name-input", "value"))
def update_output(n_clicks, name):
if not n_clicks:
return ""
return f"Hello, {name or 'World'}!"
if __name__ == "__main__":
app.run(debug=True)
Critical: All DMC components MUST be inside dmc.MantineProvider.
Workflow Decision Tree
Select components by use case:
Form Inputs
| Need |
Component |
Key Props |
| Text input |
TextInput |
label, placeholder, value, debounce |
| Dropdown |
Select |
data, value, searchable, clearable |
| Multi-select |
MultiSelect |
data, value, searchable |
| Checkbox |
Checkbox |
label, checked |
| Toggle |
Switch |
label, checked, onLabel, offLabel |
| Number |
NumberInput |
value, min, max, step |
| Date |
DatePickerInput |
value, type, minDate, maxDate |
| Rich text |
Textarea |
label, value, autosize, minRows |
| File upload |
FileInput |
value, accept, multiple |
Layout
| Need |
Component |
Key Props |
| Content wrapper |
Container |
size, px, py |
| Vertical stack |
Stack |
gap, align, justify |
| Horizontal row |
Group |
gap, justify, wrap |
| CSS Grid |
Grid, GridCol |
columns, gutter, span |
| Full app shell |
AppShell |
header, navbar, aside, footer |
| Card container |
Card |
shadow, padding, radius, withBorder |
| Flex layout |
Flex |
direction, wrap, gap, align |
Navigation
| Need |
Component |
Key Props |
| Nav item |
NavLink |
label, href, active, leftSection |
| Tabs |
Tabs, TabsList, TabsPanel |
value, orientation |
| Breadcrumb |
Breadcrumbs |
separator |
| Stepper |
Stepper, StepperStep |
active, onStepClick |
| Pagination |
Pagination |
value, total, siblings |
Feedback & Overlays
| Need |
Component |
Key Props |
| Modal dialog |
Modal |
opened, onClose, title, centered |
| Side panel |
Drawer |
opened, onClose, position, size |
| Toast |
Notification |
title, message, color, icon |
| Alert banner |
Alert |
title, color, variant, icon |
| Loading |
Loader, LoadingOverlay |
size, type, visible |
| Progress |
Progress, RingProgress |
value, size, sections |
| Tooltip |
Tooltip |
label, position, withArrow |
Data Display
| Need |
Component |
Key Props |
| Data table |
Table |
data, striped, highlightOnHover |
| Accordion |
Accordion, AccordionItem |
value, multiple, variant |
| Timeline |
Timeline, TimelineItem |
active, bulletSize |
| Badge |
Badge |
color, variant, size |
Charts
| Need |
Component |
Key Props |
| Line |
LineChart |
data, dataKey, series |
| Bar |
BarChart |
data, dataKey, series, orientation |
| Area |
AreaChart |
data, dataKey, series |
| Pie/Donut |
DonutChart, PieChart |
data, chartLabel |
| Scatter |
ScatterChart |
data, dataKey, series |
→ Full component reference: references/components-quick-ref.md
Core Patterns
Theming
Configure theme via MantineProvider:
theme = {
"primaryColor": "blue",
"fontFamily": "Inter, sans-serif",
"defaultRadius": "md",
"colors": {
"brand": ["#f0f9ff", "#e0f2fe", "#bae6fd", "#7dd3fc", "#38bdf8",
"#0ea5e9", "#0284c7", "#0369a1", "#075985", "#0c4a6e"]
},
"components": {
"Button": {"defaultProps": {"size": "md", "radius": "md"}},
"TextInput": {"defaultProps": {"size": "sm"}},
}
}
app.layout = dmc.MantineProvider(
theme=theme,
forceColorScheme="light", # or "dark", or None for auto
children=[...]
)
Theme Toggle Pattern (clientside callback):
from dash import clientside_callback, ClientsideFunction
app.layout = dmc.MantineProvider(
id="mantine-provider",
children=[
dcc.Store(id="theme-store", storage_type="local", data="light"),
dmc.Switch(id="theme-switch", label="Dark mode", checked=False),
# ... rest of layout
]
)
clientside_callback(
"""(checked) => checked ? "dark" : "light" """,
Output("mantine-provider", "forceColorScheme"),
Input("theme-switch", "checked"),
)
→ Full theming guide: references/theming-patterns.md
Styling
Style Props - Universal props on all DMC components:
| Prop |
CSS Property |
Values |
m, mt, mb, ml, mr, mx, my |
margin |
xs, sm, md, lg, xl or number (px) |
p, pt, pb, pl, pr, px, py |
padding |
same as margin |
c |
color |
"blue", "red.6", "dimmed", "var(--mantine-color-text)" |
bg |
background |
same as color |
w, h |
width, height |
"100%", "50vw", number (px) |
maw, mah, miw, mih |
max/min width/height |
same as w, h |
fw |
font-weight |
400, 500, 700 |
fz |
font-size |
xs, sm, md, lg, xl or number |
ta |
text-align |
"left", "center", "right" |
td |
text-decoration |
"underline", "line-through" |
Responsive Values - Dict with breakpoints:
dmc.Button("Click", w={"base": "100%", "sm": "auto", "lg": 200})
dmc.Stack(gap={"base": "xs", "md": "lg"})
Styles API - Target nested elements:
dmc.Select(
data=["A", "B", "C"],
classNames={"input": "my-input", "dropdown": "my-dropdown"},
styles={"label": {"fontWeight": 700}, "input": {"borderColor": "blue"}},
)
→ Full styling guide: references/styling-guide.md
Callbacks
Basic Pattern:
from dash import callback, Input, Output, State
@callback(
Output("output", "children"),
Input("button", "n_clicks"),
State("input", "value"),
prevent_initial_call=True,
)
def update(n_clicks, value):
return f"Clicked {n_clicks} times with value: {value}"
Pattern-Matching (dynamic components):
from dash import ALL, MATCH, callback_context as ctx
# ALL: Respond to any button with type "dynamic-btn"
@callback(
Output("output", "children"),
Input({"type": "dynamic-btn", "index": ALL}, "n_clicks"),
)
def handle_all(n_clicks_list):
triggered = ctx.triggered_id # {"type": "dynamic-btn", "index": X}
return f"Button {triggered['index']} clicked"
# MATCH: Update the output matching the triggered input
@callback(
Output({"type": "item-output", "index": MATCH}, "children"),
Input({"type": "item-btn", "index": MATCH}, "n_clicks"),
prevent_initial_call=True,
)
def handle_match(n):
return f"Clicked {n} times"
Clientside Callback (browser-side JavaScript):
from dash import clientside_callback
clientside_callback(
"""(n) => n ? `Clicked ${n} times` : "Not clicked" """,
Output("output", "children"),
Input("button", "n_clicks"),
)
DMC-Specific Props:
debounce=300 - Delay callback trigger (ms) for TextInput, Textarea
persistence=True - Persist value across page reloads
persistence_type="local" - Storage type: memory, local, session
→ Full callbacks reference: references/callbacks-advanced.md
Multi-Page Apps
Use Dash Pages with DMC AppShell:
# app.py
import dash
from dash import Dash
import dash_mantine_components as dmc
app = Dash(__name__, use_pages=True, pages_folder="pages")
app.layout = dmc.MantineProvider([
dmc.AppShell(
[
dmc.AppShellHeader(dmc.Group([
dmc.Title("My App", order=3),
dmc.Switch(id="theme-switch"),
], h="100%", px="md")),
dmc.AppShellNavbar([
dmc.NavLink(label=page["name"], href=page["path"], active=page["path"] == "/")
for page in dash.page_registry.values()
], p="md"),
dmc.AppShellMain(dash.page_container),
],
header={"height": 60},
navbar={"width": 250, "breakpoint": "sm", "collapsed": {"mobile": True}},
padding="md",
)
])
if __name__ == "__main__":
app.run(debug=True)
# pages/home.py
import dash
import dash_mantine_components as dmc
dash.register_page(__name__, path="/", name="Home")
layout = dmc.Container([
dmc.Title("Welcome", order=2),
dmc.Text("Home page content"),
], py="xl")
# pages/analytics.py
import dash
import dash_mantine_components as dmc
dash.register_page(__name__, path="/analytics", name="Analytics")
layout = dmc.Container([
dmc.Title("Analytics", order=2),
# Charts, tables, etc.
], py="xl")
Variable Paths:
# pages/user.py
dash.register_page(__name__, path_template="/user/<user_id>")
def layout(user_id=None):
return dmc.Container([
dmc.Title(f"User: {user_id}", order=2),
])
→ Full multi-page guide: references/multi-page-apps.md
Component Categories
Quick links to reference documentation:
| Category |
Components |
Reference |
| All Components |
90+ components with props/events |
components-quick-ref.md |
| Theming |
MantineProvider, theme object, colors |
theming-patterns.md |
| Styling |
Style props, Styles API, CSS variables |
styling-guide.md |
| Callbacks |
Pattern-matching, clientside, background |
callbacks-advanced.md |
| Multi-Page |
Dash Pages, routing, AppShell |
multi-page-apps.md |
| Charts |
Data formats, series config |
charts-data-formats.md |
| Date Pickers |
DatePicker, DatesProvider, localization |
date-pickers-guide.md |
| Dash Core |
dcc.Store, caching, performance |
dash-fundamentals.md |
| Migration |
v1.x to v2.x breaking changes |
migration-v2.md |
Asset Templates
Copy and adapt these templates:
| Template |
Description |
| app_single_page.py |
Complete single-page DMC app with theme toggle |
| app_multi_page.py |
Multi-page app with Dash Pages and AppShell |
| callbacks_patterns.py |
All callback pattern examples |
| theme_presets.py |
Pre-built theme configurations |
Utility Scripts
| Script |
Usage |
| scaffold_app.py |
python scaffold_app.py myapp --type multi --shell |
| generate_theme.py |
python generate_theme.py --primary "#0ea5e9" |
| component_search.py |
python component_search.py "select" |
Common Tasks
Form with Validation
@callback(
Output("submit-btn", "disabled"),
Output("error-text", "children"),
Input("email-input", "value"),
Input("password-input", "value"),
)
def validate_form(email, password):
errors = []
if not email or "@" not in email:
errors.append("Valid email required")
if not password or len(password) < 8:
errors.append("Password must be 8+ characters")
return bool(errors), ", ".join(errors)
Modal Open/Close
app.layout = dmc.MantineProvider([
dmc.Button("Open Modal", id="open-modal-btn"),
dmc.Modal(
id="my-modal",
title="Confirm Action",
children=[
dmc.Text("Are you sure?"),
dmc.Group([
dmc.Button("Cancel", id="cancel-btn", variant="outline"),
dmc.Button("Confirm", id="confirm-btn", color="red"),
], justify="flex-end", mt="md"),
],
),
])
@callback(
Output("my-modal", "opened"),
Input("open-modal-btn", "n_clicks"),
Input("cancel-btn", "n_clicks"),
Input("confirm-btn", "n_clicks"),
prevent_initial_call=True,
)
def toggle_modal(open_clicks, cancel, confirm):
from dash import ctx
if ctx.triggered_id == "open-modal-btn":
return True
return False
Loading State
from dash import dcc
app.layout = dmc.MantineProvider([
dmc.Button("Load Data", id="load-btn"),
dcc.Loading(
id="loading",
type="circle",
children=dmc.Container(id="data-container"),
),
])
@callback(Output("data-container", "children"), Input("load-btn", "n_clicks"))
def load_data(n):
import time
time.sleep(2) # Simulate slow operation
return dmc.Text("Data loaded!")
Chart with Data
data = [
{"month": "Jan", "sales": 100, "profit": 20},
{"month": "Feb", "sales": 150, "profit": 35},
{"month": "Mar", "sales": 120, "profit": 25},
]
dmc.BarChart(
data=data,
dataKey="month",
series=[
{"name": "sales", "color": "blue.6"},
{"name": "profit", "color": "green.6"},
],
h=300,
withLegend=True,
withTooltip=True,
)
Troubleshooting
Common Errors
| Error |
Cause |
Fix |
MantineProvider is required |
Component outside provider |
Wrap entire layout in dmc.MantineProvider([...]) |
Invalid theme color |
Color not in theme |
Use built-in colors (blue, red) or add to theme["colors"] |
Callback output not found |
Component not in layout |
Ensure component with ID exists in layout |
Circular callback detected |
Output also used as Input |
Use State instead of Input for non-triggering values |
Pattern-matching ID mismatch |
Dict keys don't match |
Ensure type and index keys match exactly |
Duplicate callback outputs |
Same output in multiple callbacks |
Add allow_duplicate=True to additional callbacks |
Debug Tips
- Check browser console for JavaScript errors
- Use
debug=True in app.run() for detailed Python errors
- Print
ctx.triggered_id to see which input fired
- Validate JSON-serializable callback returns (no Python objects)
- Test with
prevent_initial_call=True to avoid startup errors
DMC v2.x Gotchas
DateTimePicker: Use timePickerProps not timeInputProps
Carousel: Embla options need {"containScroll": "trimSnaps"} wrapper
- Default
reuseTargetNode=True may cause Portal issues - set to False if overlays misbehave
- Use
MantineProvider not MantineProviderV2 (deprecated)
→ Full migration guide: references/migration-v2.md
1---2name: dmc-py3description: Expert guidance for building Dash applications with Dash Mantine Components (DMC) v2.4.0. Use when creating dashboards, forms, data visualization apps with DMC. Covers: MantineProvider theming, style props (m, p, c, bg, w, h), Styles API, callbacks (basic, pattern-matching ALL/MATCH/ALLSMALLER, clientside, background), multi-page apps with Dash Pages, charts (LineChart, BarChart, DonutChart), date pickers, modals, and all 90+ components. Triggers on: dash-mantine-components, DMC, MantineProvider, dmc.Button, dmc.Select, dmc.Modal, dmc.BarChart, Mantine theme, Dash UI components, Dash callbacks, multi-page Dash app, pattern-matching callbacks, clientside callbacks, AppShell.4---5
6# Dash Mantine Components (DMC) v2.4.0
7
8Build modern Dash applications with 90+ Mantine UI components.
9
10## Quick Start
11
12Minimal DMC app requiring MantineProvider wrapper:
13
14```python
15from dash import Dash, callback, Input, Output
16import dash_mantine_components as dmc
17
18app = Dash(__name__)
19
20app.layout = dmc.MantineProvider([
21 dmc.Container([
22 dmc.Title("My DMC App", order=1),
23 dmc.TextInput(label="Name", id="name-input", placeholder="Enter name"),
24 dmc.Button("Submit", id="submit-btn", mt="md"),
25 dmc.Text(id="output", mt="md"),
26 ], size="sm", py="xl")
27])
28
29@callback(Output("output", "children"), Input("submit-btn", "n_clicks"), Input("name-input", "value"))
30def update_output(n_clicks, name):
31 if not n_clicks:
32 return ""
33 return f"Hello, {name or 'World'}!"
34
35if __name__ == "__main__":
36 app.run(debug=True)
37```
38
39**Critical**: All DMC components MUST be inside `dmc.MantineProvider`.
40
41---
42
43## Workflow Decision Tree
44
45Select components by use case:
46
47### Form Inputs
48| Need | Component | Key Props |
49|------|-----------|-----------|
50| Text input | `TextInput` | `label`, `placeholder`, `value`, `debounce` |
51| Dropdown | `Select` | `data`, `value`, `searchable`, `clearable` |
52| Multi-select | `MultiSelect` | `data`, `value`, `searchable` |
53| Checkbox | `Checkbox` | `label`, `checked` |
54| Toggle | `Switch` | `label`, `checked`, `onLabel`, `offLabel` |
55| Number | `NumberInput` | `value`, `min`, `max`, `step` |
56| Date | `DatePickerInput` | `value`, `type`, `minDate`, `maxDate` |
57| Rich text | `Textarea` | `label`, `value`, `autosize`, `minRows` |
58| File upload | `FileInput` | `value`, `accept`, `multiple` |
59
60### Layout
61| Need | Component | Key Props |
62|------|-----------|-----------|
63| Content wrapper | `Container` | `size`, `px`, `py` |
64| Vertical stack | `Stack` | `gap`, `align`, `justify` |
65| Horizontal row | `Group` | `gap`, `justify`, `wrap` |
66| CSS Grid | `Grid`, `GridCol` | `columns`, `gutter`, `span` |
67| Full app shell | `AppShell` | `header`, `navbar`, `aside`, `footer` |
68| Card container | `Card` | `shadow`, `padding`, `radius`, `withBorder` |
69| Flex layout | `Flex` | `direction`, `wrap`, `gap`, `align` |
70
71### Navigation
72| Need | Component | Key Props |
73|------|-----------|-----------|
74| Nav item | `NavLink` | `label`, `href`, `active`, `leftSection` |
75| Tabs | `Tabs`, `TabsList`, `TabsPanel` | `value`, `orientation` |
76| Breadcrumb | `Breadcrumbs` | `separator` |
77| Stepper | `Stepper`, `StepperStep` | `active`, `onStepClick` |
78| Pagination | `Pagination` | `value`, `total`, `siblings` |
79
80### Feedback & Overlays
81| Need | Component | Key Props |
82|------|-----------|-----------|
83| Modal dialog | `Modal` | `opened`, `onClose`, `title`, `centered` |
84| Side panel | `Drawer` | `opened`, `onClose`, `position`, `size` |
85| Toast | `Notification` | `title`, `message`, `color`, `icon` |
86| Alert banner | `Alert` | `title`, `color`, `variant`, `icon` |
87| Loading | `Loader`, `LoadingOverlay` | `size`, `type`, `visible` |
88| Progress | `Progress`, `RingProgress` | `value`, `size`, `sections` |
89| Tooltip | `Tooltip` | `label`, `position`, `withArrow` |
90
91### Data Display
92| Need | Component | Key Props |
93|------|-----------|-----------|
94| Data table | `Table` | `data`, `striped`, `highlightOnHover` |
95| Accordion | `Accordion`, `AccordionItem` | `value`, `multiple`, `variant` |
96| Timeline | `Timeline`, `TimelineItem` | `active`, `bulletSize` |
97| Badge | `Badge` | `color`, `variant`, `size` |
98
99### Charts
100| Need | Component | Key Props |
101|------|-----------|-----------|
102| Line | `LineChart` | `data`, `dataKey`, `series` |
103| Bar | `BarChart` | `data`, `dataKey`, `series`, `orientation` |
104| Area | `AreaChart` | `data`, `dataKey`, `series` |
105| Pie/Donut | `DonutChart`, `PieChart` | `data`, `chartLabel` |
106| Scatter | `ScatterChart` | `data`, `dataKey`, `series` |
107
108→ Full component reference: [references/components-quick-ref.md](references/components-quick-ref.md)
109
110---
111
112## Core Patterns
113
114### Theming
115
116Configure theme via MantineProvider:
117
118```python
119theme = {
120 "primaryColor": "blue",
121 "fontFamily": "Inter, sans-serif",
122 "defaultRadius": "md",
123 "colors": {
124 "brand": ["#f0f9ff", "#e0f2fe", "#bae6fd", "#7dd3fc", "#38bdf8",
125 "#0ea5e9", "#0284c7", "#0369a1", "#075985", "#0c4a6e"]
126 },
127 "components": {
128 "Button": {"defaultProps": {"size": "md", "radius": "md"}},
129 "TextInput": {"defaultProps": {"size": "sm"}},
130 }
131}
132
133app.layout = dmc.MantineProvider(
134 theme=theme,
135 forceColorScheme="light", # or "dark", or None for auto
136 children=[...]
137)
138```
139
140**Theme Toggle Pattern** (clientside callback):
141
142```python
143from dash import clientside_callback, ClientsideFunction
144
145app.layout = dmc.MantineProvider(
146 id="mantine-provider",
147 children=[
148 dcc.Store(id="theme-store", storage_type="local", data="light"),
149 dmc.Switch(id="theme-switch", label="Dark mode", checked=False),
150 # ... rest of layout
151 ]
152)
153
154clientside_callback(
155 """(checked) => checked ? "dark" : "light" """,
156 Output("mantine-provider", "forceColorScheme"),
157 Input("theme-switch", "checked"),
158)
159```
160
161→ Full theming guide: [references/theming-patterns.md](references/theming-patterns.md)
162
163### Styling
164
165**Style Props** - Universal props on all DMC components:
166
167| Prop | CSS Property | Values |
168|------|--------------|--------|
169| `m`, `mt`, `mb`, `ml`, `mr`, `mx`, `my` | margin | `xs`, `sm`, `md`, `lg`, `xl` or number (px) |
170| `p`, `pt`, `pb`, `pl`, `pr`, `px`, `py` | padding | same as margin |
171| `c` | color | `"blue"`, `"red.6"`, `"dimmed"`, `"var(--mantine-color-text)"` |
172| `bg` | background | same as color |
173| `w`, `h` | width, height | `"100%"`, `"50vw"`, number (px) |
174| `maw`, `mah`, `miw`, `mih` | max/min width/height | same as w, h |
175| `fw` | font-weight | `400`, `500`, `700` |
176| `fz` | font-size | `xs`, `sm`, `md`, `lg`, `xl` or number |
177| `ta` | text-align | `"left"`, `"center"`, `"right"` |
178| `td` | text-decoration | `"underline"`, `"line-through"` |
179
180**Responsive Values** - Dict with breakpoints:
181
182```python
183dmc.Button("Click", w={"base": "100%", "sm": "auto", "lg": 200})
184dmc.Stack(gap={"base": "xs", "md": "lg"})
185```
186
187**Styles API** - Target nested elements:
188
189```python
190dmc.Select(
191 data=["A", "B", "C"],
192 classNames={"input": "my-input", "dropdown": "my-dropdown"},
193 styles={"label": {"fontWeight": 700}, "input": {"borderColor": "blue"}},
194)
195```
196
197→ Full styling guide: [references/styling-guide.md](references/styling-guide.md)
198
199### Callbacks
200
201**Basic Pattern**:
202
203```python
204from dash import callback, Input, Output, State
205
206@callback(
207 Output("output", "children"),
208 Input("button", "n_clicks"),
209 State("input", "value"),
210 prevent_initial_call=True,
211)
212def update(n_clicks, value):
213 return f"Clicked {n_clicks} times with value: {value}"
214```
215
216**Pattern-Matching** (dynamic components):
217
218```python
219from dash import ALL, MATCH, callback_context as ctx
220
221# ALL: Respond to any button with type "dynamic-btn"
222@callback(
223 Output("output", "children"),
224 Input({"type": "dynamic-btn", "index": ALL}, "n_clicks"),
225)
226def handle_all(n_clicks_list):
227 triggered = ctx.triggered_id # {"type": "dynamic-btn", "index": X}
228 return f"Button {triggered['index']} clicked"
229
230# MATCH: Update the output matching the triggered input
231@callback(
232 Output({"type": "item-output", "index": MATCH}, "children"),
233 Input({"type": "item-btn", "index": MATCH}, "n_clicks"),
234 prevent_initial_call=True,
235)
236def handle_match(n):
237 return f"Clicked {n} times"
238```
239
240**Clientside Callback** (browser-side JavaScript):
241
242```python
243from dash import clientside_callback
244
245clientside_callback(
246 """(n) => n ? `Clicked ${n} times` : "Not clicked" """,
247 Output("output", "children"),
248 Input("button", "n_clicks"),
249)
250```
251
252**DMC-Specific Props**:
253- `debounce=300` - Delay callback trigger (ms) for TextInput, Textarea
254- `persistence=True` - Persist value across page reloads
255- `persistence_type="local"` - Storage type: memory, local, session
256
257→ Full callbacks reference: [references/callbacks-advanced.md](references/callbacks-advanced.md)
258
259---
260
261## Multi-Page Apps
262
263Use Dash Pages with DMC AppShell:
264
265```python
266# app.py
267import dash
268from dash import Dash
269import dash_mantine_components as dmc
270
271app = Dash(__name__, use_pages=True, pages_folder="pages")
272
273app.layout = dmc.MantineProvider([
274 dmc.AppShell(
275 [
276 dmc.AppShellHeader(dmc.Group([
277 dmc.Title("My App", order=3),
278 dmc.Switch(id="theme-switch"),
279 ], h="100%", px="md")),
280 dmc.AppShellNavbar([
281 dmc.NavLink(label=page["name"], href=page["path"], active=page["path"] == "/")
282 for page in dash.page_registry.values()
283 ], p="md"),
284 dmc.AppShellMain(dash.page_container),
285 ],
286 header={"height": 60},
287 navbar={"width": 250, "breakpoint": "sm", "collapsed": {"mobile": True}},
288 padding="md",
289 )
290])
291
292if __name__ == "__main__":
293 app.run(debug=True)
294```
295
296```python
297# pages/home.py
298import dash
299import dash_mantine_components as dmc
300
301dash.register_page(__name__, path="/", name="Home")
302
303layout = dmc.Container([
304 dmc.Title("Welcome", order=2),
305 dmc.Text("Home page content"),
306], py="xl")
307```
308
309```python
310# pages/analytics.py
311import dash
312import dash_mantine_components as dmc
313
314dash.register_page(__name__, path="/analytics", name="Analytics")
315
316layout = dmc.Container([
317 dmc.Title("Analytics", order=2),
318 # Charts, tables, etc.
319], py="xl")
320```
321
322**Variable Paths**:
323
324```python
325# pages/user.py
326dash.register_page(__name__, path_template="/user/<user_id>")
327
328def layout(user_id=None):
329 return dmc.Container([
330 dmc.Title(f"User: {user_id}", order=2),
331 ])
332```
333
334→ Full multi-page guide: [references/multi-page-apps.md](references/multi-page-apps.md)
335
336---
337
338## Component Categories
339
340Quick links to reference documentation:
341
342| Category | Components | Reference |
343|----------|------------|-----------|
344| **All Components** | 90+ components with props/events | [components-quick-ref.md](references/components-quick-ref.md) |
345| **Theming** | MantineProvider, theme object, colors | [theming-patterns.md](references/theming-patterns.md) |
346| **Styling** | Style props, Styles API, CSS variables | [styling-guide.md](references/styling-guide.md) |
347| **Callbacks** | Pattern-matching, clientside, background | [callbacks-advanced.md](references/callbacks-advanced.md) |
348| **Multi-Page** | Dash Pages, routing, AppShell | [multi-page-apps.md](references/multi-page-apps.md) |
349| **Charts** | Data formats, series config | [charts-data-formats.md](references/charts-data-formats.md) |
350| **Date Pickers** | DatePicker, DatesProvider, localization | [date-pickers-guide.md](references/date-pickers-guide.md) |
351| **Dash Core** | dcc.Store, caching, performance | [dash-fundamentals.md](references/dash-fundamentals.md) |
352| **Migration** | v1.x to v2.x breaking changes | [migration-v2.md](references/migration-v2.md) |
353
354### Asset Templates
355
356Copy and adapt these templates:
357
358| Template | Description |
359|----------|-------------|
360| [app_single_page.py](assets/app_single_page.py) | Complete single-page DMC app with theme toggle |
361| [app_multi_page.py](assets/app_multi_page.py) | Multi-page app with Dash Pages and AppShell |
362| [callbacks_patterns.py](assets/callbacks_patterns.py) | All callback pattern examples |
363| [theme_presets.py](assets/theme_presets.py) | Pre-built theme configurations |
364
365### Utility Scripts
366
367| Script | Usage |
368|--------|-------|
369| [scaffold_app.py](scripts/scaffold_app.py) | `python scaffold_app.py myapp --type multi --shell` |
370| [generate_theme.py](scripts/generate_theme.py) | `python generate_theme.py --primary "#0ea5e9"` |
371| [component_search.py](scripts/component_search.py) | `python component_search.py "select"` |
372
373---
374
375## Common Tasks
376
377### Form with Validation
378
379```python
380@callback(
381 Output("submit-btn", "disabled"),
382 Output("error-text", "children"),
383 Input("email-input", "value"),
384 Input("password-input", "value"),
385)
386def validate_form(email, password):
387 errors = []
388 if not email or "@" not in email:
389 errors.append("Valid email required")
390 if not password or len(password) < 8:
391 errors.append("Password must be 8+ characters")
392 return bool(errors), ", ".join(errors)
393```
394
395### Modal Open/Close
396
397```python
398app.layout = dmc.MantineProvider([
399 dmc.Button("Open Modal", id="open-modal-btn"),
400 dmc.Modal(
401 id="my-modal",
402 title="Confirm Action",
403 children=[
404 dmc.Text("Are you sure?"),
405 dmc.Group([
406 dmc.Button("Cancel", id="cancel-btn", variant="outline"),
407 dmc.Button("Confirm", id="confirm-btn", color="red"),
408 ], justify="flex-end", mt="md"),
409 ],
410 ),
411])
412
413@callback(
414 Output("my-modal", "opened"),
415 Input("open-modal-btn", "n_clicks"),
416 Input("cancel-btn", "n_clicks"),
417 Input("confirm-btn", "n_clicks"),
418 prevent_initial_call=True,
419)
420def toggle_modal(open_clicks, cancel, confirm):
421 from dash import ctx
422 if ctx.triggered_id == "open-modal-btn":
423 return True
424 return False
425```
426
427### Loading State
428
429```python
430from dash import dcc
431
432app.layout = dmc.MantineProvider([
433 dmc.Button("Load Data", id="load-btn"),
434 dcc.Loading(
435 id="loading",
436 type="circle",
437 children=dmc.Container(id="data-container"),
438 ),
439])
440
441@callback(Output("data-container", "children"), Input("load-btn", "n_clicks"))
442def load_data(n):
443 import time
444 time.sleep(2) # Simulate slow operation
445 return dmc.Text("Data loaded!")
446```
447
448### Chart with Data
449
450```python
451data = [
452 {"month": "Jan", "sales": 100, "profit": 20},
453 {"month": "Feb", "sales": 150, "profit": 35},
454 {"month": "Mar", "sales": 120, "profit": 25},
455]
456
457dmc.BarChart(
458 data=data,
459 dataKey="month",
460 series=[
461 {"name": "sales", "color": "blue.6"},
462 {"name": "profit", "color": "green.6"},
463 ],
464 h=300,
465 withLegend=True,
466 withTooltip=True,
467)
468```
469
470---
471
472## Troubleshooting
473
474### Common Errors
475
476| Error | Cause | Fix |
477|-------|-------|-----|
478| `MantineProvider is required` | Component outside provider | Wrap entire layout in `dmc.MantineProvider([...])` |
479| `Invalid theme color` | Color not in theme | Use built-in colors (`blue`, `red`) or add to `theme["colors"]` |
480| `Callback output not found` | Component not in layout | Ensure component with ID exists in layout |
481| `Circular callback detected` | Output also used as Input | Use `State` instead of `Input` for non-triggering values |
482| `Pattern-matching ID mismatch` | Dict keys don't match | Ensure `type` and `index` keys match exactly |
483| `Duplicate callback outputs` | Same output in multiple callbacks | Add `allow_duplicate=True` to additional callbacks |
484
485### Debug Tips
486
4871. **Check browser console** for JavaScript errors
4882. **Use `debug=True`** in `app.run()` for detailed Python errors
4893. **Print `ctx.triggered_id`** to see which input fired
4904. **Validate JSON-serializable** callback returns (no Python objects)
4915. **Test with `prevent_initial_call=True`** to avoid startup errors
492
493### DMC v2.x Gotchas
494
495- `DateTimePicker`: Use `timePickerProps` not `timeInputProps`
496- `Carousel`: Embla options need `{"containScroll": "trimSnaps"}` wrapper
497- Default `reuseTargetNode=True` may cause Portal issues - set to `False` if overlays misbehave
498- Use `MantineProvider` not `MantineProviderV2` (deprecated)
499
500→ Full migration guide: [references/migration-v2.md](references/migration-v2.md)