Giter Site home page Giter Site logo

akofman / react-select-places Goto Github PK

View Code? Open in Web Editor NEW
8.0 2.0 7.0 419 KB

๐ŸŒ A Select control for places built from React-Select and Google Places API.

Home Page: http://akofman.github.io/react-select-places

License: MIT License

JavaScript 95.89% CSS 2.78% HTML 1.33%
react react-component react-select google-places

react-select-places's Introduction

React-Select-Places

Travis npm package Coveralls styled with prettier

A Select control for places built from React-Select and Google Places.

Demo & Examples

demo

Live demo: akofman.github.io/react-select-places

To run it locally, clone this repo then run:

npm install
npm run storybook

Then open localhost:6006 in a browser.

Installation

โš ๏ธreact-select is not bundled into this component. You must add it as a dependency of your project in order to use react-select-places.

npm install --save react-select
npm install --save react-select-places

Then you can import react-select-places in your application:

import SelectPlaces from 'react-select-places';

In order to style SelectPlaces, you can import the react-select css:

import 'react-select/dist/react-select.css';

Or you can use styled-component.

Usage

React-Select-Places uses the Google Maps Places API, so you need to include it in the <head> of your HTML:

<!DOCTYPE html>
  <html>
  <head>
    โ€ฆ
    <script src="https://maps.googleapis.com/maps/api/js?key=YOUR_API_KEY&libraries=places"></script>
  </head>
  <body>
    โ€ฆ
  </body>
</html>

It wraps React-Select so that you can use all of its options.

Example:

var SelectPlaces = require('react-select-places');

function logChange(val) {
  console.log("Selected: " + val);
}

<SelectPlaces
  onChange={logChange}
/>

The value retrieved from the parameter of the onChange callback is a PlaceResult.

You also have the possibility to configure the AutocompletionRequest as it is specified in the Google Places API.

Example:

const autocompletionRequest = {
  types: ['(cities)'],
  componentRestrictions: {
    country: 'FR'
  }
};

<SelectPlaces autocompletionRequest={autocompletionRequest} />

A default value can be provided from the value property:

<SelectPlaces value={{ label:'Paris' }} />

The value property can be an object with the label and placeId attributes. If placeId is provided, this component will use the Google Maps Places API in order to retrieve the label to display in the right language. If the place is not retrieved, the provided label will be used.

<SelectPlaces value={{ label:'defaultLabel', placeId:'ChIJpTvG15DL1IkRd8S0KlBVNTI' }} />

It is also possible to provide only the label as a string:

<SelectPlaces value='Paris' />

Contributing

See the CONTRIBUTING.md for information on how to contribute.

License

MIT Licensed. Copyright (c) Alexis Kofman 2017.

react-select-places's People

Contributors

akofman avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.