Coverage for src / lexigram / ui / styles / tokens.py: 100%

13 statements  

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

1"""Semantic color maps for Lexigram UI components. 

2 

3All values use CSS variable references (Tailwind arbitrary value syntax) 

4instead of hardcoded color classes. Tokens are resolved from ShadCN- 

5compatible CSS variables defined in design_tokens.py. 

6""" 

7 

8from __future__ import annotations 

9 

10SEMANTIC_CLASSES: dict[str, str] = { 

11 "default": "bg-muted text-muted-foreground", 

12 "gray": "bg-muted text-muted-foreground", 

13 "primary": "bg-primary text-primary-foreground", 

14 "success": "bg-success text-success-foreground", 

15 "warning": "bg-warning text-warning-foreground", 

16 "danger": "bg-destructive text-destructive-foreground", 

17 "error": "bg-destructive text-destructive-foreground", 

18 "info": "bg-info text-info-foreground", 

19 "red": "bg-destructive text-destructive-foreground", 

20 "yellow": "bg-warning text-warning-foreground", 

21 "green": "bg-success text-success-foreground", 

22 "blue": "bg-info text-info-foreground", 

23 "indigo": "bg-primary text-primary-foreground", 

24 "purple": "bg-primary text-primary-foreground", 

25 "pink": "bg-primary text-primary-foreground", 

26 "orange": "bg-warning text-warning-foreground", 

27} 

28 

29 

30 

31SEMANTIC_ICONS: dict[str, str] = { 

32 "info": "info", 

33 "success": "check", 

34 "warning": "alert-circle", 

35 "error": "alert-circle", 

36 "danger": "alert-circle", 

37 "default": "info", 

38} 

39 

40TOAST_CLASSES: dict[str, str] = { 

41 "info": "bg-info", 

42 "success": "bg-success", 

43 "warning": "bg-warning", 

44 "error": "bg-destructive", 

45 "danger": "bg-destructive", 

46 "default": "bg-primary", 

47} 

48 

49ALERT_CLASSES: dict[str, str] = { 

50 "info": "bg-info/10 text-info border-info/30", 

51 "success": "bg-success/10 text-success border-success/30", 

52 "warning": "bg-warning/10 text-warning border-warning/30", 

53 "error": "bg-destructive/10 text-destructive border-destructive/30", 

54 "danger": "bg-destructive/10 text-destructive border-destructive/30", 

55} 

56 

57 

58def get_semantic_classes(variant: str, default: str = "default") -> str: 

59 """Resolve a variant name to CSS variable-based utility classes. 

60 

61 Args: 

62 variant: Variant name (e.g. ``"success"``, ``"danger"``, ``"blue"``). 

63 default: Fallback when *variant* is not recognised. 

64 

65 Returns: 

66 CSS class string for the resolved variant. 

67 """ 

68 return SEMANTIC_CLASSES.get(variant, SEMANTIC_CLASSES[default]) 

69 

70 

71def get_semantic_icon(variant: str, default: str = "info") -> str: 

72 """Resolve a variant name to a registered icon name. 

73 

74 Args: 

75 variant: Variant name (e.g. ``"success"``, ``"error"``). 

76 default: Fallback when *variant* is not recognised. 

77 

78 Returns: 

79 Icon name string (empty string if not found). 

80 """ 

81 return SEMANTIC_ICONS.get(variant, SEMANTIC_ICONS.get(default, "")) 

82 

83 

84def get_toast_classes(toast_type: str, default: str = "default") -> str: 

85 """Resolve a toast type to CSS variable-based background classes. 

86 

87 Args: 

88 toast_type: Toast type name (``"info"``, ``"success"``, etc.). 

89 default: Fallback when *toast_type* is not recognised. 

90 

91 Returns: 

92 CSS class string for the resolved toast type. 

93 """ 

94 return TOAST_CLASSES.get(toast_type, TOAST_CLASSES[default]) 

95 

96 

97def get_alert_classes(variant: str, default: str = "info") -> str: 

98 """Resolve an alert variant to CSS variable-based alert classes. 

99 

100 Args: 

101 variant: Alert variant (``"info"``, ``"success"``, etc.). 

102 default: Fallback when *variant* is not recognised. 

103 

104 Returns: 

105 CSS class string for the resolved variant. 

106 """ 

107 return ALERT_CLASSES.get(variant, ALERT_CLASSES[default])