UNPKG

material-ui-geosuggest

Version:
176 lines (142 loc) 5.9 kB
(function (global, factory) { if (typeof define === "function" && define.amd) { define(['exports', 'react', 'material-ui/TextField'], factory); } else if (typeof exports !== "undefined") { factory(exports, require('react'), require('material-ui/TextField')); } else { var mod = { exports: {} }; factory(mod.exports, global.react, global.TextField); global.index = mod.exports; } })(this, function (exports, _react, _TextField) { 'use strict'; Object.defineProperty(exports, "__esModule", { value: true }); var _react2 = _interopRequireDefault(_react); var _TextField2 = _interopRequireDefault(_TextField); function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; } var _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; function _objectWithoutProperties(obj, keys) { var target = {}; for (var i in obj) { if (keys.indexOf(i) >= 0) continue; if (!Object.prototype.hasOwnProperty.call(obj, i)) continue; target[i] = obj[i]; } return target; } function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } } var _createClass = function () { function defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } } return function (Constructor, protoProps, staticProps) { if (protoProps) defineProperties(Constructor.prototype, protoProps); if (staticProps) defineProperties(Constructor, staticProps); return Constructor; }; }(); function _possibleConstructorReturn(self, call) { if (!self) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return call && (typeof call === "object" || typeof call === "function") ? call : self; } function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function, not " + typeof superClass); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, enumerable: false, writable: true, configurable: true } }); if (superClass) Object.setPrototypeOf ? Object.setPrototypeOf(subClass, superClass) : subClass.__proto__ = superClass; } var MuiGeoSuggest = function (_Component) { _inherits(MuiGeoSuggest, _Component); function MuiGeoSuggest(props) { _classCallCheck(this, MuiGeoSuggest); var _this = _possibleConstructorReturn(this, (MuiGeoSuggest.__proto__ || Object.getPrototypeOf(MuiGeoSuggest)).call(this, props)); _this.onPlaceChange = props.onPlaceChange; return _this; } _createClass(MuiGeoSuggest, [{ key: 'componentDidMount', value: function componentDidMount() { var _this2 = this; if (typeof window.google !== 'undefined' && typeof window.google.maps !== 'undefined') { var inputElement = document.getElementsByName(this.props.name)[0]; this.apiObj = new window.google.maps.places.Autocomplete(inputElement, this.props.options); this.apiObj.addListener('place_changed', function () { _this2.onPlaceChange(_this2.apiObj.getPlace()); }); } else { console.error('Google API object is not defined'); } } }, { key: 'render', value: function render() { var _props = this.props, options = _props.options, onPlaceChange = _props.onPlaceChange, props = _objectWithoutProperties(_props, ['options', 'onPlaceChange']); if (onPlaceChange !== this.onPlaceChange) { this.onPlaceChange = onPlaceChange; } var finalProps = _extends({}, props, { placeholder: props.floatingLabelText || props.hintText ? '' : props.placeholder }); return _react2.default.createElement(_TextField2.default, finalProps); } }]); return MuiGeoSuggest; }(_react.Component); ; MuiGeoSuggest.propTypes = { name: _react.PropTypes.string, onPlaceChange: _react.PropTypes.func, floatingLabelText: _react.PropTypes.string, hintText: _react.PropTypes.string, options: _react.PropTypes.shape({}) }; MuiGeoSuggest.defaultProps = { name: 'muiGeoSuggest', onPlaceChange: function onPlaceChange() {}, floatingLabelText: '', hintText: '', options: {} }; exports.default = MuiGeoSuggest; });