Skip to content

Commit a821c38

Browse files
authored
Include tooltip() and popover() in express (#949)
1 parent 3787c01 commit a821c38

File tree

2 files changed

+91
-2
lines changed

2 files changed

+91
-2
lines changed

shiny/express/ui/__init__.py

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -133,6 +133,8 @@
133133
panel_conditional,
134134
panel_fixed,
135135
panel_absolute,
136+
tooltip,
137+
popover,
136138
)
137139

138140
from ._page import (
@@ -269,6 +271,8 @@
269271
"panel_conditional",
270272
"panel_fixed",
271273
"panel_absolute",
274+
"popover",
275+
"tooltip",
272276
# Imports from ._page
273277
"page_opts",
274278
)
@@ -294,11 +298,9 @@
294298
"panel_main", # Deprecated
295299
"panel_sidebar", # Deprecated
296300
"panel_title",
297-
"popover",
298301
"showcase_bottom",
299302
"showcase_left_center",
300303
"showcase_top_right",
301-
"tooltip",
302304
),
303305
# Items from shiny.express.ui that don't have a counterpart in shiny.ui
304306
"shiny.express.ui": ("page_opts",),

shiny/express/ui/_cm_components.py

Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1400,3 +1400,90 @@ def panel_absolute(
14001400
**kwargs,
14011401
),
14021402
)
1403+
1404+
1405+
# ======================================================================================
1406+
# Tooltips and popovers
1407+
# ======================================================================================
1408+
1409+
1410+
def tooltip(
1411+
*,
1412+
id: Optional[str] = None,
1413+
placement: Literal["auto", "top", "right", "bottom", "left"] = "auto",
1414+
options: Optional[dict[str, object]] = None,
1415+
**kwargs: TagAttrValue,
1416+
) -> RecallContextManager[Tag]:
1417+
"""
1418+
Context manager for a tooltip
1419+
1420+
This function wraps :func:`~shiny.ui.tooltip`.
1421+
1422+
Display additional information when focusing (or hovering over) a UI element.
1423+
1424+
Parameters
1425+
----------
1426+
id
1427+
A character string. Required to reactively respond to the visibility of the
1428+
tooltip (via the `input[id]` value) and/or update the visibility/contents of the
1429+
tooltip.
1430+
placement
1431+
The placement of the tooltip relative to its trigger.
1432+
options
1433+
A list of additional [Bootstrap
1434+
options](https://getbootstrap.com/docs/5.3/components/tooltips/#options).
1435+
"""
1436+
1437+
return RecallContextManager(
1438+
ui.tooltip,
1439+
kwargs=dict(
1440+
id=id,
1441+
placement=placement,
1442+
options=options,
1443+
**kwargs,
1444+
),
1445+
)
1446+
1447+
1448+
def popover(
1449+
*,
1450+
title: Optional[TagChild] = None,
1451+
id: Optional[str] = None,
1452+
placement: Literal["auto", "top", "right", "bottom", "left"] = "auto",
1453+
options: Optional[dict[str, object]] = None,
1454+
**kwargs: TagAttrValue,
1455+
) -> RecallContextManager[Tag]:
1456+
"""
1457+
Context manager for a popover
1458+
1459+
This function wraps :func:`~shiny.ui.popover`.
1460+
1461+
Display additional information when clicking on a UI element (typically a
1462+
button).
1463+
1464+
Parameters
1465+
----------
1466+
title
1467+
A title to display in the popover. Can be a character string or UI elements
1468+
(i.e., tags).
1469+
id
1470+
A character string. Required to reactively respond to the visibility of the
1471+
popover (via the `input[id]` value) and/or update the visibility/contents of the
1472+
popover.
1473+
placement
1474+
The placement of the popover relative to its trigger.
1475+
options
1476+
A list of additional [Bootstrap
1477+
options](https://getbootstrap.com/docs/5.3/components/popovers/#options).
1478+
"""
1479+
1480+
return RecallContextManager(
1481+
ui.popover,
1482+
kwargs=dict(
1483+
title=title,
1484+
id=id,
1485+
placement=placement,
1486+
options=options,
1487+
**kwargs,
1488+
),
1489+
)

0 commit comments

Comments
 (0)