teleport.py 806 B

1234567891011121314151617181920212223242526
  1. from typing import Union
  2. from nicegui.element import Element
  3. class Teleport(Element, component='teleport.js'):
  4. def __init__(self, to: Union[str, Element]) -> None:
  5. """Teleport
  6. An element that allows us to transmit the content from within a component to any location on the page.
  7. :param to: NiceGUI element or CSS selector of the target element for the teleported content
  8. """
  9. super().__init__()
  10. if isinstance(to, Element):
  11. to = f'#c{to.id}'
  12. self._props['to'] = to
  13. def update(self) -> None:
  14. """Force the internal content to be retransmitted to the specified location.
  15. This method is usually called after the target container is rebuilt.
  16. """
  17. super().update()
  18. self.run_method('update')