Coverage for src / lexigram / ui / atoms / icon.py: 100%

20 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.atoms.icons import get_icon 

6from lexigram.ui.core.base import Component 

7 

8 

9class Icon(Component): 

10 """Icon atom that wraps `get_icon` for consistent usage in templates. 

11 

12 Args: 

13 name: icon name (string or raw node) 

14 size: Tailwind size classes for icon (default: 'w-5 h-5') 

15 class_name: extra classes to apply to the icon 

16 aria_hidden: When True (default), marks icon as decorative with aria-hidden="true". 

17 Set to False for meaningful icons and supply an aria_label. 

18 aria_label: Accessible label for meaningful icons (used when aria_hidden=False). 

19 """ 

20 

21 def __init__( 

22 self, 

23 name: str | Any, 

24 size: str = "w-5 h-5", 

25 class_name: str = "", 

26 aria_hidden: bool = True, 

27 aria_label: str | None = None, 

28 **props, 

29 ) -> None: 

30 super().__init__(name=name, size=size, class_name=class_name, **props) 

31 self.name = name 

32 self.size = size 

33 self.class_name = class_name 

34 self.aria_hidden = aria_hidden 

35 self.aria_label = aria_label 

36 self.props = props 

37 

38 def render(self) -> Any: 

39 extra: dict[str, Any] = {} 

40 if self.aria_hidden: 

41 extra["aria_hidden"] = "true" 

42 elif self.aria_label is not None: 

43 extra["aria_label"] = self.aria_label 

44 

45 return get_icon( 

46 self.name, 

47 class_name=self.class_name, 

48 size=self.size, 

49 **extra, 

50 **self.props, 

51 )