Skip to content

Commit

Permalink
added the tooltips module
Browse files Browse the repository at this point in the history
  • Loading branch information
volfpeter committed Jun 16, 2019
1 parent 659db91 commit 6913e51
Showing 1 changed file with 64 additions and 0 deletions.
64 changes: 64 additions & 0 deletions markyp_bootstrap4/tooltips.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,64 @@
"""
Bootstrap tooltip elements.
See https://getbootstrap.com/docs/4.0/components/tooltips/.
"""

from typing import Optional

from markyp import PropertyDict, PropertyValue
from markyp_html import script


__all__ = ("enable_tooltips", "Placement", "tooltip")


enable_tooltips = script("$(function () { $('[data-toggle=\"tooltip\"]').tooltip() })")
"""
Script element that enables tooltip elements on the page.
See https://getbootstrap.com/docs/4.0/components/tooltips/#example-enable-tooltips-everywhere.
"""


class Placement(object):
"""
Enumeration class that lists tooltip placement options.
"""

TOP = "top"

BOTTOM = "bottom"

LEFT = "left"

RIGHT = "right"


def tooltip(title: str,
*,
placement: str = Placement.TOP,
**kwargs: PropertyValue) -> PropertyDict:
"""
Returns a `PropertyDict` whose items must be added to the element that has the tooltip.
Examples:
```Python
p("Adding", em("tooltips", **tooltip("Hello")), "is pretty easy.")
p("Adding", em("tooltips", **tooltip("Hello", placement=Placement.BOTTOM)), "is pretty easy.")
```
Please see `enable_tooltips` for information on how to enable tooltips.
Keyword arguments not listed in the arguments section will be included in the returned `PropertyDict`.
Arguments:
title: The content of the tooltip.
placement: The desired placement of the tooltip, one of the constants from `Placement`.
"""
kwargs["title"] = title
kwargs["data-toggle"] = "tooltip"
kwargs["data-placement"] = placement
return kwargs

0 comments on commit 6913e51

Please sign in to comment.