Skip to content

Commit ebbc5e7

Browse files
authored
Merge pull request #76 from mathvaleriano/master
feat: add options to autocomplete constructor
2 parents dde431d + 1747500 commit ebbc5e7

File tree

3 files changed

+34
-7
lines changed

3 files changed

+34
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -32,6 +32,7 @@ A `types` props means type of places in [google place API](https://developers.go
3232
A [componentRestrictions](https://developers.google.com/maps/documentation/javascript/reference#ComponentRestrictions) prop by default is empty.
3333
A [bounds](https://developers.google.com/maps/documentation/javascript/reference#AutocompleteOptions) prop by default is empty.
3434
You also can pass any props you want to the final input. You can also set [fields](https://developers.google.com/maps/documentation/javascript/reference/places-service#PlaceResult) prop if you need extra information, now it defaults to basic data in order to control expenses.
35+
The `options`(optional) prop is the optional configuration to your Autocomplete instance. You can see full options [here](https://developers.google.com/maps/documentation/javascript/places-autocomplete#add_autocomplete)
3536

3637
## Contribution
3738

lib/index.js

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -72,13 +72,15 @@ var ReactGoogleAutocomplete = function (_React$Component) {
7272
bounds = _props.bounds,
7373
apiKey = _props.apiKey,
7474
_props$fields = _props.fields,
75-
fields = _props$fields === undefined ? ['address_components', 'geometry.location', 'place_id', 'formatted_address'] : _props$fields;
75+
fields = _props$fields === undefined ? ['address_components', 'geometry.location', 'place_id', 'formatted_address'] : _props$fields,
76+
_props$options = _props.options,
77+
options = _props$options === undefined ? {} : _props$options;
7678

77-
var config = {
79+
var config = _extends({}, options, {
7880
types: types,
7981
bounds: bounds,
8082
fields: fields
81-
};
83+
});
8284

8385
if (componentRestrictions) {
8486
config.componentRestrictions = componentRestrictions;
@@ -139,8 +141,9 @@ var ReactGoogleAutocomplete = function (_React$Component) {
139141
types = _props2.types,
140142
componentRestrictions = _props2.componentRestrictions,
141143
bounds = _props2.bounds,
144+
options = _props2.options,
142145
apiKey = _props2.apiKey,
143-
rest = _objectWithoutProperties(_props2, ['onPlaceSelected', 'types', 'componentRestrictions', 'bounds', 'apiKey']);
146+
rest = _objectWithoutProperties(_props2, ['onPlaceSelected', 'types', 'componentRestrictions', 'bounds', 'options', 'apiKey']);
144147

145148
return _react2.default.createElement('input', _extends({ ref: 'input' }, rest));
146149
}
@@ -151,11 +154,21 @@ var ReactGoogleAutocomplete = function (_React$Component) {
151154

152155
ReactGoogleAutocomplete.propTypes = {
153156
onPlaceSelected: _propTypes2.default.func,
154-
types: _propTypes2.default.array,
157+
types: _propTypes2.default.arrayOf(_propTypes2.default.string),
155158
componentRestrictions: _propTypes2.default.object,
156159
bounds: _propTypes2.default.object,
157160
fields: _propTypes2.default.array,
158161
inputAutocompleteValue: _propTypes2.default.string,
162+
options: _propTypes2.default.shape({
163+
componentRestrictions: _propTypes2.default.object,
164+
bounds: _propTypes2.default.object,
165+
location: _propTypes2.default.object,
166+
offset: _propTypes2.default.number,
167+
origin: _propTypes2.default.object,
168+
radius: _propTypes2.default.number,
169+
sessionToken: _propTypes2.default.object,
170+
types: _propTypes2.default.arrayOf(_propTypes2.default.string)
171+
}),
159172
apiKey: _propTypes2.default.string
160173
};
161174
exports.default = ReactGoogleAutocomplete;

src/index.js

Lines changed: 15 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,21 @@ import PropTypes from 'prop-types';
44
export default class ReactGoogleAutocomplete extends React.Component {
55
static propTypes = {
66
onPlaceSelected: PropTypes.func,
7-
types: PropTypes.array,
7+
types: PropTypes.arrayOf(PropTypes.string),
88
componentRestrictions: PropTypes.object,
99
bounds: PropTypes.object,
1010
fields: PropTypes.array,
1111
inputAutocompleteValue: PropTypes.string,
12+
options: PropTypes.shape({
13+
componentRestrictions: PropTypes.object,
14+
bounds: PropTypes.object,
15+
location: PropTypes.object,
16+
offset: PropTypes.number,
17+
origin: PropTypes.object,
18+
radius: PropTypes.number,
19+
sessionToken: PropTypes.object,
20+
types: PropTypes.arrayOf(PropTypes.string)
21+
}),
1222
apiKey: PropTypes.string
1323
};
1424

@@ -29,9 +39,11 @@ export default class ReactGoogleAutocomplete extends React.Component {
2939
'geometry.location',
3040
'place_id',
3141
'formatted_address'
32-
]
42+
],
43+
options = {}
3344
} = this.props;
3445
const config = {
46+
...options,
3547
types,
3648
bounds,
3749
fields
@@ -115,6 +127,7 @@ export default class ReactGoogleAutocomplete extends React.Component {
115127
types,
116128
componentRestrictions,
117129
bounds,
130+
options,
118131
apiKey,
119132
...rest
120133
} = this.props;

0 commit comments

Comments
 (0)