• Home
  • Features
  • Pricing
  • Docs
  • Announcements
  • Sign In

agentic-dev-library / thumbcode / 21114153287

18 Jan 2026 03:29PM UTC coverage: 13.095%. First build
21114153287

Pull #31

github

web-flow
Merge 0491eb3a5 into 5ee4c4536
Pull Request #31: Feat(infra): Add CI/CD and Environment Management

14 of 80 branches covered (17.5%)

Branch coverage included in aggregate %.

0 of 5 new or added lines in 3 files covered. (0.0%)

8 of 88 relevant lines covered (9.09%)

0.09 hits per line

Source File
Press 'n' to go to next uncovered line, 'b' for previous

0.0
/src/components/ui/ThemeProvider.tsx
1
/**
2
 * Theme Provider
3
 *
4
 * Provides design tokens to all child components
5
 * Programmatically loads from tokens.json
6
 */
7

8
import type { ReactNode } from 'react';
9
import { createContext, useContext, useMemo } from 'react';
10
import tokens from '../../../design-system/tokens.json';
11

12
interface ColorValue {
13
  [key: string]: string;
14
}
15

16
interface ThemeContextValue {
17
  tokens: typeof tokens;
18
  colors: Record<string, string | ColorValue>;
19
  spacing: Record<string, string>;
20
  typography: typeof tokens.typography;
21
}
22

23
const ThemeContext = createContext<ThemeContextValue | undefined>(undefined);
×
24

25
/**
26
 * Provides theme tokens, flattened color map, spacing, and typography to descendant components via ThemeContext.
27
 *
28
 * The provider loads design tokens and exposes `tokens`, `colors` (flat map with either hex strings or shade maps), `spacing`, and `typography` to all children.
29
 *
30
 * @returns A React element that supplies the theme context to its children.
31
 */
32
export function ThemeProvider({ children }: { children: ReactNode }) {
33
  const value = useMemo(() => {
×
34
    // Process colors into flat structure
NEW
35
    const colors: Record<string, string | ColorValue> = {};
×
36
    Object.entries(tokens.colors).forEach(([colorName, colorData]) => {
×
37
      if (typeof colorData === 'string') {
×
38
        colors[colorName] = colorData;
×
39
      } else if ('values' in colorData) {
×
40
        colors[colorName] = {};
×
41
        Object.entries(colorData.values).forEach(([shade, value]) => {
×
42
          colors[colorName][shade] = value.hex;
×
43
        });
44
      }
45
    });
46

47
    return {
×
48
      tokens,
49
      colors,
50
      spacing: tokens.spacing.values,
51
      typography: tokens.typography,
52
    };
53
  }, []);
54

NEW
55
  return <ThemeContext.Provider value={value}>{children}</ThemeContext.Provider>;
×
56
}
57

58
/**
59
 * Accesses the current theme context value.
60
 *
61
 * @returns The ThemeContextValue containing `tokens`, `colors`, `spacing`, and `typography`.
62
 * @throws Error if called outside of a ThemeProvider.
63
 */
64
export function useTheme() {
65
  const context = useContext(ThemeContext);
×
66
  if (!context) {
×
67
    throw new Error('useTheme must be used within ThemeProvider');
×
68
  }
69
  return context;
×
70
}
71

72
/**
73
 * Retrieve a color value from the current theme by name and optional shade.
74
 *
75
 * @param colorName - The color name or color group key defined in the theme's colors.
76
 * @param shade - The shade key within a color group (defaults to `'500'`).
77
 * @returns The resolved color string (e.g., hex value). Returns `'#000000'` if the color or shade is not found.
78
 */
79
export function useColor(colorName: string, shade: string = '500'): string {
×
80
  const { colors } = useTheme();
×
81

82
  if (typeof colors[colorName] === 'string') {
×
83
    return colors[colorName];
×
84
  }
85

86
  return colors[colorName]?.[shade] || '#000000';
×
87
}
88

89
/**
90
 * Retrieve a spacing token value by key from the theme.
91
 *
92
 * @param key - The spacing token key (for example, `"sm"`, `"md"`, `"lg"`)
93
 * @returns The spacing value for the given key, or `'0px'` if the key is not present
94
 */
95
export function useSpacing(key: string): string {
96
  const { spacing } = useTheme();
×
97
  return spacing[key] || '0px';
×
98
}
STATUS · Troubleshooting · Open an Issue · Sales · Support · CAREERS · ENTERPRISE · START FREE · SCHEDULE DEMO
ANNOUNCEMENTS · TWITTER · TOS & SLA · Supported CI Services · What's a CI service? · Automated Testing

© 2026 Coveralls, Inc