1.0.22 • Published 2 months ago

@taida-dream/map-picker v1.0.22

Weekly downloads
-
License
ISC
Repository
-
Last release
2 months ago

React Google Map Location

A highly customizable React component library for Google Maps location selection and preview, featuring dark/light mode support, fullscreen capabilities, and seamless Tailwind CSS integration. Built with TypeScript for robust type safety and modern development practices.

Installation

npm install @taida-dream/map-picker
# or
yarn add @taida-dream/map-picker

Usage

import React, { useState } from 'react';
import { GoogleMapSelector, GoogleMapPreview } from '@taida-dream/map-picker';


function App() {
  const [selectedCoords, setSelectedCoords] = useState<{ lat: number; lng: number } | null>(null);

  return (
    <div>
      <h2>Map Selector</h2>
      <GoogleMapSelector
        apiKey="YOUR_GOOGLE_MAPS_API_KEY"
        onLocationSelect={setSelectedCoords}
        selectedLocation={selectedCoords}
        // Example customization:
        // showSaveCancel={true}
        // saveText="Confirm Location"
        // defaultMapMode="light"
      />

      <h2>Preview</h2>
      <GoogleMapPreview
        apiKey="YOUR_GOOGLE_MAPS_API_KEY"
        latitude={selectedCoords?.lat}
        longitude={selectedCoords?.lng}
        // Example customization:
        // height="200px"
        // mapType="satellite"
      />

      {selectedCoords && (
        <p>
          Selected: Lat {selectedCoords.lat.toFixed(6)}, Lng {selectedCoords.lng.toFixed(6)}
        </p>
      )}
    </div>
  );
}

export default App;

API

GoogleMapSelector Props

PropTypeDefaultDescription
apiKeystringnullRequired. Google Maps API Key.
onLocationSelect(coords: Coords | null) => void-Required. Callback on location change(select/deselect).
selectedLocationCoords | nullnullCurrently selected coordinatesto display on the map.
defaultCenterCoords{ lat: 15.3694, lng: 44.1910 } (Sana'a)Initial map center if selectedLocationis not provided.
defaultZoomnumber12The initial zoom level of the map.
heightstring"60vh"Height of the map container(e.g., '500px', '70vh').
widthstring"100%"Width of the map container(e.g., '100%', '600px').
defaultMapMode'dark' | 'light''dark'Sets the initial theme for the map.
showModeTogglebooleantrueShow/hide the dark/light modetoggle button.
showFullscreenTogglebooleantrueShow/hide the fullscreentoggle button.
showLocationButtonbooleantrueShow/hide the "Get my currentlocation" button.
showSaveCancelbooleanfalseShow/hide the Save and Cancel buttons.
showCoordinatesDisplaybooleantrueShow/hide the selected coordinatestext below the map.
saveTextstring"Save Changes"Text for the Save button.
cancelTextstring"Cancel"Text for the Cancel button.
savingTextstring"Saving..."Text for Save buttonwhile isSaving is true.
onSave() => void-Callback executed when Savebutton is clicked.
onCancel() => void-Callback executed when Cancelbutton is clicked.
isSavingbooleanfalseIf true, disables Save/Canceland shows savingText.
modeToggleButtonColorstring"#ffffff"Text/Icon color for the modetoggle button.
modeToggleButtonBgstring"rgba(31, 41, 55, 0.8)"Background color for the modetoggle button.
saveButtonColorstring"#ffffff"Text color for the Save button.
saveButtonBgstring"#374151"Background color for the Save button.
cancelButtonColorstring"#f3f4f6"Text color for the Cancel button.
cancelButtonBgstring"#374151"Background color for the Cancel button.
fullscreenButtonColorstring"#ffffff"Text/Icon color for thefullscreen button.
fullscreenButtonBgstring"rgba(31, 41, 55, 0.8)"Background color for thefullscreen button.
locationButtonColorstring"#ffffff"Text/Icon color for thelocation button.
locationButtonBgstring"rgba(31, 41, 55, 0.8)"Background color for thelocation button.
containerClassNamestring""Custom CSS classes for themain map container div.
modeToggleButtonClassNamestring""Custom CSS classes for themode toggle button.
saveButtonClassNamestring""Custom CSS classes for the Save button.
cancelButtonClassNamestring""Custom CSS classes for the Cancel button.
fullscreenButtonClassNamestring""Custom CSS classes for thefullscreen button.
locationButtonClassNamestring""Custom CSS classes for thelocation button.
customLoadingIndicatorReact.ReactNode-Replace default loading spinnerwith a custom component.
customErrorDisplay(error: string \| null) => React.ReactNode-Render custom componentwhen an error occurs.
customModeToggleReact.ReactNode-Replace default mode togglewith a custom component.
customFullscreenToggleReact.ReactNode-Replace default fullscreen buttonwith a custom component.
customLocationButtonReact.ReactNode-Replace default location buttonwith a custom component.
customSaveButtonReact.ReactNode-Replace default Save buttonwith a custom component.
customCancelButtonReact.ReactNode-Replace default Cancel buttonwith a custom component.
customCoordinatesDisplay(coords: Coords \| null) => React.ReactNode-Render custom componentto display selected coords.
modeToggleStyleCSSProperties{ position: 'absolute', top: '0.5rem', left: '0.5rem', zIndex: 10 }Inline styles for the modetoggle button's position.
saveButtonStyleCSSProperties{ position: 'absolute', top: '0.5rem', right: '0.5rem', zIndex: 10 }Inline styles for the Savebutton's position.
cancelButtonStyleCSSProperties{ position: 'absolute', top: '0.5rem', right: 'calc(0.5rem + 130px + 8px)', zIndex: 10 }Inline styles for the Cancelbutton's position.
locationButtonStyleCSSProperties{ position: 'absolute', bottom: '3.5rem', right: '2rem', zIndex: 10 }Inline styles for the locationbutton's position.
fullscreenToggleStyleCSSProperties{ position: 'absolute', bottom: '1rem', right: '2rem', zIndex: 10 }Inline styles for the fullscreenbutton's position.

Note on Coords type: { lat: number; lng: number }

GoogleMapPreview Props

PropTypeDefaultDescription
apiKeystring \| nullnullRequired. Google Maps API Key.Displays error if missing.
latitudenumber \| string \| nullnullLatitude for the map preview center.Can be number or "-".
longitudenumber \| string \| nullnullLongitude for the map preview center.Can be number or "-".
heightstring"150px"Height of the preview container(e.g., '100px', '20vh').
widthstring"100%"Width of the preview container(e.g., '100%', '300px').
zoomnumber14Zoom level for the static mapimage (0-21).
mapType'roadmap' \| 'satellite' \| 'hybrid' \| 'terrain''roadmap'Map tiles type for the preview image.
containerClassNamestring""Custom CSS classes for the mainpreview container div.
placeholderTextClassNamestring""Custom CSS classes for placeholder text(p tags) shown when key/coordsare missing.
apiKeyMissingPlaceholderReact.ReactNode-Custom component/node to displaywhen the API key is missing.
noCoordsPlaceholderReact.ReactNode-Custom component/node to displaywhen no coordinates are provided.

License

ISC