evijit HF Staff commited on
Commit
fbae805
·
verified ·
1 Parent(s): 0586937

fix colors in light and dark mode (#7)

Browse files

- fix colors (75230f3bad330e77d42e16c64535b9b3e0d9bad3)

src/components/Heatmap.tsx CHANGED
@@ -56,14 +56,22 @@ const Heatmap: React.FC<HeatmapProps> = ({
56
  // Use theme-aware colors
57
  const emptyColor = isDarkMode ? "#374151" : "#d1d5db";
58
 
59
- // Create intensity levels for daily view (same as weekly)
60
- const intensityColors = [
61
  emptyColor, // level 0
62
- getHeatmapColorIntensity(1, color), // level 1 (40% intensity)
63
- getHeatmapColorIntensity(2, color), // level 2 (60% intensity)
64
- getHeatmapColorIntensity(3, color), // level 3 (80% intensity)
65
- getHeatmapColorIntensity(4, color) // level 4 (100% intensity)
66
- ].filter((color): color is string => color !== null); // Remove any null values and type guard
 
 
 
 
 
 
 
 
67
 
68
  return (
69
  <div className="flex flex-col items-center w-full mx-auto">
@@ -93,8 +101,8 @@ const Heatmap: React.FC<HeatmapProps> = ({
93
  <ActivityCalendar
94
  data={processedData}
95
  theme={{
96
- light: intensityColors,
97
- dark: intensityColors
98
  }}
99
  blockSize={11}
100
  blockMargin={2}
 
56
  // Use theme-aware colors
57
  const emptyColor = isDarkMode ? "#374151" : "#d1d5db";
58
 
59
+ // Create separate intensity levels for light and dark modes
60
+ const lightIntensityColors = [
61
  emptyColor, // level 0
62
+ getHeatmapColorIntensity(1, color, false), // level 1 (bright for light mode)
63
+ getHeatmapColorIntensity(2, color, false), // level 2
64
+ getHeatmapColorIntensity(3, color, false), // level 3
65
+ getHeatmapColorIntensity(4, color, false) // level 4 (darkest for light mode)
66
+ ].filter((color): color is string => color !== null);
67
+
68
+ const darkIntensityColors = [
69
+ emptyColor, // level 0
70
+ getHeatmapColorIntensity(1, color, true), // level 1 (darker for dark mode)
71
+ getHeatmapColorIntensity(2, color, true), // level 2
72
+ getHeatmapColorIntensity(3, color, true), // level 3
73
+ getHeatmapColorIntensity(4, color, true) // level 4 (brightest for dark mode)
74
+ ].filter((color): color is string => color !== null);
75
 
76
  return (
77
  <div className="flex flex-col items-center w-full mx-auto">
 
101
  <ActivityCalendar
102
  data={processedData}
103
  theme={{
104
+ light: lightIntensityColors,
105
+ dark: darkIntensityColors
106
  }}
107
  blockSize={11}
108
  blockMargin={2}
src/components/WeeklyHeatmap.tsx CHANGED
@@ -52,10 +52,10 @@ const WeeklyHeatmap: React.FC<WeeklyHeatmapProps> = ({ data, color }) => {
52
  // Memoize sorted months
53
  const sortedMonths = useMemo(() => Object.keys(groupedData).sort(), [groupedData]);
54
 
55
- // Memoize the color intensity function
56
  const getColorIntensity = useCallback((level: number) => {
57
- return getHeatmapColorIntensity(level, color) || undefined;
58
- }, [color]);
59
 
60
  // Get the exact same empty dot color as ActivityCalendar
61
  const emptyDotColor = useMemo(() => {
 
52
  // Memoize sorted months
53
  const sortedMonths = useMemo(() => Object.keys(groupedData).sort(), [groupedData]);
54
 
55
+ // Memoize the color intensity function with theme awareness
56
  const getColorIntensity = useCallback((level: number) => {
57
+ return getHeatmapColorIntensity(level, color, isDark) || undefined;
58
+ }, [color, isDark]);
59
 
60
  // Get the exact same empty dot color as ActivityCalendar
61
  const emptyDotColor = useMemo(() => {
src/utils/heatmapColors.ts CHANGED
@@ -9,7 +9,7 @@ export const getHeatmapTheme = (primaryColor: string) => ({
9
  light: [EMPTY_DOT_LIGHT, primaryColor],
10
  });
11
 
12
- export const getHeatmapColorIntensity = (level: number, primaryColor: string) => {
13
  if (level === 0) {
14
  return null; // Will use CSS classes for theme-aware empty state
15
  }
@@ -35,9 +35,17 @@ export const getHeatmapColorIntensity = (level: number, primaryColor: string) =>
35
  return greenIntensities[Math.min(level - 1, 3)];
36
  }
37
 
38
- // Create intensity levels by adjusting brightness
39
- // Level 1: 40% intensity, Level 2: 60%, Level 3: 80%, Level 4: 100%
40
- const intensityMultipliers = [0.4, 0.6, 0.8, 1.0];
 
 
 
 
 
 
 
 
41
  const multiplier = intensityMultipliers[Math.min(level - 1, 3)];
42
 
43
  const adjustedR = Math.round(rgb.r * multiplier);
 
9
  light: [EMPTY_DOT_LIGHT, primaryColor],
10
  });
11
 
12
+ export const getHeatmapColorIntensity = (level: number, primaryColor: string, isDarkMode: boolean = false) => {
13
  if (level === 0) {
14
  return null; // Will use CSS classes for theme-aware empty state
15
  }
 
35
  return greenIntensities[Math.min(level - 1, 3)];
36
  }
37
 
38
+ // Create intensity levels based on theme
39
+ let intensityMultipliers: number[];
40
+
41
+ if (isDarkMode) {
42
+ // Dark mode: Start darker, get brighter (40% → 100%)
43
+ intensityMultipliers = [0.4, 0.6, 0.8, 1.0];
44
+ } else {
45
+ // Light mode: Start brighter, get darker (100% → 40%)
46
+ intensityMultipliers = [1.0, 0.8, 0.6, 0.4];
47
+ }
48
+
49
  const multiplier = intensityMultipliers[Math.min(level - 1, 3)];
50
 
51
  const adjustedR = Math.round(rgb.r * multiplier);