npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2024 – Pkg Stats / Ryan Hefner

geo-autocomplete-form

v1.0.5

Published

`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.

Downloads

23

Readme

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 Name | Type | Default Value | Description | |--------------------------|--------------------------|---------------------|----------------------------------------------------------------------------------------------------------------------------------------------| | API_KEY | string | undefined | Your Google Maps API Key. Required to load the Places Library. | | onFinish | (address: Address) => void | undefined | Callback function triggered on form submission, returning the selected address information. | | formRowGutter | Gutter or [Gutter, Gutter] | [10, 10] | Gutter size for the layout grid of the form. | | countyColSpan | number | string | 24 | Column span for the country input field. | | cityColSpan | number | string | 24 | Column span for the city input field. | | submitColSpan | number | string | 24 | Column span for the submit button. | | cityClassName | string | undefined | CSS class for the city input field. | | countryClassName | string | undefined | CSS class for the country input field. | | submitClassName | string | undefined | CSS class for the submit button. | | cityStyle | React.CSSProperties | undefined | Inline style for the city input field. | | countryStyle | React.CSSProperties | undefined | Inline style for the country input field. | | submitStyle | React.CSSProperties | undefined | Inline style for the submit button. | | cityPlaceholder | string | 'Select city' | Placeholder text for the city input field. | | countryPlaceholder | string | 'Select country' | Placeholder text for the country input field. | | submitText | string | 'Submit' | Text to display on the submit button. | | loading | boolean | undefined | Shows a loading state if set to true. | | rowWrapperClassName | string | undefined | CSS class for the wrapper row element. | | rowWrapperStyle | React.CSSProperties | undefined | Inline style for the wrapper row element. | | cityColClassName | string | undefined | CSS class for the column containing the city input field. | | cityColStyle | React.CSSProperties | undefined | Inline style for the column containing the city input field. | | countryColClassName | string | undefined | CSS class for the column containing the country input field. | | countryColStyle | React.CSSProperties | undefined | Inline style for the column containing the country input field. | | submitColClassName | string | undefined | CSS class for the column containing the submit button. | | submitColStyle | React.CSSProperties | undefined | Inline style for the column containing the submit button. | | citySkeletonClassName | string | undefined | CSS class for the skeleton loader of the city input field. | | citySkeletonStyle | React.CSSProperties | undefined | Inline style for the skeleton loader of the city input field. | | countrySkeletonClassName | string | undefined | CSS class for the skeleton loader of the country input field. | | countrySkeletonStyle | React.CSSProperties | undefined | Inline style for the skeleton loader of the country input field. | | submitSkeletonClassName | string | undefined | CSS class for the skeleton loader of the submit button. | | submitSkeletonStyle | React.CSSProperties | undefined | Inline style for the skeleton loader of the submit button. |

Address Object

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

| Property | Type | Description | |-----------|----------|---------------------------------------| | name | string | Full formatted address. | | city | string | Name of the selected city. | | country | string | Name of the selected country. | | latitude| number | Latitude coordinate of the location. | | longitude| number| Longitude 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.