@cashub/ui 0.44.2 → 0.45.0

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.
package/button/Button.js CHANGED
@@ -63,6 +63,6 @@ const Button = _styledComponents.default.button.attrs(() => ({
63
63
  let {
64
64
  variant
65
65
  } = _ref10;
66
- return variant === 'link' && (0, _styledComponents.css)(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n background: transparent;\n color: var(--color-primary);\n border: none;\n padding: 0;\n text-decoration: underline;\n text-transform: none;\n\n &:hover {\n opacity: 0.8;\n box-shadow: none;\n }\n "])));
66
+ return variant === 'link' && (0, _styledComponents.css)(_templateObject8 || (_templateObject8 = _taggedTemplateLiteral(["\n font-size: var(--font-body1);\n background: transparent;\n color: var(--color-primary);\n border: none;\n padding: 0;\n text-decoration: underline;\n text-transform: none;\n &:hover {\n opacity: 0.8;\n box-shadow: none;\n }\n "])));
67
67
  });
68
68
  var _default = exports.default = Button;
@@ -5,14 +5,19 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var _react = require("react");
8
- var _styledComponents = require("styled-components");
8
+ var _styledComponents = _interopRequireWildcard(require("styled-components"));
9
9
  var _reactChartjs = require("react-chartjs-2");
10
10
  var _lodash = _interopRequireDefault(require("lodash.uniqueid"));
11
11
  var _htmlLegendPlugin = _interopRequireDefault(require("./utils/htmlLegendPlugin"));
12
12
  var _customTooltip = _interopRequireDefault(require("./utils/customTooltip"));
13
+ var _centerTextPlugin = _interopRequireDefault(require("./utils/centerTextPlugin"));
13
14
  var _jsxRuntime = require("react/jsx-runtime");
14
- const _excluded = ["height", "data"];
15
+ var _templateObject;
16
+ const _excluded = ["height", "data", "showCenterText", "centerTextTitle"];
15
17
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
18
+ function _getRequireWildcardCache(e) { if ("function" != typeof WeakMap) return null; var r = new WeakMap(), t = new WeakMap(); return (_getRequireWildcardCache = function (e) { return e ? t : r; })(e); }
19
+ function _interopRequireWildcard(e, r) { if (!r && e && e.__esModule) return e; if (null === e || "object" != typeof e && "function" != typeof e) return { default: e }; var t = _getRequireWildcardCache(r); if (t && t.has(e)) return t.get(e); var n = { __proto__: null }, a = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var u in e) if ("default" !== u && {}.hasOwnProperty.call(e, u)) { var i = a ? Object.getOwnPropertyDescriptor(e, u) : null; i && (i.get || i.set) ? Object.defineProperty(n, u, i) : n[u] = e[u]; } return n.default = e, t && t.set(e, n), n; }
20
+ function _taggedTemplateLiteral(e, t) { return t || (t = e.slice(0)), Object.freeze(Object.defineProperties(e, { raw: { value: Object.freeze(t) } })); }
16
21
  function ownKeys(e, r) { var t = Object.keys(e); if (Object.getOwnPropertySymbols) { var o = Object.getOwnPropertySymbols(e); r && (o = o.filter(function (r) { return Object.getOwnPropertyDescriptor(e, r).enumerable; })), t.push.apply(t, o); } return t; }
17
22
  function _objectSpread(e) { for (var r = 1; r < arguments.length; r++) { var t = null != arguments[r] ? arguments[r] : {}; r % 2 ? ownKeys(Object(t), !0).forEach(function (r) { _defineProperty(e, r, t[r]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(e, Object.getOwnPropertyDescriptors(t)) : ownKeys(Object(t)).forEach(function (r) { Object.defineProperty(e, r, Object.getOwnPropertyDescriptor(t, r)); }); } return e; }
18
23
  function _defineProperty(e, r, t) { return (r = _toPropertyKey(r)) in e ? Object.defineProperty(e, r, { value: t, enumerable: !0, configurable: !0, writable: !0 }) : e[r] = t, e; }
@@ -23,7 +28,9 @@ function _objectWithoutPropertiesLoose(r, e) { if (null == r) return {}; var t =
23
28
  const DoughnutChart = _ref => {
24
29
  let {
25
30
  height = 300,
26
- data
31
+ data,
32
+ showCenterText = false,
33
+ centerTextTitle
27
34
  } = _ref,
28
35
  props = _objectWithoutProperties(_ref, _excluded);
29
36
  const [legendContainerId] = (0, _react.useState)((0, _lodash.default)('legend-container-'));
@@ -72,21 +79,26 @@ const DoughnutChart = _ref => {
72
79
  return color;
73
80
  }
74
81
  }
82
+ },
83
+ centerText: {
84
+ display: showCenterText,
85
+ title: centerTextTitle
75
86
  }
76
87
  }
77
88
  };
78
- }, [legendContainerId, theme.fontOnPrimary]);
89
+ }, [legendContainerId, theme.fontOnPrimary, showCenterText, centerTextTitle]);
79
90
  return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
