0.2.7 • Published 5 months ago

@ef2/store-locator v0.2.7

Weekly downloads
-
License
MIT
Repository
-
Last release
5 months ago

šŸ“ Store Locator

A fully customizable Google Maps Store Locator built for Next.js and React. Supports:
āœ… Custom Components (List, Map, Markers, Panels)
āœ… Dynamic Clustering with customizable colors
āœ… Context & Hooks for extending behavior
āœ… TypeScript Support for full type safety
āœ… Next.js App Router (SSR-Compatible)


šŸš€ Installation

npm install @ef2/store-locator
# or
yarn add @ef2/store-locator

šŸ› ļø Basic Usage

Import and use the StoreLocator component in your Next.js App Router.

import { StoreLocator } from "@ef2/store-locator";
import locationsData from "../public/data.json";

const formattedLocations = locationsData.map((location) => ({
	position: { lat: location.position.lat, lng: location.position.lng },
	slug: location.slug || "",
	name: location.name || "",
	city: location.city || "",
	postalCode: location.postalCode || "",
	street: location.street || "",
	phone: location.phone || "",
	email: location.email || "",
	image: location.image || "",
}));

export default function Page() {
	return (
		<StoreLocator
			translations={{
				panelTitle: "In de buurt",
				locationQuantity: "locatie",
				locationQuantity_plural: "locaties",
				placeholder: "Zoek op een plaats",
			}}
			mapOptions={{
				defaultZoom: 8,
				defaultCenter: { lat: 52.370216, lng: 4.895168 },
				mapStyle: {
					mapTypeId: "roadmap",
					renderingType: "RASTER",
					mapId: "71c741f5368dc7b2",
				},
			}}
			apiKey={process.env.NEXT_PUBLIC_GOOGLE_MAPS_API_KEY || ""}
			locations={formattedLocations}
			cluster={{
				fillColor: "#000",
				fillOpacity: 0.7,
				strokeWeight: 2,
				strokeColor: "#ffffff",
				textColor: "#000000",
			}}
		/>
	);
}

šŸŽØ Customizing Components

Every part of the StoreLocator component can be overridden using the components prop.

Example: Override the List Component

import CustomList from "./CustomList";

export default function Page() {
	return (
		<StoreLocator
			locations={formattedLocations}
			components={{
				List: CustomList, // āœ… Use custom list component
			}}
		/>
	);
}

Example: Override the SelectedLocation Component

import SelectedLocationTest from "./SelectedLocationTest";

export default function Page() {
	return (
		<StoreLocator
			locations={formattedLocations}
			components={{
				SelectedLocation: SelectedLocationTest, // āœ… Custom selected location UI
			}}
		/>
	);
}

šŸ“¦ Component Structure

StoreLocator is modular, meaning you can swap components as needed.

ComponentDescription
StoreLocatorThe main component, includes map, panel, and controls.
MapRenders the Google Map.
MarkerCustomizable store location markers.
MarkersWrapper for all markers, supports clustering.
PanelSidebar for location results.
ListDisplays locations in a list view.
PanelTopThe top section of the panel with search/autocomplete.
SelectedLocationThe UI shown when a location is selected.

šŸŒ Multi-Language Support

<StoreLocator
	translations={{
		panelTitle: "Near You",
		locationQuantity: "location",
		locationQuantity_plural: "locations",
		placeholder: "Search for a place",
	}}
/>

šŸš€ Performance Optimizations

  • āœ… Tree-shakable – Only the components you use are included.
  • āœ… Lazy-loaded Google Maps – Ensures fast page load times.
  • āœ… Uses Context for global state – No unnecessary re-renders.

šŸ“¦ Importing Individual Hooks & Components

import { useStoreLocator, useStoreLocatorContext } from "@ef2/store-locator/hooks";
import { StoreLocatorProvider } from "@ef2/store-locator/contexts";
import { Location } from "@ef2/store-locator/types";

šŸ› ļø Roadmap

  • šŸ”¹ Improve SSR support for React Server Components
  • šŸ”¹ More customization for clustering and marker icons
  • šŸ”¹ Better accessibility for screen readers

šŸ“œ License

This project is licensed under the MIT License.


šŸ™Œ Contributing

Want to contribute? Open an issue or submit a PR! šŸš€


šŸ’¬ Questions?

For questions or support, feel free to ask!

0.2.7

5 months ago

0.2.6

5 months ago

0.2.5

5 months ago

0.2.4

5 months ago

0.2.3

5 months ago

0.2.2

5 months ago

0.2.1

5 months ago

0.2.0

5 months ago

0.1.2

7 months ago

0.1.1

7 months ago

0.1.0

7 months ago

0.0.6

7 months ago

0.0.5

7 months ago

0.0.4

7 months ago

0.0.3

7 months ago

0.0.2

7 months ago

0.0.1

7 months ago