@particle-network/ui-react 0.7.0-beta.13 → 0.7.0-beta.14

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.
@@ -5,36 +5,61 @@ import { radiusMap, useThemeColor } from "@particle-network/ui-shared";
5
5
  import { useSize } from "ahooks";
6
6
  import { cn } from "../../utils/index.js";
7
7
  import { Center } from "../layout/index.js";
8
+ function createPathData(x, y, w, h, r) {
9
+ if (0 === r) return `
10
+ M ${x + w} ${y + h}
11
+ L ${x} ${y + h}
12
+ L ${x} ${y}
13
+ L ${x + w} ${y}
14
+ Z
15
+ `;
16
+ return `
17
+ M ${x + w - r} ${y + h}
18
+ L ${x + r} ${y + h}
19
+ Q ${x} ${y + h} ${x} ${y + h - r}
20
+ L ${x} ${y + r}
21
+ Q ${x} ${y} ${x + r} ${y}
22
+ L ${x + w - r} ${y}
23
+ Q ${x + w} ${y} ${x + w} ${y + r}
24
+ L ${x + w} ${y + h - r}
25
+ Q ${x + w} ${y + h} ${x + w - r} ${y + h}
26
+ Z
27
+ `;
28
+ }
8
29
  const ProgressWrapper = ({ className, value = 0, width, height, radius = 'sm', strokeWidth = 1, color = 'primary', children, svgClassName, ...restProps })=>{
9
30
  const uxColors = useThemeColor();
10
31
  const autoLayout = !width && !height;
11
32
  const containerRef = useRef(null);
12
- const { width: childWidth, height: childHeight } = useSize(containerRef) ?? {
13
- width: 0,
14
- height: 0
15
- };
16
- const widthValue = useMemo(()=>{
17
- if (width) return width;
18
- return childWidth + 2 * strokeWidth;
33
+ const size = useSize(autoLayout ? containerRef : void 0);
34
+ const childWidth = size?.width ?? 0;
35
+ const childHeight = size?.height ?? 0;
36
+ const radiusValue = 'number' == typeof radius ? radius : radiusMap[radius];
37
+ const { widthValue, heightValue, pathData, perimeter, strokeDashoffset } = useMemo(()=>{
38
+ const w = width ?? childWidth + 2 * strokeWidth;
39
+ const h = height ?? childHeight + 2 * strokeWidth;
40
+ const rectWidth = w - strokeWidth;
41
+ const rectHeight = h - strokeWidth;
42
+ const rectXY = strokeWidth / 2;
43
+ const p = 2 * (rectWidth + rectHeight);
44
+ const clamped = Math.max(0, Math.min(100, value));
45
+ const offset = p * (1 - clamped / 100);
46
+ const path = createPathData(rectXY, rectXY, rectWidth, rectHeight, radiusValue);
47
+ return {
48
+ widthValue: w,
49
+ heightValue: h,
50
+ pathData: path,
51
+ perimeter: p,
52
+ strokeDashoffset: offset
53
+ };
19
54
  }, [
55
+ width,
56
+ height,
20
57
  childWidth,
21
- strokeWidth,
22
- width
23
- ]);
24
- const heightValue = useMemo(()=>{
25
- if (height) return height;
26
- return childHeight + 2 * strokeWidth;
27
- }, [
28
58
  childHeight,
29
59
  strokeWidth,
30
- height
60
+ value,
61
+ radiusValue
31
62
  ]);
32
- const clampedProgress = Math.max(0, Math.min(100, value));
33
- const rectWidth = widthValue - strokeWidth;
34
- const rectHeight = heightValue - strokeWidth;
35
- const rectXY = strokeWidth / 2;
36
- const perimeter = 2 * (rectWidth + rectHeight);
37
- const strokeDashoffset = perimeter * (1 - clampedProgress / 100);
38
63
  const colorValue = useMemo(()=>{
39
64
  if ('transparent' === color) return 'transparent';
40
65
  if (color.startsWith('#')) return color;
@@ -50,29 +75,6 @@ const ProgressWrapper = ({ className, value = 0, width, height, radius = 'sm', s
50
75
  color,
51
76
  colorValue
52
77
  ]);
53
- const radiusValue = 'number' == typeof radius ? radius : radiusMap[radius];
54
- const createPathData = (x, y, w, h, r)=>{
55
- if (0 === r) return `
56
- M ${x + w} ${y + h}
57
- L ${x} ${y + h}
58
- L ${x} ${y}
59
- L ${x + w} ${y}
60
- Z
61
- `;
62
- return `
63
- M ${x + w - r} ${y + h}
64
- L ${x + r} ${y + h}
65
- Q ${x} ${y + h} ${x} ${y + h - r}
66
- L ${x} ${y + r}
67
- Q ${x} ${y} ${x + r} ${y}
68
- L ${x + w - r} ${y}
69
- Q ${x + w} ${y} ${x + w} ${y + r}
70
- L ${x + w} ${y + h - r}
71
- Q ${x + w} ${y + h} ${x + w - r} ${y + h}
72
- Z
73
- `;
74
- };
75
- const pathData = createPathData(rectXY, rectXY, rectWidth, rectHeight, radiusValue);
76
78
  return /*#__PURE__*/ jsxs(Center, {
77
79
  style: {
78
80
  width: `${widthValue}px`,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@particle-network/ui-react",
3
- "version": "0.7.0-beta.13",
3
+ "version": "0.7.0-beta.14",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {