Skip to content

Commit

Permalink
✨ Add support for duration and delay tippy_props (#18)
Browse files Browse the repository at this point in the history
  • Loading branch information
ccoVeille authored Apr 22, 2024
1 parent 858b959 commit d03ff16
Show file tree
Hide file tree
Showing 2 changed files with 31 additions and 4 deletions.
12 changes: 10 additions & 2 deletions docs/index.md
Original file line number Diff line number Diff line change
Expand Up @@ -121,10 +121,18 @@ The extension has the following configuration options.
Overrides for the [tippy.js props](https://atomiks.github.io/tippyjs/v6/all-props/) to use, by default:

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

Note, only the `placement`, `maxWidth`, `theme`, and `interactive` props are allowed to be overridden currently.
Note, only the following props are allowed to be overridden currently:

- [placement](https://atomiks.github.io/tippyjs/v6/all-props/#placement)
- [maxWidth](https://atomiks.github.io/tippyjs/v6/all-props/#maxwidth)
- [theme](https://atomiks.github.io/tippyjs/v6/all-props/#theme)
- [interactive](https://atomiks.github.io/tippyjs/v6/all-props/#interactive)
- [delay](https://atomiks.github.io/tippyjs/v6/all-props/#delay)
- [duration](https://atomiks.github.io/tippyjs/v6/all-props/#duration)

:::

:::{confval} tippy_add_class
Expand Down
23 changes: 21 additions & 2 deletions src/sphinx_tippy.py
Original file line number Diff line number Diff line change
@@ -1,4 +1,5 @@
"""Get rich tool tips in your sphinx documentation!"""

from __future__ import annotations

import json
Expand Down Expand Up @@ -125,9 +126,19 @@ def compile_config(app: Sphinx):
props = dict(
{"placement": "auto-start", "maxWidth": 500, "interactive": False}, **updates
)
if set(props.keys()) - {"placement", "maxWidth", "interactive", "theme"}:

supported_properties = {
"placement",
"maxWidth",
"interactive",
"theme",
"delay",
"duration",
}

if set(props.keys()) - supported_properties:
raise ExtensionError(
"tippy_props can only contain keys 'placement', 'maxWidth', 'interactive'"
"tippy_props can only contain keys '%s'" % "', '".join(supported_properties)
)
allowed_placements = {
"auto",
Expand Down Expand Up @@ -163,6 +174,14 @@ def compile_config(app: Sphinx):
if not (props["theme"] is None or isinstance(props["theme"], str)):
raise ExtensionError("tippy_props['theme'] must be None or a string")
props["theme"] = f"'{props['theme']}'" if props["theme"] else "null"
if "delay" in props:
if not (props["delay"] is None or isinstance(props["delay"], list)):
raise ExtensionError("tippy_props['delay'] must be None or a list")
props["delay"] = props["delay"] if props["delay"] else "null"
if "duration" in props:
if not (props["duration"] is None or isinstance(props["duration"], list)):
raise ExtensionError("tippy_props['duration'] must be None or a list")
props["duration"] = props["duration"] if props["duration"] else "null"
app.env.tippy_config = TippyConfig( # type: ignore[attr-defined]
props=props,
custom_tips=app.config.tippy_custom_tips,
Expand Down

0 comments on commit d03ff16

Please sign in to comment.