Creates an HTML button element.
Args:
class_name (str): The class name for the button.
text (str): The text content of the button.
onclick_handler (str, optional): The JavaScript function to call on click.
name (str, optional): The name of the button.
attrs (dict): Additional attributes for the button.
Returns:
An HTML button element with the specified attributes and text.
Source code in zenaura/ui/common.py
| def Button(class_name, text, onclick_handler=None, name=None, attrs={}):
"""
Creates an HTML button element.
Args:
class_name (str): The class name for the button.
text (str): The text content of the button.
onclick_handler (str, optional): The JavaScript function to call on click.
name (str, optional): The name of the button.
attrs (dict): Additional attributes for the button.
Returns:
An HTML button element with the specified attributes and text.
"""
builder = Builder('button').with_attribute('class', class_name).with_text(text)
if onclick_handler:
builder = builder.with_attribute('py-click', onclick_handler)
if name:
builder = builder.with_attribute("name", name)
return builder.with_attributes(**attrs).build()
|