|
@@ -6,7 +6,7 @@ from .. import context
|
|
from ..element import Element
|
|
from ..element import Element
|
|
|
|
|
|
|
|
|
|
-class Query(Element, component='query.js'):
|
|
|
|
|
|
+class QueryElement(Element, component='query.js'):
|
|
|
|
|
|
def __init__(self, selector: str) -> None:
|
|
def __init__(self, selector: str) -> None:
|
|
super().__init__()
|
|
super().__init__()
|
|
@@ -53,16 +53,62 @@ class Query(Element, component='query.js'):
|
|
return self
|
|
return self
|
|
|
|
|
|
|
|
|
|
-def query(selector: str) -> Query:
|
|
|
|
- """Query Selector
|
|
|
|
|
|
+class Query:
|
|
|
|
|
|
- To manipulate elements like the document body, you can use the `ui.query` function.
|
|
|
|
- With the query result you can add classes, styles, and attributes like with every other UI element.
|
|
|
|
- This can be useful for example to change the background color of the page (e.g. `ui.query('body').classes('bg-green')`).
|
|
|
|
|
|
+ def __init__(self, selector: str) -> None:
|
|
|
|
+ """Query Selector
|
|
|
|
+
|
|
|
|
+ To manipulate elements like the document body, you can use the `ui.query` function.
|
|
|
|
+ With the query result you can add classes, styles, and attributes like with every other UI element.
|
|
|
|
+ This can be useful for example to change the background color of the page (e.g. `ui.query('body').classes('bg-green')`).
|
|
|
|
+
|
|
|
|
+ :param selector: the CSS selector (e.g. "body", "#my-id", ".my-class", "div > p")
|
|
|
|
+ """
|
|
|
|
+ for element in context.get_client().elements.values():
|
|
|
|
+ if isinstance(element, QueryElement) and element._props['selector'] == selector: # pylint: disable=protected-access
|
|
|
|
+ self.element = element
|
|
|
|
+ break
|
|
|
|
+ else:
|
|
|
|
+ self.element = QueryElement(selector)
|
|
|
|
+
|
|
|
|
+ def classes(self, add: Optional[str] = None, *, remove: Optional[str] = None, replace: Optional[str] = None) \
|
|
|
|
+ -> Self:
|
|
|
|
+ """Apply, remove, or replace HTML classes.
|
|
|
|
|
|
- :param selector: the CSS selector (e.g. "body", "#my-id", ".my-class", "div > p")
|
|
|
|
- """
|
|
|
|
- for element in context.get_client().elements.values():
|
|
|
|
- if isinstance(element, Query) and element._props['selector'] == selector: # pylint: disable=protected-access
|
|
|
|
- return element
|
|
|
|
- return Query(selector)
|
|
|
|
|
|
+ This allows modifying the look of the element or its layout using `Tailwind <https://tailwindcss.com/>`_ or `Quasar <https://quasar.dev/>`_ classes.
|
|
|
|
+
|
|
|
|
+ Removing or replacing classes can be helpful if predefined classes are not desired.
|
|
|
|
+
|
|
|
|
+ :param add: whitespace-delimited string of classes
|
|
|
|
+ :param remove: whitespace-delimited string of classes to remove from the element
|
|
|
|
+ :param replace: whitespace-delimited string of classes to use instead of existing ones
|
|
|
|
+ """
|
|
|
|
+ self.element.classes(add, remove=remove, replace=replace)
|
|
|
|
+ return self
|
|
|
|
+
|
|
|
|
+ def style(self, add: Optional[str] = None, *, remove: Optional[str] = None, replace: Optional[str] = None) \
|
|
|
|
+ -> Self:
|
|
|
|
+ """Apply, remove, or replace CSS definitions.
|
|
|
|
+
|
|
|
|
+ Removing or replacing styles can be helpful if the predefined style is not desired.
|
|
|
|
+
|
|
|
|
+ :param add: semicolon-separated list of styles to add to the element
|
|
|
|
+ :param remove: semicolon-separated list of styles to remove from the element
|
|
|
|
+ :param replace: semicolon-separated list of styles to use instead of existing ones
|
|
|
|
+ """
|
|
|
|
+ self.element.style(add, remove=remove, replace=replace)
|
|
|
|
+ return self
|
|
|
|
+
|
|
|
|
+ def props(self, add: Optional[str] = None, *, remove: Optional[str] = None) -> Self:
|
|
|
|
+ """Add or remove props.
|
|
|
|
+
|
|
|
|
+ This allows modifying the look of the element or its layout using `Quasar <https://quasar.dev/>`_ props.
|
|
|
|
+ Since props are simply applied as HTML attributes, they can be used with any HTML element.
|
|
|
|
+
|
|
|
|
+ Boolean properties are assumed ``True`` if no value is specified.
|
|
|
|
+
|
|
|
|
+ :param add: whitespace-delimited list of either boolean values or key=value pair to add
|
|
|
|
+ :param remove: whitespace-delimited list of property keys to remove
|
|
|
|
+ """
|
|
|
|
+ self.element.props(add, remove=remove)
|
|
|
|
+ return self
|