From 18990df41ff1cef19c6d0b714d262be3328173d9 Mon Sep 17 00:00:00 2001 From: Khaleel Al-Adhami Date: Tue, 18 Feb 2025 12:45:43 -0800 Subject: [PATCH] add capitalize and title var operations (#4840) --- reflex/components/core/auto_scroll.pyi | 219 ++++++++++++++++++++++--- reflex/vars/sequence.py | 48 ++++++ 2 files changed, 248 insertions(+), 19 deletions(-) diff --git a/reflex/components/core/auto_scroll.pyi b/reflex/components/core/auto_scroll.pyi index 690b11e57..c34ed32d6 100644 --- a/reflex/components/core/auto_scroll.pyi +++ b/reflex/components/core/auto_scroll.pyi @@ -3,7 +3,7 @@ # ------------------- DO NOT EDIT ---------------------- # This file was generated by `reflex/utils/pyi_generator.py`! # ------------------------------------------------------ -from typing import Any, Dict, Optional, Union, overload +from typing import Any, Dict, Literal, Optional, Union, overload from reflex.components.el.elements.typography import Div from reflex.event import EventType @@ -17,30 +17,211 @@ class AutoScroll(Div): def create( # type: ignore cls, *children, - access_key: Optional[Union[Var[Union[bool, int, str]], bool, int, str]] = None, + access_key: Optional[Union[Var[str], str]] = None, auto_capitalize: Optional[ - Union[Var[Union[bool, int, str]], bool, int, str] + Union[ + Literal["characters", "none", "off", "on", "sentences", "words"], + Var[Literal["characters", "none", "off", "on", "sentences", "words"]], + ] ] = None, content_editable: Optional[ - Union[Var[Union[bool, int, str]], bool, int, str] + Union[ + Literal["inherit", "plaintext-only", False, True], + Var[Literal["inherit", "plaintext-only", False, True]], + ] ] = None, - context_menu: Optional[ - Union[Var[Union[bool, int, str]], bool, int, str] - ] = None, - dir: Optional[Union[Var[Union[bool, int, str]], bool, int, str]] = None, - draggable: Optional[Union[Var[Union[bool, int, str]], bool, int, str]] = None, + context_menu: Optional[Union[Var[str], str]] = None, + dir: Optional[Union[Var[str], str]] = None, + draggable: Optional[Union[Var[bool], bool]] = None, enter_key_hint: Optional[ - Union[Var[Union[bool, int, str]], bool, int, str] + Union[ + Literal["done", "enter", "go", "next", "previous", "search", "send"], + Var[ + Literal["done", "enter", "go", "next", "previous", "search", "send"] + ], + ] ] = None, - hidden: Optional[Union[Var[Union[bool, int, str]], bool, int, str]] = None, - input_mode: Optional[Union[Var[Union[bool, int, str]], bool, int, str]] = None, - item_prop: Optional[Union[Var[Union[bool, int, str]], bool, int, str]] = None, - lang: Optional[Union[Var[Union[bool, int, str]], bool, int, str]] = None, - role: Optional[Union[Var[Union[bool, int, str]], bool, int, str]] = None, - slot: Optional[Union[Var[Union[bool, int, str]], bool, int, str]] = None, - spell_check: Optional[Union[Var[Union[bool, int, str]], bool, int, str]] = None, - tab_index: Optional[Union[Var[Union[bool, int, str]], bool, int, str]] = None, - title: Optional[Union[Var[Union[bool, int, str]], bool, int, str]] = None, + hidden: Optional[Union[Var[bool], bool]] = None, + input_mode: Optional[ + Union[ + Literal[ + "decimal", + "email", + "none", + "numeric", + "search", + "tel", + "text", + "url", + ], + Var[ + Literal[ + "decimal", + "email", + "none", + "numeric", + "search", + "tel", + "text", + "url", + ] + ], + ] + ] = None, + item_prop: Optional[Union[Var[str], str]] = None, + lang: Optional[Union[Var[str], str]] = None, + role: Optional[ + Union[ + Literal[ + "alert", + "alertdialog", + "application", + "article", + "banner", + "button", + "cell", + "checkbox", + "columnheader", + "combobox", + "complementary", + "contentinfo", + "definition", + "dialog", + "directory", + "document", + "feed", + "figure", + "form", + "grid", + "gridcell", + "group", + "heading", + "img", + "link", + "list", + "listbox", + "listitem", + "log", + "main", + "marquee", + "math", + "menu", + "menubar", + "menuitem", + "menuitemcheckbox", + "menuitemradio", + "navigation", + "none", + "note", + "option", + "presentation", + "progressbar", + "radio", + "radiogroup", + "region", + "row", + "rowgroup", + "rowheader", + "scrollbar", + "search", + "searchbox", + "separator", + "slider", + "spinbutton", + "status", + "switch", + "tab", + "table", + "tablist", + "tabpanel", + "term", + "textbox", + "timer", + "toolbar", + "tooltip", + "tree", + "treegrid", + "treeitem", + ], + Var[ + Literal[ + "alert", + "alertdialog", + "application", + "article", + "banner", + "button", + "cell", + "checkbox", + "columnheader", + "combobox", + "complementary", + "contentinfo", + "definition", + "dialog", + "directory", + "document", + "feed", + "figure", + "form", + "grid", + "gridcell", + "group", + "heading", + "img", + "link", + "list", + "listbox", + "listitem", + "log", + "main", + "marquee", + "math", + "menu", + "menubar", + "menuitem", + "menuitemcheckbox", + "menuitemradio", + "navigation", + "none", + "note", + "option", + "presentation", + "progressbar", + "radio", + "radiogroup", + "region", + "row", + "rowgroup", + "rowheader", + "scrollbar", + "search", + "searchbox", + "separator", + "slider", + "spinbutton", + "status", + "switch", + "tab", + "table", + "tablist", + "tabpanel", + "term", + "textbox", + "timer", + "toolbar", + "tooltip", + "tree", + "treegrid", + "treeitem", + ] + ], + ] + ] = None, + slot: Optional[Union[Var[str], str]] = None, + spell_check: Optional[Union[Var[bool], bool]] = None, + tab_index: Optional[Union[Var[int], int]] = None, + title: Optional[Union[Var[str], str]] = None, style: Optional[Style] = None, key: Optional[Any] = None, id: Optional[Any] = None, diff --git a/reflex/vars/sequence.py b/reflex/vars/sequence.py index 0e7b082f9..137ce965f 100644 --- a/reflex/vars/sequence.py +++ b/reflex/vars/sequence.py @@ -191,6 +191,22 @@ class StringVar(Var[STRING_TYPE], python_types=str): """ return string_upper_operation(self) + def title(self) -> StringVar: + """Convert the string to title case. + + Returns: + The string title operation. + """ + return string_title_operation(self) + + def capitalize(self) -> StringVar: + """Capitalize the string. + + Returns: + The string capitalize operation. + """ + return string_capitalize_operation(self) + def strip(self) -> StringVar: """Strip the string. @@ -482,6 +498,38 @@ def string_upper_operation(string: StringVar[Any]): return var_operation_return(js_expression=f"{string}.toUpperCase()", var_type=str) +@var_operation +def string_title_operation(string: StringVar[Any]): + """Convert a string to title case. + + Args: + string: The string to convert. + + Returns: + The title case string. + """ + return var_operation_return( + js_expression=f"{string}.split(' ').map(word => word.charAt(0).toUpperCase() + word.slice(1).toLowerCase()).join(' ')", + var_type=str, + ) + + +@var_operation +def string_capitalize_operation(string: StringVar[Any]): + """Capitalize a string. + + Args: + string: The string to capitalize. + + Returns: + The capitalized string. + """ + return var_operation_return( + js_expression=f"(((s) => s.charAt(0).toUpperCase() + s.slice(1).toLowerCase())({string}))", + var_type=str, + ) + + @var_operation def string_strip_operation(string: StringVar[Any]): """Strip a string.