Skip to content

Commit f17e9d1

Browse files
authored
Add data-style support to attribute generator (#11)
1 parent a789aeb commit f17e9d1

File tree

1 file changed

+5
-0
lines changed

1 file changed

+5
-0
lines changed

src/datastar_py/attributes.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -256,6 +256,11 @@ def show(self, expression: str) -> BaseAttr:
256256
"""Show or hides an element based on whether an expression evaluates to true or false."""
257257
return BaseAttr("show", value=expression, alias=self._alias)
258258

259+
def style(self, style_dict: Mapping | None = None, /, **styles: str) -> BaseAttr:
260+
"""Sets the value of inline CSS styles on an element based on an expression, and keeps them in sync."""
261+
styles = {**(style_dict if style_dict else {}), **styles}
262+
return BaseAttr("style", value=_js_object(styles), alias=self._alias)
263+
259264
def text(self, expression: str) -> BaseAttr:
260265
"""Bind the text content of an element to an expression."""
261266
return BaseAttr("text", value=expression, alias=self._alias)

0 commit comments

Comments
 (0)