From b79b5a2eb527d0e91485b22f7cee39a3588f3dad Mon Sep 17 00:00:00 2001 From: Marek Mihok Date: Fri, 28 Apr 2023 14:59:28 +0200 Subject: [PATCH 1/4] feat: add path attribute to ui.nav_item #1952 --- py/h2o_lightwave/h2o_lightwave/types.py | 10 ++++++++++ py/h2o_lightwave/h2o_lightwave/ui.py | 3 +++ py/h2o_wave/h2o_wave/types.py | 10 ++++++++++ py/h2o_wave/h2o_wave/ui.py | 3 +++ r/R/ui.R | 8 ++++++-- .../main/resources/templates/wave-components.xml | 3 ++- tools/vscode-extension/component-snippets.json | 2 +- ui/src/nav.tsx | 16 +++++++++------- website/widgets/content/navigation.md | 2 ++ 9 files changed, 46 insertions(+), 11 deletions(-) diff --git a/py/h2o_lightwave/h2o_lightwave/types.py b/py/h2o_lightwave/h2o_lightwave/types.py index 3163a256dc..8b71e1945d 100644 --- a/py/h2o_lightwave/h2o_lightwave/types.py +++ b/py/h2o_lightwave/h2o_lightwave/types.py @@ -8700,12 +8700,14 @@ def __init__( icon: Optional[str] = None, disabled: Optional[bool] = None, tooltip: Optional[str] = None, + path: Optional[str] = None, ): _guard_scalar('NavItem.name', name, (str,), True, False, False) _guard_scalar('NavItem.label', label, (str,), False, False, False) _guard_scalar('NavItem.icon', icon, (str,), False, True, False) _guard_scalar('NavItem.disabled', disabled, (bool,), False, True, False) _guard_scalar('NavItem.tooltip', tooltip, (str,), False, True, False) + _guard_scalar('NavItem.path', path, (str,), False, True, False) self.name = name """The name of this item. Prefix the name with a '#' to trigger hash-change navigation.""" self.label = label @@ -8716,6 +8718,8 @@ def __init__( """True if this item should be disabled.""" self.tooltip = tooltip """An optional tooltip message displayed when a user hovers over this item.""" + self.path = path + """The path or URL to link to. If specified, the `name` is ignored. The URL is opened in a new browser window or tab. E.g. `/foo.html` or `http://example.com/foo.html`""" def dump(self) -> Dict: """Returns the contents of this object as a dict.""" @@ -8724,12 +8728,14 @@ def dump(self) -> Dict: _guard_scalar('NavItem.icon', self.icon, (str,), False, True, False) _guard_scalar('NavItem.disabled', self.disabled, (bool,), False, True, False) _guard_scalar('NavItem.tooltip', self.tooltip, (str,), False, True, False) + _guard_scalar('NavItem.path', self.path, (str,), False, True, False) return _dump( name=self.name, label=self.label, icon=self.icon, disabled=self.disabled, tooltip=self.tooltip, + path=self.path, ) @staticmethod @@ -8745,17 +8751,21 @@ def load(__d: Dict) -> 'NavItem': _guard_scalar('NavItem.disabled', __d_disabled, (bool,), False, True, False) __d_tooltip: Any = __d.get('tooltip') _guard_scalar('NavItem.tooltip', __d_tooltip, (str,), False, True, False) + __d_path: Any = __d.get('path') + _guard_scalar('NavItem.path', __d_path, (str,), False, True, False) name: str = __d_name label: str = __d_label icon: Optional[str] = __d_icon disabled: Optional[bool] = __d_disabled tooltip: Optional[str] = __d_tooltip + path: Optional[str] = __d_path return NavItem( name, label, icon, disabled, tooltip, + path, ) diff --git a/py/h2o_lightwave/h2o_lightwave/ui.py b/py/h2o_lightwave/h2o_lightwave/ui.py index 0bc77feeda..fefbbe9644 100644 --- a/py/h2o_lightwave/h2o_lightwave/ui.py +++ b/py/h2o_lightwave/h2o_lightwave/ui.py @@ -3054,6 +3054,7 @@ def nav_item( icon: Optional[str] = None, disabled: Optional[bool] = None, tooltip: Optional[str] = None, + path: Optional[str] = None, ) -> NavItem: """Create a navigation item. @@ -3063,6 +3064,7 @@ def nav_item( icon: An optional icon to display next to the label. disabled: True if this item should be disabled. tooltip: An optional tooltip message displayed when a user hovers over this item. + path: The path or URL to link to. If specified, the `name` is ignored. The URL is opened in a new browser window or tab. E.g. `/foo.html` or `http://example.com/foo.html` Returns: A `h2o_wave.types.NavItem` instance. """ @@ -3072,6 +3074,7 @@ def nav_item( icon, disabled, tooltip, + path, ) diff --git a/py/h2o_wave/h2o_wave/types.py b/py/h2o_wave/h2o_wave/types.py index 3163a256dc..8b71e1945d 100644 --- a/py/h2o_wave/h2o_wave/types.py +++ b/py/h2o_wave/h2o_wave/types.py @@ -8700,12 +8700,14 @@ def __init__( icon: Optional[str] = None, disabled: Optional[bool] = None, tooltip: Optional[str] = None, + path: Optional[str] = None, ): _guard_scalar('NavItem.name', name, (str,), True, False, False) _guard_scalar('NavItem.label', label, (str,), False, False, False) _guard_scalar('NavItem.icon', icon, (str,), False, True, False) _guard_scalar('NavItem.disabled', disabled, (bool,), False, True, False) _guard_scalar('NavItem.tooltip', tooltip, (str,), False, True, False) + _guard_scalar('NavItem.path', path, (str,), False, True, False) self.name = name """The name of this item. Prefix the name with a '#' to trigger hash-change navigation.""" self.label = label @@ -8716,6 +8718,8 @@ def __init__( """True if this item should be disabled.""" self.tooltip = tooltip """An optional tooltip message displayed when a user hovers over this item.""" + self.path = path + """The path or URL to link to. If specified, the `name` is ignored. The URL is opened in a new browser window or tab. E.g. `/foo.html` or `http://example.com/foo.html`""" def dump(self) -> Dict: """Returns the contents of this object as a dict.""" @@ -8724,12 +8728,14 @@ def dump(self) -> Dict: _guard_scalar('NavItem.icon', self.icon, (str,), False, True, False) _guard_scalar('NavItem.disabled', self.disabled, (bool,), False, True, False) _guard_scalar('NavItem.tooltip', self.tooltip, (str,), False, True, False) + _guard_scalar('NavItem.path', self.path, (str,), False, True, False) return _dump( name=self.name, label=self.label, icon=self.icon, disabled=self.disabled, tooltip=self.tooltip, + path=self.path, ) @staticmethod @@ -8745,17 +8751,21 @@ def load(__d: Dict) -> 'NavItem': _guard_scalar('NavItem.disabled', __d_disabled, (bool,), False, True, False) __d_tooltip: Any = __d.get('tooltip') _guard_scalar('NavItem.tooltip', __d_tooltip, (str,), False, True, False) + __d_path: Any = __d.get('path') + _guard_scalar('NavItem.path', __d_path, (str,), False, True, False) name: str = __d_name label: str = __d_label icon: Optional[str] = __d_icon disabled: Optional[bool] = __d_disabled tooltip: Optional[str] = __d_tooltip + path: Optional[str] = __d_path return NavItem( name, label, icon, disabled, tooltip, + path, ) diff --git a/py/h2o_wave/h2o_wave/ui.py b/py/h2o_wave/h2o_wave/ui.py index 0bc77feeda..fefbbe9644 100644 --- a/py/h2o_wave/h2o_wave/ui.py +++ b/py/h2o_wave/h2o_wave/ui.py @@ -3054,6 +3054,7 @@ def nav_item( icon: Optional[str] = None, disabled: Optional[bool] = None, tooltip: Optional[str] = None, + path: Optional[str] = None, ) -> NavItem: """Create a navigation item. @@ -3063,6 +3064,7 @@ def nav_item( icon: An optional icon to display next to the label. disabled: True if this item should be disabled. tooltip: An optional tooltip message displayed when a user hovers over this item. + path: The path or URL to link to. If specified, the `name` is ignored. The URL is opened in a new browser window or tab. E.g. `/foo.html` or `http://example.com/foo.html` Returns: A `h2o_wave.types.NavItem` instance. """ @@ -3072,6 +3074,7 @@ def nav_item( icon, disabled, tooltip, + path, ) diff --git a/r/R/ui.R b/r/R/ui.R index a97b618819..ad8ea86b27 100644 --- a/r/R/ui.R +++ b/r/R/ui.R @@ -3549,6 +3549,7 @@ ui_grid_card <- function( #' @param icon An optional icon to display next to the label. #' @param disabled True if this item should be disabled. #' @param tooltip An optional tooltip message displayed when a user hovers over this item. +#' @param path The path or URL to link to. If specified, the `name` is ignored. The URL is opened in a new browser window or tab. E.g. `/foo.html` or `http://example.com/foo.html` #' @return A NavItem instance. #' @export ui_nav_item <- function( @@ -3556,18 +3557,21 @@ ui_nav_item <- function( label, icon = NULL, disabled = NULL, - tooltip = NULL) { + tooltip = NULL, + path = NULL) { .guard_scalar("name", "character", name) .guard_scalar("label", "character", label) .guard_scalar("icon", "character", icon) .guard_scalar("disabled", "logical", disabled) .guard_scalar("tooltip", "character", tooltip) + .guard_scalar("path", "character", path) .o <- list( name=name, label=label, icon=icon, disabled=disabled, - tooltip=tooltip) + tooltip=tooltip, + path=path) class(.o) <- append(class(.o), c(.wave_obj, "WaveNavItem")) 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 9e1276048b..6cd85094fb 100644 --- a/tools/intellij-plugin/src/main/resources/templates/wave-components.xml +++ b/tools/intellij-plugin/src/main/resources/templates/wave-components.xml @@ -1733,12 +1733,13 @@