contentoh-components-library 21.6.63 → 21.6.64
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.
|
@@ -43,31 +43,34 @@ var DashboardMetric = function DashboardMetric(_ref) {
|
|
|
43
43
|
borderColor = _ref.borderColor,
|
|
44
44
|
total = _ref.total,
|
|
45
45
|
totalFiltered = _ref.totalFiltered;
|
|
46
|
+
// Chart.js coloca la leyenda por opción, no por CSS. Se mide el panel y no
|
|
47
|
+
// la ventana, porque el ancho real depende también del menú de la app: a
|
|
48
|
+
// 828px de ventana el panel queda en 331 y la leyenda de lado sale cortada.
|
|
49
|
+
var containerRef = (0, _react.useRef)(null);
|
|
46
50
|
|
|
47
|
-
// Chart.js coloca la leyenda por opción, no por CSS: en pantallas angostas
|
|
48
|
-
// va abajo, porque a un lado deja la gráfica en nada.
|
|
49
51
|
var _useState = (0, _react.useState)(false),
|
|
50
52
|
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
51
53
|
isNarrow = _useState2[0],
|
|
52
54
|
setIsNarrow = _useState2[1];
|
|
53
55
|
|
|
54
56
|
(0, _react.useEffect)(function () {
|
|
55
|
-
var
|
|
56
|
-
|
|
57
|
-
var
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
57
|
+
var node = containerRef.current;
|
|
58
|
+
if (!node || typeof ResizeObserver === "undefined") return undefined;
|
|
59
|
+
var observer = new ResizeObserver(function (_ref2) {
|
|
60
|
+
var _ref3 = (0, _slicedToArray2.default)(_ref2, 1),
|
|
61
|
+
entry = _ref3[0];
|
|
62
|
+
|
|
63
|
+
return setIsNarrow(entry.contentRect.width < 420);
|
|
64
|
+
});
|
|
65
|
+
observer.observe(node);
|
|
63
66
|
return function () {
|
|
64
|
-
return
|
|
67
|
+
return observer.disconnect();
|
|
65
68
|
};
|
|
66
69
|
}, []);
|
|
67
|
-
var labels = type === "doughnut" ? Object.entries(dataObject).map(function (
|
|
68
|
-
var
|
|
69
|
-
key =
|
|
70
|
-
value =
|
|
70
|
+
var labels = type === "doughnut" ? Object.entries(dataObject).map(function (_ref4) {
|
|
71
|
+
var _ref5 = (0, _slicedToArray2.default)(_ref4, 2),
|
|
72
|
+
key = _ref5[0],
|
|
73
|
+
value = _ref5[1];
|
|
71
74
|
|
|
72
75
|
return key !== "NS" && "".concat((0, _dashboardMetricUtils.getFullStatus)(key), " (").concat(value, ")");
|
|
73
76
|
}) : Object.keys(dataObject);
|
|
@@ -97,11 +100,11 @@ var DashboardMetric = function DashboardMetric(_ref) {
|
|
|
97
100
|
plugins: {
|
|
98
101
|
tooltip: {
|
|
99
102
|
callbacks: {
|
|
100
|
-
label: function label(
|
|
103
|
+
label: function label(_ref6) {
|
|
101
104
|
var _dataset$data;
|
|
102
105
|
|
|
103
|
-
var dataset =
|
|
104
|
-
element =
|
|
106
|
+
var dataset = _ref6.dataset,
|
|
107
|
+
element = _ref6.element;
|
|
105
108
|
var sum = dataset === null || dataset === void 0 ? void 0 : (_dataset$data = dataset.data) === null || _dataset$data === void 0 ? void 0 : _dataset$data.reduce(function (accumulator, value) {
|
|
106
109
|
return accumulator + value;
|
|
107
110
|
}, 0);
|
|
@@ -136,6 +139,8 @@ var DashboardMetric = function DashboardMetric(_ref) {
|
|
|
136
139
|
showTooltips: true
|
|
137
140
|
};
|
|
138
141
|
return /*#__PURE__*/(0, _jsxRuntime.jsxs)(_styles.Container, {
|
|
142
|
+
ref: containerRef,
|
|
143
|
+
className: isNarrow ? "is-narrow" : "",
|
|
139
144
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsxs)("div", {
|
|
140
145
|
className: "text-container",
|
|
141
146
|
children: [/*#__PURE__*/(0, _jsxRuntime.jsx)("p", {
|
|
@@ -15,6 +15,6 @@ var _variables = require("../../../global-files/variables");
|
|
|
15
15
|
|
|
16
16
|
var _templateObject;
|
|
17
17
|
|
|
18
|
-
var Container = _styledComponents.default.div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n border: 1px solid ", ";\n border-radius: 5px;\n padding: 24px;\n position: relative;\n\n @media (max-width: 600px) {\n padding: 12px;\n\n .graphic-cotainer {\n padding: 5px;\n }\n\n /* Va rotada y fuera del recuadro; con el padding chico se encima. */\n > p.y-label {\n display: none;\n }\n }\n\n .text-container {\n p {\n font-family: ", ";\n color: ", ";\n font-size: 17px;\n\n &:last-of-type {\n font-size: 12px;\n color: ", ";\n }\n\n & + * {\n margin-top: 5px;\n }\n }\n\n & + * {\n margin-top: 15px;\n }\n }\n\n .select-container {\n display: flex;\n\n .select {\n flex: 0.1 1 30%;\n\n select {\n width: 100%;\n }\n\n & + * {\n margin-left: 10px;\n }\n }\n\n & + * {\n margin-top: 10px;\n }\n }\n\n .graphic-cotainer {\n height: 350px;\n border: 1px solid ", ";\n padding: 10px;\n border-radius: 5px;\n\n div {\n height: fill-available;\n }\n }\n\n & > p {\n font-family: ", ";\n color: ", ";\n font-size: 17px;\n\n &.x-label {\n position: absolute;\n left: 50%;\n transform: translate(-50%);\n bottom: 4px;\n }\n\n &.y-label {\n position: absolute;\n transform: rotate(-90deg);\n left: -28px;\n top: 50%;\n }\n\n &.center-label {\n position: absolute;\n top: 52%;\n right: 58%;\n font-size: 28px;\n color: #000;\n font-feature-settings: \"pnum\", \"lnum\";\n font-family: ", ";\n }\n }\n"])), _variables.GlobalColors.s3, _variables.FontFamily.Raleway, _variables.GlobalColors.s5, _variables.GlobalColors.s4, _variables.GlobalColors.s3, _variables.FontFamily.Raleway, _variables.GlobalColors.s5, _variables.FontFamily.Raleway_600);
|
|
18
|
+
var Container = _styledComponents.default.div(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n border: 1px solid ", ";\n border-radius: 5px;\n padding: 24px;\n position: relative;\n\n @media (max-width: 600px) {\n padding: 12px;\n\n .graphic-cotainer {\n padding: 5px;\n }\n\n /* Va rotada y fuera del recuadro; con el padding chico se encima. */\n > p.y-label {\n display: none;\n }\n }\n\n .text-container {\n p {\n font-family: ", ";\n color: ", ";\n font-size: 17px;\n\n &:last-of-type {\n font-size: 12px;\n color: ", ";\n }\n\n & + * {\n margin-top: 5px;\n }\n }\n\n & + * {\n margin-top: 15px;\n }\n }\n\n .select-container {\n display: flex;\n\n .select {\n flex: 0.1 1 30%;\n\n select {\n width: 100%;\n }\n\n & + * {\n margin-left: 10px;\n }\n }\n\n & + * {\n margin-top: 10px;\n }\n }\n\n /* Con la leyenda abajo, Chart.js le da un m\xE1ximo de la altura del recuadro\n y descarta las entradas que no caben; por eso crece junto con ella. */\n &.is-narrow .graphic-cotainer {\n height: 500px;\n }\n\n .graphic-cotainer {\n height: 350px;\n border: 1px solid ", ";\n padding: 10px;\n border-radius: 5px;\n\n div {\n height: fill-available;\n }\n }\n\n & > p {\n font-family: ", ";\n color: ", ";\n font-size: 17px;\n\n &.x-label {\n position: absolute;\n left: 50%;\n transform: translate(-50%);\n bottom: 4px;\n }\n\n &.y-label {\n position: absolute;\n transform: rotate(-90deg);\n left: -28px;\n top: 50%;\n }\n\n &.center-label {\n position: absolute;\n top: 52%;\n right: 58%;\n font-size: 28px;\n color: #000;\n font-feature-settings: \"pnum\", \"lnum\";\n font-family: ", ";\n }\n }\n"])), _variables.GlobalColors.s3, _variables.FontFamily.Raleway, _variables.GlobalColors.s5, _variables.GlobalColors.s4, _variables.GlobalColors.s3, _variables.FontFamily.Raleway, _variables.GlobalColors.s5, _variables.FontFamily.Raleway_600);
|
|
19
19
|
|
|
20
20
|
exports.Container = Container;
|
package/package.json
CHANGED
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { useEffect, useState } from "react";
|
|
1
|
+
import { useEffect, useRef, useState } from "react";
|
|
2
2
|
import { Container } from "./styles";
|
|
3
3
|
import { Graphic } from "../../atoms/Graphic";
|
|
4
4
|
import {
|
|
@@ -21,15 +21,19 @@ export const DashboardMetric = ({
|
|
|
21
21
|
total,
|
|
22
22
|
totalFiltered,
|
|
23
23
|
}) => {
|
|
24
|
-
// Chart.js coloca la leyenda por opción, no por CSS
|
|
25
|
-
//
|
|
24
|
+
// Chart.js coloca la leyenda por opción, no por CSS. Se mide el panel y no
|
|
25
|
+
// la ventana, porque el ancho real depende también del menú de la app: a
|
|
26
|
+
// 828px de ventana el panel queda en 331 y la leyenda de lado sale cortada.
|
|
27
|
+
const containerRef = useRef(null);
|
|
26
28
|
const [isNarrow, setIsNarrow] = useState(false);
|
|
27
29
|
useEffect(() => {
|
|
28
|
-
const
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
30
|
+
const node = containerRef.current;
|
|
31
|
+
if (!node || typeof ResizeObserver === "undefined") return undefined;
|
|
32
|
+
const observer = new ResizeObserver(([entry]) =>
|
|
33
|
+
setIsNarrow(entry.contentRect.width < 420)
|
|
34
|
+
);
|
|
35
|
+
observer.observe(node);
|
|
36
|
+
return () => observer.disconnect();
|
|
33
37
|
}, []);
|
|
34
38
|
|
|
35
39
|
const labels =
|
|
@@ -113,7 +117,7 @@ export const DashboardMetric = ({
|
|
|
113
117
|
};
|
|
114
118
|
|
|
115
119
|
return (
|
|
116
|
-
<Container>
|
|
120
|
+
<Container ref={containerRef} className={isNarrow ? "is-narrow" : ""}>
|
|
117
121
|
<div className="text-container">
|
|
118
122
|
<p>{label}</p>
|
|
119
123
|
<p>{description}</p>
|
|
@@ -61,6 +61,12 @@ export const Container = styled.div`
|
|
|
61
61
|
}
|
|
62
62
|
}
|
|
63
63
|
|
|
64
|
+
/* Con la leyenda abajo, Chart.js le da un máximo de la altura del recuadro
|
|
65
|
+
y descarta las entradas que no caben; por eso crece junto con ella. */
|
|
66
|
+
&.is-narrow .graphic-cotainer {
|
|
67
|
+
height: 500px;
|
|
68
|
+
}
|
|
69
|
+
|
|
64
70
|
.graphic-cotainer {
|
|
65
71
|
height: 350px;
|
|
66
72
|
border: 1px solid ${GlobalColors.s3};
|