Giter Club home page Giter Club logo

react-mapbox-autocomplete's Introduction

Independent geolocation autocomplete component based on Mapbox

Mapbox Geo API

Maintained and Developed By: Localvore Today

The component uses mapbox api to autocompelete cities and states without mapbox maps. It's designed to be extremely light weight and simple to use.

Change Log

version 0.2.3
Upgrade to React es6 class implmentation and updated babel presets

version 0.2.2
Bug fixes for search results when resetSearch is false

version 0.2.0
Add the ability to prepopulate the input field using the query param
Resetting the input after selection is now optional
Added lat, lng, and text to event.target.dataset

Dependencies

Lodash

React 15+

Mapbox Account + API Key

react-mapbox-autocomplete is designed to be agnostic of environment. Works with any data store(redux, flux, etc) and is compiled to vanilla javascript to work with any version of ES.

Installation

npm install react-mapbox-autocomplete

Example(ES6)

Available PropTypes

publicKey:Required(String)

inputClass:Optional(String):Used for passing bootstrap or other classes for input styling

country:Optional(String)

onSuggestionSelect:Required(Func):For handling suggestion selections

query:Optional(String):Pre-populate search field

resetSearch:Optional(Boolean): Default is false. Resets the input field after suggestion select

Retriving Suggestion Information

you can retrive the event data by targeting event.target.dataset.suggestion as seen in the example below.

.search {
  margin-bottom: 1.5rem;
}
import MapboxAutocomplete from 'react-mapbox-autocomplete';

_suggestionSelect(result, lat, lng, text) {
  console.log(result, lat, lng, text)
}

<MapboxAutocomplete publicKey='Your Mapbox Public Key'
                    inputClass='form-control search'
                    onSuggestionSelect={this._suggestionSelect}
                    country='us'
                    resetSearch={false}/>

Styling

You can style the following classes as you see fit.

.react-mapbox-ac-menu {
  width: auto;
  position: absolute;
  z-index: 9999;
  background-color: #fff;
  border: 1px solid #ccc;
  padding-top: 1rem;
  padding-bottom: 1rem;
  margin-top: -1.3rem;
}

.react-mapbox-ac-input {
  margin-bottom: 1.5rem;
}

.react-mapbox-ac-suggestion {
  font-size: 18px;
  margin-bottom: .5rem;
  cursor: pointer;
  padding-left: 1.5rem;
  padding-right: 1.5rem;
}

.react-mapbox-ac-suggestion:hover {
  background-color: #58a;
}

ToDo

  1. Tests
  • Implement JEST
  • Test: each function and render
  1. Add Examples
  • add examples to project in a folder called "Examples"
  1. Add all query params as Props

Contributing

If you would like to contribute to react-mapbox-autocomplete fork the project and submit a pull request.

react-mapbox-autocomplete's People

Contributors

bakedbean avatar donedgardo avatar travisdmathis avatar

Watchers

 avatar

Forkers

autopilot-org

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.