Spaces:
Running
Running
File size: 1,437 Bytes
8e04495 d8d6fe1 8e04495 |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
import mesop as me
@me.stateclass
class FeedbackState:
feedback: str = ""
reason: str = ""
ask_reason: bool = False
def on_feedback(isup: bool):
state = me.state(FeedbackState)
state.feedback = "Thumbs up!" if isup else "Thumbs down!"
state.ask_reason = not isup
def on_reason_input(e: me.InputEvent):
state = me.state(FeedbackState)
state.reason = e.value
def load(e: me.LoadEvent):
me.set_theme_mode("system")
@me.page(
on_load=load,
security_policy=me.SecurityPolicy(
allowed_iframe_parents=["https://mesop-dev.github.io"]
),
path="/feedback",
)
def feedback_page():
state = me.state(FeedbackState)
with me.box(style=me.Style(margin=me.Margin.all(15))):
me.text("Provide your feedback:", type="headline-5")
with me.box(style=me.Style(display="flex", flex_direction="row", gap=20)):
with me.content_button(type="icon", on_click=lambda _: on_feedback(True)):
me.icon("thumb_up")
with me.content_button(
type="icon", on_click=lambda _: on_feedback(False)
):
me.icon("thumb_down")
if state.ask_reason:
with me.box(style=me.Style(margin=me.Margin(top=15))):
me.textarea(label="Tell us why", on_input=on_reason_input)
if state.feedback:
with me.box(style=me.Style(margin=me.Margin(top=15))):
me.text(f"\n\nFeedback : {state.feedback}")
if state.reason:
me.text(f"Reason : {state.reason}")
|