Giter Club home page Giter Club logo

react-mui-mapbox-geocoder's Introduction

react-mui-mapbox-geocoder

A Material UI Autosuggest'ing Mapbox Geocoder for locating addresses and points of interest.

What Is This?

basically it is a combination of...

@mapbox/react-geocoder

and

material-ui & react-autosuggest

How can I add this to my project?

yarn add react-mui-mapbox-geocoder

or

npm install --save react-mui-mapbox-geocoder

What Does This Component Look Like?

it looks like this...

What does this component look like?

How Can I Use It?

Here are some hints...

import MatGeocoder from 'react-mui-mapbox-geocoder'

...

const geocoderApiOptions = {
  country: 'us',
  proximity: {longitude: -121.0681, latitude: 38.9197},
  bbox: [-123.8501, 38.08, -117.5604, 39.8735]
}

const onSelectHandler = (result) => {
  // Go to result handler.
}


return (
  ...
  <MatGeocoder
    inputPlaceholder="Search Address"
    accessToken={MAPBOX_TOKEN}
    onSelect={onSelectHandler}
    showLoader={true}
    {...geocoderApiOptions}
  />
)

...

Are There Any Other Props I Can Pass?

Yes.

endpoint: string, default "'https://api.mapbox.com'"
source: string, default "'mapbox.places'"
inputPlaceholder: string, default "'Search'"
accessToken: (required) string
proximity: (optional) {longitude: number, latitude: number}
country: (optional) string, eg. 'us'
bbox: (optional) [number, number, number, number]
types: (optional) string,
limit: (optional) number,
autocomplete: (optional) boolean
language: (optional) string,
showLoader: boolean, default "true"
focusOnMount: boolean, default "false"
onSelect: (required), (selectedFeature) => {...},
onSuggest: (optional), (suggestedResults) => {...}

Can I use a Material UI TextField instead of a raw Input?

Yes.

To replace the <InputBase /> component by a <TextField />, specify an object using the TextFieldProps property. This object can be empty: as long as it is not undefined, a <TextField /> will be used.

Please note that if you use the property TextFieldProps, the property inputProps will be completely ignored. To specify the inputProps of the <TextField />, do:

textFieldProps={{
	inputProps: {
		...
	}	
}}

More

See Mapbox API Docs for more information.

react-mui-mapbox-geocoder's People

Contributors

clementlize avatar dependabot[bot] avatar pcwa-ahendricks avatar wheredoesyourmindgo avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar

react-mui-mapbox-geocoder's Issues

[Feature]: let the user chose between a <InputBase /> and a <TextField />

Hello again!

Some days ago I identified a feature that I needed for my project, and thought I could make it a merge request for it. I don't know if you get notifications for merge requests, so I am writing an issue too :)

As it is, the component does not have anything to indicate to the user that the field is a field, more than the search icon and the placeholder. So I needed the MUI v4 search field design back (with the underline). And maybe other people would like their input to have a border, like when using the "outlined" variant.

The idea of my implementation is to let the user chose whether they want to use an <InputBase /> or a <TextField />.

The changes I made do not break the component, apart from the removal of the disableUnderline property (which was not used anywhere in the code). Indeed, by default the <InputBase /> is used, and does not have any border or underline. Maybe this removal is not a great thing, I'll let you decide ๐Ÿ˜„

For my use case (in my project), I just have to rename inputProps into textFieldProps, and add "variant: standard" to get the MUI v4 design back.

If you want me to explain more, or want to talk about this feature, feel free :)
#55

UX: text field and cross are too far and cannot make them closer

Hi there, thanks for the library.

I spent one hour on a UI-UX bug and I couldn't make it work. In mobile view, the space between the textflield and the cross is too large. This is due to padding inside the component and I couldn't set them to 0 with the properties I can access.

Here is a picture, a bug part of the address is truncated because of this space.

bug_matgeocoder

Can you make this space a parameter? Thanks !

Add endAdornment to input

Input loses value and autosuggest doesn't work, when I add endAdornment.
My inputTextFieldProps:

inputTextFieldProps={{
variant: 'outlined',
classes: {
root: classes.textField
},
label: "Z",
InputProps: {
endAdornment: <InputAdornment position="end">
<SearchIcon color="action" />
</InputAdornment>
}
}}

I think InputProps are overwritten and loses ref.
Can anyone help how add endAdornment?

Upgrade pkg depency to react v17

Hello, could you please upgrade the dependency of the main package to react v17? I made a pull request with the changes, tested in the demo project, and saw no problem. Thank you!

#52

New feature + better documentation

Hi, I created a merge request last week about a new property and better comments. I don't know if you receive merge request notifications, so here's an issue to say that it's opened and that I'd like you to review it :) #63

Thanks!

Add ref

Is it possible to add ref to this component? It returns error below:

Function components cannot be given refs. Attempts to access this ref will fail. Did you mean to use React.forwardRef()?

How to style default input?

Hey there, thanks for the awesome library!

I'm using material-ui's outlined inputs across my app. Is there a way to specify the type of input I want to use? Or better yet, use my existing (nonfunctioning) styled input with your library?

Screen Shot 2019-03-10 at 9 06 35 AM

Any thoughts on how to fix this? Thanks!

How to target fieldset of input?

Hi there, me again.

Apologies for my ignorance... I'm having a bit of trouble figuring out how to target the fieldset inside of the input style. For me, it has a "NotchedOutline" class.

Screen Shot 2019-03-28 at 8 28 21 PM

More specifically, I need to alter the blue border when the input has focus.

Screen Shot 2019-03-28 at 8 29 37 PM

My code is as follows:
const Geocoder = withStyles({
container: {
backgroundColor: 'inherit',
marginTop: '16px',
},
})(MatGeocoder);

const styles = {
input: {
'&$cssFocused $notchedOutline': {
backgroundColor: 'green'
}
},
textField: {
// backgroundColor: 'blue',
}
};

<Geocoder
inputPlaceholder='City, State'
accessToken={MAPBOX_TOKEN}
onSelect={result => this._handleChange}
showLoader={true}
inputPaperProps={{ square: true }}
suggestionsPaperProps={{
square: true,
}}
inputTextFieldProps={{
variant: 'outlined',
fullWidth: true,
classes: {
root: classes.textField
}
}}
inputClasses={{
root: classes.input
}}
showInputContainer={false}
{...geocoderOptions}
>
</Geocoder>

Thanks for your help!

Place Geocoder outside the map

Hello,

Nice library by the way :)

I wonder if I can set the geocoder in a different place other than the map.
I want to place it for example in a form beside the map.

Upgrade pkg depency to react v17

Hello, could you please upgrade the dependency of the main package to react v17? I made a pull request with the changes, tested in the demo project, and saw no problem. Thank you!

#52

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.