Skip to content

Commit 63add4a

Browse files
authored
Merge branch 'master' into master
2 parents 30ed6a0 + a4aca63 commit 63add4a

File tree

3 files changed

+36
-7
lines changed

3 files changed

+36
-7
lines changed

README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,7 @@ A `types` props means type of places in [google place API](https://developers.go
4343
A [componentRestrictions](https://developers.google.com/maps/documentation/javascript/reference#ComponentRestrictions) prop by default is empty.
4444
A [bounds](https://developers.google.com/maps/documentation/javascript/reference#AutocompleteOptions) prop by default is empty.
4545
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.
46+
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)
4647

4748
## Contribution
4849

lib/index.js

Lines changed: 19 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -65,20 +65,23 @@ var ReactGoogleAutocomplete = function (_React$Component) {
6565
value: function componentDidMount() {
6666
var _this2 = this;
6767

68+
// TODO: only take options as configuration object, remove config props from the components props.
6869
var _props = this.props,
6970
_props$types = _props.types,
7071
types = _props$types === undefined ? ['(cities)'] : _props$types,
7172
componentRestrictions = _props.componentRestrictions,
7273
bounds = _props.bounds,
7374
apiKey = _props.apiKey,
7475
_props$fields = _props.fields,
75-
fields = _props$fields === undefined ? ['address_components', 'geometry.location', 'place_id', 'formatted_address'] : _props$fields;
76+
fields = _props$fields === undefined ? ['address_components', 'geometry.location', 'place_id', 'formatted_address'] : _props$fields,
77+
_props$options = _props.options,
78+
options = _props$options === undefined ? {} : _props$options;
7679

77-
var config = {
80+
var config = _extends({}, options, {
7881
types: types,
7982
bounds: bounds,
8083
fields: fields
81-
};
84+
});
8285

8386
if (componentRestrictions) {
8487
config.componentRestrictions = componentRestrictions;
@@ -139,9 +142,10 @@ var ReactGoogleAutocomplete = function (_React$Component) {
139142
types = _props2.types,
140143
componentRestrictions = _props2.componentRestrictions,
141144
bounds = _props2.bounds,
145+
options = _props2.options,
142146
apiKey = _props2.apiKey,
143147
inputAutocompleteValue = _props2.inputAutocompleteValue,
144-
rest = _objectWithoutProperties(_props2, ['onPlaceSelected', 'types', 'componentRestrictions', 'bounds', 'apiKey', 'inputAutocompleteValue']);
148+
rest = _objectWithoutProperties(_props2, ['onPlaceSelected', 'types', 'componentRestrictions', 'bounds', 'options', 'apiKey', 'inputAutocompleteValue']);
145149

146150
return _react2.default.createElement('input', _extends({ ref: 'input' }, rest));
147151
}
@@ -152,11 +156,21 @@ var ReactGoogleAutocomplete = function (_React$Component) {
152156

153157
ReactGoogleAutocomplete.propTypes = {
154158
onPlaceSelected: _propTypes2.default.func,
155-
types: _propTypes2.default.array,
159+
types: _propTypes2.default.arrayOf(_propTypes2.default.string),
156160
componentRestrictions: _propTypes2.default.object,
157161
bounds: _propTypes2.default.object,
158162
fields: _propTypes2.default.array,
159163
inputAutocompleteValue: _propTypes2.default.string,
164+
options: _propTypes2.default.shape({
165+
componentRestrictions: _propTypes2.default.object,
166+
bounds: _propTypes2.default.object,
167+
location: _propTypes2.default.object,
168+
offset: _propTypes2.default.number,
169+
origin: _propTypes2.default.object,
170+
radius: _propTypes2.default.number,
171+
sessionToken: _propTypes2.default.object,
172+
types: _propTypes2.default.arrayOf(_propTypes2.default.string)
173+
}),
160174
apiKey: _propTypes2.default.string
161175
};
162176
exports.default = ReactGoogleAutocomplete;

src/index.js

Lines changed: 16 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

@@ -19,6 +29,7 @@ export default class ReactGoogleAutocomplete extends React.Component {
1929
}
2030

2131
componentDidMount() {
32+
// TODO: only take options as configuration object, remove config props from the components props.
2233
const {
2334
types = ['(cities)'],
2435
componentRestrictions,
@@ -29,9 +40,11 @@ export default class ReactGoogleAutocomplete extends React.Component {
2940
'geometry.location',
3041
'place_id',
3142
'formatted_address'
32-
]
43+
],
44+
options = {}
3345
} = this.props;
3446
const config = {
47+
...options,
3548
types,
3649
bounds,
3750
fields
@@ -115,6 +128,7 @@ export default class ReactGoogleAutocomplete extends React.Component {
115128
types,
116129
componentRestrictions,
117130
bounds,
131+
options,
118132
apiKey,
119133
inputAutocompleteValue,
120134
...rest

0 commit comments

Comments
 (0)