ui.element

Element

Represents an HTML element. This class is used to create HTML elements.

It is possible to create a custom element by subclassing this class.

Content of any element will be escaped by default. If you want to render

the content as HTML, you can use the ui.html(content="<div>html content</div>") element.

The rendering of the element is done by calling the render method.

If some work needs to be done before or after rendering, the before_render

and after_render methods can be overridden.

The element attributes can be accessed and modified through the attributes property.

The content of an attribute can either be a string or a callable that returns a string.

Example:

:type tag: str

:type content: str, optional

:type render_html: bool, optional

:type oob: bool, optional

:type kwargs: dict[str, str], optional

from uiwiz import ui

ui.element("h1", "Hello World")

Hello World

Constructor

tag: Literal= div
content: str=
render_html: bool= True
oob: bool= False
kwargs: OptionalNo default required argument

Methods

after_render(html: str) -> str
This method is called after the element is rendered.
:param html: The rendered HTML of the element.
before_render() -> Any
This method is called before the element is rendered.
classes(input: str) -> Self
Set tailwind classes for the element.
:param input: The tailwind classes to apply to the element.
:return: The current instance of the element.
get_classes() -> str
Get html classes of the element.
:return: The classes of the element.
:type: str
render(render_script: bool) -> str
Render the element as HTML.
:param render_script: If any element has a javascript script, it will be rendered as well.
:type render_script: bool
size(size: Literal) -> Self
Set the size of the element.
:param size: The size of the element.
:return: The current instance of the element.
GitHub