Skip to content

Commit

Permalink
Include tooltip() and popover() in express (#949)
Browse files Browse the repository at this point in the history
  • Loading branch information
cpsievert authored Jan 3, 2024
1 parent 3787c01 commit a821c38
Show file tree
Hide file tree
Showing 2 changed files with 91 additions and 2 deletions.
6 changes: 4 additions & 2 deletions shiny/express/ui/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,8 @@
panel_conditional,
panel_fixed,
panel_absolute,
tooltip,
popover,
)

from ._page import (
Expand Down Expand Up @@ -269,6 +271,8 @@
"panel_conditional",
"panel_fixed",
"panel_absolute",
"popover",
"tooltip",
# Imports from ._page
"page_opts",
)
Expand All @@ -294,11 +298,9 @@
"panel_main", # Deprecated
"panel_sidebar", # Deprecated
"panel_title",
"popover",
"showcase_bottom",
"showcase_left_center",
"showcase_top_right",
"tooltip",
),
# Items from shiny.express.ui that don't have a counterpart in shiny.ui
"shiny.express.ui": ("page_opts",),
Expand Down
87 changes: 87 additions & 0 deletions shiny/express/ui/_cm_components.py
Original file line number Diff line number Diff line change
Expand Up @@ -1400,3 +1400,90 @@ def panel_absolute(
**kwargs,
),
)


# ======================================================================================
# Tooltips and popovers
# ======================================================================================


def tooltip(
*,
id: Optional[str] = None,
placement: Literal["auto", "top", "right", "bottom", "left"] = "auto",
options: Optional[dict[str, object]] = None,
**kwargs: TagAttrValue,
) -> RecallContextManager[Tag]:
"""
Context manager for a tooltip
This function wraps :func:`~shiny.ui.tooltip`.
Display additional information when focusing (or hovering over) a UI element.
Parameters
----------
id
A character string. Required to reactively respond to the visibility of the
tooltip (via the `input[id]` value) and/or update the visibility/contents of the
tooltip.
placement
The placement of the tooltip relative to its trigger.
options
A list of additional [Bootstrap
options](https://getbootstrap.com/docs/5.3/components/tooltips/#options).
"""

return RecallContextManager(
ui.tooltip,
kwargs=dict(
id=id,
placement=placement,
options=options,
**kwargs,
),
)


def popover(
*,
title: Optional[TagChild] = None,
id: Optional[str] = None,
placement: Literal["auto", "top", "right", "bottom", "left"] = "auto",
options: Optional[dict[str, object]] = None,
**kwargs: TagAttrValue,
) -> RecallContextManager[Tag]:
"""
Context manager for a popover
This function wraps :func:`~shiny.ui.popover`.
Display additional information when clicking on a UI element (typically a
button).
Parameters
----------
title
A title to display in the popover. Can be a character string or UI elements
(i.e., tags).
id
A character string. Required to reactively respond to the visibility of the
popover (via the `input[id]` value) and/or update the visibility/contents of the
popover.
placement
The placement of the popover relative to its trigger.
options
A list of additional [Bootstrap
options](https://getbootstrap.com/docs/5.3/components/popovers/#options).
"""

return RecallContextManager(
ui.popover,
kwargs=dict(
title=title,
id=id,
placement=placement,
options=options,
**kwargs,
),
)

0 comments on commit a821c38

Please sign in to comment.