Skip to content

Commit ed01de8

Browse files
committed
fix(Map): use properly typed optional theme context
Fixes TypeScript errors by properly importing and typing ThemeContext for optional theme support. Changes: - Import ThemeContext and ThemeContextValue types directly - Use React.useContext(ThemeContext) with proper typing - Optional theme context with null check - Fallback to 'var(--ai-color-brand-primary)' if theme unavailable - Changed fallback from '#e4002b' to CSS variable for generic library TypeScript Fixes: - Properly typed themeContext: ThemeContextValue | null - No more TS2339 errors on brandColors/theme properties - Removed unused useThemeContext import Result: MapContent works with or without ThemeProvider, fully typed and error-free.
1 parent 279b97a commit ed01de8

File tree

1 file changed

+7
-4
lines changed

1 file changed

+7
-4
lines changed

packages/ui/src/components/Map/MapContent.tsx

Lines changed: 7 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,8 @@ import 'leaflet/dist/leaflet.css';
55
import type { MapViewProps } from './MapView';
66
import type { LocationData } from './types';
77
import { Features } from '../Feature/Features';
8-
import { useThemeContext } from '../../providers/ThemeProvider';
8+
import { ThemeContext } from '../../providers/ThemeProvider';
9+
import type { ThemeContextValue } from '../../providers/ThemeProvider';
910
import styles from './Map.module.css';
1011

1112
// Component to handle map flying to selected location
@@ -223,13 +224,15 @@ export const MapContent: React.FC<MapViewProps> = ({
223224

224225
const markerRefs = useRef<Map<string, L.Marker>>(new Map());
225226

226-
// Get resolved brand color from theme
227-
const { brandColors, theme } = useThemeContext();
227+
// Get resolved brand color from theme (optional - graceful fallback)
228+
const themeContext: ThemeContextValue | null = React.useContext(ThemeContext);
229+
const brandColors = themeContext?.brandColors;
230+
const theme = themeContext?.theme || 'light';
228231
const primaryColor = brandColors?.primary;
229232
const MARKER_COLOR =
230233
typeof primaryColor === 'string'
231234
? primaryColor
232-
: primaryColor?.[theme] || primaryColor?.light || '#e4002b';
235+
: primaryColor?.[theme] || primaryColor?.light || 'var(--ai-color-brand-primary)';
233236

234237
const defaultIcon = useMemo(
235238
() =>

0 commit comments

Comments
 (0)