@cashub/ui 0.14.3 → 0.14.5

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -11,6 +11,10 @@ var _styledComponents = require("styled-components");
11
11
 
12
12
  var _reactChartjs = require("react-chartjs-2");
13
13
 
14
+ var _lodash = _interopRequireDefault(require("lodash.uniqueid"));
15
+
16
+ var _htmlLegendPlugin = _interopRequireDefault(require("./utils/htmlLegendPlugin"));
17
+
14
18
  var _customTooltip = _interopRequireDefault(require("./utils/customTooltip"));
15
19
 
16
20
  var _jsxRuntime = require("react/jsx-runtime");
@@ -25,6 +29,18 @@ function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { va
25
29
 
26
30
  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; }
27
31
 
32
+ function _slicedToArray(arr, i) { return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest(); }
33
+
34
+ function _nonIterableRest() { throw new TypeError("Invalid attempt to destructure non-iterable instance.\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method."); }
35
+
36
+ function _unsupportedIterableToArray(o, minLen) { if (!o) return; if (typeof o === "string") return _arrayLikeToArray(o, minLen); var n = Object.prototype.toString.call(o).slice(8, -1); if (n === "Object" && o.constructor) n = o.constructor.name; if (n === "Map" || n === "Set") return Array.from(o); if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen); }
37
+
38
+ function _arrayLikeToArray(arr, len) { if (len == null || len > arr.length) len = arr.length; for (var i = 0, arr2 = new Array(len); i < len; i++) { arr2[i] = arr[i]; } return arr2; }
39
+
40
+ function _iterableToArrayLimit(arr, i) { var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"]; if (_i == null) return; var _arr = []; var _n = true; var _d = false; var _s, _e; try { for (_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true) { _arr.push(_s.value); if (i && _arr.length === i) break; } } catch (err) { _d = true; _e = err; } finally { try { if (!_n && _i["return"] != null) _i["return"](); } finally { if (_d) throw _e; } } return _arr; }
41
+
42
+ function _arrayWithHoles(arr) { if (Array.isArray(arr)) return arr; }
43
+
28
44
  function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
29
45
 
30
46
  function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
@@ -35,6 +51,10 @@ var DoughnutChart = function DoughnutChart(_ref) {
35
51
  data = _ref.data,
36
52
  props = _objectWithoutProperties(_ref, _excluded);
37
53
 
54
+ var _useState = (0, _react.useState)((0, _lodash.default)('legend-container-')),
55
+ _useState2 = _slicedToArray(_useState, 1),
56
+ legendContainerId = _useState2[0];
57
+
38
58
  var theme = (0, _react.useContext)(_styledComponents.ThemeContext); // fix: read value from theme
39
59
 
40
60
  _reactChartjs.defaults.font.family = theme.fontFamily;
@@ -47,15 +67,27 @@ var DoughnutChart = function DoughnutChart(_ref) {
47
67
  maintainAspectRatio: false,
48
68
  aspectRatio: 1,
49
69
  plugins: {
70
+ htmlLegend: {
71
+ containerID: legendContainerId
72
+ },
50
73
  legend: {
51
- position: 'bottom',
52
- labels: {
53
- padding: 24
54
- }
74
+ display: false
55
75
  },
56
76
  tooltip: {
57
77
  enabled: false,
58
78
  callbacks: {
79
+ title: function title(context) {
80
+ return context[0] ? context[0].label.match(/(.{1,20})/g) : '';
81
+ },
82
+ label: function label(context) {
83
+ var label = context.dataset.data[context.dataIndex];
84
+
85
+ if (context.dataset.customLabel) {
86
+ return context.dataset.customLabel[context.dataIndex].toString();
87
+ }
88
+
89
+ return label.toString();
90
+ },
59
91
  labelTextColor: function labelTextColor(context) {
60
92
  var color = context.dataset.color;
61
93
 
@@ -73,12 +105,19 @@ var DoughnutChart = function DoughnutChart(_ref) {
73
105
  }
74
106
  }
75
107
  };
76
- }, [theme.fontOnPrimary]);
77
- return /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactChartjs.Doughnut, _objectSpread({
78
- height: height,
79
- data: data,
80
- options: defaultOptions
81
- }, props));
108
+ }, [legendContainerId, theme.fontOnPrimary]);
109
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
110
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
111
+ children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactChartjs.Doughnut, _objectSpread({
112
+ height: height,
113
+ data: data,
114
+ options: defaultOptions,
115
+ plugins: [_htmlLegendPlugin.default]
116
+ }, props))
117
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
118
+ id: legendContainerId
119
+ })]
120
+ });
82
121
  };
83
122
 
84
123
  var _default = DoughnutChart;
