@hybridcore/ui 1.5.79 → 1.5.82

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.
@@ -1,190 +1,103 @@
1
- import { jsxs as a, jsx as e } from "react/jsx-runtime";
2
- import { TrendingUp as C, TrendingDown as S, Remove as z } from "@mui/icons-material";
3
- import { useTheme as j, Card as R, Stack as h, Box as o, Typography as s, alpha as t } from "@mui/material";
4
- const W = ({
5
- label: g,
6
- value: u,
7
- change: d,
8
- changeType: m = "percentage",
9
- trend: c,
10
- icon: i,
11
- iconPosition: n = "right",
12
- description: p,
13
- variant: b = "default",
14
- sx: f
15
- }) => {
16
- const r = j(), x = () => c === "up" ? /* @__PURE__ */ e(C, { sx: { fontSize: 16 } }) : c === "down" ? /* @__PURE__ */ e(S, { sx: { fontSize: 16 } }) : /* @__PURE__ */ e(z, { sx: { fontSize: 16 } }), y = () => c === "up" ? {
17
- color: r.palette.success.main,
18
- bgcolor: t(r.palette.success.main, 0.1)
19
- } : c === "down" ? {
20
- color: r.palette.error.main,
21
- bgcolor: t(r.palette.error.main, 0.1)
22
- } : {
23
- color: r.palette.text.secondary,
24
- bgcolor: r.palette.action.hover
25
- }, v = () => {
26
- const l = {
27
- p: 3,
28
- borderRadius: 2,
29
- boxShadow: 1,
30
- transition: "all 0.3s",
31
- "&:hover": { boxShadow: 3 },
32
- border: 1
33
- };
34
- switch (b) {
35
- case "primary":
36
- return {
37
- ...l,
38
- bgcolor: t(r.palette.primary.main, 0.05),
39
- borderColor: t(r.palette.primary.main, 0.2)
40
- };
41
- case "success":
42
- return {
43
- ...l,
44
- bgcolor: t(r.palette.success.main, 0.05),
45
- borderColor: t(r.palette.success.main, 0.2)
46
- };
47
- case "warning":
48
- return {
49
- ...l,
50
- bgcolor: t(r.palette.warning.main, 0.05),
51
- borderColor: t(r.palette.warning.main, 0.2)
52
- };
53
- case "danger":
54
- return {
55
- ...l,
56
- bgcolor: t(r.palette.error.main, 0.05),
57
- borderColor: t(r.palette.error.main, 0.2)
58
- };
59
- default:
60
- return {
61
- ...l,
62
- bgcolor: "background.paper",
63
- borderColor: "divider"
64
- };
65
- }
66
- }, w = () => !i || !["top-left", "top-right", "bottom-left", "bottom-right"].includes(
67
- n
68
- ) ? null : /* @__PURE__ */ e(
69
- o,
70
- {
71
- sx: {
72
- position: "absolute",
73
- top: n.includes("top") ? 24 : void 0,
74
- bottom: n.includes("bottom") ? 24 : void 0,
75
- left: n.includes("left") ? 24 : void 0,
76
- right: n.includes("right") ? 24 : void 0,
77
- zIndex: 1
78
- },
79
- children: /* @__PURE__ */ e(
80
- o,
1
+ import { jsx as e, jsxs as t } from "react/jsx-runtime";
2
+ import { useTheme as R, Stack as o, Skeleton as l } from "@mui/material";
3
+ import * as k from "react";
4
+ import { useMetricCardLogic as L } from "./logic.js";
5
+ import { MetricChart as V } from "./MetricChart.js";
6
+ import { MetricCardRoot as v, MetricCardCornerIconContainer as A, MetricCardIconContainer as I, MetricCardContent as D, MetricCardLabel as P, MetricCardValue as W, MetricCardTrendContainer as q, MetricCardDescription as B, MetricCardChartContainer as E } from "./styled.js";
7
+ const N = k.forwardRef(
8
+ (S, s) => {
9
+ const {
10
+ label: y,
11
+ value: d,
12
+ calculatedValue: b,
13
+ calculatedChange: h,
14
+ description: m,
15
+ variant: c,
16
+ loading: T,
17
+ showChange: p,
18
+ showTrend: C,
19
+ Icon: i,
20
+ iconPosition: f,
21
+ showChart: x,
22
+ chartType: g,
23
+ sx: w,
24
+ other: u,
25
+ ownerState: r,
26
+ TrendIcon: z,
27
+ showCornerIcon: j,
28
+ showSideIcon: M
29
+ } = L(S), n = R();
30
+ let a = n.palette.text.secondary;
31
+ return c === "primary" && (a = n.palette.primary.main), c === "success" && (a = n.palette.success.main), c === "warning" && (a = n.palette.warning.main), c === "danger" && (a = n.palette.error.main), T ? /* @__PURE__ */ e(v, { ref: s, ownerState: r, sx: w, ...u, children: /* @__PURE__ */ t(o, { spacing: 1, children: [
32
+ /* @__PURE__ */ e(l, { variant: "text", width: "60%" }),
33
+ /* @__PURE__ */ e(l, { variant: "rectangular", height: 40, width: "40%" }),
34
+ /* @__PURE__ */ e(l, { variant: "text", width: "80%" }),
35
+ x && /* @__PURE__ */ e(
36
+ l,
81
37
  {
82
- sx: {
83
- width: 48,
84
- height: 48,
85
- borderRadius: "50%",
86
- bgcolor: "action.hover",
87
- display: "flex",
88
- alignItems: "center",
89
- justifyContent: "center"
90
- },
91
- children: /* @__PURE__ */ e(i, { sx: { fontSize: 24, color: "text.secondary" } })
38
+ variant: "rectangular",
39
+ height: 40,
40
+ width: "100%",
41
+ sx: { mt: 2 }
92
42
  }
93
43
  )
94
- }
95
- );
96
- return /* @__PURE__ */ a(
97
- R,
98
- {
99
- sx: {
100
- ...v(),
101
- position: "relative",
102
- overflow: "hidden",
103
- ...f
104
- },
105
- children: [
106
- w(),
107
- /* @__PURE__ */ a(
108
- h,
109
- {
110
- direction: "row",
111
- justifyContent: "space-between",
112
- alignItems: "flex-start",
113
- children: [
114
- i && n === "left" && /* @__PURE__ */ e(o, { mr: 2, children: /* @__PURE__ */ e(
115
- o,
116
- {
117
- sx: {
118
- width: 48,
119
- height: 48,
120
- borderRadius: "50%",
121
- bgcolor: "action.hover",
122
- display: "flex",
123
- alignItems: "center",
124
- justifyContent: "center"
125
- },
126
- children: /* @__PURE__ */ e(i, { sx: { fontSize: 24, color: "text.secondary" } })
127
- }
128
- ) }),
129
- /* @__PURE__ */ a(o, { flex: 1, children: [
130
- /* @__PURE__ */ e(s, { variant: "subtitle2", color: "text.secondary", mb: 0.5, children: g }),
131
- /* @__PURE__ */ e(
132
- s,
133
- {
134
- variant: "h4",
135
- fontWeight: "bold",
136
- color: "text.primary",
137
- mb: 1,
138
- children: u
139
- }
140
- ),
141
- d !== void 0 && /* @__PURE__ */ a(h, { direction: "row", alignItems: "center", spacing: 1, children: [
142
- /* @__PURE__ */ a(
143
- o,
144
- {
145
- sx: {
146
- display: "inline-flex",
147
- alignItems: "center",
148
- gap: 0.5,
149
- px: 1,
150
- py: 0.5,
151
- borderRadius: 10,
152
- typography: "caption",
153
- fontWeight: "medium",
154
- ...y()
155
- },
156
- children: [
157
- x(),
158
- d,
159
- m === "percentage" ? "%" : ""
160
- ]
161
- }
162
- ),
163
- p && /* @__PURE__ */ e(s, { variant: "caption", color: "text.secondary", children: p })
164
- ] })
165
- ] }),
166
- i && n === "right" && /* @__PURE__ */ e(o, { ml: 2, children: /* @__PURE__ */ e(
44
+ ] }) }) : /* @__PURE__ */ t(v, { ref: s, ownerState: r, sx: w, ...u, children: [
45
+ j && i && /* @__PURE__ */ e(A, { ownerState: r, children: /* @__PURE__ */ e(i, { sx: { fontSize: 24 } }) }),
46
+ /* @__PURE__ */ t(
47
+ o,
48
+ {
49
+ direction: "row",
50
+ justifyContent: "space-between",
51
+ alignItems: "flex-start",
52
+ sx: { flex: 1 },
53
+ children: [
54
+ M && i && f === "left" && /* @__PURE__ */ e(I, { ownerState: r, children: /* @__PURE__ */ e(i, { sx: { fontSize: 24 } }) }),
55
+ /* @__PURE__ */ t(D, { ownerState: r, children: [
56
+ /* @__PURE__ */ e(P, { variant: "subtitle2", ownerState: r, children: y }),
57
+ /* @__PURE__ */ t(
167
58
  o,
168
59
  {
169
- sx: {
170
- width: 48,
171
- height: 48,
172
- borderRadius: "50%",
173
- bgcolor: "action.hover",
174
- display: "flex",
175
- alignItems: "center",
176
- justifyContent: "center"
177
- },
178
- children: /* @__PURE__ */ e(i, { sx: { fontSize: 24, color: "text.secondary" } })
60
+ direction: "row",
61
+ alignItems: "baseline",
62
+ spacing: 1,
63
+ flexWrap: "wrap",
64
+ children: [
65
+ /* @__PURE__ */ e(W, { variant: "h4", ownerState: r, children: b }),
66
+ (p || C) && h !== "" && /* @__PURE__ */ t(q, { ownerState: r, children: [
67
+ C && /* @__PURE__ */ e(z, { sx: { fontSize: 16 } }),
68
+ p && h
69
+ ] })
70
+ ]
179
71
  }
180
- ) })
181
- ]
182
- }
183
- )
184
- ]
185
- }
186
- );
187
- };
72
+ )
73
+ ] }),
74
+ M && i && f === "right" && /* @__PURE__ */ e(I, { ownerState: r, children: /* @__PURE__ */ e(i, { sx: { fontSize: 24 } }) })
75
+ ]
76
+ }
77
+ ),
78
+ /* @__PURE__ */ t(
79
+ o,
80
+ {
81
+ direction: { xs: "column-reverse", sm: "column" },
82
+ spacing: 1,
83
+ sx: { width: "100%", mt: 2 },
84
+ children: [
85
+ m && /* @__PURE__ */ e(
86
+ B,
87
+ {
88
+ variant: "caption",
89
+ ownerState: r,
90
+ sx: { textAlign: { xs: "center", sm: "left" } },
91
+ children: m
92
+ }
93
+ ),
94
+ x && g && d.length >= 2 && /* @__PURE__ */ e(E, { ownerState: r, children: /* @__PURE__ */ e(V, { type: g, data: d, color: a }) })
95
+ ]
96
+ }
97
+ )
98
+ ] });
99
+ }
100
+ );
188
101
  export {
189
- W as MetricCard
102
+ N as MetricCard
190
103
  };
@@ -0,0 +1,91 @@
1
+ import { ArrowForward as S, TrendingUp as $, TrendingDown as y } from "@mui/icons-material";
2
+ import { useThemeProps as P } from "@mui/material";
3
+ const L = (N) => {
4
+ const u = P({ props: N, name: "MuiMetricCard" }), {
5
+ label: w,
6
+ value: e = [],
7
+ description: b,
8
+ variant: f = "default",
9
+ loading: v = !1,
10
+ showChange: p = !1,
11
+ changeType: r = "percentage",
12
+ showTrend: d = !1,
13
+ showIcon: l = !1,
14
+ icon: c,
15
+ iconPosition: i = "right",
16
+ showChart: T = !1,
17
+ chartType: C,
18
+ sx: I,
19
+ ...x
20
+ } = u, m = e.length > 0;
21
+ let h = "—";
22
+ if (m) {
23
+ const t = Number(e[e.length - 1].v);
24
+ isNaN(t) || (h = new Intl.NumberFormat("en-US", {
25
+ maximumFractionDigits: 2
26
+ }).format(t));
27
+ }
28
+ let s;
29
+ if (p)
30
+ if (e.length >= 2) {
31
+ const t = Number(e[e.length - 1].v), n = Number(e[e.length - 2].v);
32
+ if (isNaN(t) || isNaN(n))
33
+ s = "—";
34
+ else if (n === 0 && r === "percentage")
35
+ s = "—";
36
+ else {
37
+ let a = 0;
38
+ r === "absolute" ? a = t - n : a = (t - n) / n * 100, s = `${a > 0 ? "+" : a < 0 ? "−" : ""}${Math.abs(a).toFixed(
39
+ r === "percentage" ? 1 : 2
40
+ )}${r === "percentage" ? "%" : ""}`;
41
+ }
42
+ } else
43
+ s = "—";
44
+ let o;
45
+ if (d && e.length >= 2) {
46
+ const t = Number(e[e.length - 1].v), n = Number(e[e.length - 2].v);
47
+ !isNaN(t) && !isNaN(n) && (t > n ? o = "up" : t < n ? o = "down" : o = "neutral");
48
+ }
49
+ const F = {
50
+ ...u,
51
+ calculatedValue: h,
52
+ calculatedChange: s,
53
+ calculatedTrend: o,
54
+ hasData: m,
55
+ changeType: r,
56
+ iconPosition: i,
57
+ variant: f
58
+ };
59
+ let g = S;
60
+ o === "up" ? g = $ : o === "down" && (g = y);
61
+ const M = l && !!c && ["top-left", "top-right", "bottom-left", "bottom-right"].includes(
62
+ i || ""
63
+ ), D = l && !!c && ["left", "right"].includes(i || "");
64
+ return {
65
+ label: w,
66
+ value: e,
67
+ calculatedValue: h,
68
+ calculatedChange: s,
69
+ calculatedTrend: o,
70
+ description: b,
71
+ variant: f,
72
+ loading: v,
73
+ showChange: p,
74
+ changeType: r,
75
+ showTrend: d,
76
+ showIcon: l,
77
+ Icon: c,
78
+ iconPosition: i,
79
+ showChart: T,
80
+ chartType: C,
81
+ sx: I,
82
+ other: x,
83
+ ownerState: F,
84
+ TrendIcon: g,
85
+ showCornerIcon: M,
86
+ showSideIcon: D
87
+ };
88
+ };
89
+ export {
90
+ L as useMetricCardLogic
91
+ };
@@ -0,0 +1,155 @@
1
+ import { styled as t, alpha as o, Stack as s, Typography as e } from "@mui/material";
2
+ const c = t("div", {
3
+ name: "MuiMetricCard",
4
+ slot: "Root"
5
+ })(({ theme: a, ownerState: i }) => {
6
+ const r = {
7
+ position: "relative",
8
+ overflow: "hidden",
9
+ padding: a.spacing(2, 3),
10
+ borderRadius: a.shape.borderRadius * 2,
11
+ boxShadow: a.shadows[1],
12
+ transition: "all 0.3s",
13
+ "&:hover": { boxShadow: a.shadows[3] },
14
+ border: `1px solid ${a.palette.divider}`,
15
+ backgroundColor: a.palette.background.paper,
16
+ display: "flex",
17
+ flexDirection: "column",
18
+ minHeight: 120
19
+ };
20
+ let n = {};
21
+ switch (i.variant) {
22
+ case "primary":
23
+ n = {
24
+ backgroundColor: o(a.palette.primary.main, 0.05),
25
+ borderColor: o(a.palette.primary.main, 0.2)
26
+ };
27
+ break;
28
+ case "success":
29
+ n = {
30
+ backgroundColor: o(a.palette.success.main, 0.05),
31
+ borderColor: o(a.palette.success.main, 0.2)
32
+ };
33
+ break;
34
+ case "warning":
35
+ n = {
36
+ backgroundColor: o(a.palette.warning.main, 0.05),
37
+ borderColor: o(a.palette.warning.main, 0.2)
38
+ };
39
+ break;
40
+ case "danger":
41
+ n = {
42
+ backgroundColor: o(a.palette.error.main, 0.05),
43
+ borderColor: o(a.palette.error.main, 0.2)
44
+ };
45
+ break;
46
+ default:
47
+ n = {
48
+ backgroundColor: a.palette.background.paper,
49
+ borderColor: a.palette.divider
50
+ };
51
+ break;
52
+ }
53
+ return {
54
+ ...r,
55
+ ...n
56
+ };
57
+ }), p = t(s, {
58
+ name: "MuiMetricCard",
59
+ slot: "Content"
60
+ })(({ theme: a }) => ({
61
+ flex: 1,
62
+ width: "100%",
63
+ zIndex: 1,
64
+ [a.breakpoints.down("sm")]: {
65
+ alignItems: "center",
66
+ textAlign: "center"
67
+ }
68
+ })), d = t(e, {
69
+ name: "MuiMetricCard",
70
+ slot: "Label"
71
+ })(({ theme: a }) => ({
72
+ color: a.palette.text.secondary,
73
+ marginBottom: a.spacing(0.5),
74
+ fontWeight: 500
75
+ })), g = t(e, {
76
+ name: "MuiMetricCard",
77
+ slot: "Value"
78
+ })(({ theme: a, ownerState: i }) => {
79
+ let r = a.palette.text.primary;
80
+ return i.variant === "primary" && (r = a.palette.primary.main), i.variant === "success" && (r = a.palette.success.main), i.variant === "warning" && (r = a.palette.warning.main), i.variant === "danger" && (r = a.palette.error.main), {
81
+ color: r,
82
+ fontWeight: "bold",
83
+ marginBottom: a.spacing(0.5)
84
+ };
85
+ }), u = t("div", {
86
+ name: "MuiMetricCard",
87
+ slot: "TrendContainer"
88
+ })(({ theme: a, ownerState: i }) => {
89
+ let r = a.palette.text.secondary;
90
+ return i.calculatedTrend === "up" ? r = a.palette.success.main : i.calculatedTrend === "down" ? r = a.palette.error.main : i.calculatedTrend === "neutral" && (r = a.palette.text.secondary), {
91
+ display: "inline-flex",
92
+ alignItems: "center",
93
+ gap: a.spacing(0.5),
94
+ fontSize: "0.875rem",
95
+ fontWeight: 500,
96
+ color: r
97
+ };
98
+ }), C = t(e, {
99
+ name: "MuiMetricCard",
100
+ slot: "Description"
101
+ })(({ theme: a }) => ({
102
+ color: a.palette.text.secondary,
103
+ display: "block"
104
+ })), f = t("div", {
105
+ name: "MuiMetricCard",
106
+ slot: "Icon"
107
+ })(({ theme: a, ownerState: i }) => {
108
+ let r = a.palette.text.secondary;
109
+ return i.variant === "primary" && (r = a.palette.primary.main), i.variant === "success" && (r = a.palette.success.main), i.variant === "warning" && (r = a.palette.warning.main), i.variant === "danger" && (r = a.palette.error.main), {
110
+ display: "flex",
111
+ alignItems: "center",
112
+ justifyContent: "center",
113
+ color: r,
114
+ marginRight: i.iconPosition === "left" ? a.spacing(2) : 0,
115
+ marginLeft: i.iconPosition === "right" ? a.spacing(2) : 0,
116
+ [a.breakpoints.down("sm")]: {
117
+ position: "absolute",
118
+ top: a.spacing(2),
119
+ left: a.spacing(2),
120
+ margin: 0
121
+ }
122
+ };
123
+ }), b = t("div", {
124
+ name: "MuiMetricCard",
125
+ slot: "CornerIcon"
126
+ })(({ theme: a, ownerState: i }) => {
127
+ let r = a.palette.text.secondary;
128
+ i.variant === "primary" && (r = a.palette.primary.main), i.variant === "success" && (r = a.palette.success.main), i.variant === "warning" && (r = a.palette.warning.main), i.variant === "danger" && (r = a.palette.error.main);
129
+ const n = {};
130
+ return i.iconPosition === "top-left" ? (n.top = a.spacing(2), n.left = a.spacing(2)) : i.iconPosition === "top-right" ? (n.top = a.spacing(2), n.right = a.spacing(2)) : i.iconPosition === "bottom-left" ? (n.bottom = a.spacing(2), n.left = a.spacing(2)) : i.iconPosition === "bottom-right" && (n.bottom = a.spacing(2), n.right = a.spacing(2)), {
131
+ position: "absolute",
132
+ ...n,
133
+ color: r,
134
+ zIndex: 2
135
+ };
136
+ }), y = t("div", {
137
+ name: "MuiMetricCard",
138
+ slot: "ChartContainer"
139
+ })(() => ({
140
+ height: 40,
141
+ width: "100%",
142
+ display: "flex",
143
+ alignItems: "flex-end"
144
+ }));
145
+ export {
146
+ y as MetricCardChartContainer,
147
+ p as MetricCardContent,
148
+ b as MetricCardCornerIconContainer,
149
+ C as MetricCardDescription,
150
+ f as MetricCardIconContainer,
151
+ d as MetricCardLabel,
152
+ c as MetricCardRoot,
153
+ u as MetricCardTrendContainer,
154
+ g as MetricCardValue
155
+ };