@classic-homes/maps-react 0.1.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -0,0 +1,423 @@
1
+ import * as React from 'react';
2
+ import { MapProps, SourceProps, MarkerProps, PopupProps, BaseLayerProps, FeatureClickEventParams, FeatureHoverEventParams, FillLayerProps, LineLayerProps, CircleLayerProps, SymbolLayerProps, FillExtrusionLayerProps, HeatmapLayerProps, LegendProps, LegendGroupProps, CoordinateDisplayProps, MapTheme, MapStyleSpec } from '@classic-homes/maps-core';
3
+ export { BaseMapProps, BoundsArray, CircleLayerProps, ClusterExpandOptions, ClusterFeatureProperties, CoordinateDisplayProps, FeatureClickEventParams, FeatureHoverEventParams, FillExtrusionLayerProps, FillLayerProps, GeoJSONFeature, GeoJSONFeatureCollection, GradientStop, HeatmapLayerProps, LegendConfig, LegendGroupProps, LegendItem, LegendProps, LineLayerProps, LngLat, LoadGeoJSONOptions, LoadGeoJSONResult, MapBounds, MapClickEventParams, MapHoverEventParams, MapMoveEventParams, MapProps, MapViewport, MarkerClickEventParams, MarkerData, MarkerDragEventParams, MarkerProps, PopupProps, SourceProps, SymbolLayerProps, THEME_DARK, THEME_LIGHT, ValidationResult, calculateBounds, calculateCentroid, combineBounds, countFeaturesByType, createHoverExpression, createSelectionExpression, darkBasicStyle, darkTheme, expandCluster, expandClusterToBounds, extendBounds, filterByGeometryType, formatArea, formatCoordinates, formatDistance, generateMapDescription, getClusterBounds, getClusterChildren, getClusterExpansionZoom, getClusterLeaves, getHighlightStyle, getSelectionStyle, isClusterFeature, isValidBounds, lightBasicStyle, lightTheme, loadGeoJSON, validateGeoJSON } from '@classic-homes/maps-core';
4
+ import maplibregl, { Map as Map$1 } from 'maplibre-gl';
5
+ import * as class_variance_authority_types from 'class-variance-authority/types';
6
+ import { VariantProps } from 'class-variance-authority';
7
+ import { ClassValue } from 'clsx';
8
+
9
+ interface MapContainerProps extends React.HTMLAttributes<HTMLDivElement> {
10
+ /** Map title for accessibility */
11
+ title: string;
12
+ /** Optional description for screen readers */
13
+ description?: string;
14
+ /** Map height */
15
+ height?: number | string;
16
+ /** Map width */
17
+ width?: number | string;
18
+ /** Show loading state */
19
+ loading?: boolean;
20
+ /** Error message */
21
+ error?: string | null;
22
+ /** Show empty state */
23
+ empty?: boolean;
24
+ /** Empty state message */
25
+ emptyMessage?: string;
26
+ /** Retry callback for error state */
27
+ onRetry?: () => void;
28
+ /** Additional wrapper styles */
29
+ wrapperClassName?: string;
30
+ }
31
+ /**
32
+ * Container component for all maps
33
+ * Handles loading, error, and empty states
34
+ */
35
+ declare const MapContainer: React.ForwardRefExoticComponent<MapContainerProps & React.RefAttributes<HTMLDivElement>>;
36
+
37
+ interface MapSkeletonProps extends React.HTMLAttributes<HTMLDivElement> {
38
+ /** Map height */
39
+ height?: number | string;
40
+ }
41
+ /**
42
+ * Loading skeleton for maps
43
+ */
44
+ declare const MapSkeleton: React.ForwardRefExoticComponent<MapSkeletonProps & React.RefAttributes<HTMLDivElement>>;
45
+
46
+ interface MapErrorProps extends React.HTMLAttributes<HTMLDivElement> {
47
+ /** Error message to display */
48
+ message?: string;
49
+ /** Map height */
50
+ height?: number | string;
51
+ /** Retry callback */
52
+ onRetry?: () => void;
53
+ }
54
+ /**
55
+ * Error state display for maps
56
+ */
57
+ declare const MapError: React.ForwardRefExoticComponent<MapErrorProps & React.RefAttributes<HTMLDivElement>>;
58
+
59
+ interface MapEmptyProps extends React.HTMLAttributes<HTMLDivElement> {
60
+ /** Message to display */
61
+ message?: string;
62
+ /** Map height */
63
+ height?: number | string;
64
+ }
65
+ /**
66
+ * Empty state display for maps with no data
67
+ */
68
+ declare const MapEmpty: React.ForwardRefExoticComponent<MapEmptyProps & React.RefAttributes<HTMLDivElement>>;
69
+
70
+ interface MapComponentProps extends Omit<MapProps, 'class'> {
71
+ /** React className prop */
72
+ className?: string;
73
+ /** Children to render inside the map (layers, markers, etc.) */
74
+ children?: React.ReactNode;
75
+ }
76
+ /**
77
+ * Main Map component wrapping MapLibre GL
78
+ *
79
+ * @remarks
80
+ * **Callback Memoization**: Event callbacks (onClick, onHover, onMove, etc.) should be
81
+ * memoized with `useCallback` to prevent unnecessary effect re-runs. Unmemoized callbacks
82
+ * will cause event handlers to be detached and reattached on every render.
83
+ *
84
+ * @example
85
+ * ```tsx
86
+ * import { useCallback } from 'react';
87
+ *
88
+ * function MyMap() {
89
+ * // GOOD: Memoized callback
90
+ * const handleClick = useCallback((e: MapClickEventParams) => {
91
+ * console.log('Clicked:', e.lngLat);
92
+ * }, []);
93
+ *
94
+ * return <Map onClick={handleClick}>...</Map>;
95
+ * }
96
+ *
97
+ * // BAD: Inline callback (creates new function every render)
98
+ * <Map onClick={(e) => console.log(e)} />
99
+ * ```
100
+ */
101
+ declare const Map: React.ForwardRefExoticComponent<MapComponentProps & React.RefAttributes<HTMLDivElement>>;
102
+
103
+ /**
104
+ * Control offset configuration for each position
105
+ */
106
+ type ControlOffsets = Record<string, number>;
107
+ /**
108
+ * Context for sharing the MapLibre map instance with child components
109
+ */
110
+ interface MapContextValue {
111
+ /** The MapLibre map instance */
112
+ map: Map$1 | null;
113
+ /** Whether the map has loaded */
114
+ loaded: boolean;
115
+ /** Pixel offsets for each position based on active controls */
116
+ controlOffsets?: ControlOffsets;
117
+ /** Register a custom control and get its vertical offset */
118
+ registerControl?: (id: string, position: string, height: number) => number;
119
+ /** Unregister a custom control */
120
+ unregisterControl?: (id: string, position: string) => void;
121
+ /** Get the vertical offset for a control */
122
+ getCustomControlOffset?: (id: string, position: string) => number;
123
+ }
124
+ declare const MapContext: React.Context<MapContextValue>;
125
+ /**
126
+ * Hook to access the MapLibre map instance from context
127
+ */
128
+ declare function useMap(): MapContextValue;
129
+ /**
130
+ * Hook to access the map instance only when loaded
131
+ * Returns null if map is not yet available
132
+ */
133
+ declare function useMapInstance(): Map$1 | null;
134
+
135
+ interface SourceComponentProps extends SourceProps {
136
+ /** Children (layers that use this source) */
137
+ children?: React.ReactNode;
138
+ }
139
+ /**
140
+ * Source component for adding data sources to the map
141
+ */
142
+ declare const Source: React.FC<SourceComponentProps>;
143
+
144
+ interface MarkerComponentProps extends MarkerProps {
145
+ /** Custom marker content (React element) */
146
+ children?: React.ReactNode;
147
+ }
148
+ /**
149
+ * Marker component for adding markers to the map
150
+ */
151
+ declare const Marker: React.ForwardRefExoticComponent<MarkerComponentProps & React.RefAttributes<maplibregl.Marker>>;
152
+
153
+ interface PopupComponentProps extends PopupProps {
154
+ /** Popup content (React element) */
155
+ children: React.ReactNode;
156
+ /** Control popup open state */
157
+ open?: boolean;
158
+ }
159
+ /**
160
+ * Popup component for displaying information on the map
161
+ */
162
+ declare const Popup: React.ForwardRefExoticComponent<PopupComponentProps & React.RefAttributes<maplibregl.Popup>>;
163
+
164
+ interface PopupCardProps extends React.HTMLAttributes<HTMLDivElement> {
165
+ /** Popup card content */
166
+ children: React.ReactNode;
167
+ }
168
+ /**
169
+ * Root wrapper component for popup content.
170
+ * Provides consistent background and text color for popup content.
171
+ */
172
+ declare const PopupCard: React.ForwardRefExoticComponent<PopupCardProps & React.RefAttributes<HTMLDivElement>>;
173
+
174
+ declare const badgeVariants: (props?: ({
175
+ badgeVariant?: "default" | "secondary" | "success" | "warning" | "info" | null | undefined;
176
+ } & class_variance_authority_types.ClassProp) | undefined) => string;
177
+ interface PopupHeaderProps extends React.HTMLAttributes<HTMLDivElement>, VariantProps<typeof badgeVariants> {
178
+ /** Main heading text */
179
+ title: string;
180
+ /** Optional badge text */
181
+ badge?: string;
182
+ }
183
+ /**
184
+ * Header component for popup content.
185
+ * Displays a title and optional badge with a bottom border.
186
+ * Includes right padding to avoid overlap with the close button.
187
+ */
188
+ declare const PopupHeader: React.ForwardRefExoticComponent<PopupHeaderProps & React.RefAttributes<HTMLDivElement>>;
189
+
190
+ interface PopupContentProps extends React.HTMLAttributes<HTMLDivElement> {
191
+ /** Content */
192
+ children: React.ReactNode;
193
+ }
194
+ /**
195
+ * Main content area for popup.
196
+ * Provides consistent padding and text styling.
197
+ */
198
+ declare const PopupContent: React.ForwardRefExoticComponent<PopupContentProps & React.RefAttributes<HTMLDivElement>>;
199
+
200
+ interface PopupFooterProps extends React.HTMLAttributes<HTMLDivElement> {
201
+ /** Footer content (typically buttons) */
202
+ children: React.ReactNode;
203
+ }
204
+ /**
205
+ * Footer component for popup content.
206
+ * Typically contains action buttons with right-aligned layout.
207
+ * Includes a top border to separate from content.
208
+ */
209
+ declare const PopupFooter: React.ForwardRefExoticComponent<PopupFooterProps & React.RefAttributes<HTMLDivElement>>;
210
+
211
+ /**
212
+ * React-specific feature click event params that includes the map instance
213
+ */
214
+ interface ReactFeatureClickEventParams extends FeatureClickEventParams {
215
+ /** The MapLibre map instance */
216
+ map: maplibregl.Map;
217
+ }
218
+ /**
219
+ * React-specific feature hover event params that includes the map instance
220
+ */
221
+ interface ReactFeatureHoverEventParams extends FeatureHoverEventParams {
222
+ /** The MapLibre map instance */
223
+ map: maplibregl.Map;
224
+ }
225
+ interface UseLayerOptions extends Omit<BaseLayerProps, 'onClick' | 'onHover'> {
226
+ type: maplibregl.LayerSpecification['type'];
227
+ paint?: Record<string, unknown>;
228
+ layout?: Record<string, unknown>;
229
+ /** Callback for feature click - includes map instance */
230
+ onClick?: (params: ReactFeatureClickEventParams) => void;
231
+ /** Callback for feature hover - includes map instance */
232
+ onHover?: (params: ReactFeatureHoverEventParams) => void;
233
+ /**
234
+ * Throttle interval for onHover callback in milliseconds.
235
+ * Set to 0 (default) for no throttling.
236
+ * Feature-state updates remain immediate for visual responsiveness.
237
+ */
238
+ hoverThrottleMs?: number;
239
+ }
240
+ /**
241
+ * Hook to manage layer lifecycle and events
242
+ */
243
+ declare function useLayer({ id, source, sourceLayer, type, visible, opacity: _opacity, minZoom, maxZoom, filter, beforeId, paint, layout, onClick, onHover, hoverThrottleMs, }: UseLayerOptions): {
244
+ layerAdded: boolean;
245
+ };
246
+
247
+ interface FillLayerComponentProps extends Omit<FillLayerProps, 'onClick' | 'onHover'> {
248
+ /** Callback for feature click - includes map instance */
249
+ onClick?: (params: ReactFeatureClickEventParams) => void;
250
+ /** Callback for feature hover - includes map instance */
251
+ onHover?: (params: ReactFeatureHoverEventParams) => void;
252
+ }
253
+ /**
254
+ * Fill layer component for rendering polygon features
255
+ */
256
+ declare const FillLayer: React.FC<FillLayerComponentProps>;
257
+
258
+ interface LineLayerComponentProps extends Omit<LineLayerProps, 'onClick' | 'onHover'> {
259
+ /** Callback for feature click - includes map instance */
260
+ onClick?: (params: ReactFeatureClickEventParams) => void;
261
+ /** Callback for feature hover - includes map instance */
262
+ onHover?: (params: ReactFeatureHoverEventParams) => void;
263
+ }
264
+ /**
265
+ * Line layer component for rendering line features
266
+ */
267
+ declare const LineLayer: React.FC<LineLayerComponentProps>;
268
+
269
+ interface CircleLayerComponentProps extends Omit<CircleLayerProps, 'onClick' | 'onHover'> {
270
+ /** Callback for feature click - includes map instance */
271
+ onClick?: (params: ReactFeatureClickEventParams) => void;
272
+ /** Callback for feature hover - includes map instance */
273
+ onHover?: (params: ReactFeatureHoverEventParams) => void;
274
+ }
275
+ /**
276
+ * Circle layer component for rendering point features as circles
277
+ */
278
+ declare const CircleLayer: React.FC<CircleLayerComponentProps>;
279
+
280
+ interface SymbolLayerComponentProps extends Omit<SymbolLayerProps, 'onClick' | 'onHover'> {
281
+ /** Callback for feature click - includes map instance */
282
+ onClick?: (params: ReactFeatureClickEventParams) => void;
283
+ /** Callback for feature hover - includes map instance */
284
+ onHover?: (params: ReactFeatureHoverEventParams) => void;
285
+ }
286
+ /**
287
+ * Symbol layer component for rendering icons and text labels
288
+ */
289
+ declare const SymbolLayer: React.FC<SymbolLayerComponentProps>;
290
+
291
+ interface FillExtrusionLayerComponentProps extends Omit<FillExtrusionLayerProps, 'onClick' | 'onHover'> {
292
+ /** Callback for feature click - includes map instance */
293
+ onClick?: (params: ReactFeatureClickEventParams) => void;
294
+ /** Callback for feature hover - includes map instance */
295
+ onHover?: (params: ReactFeatureHoverEventParams) => void;
296
+ }
297
+ /**
298
+ * Fill extrusion layer component for rendering 3D buildings and polygons
299
+ */
300
+ declare const FillExtrusionLayer: React.FC<FillExtrusionLayerComponentProps>;
301
+
302
+ interface HeatmapLayerComponentProps extends Omit<HeatmapLayerProps, 'onClick' | 'onHover'> {
303
+ /** Callback for feature click - includes map instance */
304
+ onClick?: (params: ReactFeatureClickEventParams) => void;
305
+ /** Callback for feature hover - includes map instance */
306
+ onHover?: (params: ReactFeatureHoverEventParams) => void;
307
+ }
308
+ /**
309
+ * Heatmap layer component for visualizing point density
310
+ */
311
+ declare const HeatmapLayer: React.FC<HeatmapLayerComponentProps>;
312
+
313
+ interface LegendComponentProps extends LegendProps {
314
+ }
315
+ /**
316
+ * Legend component for displaying map legends
317
+ */
318
+ declare const Legend: React.FC<LegendComponentProps>;
319
+
320
+ interface LegendGroupComponentProps extends LegendGroupProps {
321
+ }
322
+ /**
323
+ * LegendGroup component - displays multiple legends in an accordion style
324
+ * where only one is expanded at a time
325
+ */
326
+ declare const LegendGroup: React.FC<LegendGroupComponentProps>;
327
+
328
+ interface CoordinateDisplayComponentProps extends CoordinateDisplayProps {
329
+ }
330
+ /**
331
+ * CoordinateDisplay component for showing cursor coordinates on the map
332
+ */
333
+ declare const CoordinateDisplay: React.FC<CoordinateDisplayComponentProps>;
334
+
335
+ /**
336
+ * Props for the DeckOverlay component
337
+ */
338
+ interface DeckOverlayProps {
339
+ /** Deck.gl layers to render */
340
+ layers?: unknown[];
341
+ /** Callback for picking events */
342
+ onHover?: (info: unknown) => void;
343
+ /** Callback for click events */
344
+ onClick?: (info: unknown) => void;
345
+ /** Callback to get cursor style based on picking state */
346
+ getCursor?: (state: {
347
+ isHovering: boolean;
348
+ isDragging: boolean;
349
+ }) => string;
350
+ /** Whether to enable interleaved rendering (default: true) */
351
+ interleaved?: boolean;
352
+ /** Deck.gl effects */
353
+ effects?: unknown[];
354
+ /** Additional Deck.gl props */
355
+ deckProps?: Record<string, unknown>;
356
+ }
357
+ /**
358
+ * Deck.gl overlay component for advanced visualizations
359
+ *
360
+ * This component provides integration with Deck.gl for features like:
361
+ * - 3D building extrusions
362
+ * - Point clouds
363
+ * - Advanced data visualizations
364
+ * - Custom WebGL layers
365
+ *
366
+ * Note: Requires @deck.gl/core, @deck.gl/layers, and @deck.gl/mapbox as peer dependencies
367
+ *
368
+ * @example
369
+ * ```tsx
370
+ * import { Map, DeckOverlay } from '@classic-homes/maps-react';
371
+ * import { ScatterplotLayer } from '@deck.gl/layers';
372
+ *
373
+ * const data = [
374
+ * { position: [-122.45, 37.78], color: [255, 0, 0], radius: 100 }
375
+ * ];
376
+ *
377
+ * function MyMap() {
378
+ * const layers = [
379
+ * new ScatterplotLayer({
380
+ * id: 'scatter-layer',
381
+ * data,
382
+ * getPosition: d => d.position,
383
+ * getFillColor: d => d.color,
384
+ * getRadius: d => d.radius,
385
+ * })
386
+ * ];
387
+ *
388
+ * return (
389
+ * <Map title="Map with Deck.gl">
390
+ * <DeckOverlay layers={layers} />
391
+ * </Map>
392
+ * );
393
+ * }
394
+ * ```
395
+ */
396
+ declare const DeckOverlay: React.FC<DeckOverlayProps>;
397
+
398
+ /**
399
+ * Hook to manage map theme based on system/document dark mode
400
+ *
401
+ * @param preference - Theme preference ('light', 'dark', or 'auto')
402
+ * @returns Current theme name and theme/style objects
403
+ */
404
+ declare function useMapTheme(preference?: 'light' | 'dark' | 'auto'): {
405
+ themeName: string;
406
+ theme: MapTheme;
407
+ style: MapStyleSpec;
408
+ isDark: boolean;
409
+ };
410
+
411
+ /**
412
+ * Hook to detect if the user prefers reduced motion
413
+ *
414
+ * @returns true if reduced motion is preferred
415
+ */
416
+ declare function useReducedMotion(): boolean;
417
+
418
+ /**
419
+ * Merge class names with Tailwind CSS conflict resolution
420
+ */
421
+ declare function cn(...inputs: ClassValue[]): string;
422
+
423
+ export { CircleLayer, type CircleLayerComponentProps, CoordinateDisplay, type CoordinateDisplayComponentProps, DeckOverlay, type DeckOverlayProps, FillExtrusionLayer, type FillExtrusionLayerComponentProps, FillLayer, type FillLayerComponentProps, HeatmapLayer, type HeatmapLayerComponentProps, Legend, type LegendComponentProps, LegendGroup, type LegendGroupComponentProps, LineLayer, type LineLayerComponentProps, Map, type MapComponentProps, MapContainer, type MapContainerProps, MapContext, type MapContextValue, MapEmpty, type MapEmptyProps, MapError, type MapErrorProps, MapSkeleton, type MapSkeletonProps, Marker, type MarkerComponentProps, Popup, PopupCard, type PopupCardProps, type PopupComponentProps, PopupContent, type PopupContentProps, PopupFooter, type PopupFooterProps, PopupHeader, type PopupHeaderProps, type ReactFeatureClickEventParams, type ReactFeatureHoverEventParams, Source, type SourceComponentProps, SymbolLayer, type SymbolLayerComponentProps, type UseLayerOptions, cn, useLayer, useMap, useMapInstance, useMapTheme, useReducedMotion };