1
"""Bootstrap inspired Alerts
2

3
See https://getbootstrap.com/docs/4.0/components/alerts/
4
"""
5 2
import param
6

7 2
from panel.pane.markup import Markdown
8

9 2
ALERT_TYPES = ["primary", "secondary", "success", "danger", "warning", "info", "light", "dark"]
10

11

12 2
class Alert(Markdown):
13
    """
14
    An Alert that renders Markdown
15

16
    - CSS Styling is done via the classes `alert` and `alert-TYPE`, where TYPE is the alert_type.
17
    - sizing_mode is set to `stretch_width` by default
18
    """
19

20 2
    alert_type = param.ObjectSelector("primary", objects=ALERT_TYPES)
21

22 2
    @classmethod
23
    def applies(cls, obj):
24 2
        priority = Markdown.applies(obj)
25 2
        return 0 if priority else False
26

27 2
    def __init__(self, object=None, **params):
28 2
        if "margin" not in params:
29 2
            params["margin"] = (0, 0, 25, 0)
30 2
        if "sizing_mode" not in params:
31 2
            params["sizing_mode"] = "stretch_width"
32 2
        super().__init__(object, **params)
33 2
        self._set_css_classes()
34

35 2
    @param.depends("alert_type", watch=True)
36
    def _set_css_classes(self):
37 2
        css_classes = []
38 2
        if self.css_classes:
39 2
            for class_ in self.css_classes:
40 2
                if class_ != "alert" and not class_.startswith("alert-"):
41 2
                    css_classes.append(class_)
42

43 2
        css_classes.append("alert")
44 2
        css_classes.append(f"alert-{self.alert_type}")
45

46 2
        self.css_classes = css_classes

Read our documentation on viewing source code .

Loading