Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 11 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -45,6 +45,17 @@ A carousel slider that integrates with Webflow CMS collections featuring:
- **Slot-based content** accepts Webflow CMS collection lists as component slots.
- **Customizable behavior** control slides to show, scroll speed, and autoplay settings.

### 🗺️ [CMS Map](./cms-map/)

An interactive map component that displays CMS-driven location data featuring:

- **CMS Collection Integration** automatically extracts location data from Webflow CMS Collection lists.
- **Mapbox GL JS** powered interactive maps with custom markers and smooth navigation.
- **Auto-Fit Bounds** automatically adjusts map view to show all markers with configurable padding.
- **Custom Popups** display rich HTML content from CMS fields in map marker popups.
- **Slot-based content** accepts Webflow CMS collection lists as component slots.
- **Flexible Configuration** control map center, zoom level, bounds fitting, and control positioning.

### 🗺️ [Store Locator](./store-locator/)

A map component and backend API that plots locations demonstrating:
Expand Down
1 change: 1 addition & 0 deletions cms-map/.env.example
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
VITE_MAP_KEY=your_mapbox_api_key_here.example
Copy link
Contributor

@zplata zplata Dec 9, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Any disclaimers we need to make with this API key on client side?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is public key safe to expose on client side. I'll add info folks need to setup the mapbox account

28 changes: 28 additions & 0 deletions cms-map/.gitignore
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
# Logs
logs
*.log
npm-debug.log*
yarn-debug.log*
yarn-error.log*
pnpm-debug.log*
lerna-debug.log*

node_modules
dist
dist-ssr
*.local

# Environment variables
.env
.env.local

