### Setup Development Environment Source: https://github.com/barikoi/barikoi-map-widget/blob/main/CONTRIBUTING.md Initial commands to clone the repository and install project dependencies. ```bash git clone https://github.com/barikoi/barikoi-map-widget.git cd barikoi-map-widget npm install ``` -------------------------------- ### Provider Setup Source: https://github.com/barikoi/barikoi-map-widget/blob/main/README.md Wrap your application components with BarikoiMapProvider to enable widget functionalities. ```APIDOC ## Usage Wrap your components with the BarikoiMapProvider to provide the necessary context for the widget: ```tsx import React from 'react'; import { BarikoiMapProvider } from 'barikoi-map-widget'; import BarikoiAutocompleteComponent from './BarikoiAutoCompleteComponent'; import BarikoiMapComponent from './BarikoiMapComponent'; const App = () => { return ( ); }; export default App; ``` ``` -------------------------------- ### Manage Storybook Source: https://github.com/barikoi/barikoi-map-widget/blob/main/DEVELOPMENT.md Commands to start the Storybook development server or build it for production. ```bash npm run storybook ``` ```bash npm run build-storybook ``` -------------------------------- ### Install Barikoi Map Widget Source: https://github.com/barikoi/barikoi-map-widget/blob/main/README.md Command to install the library via npm. ```bash npm install barikoi-map-widget ``` -------------------------------- ### Installation Source: https://github.com/barikoi/barikoi-map-widget/blob/main/README.md Install the barikoi-map-widget library using npm. ```APIDOC ## Installation To install the `barikoi-map-widget` library, run: ```bash npm install barikoi-map-widget ``` ``` -------------------------------- ### Perform Local Testing Source: https://github.com/barikoi/barikoi-map-widget/blob/main/DEVELOPMENT.md Steps to build the package, create a tarball, and install it in a local project for testing. ```bash npm run build ``` ```bash npm pack ``` ```bash npm install /path/to/barikoi-map-widget-*.tgz ``` -------------------------------- ### Style BarikoiAutocomplete with CSS Source: https://github.com/barikoi/barikoi-map-widget/blob/main/README.md Example CSS definitions for customizing the appearance of the autocomplete component. ```css /* customStyles.css */ .custom-container { border: 2px solid blue; border-radius: 6px; } .custom-input { font-size: 16px; border: 1px solid #aaa; } .custom-dropdown { border: 1px solid green; background-color: #f9fafb; } .custom-dropdown-item { padding: 12px; font-weight: bold; } .custom-no-result { color: red; font-style: italic; } ``` -------------------------------- ### Control Prop Structure Example Source: https://github.com/barikoi/barikoi-map-widget/blob/main/README.md Configure various map controls like geolocate, fullscreen, navigation, scale, and marker. You can enable or disable them and specify their positions. ```tsx const controls = { geolocate: { enabled: true, position: 'top-left' }, fullscreen: { enabled: true, position: 'top-right' }, navigation: { enabled: true, position: 'bottom-left' }, scale: { enabled: true, position: 'bottom-right' }, marker: { enabled: true, url: 'path-to-marker-icon' }, }; ``` -------------------------------- ### Define PlaceType Structure Source: https://context7.com/barikoi/barikoi-map-widget/llms.txt Defines the TypeScript interface for place objects returned by the Barikoi API and provides an example object instance. ```typescript type PlaceType = { id: number | string; // Unique identifier for the place name: string; // Display name of the place longitude: string; // Longitude coordinate latitude: string; // Latitude coordinate address: string; // Full address string city: string; // City name area: string; // Area/neighborhood name postCode: number; // Postal code pType: string; // Primary type classification subType: string; // Sub-type classification district: string; // District name uCode: string; // Unique Barikoi code }; // Example place object from API const examplePlace: PlaceType = { id: 123456, name: "Banani Road 11", longitude: "90.4025", latitude: "23.7937", address: "Road 11, Banani, Dhaka 1213", city: "Dhaka", area: "Banani", postCode: 1213, pType: "Road", subType: "Residential Road", district: "Dhaka", uCode: "BKOI-ABC123" }; ``` -------------------------------- ### Release and Publish Source: https://github.com/barikoi/barikoi-map-widget/blob/main/CONTRIBUTING.md Commands to update the version, build the production bundle, and publish to npm. ```bash npm run update-version npm run build npm publish ``` -------------------------------- ### Verify Changes Locally Source: https://github.com/barikoi/barikoi-map-widget/blob/main/CONTRIBUTING.md Build the project and create a tarball to test the package in a separate project. ```bash npm run build npm pack # creates .tgz file # In test project: npm install /path/to/barikoi-map-widget-*.tgz ``` -------------------------------- ### Publish to NPM Source: https://github.com/barikoi/barikoi-map-widget/blob/main/DEVELOPMENT.md Commands required to authenticate, update versions, build, and publish the package to the NPM registry. ```bash npm login ``` ```bash npm run update-version ``` ```bash npm run build ``` ```bash npm publish ``` -------------------------------- ### Initialize BarikoiMapProvider Source: https://context7.com/barikoi/barikoi-map-widget/llms.txt Wrap your application components with the BarikoiMapProvider to enable state synchronization between the autocomplete and map components. ```tsx import React from 'react'; import { BarikoiMapProvider } from 'barikoi-map-widget'; import BarikoiAutocompleteComponent from './BarikoiAutocompleteComponent'; import BarikoiMapComponent from './BarikoiMapComponent'; const App = () => { return ( {/* All Barikoi components must be children of the provider */} ); }; export default App; ``` -------------------------------- ### Initialize Barikoi Map Provider Source: https://github.com/barikoi/barikoi-map-widget/blob/main/README.md Wrap the application components with BarikoiMapProvider to enable context for the widget. ```ts import React from 'react'; import { BarikoiMapProvider } from 'barikoi-map-widget'; import BarikoiAutocompleteComponent from './BarikoiAutoCompleteComponent'; import BarikoiMapComponent from './BarikoiMapComponent'; const App = () => { return ( ); }; export default App; ``` -------------------------------- ### View Project Structure Source: https://github.com/barikoi/barikoi-map-widget/blob/main/DEVELOPMENT.md Displays the directory layout of the Barikoi Map Widget repository. ```plaintext barikoi-map-widget/ ├── .husky/ │ ├── pre-commit │ └── commit-msg ├── .storybook/ │ ├── main.ts │ └── preview.ts ├── example/ │ ├── App.tsx │ └── BarikoiMapWidget.tsx ├── src/ │ ├── components/ │ │ ├── BarikoiAutocomplete.tsx │ │ ├── BarikoiMap.tsx │ │ └── index.ts │ ├── contexts/ │ │ ├── BarikoiMapProvider.tsx │ │ └── hooks/ │ │ ├── useAutocomplete.ts │ │ ├── useMap.ts │ │ └── index.ts │ ├── stories/ │ │ └── BarikoiMap.stories.tsx │ ├── types/ │ │ └── index.ts │ └── index.ts ├── package.json ├── tsconfig.json ├── tsup.config.ts ├── CONTRIBUTING.md ├── DEVELOPMENT.md └── ... ``` -------------------------------- ### Implement BarikoiAutocomplete Source: https://context7.com/barikoi/barikoi-map-widget/llms.txt Integrate the search input field with real-time suggestions. Requires a valid Barikoi API key and supports custom CSS classes for styling. ```tsx import { BarikoiAutocomplete } from 'barikoi-map-widget'; const BarikoiAutocompleteComponent = () => { const BARIKOI_API_KEY = 'YOUR_BARIKOI_API_KEY'; return (