@@ -73,6 +73,7 @@ var customTooltip = function customTooltip(theme) {
73
73
  tooltipEl.style.fontSize = theme.fontBody1;
74
74
  tooltipEl.style.display = 'block';
75
75
  tooltipEl.style.position = 'absolute';
76
+ tooltipEl.style.boxShadow = theme.boxShadow;
76
77
 
77
78
  var _tooltipModel$labelTe = _slicedToArray(tooltipModel.labelTextColors, 1);
78
79
 
@@ -0,0 +1,89 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+
8
+ var _reactChartjs = require("react-chartjs-2");
9
+
10
+ var htmlLegendPlugin = {
11
+ id: 'htmlLegend',
12
+ afterUpdate: function afterUpdate(chart, args, options) {
13
+ var ul = getOrCreateLegendList(chart, options.containerID); // Remove old legend items
14
+
15
+ while (ul.firstChild) {
16
+ ul.firstChild.remove();
17
+ } // Reuse the built-in legendItems generator
18
+
19
+
20
+ var items = chart.options.plugins.legend.labels.generateLabels(chart);
21
+ items.forEach(function (item) {
22
+ var li = document.createElement('li');
23
+ li.style.alignItems = 'center';
24
+ li.style.cursor = 'pointer';
25
+ li.style.display = 'flex';
26
+ li.style.flexDirection = 'row';
27
+ li.style.marginLeft = '16px';
28
+ li.style.marginTop = '16px';
29
+ li.style.color = _reactChartjs.defaults.color;
30
+
31
+ li.onclick = function () {
32
+ var type = chart.config.type;
33
+
34
+ if (type === 'pie' || type === 'doughnut') {
35
+ // Pie and doughnut charts only have a single dataset and visibility is per item
36
+ chart.toggleDataVisibility(item.index);
37
+ } else {
38
+ chart.setDatasetVisibility(item.datasetIndex, !chart.isDatasetVisible(item.datasetIndex));
39
+ }
40
+
41
+ chart.update();
42
+ }; // Color box
43
+
44
+
45
+ var boxSpan = document.createElement('span');
46
+ boxSpan.style.background = item.fillStyle;
47
+ boxSpan.style.borderColor = item.strokeStyle;
48
+ boxSpan.style.borderWidth = "".concat(item.lineWidth, "px");
49
+ boxSpan.style.borderStyle = 'solid';
50
+ boxSpan.style.display = 'inline-block';
51
+ boxSpan.style.height = '16px';
52
+ boxSpan.style.marginRight = '8px';
53
+ boxSpan.style.width = '32px'; // Text
54
+
55
+ var textContainer = document.createElement('p');
56
+ textContainer.style.color = item.fontColor;
57
+ textContainer.style.margin = 0;
58
+ textContainer.style.padding = 0;
59
+ textContainer.style.wordBreak = 'break-all';
60
+ textContainer.style.textDecoration = item.hidden ? 'line-through' : '';
61
+ var text = document.createTextNode(item.text);
62
+ textContainer.appendChild(text);
63
+ li.appendChild(boxSpan);
64
+ li.appendChild(textContainer);
65
+ ul.appendChild(li);
66
+ });
67
+ }
68
+ };
69
+
70
+ var getOrCreateLegendList = function getOrCreateLegendList(chart, id) {
71
+ var legendContainer = document.getElementById(id);
72
+ var listContainer = legendContainer.querySelector('ul');
73
+
74
+ if (!listContainer) {
75
+ listContainer = document.createElement('ul');
76
+ listContainer.style.display = 'flex';
77
+ listContainer.style.flexDirection = 'row';
78
+ listContainer.style.flexWrap = 'wrap';
79
+ listContainer.style.justifyContent = 'center';
80
+ listContainer.style.margin = 0;
81
+ listContainer.style.padding = 0;
82
+ legendContainer.appendChild(listContainer);
83
+ }
84
+
85
+ return listContainer;
86
+ };
87
+
88
+ var _default = htmlLegendPlugin;
89
+ exports.default = _default;
@@ -9,6 +9,12 @@ Object.defineProperty(exports, "customTooltip", {
9
9
  return _customTooltip.default;
10
10
  }
11
11
  });
12
+ Object.defineProperty(exports, "htmlLegendPlugin", {
13
+ enumerable: true,
14
+ get: function get() {
15
+ return _htmlLegendPlugin.default;
16
+ }
17
+ });
12
18
  Object.defineProperty(exports, "padEmptyChartBar", {
13
19
  enumerable: true,
14
20
  get: function get() {
@@ -20,4 +26,6 @@ var _customTooltip = _interopRequireDefault(require("./customTooltip"));
20
26
 
21
27
  var _padEmptyChartBar = _interopRequireDefault(require("./padEmptyChartBar"));
22
28
 
29
+ var _htmlLegendPlugin = _interopRequireDefault(require("./htmlLegendPlugin"));
30
+
23
31
  function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cashub/ui",
3
- "version": "0.14.3",
3
+ "version": "0.14.5",
4
4
  "private": false,
5
5
  "author": "CASHUB Team",
6
6
  "description": "CASHUB UI components library",
package/text/Paragraph.js CHANGED
@@ -13,7 +13,7 @@ function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { de
13
13
 
14
14
  function _taggedTemplateLiteral(strings, raw) { if (!raw) { raw = strings.slice(0); } return Object.freeze(Object.defineProperties(strings, { raw: { value: Object.freeze(raw) } })); }
15
15
 
16
- var Paragraph = _styledComponents.default.p(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n font-size: var(--font-body1);\n margin-bottom: var(--spacing-s);\n word-break: break-word;\n overflow-wrap: break-word;\n\n &:last-child {\n margin-bottom: 0;\n }\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n"])), function (_ref) {
16
+ var Paragraph = _styledComponents.default.p(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n color: var(--font-on-background);\n font-size: var(--font-body1);\n margin-bottom: var(--spacing-s);\n word-break: break-word;\n overflow-wrap: break-word;\n\n &:last-child {\n margin-bottom: 0;\n }\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n\n ", "\n"])), function (_ref) {
17
17
  var flex = _ref.flex;
18
18
  return flex && 'display: flex;';
19
19
  }, function (_ref2) {