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

30 statements  

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

1from __future__ import annotations 

2 

3from lexigram.ui.styles.design_tokens import ( 

4 SHADCN_DARK_COLORS, 

5 SHADCN_DEFAULT_COLORS, 

6 render_all_tokens, 

7 render_utility_classes, 

8) 

9 

10 

11def shadcn_css( 

12 primary: str | None = None, 

13 background: str | None = None, 

14 foreground: str | None = None, 

15 radius: str | None = None, 

16 success: str | None = None, 

17 warning: str | None = None, 

18 info: str | None = None, 

19) -> str: 

20 """Generate ShadCN-compatible CSS with optional overrides. 

21 

22 Args: 

23 primary: Override primary color (oklch or hex value). 

24 background: Override background color. 

25 foreground: Override foreground color. 

26 radius: Override border radius. 

27 success: Override success color. 

28 warning: Override warning color. 

29 info: Override info color. 

30 

31 Returns: 

32 Complete CSS string with :root and .dark variable blocks + utility classes. 

33 """ 

34 colors = dict(SHADCN_DEFAULT_COLORS) 

35 dark_colors = dict(SHADCN_DARK_COLORS) 

36 

37 if primary: 

38 colors["--primary"] = primary 

39 colors["--ring"] = primary 

40 dark_colors["--primary"] = primary 

41 dark_colors["--ring"] = primary 

42 if background: 

43 colors["--background"] = background 

44 dark_colors["--background"] = background 

45 if foreground: 

46 colors["--foreground"] = foreground 

47 dark_colors["--foreground"] = foreground 

48 if radius: 

49 colors["--radius"] = radius 

50 dark_colors["--radius"] = radius 

51 if success: 

52 colors["--color-success"] = success 

53 dark_colors["--color-success"] = success 

54 if warning: 

55 colors["--color-warning"] = warning 

56 dark_colors["--color-warning"] = warning 

57 if info: 

58 colors["--color-info"] = info 

59 dark_colors["--color-info"] = info 

60 

61 parts = [ 

62 "/* Lexigram UI — ShadCN-compatible design tokens */", 

63 render_all_tokens(colors, dark_colors), 

64 "", 

65 "/* Utility classes */", 

66 render_utility_classes(), 

67 ] 

68 return "\n".join(parts)