-
Notifications
You must be signed in to change notification settings - Fork 5
Enhance CMSSlider component with improved accessibility features #10
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
viratatwebflow
wants to merge
4
commits into
Webflow-Examples:main
Choose a base branch
from
viratatwebflow:cms-map
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
Show all changes
4 commits
Select commit
Hold shift + click to select a range
3220954
Enhance CMSSlider component with improved accessibility features
viratatwebflow 79217b6
Update README.md for CMS Map component with enhanced features and set…
viratatwebflow 554e816
Updated README
viratatwebflow 4867d84
Added CMS Map section to README with detailed features and integratio…
viratatwebflow File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| Original file line number | Diff line number | Diff line change |
|---|---|---|
| @@ -0,0 +1 @@ | ||
| VITE_MAP_KEY=your_mapbox_api_key_here.example | ||
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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? |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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. | ||
|
|
||
|  | ||
|
|
||
| ## 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> | ||
| ``` |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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, | ||
| }, | ||
| }, | ||
| ]) |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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> |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| 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" | ||
| } | ||
| } |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
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?
There was a problem hiding this comment.
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