From 53e402f47b8a4f5e5a0b78c6197af7a1bec42689 Mon Sep 17 00:00:00 2001 From: Elijah Ahianyo Date: Mon, 18 Dec 2023 23:43:51 +0000 Subject: [PATCH] Chakra input component type_ prop literal (#2292) --- reflex/components/forms/input.py | 3 +- reflex/components/forms/input.pyi | 56 ++++++++++++++++++++++++++++++- reflex/components/literals.py | 27 +++++++++++++++ 3 files changed, 84 insertions(+), 2 deletions(-) diff --git a/reflex/components/forms/input.py b/reflex/components/forms/input.py index 17f194daa..48f6009fc 100644 --- a/reflex/components/forms/input.py +++ b/reflex/components/forms/input.py @@ -9,6 +9,7 @@ from reflex.components.libs.chakra import ( LiteralButtonSize, LiteralInputVariant, ) +from reflex.components.literals import LiteralInputType from reflex.constants import EventTriggers, MemoizationMode from reflex.utils import imports from reflex.vars import Var @@ -29,7 +30,7 @@ class Input(ChakraComponent): placeholder: Var[str] # The type of input. - type_: Var[str] = "text" # type: ignore + type_: Var[LiteralInputType] = "text" # type: ignore # The border color when the input is invalid. error_border_color: Var[str] diff --git a/reflex/components/forms/input.pyi b/reflex/components/forms/input.pyi index c82deca50..a0266c5a0 100644 --- a/reflex/components/forms/input.pyi +++ b/reflex/components/forms/input.pyi @@ -15,6 +15,7 @@ from reflex.components.libs.chakra import ( LiteralButtonSize, LiteralInputVariant, ) +from reflex.components.literals import LiteralInputType from reflex.constants import EventTriggers, MemoizationMode from reflex.utils import imports from reflex.vars import Var @@ -29,7 +30,60 @@ class Input(ChakraComponent): value: Optional[Union[Var[str], str]] = None, default_value: Optional[Union[Var[str], str]] = None, placeholder: Optional[Union[Var[str], str]] = None, - type_: Optional[Union[Var[str], str]] = None, + type_: Optional[ + Union[ + Var[ + Literal[ + "button", + "checkbox", + "color", + "date", + "datetime-local", + "email", + "file", + "hidden", + "image", + "month", + "number", + "password", + "radio", + "range", + "reset", + "search", + "submit", + "tel", + "text", + "time", + "url", + "week", + ] + ], + Literal[ + "button", + "checkbox", + "color", + "date", + "datetime-local", + "email", + "file", + "hidden", + "image", + "month", + "number", + "password", + "radio", + "range", + "reset", + "search", + "submit", + "tel", + "text", + "time", + "url", + "week", + ], + ] + ] = None, error_border_color: Optional[Union[Var[str], str]] = None, focus_border_color: Optional[Union[Var[str], str]] = None, is_disabled: Optional[Union[Var[bool], bool]] = None, diff --git a/reflex/components/literals.py b/reflex/components/literals.py index d46d1899a..df5e05c3f 100644 --- a/reflex/components/literals.py +++ b/reflex/components/literals.py @@ -2,4 +2,31 @@ from typing import Literal +# Base Literals +LiteralInputType = Literal[ + "button", + "checkbox", + "color", + "date", + "datetime-local", + "email", + "file", + "hidden", + "image", + "month", + "number", + "password", + "radio", + "range", + "reset", + "search", + "submit", + "tel", + "text", + "time", + "url", + "week", +] + + LiteralRowMarker = Literal["none", "number", "checkbox", "both", "clickable-number"]