duck.html.components.core.propsยถ

Module containing dictionaries for containing HTML props/style.

Module Contentsยถ

Classesยถ

PropertyStore

A dictionary subclass to store properties for HTML components, with certain restrictions.

StyleStore

PropertyStore dictionary for component styling.

APIยถ

class duck.html.components.core.props.PropertyStore(initdict: Optional[Dict[Any, Any]] = None, on_set_item: Optional[Callable] = None, on_delete_item: Optional[Callable] = None)[source]ยถ

Bases: dict

A dictionary subclass to store properties for HTML components, with certain restrictions.

Keys and values must both be strings. Certain methods (pop, popitem, update, setdefault, etc.) are overridden to ensure they utilize the custom setitem and delitem logic, including event hooks for set and delete operations.

Args:

  • *args: Arguments to initialize the dictionary.

  • **kwargs: Keyword arguments to initialize the dictionary.

Initialization

Initialize self. See help(type(self)) for accurate signature.

__delitem__(key: str, call_on_delete_item_handler: bool = True) โ†’ None[source]ยถ

Deletes a key from the property store.

Parameters:
  • key โ€“ The key to delete. Must be a string.

  • call_on_delete_item_handler โ€“ Whether to call on_delete_item after the actual __delitem__.

__repr__() โ†’ str[source]ยถ

Returns a string representation of PropertyStore.

Returns:

String representation of the PropertyStore.

Return type:

str

__setitem__(key: str, value: str, call_on_set_item_handler: bool = True) โ†’ None[source]ยถ

Sets the value for the given key if the key is allowed.

Parameters:
  • key โ€“ The key to set the value for. Must be a string.

  • value โ€“ The value to set. Must be a string.

  • call_on_set_item_handler โ€“ Whether to call on_set_item after the actual __setitem__.

Raises:

AssertionError โ€“ If the key or value is not a string.

__slots__ยถ

(โ€˜__versionโ€™, โ€˜_on_set_item_funcโ€™, โ€˜_on_delete_item_funcโ€™)

_on_delete_item(k)[source]ยถ
_on_set_item(k, v)[source]ยถ
property _version: intยถ
on_delete_item(key: str) โ†’ None[source]ยถ

Called after __delitem__.

Parameters:

key โ€“ The key deleted.

on_set_item(key: str, value: Any) โ†’ None[source]ยถ

Called after __setitem__.

Parameters:
  • key โ€“ The key set.

  • value โ€“ The value set.

pop(key: str, default: Any = None) โ†’ Any[source]ยถ

Removes the specified key and returns its value. If key is not found, default is returned if provided, otherwise KeyError is raised.

Parameters:
  • key โ€“ The key to remove.

  • default โ€“ The value to return if key is not found.

Returns:

The value associated with the key, or default.

Return type:

Any

Raises:

KeyError โ€“ If key is not found and default is not provided.

popitem() โ†’ Tuple[str, str][source]ยถ

Removes and returns a (key, value) pair from the dictionary. Pairs are returned in LIFO order.

Returns:

The removed (key, value) pair.

Return type:

Tuple[str, str]

Raises:

KeyError โ€“ If the dictionary is empty.

setdefault(key: str, default: Optional[str] = None, call_on_set_item_handler: bool = True) โ†’ str[source]ยถ

Inserts key with a value of default if key is not in the dictionary.

Parameters:
  • key โ€“ The key to check.

  • default โ€“ The default value to set if key is missing.

  • call_on_set_item_handler โ€“ Whether to call on_set_item if setting.

Returns:

The value for the key.

Return type:

str

setdefaults(data: Dict[str, str]) โ†’ None[source]ยถ

Calls setdefault on multiple items.

Parameters:

data โ€“ The key-value pairs to set as defaults.

update(data: Any = None, call_on_set_item_handler: bool = True, *args, **kwargs) โ†’ None[source]ยถ

Updates the PropertyStore with the key/value pairs from data, ensuring setitem logic.

Parameters:
  • data โ€“ Mapping or iterable to update from.

  • call_on_set_item_handler โ€“ Whether to call on_set_item for each item.

  • *args โ€“ Additional data.

  • **kwargs โ€“ Additional data.

class duck.html.components.core.props.StyleStore(initdict: Optional[Dict[Any, Any]] = None, on_set_item: Optional[Callable] = None, on_delete_item: Optional[Callable] = None)[source]ยถ

Bases: duck.html.components.core.props.PropertyStore

PropertyStore dictionary for component styling.

Initialization

Initialize self. See help(type(self)) for accurate signature.