Material Design UI components for FastHTML
Project description
FastMDUI
Material Design UI components for FastHTML projects with full Material Icons support.
Installation
pip install fastmdui
Quick Start
from fasthtml.common import FastHTML, serve
from fastmdui import MDUI, Button, Card, TextField, Icon, TopAppBar, TopAppBarTitle, ThemeToggle, Div
# Initialize with Material Icons and Open Sans font
app = FastHTML(hdrs=MDUI.headers())
@app.get("/")
def home():
return (
TopAppBar(
TopAppBarTitle("My App"),
Button(icon="menu", variant="text", slot="start"),
Div(slot="end")(
Button(icon="search", variant="text"),
ThemeToggle()
)
),
Card(
title="Welcome to fastMDUI",
subtitle="Material Design for FastHTML",
content=[
TextField(label="Enter your name", type="text"),
Button("Submit", variant="filled", icon="send"),
Icon("favorite", variant="outlined")
]
)
)
serve()
Material Icons Support
FastMDUI includes built-in support for Google Material Icons with multiple variants:
Icon Variants
# Choose your preferred icon style when initializing
app = FastHTML(hdrs=MDUI.headers(icons="outlined")) # Outlined
app = FastHTML(hdrs=MDUI.headers(icons="rounded")) # Rounded corners
app = FastHTML(hdrs=MDUI.headers(icons="sharp")) # Sharp corners
app = FastHTML(hdrs=MDUI.headers(icons="filled")) # Filled style
app = FastHTML(hdrs=MDUI.headers()) # default, all icons included (recommended)
Note: Using icons="all" ensures all icon variants work correctly across all components. This is recommended for full compatibility and selected by default.
Using Icons
from fastmdui import Icon, Button
# Standalone icon with variant
Icon("home", variant="outlined")
Icon("search", variant="rounded")
Icon("settings", variant="sharp")
Icon("favorite", variant="filled")
# Buttons with icons (simple attribute method) - MDUI handles rendering
Button("Search", icon="search") # Icon at start
Button("Next", end_icon="arrow_forward") # Icon at end
Button("Navigate", icon="arrow_back", end_icon="arrow_forward") # Both
# Buttons with custom icon slots (advanced)
Button("Download",
icon_slot=Icon("downloading", variant="outlined"),
end_icon_slot=Icon("attach_file", variant="filled"))
# Icons in other components
Chip("Python", icon="code")
ListItem("Settings", icon="settings")
Fab(icon="add")
Important: When using the icon attribute on components like Button, Chip, etc., just pass the icon name as a string. MDUI will automatically render the icon using Material Icons.
Troubleshooting Icons
If you see icon names as text instead of icons:
-
Use
icons="all"when initializing to ensure all variants load:app = FastHTML(hdrs=MDUI.headers(icons="all"))
-
Check browser console for font loading errors
-
Verify icon names at Google Material Icons - use the exact names shown there (e.g.,
arrow_forward, notarrow-forward) -
Test icon loading by running the icon test example:
python examples/icon_test.py -
Ensure you're not blocking Google Fonts - Material Icons load from Google's CDN
Using Icons
from fastmdui import Icon, Button
# Standalone icon with variant
Icon("home", variant="outlined")
Icon("search", variant="rounded")
Icon("settings", variant="sharp")
Icon("favorite", variant="filled")
# Buttons with icons (simple attribute method)
Button("Search", icon="search") # Icon at start
Button("Next", end_icon="arrow_forward") # Icon at end
Button("Navigate", icon="arrow_back", end_icon="arrow_forward") # Both
# Buttons with custom icon slots (advanced)
Button("Download",
icon_slot=Icon("downloading", variant="outlined"),
end_icon_slot=Icon("attach_file", variant="filled"))
# Icons in other components
Chip("Python", icon="code")
ListItem("Settings", icon="settings")
Fab(icon="add")
Button Icon Options
Buttons support icons in multiple ways:
- Simple icon attribute (recommended for most cases):
Button("Search", icon="search")
Button("Next", end_icon="arrow_forward")
Button("Navigate", icon="arrow_back", end_icon="arrow_forward")
- Custom icon slots (for advanced styling):
Button("Download",
icon_slot=Icon("cloud_download", variant="outlined"),
end_icon_slot=Icon("check", variant="filled", style="color: green;"))
Available Icon Names
Browse the full icon library at Google Material Icons:
home,search,settings,favorite,menuadd,delete,edit,check,closearrow_back,arrow_forward,expand_more,expand_lessperson,email,phone,location_on- And 2000+ more icons!
Components
- Button: Material Design buttons with variants and icons
- Card: Cards for displaying content
- TextField: Text input fields
- Select: Dropdown selection
- Checkbox, Radio, Switch: Form controls
- Dialog: Modal dialogs
- Snackbar: Notification messages
- Navigation: NavigationBar, NavigationDrawer, TopAppBar (with child support)
- Chip: Compact elements for tags/filters
- List: Lists with items
- Icon: Material icons with variants (outlined, rounded, sharp, filled)
- Avatar: User avatars
- Badge: Notification badges
- Fab: Floating action buttons
- Progress: Progress indicators
- Slider: Range sliders
- Tab: Tabbed interfaces
- Tooltip: Hover tooltips
- ThemeToggle: Dark/Light theme toggle button
- Div: Convenience wrapper for div elements
TopAppBar with Children
The TopAppBar component now accepts children, allowing you to add any UI components:
from fastmdui import TopAppBar, TopAppBarTitle, Button, ThemeToggle, Div
# Simple title
TopAppBar(title="My App")
# With menu button at start
TopAppBar(
TopAppBarTitle("My App"),
Button(icon="menu", variant="text", slot="start")
)
# With actions at end
TopAppBar(
TopAppBarTitle("My App"),
Div(slot="end")(
Button(icon="search", variant="text"),
Button(icon="notifications", variant="text"),
ThemeToggle()
)
)
# Complete configuration
TopAppBar(
TopAppBarTitle("My App"),
Button(icon="menu", variant="text", slot="start"),
Div(slot="end", style="display: flex; gap: 8px;")(
Button(icon="search", variant="text"),
Button(icon="more_vert", variant="text")
)
)
# Custom content (no title prop)
TopAppBar(
TopAppBarTitle("My App"),
Button(icon="arrow_back", variant="text", slot="start"),
TextField(placeholder="Search...", style="flex: 1; margin: 0 16px;"),
Button(icon="close", variant="text", slot="end")
)
TopAppBar Slots:
- slot="start": Place elements at the start (left side) before the title
- slot="end": Place elements at the end (right side) after the title
- No slot: Elements appear between start and end sections
Theme Toggle
fastMDUI includes a built-in theme toggle component that allows users to switch between light and dark themes:
from fastmdui import ThemeToggle, TopAppBar
# Add to your top bar
TopAppBar(title="My App")(
Div(slot="end")(
ThemeToggle()
)
)
# Or use anywhere in your app
ThemeToggle()
# Customize icons
ThemeToggle(icon_light="wb_sunny", icon_dark="nights_stay")
# Or manually trigger with a custom button
Button("Toggle Theme", onclick="toggleTheme()")
Theme Features:
- Auto-detects system preference: Automatically uses your system's theme setting
- Persistent storage: Remembers user's choice using localStorage
- Smooth transitions: Theme changes apply instantly to all components
- Customizable icons: Use any Material Icon for light/dark states
Theming
# Set theme, primary color, and icon style
app = FastHTML(hdrs=MDUI.headers(
theme="dark",
primary_light_color="100, 20, 30",
primary_dark_color="100, 20, 30",
icons="rounded"
))
Theme Options
theme:"auto"(default),"light", or"dark"primary_light_color: Any rgb color (e.g.,"10, 0, 20")primary_dark_color: Any rgb color (e.g.,"100, 40, 35")icons:"outlined","rounded","sharp","filled", or"all"(default)
Examples
Form with Icons
from fastmdui import Card, TextField, Button, Icon
Card(
title="Login",
content=[
Icon("person", variant="outlined"),
TextField(label="Username", type="text"),
Icon("lock", variant="outlined"),
TextField(label="Password", type="password"),
Button("Sign In", variant="filled", icon="login")
]
)
Navigation with Icons
from fastmdui import TopAppBar, TopAppBarTitle, NavigationBar, Fab
TopAppBar(
TopAppBarTitle("FastMDUI App")
)
NavigationBar(
# Add navigation items with icons
)
Fab(icon="add", variant="primary")
Icon Gallery
from fastmdui import List, ListItem, Divider
List(
ListItem("Home", icon="home"),
Divider(),
ListItem("Search", icon="search"),
Divider(),
ListItem("Settings", icon="settings"),
Divider(),
ListItem("Favorites", icon="favorite"),
)
License
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file fastmdui-0.1.3.tar.gz.
File metadata
- Download URL: fastmdui-0.1.3.tar.gz
- Upload date:
- Size: 155.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a79b774dafa5a34edb33f9b84e6880cc2816c75455b557243d204f2e00bc9806
|
|
| MD5 |
4c748bd69903c44eb8bbc67a60025593
|
|
| BLAKE2b-256 |
73d91ecbb736ac5b9d72bd77d58ab588594b85c0f9a098c3c353e94b77bf3f79
|
File details
Details for the file fastmdui-0.1.3-py3-none-any.whl.
File metadata
- Download URL: fastmdui-0.1.3-py3-none-any.whl
- Upload date:
- Size: 11.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4d122978802b82ae89980a856d7992a69dd25caf62907c3a6518dd48eec224d4
|
|
| MD5 |
6b251b06974519f12d4d93f1fd898e5d
|
|
| BLAKE2b-256 |
e8d41e483c29b869563b285689f46c2c0ac1a47f87a423559bcc784f7474af93
|