Search Address

); }; // Custom CSS styling // .custom-container { width: 400px; position: relative; } // .custom-input { padding: 10px; font-size: 14px; border: 1px solid #ccc; border-radius: 4px; } // .custom-dropdown { border: 1px solid #ccc; border-radius: 4px; box-shadow: 0 4px 8px rgba(0,0,0,0.1); } // .custom-dropdown-item { padding: 10px; cursor: pointer; } // .custom-no-result { padding: 10px; color: #999; } export default BarikoiAutocompleteComponent; ``` -------------------------------- ### Configure BarikoiMap Source: https://context7.com/barikoi/barikoi-map-widget/llms.txt Render an interactive map with configurable controls and initial view state. Ensure the map container has defined dimensions via CSS. ```tsx import { BarikoiMap } from 'barikoi-map-widget'; const BarikoiMapComponent = () => { const BARIKOI_API_KEY = 'YOUR_BARIKOI_API_KEY'; const initialViewState = { longitude: 90.36402, // Dhaka, Bangladesh latitude: 23.823731, minZoom: 4, maxZoom: 30, zoom: 16 }; return ( ); }; // Required CSS for map container // .map-container { width: 100%; height: 100vh; } export default BarikoiMapComponent; ``` -------------------------------- ### Implement BarikoiAutocomplete Component Source: https://github.com/barikoi/barikoi-map-widget/blob/main/README.md Basic implementation of the autocomplete search component with custom class name overrides. ```tsx import { BarikoiAutocomplete } from 'barikoi-map-widget'; const BarikoiAutocompleteComponent = () => { return (

