pywry.modal¶
Modal dialog definitions and HTML generation.
pywry.modal.Modal
¶
Bases: BaseModel
A modal overlay container with input components.
| ATTRIBUTE | DESCRIPTION |
|---|---|
component_id |
title: Modal header title items: List of input items (Button, Select, TextInput, Div, etc.) size: Preset size ("sm", "md", "lg", "xl", "full") width: Custom width override (e.g., "600px") max_height: Maximum height before scrolling (default: "80vh") overlay_opacity: Background overlay opacity 0.0-1.0 (default: 0.5) close_on_escape: Close when Escape key pressed (default: True) close_on_overlay_click: Close when clicking outside modal (default: True) reset_on_close: Reset form inputs when closed (default: True) on_close_event: Custom event name to emit when modal closes open_on_load: Whether modal starts open (default: False) style: Inline CSS for the modal container script: JS file path or inline string to inject class_name: Custom CSS class for the modal container
TYPE:
|
Example |
Modal( title="User Settings", size="md", class_name="settings-modal", items=[ TextInput(label="Username", event="user:name"), Toggle(label="Notifications", event="user:notifications"), Button(label="Save", event="user:save", variant="primary"), ], reset_on_close=False, # Preserve values between opens on_close_event="settings:closed", )
|
Functions¶
normalize_items
classmethod
¶
normalize_items(v: Any) -> list[ToolbarItem]
Accept list of dicts or ToolbarItem objects.
build_html
¶
Build complete modal HTML.
| RETURNS | DESCRIPTION |
|---|---|
str
|
The modal HTML structure with overlay, container, header, and body. |
collect_scripts
¶
Collect scripts from modal and all nested Div children.
Modal script runs first, then Div scripts in item order.
| RETURNS | DESCRIPTION |
|---|---|
list[str]
|
List of script content strings. |
to_dict
¶
Convert modal to dict for state/serialization.
| RETURNS | DESCRIPTION |
|---|---|
dict
|
Modal configuration as a dictionary. |
get_secret_inputs
¶
get_secret_inputs() -> list[SecretInput]
Get all SecretInput items in this modal (including nested in Divs).
| RETURNS | DESCRIPTION |
|---|---|
list[SecretInput]
|
All SecretInput components found. |
pywry.modal.get_modal_script
¶
Get the modal initialization script.
This script is injected once per page to enable modal functionality.
| RETURNS | DESCRIPTION |
|---|---|
str
|
Complete modal script wrapped in script tags. |
pywry.modal.wrap_content_with_modals
¶
wrap_content_with_modals(_content: str, modals: Sequence[Modal | dict[str, Any]] | None) -> tuple[str, str]
Build modal HTML and scripts to inject into page.
| PARAMETER | DESCRIPTION |
|---|---|
_content
|
The main page content (unused, kept for API symmetry with toolbars).
TYPE:
|
modals
|
List of Modal objects or dicts to render.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
tuple[str, str]
|
A tuple of (modal_html, modal_scripts) to inject into the page. |