80
91
  children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
81
92
  children: /*#__PURE__*/(0, _jsxRuntime.jsx)(_reactChartjs.Doughnut, _objectSpread({
82
93
  height: height,
83
94
  data: data,
84
95
  options: defaultOptions,
85
- plugins: [_htmlLegendPlugin.default]
96
+ plugins: [_htmlLegendPlugin.default, _centerTextPlugin.default]
86
97
  }, props))
87
- }), /*#__PURE__*/(0, _jsxRuntime.jsx)("div", {
98
+ }), /*#__PURE__*/(0, _jsxRuntime.jsx)(LegendWrapper, {
88
99
  id: legendContainerId
89
100
  })]
90
101
  });
91
102
  };
103
+ const LegendWrapper = _styledComponents.default.div(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n .custom-legend-tooltip {\n position: relative;\n }\n\n .custom-legend-tooltip:hover::after {\n content: attr(data-tooltip);\n position: absolute;\n top: calc(1rem + var(--spacing-xs));\n left: 50%;\n transform: translateX(-50%);\n border: 1px solid var(--border-color);\n color: var(--font-on-background);\n background: var(--color-background2);\n box-shadow: var(--box-shadow);\n border-radius: calc(var(--border-radius) / 2);\n padding: var(--spacing-xs);\n font-size: var(--font-body1);\n font-weight: var(--font-normal);\n text-align: center;\n width: max-content;\n max-width: 50vw;\n }\n"])));
92
104
  var _default = exports.default = DoughnutChart;
@@ -0,0 +1,62 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
6
+ exports.default = void 0;
7
+ var _reactChartjs = require("react-chartjs-2");
8
+ const centerTextPlugin = {
9
+ id: 'centerText',
10
+ beforeDraw: chart => {
11
+ const {
12
+ options,
13
+ data
14
+ } = chart.config;
15
+ const config = options.plugins.centerText;
16
+ if (!config || !config.display) {
17
+ return;
18
+ }
19
+ const {
20
+ ctx,
21
+ chartArea: {
22
+ top,
23
+ width,
24
+ height
25
+ }
26
+ } = chart;
27
+ ctx.save();
28
+
29
+ // calculate center position
30
+ const centerX = width / 2;
31
+ const centerY = height / 2 + top;
32
+
33
+ // font settings
34
+ const {
35
+ font,
36
+ color
37
+ } = _reactChartjs.defaults;
38
+ const {
39
+ family,
40
+ size,
41
+ lineHeight
42
+ } = font;
43
+ const offset = size * lineHeight / 2;
44
+ ctx.textAlign = 'center';
45
+ ctx.textBaseline = 'middle';
46
+ ctx.fillStyle = color;
47
+ const {
48
+ title
49
+ } = config;
50
+ if (title) {
51
+ ctx.font = "bold ".concat(size, "px ").concat(family);
52
+ ctx.fillText(title, centerX, centerY - offset);
53
+ }
54
+ const total = data.datasets[0].data.reduce((total, current) => {
55
+ return total + current;
56
+ }, 0);
57
+ ctx.font = "".concat(size, "px ").concat(family);
58
+ ctx.fillText(total.toLocaleString(), centerX, centerY + (title ? offset : 0));
59
+ ctx.restore();
60
+ }
61
+ };
62
+ var _default = exports.default = centerTextPlugin;
@@ -26,6 +26,12 @@ const htmlLegendPlugin = {
26
26
  li.style.marginLeft = '16px';
27
27
  li.style.marginTop = '16px';
28
28
  li.style.color = _reactChartjs.defaults.color;
29
+ const [dataset] = chart.data.datasets;
30
+ const description = dataset.descriptions ? dataset.descriptions[item.index] : '';
31
+ if (description) {
32
+ li.setAttribute('data-tooltip', description);
33
+ li.classList.add('custom-legend-tooltip');
34
+ }
29
35
  li.onclick = () => {
30
36
  const {
31
37
  type
@@ -22,7 +22,10 @@ const padEmptyChartBar = {
22
22
  for (let index = validLabels.length; index < maxBarNumber; index += 1) {
23
23
  this.length = this.length === -1 ? index : this.length;
24
24
  data.labels[index] = null;
25
- data.datasets[0].data[index] = 0;
25
+ const [datasets] = data.datasets;
26
+ if (datasets) {
27
+ datasets.data[index] = 0;
28
+ }
26
29
  }
27
30
  },
28
31
  // prevent padded empty chart bar to be drawn
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@cashub/ui",
3
- "version": "0.44.2",
3
+ "version": "0.45.0",
4
4
  "private": false,
5
5
  "author": "CasHUB Team",
6
6
  "description": "CasHUB UI components library",
@@ -4,9 +4,51 @@ Object.defineProperty(exports, "__esModule", {
4
4
  value: true
5
5
  });
6
6
  exports.default = void 0;
7
+ var _react = require("react");
7
8
  var _styledComponents = _interopRequireDefault(require("styled-components"));
8
- var _templateObject;
9
+ var _jsxRuntime = require("react/jsx-runtime");
10
+ var _templateObject, _templateObject2;
9
11
  function _interopRequireDefault(e) { return e && e.__esModule ? e : { default: e }; }
10
12
  function _taggedTemplateLiteral(e, t) { return t || (t = e.slice(0)), Object.freeze(Object.defineProperties(e, { raw: { value: Object.freeze(t) } })); }
11
- const SelectedMultipleText = _styledComponents.default.span(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n"])));
13
+ const SelectedMultipleText = _ref => {
14
+ let {
15
+ children
16
+ } = _ref;
17
+ const textRef = (0, _react.useRef)(null);
18
+ const [position, setPosition] = (0, _react.useState)({
19
+ x: 0,
20
+ y: 0
21
+ });
22
+ const [show, setShow] = (0, _react.useState)(false);
23
+ const handleMouseEnter = () => {
24
+ const element = textRef.current;
25
+ // show tooltip on content width exceeds container width only
26
+ if (element.scrollWidth > element.clientWidth) {
27
+ const rect = element.getBoundingClientRect();
28
+ setPosition({
29
+ x: rect.left,
30
+ y: rect.bottom + 8
31
+ });
32
+ setShow(true);
33
+ }
34
+ };
35
+ return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_jsxRuntime.Fragment, {
36
+ children: [/*#__PURE__*/(0, _jsxRuntime.jsx)(Text, {
37
+ ref: textRef,
38
+ onMouseEnter: handleMouseEnter,
39
+ onMouseLeave: () => {
40
+ setShow(false);
41
+ },
42
+ children: children
43
+ }), show && /*#__PURE__*/(0, _jsxRuntime.jsx)(Tooltip, {
44
+ style: {
45
+ left: position.x,
46
+ top: position.y
47
+ },
48
+ children: children
49
+ })]
50
+ });
51
+ };
52
+ const Text = _styledComponents.default.span(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n white-space: nowrap;\n overflow: hidden;\n text-overflow: ellipsis;\n"])));
53
+ const Tooltip = _styledComponents.default.div(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n position: fixed;\n border: 1px solid var(--border-color);\n color: var(--font-on-background);\n background: var(--color-background2);\n box-shadow: var(--box-shadow);\n border-radius: calc(var(--border-radius) / 2);\n padding: var(--spacing-xs);\n font-size: var(--font-body1);\n font-weight: var(--font-normal);\n z-index: 90;\n width: max-content;\n max-width: 50vw;\n"])));
12
54
  var _default = exports.default = SelectedMultipleText;