Search

); }; export default BarikoiAutocompleteComponent; ``` -------------------------------- ### useMap Hook Source: https://context7.com/barikoi/barikoi-map-widget/llms.txt Provides access to map-related state managed by BarikoiMapProvider. Exposes zoom level, center point coordinates, and marker data with their setter functions for programmatic map control. ```APIDOC ## useMap Hook ### Description The `useMap` hook provides access to the map-related state managed by `BarikoiMapProvider`. It exposes the current zoom level, center point coordinates, and marker data along with their setter functions for programmatic map control. ### Usage ```tsx import { useEffect } from 'react'; import { useAutocomplete, useMap } from 'barikoi-map-widget'; const MapController = () => { const { selectedPlace } = useAutocomplete(); const { zoomLevel, setZoomLevel, centerPoint, setCenterPoint, markerData, setMarkerData } = useMap(); // Sync map center with selected place from autocomplete useEffect(() => { if (selectedPlace?.latitude && selectedPlace?.longitude) { setCenterPoint({ lat: parseFloat(selectedPlace.latitude), lng: parseFloat(selectedPlace.longitude) }); } }, [selectedPlace, setCenterPoint]); const handleGoToDhaka = () => { setCenterPoint({ lat: 23.8103, lng: 90.4125 }); }; return (

Current Center: {centerPoint.lat}, {centerPoint.lng}

Zoom Level: {zoomLevel}

); }; export default MapController; ``` ### State Variables Exposed - **zoomLevel** (number): Current zoom level. - **setZoomLevel** (function): Function to set zoom level. - **centerPoint** ({ lat: number, lng: number }): Current center coordinates. - **setCenterPoint** (function): Function to set center point. - **markerData** (array): Array of marker data. - **setMarkerData** (function): Function to set marker data. ``` -------------------------------- ### useAutocomplete Hook Source: https://context7.com/barikoi/barikoi-map-widget/llms.txt Provides access to autocomplete-related state managed by BarikoiMapProvider. Exposes search text, selected place, suggestions, and loading state with their setter functions. ```APIDOC ## useAutocomplete Hook ### Description The `useAutocomplete` hook provides access to the autocomplete-related state managed by `BarikoiMapProvider`. It exposes the current search text, selected place, suggestions list, and loading state along with their setter functions for custom implementations. ### Usage ```tsx import { useAutocomplete } from 'barikoi-map-widget'; const CustomAutocompleteDisplay = () => { const { searchedPlace, setSearchedPlace, selectedPlace, setSelectedPlace, suggestions, setSuggestions, isAutocompleteLoading, setIsAutocompleteLoading } = useAutocomplete(); return (

Searching for: {searchedPlace}

Loading: {isAutocompleteLoading ? 'Yes' : 'No'}

Suggestions count: {suggestions.length}

{selectedPlace && (

Selected Place:

Name: {selectedPlace.name}

Address: {selectedPlace.address}

Coordinates: {selectedPlace.latitude}, {selectedPlace.longitude}

Area: {selectedPlace.area}

City: {selectedPlace.city}

)}
); }; export default CustomAutocompleteDisplay; ``` ### State Variables Exposed - **searchedPlace** (string): Current search input value. - **setSearchedPlace** (function): Function to update search input. - **selectedPlace** (object): Currently selected place object. - **setSelectedPlace** (function): Function to set selected place. - **suggestions** (array): Array of autocomplete suggestions. - **setSuggestions** (function): Function to update suggestions. - **isAutocompleteLoading** (boolean): Boolean indicating loading state. - **setIsAutocompleteLoading** (function): Function to set loading state. ``` -------------------------------- ### BarikoiAutocomplete Component Source: https://github.com/barikoi/barikoi-map-widget/blob/main/README.md The BarikoiAutocomplete component provides a customizable search input with autocomplete suggestions. ```APIDOC ## BarikoiAutoComplete The **BarikoiAutoComplete** component is a customizable search input field with real-time autocomplete suggestions fetched from the **Barikoi API**. It supports **debounced search**, **smooth dropdown animations**, and allows **custom styling** via `className` props. ### Basic Example ```tsx import { BarikoiAutocomplete } from 'barikoi-map-widget'; const BarikoiAutocompleteComponent = () => { return (

