| name | pythonista-nicegui |
| description | Use when building UI with NiceGUI, creating components, fixing styling issues. Triggers on "nicegui", "quasar", "tailwind", "ui.row", "ui.column", "ui.card", "ui.dialog", "gap", "spacing", "layout", "modal", "component", "styling", "flexbox", "chart", or when creating/editing UI code. |
NiceGUI Development Best Practices
Core Philosophy
Understand the user workflow before building. Same data MUST look the same everywhere. Extract business logic from UI into testable controllers.
Key Points From References
- No threads for UI - Only use asyncio (see ui-architecture.md)
- Three-layer architecture: Data fetching → Controller → UI (see ui-architecture.md)
- Progressive complexity: Simple pages → Controllers → State machines (see ui-architecture.md)
Quick Start
ls src/*/ui/components/
Critical Styling Rules
with ui.row().classes("items-center").style("gap: 0.75rem"):
ui.icon("info")
ui.label("Message")
with ui.card().style("height: 80vh"):
with ui.scroll_area().style("height: 100%"):
ui.label("Content")
with ui.element("div").style("display: flex; width: 100%; gap: 24px"):
with ui.element("div").style("flex: 1; min-width: 0"):
ui.highchart(options)
Controller Pattern
class PageController:
async def handle_task_change(self, new_task: str) -> PageUpdate:
data = await self.fetcher.fetch_data(new_task)
return PageUpdate.refresh_all(data)
async def on_task_change(e):
logger.info(f"User selected task: {e.value}")
update = await controller.handle_task_change(e.value)
apply_ui_update(update)
Component Reuse
class ItemReference:
def __init__(self, item, mode: Literal["LIBRARY", "REFERENCE", "PREVIEW"]):
if mode == "LIBRARY":
elif mode == "REFERENCE":
Modal/Dialog Button Docking
with ui.dialog() as dialog, ui.card().style(
"height: 85vh; display: flex; flex-direction: column;"
):
with ui.scroll_area().style("flex: 1; overflow-y: auto;"):
with ui.element("div").style(
"position: sticky; bottom: 0; padding: 1rem;"
):
with ui.row().classes("justify-end"):
ui.button("Cancel", on_click=dialog.close)
ui.button("Save", on_click=save_handler)
Checklists
Styling Checklist
Component Checklist
Architecture Checklist
Reference Files
Related Skills