@hilum/ui 3.2.13 → 3.3.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/README.md +15 -11
- package/dist/index.js +33 -1
- package/dist/index.js.map +1 -1
- package/llms.txt +128 -1491
- package/package.json +1 -1
- package/src/components/chart.tsx +40 -3
package/package.json
CHANGED
package/src/components/chart.tsx
CHANGED
|
@@ -59,12 +59,44 @@ function ChartContainer({
|
|
|
59
59
|
}: ChartContainerProps) {
|
|
60
60
|
const uniqueId = React.useId();
|
|
61
61
|
const chartId = `chart-${id || uniqueId.replace(/:/g, "")}`;
|
|
62
|
+
const containerRef = React.useRef<HTMLDivElement>(null);
|
|
63
|
+
const [canRenderChart, setCanRenderChart] = React.useState(false);
|
|
64
|
+
const initialDimension = React.useMemo(
|
|
65
|
+
() => ({ width: 800, height: typeof height === "number" ? height : 450 }),
|
|
66
|
+
[height],
|
|
67
|
+
);
|
|
62
68
|
const resolvedStyle =
|
|
63
69
|
height === undefined ? style : ({ ...style, height } as React.CSSProperties);
|
|
64
70
|
|
|
71
|
+
React.useEffect(() => {
|
|
72
|
+
const element = containerRef.current;
|
|
73
|
+
|
|
74
|
+
if (!element) {
|
|
75
|
+
return;
|
|
76
|
+
}
|
|
77
|
+
|
|
78
|
+
const updateCanRenderChart = () => {
|
|
79
|
+
const rect = element.getBoundingClientRect();
|
|
80
|
+
setCanRenderChart(rect.width > 0 && rect.height > 0);
|
|
81
|
+
};
|
|
82
|
+
|
|
83
|
+
updateCanRenderChart();
|
|
84
|
+
|
|
85
|
+
if (typeof ResizeObserver === "undefined") {
|
|
86
|
+
setCanRenderChart(true);
|
|
87
|
+
return;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
const observer = new ResizeObserver(updateCanRenderChart);
|
|
91
|
+
observer.observe(element);
|
|
92
|
+
|
|
93
|
+
return () => observer.disconnect();
|
|
94
|
+
}, []);
|
|
95
|
+
|
|
65
96
|
return (
|
|
66
97
|
<ChartContext.Provider value={{ config }}>
|
|
67
98
|
<div
|
|
99
|
+
ref={containerRef}
|
|
68
100
|
data-slot="chart"
|
|
69
101
|
data-chart={chartId}
|
|
70
102
|
className={cn(
|
|
@@ -87,9 +119,14 @@ function ChartContainer({
|
|
|
87
119
|
{...props}
|
|
88
120
|
>
|
|
89
121
|
<ChartStyle id={chartId} config={config} />
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
122
|
+
{canRenderChart ? (
|
|
123
|
+
<RechartsPrimitive.ResponsiveContainer
|
|
124
|
+
initialDimension={initialDimension}
|
|
125
|
+
minWidth={0}
|
|
126
|
+
>
|
|
127
|
+
{children}
|
|
128
|
+
</RechartsPrimitive.ResponsiveContainer>
|
|
129
|
+
) : null}
|
|
93
130
|
</div>
|
|
94
131
|
</ChartContext.Provider>
|
|
95
132
|
);
|