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

@synapsestudios/google-places-field

v0.3.0

Published

A slightly-modified implementation of React Geosuggest

Downloads

5

Readme

@synapsestudios/google-places-field

A slightly-modified implementation of React Geosuggest.

npm version google-places-field dependencies google-places-field peer dependencies

Demo

A demo is available at https://synapsestudios.github.io/google-places-field/

Usage

Installing via CLI

// yarn
yarn add @synapsestudios/google-places-field

// npm
npm install --save @synapsestudios/google-places-field

Importing JS

import GooglePlaces from '@synapsestudios/google-places-field';

Importing CSS

// Minified, autoprefixed css
import '@synapsestudios/google-places-field/lib/google-places-field.min.css';

// Not-minified, not-autoprefixed css
import '@synapsestudios/google-places-field/lib/google-places-field.css';

Using Stylus

If you are using Stylus you can import the .styl file into your build:

@import '@synapsestudios/google-places-field/lib/google-places-field.styl';

! See the Stylus Variables section below for variables/details.

Using with an ES6 Class and React Component State

import React, { Component } from 'react';
import Script from 'react-load-script';
import GooglePlaces from '@synapsestudios/google-places-field';

import '@synapsestudios/google-places-field/lib/google-places-field.min.css';

class SetStateExample extends Component {
  state = {
    googleApiLoaded: false,
    googleApiError: false,
    result: null,
  };

  onGoogleApiLoaded = () => {
    this.setState({ googleApiLoaded: true });
  };

  onGoogleApiError = error => {
    this.setState({ googleApiError: true });
  };

  onSelect = result => {
    console.log(result);
    this.setState(result);
  };

  render() {
    const { googleApiLoaded, googleApiError } = this.state;
    return (
      <div>
       {!googleApiLoaded
          ? <Script
            url="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places"
            onLoad={this.onGoogleApiLoaded}
            onError={this.onGoogleApiError}
          /> : null}
        {googleApiLoaded
          ? <GooglePlaces onSelect={this.onSelect} />
          : null}
        {googleApiError
          ? <div>An error occured while loading the Google Places API</div>
          : null}
      </div>
    );
  }
}

export default SetStateExample;

API

Required Props

onSelect: (required)

onSelect is the callback function invoked when a user selects an address from the Google Places dropdown. onSelect returns an object with formatted location data as well as the original Google Places data object.

onSelect: PropTypes.func.isRequired,

Additional Props

Any additional props will be passed thru directly to the React Geosuggest component. See their documentation for additional props/usage.

Stylus Variables

google-places-field comes with a set of stylus variables that can be overridden to add your own project-specific theming, as shown below:

/* Theming by overriding default stylus variables with your projects colors */

$google-places-field--border-color = #b1c1c5;
$google-places-field--box-shadow = 0 2px 5px 0 rgba(0,0,0,0.16), 0 2px 10px 0 rgba(0,0,0,0.12);

@import '@synapsestudios.com/google-places-field/css/google-places-field.styl';

Contributing

To run the project on your own computer:

  • Clone this repository
  • yarn install or npm install
  • yarn run storybook or npm run storybook
  • Visit http://localhost:5000/
  • Changes made to files in the src directory should immediately compile and be visible in your browser.