DefaultLegend.js 2.5 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.default = void 0;
  4. var _react = _interopRequireWildcard(require("react"));
  5. var _DefaultLegendGroup = _interopRequireDefault(require("./DefaultLegendGroup"));
  6. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  7. function _getRequireWildcardCache() { if (typeof WeakMap !== "function") return null; var cache = new WeakMap(); _getRequireWildcardCache = function _getRequireWildcardCache() { return cache; }; return cache; }
  8. function _interopRequireWildcard(obj) { if (obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
  9. function _extends() { _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; }; return _extends.apply(this, arguments); }
  10. const LEGEND_CONTAINER_STYLE = {
  11. display: 'flex',
  12. flexBasis: 'auto',
  13. flexGrow: 1,
  14. flexShrink: 1,
  15. maxHeight: 100,
  16. overflowY: 'auto',
  17. position: 'relative'
  18. };
  19. class DefaultLegend extends _react.PureComponent {
  20. render() {
  21. const {
  22. groups,
  23. LegendGroupRenderer = _DefaultLegendGroup.default,
  24. LegendItemRenderer,
  25. LegendItemMarkRenderer,
  26. LegendItemLabelRenderer,
  27. style
  28. } = this.props;
  29. const combinedStyle = typeof style === 'undefined' ? LEGEND_CONTAINER_STYLE : _extends({}, LEGEND_CONTAINER_STYLE, {}, style);
  30. return _react.default.createElement("div", {
  31. style: combinedStyle
  32. }, groups.map(items => _react.default.createElement(LegendGroupRenderer, {
  33. key: items[0].field,
  34. items: items,
  35. ItemRenderer: LegendItemRenderer,
  36. ItemMarkRenderer: LegendItemMarkRenderer,
  37. ItemLabelRenderer: LegendItemLabelRenderer
  38. })));
  39. }
  40. }
  41. exports.default = DefaultLegend;