Skip to content

Commit d03ff16

Browse files
authored
✨ Add support for duration and delay tippy_props (#18)
1 parent 858b959 commit d03ff16

File tree

2 files changed

+31
-4
lines changed

2 files changed

+31
-4
lines changed

docs/index.md

Lines changed: 10 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -121,10 +121,18 @@ The extension has the following configuration options.
121121
Overrides for the [tippy.js props](https://atomiks.github.io/tippyjs/v6/all-props/) to use, by default:
122122

123123
```python
124-
tippy_props = {"placement": "auto-start", "maxWidth": 500, "interactive": False, "arrow": True}
124+
tippy_props = {"placement": "auto-start", "maxWidth": 500, "interactive": False, "theme": "material", "duration": [200, 100], "delay": [200, 500]}
125125
```
126126

127-
Note, only the `placement`, `maxWidth`, `theme`, and `interactive` props are allowed to be overridden currently.
127+
Note, only the following props are allowed to be overridden currently:
128+
129+
- [placement](https://atomiks.github.io/tippyjs/v6/all-props/#placement)
130+
- [maxWidth](https://atomiks.github.io/tippyjs/v6/all-props/#maxwidth)
131+
- [theme](https://atomiks.github.io/tippyjs/v6/all-props/#theme)
132+
- [interactive](https://atomiks.github.io/tippyjs/v6/all-props/#interactive)
133+
- [delay](https://atomiks.github.io/tippyjs/v6/all-props/#delay)
134+
- [duration](https://atomiks.github.io/tippyjs/v6/all-props/#duration)
135+
128136
:::
129137

130138
:::{confval} tippy_add_class

src/sphinx_tippy.py

Lines changed: 21 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
"""Get rich tool tips in your sphinx documentation!"""
2+
23
from __future__ import annotations
34

45
import json
@@ -125,9 +126,19 @@ def compile_config(app: Sphinx):
125126
props = dict(
126127
{"placement": "auto-start", "maxWidth": 500, "interactive": False}, **updates
127128
)
128-
if set(props.keys()) - {"placement", "maxWidth", "interactive", "theme"}:
129+
130+
supported_properties = {
131+
"placement",
132+
"maxWidth",
133+
"interactive",
134+
"theme",
135+
"delay",
136+
"duration",
137+
}
138+
139+
if set(props.keys()) - supported_properties:
129140
raise ExtensionError(
130-
"tippy_props can only contain keys 'placement', 'maxWidth', 'interactive'"
141+
"tippy_props can only contain keys '%s'" % "', '".join(supported_properties)
131142
)
132143
allowed_placements = {
133144
"auto",
@@ -163,6 +174,14 @@ def compile_config(app: Sphinx):
163174
if not (props["theme"] is None or isinstance(props["theme"], str)):
164175
raise ExtensionError("tippy_props['theme'] must be None or a string")
165176
props["theme"] = f"'{props['theme']}'" if props["theme"] else "null"
177+
if "delay" in props:
178+
if not (props["delay"] is None or isinstance(props["delay"], list)):
179+
raise ExtensionError("tippy_props['delay'] must be None or a list")
180+
props["delay"] = props["delay"] if props["delay"] else "null"
181+
if "duration" in props:
182+
if not (props["duration"] is None or isinstance(props["duration"], list)):
183+
raise ExtensionError("tippy_props['duration'] must be None or a list")
184+
props["duration"] = props["duration"] if props["duration"] else "null"
166185
app.env.tippy_config = TippyConfig( # type: ignore[attr-defined]
167186
props=props,
168187
custom_tips=app.config.tippy_custom_tips,

0 commit comments

Comments
 (0)