duck.html.components.select

Select HTML Component.

This module provides reusable Select and Option components for creating dropdown menus in HTML.

Module Contents

Classes

Option

Represents an individual option within a Select dropdown.

Select

A reusable HTML <select> component for creating dropdown menus.

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.InnerComponent

Represents an individual option within a Select dropdown.

This component is used to define selectable items inside a Select component.

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.

get_element()[source]

Returns the HTML tag for the component.

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.InnerComponent

A 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 Theme class.

  • 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.

get_element()[source]

Returns the HTML tag for the component.

on_create()[source]

Initializes the component with default styles and options.