Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

geo-autocomplete-form

Package Overview
Dependencies
Maintainers
0
Versions
6
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

geo-autocomplete-form

`GeoAutocompleteForm` is a React component that allows users to autofill geolocation information based on the input of a city and country. It utilizes the Google Maps API (Places Library) and Ant Design for UI elements.

  • 1.0.5
  • latest
  • Source
  • npm
  • Socket score

Version published
Maintainers
0
Created
Source

GeoAutocompleteForm

GeoAutocompleteForm is a React component that allows users to autofill geolocation information based on the input of a city and country. It utilizes the Google Maps API (Places Library) and Ant Design for UI elements.

Features

  • Autofill suggestions for cities and countries.
  • Uses Google Maps API (Places Library) to fetch geolocation data.
  • Displays city and country input fields with autocompletion and suggestions.
  • Returns an address object containing city, country, latitude, and longitude upon submission.
  • Customizable styles and placeholders for each field.

Installation

  1. Install Ant Design and React Google Maps API.
yarn add antd @react-google-maps/api
  1. Get a Google Maps API key with access to the "Places" library.

Props

AutoCompleteComponentProps

Prop NameTypeDefault ValueDescription
API_KEYstringundefinedYour Google Maps API Key. Required to load the Places Library.
onFinish(address: Address) => voidundefinedCallback function triggered on form submission, returning the selected address information.
formRowGutterGutter or [Gutter, Gutter][10, 10]Gutter size for the layout grid of the form.
countyColSpan`numberstring`24
cityColSpan`numberstring`24
submitColSpan`numberstring`24
cityClassNamestringundefinedCSS class for the city input field.
countryClassNamestringundefinedCSS class for the country input field.
submitClassNamestringundefinedCSS class for the submit button.
cityStyleReact.CSSPropertiesundefinedInline style for the city input field.
countryStyleReact.CSSPropertiesundefinedInline style for the country input field.
submitStyleReact.CSSPropertiesundefinedInline style for the submit button.
cityPlaceholderstring'Select city'Placeholder text for the city input field.
countryPlaceholderstring'Select country'Placeholder text for the country input field.
submitTextstring'Submit'Text to display on the submit button.
loadingbooleanundefinedShows a loading state if set to true.
rowWrapperClassNamestringundefinedCSS class for the wrapper row element.
rowWrapperStyleReact.CSSPropertiesundefinedInline style for the wrapper row element.
cityColClassNamestringundefinedCSS class for the column containing the city input field.
cityColStyleReact.CSSPropertiesundefinedInline style for the column containing the city input field.
countryColClassNamestringundefinedCSS class for the column containing the country input field.
countryColStyleReact.CSSPropertiesundefinedInline style for the column containing the country input field.
submitColClassNamestringundefinedCSS class for the column containing the submit button.
submitColStyleReact.CSSPropertiesundefinedInline style for the column containing the submit button.
citySkeletonClassNamestringundefinedCSS class for the skeleton loader of the city input field.
citySkeletonStyleReact.CSSPropertiesundefinedInline style for the skeleton loader of the city input field.
countrySkeletonClassNamestringundefinedCSS class for the skeleton loader of the country input field.
countrySkeletonStyleReact.CSSPropertiesundefinedInline style for the skeleton loader of the country input field.
submitSkeletonClassNamestringundefinedCSS class for the skeleton loader of the submit button.
submitSkeletonStyleReact.CSSPropertiesundefinedInline style for the skeleton loader of the submit button.

Address Object

The Address object returned in the onFinish callback contains the following properties:

PropertyTypeDescription
namestringFull formatted address.
citystringName of the selected city.
countrystringName of the selected country.
latitudenumberLatitude coordinate of the location.
longitudenumberLongitude coordinate of the location.

Example Usage

import React from 'react';
import GeoAutocompleteForm from './GeoAutocompleteForm';

const MyComponent = () => {
  const handleFinish = (address) => {
    console.log('Selected Address:', address);
  };

  return (
    <GeoAutocompleteForm 
      API_KEY="YOUR_GOOGLE_MAPS_API_KEY" 
      onFinish={handleFinish} 
    />
  );
};

export default MyComponent;

Error Handling

  • If the API_KEY is missing, the component will display a message asking the user to provide a valid Google Maps API key.
  • If there is a failure to load the Google Maps API, it will display an error message.

Skeleton States

Skeletons are displayed while the Google Maps API is loading or if the loading prop is set to true. You can customize the skeleton styles with the citySkeletonClassName, countrySkeletonClassName, and submitSkeletonClassName props.

License

This project is licensed under the MIT License.

Keywords

FAQs

Package last updated on 06 Oct 2024

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc