duck.html.components.select¶
Select HTML Component.
This module provides reusable Select and Option components for creating dropdown menus in HTML.
Module Contents¶
Classes¶
Represents an individual option within a |
|
A reusable HTML |
API¶
- class duck.html.components.select.Option(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.InnerComponentRepresents an individual option within a
Selectdropdown.This component is used to define selectable items inside a
Selectcomponent.Example Usage:
option = Option(inner_body="Option 1") select.add_child(option)This generates:
<option>Option 1</option>Returns: - An
<option>HTML element.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.
- class duck.html.components.select.Select(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.InnerComponentA reusable HTML
<select>component for creating dropdown menus.This component generates a customizable
<select>dropdown with options.Args: options (list[str], optional): A list of options as text or HTML. Note: The ‘option’ tag should not be included in individual options.
Example Usage:
select = Select( options=[ "Option 1", "Option 2", "Option 3" ] ) component.add_child(select)This generates:
<select> <option>Option 1</option> <option>Option 2</option> <option>Option 3</option> </select>Styling:
Uses default styling based on the
Themeclass.Can be customized using CSS styles.
Returns: - A
<select>HTML element.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.