Search

); }; export default BarikoiAutocompleteComponent; ``` ### Props | **Prop Name** | **Type** | **Required** | **Description** | | ------------- | -------- | ------------ | --------------------------------------------------------------- | | `apiKey` | `string` | ✅ Yes | Your **Barikoi API key** for fetching autocomplete suggestions. | | `className` | `object` | ❌ No | Object to override default styles using CSS class names. | ### Class Name Object Structure | **Key** | **Type** | **Description** | | ----------------- | -------- | ------------------------------------- | | `container` | `string` | Class for the main container. | | `input` | `string` | Class for the input field. | | `dropdown` | `string` | Class for the dropdown container. | | `dropdownVisible` | `string` | Class for the dropdown visibility. | | `dropdownItem` | `string` | Class for each dropdown item. | | `noResult` | `string` | Class for "No Results Found" message. | | `clearButton` | `string` | Class for clear button. | ### Styling The component uses **default inline styles** but allows **className** overrides. Below is an example of CSS customizations: ```css /* customStyles.css */ .custom-container { border: 2px solid blue; border-radius: 6px; } .custom-input { font-size: 16px; border: 1px solid #aaa; } .custom-dropdown { border: 1px solid green; background-color: #f9fafb; } .custom-dropdown-item { padding: 12px; font-weight: bold; } .custom-no-result { color: red; font-style: italic; } ``` ### State Management The BarikoiAutoComplete component uses the following state variables to manage its internal state: - `searchedPlace`: Tracks the current search input value. - `setSearchedPlace`: A function to update the searchedPlace state. - `selectedPlace`: Stores the place that the user has selected from the autocomplete suggestions. - `setSelectedPlace`: A function to update the selectedPlace state. - `suggestions`: Contains the list of autocomplete suggestions fetched from the API. - `setSuggestions`: A function to update the suggestions state. - `isAutocompleteLoading`: A boolean that indicates whether the autocomplete data is being fetched. - `setIsAutocompleteLoading`: A function to update the isAutocompleteLoading state. ``` -------------------------------- ### Integrate Barikoi Map and Autocomplete in React Source: https://context7.com/barikoi/barikoi-map-widget/llms.txt Connects the autocomplete search component with the map view using the BarikoiMapProvider and custom hooks. Requires a valid Barikoi API key and React 18+. ```tsx import { useEffect } from 'react'; import { BarikoiMapProvider, BarikoiAutocomplete, BarikoiMap, useAutocomplete, useMap } from 'barikoi-map-widget'; // Component that connects autocomplete and map const BarikoiMapWidget = () => { const { selectedPlace } = useAutocomplete(); const { setCenterPoint } = useMap(); const BARIKOI_API_KEY = 'YOUR_BARIKOI_API_KEY'; const initialViewState = { longitude: 90.36402, latitude: 23.823731, minZoom: 4, maxZoom: 30, zoom: 16 }; // Update map center when a place is selected useEffect(() => { if (selectedPlace?.latitude && selectedPlace?.longitude) { setCenterPoint({ lat: parseFloat(selectedPlace.latitude), lng: parseFloat(selectedPlace.longitude) }); } }, [selectedPlace, setCenterPoint]); return (
{selectedPlace && (

Selected Location

Address: {selectedPlace.address}

Area: {selectedPlace.area}

City: {selectedPlace.city}

Coordinates: {selectedPlace.latitude}, {selectedPlace.longitude}

)}
); }; // Main App with Provider wrapper const App = () => { return ( ); }; export default App; // CSS required // .map-container { width: 100%; height: 100%; min-height: 500px; } ``` -------------------------------- ### Basic Barikoi Map Widget Usage Source: https://github.com/barikoi/barikoi-map-widget/blob/main/README.md Integrate the BarikoiMap component into your React application. Ensure you replace 'YOUR_BARIKOI_API_KEY' with your actual API key and adjust the initial view state and map style as needed. ```tsx import { BarikoiMap } from 'barikoi-map-widget'; const BarikoiMapComponent = () => { const BARIKOI_API_KEY = 'YOUR_BARIKOI_API_KEY'; // Replace with your actual API key const initialViewState = { longitude: 90.36402, latitude: 23.823731, minZoom: 4, maxZoom: 30, zoom: 16, }; return ( ); }; export default BarikoiMapComponent; ``` -------------------------------- ### BarikoiMap Component Source: https://github.com/barikoi/barikoi-map-widget/blob/main/README.md The BarikoiMap component is the primary interface for rendering the map. It requires an API key and allows for extensive customization of controls and styles. ```APIDOC ## BarikoiMap Component ### Description The BarikoiMap component renders an interactive map using the Barikoi service. It supports various controls such as geolocating, fullscreen toggles, and custom markers. ### Props - **apiKey** (string) - Required - Your Barikoi API key. - **initialViewState** (object) - Optional - Initial map view state (longitude, latitude, zoom, minZoom, maxZoom). - **controls** (object) - Optional - Configuration for map controls (geolocate, fullscreen, navigation, scale, marker). - **mapStyle** (string) - Optional - The visual style of the map (e.g., 'osm-liberty', 'barikoi-dark'). - **className** (string) - Required - CSS class name for the container. ### Request Example ``` -------------------------------- ### BarikoiMap Component Source: https://github.com/barikoi/barikoi-map-widget/blob/main/README.md The BarikoiMap component renders a map with customizable controls and view settings. ```APIDOC ## BarikoiMap The **BarikoiMap** component is a customizable React component designed to render a map using the Barikoi Maps service. It provides several map controls, such as geolocation, fullscreen mode, and scale controls, and allows for dynamic positioning of a marker. The map’s initial view state and style are customizable, and the component provides an API key to integrate with Barikoi’s map services. ``` -------------------------------- ### Use Autocomplete Hook for Custom Display Source: https://context7.com/barikoi/barikoi-map-widget/llms.txt Use the useAutocomplete hook to access and manage autocomplete state, including search text, selected place, suggestions, and loading status. This is useful for building custom UI components that display search results or interact with selected locations. ```tsx import { useAutocomplete } from 'barikoi-map-widget'; const CustomAutocompleteDisplay = () => { const { searchedPlace, setSearchedPlace, selectedPlace, setSelectedPlace, suggestions, setSuggestions, isAutocompleteLoading, setIsAutocompleteLoading } = useAutocomplete(); return (

