DefaultLegendGroup.js 1.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142
  1. "use strict";
  2. exports.__esModule = true;
  3. exports.default = DefaultLegendGroupRenderer;
  4. var _react = _interopRequireDefault(require("react"));
  5. var _DefaultLegendItem = _interopRequireDefault(require("./DefaultLegendItem"));
  6. function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
  7. 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); }
  8. const LEGEND_GROUP_STYLE = {
  9. display: 'flex',
  10. flexBasis: 'auto',
  11. flexDirection: 'row',
  12. flexGrow: 1,
  13. flexShrink: 1,
  14. flexWrap: 'wrap',
  15. fontSize: '0.8em',
  16. justifyContent: 'flex-end',
  17. padding: 8
  18. };
  19. function DefaultLegendGroupRenderer({
  20. items,
  21. ItemRenderer = _DefaultLegendItem.default,
  22. ItemMarkRenderer,
  23. ItemLabelRenderer,
  24. style
  25. }) {
  26. const combinedStyle = typeof style === 'undefined' ? LEGEND_GROUP_STYLE : _extends({}, LEGEND_GROUP_STYLE, {}, style);
  27. return _react.default.createElement("div", {
  28. style: combinedStyle
  29. }, items.map(item => _react.default.createElement(ItemRenderer, {
  30. key: "legend-item-" + item.field + "-" + item.value,
  31. item: item,
  32. MarkRenderer: ItemMarkRenderer,
  33. LabelRenderer: ItemLabelRenderer
  34. })));
  35. }