Coverage for src / lexigram / ui / molecules / error_state.py: 100%

12 statements  

« prev     ^ index     » next       coverage.py v7.13.5, created at 2026-08-10 04:11 +0800

1from __future__ import annotations 

2 

3from typing import Any 

4 

5from lexigram.ui.core.base import Component, el 

6 

7 

8class ErrorState(Component): 

9 """Error state component for when something goes wrong. 

10 

11 Args: 

12 title: Error heading 

13 message: Error description 

14 action: Optional retry button/link 

15 """ 

16 

17 def __init__( 

18 self, 

19 title: str = "Something went wrong", 

20 message: str = "We encountered an error loading this data.", 

21 action: Any = None, 

22 **props, 

23 ) -> None: 

24 super().__init__(title=title, message=message, action=action, **props) 

25 self.title = title 

26 self.message = message 

27 self.action = action 

28 

29 def render(self) -> Any: 

30 from lexigram.ui.atoms.icons import get_icon 

31 

32 return el( 

33 "div", 

34 el( 

35 "div", 

36 el( 

37 "div", 

38 get_icon( 

39 "alert-circle", class_name="w-16 h-16 text-destructive" 

40 ), 

41 class_="mb-4", 

42 aria_hidden="true", 

43 ), 

44 el( 

45 "h3", 

46 self.title, 

47 class_="text-lg font-semibold text-foreground mb-2", 

48 ), 

49 el( 

50 "p", 

51 self.message, 

52 class_="text-sm text-muted-foreground mb-4", 

53 ), 

54 self.action if self.action else "", 

55 class_="flex flex-col items-center justify-center text-center", 

56 ), 

57 class_="py-16 px-4 bg-destructive/10 border border-destructive/30 rounded-lg", 

58 role="alert", 

59 )