Coverage for src / lexigram / ui / molecules / simple_alert.py: 100%
15 statements
« prev ^ index » next coverage.py v7.13.5, created at 2026-08-10 04:11 +0800
« prev ^ index » next coverage.py v7.13.5, created at 2026-08-10 04:11 +0800
1from __future__ import annotations
3from typing import Any
5from lexigram.ui.core.base import Component, el
8class SimpleAlert(Component):
9 """Inline alert component for contextual feedback.
11 Args:
12 message: Alert message
13 type: Alert type (info, success, warning, error)
14 title: Optional alert title
15 """
17 def __init__(
18 self,
19 message: str,
20 alert_type: str = "info",
21 title: str | None = None,
22 **props,
23 ) -> None:
24 super().__init__(message=message, type=alert_type, title=title, **props)
25 self.message = message
26 self.type = alert_type
27 self.title = title
29 def render(self) -> Any:
30 from lexigram.ui.atoms.icons import get_icon
31 from lexigram.ui.styles.tokens import get_alert_classes, get_semantic_icon
33 classes = get_alert_classes(self.type)
34 icon_name = get_semantic_icon(self.type)
36 return el(
37 "div",
38 el(
39 "div",
40 el(
41 "div",
42 get_icon(icon_name, class_name="h-5 w-5"),
43 class_="flex-shrink-0",
44 ),
45 el(
46 "div",
47 el("h3", self.title, class_="text-sm font-medium")
48 if self.title
49 else "",
50 el(
51 "div",
52 self.message,
53 class_=f"text-sm {'mt-2' if self.title else ''}",
54 ),
55 class_="ml-3",
56 ),
57 class_="flex",
58 ),
59 class_=f"rounded-md p-4 border {classes}",
60 role="alert",
61 )