@x-plat/design-system 0.5.36 → 0.5.38
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/dist/components/Chart/index.cjs +33 -27
- package/dist/components/Chart/index.css +26 -6
- package/dist/components/Chart/index.d.cts +1 -0
- package/dist/components/Chart/index.d.ts +1 -0
- package/dist/components/Chart/index.js +33 -27
- package/dist/components/Tooltip/index.cjs +98 -8
- package/dist/components/Tooltip/index.css +38 -38
- package/dist/components/Tooltip/index.d.cts +6 -8
- package/dist/components/Tooltip/index.d.ts +6 -8
- package/dist/components/Tooltip/index.js +98 -8
- package/dist/components/index.cjs +116 -34
- package/dist/components/index.css +61 -41
- package/dist/components/index.js +117 -35
- package/dist/index.cjs +116 -34
- package/dist/index.css +61 -41
- package/dist/index.js +119 -37
- package/package.json +1 -1
package/dist/index.js
CHANGED
|
@@ -6380,15 +6380,11 @@ var useChartTooltip = (enabled) => {
|
|
|
6380
6380
|
if (!rect) return;
|
|
6381
6381
|
setTooltip({ visible: true, x: e.clientX - rect.left, y: e.clientY - rect.top, content });
|
|
6382
6382
|
}, [enabled]);
|
|
6383
|
-
const showAt = React6.useCallback((x, y, content) => {
|
|
6384
|
-
if (!enabled) return;
|
|
6385
|
-
setTooltip({ visible: true, x, y, content });
|
|
6386
|
-
}, [enabled]);
|
|
6387
6383
|
const hide = React6.useCallback(() => {
|
|
6388
6384
|
cancelAnimationFrame(rafRef.current);
|
|
6389
6385
|
setTooltip((prev) => ({ ...prev, visible: false }));
|
|
6390
6386
|
}, []);
|
|
6391
|
-
return { tooltip, show,
|
|
6387
|
+
return { tooltip, show, hide, move, containerRef };
|
|
6392
6388
|
};
|
|
6393
6389
|
var GridLines = React6.memo(({ width, height, chartH, maxVal }) => /* @__PURE__ */ jsx307(Fragment2, { children: [0, 0.25, 0.5, 0.75, 1].map((ratio) => {
|
|
6394
6390
|
const y = PADDING.top + (1 - ratio) * chartH;
|
|
@@ -6453,7 +6449,7 @@ var useCrosshair = (seriesPoints, entries, labels, chartH) => {
|
|
|
6453
6449
|
}, [entries, seriesPoints]);
|
|
6454
6450
|
return { activeIndex, handleMouseMove, handleMouseLeave, tooltipContent, getTooltipAt };
|
|
6455
6451
|
};
|
|
6456
|
-
var LineChart = React6.memo(({ data, labels, width, height, animate, onHover,
|
|
6452
|
+
var LineChart = React6.memo(({ data, labels, width, height, animate, onHover, onMove, onLeave }) => {
|
|
6457
6453
|
const entries = React6.useMemo(() => Object.entries(data), [data]);
|
|
6458
6454
|
const maxVal = React6.useMemo(() => {
|
|
6459
6455
|
const allValues = entries.flatMap(([, v]) => v);
|
|
@@ -6493,9 +6489,8 @@ var LineChart = React6.memo(({ data, labels, width, height, animate, onHover, on
|
|
|
6493
6489
|
className: "chart-svg",
|
|
6494
6490
|
onMouseMove: (e) => {
|
|
6495
6491
|
handleMouseMove(e);
|
|
6496
|
-
if (activeIndex !== null
|
|
6497
|
-
|
|
6498
|
-
onShowAt(p.x, p.y, `${labels[activeIndex]} \u2014 ${getTooltipAt(activeIndex)}`);
|
|
6492
|
+
if (activeIndex !== null) {
|
|
6493
|
+
onHover(e, `${labels[activeIndex]} \u2014 ${getTooltipAt(activeIndex)}`);
|
|
6499
6494
|
} else {
|
|
6500
6495
|
onLeave();
|
|
6501
6496
|
}
|
|
@@ -6563,7 +6558,7 @@ var LineChart = React6.memo(({ data, labels, width, height, animate, onHover, on
|
|
|
6563
6558
|
);
|
|
6564
6559
|
});
|
|
6565
6560
|
LineChart.displayName = "LineChart";
|
|
6566
|
-
var CurveChart = React6.memo(({ data, labels, width, height, animate, onHover,
|
|
6561
|
+
var CurveChart = React6.memo(({ data, labels, width, height, animate, onHover, onMove, onLeave }) => {
|
|
6567
6562
|
const entries = React6.useMemo(() => Object.entries(data), [data]);
|
|
6568
6563
|
const maxVal = React6.useMemo(() => {
|
|
6569
6564
|
const allValues = entries.flatMap(([, v]) => v);
|
|
@@ -6605,7 +6600,7 @@ var CurveChart = React6.memo(({ data, labels, width, height, animate, onHover, o
|
|
|
6605
6600
|
handleMouseMove(e);
|
|
6606
6601
|
if (activeIndex !== null && seriesPoints[0]?.[activeIndex]) {
|
|
6607
6602
|
const p = seriesPoints[0][activeIndex];
|
|
6608
|
-
|
|
6603
|
+
onHover(e, `${labels[activeIndex]} \u2014 ${getTooltipAt(activeIndex)}`);
|
|
6609
6604
|
} else {
|
|
6610
6605
|
onLeave();
|
|
6611
6606
|
}
|
|
@@ -6673,7 +6668,7 @@ var CurveChart = React6.memo(({ data, labels, width, height, animate, onHover, o
|
|
|
6673
6668
|
);
|
|
6674
6669
|
});
|
|
6675
6670
|
CurveChart.displayName = "CurveChart";
|
|
6676
|
-
var BarChart = React6.memo(({ data, labels, width, height, animate, onHover,
|
|
6671
|
+
var BarChart = React6.memo(({ data, labels, width, height, animate, onHover, onMove, onLeave }) => {
|
|
6677
6672
|
const entries = React6.useMemo(() => Object.entries(data), [data]);
|
|
6678
6673
|
const maxVal = React6.useMemo(() => {
|
|
6679
6674
|
const allValues = entries.flatMap(([, v]) => v);
|
|
@@ -6723,7 +6718,8 @@ var BarChart = React6.memo(({ data, labels, width, height, animate, onHover, onS
|
|
|
6723
6718
|
transformOrigin: `${b.x + b.w / 2}px ${baseline}px`,
|
|
6724
6719
|
animationDelay: `${delay}ms`
|
|
6725
6720
|
} : void 0,
|
|
6726
|
-
onMouseEnter: () =>
|
|
6721
|
+
onMouseEnter: (e) => onHover(e, `${key}: ${labels[i]} \u2014 ${b.v}`),
|
|
6722
|
+
onMouseMove: onMove,
|
|
6727
6723
|
onMouseLeave: onLeave
|
|
6728
6724
|
},
|
|
6729
6725
|
`${di}-${i}`
|
|
@@ -6811,14 +6807,17 @@ var PieDonutChart = React6.memo(
|
|
|
6811
6807
|
{
|
|
6812
6808
|
d: s.d,
|
|
6813
6809
|
fill: PIE_COLORS[(i + colorOffset) % PIE_COLORS.length],
|
|
6814
|
-
className: "chart-slice"
|
|
6810
|
+
className: "chart-slice",
|
|
6811
|
+
onMouseEnter: (e) => onHover(e, `${s.label} \u2014 ${s.v.toLocaleString()} (${s.pct}%)`),
|
|
6812
|
+
onMouseMove: onMove,
|
|
6813
|
+
onMouseLeave: onLeave
|
|
6815
6814
|
}
|
|
6816
6815
|
) }, i)) })
|
|
6817
6816
|
] });
|
|
6818
6817
|
}
|
|
6819
6818
|
);
|
|
6820
6819
|
PieDonutChart.displayName = "PieDonutChart";
|
|
6821
|
-
var ChartTooltip = ({ x, y, containerWidth, containerHeight, children }) => {
|
|
6820
|
+
var ChartTooltip = ({ x, y, containerWidth, containerHeight, tooltipType, children }) => {
|
|
6822
6821
|
const ref = React6.useRef(null);
|
|
6823
6822
|
const [pos, setPos] = React6.useState({ left: 0, top: 0 });
|
|
6824
6823
|
React6.useLayoutEffect(() => {
|
|
@@ -6833,13 +6832,20 @@ var ChartTooltip = ({ x, y, containerWidth, containerHeight, children }) => {
|
|
|
6833
6832
|
if (left < 0) left = 0;
|
|
6834
6833
|
setPos({ left, top });
|
|
6835
6834
|
}, [x, y, containerWidth, containerHeight]);
|
|
6836
|
-
|
|
6835
|
+
const content = typeof children === "string" ? children : "";
|
|
6836
|
+
const sepIdx = content.indexOf(" \u2014 ");
|
|
6837
|
+
const title = sepIdx >= 0 ? content.slice(0, sepIdx) : content;
|
|
6838
|
+
const desc = sepIdx >= 0 ? content.slice(sepIdx + 3) : "";
|
|
6839
|
+
return /* @__PURE__ */ jsxs197(
|
|
6837
6840
|
"div",
|
|
6838
6841
|
{
|
|
6839
6842
|
ref,
|
|
6840
|
-
className:
|
|
6843
|
+
className: `chart-tooltip chart-tooltip-show chart-tooltip-${tooltipType}`,
|
|
6841
6844
|
style: { left: pos.left, top: pos.top },
|
|
6842
|
-
children
|
|
6845
|
+
children: [
|
|
6846
|
+
title && /* @__PURE__ */ jsx307("div", { className: "chart-tooltip-title", children: title }),
|
|
6847
|
+
desc && /* @__PURE__ */ jsx307("div", { className: "chart-tooltip-desc", children: desc })
|
|
6848
|
+
]
|
|
6843
6849
|
}
|
|
6844
6850
|
);
|
|
6845
6851
|
};
|
|
@@ -6882,8 +6888,8 @@ var ChartLegend = ({ data, labels, type }) => {
|
|
|
6882
6888
|
}) });
|
|
6883
6889
|
};
|
|
6884
6890
|
var Chart = React6.memo((props) => {
|
|
6885
|
-
const { type, data, labels, tooltip: showTooltip = true } = props;
|
|
6886
|
-
const { tooltip, show,
|
|
6891
|
+
const { type, data, labels, tooltip: showTooltip = true, tooltipType = "dark" } = props;
|
|
6892
|
+
const { tooltip, show, hide, move, containerRef } = useChartTooltip(showTooltip);
|
|
6887
6893
|
const { width, height } = useChartSize(containerRef);
|
|
6888
6894
|
const stableData = React6.useMemo(() => data, [JSON.stringify(data)]);
|
|
6889
6895
|
const stableLabels = React6.useMemo(() => labels, [JSON.stringify(labels)]);
|
|
@@ -6891,13 +6897,13 @@ var Chart = React6.memo((props) => {
|
|
|
6891
6897
|
const animate = useChartAnimation(containerRef, dataKey);
|
|
6892
6898
|
const ready = width > 0 && height > 0;
|
|
6893
6899
|
return /* @__PURE__ */ jsxs197("div", { className: "lib-xplat-chart", ref: containerRef, children: [
|
|
6894
|
-
ready && type === "line" && /* @__PURE__ */ jsx307(LineChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show,
|
|
6895
|
-
ready && type === "curve" && /* @__PURE__ */ jsx307(CurveChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show,
|
|
6896
|
-
ready && type === "bar" && /* @__PURE__ */ jsx307(BarChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show,
|
|
6897
|
-
ready && type === "pie" && /* @__PURE__ */ jsx307(PieDonutChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show,
|
|
6898
|
-
ready && type === "doughnut" && /* @__PURE__ */ jsx307(PieDonutChart, { data: stableData, labels: stableLabels, width, height, animate, isDoughnut: true, onHover: show,
|
|
6899
|
-
ready && (type === "
|
|
6900
|
-
tooltip.visible && tooltip.content && /* @__PURE__ */ jsx307(ChartTooltip, { x: tooltip.x, y: tooltip.y, containerWidth: width, containerHeight: height, children: tooltip.content })
|
|
6900
|
+
ready && type === "line" && /* @__PURE__ */ jsx307(LineChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onMove: move, onLeave: hide }),
|
|
6901
|
+
ready && type === "curve" && /* @__PURE__ */ jsx307(CurveChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onMove: move, onLeave: hide }),
|
|
6902
|
+
ready && type === "bar" && /* @__PURE__ */ jsx307(BarChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onMove: move, onLeave: hide }),
|
|
6903
|
+
ready && type === "pie" && /* @__PURE__ */ jsx307(PieDonutChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onMove: move, onLeave: hide }),
|
|
6904
|
+
ready && type === "doughnut" && /* @__PURE__ */ jsx307(PieDonutChart, { data: stableData, labels: stableLabels, width, height, animate, isDoughnut: true, onHover: show, onMove: move, onLeave: hide }),
|
|
6905
|
+
ready && (type === "pie" || type === "doughnut") && /* @__PURE__ */ jsx307(ChartLegend, { data: stableData, labels: stableLabels, type }),
|
|
6906
|
+
tooltip.visible && tooltip.content && /* @__PURE__ */ jsx307(ChartTooltip, { x: tooltip.x, y: tooltip.y, containerWidth: width, containerHeight: height, tooltipType, children: tooltip.content })
|
|
6901
6907
|
] });
|
|
6902
6908
|
});
|
|
6903
6909
|
Chart.displayName = "Chart";
|
|
@@ -9417,18 +9423,94 @@ ToastProvider.displayName = "ToastProvider";
|
|
|
9417
9423
|
|
|
9418
9424
|
// src/components/Tooltip/Tooltip.tsx
|
|
9419
9425
|
import React39 from "react";
|
|
9420
|
-
import { jsx as jsx348, jsxs as jsxs221 } from "react/jsx-runtime";
|
|
9426
|
+
import { Fragment as Fragment5, jsx as jsx348, jsxs as jsxs221 } from "react/jsx-runtime";
|
|
9427
|
+
var OFFSET = 12;
|
|
9428
|
+
var SHOW_DELAY = 300;
|
|
9421
9429
|
var Tooltip = (props) => {
|
|
9422
9430
|
const {
|
|
9423
|
-
type = "
|
|
9431
|
+
type = "dark",
|
|
9432
|
+
title,
|
|
9424
9433
|
description,
|
|
9425
|
-
children
|
|
9434
|
+
children,
|
|
9435
|
+
disabled = false
|
|
9426
9436
|
} = props;
|
|
9427
|
-
const
|
|
9428
|
-
|
|
9429
|
-
|
|
9430
|
-
|
|
9431
|
-
|
|
9437
|
+
const triggerRef = React39.useRef(null);
|
|
9438
|
+
const tooltipRef = React39.useRef(null);
|
|
9439
|
+
const [visible, setVisible] = React39.useState(false);
|
|
9440
|
+
const [pos, setPos] = React39.useState({ left: 0, top: 0 });
|
|
9441
|
+
const delayTimer = React39.useRef(0);
|
|
9442
|
+
const calculatePos = React39.useCallback((clientX, clientY) => {
|
|
9443
|
+
const el = tooltipRef.current;
|
|
9444
|
+
if (!el) return;
|
|
9445
|
+
const w = el.offsetWidth;
|
|
9446
|
+
const h = el.offsetHeight;
|
|
9447
|
+
const vw = window.innerWidth;
|
|
9448
|
+
let left = clientX + OFFSET;
|
|
9449
|
+
let top = clientY - h - OFFSET;
|
|
9450
|
+
if (left + w > vw - 8) left = clientX - w - OFFSET;
|
|
9451
|
+
if (top < 8) top = clientY + OFFSET;
|
|
9452
|
+
if (left < 8) left = 8;
|
|
9453
|
+
setPos({ left, top });
|
|
9454
|
+
}, []);
|
|
9455
|
+
const handleMouseEnter = React39.useCallback(() => {
|
|
9456
|
+
if (disabled) return;
|
|
9457
|
+
delayTimer.current = window.setTimeout(() => {
|
|
9458
|
+
setVisible(true);
|
|
9459
|
+
}, SHOW_DELAY);
|
|
9460
|
+
}, [disabled]);
|
|
9461
|
+
const handleMouseMove = React39.useCallback((e) => {
|
|
9462
|
+
if (!visible) return;
|
|
9463
|
+
calculatePos(e.clientX, e.clientY);
|
|
9464
|
+
}, [visible, calculatePos]);
|
|
9465
|
+
const handleMouseLeave = React39.useCallback(() => {
|
|
9466
|
+
window.clearTimeout(delayTimer.current);
|
|
9467
|
+
setVisible(false);
|
|
9468
|
+
}, []);
|
|
9469
|
+
const handleClick = React39.useCallback(() => {
|
|
9470
|
+
window.clearTimeout(delayTimer.current);
|
|
9471
|
+
setVisible(false);
|
|
9472
|
+
}, []);
|
|
9473
|
+
const handleFocus = React39.useCallback(() => {
|
|
9474
|
+
if (disabled) return;
|
|
9475
|
+
setVisible(true);
|
|
9476
|
+
}, [disabled]);
|
|
9477
|
+
const handleBlur = React39.useCallback(() => {
|
|
9478
|
+
setVisible(false);
|
|
9479
|
+
}, []);
|
|
9480
|
+
React39.useLayoutEffect(() => {
|
|
9481
|
+
if (!visible || !triggerRef.current) return;
|
|
9482
|
+
const rect = triggerRef.current.getBoundingClientRect();
|
|
9483
|
+
calculatePos(rect.right, rect.top);
|
|
9484
|
+
}, [visible, calculatePos]);
|
|
9485
|
+
if (!title && !description) return /* @__PURE__ */ jsx348(Fragment5, { children });
|
|
9486
|
+
return /* @__PURE__ */ jsxs221(
|
|
9487
|
+
"div",
|
|
9488
|
+
{
|
|
9489
|
+
ref: triggerRef,
|
|
9490
|
+
className: "lib-xplat-tooltip-trigger",
|
|
9491
|
+
onMouseEnter: handleMouseEnter,
|
|
9492
|
+
onMouseMove: handleMouseMove,
|
|
9493
|
+
onMouseLeave: handleMouseLeave,
|
|
9494
|
+
onClick: handleClick,
|
|
9495
|
+
onFocus: handleFocus,
|
|
9496
|
+
onBlur: handleBlur,
|
|
9497
|
+
children: [
|
|
9498
|
+
children,
|
|
9499
|
+
visible && /* @__PURE__ */ jsx348(Portal_default, { children: /* @__PURE__ */ jsxs221(
|
|
9500
|
+
"div",
|
|
9501
|
+
{
|
|
9502
|
+
ref: tooltipRef,
|
|
9503
|
+
className: clsx_default("lib-xplat-tooltip", type),
|
|
9504
|
+
style: { position: "fixed", left: pos.left, top: pos.top },
|
|
9505
|
+
children: [
|
|
9506
|
+
title && /* @__PURE__ */ jsx348("div", { className: "tooltip-title", children: title }),
|
|
9507
|
+
description && /* @__PURE__ */ jsx348("div", { className: "tooltip-desc", children: description })
|
|
9508
|
+
]
|
|
9509
|
+
}
|
|
9510
|
+
) })
|
|
9511
|
+
]
|
|
9512
|
+
}
|
|
9513
|
+
);
|
|
9432
9514
|
};
|
|
9433
9515
|
Tooltip.displayName = "Tooltip";
|
|
9434
9516
|
var Tooltip_default = Tooltip;
|
|
@@ -9873,11 +9955,11 @@ Header.displayName = "Header";
|
|
|
9873
9955
|
var Header_default = Header;
|
|
9874
9956
|
|
|
9875
9957
|
// src/layout/Layout/Layout.tsx
|
|
9876
|
-
import { Fragment as
|
|
9958
|
+
import { Fragment as Fragment6, jsx as jsx354, jsxs as jsxs224 } from "react/jsx-runtime";
|
|
9877
9959
|
var Layout = (props) => {
|
|
9878
9960
|
const { header, sideBar, children } = props;
|
|
9879
9961
|
return /* @__PURE__ */ jsx354("div", { className: "lib-xplat-layout", children: /* @__PURE__ */ jsxs224("div", { className: "lib-xplat-layout-content-wrapper", children: [
|
|
9880
|
-
sideBar && /* @__PURE__ */ jsx354(
|
|
9962
|
+
sideBar && /* @__PURE__ */ jsx354(Fragment6, { children: sideBar }),
|
|
9881
9963
|
/* @__PURE__ */ jsxs224("div", { className: "lib-xplat-layout-content", children: [
|
|
9882
9964
|
header && /* @__PURE__ */ jsx354("div", { className: "lib-xplat-layout-conent-header", children: header }),
|
|
9883
9965
|
children
|