@particle-network/ui-react 0.7.0-beta.12 → 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`,
@@ -1,8 +1,11 @@
1
1
  import React from 'react';
2
- import { type UXTooltipProps } from '..';
3
- export type UXHintProps = UXTooltipProps & {
2
+ import { type SimplePopoverPlacement } from '..';
3
+ export interface UXHintProps {
4
+ content?: React.ReactNode;
5
+ children?: React.ReactNode;
4
6
  triggerType?: 'hover' | 'click';
7
+ placement?: SimplePopoverPlacement;
5
8
  buttonClassName?: string;
6
9
  iconClassName?: string;
7
- };
10
+ }
8
11
  export declare const UXHint: React.FC<UXHintProps>;
@@ -1,31 +1,21 @@
1
- import { jsx, jsxs } from "react/jsx-runtime";
1
+ import { jsx } from "react/jsx-runtime";
2
2
  import "react";
3
3
  import CircleQuestionIcon from "@particle-network/icons/web/CircleQuestionIcon";
4
- import { Center, UXPopover, UXPopoverContent, UXPopoverTrigger, UXTooltip } from "../index.js";
4
+ import { Center, UXSimplePopover } from "../index.js";
5
5
  import { cn } from "../../utils/index.js";
6
6
  const UXHint = (props)=>{
7
- const { content, children, buttonClassName, iconClassName, triggerType = 'hover', ...restProps } = props;
8
- const renderTriggerContent = ()=>/*#__PURE__*/ jsx(Center, {
7
+ const { content, children, buttonClassName, iconClassName, triggerType = 'hover', placement = 'top' } = props;
8
+ return /*#__PURE__*/ jsx(UXSimplePopover, {
9
+ content: content || children,
10
+ triggerType: triggerType,
11
+ placement: placement,
12
+ children: /*#__PURE__*/ jsx(Center, {
9
13
  className: cn('min-h-4 min-w-4 cursor-pointer', buttonClassName),
10
14
  children: /*#__PURE__*/ jsx(CircleQuestionIcon, {
11
15
  size: 14,
12
16
  className: iconClassName
13
17
  })
14
- });
15
- if ('hover' === triggerType) return /*#__PURE__*/ jsx(UXTooltip, {
16
- content: content || children,
17
- ...restProps,
18
- children: renderTriggerContent()
19
- });
20
- return /*#__PURE__*/ jsxs(UXPopover, {
21
- children: [
22
- /*#__PURE__*/ jsx(UXPopoverTrigger, {
23
- children: renderTriggerContent()
24
- }),
25
- /*#__PURE__*/ jsx(UXPopoverContent, {
26
- children: content || children
27
- })
28
- ]
18
+ })
29
19
  });
30
20
  };
31
21
  UXHint.displayName = 'UX.Hint';
@@ -1,5 +1,5 @@
1
1
  import React from 'react';
2
- export type SimplePopoverPlacement = 'top' | 'bottom' | 'left' | 'right';
2
+ export type SimplePopoverPlacement = 'top' | 'top-left' | 'top-right' | 'bottom' | 'bottom-left' | 'bottom-right' | 'left' | 'left-top' | 'left-bottom' | 'right' | 'right-top' | 'right-bottom';
3
3
  export type SimplePopoverTriggerType = 'click' | 'hover';
4
4
  export interface UXSimplePopoverProps {
5
5
  /** Popover content */
@@ -14,6 +14,8 @@ export interface UXSimplePopoverProps {
14
14
  delay?: number;
15
15
  /** Hover only: delay before closing (ms) */
16
16
  closeDelay?: number;
17
+ /** Distance between popover and trigger (px) */
18
+ offset?: number;
17
19
  /** ClassName for the trigger wrapper (when cloning a single child, applied to that child) */
18
20
  classNames?: {
19
21
  trigger?: string;
@@ -2,7 +2,7 @@ import { Fragment, jsx, jsxs } from "react/jsx-runtime";
2
2
  import react, { cloneElement, isValidElement, useCallback, useId, useRef } from "react";
3
3
  import { cn } from "../../utils/index.js";
4
4
  const UXSimplePopover = (props)=>{
5
- const { content, children, triggerType = 'hover', placement = 'top', delay = 300, closeDelay = 100, classNames = {
5
+ const { content, children, triggerType = 'hover', placement = 'top', offset = 8, delay = 300, closeDelay = 100, classNames = {
6
6
  trigger: '',
7
7
  content: ''
8
8
  } } = props;
@@ -54,10 +54,26 @@ const UXSimplePopover = (props)=>{
54
54
  const triggerAnchorStyle = {
55
55
  anchorName
56
56
  };
57
+ const offsetMargin = {
58
+ top: {
59
+ marginBottom: offset
60
+ },
61
+ bottom: {
62
+ marginTop: offset
63
+ },
64
+ left: {
65
+ marginRight: offset
66
+ },
67
+ right: {
68
+ marginLeft: offset
69
+ }
70
+ };
71
+ const primarySide = placement.split('-')[0];
57
72
  const popoverAnchorStyle = {
58
73
  positionAnchor: anchorName,
59
- positionArea: placement,
60
- positionTryFallbacks: 'flip-block, flip-inline, flip-block flip-inline'
74
+ positionArea: placement.replace(/-/g, ' '),
75
+ positionTryFallbacks: 'flip-block, flip-inline, flip-block flip-inline',
76
+ ...offsetMargin[primarySide]
61
77
  };
62
78
  const isClick = 'click' === triggerType;
63
79
  const trigger = isClick ? /*#__PURE__*/ jsx("button", {
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@particle-network/ui-react",
3
- "version": "0.7.0-beta.12",
3
+ "version": "0.7.0-beta.14",
4
4
  "type": "module",
5
5
  "exports": {
6
6
  ".": {
@@ -37,8 +37,8 @@
37
37
  "@rslib/core": "^0.12.3",
38
38
  "@types/react": "^19.1.10",
39
39
  "react": "^19.1.0",
40
- "@particle-network/eslint-config": "0.3.0",
41
- "@particle-network/lintstaged-config": "0.1.0"
40
+ "@particle-network/lintstaged-config": "0.1.0",
41
+ "@particle-network/eslint-config": "0.3.0"
42
42
  },
43
43
  "peerDependencies": {
44
44
  "react": ">=16.9.0",