# Editor directories and files
.vscode/*
!.vscode/extensions.json
.idea
.DS_Store
*.suo
*.ntvs*
*.njsproj
*.sln
*.sw?
69 changes: 69 additions & 0 deletions cms-map/README.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,69 @@
# CMS Map

This code component example integrates Mapbox with Webflow CMS collections to display dynamic location data on an interactive map. Perfect for store locators, event maps, or any location-based content.

![](./screenshot/preview.png)

## Features

- **CMS Collection Integration** - Automatically extracts location data from Webflow CMS Collection lists via slot-based architecture
- **Mapbox GL JS** - Powered by Mapbox for smooth, interactive maps with custom markers
- **Auto-Fit Bounds** - Automatically adjusts map view to show all markers with configurable padding and zoom limits
- **Custom Popups** - Display rich HTML content from CMS fields in map marker popups
- **Configurable Controls** - Control map center, zoom level, bounds fitting, and control positioning
- **Slot-Based Content** - Accepts any Webflow CMS collection list as a component slot for maximum flexibility
- **Vite Project Setup** - Fast development experience with Hot Module Replacement (HMR)

## Getting Started

1. Install dependencies: `npm i`
2. Create a `.env` file in the root directory with your Mapbox API key:
```
VITE_MAP_KEY=your_mapbox_api_key_here
```
Get your Mapbox API key from [https://account.mapbox.com/](https://account.mapbox.com/)
3. Run `npx webflow library share` to create a code library for this example in your designated Webflow workspace

## Component Properties

| Prop Name | Type | Default | Description |
| --------------------------- | --------- | ------- | ------------------------------------------------------------ |
| `mapKey` | `Text` | `""` | Your Mapbox API access token |
| `centerLat` | `Number` | `0` | Default latitude for map center |
| `centerLng` | `Number` | `0` | Default longitude for map center |
| `zoom` | `Number` | `10` | Default zoom level (0-22) |
| `fitBounds` | `Boolean` | `true` | Automatically adjust map to fit all markers |
| `fitBoundsPadding` | `Number` | `10` | Padding around markers when auto-fitting (in pixels) |
| `fitBoundsMaxZoom` | `Number` | `15` | Maximum zoom level when auto-fitting bounds |
| `controlsVerticalPadding` | `Number` | `20` | Top padding for map controls (in pixels) |
| `controlsHorizontalPadding` | `Number` | `20` | Right padding for map controls (in pixels) |
| `MarkersCollection` | `Slot` | - | The slot where you place your Webflow CMS Collection List |
| `ShowMarkersCollection` | `Boolean` | `true` | Toggle visibility of the CMS collection for editing purposes |

## Technical Implementation

This component showcases several advanced patterns for Webflow Code Components:

- **Custom Hook (`useCMSCollectionItems`)** - Extracts CMS list items from Webflow slots using Shadow DOM slot APIs
- **Custom Hook (`useMapbox`)** - Manages Mapbox GL JS instance lifecycle, marker creation, and bounds fitting
- **Data Attributes** - Reads `data-lat` and `data-lng` attributes from CMS items to position markers
- **Element Cloning** - Clones popup content from CMS elements to display rich HTML in map popups
- **Dynamic CSS Variables** - Uses CSS custom properties for flexible control positioning

## CMS Collection Structure

Your CMS collection should include items with the following structure:

- A wrapper element with class `marker-pin` that has `data-lat` and `data-lng` attributes
- Optional: A child element with class `maker-pop-up` containing HTML content to display in the popup

Example CMS item structure:

```html
<div class="marker-pin" data-lat="40.7128" data-lng="-74.0060">
<div class="maker-pop-up">
<h3>Location Name</h3>
<p>Location description...</p>
</div>
</div>
```
23 changes: 23 additions & 0 deletions cms-map/eslint.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
import js from '@eslint/js'
import globals from 'globals'
import reactHooks from 'eslint-plugin-react-hooks'
import reactRefresh from 'eslint-plugin-react-refresh'
import tseslint from 'typescript-eslint'
import { defineConfig, globalIgnores } from 'eslint/config'

export default defineConfig([
globalIgnores(['dist']),
{
files: ['**/*.{ts,tsx}'],
extends: [
js.configs.recommended,
tseslint.configs.recommended,
reactHooks.configs.flat.recommended,
reactRefresh.configs.vite,
],
languageOptions: {
ecmaVersion: 2020,
globals: globals.browser,
},
},
])
22 changes: 22 additions & 0 deletions cms-map/index.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,22 @@
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<link rel="icon" type="image/svg+xml" href="/vite.svg" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<link href="https://cdn.prod.website-files.com/6937ee7fa021ce3a67acc658/css/cms-map-code-component.webflow.shared.9aeef5480.css" rel="stylesheet" type="text/css"/>
<title>cms-map</title>
</head>
<body>
<div id="root"></div>
<script type="module" src="/src/main.tsx"></script>
<style>
.map-holder{
corner-shape: superellipse(-1.8);
}
.marker-popup-img{
corner-shape: squircle;
}
</style>
</body>
</html>
34 changes: 34 additions & 0 deletions cms-map/package.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,34 @@
{
"name": "cms-map",
"private": true,
"version": "0.0.0",
"type": "module",
"scripts": {
"dev": "vite",
"build": "tsc -b && vite build",
"lint": "eslint .",
"preview": "vite preview"
},
"dependencies": {
"@webflow/data-types": "^1.0.4",
"@webflow/react": "^1.0.4",
"@webflow/webflow-cli": "^1.8.51",
"mapbox-gl": "^3.17.0",
"react": "^19.2.0",
"react-dom": "^19.2.0"
},
"devDependencies": {
"@eslint/js": "^9.39.1",
"@types/node": "^24.10.1",
"@types/react": "^19.2.5",
"@types/react-dom": "^19.2.3",
"@vitejs/plugin-react": "^5.1.1",
"eslint": "^9.39.1",
"eslint-plugin-react-hooks": "^7.0.1",
"eslint-plugin-react-refresh": "^0.4.24",
"globals": "^16.5.0",
"typescript": "~5.9.3",
"typescript-eslint": "^8.46.4",
"vite": "^7.2.4"
}
}
Loading