vibe.web.htmx

HTMX utilities for out-of-band swaps.

This module provides utilities for creating HTMX out-of-band (OOB) swap elements, consolidating the patterns used throughout the web interface.

OOBSwap

Represents an HTMX out-of-band swap element.

OOB swaps allow updating multiple page elements in a single response, independent of the main content being swapped.

Attributes:
  • target_id (str | None) –

    The element ID to swap content into (or None for selector-based swap)

  • swap_method (str) –

    The swap method (e.g., "innerHTML", "outerHTML", "innerHTML:#selector")

  • content (str) –

    The HTML content to swap in

  • css_class (str | None) –

    Optional CSS class to add to the wrapper div

  • style (str | None) –

    Optional inline style for the wrapper div

render

render() -> str

Render the OOB swap as an HTML div element.

Returns:
  • str

    HTML string for the OOB swap element

render_oob_div

render_oob_div(element_id: str | None, swap: str, content: str = '', *, css_class: str | None = None, style: str | None = None) -> str

Render a generic HTMX out-of-band swap div.

This is a convenience function that creates an OOBSwap and renders it.

Parameters:
  • element_id (str | None) –

    The element ID to swap into (or None for selector-based swap)

  • swap (str) –

    The swap method (e.g., "innerHTML", "outerHTML")

  • content (str, default: '' ) –

    The HTML content to swap in

  • css_class (str | None, default: None ) –

    Optional CSS class for the wrapper div

  • style (str | None, default: None ) –

    Optional inline style for the wrapper div

Returns:
  • str

    Rendered HTML string for the OOB swap element

render_oob_swaps

render_oob_swaps(swaps: list[OOBSwap]) -> str

Render multiple OOB swaps as a combined HTML string.

Parameters:
  • swaps (list[OOBSwap]) –

    List of OOBSwap objects to render

Returns:
  • str

    Combined HTML string with all OOB swap elements