-
-
Notifications
You must be signed in to change notification settings - Fork 473
/
alert.py
58 lines (41 loc) · 1.69 KB
/
alert.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
"""
Bootstrap inspired Alerts
See https://getbootstrap.com/docs/4.0/components/alerts/
"""
from __future__ import annotations
from typing import Any, ClassVar, Mapping
import param
from panel.pane.markup import Markdown
ALERT_TYPES = ["primary", "secondary", "success", "danger", "warning", "info", "light", "dark"]
class Alert(Markdown):
"""
The `Alert` pane allows providing contextual feedback messages for typical
user actions. The Alert supports markdown strings.
Reference: https://panel.holoviz.org/reference/panes/Alert.html
:Example:
>>> Alert('Some important message', alert_type='warning')
"""
alert_type = param.ObjectSelector("primary", objects=ALERT_TYPES)
priority: ClassVar[float | bool | None] = 0
_rename: ClassVar[Mapping[str, str | None]] = dict(Markdown._rename, alert_type=None)
@classmethod
def applies(cls, obj: Any) -> float | bool | None:
priority = Markdown.applies(obj)
return 0 if priority else False
def __init__(self, object=None, **params):
if "margin" not in params:
params["margin"] = (0, 0, 25, 0)
if "sizing_mode" not in params:
params["sizing_mode"] = "stretch_width"
super().__init__(object, **params)
self._set_css_classes()
@param.depends("alert_type", watch=True)
def _set_css_classes(self):
css_classes = []
if self.css_classes:
for class_ in self.css_classes:
if class_ != "alert" and not class_.startswith("alert-"):
css_classes.append(class_)
css_classes.append("alert")
css_classes.append(f"alert-{self.alert_type}")
self.css_classes = css_classes