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

10 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 Breadcrumbs(Component): 

9 """ 

10 Breadcrumb navigation component with home icon. 

11 

12 Args: 

13 items: List of dicts with 'label' and 'url' 

14 """ 

15 

16 def __init__(self, items: list[dict[str, str]], **props) -> None: 

17 super().__init__(**props) 

18 self.items = items 

19 

20 def render(self) -> Any: 

21 from lexigram.ui.atoms.icons import get_icon 

22 

23 return el( 

24 "nav", 

25 {"class": "flex", "aria-label": "Breadcrumb"}, 

26 el( 

27 "ol", 

28 {"class": "flex items-center space-x-4"}, 

29 # Home Icon 

30 el( 

31 "li", 

32 el( 

33 "div", 

34 el( 

35 "a", 

36 get_icon("home", class_name="h-5 w-5 flex-shrink-0", aria_hidden="true"), 

37 href="/admin", 

38 class_="text-muted-foreground hover:text-foreground transition-colors", 

39 ), 

40 ), 

41 ), 

42 # Breadcrumb Items 

43 *[ 

44 el( 

45 "li", 

46 el( 

47 "div", 

48 {"class": "flex items-center"}, 

49 get_icon( 

50 "chevron-right", 

51 class_name="h-5 w-5 flex-shrink-0 text-muted-foreground", 

52 aria_hidden="true", 

53 ), 

54 el( 

55 "a", 

56 item["label"], 

57 href=item.get("url", "#"), 

58 class_=f"ml-4 text-sm font-medium transition-colors {'text-muted-foreground hover:text-foreground' if i < len(self.items) - 1 else 'text-foreground cursor-default'}", 

59 # Only add hx attributes if it's a link and not the last item 

60 **( 

61 { 

62 "hx_get": item.get("url"), 

63 "hx_target": "#main-content", 

64 "hx_swap": "innerHTML", 

65 "hx_push_url": "true", 

66 } 

67 if i < len(self.items) - 1 and item.get("url") 

68 else {} 

69 ), 

70 ), 

71 ), 

72 ) 

73 for i, item in enumerate(self.items) 

74 ], 

75 ), 

76 )