Skip to content

Commit 750125b

Browse files
authored
Update attributes for upcoming v1 changes (#40)
1 parent e10e113 commit 750125b

1 file changed

Lines changed: 22 additions & 1 deletion

File tree

src/datastar_py/attributes.py

Lines changed: 22 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -157,7 +157,7 @@ def attr(self, attr_dict: Mapping | None = None, /, **attrs: str) -> BaseAttr:
157157

158158
def bind(self, signal_name: str) -> BaseAttr:
159159
"""Set up two-way data binding between a signal and an element's value."""
160-
return BaseAttr("bind", value=signal_name, alias=self._alias)
160+
return BindAttr(value=signal_name, alias=self._alias)
161161

162162
def class_(self, class_dict: Mapping | None = None, /, **classes: str) -> BaseAttr:
163163
"""Add or removes classes to or from an element based on expressions."""
@@ -432,6 +432,21 @@ def self(self) -> Self:
432432
return self
433433

434434

435+
class BindAttr(BaseAttr):
436+
_attr = "bind"
437+
438+
def prop(self, prop: str) -> Self:
439+
"""Bind to a specified property."""
440+
self._mods["prop"] = [prop]
441+
return self
442+
443+
def event(self, event: str | Iterable[str]) -> Self:
444+
"""Only update the signal when the specified events are fired."""
445+
events = [event] if isinstance(event, str) else list(event)
446+
self._mods["event"] = events
447+
return self
448+
449+
435450
class OnAttr(BaseAttr, TimingMod, DelayMod, ViewtransitionMod):
436451
_attr = "on"
437452

@@ -459,6 +474,12 @@ def window(self) -> Self:
459474
self._mods["window"] = []
460475
return self
461476

477+
@property
478+
def document(self) -> Self:
479+
"""Attach the event listener to the document element."""
480+
self._mods["document"] = []
481+
return self
482+
462483
@property
463484
def outside(self) -> Self:
464485
"""Trigger when the event is outside the element."""

0 commit comments

Comments
 (0)