@salesforce/design-system-react
Version:
Salesforce Lightning Design System for React
192 lines (161 loc) • 8.06 kB
JavaScript
function _typeof(obj) { if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a 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); } }
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
function _possibleConstructorReturn(self, call) { if (call && (_typeof(call) === "object" || typeof call === "function")) { return call; } return _assertThisInitialized(self); }
function _getPrototypeOf(o) { _getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return _getPrototypeOf(o); }
function _assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
function _defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
/* Copyright (c) 2015-present, salesforce.com, inc. All rights reserved */
/* Licensed under BSD 3-Clause - see LICENSE.txt or git.io/sfdc-license */
// Implements the [Map design pattern](https://lightningdesignsystem.com/components/map/) in React.
// Based on SLDS v2.4.0
import React from 'react';
import PropTypes from 'prop-types';
import classNames from 'classnames'; // ### shortid
// [npmjs.com/package/shortid](https://www.npmjs.com/package/shortid)
// shortid is a short, non-sequential, url-friendly, unique id generator
import shortid from 'shortid';
import Icon from '../icon';
import { MAP } from '../../utilities/constants';
var displayName = MAP;
var propTypes = {
/**
* CSS class names to be added with `slds-map` class. `array`, `object`, or `string` are accepted.
*/
className: PropTypes.oneOfType([PropTypes.array, PropTypes.object, PropTypes.string]),
/**
* CSS class names to be added to the container element. `array`, `object`, or `string` are accepted.
*/
classNameContainer: PropTypes.oneOfType([PropTypes.array, PropTypes.object, PropTypes.string]),
/**
* HTML id for component.
*/
id: PropTypes.string,
/**
* Labels
* * `title` - Title for the Map component.
*/
labels: PropTypes.shape({
title: PropTypes.string
}),
/**
* Array of locations objects for the Map component.**
* Each location object can contain:
* * `id` : A unique identifier string for the location
* * `name` : Name of the location
* * `address` : Address of the location
*/
locations: PropTypes.arrayOf(PropTypes.shape({
id: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
address: PropTypes.string.isRequired
})).isRequired,
/**
* Callback function triggered when a location is selected
*/
onClickLocation: PropTypes.func,
/**
* Accepts a Google Map API Key that will be used for showing the map
*/
googleAPIKey: PropTypes.string.isRequired,
/**
* Accepts location object that will be selected to shown on load
* * `id` : A unique identifier string for the location
* * `name` : Name of the location
* * `address` : Address of the location
*/
selection: PropTypes.shape({
id: PropTypes.string.isRequired,
name: PropTypes.string.isRequired,
address: PropTypes.string.isRequired
})
};
/**
* A map component is used to find a location
*/
var Map =
/*#__PURE__*/
function (_React$Component) {
_inherits(Map, _React$Component);
function Map(props) {
var _this;
_classCallCheck(this, Map);
_this = _possibleConstructorReturn(this, _getPrototypeOf(Map).call(this, props));
_defineProperty(_assertThisInitialized(_this), "handleClick", function (event, i) {
if (typeof _this.props.onClickLocation === 'function') _this.props.onClickLocation(event, _this.props.locations[i]);
});
_this.generatedId = shortid.generate();
return _this;
}
/**
* Get the Map's HTML id. Generate a new one if no ID present.
*/
_createClass(Map, [{
key: "getId",
value: function getId() {
return this.props.id || this.generatedId;
}
/**
* Handles clicking of a location
*/
}, {
key: "render",
value: function render() {
var _this2 = this;
return React.createElement("div", {
id: this.getId(),
className: classNames("slds-grid", {
'slds-has-coordinates': this.props.locations
}, this.props.classNameContainer)
}, React.createElement("div", {
className: "slds-map_container"
}, React.createElement("div", {
className: classNames("slds-map", this.props.className)
}, React.createElement("iframe", {
id: "".concat(this.getId(), "-google-map"),
title: this.props.labels.title,
src: "https://www.google.com/maps/embed/v1/place?key=".concat(this.props.googleAPIKey, "&q=").concat(encodeURIComponent(this.props.selection.address))
}))), this.props.locations.length > 1 ? React.createElement("div", {
className: "slds-coordinates"
}, React.createElement("div", {
className: "slds-coordinates__header"
}, React.createElement("h2", {
className: "slds-coordinates__title"
}, "".concat(this.props.labels.title, " (").concat(this.props.locations.length, ")"))), React.createElement("ul", {
className: "slds-coordinates__list"
}, this.props.locations.map(function (location, i) {
return React.createElement("li", {
key: location.id,
className: "slds-coordinates__item"
}, React.createElement("span", {
className: "slds-assistive-text",
"aria-live": "polite"
}, "".concat(location.name, " is currently selected")), React.createElement("button", {
type: "button",
onClick: function onClick(event) {
return _this2.handleClick(event, i);
},
className: "slds-coordinates__item-action slds-button_reset slds-media",
"aria-pressed": _this2.props.selection.id === location.id
}, React.createElement("span", {
className: "slds-media__figure"
}, React.createElement(Icon, {
category: "standard",
name: "account"
})), React.createElement("span", {
className: "slds-media__body"
}, React.createElement("span", {
className: "slds-text-link"
}, location.name), React.createElement("span", null, location.address))));
}))) : null);
}
}]);
return Map;
}(React.Component);
Map.displayName = displayName;
Map.propTypes = propTypes;
export default Map;
//# sourceMappingURL=index.js.map