duck.html.components.modalยถ

Modal components module.

Module Contentsยถ

Classesยถ

Modal

Modal component with overlay and centered content.

APIยถ

class duck.html.components.modal.Modal(element: Optional[str] = None, properties: Optional[Dict[str, str]] = None, props: Optional[Dict[str, str]] = None, style: Optional[Dict[str, str]] = None, inner_html: Optional[Union[str, str, float]] = None, children: Optional[List[duck.html.components.HtmlComponent]] = None, **kwargs)[source]ยถ

Bases: duck.html.components.container.FlexContainer

Modal component with overlay and centered content.

Parameters:
  • title โ€“ Optional title for the modal dialog.

  • show_close โ€“ Whether to show a close (โ€˜ร—โ€™) button (default: True).

  • open_on_ready โ€“ Whether to open modal instantly after page load. Defaults to False.

  • modal_props โ€“ Props for the modal content container (optional).

  • modal_style โ€“ Style for the content container (optional).

  • children โ€“ List of child components (modal body).

  • **kwargs โ€“ Extra arguments passed to the overlay.

Example:

from duck.html.components.label import Label

modal = Modal(title="Test modal", open_on_ready=True) # `open_on_ready` will open modal instantly on page load
modal.set_content(Label(color="blue", text="Some Content"))

Initialization

Initialize an HTML component.

Parameters:
  • element โ€“ The HTML element tag name (e.g., textarea, input, button). Can be None, but make sure element is returned by get_element method.

  • accept_inner_html โ€“ Whether the HTML component accepts an inner body (e.g., inner-body-here).

  • inner_html โ€“ Inner html to add to the HTML component. Defaults to None.

  • properties โ€“ Dictionary for properties to initialize the component with.

  • props โ€“ Just same as properties argument (added for simplicity).

  • style โ€“ Dictionary for style to initialize the component with.

  • **kwargs โ€“ Extra keyword arguments

Raises:

HtmlComponentError โ€“ If โ€˜elementโ€™ is not a string or โ€˜inner_htmlโ€™ is set but โ€˜accept_inner_htmlโ€™ is False.

add_child(child)[source]ยถ
on_create()[source]ยถ
set_content(content: duck.html.components.Component)[source]ยถ

Set modal content.