From e4189f8262203565843a3e0b459b1f1be068884f Mon Sep 17 00:00:00 2001 From: Marek Mihok Date: Wed, 15 Nov 2023 12:31:26 +0100 Subject: [PATCH 1/8] feat: show numberic keyboard on ios devices when input type is number #2170 --- py/h2o_lightwave/h2o_lightwave/types.py | 19 +++++++++++++++++++ py/h2o_lightwave/h2o_lightwave/ui.py | 3 +++ py/h2o_wave/h2o_wave/types.py | 19 +++++++++++++++++++ py/h2o_wave/h2o_wave/ui.py | 3 +++ r/R/ui.R | 9 +++++++-- .../resources/templates/wave-components.xml | 3 ++- .../vscode-extension/component-snippets.json | 2 +- ui/src/index.scss | 2 +- ui/src/textbox.tsx | 7 ++++++- 9 files changed, 61 insertions(+), 6 deletions(-) diff --git a/py/h2o_lightwave/h2o_lightwave/types.py b/py/h2o_lightwave/h2o_lightwave/types.py index c7dc22ce29..2f574d9200 100644 --- a/py/h2o_lightwave/h2o_lightwave/types.py +++ b/py/h2o_lightwave/h2o_lightwave/types.py @@ -969,6 +969,15 @@ def load(__d: Dict) -> 'MessageBar': ) +_TextboxType = ['text', 'number', 'tel'] + + +class TextboxType: + TEXT = 'text' + NUMBER = 'number' + TEL = 'tel' + + class Textbox: """Create a text box. @@ -998,6 +1007,7 @@ def __init__( visible: Optional[bool] = None, tooltip: Optional[str] = None, spellcheck: Optional[bool] = None, + type: Optional[str] = None, ): _guard_scalar('Textbox.name', name, (str,), True, False, False) _guard_scalar('Textbox.label', label, (str,), False, True, False) @@ -1019,6 +1029,7 @@ def __init__( _guard_scalar('Textbox.visible', visible, (bool,), False, True, False) _guard_scalar('Textbox.tooltip', tooltip, (str,), False, True, False) _guard_scalar('Textbox.spellcheck', spellcheck, (bool,), False, True, False) + _guard_enum('Textbox.type', type, _TextboxType, True) self.name = name """An identifying name for this component.""" self.label = label @@ -1059,6 +1070,8 @@ def __init__( """An optional tooltip message displayed when a user clicks the help icon to the right of the component.""" self.spellcheck = spellcheck """True if the text may be checked for spelling errors. Defaults to True.""" + self.type = type + """Input type. Defaults to 'text'. One of 'text', 'number', 'tel'. See enum h2o_wave.ui.TextboxType.""" def dump(self) -> Dict: """Returns the contents of this object as a dict.""" @@ -1082,6 +1095,7 @@ def dump(self) -> Dict: _guard_scalar('Textbox.visible', self.visible, (bool,), False, True, False) _guard_scalar('Textbox.tooltip', self.tooltip, (str,), False, True, False) _guard_scalar('Textbox.spellcheck', self.spellcheck, (bool,), False, True, False) + _guard_enum('Textbox.type', self.type, _TextboxType, True) return _dump( name=self.name, label=self.label, @@ -1103,6 +1117,7 @@ def dump(self) -> Dict: visible=self.visible, tooltip=self.tooltip, spellcheck=self.spellcheck, + type=self.type, ) @staticmethod @@ -1148,6 +1163,8 @@ def load(__d: Dict) -> 'Textbox': _guard_scalar('Textbox.tooltip', __d_tooltip, (str,), False, True, False) __d_spellcheck: Any = __d.get('spellcheck') _guard_scalar('Textbox.spellcheck', __d_spellcheck, (bool,), False, True, False) + __d_type: Any = __d.get('type') + _guard_enum('Textbox.type', __d_type, _TextboxType, True) name: str = __d_name label: Optional[str] = __d_label placeholder: Optional[str] = __d_placeholder @@ -1168,6 +1185,7 @@ def load(__d: Dict) -> 'Textbox': visible: Optional[bool] = __d_visible tooltip: Optional[str] = __d_tooltip spellcheck: Optional[bool] = __d_spellcheck + type: Optional[str] = __d_type return Textbox( name, label, @@ -1189,6 +1207,7 @@ def load(__d: Dict) -> 'Textbox': visible, tooltip, spellcheck, + type, ) diff --git a/py/h2o_lightwave/h2o_lightwave/ui.py b/py/h2o_lightwave/h2o_lightwave/ui.py index 89bafb8628..c271c666ff 100644 --- a/py/h2o_lightwave/h2o_lightwave/ui.py +++ b/py/h2o_lightwave/h2o_lightwave/ui.py @@ -398,6 +398,7 @@ def textbox( visible: Optional[bool] = None, tooltip: Optional[str] = None, spellcheck: Optional[bool] = None, + type: Optional[str] = None, ) -> Component: """Create a text box. @@ -426,6 +427,7 @@ def textbox( visible: True if the component should be visible. Defaults to True. tooltip: An optional tooltip message displayed when a user clicks the help icon to the right of the component. spellcheck: True if the text may be checked for spelling errors. Defaults to True. + type: Input type. Defaults to 'text'. One of 'text', 'number', 'tel'. See enum h2o_wave.ui.TextboxType. Returns: A `h2o_wave.types.Textbox` instance. """ @@ -450,6 +452,7 @@ def textbox( visible, tooltip, spellcheck, + type, )) diff --git a/py/h2o_wave/h2o_wave/types.py b/py/h2o_wave/h2o_wave/types.py index c7dc22ce29..2f574d9200 100644 --- a/py/h2o_wave/h2o_wave/types.py +++ b/py/h2o_wave/h2o_wave/types.py @@ -969,6 +969,15 @@ def load(__d: Dict) -> 'MessageBar': ) +_TextboxType = ['text', 'number', 'tel'] + + +class TextboxType: + TEXT = 'text' + NUMBER = 'number' + TEL = 'tel' + + class Textbox: """Create a text box. @@ -998,6 +1007,7 @@ def __init__( visible: Optional[bool] = None, tooltip: Optional[str] = None, spellcheck: Optional[bool] = None, + type: Optional[str] = None, ): _guard_scalar('Textbox.name', name, (str,), True, False, False) _guard_scalar('Textbox.label', label, (str,), False, True, False) @@ -1019,6 +1029,7 @@ def __init__( _guard_scalar('Textbox.visible', visible, (bool,), False, True, False) _guard_scalar('Textbox.tooltip', tooltip, (str,), False, True, False) _guard_scalar('Textbox.spellcheck', spellcheck, (bool,), False, True, False) + _guard_enum('Textbox.type', type, _TextboxType, True) self.name = name """An identifying name for this component.""" self.label = label @@ -1059,6 +1070,8 @@ def __init__( """An optional tooltip message displayed when a user clicks the help icon to the right of the component.""" self.spellcheck = spellcheck """True if the text may be checked for spelling errors. Defaults to True.""" + self.type = type + """Input type. Defaults to 'text'. One of 'text', 'number', 'tel'. See enum h2o_wave.ui.TextboxType.""" def dump(self) -> Dict: """Returns the contents of this object as a dict.""" @@ -1082,6 +1095,7 @@ def dump(self) -> Dict: _guard_scalar('Textbox.visible', self.visible, (bool,), False, True, False) _guard_scalar('Textbox.tooltip', self.tooltip, (str,), False, True, False) _guard_scalar('Textbox.spellcheck', self.spellcheck, (bool,), False, True, False) + _guard_enum('Textbox.type', self.type, _TextboxType, True) return _dump( name=self.name, label=self.label, @@ -1103,6 +1117,7 @@ def dump(self) -> Dict: visible=self.visible, tooltip=self.tooltip, spellcheck=self.spellcheck, + type=self.type, ) @staticmethod @@ -1148,6 +1163,8 @@ def load(__d: Dict) -> 'Textbox': _guard_scalar('Textbox.tooltip', __d_tooltip, (str,), False, True, False) __d_spellcheck: Any = __d.get('spellcheck') _guard_scalar('Textbox.spellcheck', __d_spellcheck, (bool,), False, True, False) + __d_type: Any = __d.get('type') + _guard_enum('Textbox.type', __d_type, _TextboxType, True) name: str = __d_name label: Optional[str] = __d_label placeholder: Optional[str] = __d_placeholder @@ -1168,6 +1185,7 @@ def load(__d: Dict) -> 'Textbox': visible: Optional[bool] = __d_visible tooltip: Optional[str] = __d_tooltip spellcheck: Optional[bool] = __d_spellcheck + type: Optional[str] = __d_type return Textbox( name, label, @@ -1189,6 +1207,7 @@ def load(__d: Dict) -> 'Textbox': visible, tooltip, spellcheck, + type, ) diff --git a/py/h2o_wave/h2o_wave/ui.py b/py/h2o_wave/h2o_wave/ui.py index 89bafb8628..c271c666ff 100644 --- a/py/h2o_wave/h2o_wave/ui.py +++ b/py/h2o_wave/h2o_wave/ui.py @@ -398,6 +398,7 @@ def textbox( visible: Optional[bool] = None, tooltip: Optional[str] = None, spellcheck: Optional[bool] = None, + type: Optional[str] = None, ) -> Component: """Create a text box. @@ -426,6 +427,7 @@ def textbox( visible: True if the component should be visible. Defaults to True. tooltip: An optional tooltip message displayed when a user clicks the help icon to the right of the component. spellcheck: True if the text may be checked for spelling errors. Defaults to True. + type: Input type. Defaults to 'text'. One of 'text', 'number', 'tel'. See enum h2o_wave.ui.TextboxType. Returns: A `h2o_wave.types.Textbox` instance. """ @@ -450,6 +452,7 @@ def textbox( visible, tooltip, spellcheck, + type, )) diff --git a/r/R/ui.R b/r/R/ui.R index d3ae9aa868..73de63d855 100644 --- a/r/R/ui.R +++ b/r/R/ui.R @@ -485,6 +485,8 @@ ui_message_bar <- function( #' @param visible True if the component should be visible. Defaults to True. #' @param tooltip An optional tooltip message displayed when a user clicks the help icon to the right of the component. #' @param spellcheck True if the text may be checked for spelling errors. Defaults to True. +#' @param type Input type. Defaults to 'text'. +#' One of 'text', 'number', 'tel'. See enum h2o_wave.ui.TextboxType. #' @return A Textbox instance. #' @export ui_textbox <- function( @@ -507,7 +509,8 @@ ui_textbox <- function( width = NULL, visible = NULL, tooltip = NULL, - spellcheck = NULL) { + spellcheck = NULL, + type = NULL) { .guard_scalar("name", "character", name) .guard_scalar("label", "character", label) .guard_scalar("placeholder", "character", placeholder) @@ -528,6 +531,7 @@ ui_textbox <- function( .guard_scalar("visible", "logical", visible) .guard_scalar("tooltip", "character", tooltip) .guard_scalar("spellcheck", "logical", spellcheck) + # TODO Validate type .o <- list(textbox=list( name=name, label=label, @@ -548,7 +552,8 @@ ui_textbox <- function( width=width, visible=visible, tooltip=tooltip, - spellcheck=spellcheck)) + spellcheck=spellcheck, + type=type)) class(.o) <- append(class(.o), c(.wave_obj, "WaveComponent")) return(.o) } diff --git a/tools/intellij-plugin/src/main/resources/templates/wave-components.xml b/tools/intellij-plugin/src/main/resources/templates/wave-components.xml index 149e668f93..cbd7a92848 100644 --- a/tools/intellij-plugin/src/main/resources/templates/wave-components.xml +++ b/tools/intellij-plugin/src/main/resources/templates/wave-components.xml @@ -2620,7 +2620,7 @@