Searching for: {searchedPlace}

Loading: {isAutocompleteLoading ? 'Yes' : 'No'}

Suggestions count: {suggestions.length}

{selectedPlace && (

Selected Place:

Name: {selectedPlace.name}

Address: {selectedPlace.address}

Coordinates: {selectedPlace.latitude}, {selectedPlace.longitude}

Area: {selectedPlace.area}

City: {selectedPlace.city}

)}
); }; export default CustomAutocompleteDisplay; ``` -------------------------------- ### CSS for Map Container Source: https://github.com/barikoi/barikoi-map-widget/blob/main/README.md Apply this CSS to style the map container. Adjust width and height to fit your layout requirements. ```css .map-container { width: 100%; height: 100vh; } ``` -------------------------------- ### Use Map Hook for Programmatic Map Control Source: https://context7.com/barikoi/barikoi-map-widget/llms.txt The useMap hook provides access to map state like zoom level and center coordinates, along with functions to update them. It also exposes marker data and its setter. This hook is essential for controlling map behavior programmatically, such as centering the map on a selected place or adjusting zoom. ```tsx import { useEffect } from 'react'; import { useAutocomplete, useMap } from 'barikoi-map-widget'; const MapController = () => { const { selectedPlace } = useAutocomplete(); const { zoomLevel, setZoomLevel, centerPoint, setCenterPoint, markerData, setMarkerData } = useMap(); // Sync map center with selected place from autocomplete useEffect(() => { if (selectedPlace?.latitude && selectedPlace?.longitude) { setCenterPoint({ lat: parseFloat(selectedPlace.latitude), lng: parseFloat(selectedPlace.longitude) }); } }, [selectedPlace, setCenterPoint]); const handleGoToDhaka = () => { setCenterPoint({ lat: 23.8103, lng: 90.4125 }); }; return (

Current Center: {centerPoint.lat}, {centerPoint.lng}

Zoom Level: {zoomLevel}

); }; export default MapController; ``` === COMPLETE CONTENT === This response contains all available snippets from this library. No additional content exists. Do not make further requests.