From 394798e4b467d55c52002afb9b81b687293e7b08 Mon Sep 17 00:00:00 2001 From: Will Chen Date: Mon, 18 Dec 2023 11:44:52 -0800 Subject: [PATCH] Support textarea for input type and clean up variant --- mesop/components/input/e2e/input_app.py | 3 +++ mesop/components/input/input.ng.html | 22 ++++++++++++++++---- mesop/components/input/input.proto | 1 - mesop/components/input/input.py | 27 ++++++++++++++++--------- 4 files changed, 38 insertions(+), 15 deletions(-) diff --git a/mesop/components/input/e2e/input_app.py b/mesop/components/input/e2e/input_app.py index 690c60808..20e797177 100644 --- a/mesop/components/input/e2e/input_app.py +++ b/mesop/components/input/e2e/input_app.py @@ -26,3 +26,6 @@ def app(): s = me.state(State) me.input(label="Basic input", on_input=on_input, key=str(s.checked)) me.text(text=s.input) + + me.input(label="Textarea", type="textarea", on_input=on_input) + me.input(label="Number input", type="number", on_input=on_input) diff --git a/mesop/components/input/input.ng.html b/mesop/components/input/input.ng.html index 2fa466a47..b8173a966 100644 --- a/mesop/components/input/input.ng.html +++ b/mesop/components/input/input.ng.html @@ -1,4 +1,3 @@ -@if(config().getVariantIndex() === 0) { {{config().getLabel()}}{{config().getLabel()}} + @if(config().getType() === "textarea") { + + } @else { + + } -} diff --git a/mesop/components/input/input.proto b/mesop/components/input/input.proto index 6ed578dd4..b2e0a47d7 100644 --- a/mesop/components/input/input.proto +++ b/mesop/components/input/input.proto @@ -21,5 +21,4 @@ message InputType { string hint_label = 15; string label = 16; string on_input_handler_id = 17; - int32 variant_index = 18; } diff --git a/mesop/components/input/input.py b/mesop/components/input/input.py index 7ff94b40e..a49abf190 100644 --- a/mesop/components/input/input.py +++ b/mesop/components/input/input.py @@ -19,7 +19,23 @@ def input( placeholder: str = "", name: str = "", required: bool = False, - type: str = "", + type: Literal[ + "", + "textarea", + "color", + "date", + "datetime-local", + "email", + "month", + "number", + "password", + "search", + "tel", + "text", + "time", + "url", + "week", + ] = "", user_aria_described_by: str = "", value: str = "", readonly: bool = False, @@ -31,7 +47,6 @@ def input( hint_label: str = "", label: str = "", on_input: Callable[[InputEvent], Any] | None = None, - variant: Literal["matInput"] = "matInput", ): """Creates a Input component. @@ -54,7 +69,6 @@ def input( hint_label (str): Text for the form field hint. label (str): on_input (Callable[[InputEvent], Any]|None): [input](https://developer.mozilla.org/en-US/docs/Web/API/HTMLElement/input_event) is a native browser event. - variant (Literal['matInput']): component variations """ insert_component( key=key, @@ -79,12 +93,5 @@ def input( on_input_handler_id=register_event_handler(on_input, event=InputEvent) if on_input else "", - variant_index=_get_variant_index(variant), ), ) - - -def _get_variant_index(variant: str) -> int: - if variant == "matInput": - return 0 - raise Exception("Unexpected variant: " + variant)