A reactive notebook for Python — run reproducible experiments, query with SQL, execute as a script, deploy as an app, and version with git. Stored as pure Python. All in a modern, AI-native editor.
Python artificial-intelligencedagdata-sciencedata-visualizationdataflowdeveloper-toolsmachine-learningnotebookspipelinepythonreactivesqlweb-app
feat: supports tooltips with data-tooltip attribute (#2086)
Myles Scolnick31539d82a60c
diff --git a/docs/api/markdown.md b/docs/api/markdown.mdindex 0df2c09d4a..ef451f52d7 100644--- a/docs/api/markdown.md+++ b/docs/api/markdown.md@@ -15,3 +15,18 @@ You can render icons from [Iconify](https://icon-sets.iconify.design/) with `mo.```{eval-rst}.. autofunction:: marimo.icon```++## Tooltips++You can render a tooltip by adding the `data-tooltip` attribute to an element.++```python+mo.md(+ '''+ <div data-tooltip="This is a tooltip">Hover over me</div>+ '''+)+mo.ui.button(+ label='<div data-tooltip="This is a tooltip">Hover over me</div>'+)+```diff --git a/frontend/src/core/islands/islands.css b/frontend/src/core/islands/islands.cssindex 44a5296ce7..3277270fe6 100644--- a/frontend/src/core/islands/islands.css+++ b/frontend/src/core/islands/islands.css@@ -4,6 +4,7 @@@import url("../../css/katex.min.css");@import url("../../css/table.css");@import url("../../css/md.css");+@import url("../../css/md-tooltip.css");.marimo {@apply bg-background text-foreground;diff --git a/frontend/src/css/index.css b/frontend/src/css/index.cssindex 470e9ebefa..da4a70a7db 100644--- a/frontend/src/css/index.css+++ b/frontend/src/css/index.css@@ -4,5 +4,6 @@@import url("./katex-fonts.css");@import url("./katex.min.css");@import url("./md.css");+@import url("./md-tooltip.css");@import url("./admonition.css");@import url("./table.css");diff --git a/frontend/src/css/md-tooltip.css b/frontend/src/css/md-tooltip.cssnew file mode 100644index 0000000000..6ae900ebee--- /dev/null+++ b/frontend/src/css/md-tooltip.css@@ -0,0 +1,50 @@+/*+ This allows you to create a basic tooltip using the data-tooltip attribute+ e.g. <span data-tooltip="Hello, World!">Hover me</span>+*/++.markdown {+ [data-tooltip] {+ position: relative;+ cursor: pointer;+ text-decoration: underline dotted;+ }++ [data-tooltip]::before,+ [data-tooltip]::after {+ visibility: hidden;+ opacity: 0;+ pointer-events: none;+ transition: all 0.2s ease;+ position: absolute;+ z-index: 1000;+ left: 50%;+ transform: translateX(-50%);+ }++ [data-tooltip]::before {+ content: attr(data-tooltip);+ bottom: calc(100% + 10px);+ padding: 5px 10px;+ width: max-content;+ max-width: 300px;+ border-radius: 6px;+ background-color: ;+ text-align: center;+ line-height: 1.4;+ white-space: pre-wrap;++ @apply bg-background text-foreground shadow-md border text-base;+ }++ [data-tooltip]:hover::before,+ [data-tooltip]:hover::after {+ visibility: visible;+ opacity: 1;+ }++ [data-tooltip]:hover::before {+ /* stylelint-disable-next-line unit-allowed-list */+ transform: translateX(-50%) translateY(10px);+ }+}diff --git a/marimo/_smoke_tests/tooltips.py b/marimo/_smoke_tests/tooltips.pynew file mode 100644index 0000000000..4c984a04b1--- /dev/null+++ b/marimo/_smoke_tests/tooltips.py@@ -0,0 +1,37 @@+import marimo++__generated_with = "0.8.0"+app = marimo.App(width="medium")+++def __():+ import marimo as mo+ return mo,+++def __(mo):+ mo.md(+ """+ # Tooltips++ <span data-tooltip="Hello world!">Hover me</span>+ """+ )+ return+++def __(mo):+ mo.ui.button(label="<span data-tooltip='I said dont press'>Don't press</span>")+ return+++def __():+ return+++if __name__ == "__main__":+ app.run()diff --git a/scripts/analyze_traces.py b/scripts/analyze_traces.pyindex e87da98022..0d9cc0a155 100644--- a/scripts/analyze_traces.py+++ b/scripts/analyze_traces.py@@ -149,7 +149,15 @@ def __(Dict, List, Span, json):@app.cell-def __(os, parse_jsonl, populate_depth):+def __(mo):+ refresh = mo.ui.refresh(options=[2, 5, 10], default_interval=5)+ refresh+ return refresh,+++def __(os, parse_jsonl, populate_depth, refresh):+ refreshfile_path = "~/.marimo/traces/spans.jsonl"spans = parse_jsonl(os.path.expanduser(file_path))spans = populate_depth(spans)@@ -198,6 +206,12 @@ def __(spans, spans_to_dataframe):return df,+def __(df):+ df[["name", "duration_ms"]]+ return++@app.cell(hide_code=True)def __(spans):total_duration = (