Skip to content
This repository has been archived by the owner on Aug 15, 2024. It is now read-only.

Commit

Permalink
fix input example
Browse files Browse the repository at this point in the history
  • Loading branch information
renardeinside committed Jun 11, 2024
1 parent 7e01568 commit c606416
Show file tree
Hide file tree
Showing 2 changed files with 14 additions and 8 deletions.
18 changes: 12 additions & 6 deletions examples/io.py → examples/inputs.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,33 +5,39 @@
from schorle.component import component
from schorle.element import button, div, h2, input_
from schorle.signal import Signal
from schorle.store import Depends, store
from schorle.text import text
from schorle.theme import Theme

app = Schorle(title="Schorle | IO Examples", theme=Theme.DARK)


@component(state=Signal.factory(""))
def simple_input(state: Signal[str]):
@store(scope="component")
def text_input():
return Signal("")


@component()
def simple_input(state: Signal[str] = Depends(text_input)):
input_(
type="text",
placeholder="Enter your name",
bind=Bind("value", state),
classes="input input-primary w-full",
)
with div(classes="text-center m-2"):
text(f"Hello, {state.val}!") if state.val else text("Hello, stranger!")
text(f"Hello, {state()}!") if state() else text("Hello, stranger!")


@component(state=Signal.factory(""), classes="flex justify-around")
def clearable_input(state: Signal[str]):
@component(classes="flex justify-around")
def clearable_input(state: Signal[str] = Depends(text_input)):
input_(
type="text",
placeholder="Enter something here",
bind=Bind("value", state),
classes="input input-primary",
)
with button(on=On("click", state.lazy("")), classes="btn btn-primary"):
with button(on=On("click", state.partial("")), classes="btn btn-primary"):
text("Clear")


Expand Down
4 changes: 2 additions & 2 deletions src/python/schorle/rendering_context.py
Original file line number Diff line number Diff line change
Expand Up @@ -78,9 +78,9 @@ def covert_proto_to_lxml(self, proto: ElementPrototype) -> LXMLElement:
if proto.bind:

async def _handler(new_value: str):
await proto.bind.reactive.set(new_value)
await proto.bind.reactive.update(new_value)

Check warning on line 81 in src/python/schorle/rendering_context.py

View check run for this annotation

Codecov / codecov/patch

src/python/schorle/rendering_context.py#L81

Added line #L81 was not covered by tests

lxml_element.set(proto.bind.property, proto.bind.reactive.val)
lxml_element.set(proto.bind.property, proto.bind.reactive())

Check warning on line 83 in src/python/schorle/rendering_context.py

View check run for this annotation

Codecov / codecov/patch

src/python/schorle/rendering_context.py#L83

Added line #L83 was not covered by tests
_on = On(event="input", handler=_handler)
handler_uuid = self.session.register_handler(_handler)
handlers.append({"event": _on.event, "handler": handler_uuid})
Expand Down

0 comments on commit c606416

Please sign in to comment.