@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.
@@ -2290,15 +2290,11 @@ var useChartTooltip = (enabled) => {
2290
2290
  if (!rect) return;
2291
2291
  setTooltip({ visible: true, x: e.clientX - rect.left, y: e.clientY - rect.top, content });
2292
2292
  }, [enabled]);
2293
- const showAt = React6.useCallback((x, y, content) => {
2294
- if (!enabled) return;
2295
- setTooltip({ visible: true, x, y, content });
2296
- }, [enabled]);
2297
2293
  const hide = React6.useCallback(() => {
2298
2294
  cancelAnimationFrame(rafRef.current);
2299
2295
  setTooltip((prev) => ({ ...prev, visible: false }));
2300
2296
  }, []);
2301
- return { tooltip, show, showAt, hide, move, containerRef };
2297
+ return { tooltip, show, hide, move, containerRef };
2302
2298
  };
2303
2299
  var GridLines = React6.memo(({ width, height, chartH, maxVal }) => /* @__PURE__ */ jsx307(Fragment2, { children: [0, 0.25, 0.5, 0.75, 1].map((ratio) => {
2304
2300
  const y = PADDING.top + (1 - ratio) * chartH;
@@ -2363,7 +2359,7 @@ var useCrosshair = (seriesPoints, entries, labels, chartH) => {
2363
2359
  }, [entries, seriesPoints]);
2364
2360
  return { activeIndex, handleMouseMove, handleMouseLeave, tooltipContent, getTooltipAt };
2365
2361
  };
2366
- var LineChart = React6.memo(({ data, labels, width, height, animate, onHover, onShowAt, onMove, onLeave }) => {
2362
+ var LineChart = React6.memo(({ data, labels, width, height, animate, onHover, onMove, onLeave }) => {
2367
2363
  const entries = React6.useMemo(() => Object.entries(data), [data]);
2368
2364
  const maxVal = React6.useMemo(() => {
2369
2365
  const allValues = entries.flatMap(([, v]) => v);
@@ -2403,9 +2399,8 @@ var LineChart = React6.memo(({ data, labels, width, height, animate, onHover, on
2403
2399
  className: "chart-svg",
2404
2400
  onMouseMove: (e) => {
2405
2401
  handleMouseMove(e);
2406
- if (activeIndex !== null && seriesPoints[0]?.[activeIndex]) {
2407
- const p = seriesPoints[0][activeIndex];
2408
- onShowAt(p.x, p.y, `${labels[activeIndex]} \u2014 ${getTooltipAt(activeIndex)}`);
2402
+ if (activeIndex !== null) {
2403
+ onHover(e, `${labels[activeIndex]} \u2014 ${getTooltipAt(activeIndex)}`);
2409
2404
  } else {
2410
2405
  onLeave();
2411
2406
  }
@@ -2473,7 +2468,7 @@ var LineChart = React6.memo(({ data, labels, width, height, animate, onHover, on
2473
2468
  );
2474
2469
  });
2475
2470
  LineChart.displayName = "LineChart";
2476
- var CurveChart = React6.memo(({ data, labels, width, height, animate, onHover, onShowAt, onMove, onLeave }) => {
2471
+ var CurveChart = React6.memo(({ data, labels, width, height, animate, onHover, onMove, onLeave }) => {
2477
2472
  const entries = React6.useMemo(() => Object.entries(data), [data]);
2478
2473
  const maxVal = React6.useMemo(() => {
2479
2474
  const allValues = entries.flatMap(([, v]) => v);
@@ -2515,7 +2510,7 @@ var CurveChart = React6.memo(({ data, labels, width, height, animate, onHover, o
2515
2510
  handleMouseMove(e);
2516
2511
  if (activeIndex !== null && seriesPoints[0]?.[activeIndex]) {
2517
2512
  const p = seriesPoints[0][activeIndex];
2518
- onShowAt(p.x, p.y, `${labels[activeIndex]} \u2014 ${getTooltipAt(activeIndex)}`);
2513
+ onHover(e, `${labels[activeIndex]} \u2014 ${getTooltipAt(activeIndex)}`);
2519
2514
  } else {
2520
2515
  onLeave();
2521
2516
  }
@@ -2583,7 +2578,7 @@ var CurveChart = React6.memo(({ data, labels, width, height, animate, onHover, o
2583
2578
  );
2584
2579
  });
2585
2580
  CurveChart.displayName = "CurveChart";
2586
- var BarChart = React6.memo(({ data, labels, width, height, animate, onHover, onShowAt, onMove, onLeave }) => {
2581
+ var BarChart = React6.memo(({ data, labels, width, height, animate, onHover, onMove, onLeave }) => {
2587
2582
  const entries = React6.useMemo(() => Object.entries(data), [data]);
2588
2583
  const maxVal = React6.useMemo(() => {
2589
2584
  const allValues = entries.flatMap(([, v]) => v);
@@ -2633,7 +2628,8 @@ var BarChart = React6.memo(({ data, labels, width, height, animate, onHover, onS
2633
2628
  transformOrigin: `${b.x + b.w / 2}px ${baseline}px`,
2634
2629
  animationDelay: `${delay}ms`
2635
2630
  } : void 0,
2636
- onMouseEnter: () => onShowAt(b.x + b.w / 2, b.y, `${key}: ${labels[i]} \u2014 ${b.v}`),
2631
+ onMouseEnter: (e) => onHover(e, `${key}: ${labels[i]} \u2014 ${b.v}`),
2632
+ onMouseMove: onMove,
2637
2633
  onMouseLeave: onLeave
2638
2634
  },
2639
2635
  `${di}-${i}`
@@ -2721,14 +2717,17 @@ var PieDonutChart = React6.memo(
2721
2717
  {
2722
2718
  d: s.d,
2723
2719
  fill: PIE_COLORS[(i + colorOffset) % PIE_COLORS.length],
2724
- className: "chart-slice"
2720
+ className: "chart-slice",
2721
+ onMouseEnter: (e) => onHover(e, `${s.label} \u2014 ${s.v.toLocaleString()} (${s.pct}%)`),
2722
+ onMouseMove: onMove,
2723
+ onMouseLeave: onLeave
2725
2724
  }
2726
2725
  ) }, i)) })
2727
2726
  ] });
2728
2727
  }
2729
2728
  );
2730
2729
  PieDonutChart.displayName = "PieDonutChart";
2731
- var ChartTooltip = ({ x, y, containerWidth, containerHeight, children }) => {
2730
+ var ChartTooltip = ({ x, y, containerWidth, containerHeight, tooltipType, children }) => {
2732
2731
  const ref = React6.useRef(null);
2733
2732
  const [pos, setPos] = React6.useState({ left: 0, top: 0 });
2734
2733
  React6.useLayoutEffect(() => {
@@ -2743,13 +2742,20 @@ var ChartTooltip = ({ x, y, containerWidth, containerHeight, children }) => {
2743
2742
  if (left < 0) left = 0;
2744
2743
  setPos({ left, top });
2745
2744
  }, [x, y, containerWidth, containerHeight]);
2746
- return /* @__PURE__ */ jsx307(
2745
+ const content = typeof children === "string" ? children : "";
2746
+ const sepIdx = content.indexOf(" \u2014 ");
2747
+ const title = sepIdx >= 0 ? content.slice(0, sepIdx) : content;
2748
+ const desc = sepIdx >= 0 ? content.slice(sepIdx + 3) : "";
2749
+ return /* @__PURE__ */ jsxs197(
2747
2750
  "div",
2748
2751
  {
2749
2752
  ref,
2750
- className: "chart-tooltip chart-tooltip-show",
2753
+ className: `chart-tooltip chart-tooltip-show chart-tooltip-${tooltipType}`,
2751
2754
  style: { left: pos.left, top: pos.top },
2752
- children
2755
+ children: [
2756
+ title && /* @__PURE__ */ jsx307("div", { className: "chart-tooltip-title", children: title }),
2757
+ desc && /* @__PURE__ */ jsx307("div", { className: "chart-tooltip-desc", children: desc })
2758
+ ]
2753
2759
  }
2754
2760
  );
2755
2761
  };
@@ -2792,8 +2798,8 @@ var ChartLegend = ({ data, labels, type }) => {
2792
2798
  }) });
2793
2799
  };
2794
2800
  var Chart = React6.memo((props) => {
2795
- const { type, data, labels, tooltip: showTooltip = true } = props;
2796
- const { tooltip, show, showAt, hide, move, containerRef } = useChartTooltip(showTooltip);
2801
+ const { type, data, labels, tooltip: showTooltip = true, tooltipType = "dark" } = props;
2802
+ const { tooltip, show, hide, move, containerRef } = useChartTooltip(showTooltip);
2797
2803
  const { width, height } = useChartSize(containerRef);
2798
2804
  const stableData = React6.useMemo(() => data, [JSON.stringify(data)]);
2799
2805
  const stableLabels = React6.useMemo(() => labels, [JSON.stringify(labels)]);
@@ -2801,13 +2807,13 @@ var Chart = React6.memo((props) => {
2801
2807
  const animate = useChartAnimation(containerRef, dataKey);
2802
2808
  const ready = width > 0 && height > 0;
2803
2809
  return /* @__PURE__ */ jsxs197("div", { className: "lib-xplat-chart", ref: containerRef, children: [
2804
- ready && type === "line" && /* @__PURE__ */ jsx307(LineChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onShowAt: showAt, onMove: move, onLeave: hide }),
2805
- ready && type === "curve" && /* @__PURE__ */ jsx307(CurveChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onShowAt: showAt, onMove: move, onLeave: hide }),
2806
- ready && type === "bar" && /* @__PURE__ */ jsx307(BarChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onShowAt: showAt, onMove: move, onLeave: hide }),
2807
- ready && type === "pie" && /* @__PURE__ */ jsx307(PieDonutChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onShowAt: showAt, onMove: move, onLeave: hide }),
2808
- ready && type === "doughnut" && /* @__PURE__ */ jsx307(PieDonutChart, { data: stableData, labels: stableLabels, width, height, animate, isDoughnut: true, onHover: show, onShowAt: showAt, onMove: move, onLeave: hide }),
2809
- ready && (type === "bar" || type === "pie" || type === "doughnut") && /* @__PURE__ */ jsx307(ChartLegend, { data: stableData, labels: stableLabels, type }),
2810
- tooltip.visible && tooltip.content && /* @__PURE__ */ jsx307(ChartTooltip, { x: tooltip.x, y: tooltip.y, containerWidth: width, containerHeight: height, children: tooltip.content })
2810
+ ready && type === "line" && /* @__PURE__ */ jsx307(LineChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onMove: move, onLeave: hide }),
2811
+ ready && type === "curve" && /* @__PURE__ */ jsx307(CurveChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onMove: move, onLeave: hide }),
2812
+ ready && type === "bar" && /* @__PURE__ */ jsx307(BarChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onMove: move, onLeave: hide }),
2813
+ ready && type === "pie" && /* @__PURE__ */ jsx307(PieDonutChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onMove: move, onLeave: hide }),
2814
+ ready && type === "doughnut" && /* @__PURE__ */ jsx307(PieDonutChart, { data: stableData, labels: stableLabels, width, height, animate, isDoughnut: true, onHover: show, onMove: move, onLeave: hide }),
2815
+ ready && (type === "pie" || type === "doughnut") && /* @__PURE__ */ jsx307(ChartLegend, { data: stableData, labels: stableLabels, type }),
2816
+ tooltip.visible && tooltip.content && /* @__PURE__ */ jsx307(ChartTooltip, { x: tooltip.x, y: tooltip.y, containerWidth: width, containerHeight: height, tooltipType, children: tooltip.content })
2811
2817
  ] });
2812
2818
  });
2813
2819
  Chart.displayName = "Chart";
@@ -5314,18 +5320,94 @@ ToastProvider.displayName = "ToastProvider";
5314
5320
 
5315
5321
  // src/components/Tooltip/Tooltip.tsx
5316
5322
  import React39 from "react";
5317
- import { jsx as jsx348, jsxs as jsxs221 } from "react/jsx-runtime";
5323
+ import { Fragment as Fragment5, jsx as jsx348, jsxs as jsxs221 } from "react/jsx-runtime";
5324
+ var OFFSET = 12;
5325
+ var SHOW_DELAY = 300;
5318
5326
  var Tooltip = (props) => {
5319
5327
  const {
5320
- type = "primary",
5328
+ type = "dark",
5329
+ title,
5321
5330
  description,
5322
- children
5331
+ children,
5332
+ disabled = false
5323
5333
  } = props;
5324
- const iconRef = React39.useRef(null);
5325
- return /* @__PURE__ */ jsxs221("div", { className: "lib-xplat-tooltip", children: [
5326
- /* @__PURE__ */ jsx348("div", { className: "tooltip-content", ref: iconRef, children: children || "Tooltip" }),
5327
- /* @__PURE__ */ jsx348("div", { className: clsx_default("tooltip-wrapper", type), children: description })
5328
- ] });
5334
+ const triggerRef = React39.useRef(null);
5335
+ const tooltipRef = React39.useRef(null);
5336
+ const [visible, setVisible] = React39.useState(false);
5337
+ const [pos, setPos] = React39.useState({ left: 0, top: 0 });
5338
+ const delayTimer = React39.useRef(0);
5339
+ const calculatePos = React39.useCallback((clientX, clientY) => {
5340
+ const el = tooltipRef.current;
5341
+ if (!el) return;
5342
+ const w = el.offsetWidth;
5343
+ const h = el.offsetHeight;
5344
+ const vw = window.innerWidth;
5345
+ let left = clientX + OFFSET;
5346
+ let top = clientY - h - OFFSET;
5347
+ if (left + w > vw - 8) left = clientX - w - OFFSET;
5348
+ if (top < 8) top = clientY + OFFSET;
5349
+ if (left < 8) left = 8;
5350
+ setPos({ left, top });
5351
+ }, []);
5352
+ const handleMouseEnter = React39.useCallback(() => {
5353
+ if (disabled) return;
5354
+ delayTimer.current = window.setTimeout(() => {
5355
+ setVisible(true);
5356
+ }, SHOW_DELAY);
5357
+ }, [disabled]);
5358
+ const handleMouseMove = React39.useCallback((e) => {
5359
+ if (!visible) return;
5360
+ calculatePos(e.clientX, e.clientY);
5361
+ }, [visible, calculatePos]);
5362
+ const handleMouseLeave = React39.useCallback(() => {
5363
+ window.clearTimeout(delayTimer.current);
5364
+ setVisible(false);
5365
+ }, []);
5366
+ const handleClick = React39.useCallback(() => {
5367
+ window.clearTimeout(delayTimer.current);
5368
+ setVisible(false);
5369
+ }, []);
5370
+ const handleFocus = React39.useCallback(() => {
5371
+ if (disabled) return;
5372
+ setVisible(true);
5373
+ }, [disabled]);
5374
+ const handleBlur = React39.useCallback(() => {
5375
+ setVisible(false);
5376
+ }, []);
5377
+ React39.useLayoutEffect(() => {
5378
+ if (!visible || !triggerRef.current) return;
5379
+ const rect = triggerRef.current.getBoundingClientRect();
5380
+ calculatePos(rect.right, rect.top);
5381
+ }, [visible, calculatePos]);
5382
+ if (!title && !description) return /* @__PURE__ */ jsx348(Fragment5, { children });
5383
+ return /* @__PURE__ */ jsxs221(
5384
+ "div",
5385
+ {
5386
+ ref: triggerRef,
5387
+ className: "lib-xplat-tooltip-trigger",
5388
+ onMouseEnter: handleMouseEnter,
5389
+ onMouseMove: handleMouseMove,
5390
+ onMouseLeave: handleMouseLeave,
5391
+ onClick: handleClick,
5392
+ onFocus: handleFocus,
5393
+ onBlur: handleBlur,
5394
+ children: [
5395
+ children,
5396
+ visible && /* @__PURE__ */ jsx348(Portal_default, { children: /* @__PURE__ */ jsxs221(
5397
+ "div",
5398
+ {
5399
+ ref: tooltipRef,
5400
+ className: clsx_default("lib-xplat-tooltip", type),
5401
+ style: { position: "fixed", left: pos.left, top: pos.top },
5402
+ children: [
5403
+ title && /* @__PURE__ */ jsx348("div", { className: "tooltip-title", children: title }),
5404
+ description && /* @__PURE__ */ jsx348("div", { className: "tooltip-desc", children: description })
5405
+ ]
5406
+ }
5407
+ ) })
5408
+ ]
5409
+ }
5410
+ );
5329
5411
  };
5330
5412
  Tooltip.displayName = "Tooltip";
5331
5413
  var Tooltip_default = Tooltip;
package/dist/index.cjs CHANGED
@@ -6779,15 +6779,11 @@ var useChartTooltip = (enabled) => {
6779
6779
  if (!rect) return;
6780
6780
  setTooltip({ visible: true, x: e.clientX - rect.left, y: e.clientY - rect.top, content });
6781
6781
  }, [enabled]);
6782
- const showAt = import_react6.default.useCallback((x, y, content) => {
6783
- if (!enabled) return;
6784
- setTooltip({ visible: true, x, y, content });
6785
- }, [enabled]);
6786
6782
  const hide = import_react6.default.useCallback(() => {
6787
6783
  cancelAnimationFrame(rafRef.current);
6788
6784
  setTooltip((prev) => ({ ...prev, visible: false }));
6789
6785
  }, []);
6790
- return { tooltip, show, showAt, hide, move, containerRef };
6786
+ return { tooltip, show, hide, move, containerRef };
6791
6787
  };
6792
6788
  var GridLines = import_react6.default.memo(({ width, height, chartH, maxVal }) => /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(import_jsx_runtime307.Fragment, { children: [0, 0.25, 0.5, 0.75, 1].map((ratio) => {
6793
6789
  const y = PADDING.top + (1 - ratio) * chartH;
@@ -6852,7 +6848,7 @@ var useCrosshair = (seriesPoints, entries, labels, chartH) => {
6852
6848
  }, [entries, seriesPoints]);
6853
6849
  return { activeIndex, handleMouseMove, handleMouseLeave, tooltipContent, getTooltipAt };
6854
6850
  };
6855
- var LineChart = import_react6.default.memo(({ data, labels, width, height, animate, onHover, onShowAt, onMove, onLeave }) => {
6851
+ var LineChart = import_react6.default.memo(({ data, labels, width, height, animate, onHover, onMove, onLeave }) => {
6856
6852
  const entries = import_react6.default.useMemo(() => Object.entries(data), [data]);
6857
6853
  const maxVal = import_react6.default.useMemo(() => {
6858
6854
  const allValues = entries.flatMap(([, v]) => v);
@@ -6892,9 +6888,8 @@ var LineChart = import_react6.default.memo(({ data, labels, width, height, anima
6892
6888
  className: "chart-svg",
6893
6889
  onMouseMove: (e) => {
6894
6890
  handleMouseMove(e);
6895
- if (activeIndex !== null && seriesPoints[0]?.[activeIndex]) {
6896
- const p = seriesPoints[0][activeIndex];
6897
- onShowAt(p.x, p.y, `${labels[activeIndex]} \u2014 ${getTooltipAt(activeIndex)}`);
6891
+ if (activeIndex !== null) {
6892
+ onHover(e, `${labels[activeIndex]} \u2014 ${getTooltipAt(activeIndex)}`);
6898
6893
  } else {
6899
6894
  onLeave();
6900
6895
  }
@@ -6962,7 +6957,7 @@ var LineChart = import_react6.default.memo(({ data, labels, width, height, anima
6962
6957
  );
6963
6958
  });
6964
6959
  LineChart.displayName = "LineChart";
6965
- var CurveChart = import_react6.default.memo(({ data, labels, width, height, animate, onHover, onShowAt, onMove, onLeave }) => {
6960
+ var CurveChart = import_react6.default.memo(({ data, labels, width, height, animate, onHover, onMove, onLeave }) => {
6966
6961
  const entries = import_react6.default.useMemo(() => Object.entries(data), [data]);
6967
6962
  const maxVal = import_react6.default.useMemo(() => {
6968
6963
  const allValues = entries.flatMap(([, v]) => v);
@@ -7004,7 +6999,7 @@ var CurveChart = import_react6.default.memo(({ data, labels, width, height, anim
7004
6999
  handleMouseMove(e);
7005
7000
  if (activeIndex !== null && seriesPoints[0]?.[activeIndex]) {
7006
7001
  const p = seriesPoints[0][activeIndex];
7007
- onShowAt(p.x, p.y, `${labels[activeIndex]} \u2014 ${getTooltipAt(activeIndex)}`);
7002
+ onHover(e, `${labels[activeIndex]} \u2014 ${getTooltipAt(activeIndex)}`);
7008
7003
  } else {
7009
7004
  onLeave();
7010
7005
  }
@@ -7072,7 +7067,7 @@ var CurveChart = import_react6.default.memo(({ data, labels, width, height, anim
7072
7067
  );
7073
7068
  });
7074
7069
  CurveChart.displayName = "CurveChart";
7075
- var BarChart = import_react6.default.memo(({ data, labels, width, height, animate, onHover, onShowAt, onMove, onLeave }) => {
7070
+ var BarChart = import_react6.default.memo(({ data, labels, width, height, animate, onHover, onMove, onLeave }) => {
7076
7071
  const entries = import_react6.default.useMemo(() => Object.entries(data), [data]);
7077
7072
  const maxVal = import_react6.default.useMemo(() => {
7078
7073
  const allValues = entries.flatMap(([, v]) => v);
@@ -7122,7 +7117,8 @@ var BarChart = import_react6.default.memo(({ data, labels, width, height, animat
7122
7117
  transformOrigin: `${b.x + b.w / 2}px ${baseline}px`,
7123
7118
  animationDelay: `${delay}ms`
7124
7119
  } : void 0,
7125
- onMouseEnter: () => onShowAt(b.x + b.w / 2, b.y, `${key}: ${labels[i]} \u2014 ${b.v}`),
7120
+ onMouseEnter: (e) => onHover(e, `${key}: ${labels[i]} \u2014 ${b.v}`),
7121
+ onMouseMove: onMove,
7126
7122
  onMouseLeave: onLeave
7127
7123
  },
7128
7124
  `${di}-${i}`
@@ -7210,14 +7206,17 @@ var PieDonutChart = import_react6.default.memo(
7210
7206
  {
7211
7207
  d: s.d,
7212
7208
  fill: PIE_COLORS[(i + colorOffset) % PIE_COLORS.length],
7213
- className: "chart-slice"
7209
+ className: "chart-slice",
7210
+ onMouseEnter: (e) => onHover(e, `${s.label} \u2014 ${s.v.toLocaleString()} (${s.pct}%)`),
7211
+ onMouseMove: onMove,
7212
+ onMouseLeave: onLeave
7214
7213
  }
7215
7214
  ) }, i)) })
7216
7215
  ] });
7217
7216
  }
7218
7217
  );
7219
7218
  PieDonutChart.displayName = "PieDonutChart";
7220
- var ChartTooltip = ({ x, y, containerWidth, containerHeight, children }) => {
7219
+ var ChartTooltip = ({ x, y, containerWidth, containerHeight, tooltipType, children }) => {
7221
7220
  const ref = import_react6.default.useRef(null);
7222
7221
  const [pos, setPos] = import_react6.default.useState({ left: 0, top: 0 });
7223
7222
  import_react6.default.useLayoutEffect(() => {
@@ -7232,13 +7231,20 @@ var ChartTooltip = ({ x, y, containerWidth, containerHeight, children }) => {
7232
7231
  if (left < 0) left = 0;
7233
7232
  setPos({ left, top });
7234
7233
  }, [x, y, containerWidth, containerHeight]);
7235
- return /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(
7234
+ const content = typeof children === "string" ? children : "";
7235
+ const sepIdx = content.indexOf(" \u2014 ");
7236
+ const title = sepIdx >= 0 ? content.slice(0, sepIdx) : content;
7237
+ const desc = sepIdx >= 0 ? content.slice(sepIdx + 3) : "";
7238
+ return /* @__PURE__ */ (0, import_jsx_runtime307.jsxs)(
7236
7239
  "div",
7237
7240
  {
7238
7241
  ref,
7239
- className: "chart-tooltip chart-tooltip-show",
7242
+ className: `chart-tooltip chart-tooltip-show chart-tooltip-${tooltipType}`,
7240
7243
  style: { left: pos.left, top: pos.top },
7241
- children
7244
+ children: [
7245
+ title && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)("div", { className: "chart-tooltip-title", children: title }),
7246
+ desc && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)("div", { className: "chart-tooltip-desc", children: desc })
7247
+ ]
7242
7248
  }
7243
7249
  );
7244
7250
  };
@@ -7281,8 +7287,8 @@ var ChartLegend = ({ data, labels, type }) => {
7281
7287
  }) });
7282
7288
  };
7283
7289
  var Chart = import_react6.default.memo((props) => {
7284
- const { type, data, labels, tooltip: showTooltip = true } = props;
7285
- const { tooltip, show, showAt, hide, move, containerRef } = useChartTooltip(showTooltip);
7290
+ const { type, data, labels, tooltip: showTooltip = true, tooltipType = "dark" } = props;
7291
+ const { tooltip, show, hide, move, containerRef } = useChartTooltip(showTooltip);
7286
7292
  const { width, height } = useChartSize(containerRef);
7287
7293
  const stableData = import_react6.default.useMemo(() => data, [JSON.stringify(data)]);
7288
7294
  const stableLabels = import_react6.default.useMemo(() => labels, [JSON.stringify(labels)]);
@@ -7290,13 +7296,13 @@ var Chart = import_react6.default.memo((props) => {
7290
7296
  const animate = useChartAnimation(containerRef, dataKey);
7291
7297
  const ready = width > 0 && height > 0;
7292
7298
  return /* @__PURE__ */ (0, import_jsx_runtime307.jsxs)("div", { className: "lib-xplat-chart", ref: containerRef, children: [
7293
- ready && type === "line" && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(LineChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onShowAt: showAt, onMove: move, onLeave: hide }),
7294
- ready && type === "curve" && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(CurveChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onShowAt: showAt, onMove: move, onLeave: hide }),
7295
- ready && type === "bar" && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(BarChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onShowAt: showAt, onMove: move, onLeave: hide }),
7296
- ready && type === "pie" && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(PieDonutChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onShowAt: showAt, onMove: move, onLeave: hide }),
7297
- ready && type === "doughnut" && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(PieDonutChart, { data: stableData, labels: stableLabels, width, height, animate, isDoughnut: true, onHover: show, onShowAt: showAt, onMove: move, onLeave: hide }),
7298
- ready && (type === "bar" || type === "pie" || type === "doughnut") && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(ChartLegend, { data: stableData, labels: stableLabels, type }),
7299
- tooltip.visible && tooltip.content && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(ChartTooltip, { x: tooltip.x, y: tooltip.y, containerWidth: width, containerHeight: height, children: tooltip.content })
7299
+ ready && type === "line" && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(LineChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onMove: move, onLeave: hide }),
7300
+ ready && type === "curve" && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(CurveChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onMove: move, onLeave: hide }),
7301
+ ready && type === "bar" && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(BarChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onMove: move, onLeave: hide }),
7302
+ ready && type === "pie" && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(PieDonutChart, { data: stableData, labels: stableLabels, width, height, animate, onHover: show, onMove: move, onLeave: hide }),
7303
+ ready && type === "doughnut" && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(PieDonutChart, { data: stableData, labels: stableLabels, width, height, animate, isDoughnut: true, onHover: show, onMove: move, onLeave: hide }),
7304
+ ready && (type === "pie" || type === "doughnut") && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(ChartLegend, { data: stableData, labels: stableLabels, type }),
7305
+ tooltip.visible && tooltip.content && /* @__PURE__ */ (0, import_jsx_runtime307.jsx)(ChartTooltip, { x: tooltip.x, y: tooltip.y, containerWidth: width, containerHeight: height, tooltipType, children: tooltip.content })
7300
7306
  ] });
7301
7307
  });
7302
7308
  Chart.displayName = "Chart";
@@ -9817,17 +9823,93 @@ ToastProvider.displayName = "ToastProvider";
9817
9823
  // src/components/Tooltip/Tooltip.tsx
9818
9824
  var import_react40 = __toESM(require("react"), 1);
9819
9825
  var import_jsx_runtime348 = require("react/jsx-runtime");
9826
+ var OFFSET = 12;
9827
+ var SHOW_DELAY = 300;
9820
9828
  var Tooltip = (props) => {
9821
9829
  const {
9822
- type = "primary",
9830
+ type = "dark",
9831
+ title,
9823
9832
  description,
9824
- children
9833
+ children,
9834
+ disabled = false
9825
9835
  } = props;
9826
- const iconRef = import_react40.default.useRef(null);
9827
- return /* @__PURE__ */ (0, import_jsx_runtime348.jsxs)("div", { className: "lib-xplat-tooltip", children: [
9828
- /* @__PURE__ */ (0, import_jsx_runtime348.jsx)("div", { className: "tooltip-content", ref: iconRef, children: children || "Tooltip" }),
9829
- /* @__PURE__ */ (0, import_jsx_runtime348.jsx)("div", { className: clsx_default("tooltip-wrapper", type), children: description })
9830
- ] });
9836
+ const triggerRef = import_react40.default.useRef(null);
9837
+ const tooltipRef = import_react40.default.useRef(null);
9838
+ const [visible, setVisible] = import_react40.default.useState(false);
9839
+ const [pos, setPos] = import_react40.default.useState({ left: 0, top: 0 });
9840
+ const delayTimer = import_react40.default.useRef(0);
9841
+ const calculatePos = import_react40.default.useCallback((clientX, clientY) => {
9842
+ const el = tooltipRef.current;
9843
+ if (!el) return;
9844
+ const w = el.offsetWidth;
9845
+ const h = el.offsetHeight;
9846
+ const vw = window.innerWidth;
9847
+ let left = clientX + OFFSET;
9848
+ let top = clientY - h - OFFSET;
9849
+ if (left + w > vw - 8) left = clientX - w - OFFSET;
9850
+ if (top < 8) top = clientY + OFFSET;
9851
+ if (left < 8) left = 8;
9852
+ setPos({ left, top });
9853
+ }, []);
9854
+ const handleMouseEnter = import_react40.default.useCallback(() => {
9855
+ if (disabled) return;
9856
+ delayTimer.current = window.setTimeout(() => {
9857
+ setVisible(true);
9858
+ }, SHOW_DELAY);
9859
+ }, [disabled]);
9860
+ const handleMouseMove = import_react40.default.useCallback((e) => {
9861
+ if (!visible) return;
9862
+ calculatePos(e.clientX, e.clientY);
9863
+ }, [visible, calculatePos]);
9864
+ const handleMouseLeave = import_react40.default.useCallback(() => {
9865
+ window.clearTimeout(delayTimer.current);
9866
+ setVisible(false);
9867
+ }, []);
9868
+ const handleClick = import_react40.default.useCallback(() => {
9869
+ window.clearTimeout(delayTimer.current);
9870
+ setVisible(false);
9871
+ }, []);
9872
+ const handleFocus = import_react40.default.useCallback(() => {
9873
+ if (disabled) return;
9874
+ setVisible(true);
9875
+ }, [disabled]);
9876
+ const handleBlur = import_react40.default.useCallback(() => {
9877
+ setVisible(false);
9878
+ }, []);
9879
+ import_react40.default.useLayoutEffect(() => {
9880
+ if (!visible || !triggerRef.current) return;
9881
+ const rect = triggerRef.current.getBoundingClientRect();
9882
+ calculatePos(rect.right, rect.top);
9883
+ }, [visible, calculatePos]);
9884
+ if (!title && !description) return /* @__PURE__ */ (0, import_jsx_runtime348.jsx)(import_jsx_runtime348.Fragment, { children });
9885
+ return /* @__PURE__ */ (0, import_jsx_runtime348.jsxs)(
9886
+ "div",
9887
+ {
9888
+ ref: triggerRef,
9889
+ className: "lib-xplat-tooltip-trigger",
9890
+ onMouseEnter: handleMouseEnter,
9891
+ onMouseMove: handleMouseMove,
9892
+ onMouseLeave: handleMouseLeave,
9893
+ onClick: handleClick,
9894
+ onFocus: handleFocus,
9895
+ onBlur: handleBlur,
9896
+ children: [
9897
+ children,
9898
+ visible && /* @__PURE__ */ (0, import_jsx_runtime348.jsx)(Portal_default, { children: /* @__PURE__ */ (0, import_jsx_runtime348.jsxs)(
9899
+ "div",
9900
+ {
9901
+ ref: tooltipRef,
9902
+ className: clsx_default("lib-xplat-tooltip", type),
9903
+ style: { position: "fixed", left: pos.left, top: pos.top },
9904
+ children: [
9905
+ title && /* @__PURE__ */ (0, import_jsx_runtime348.jsx)("div", { className: "tooltip-title", children: title }),
9906
+ description && /* @__PURE__ */ (0, import_jsx_runtime348.jsx)("div", { className: "tooltip-desc", children: description })
9907
+ ]
9908
+ }
9909
+ ) })
9910
+ ]
9911
+ }
9912
+ );
9831
9913
  };
9832
9914
  Tooltip.displayName = "Tooltip";
9833
9915
  var Tooltip_default = Tooltip;
package/dist/index.css CHANGED
@@ -2034,17 +2034,37 @@
2034
2034
  position: absolute;
2035
2035
  z-index: 10;
2036
2036
  padding: var(--spacing-space-3);
2037
- background-color: var(--semantic-surface-neutral-strong);
2038
- color: var(--semantic-text-inverse);
2039
- font-size: 12px;
2040
- line-height: 18px;
2041
- font-weight: 500;
2042
2037
  border-radius: var(--spacing-radius-md);
2043
2038
  max-width: 240px;
2044
2039
  pointer-events: none;
2045
- box-shadow: 0 2px 8px rgba(0, 0, 0, 0.15);
2046
2040
  animation: chart-tooltip-in 120ms ease-out;
2047
2041
  }
2042
+ .lib-xplat-chart .chart-tooltip .chart-tooltip-title {
2043
+ font-size: 13px;
2044
+ line-height: 18px;
2045
+ font-weight: 400;
2046
+ }
2047
+ .lib-xplat-chart .chart-tooltip .chart-tooltip-desc {
2048
+ font-size: 12px;
2049
+ line-height: 18px;
2050
+ font-weight: 400;
2051
+ }
2052
+ .lib-xplat-chart .chart-tooltip.chart-tooltip-dark {
2053
+ background-color: var(--semantic-surface-neutral-strong);
2054
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
2055
+ }
2056
+ .lib-xplat-chart .chart-tooltip.chart-tooltip-dark .chart-tooltip-title,
2057
+ .lib-xplat-chart .chart-tooltip.chart-tooltip-dark .chart-tooltip-desc {
2058
+ color: var(--semantic-text-inverse);
2059
+ }
2060
+ .lib-xplat-chart .chart-tooltip.chart-tooltip-light {
2061
+ background-color: var(--semantic-surface-neutral-default);
2062
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
2063
+ }
2064
+ .lib-xplat-chart .chart-tooltip.chart-tooltip-light .chart-tooltip-title,
2065
+ .lib-xplat-chart .chart-tooltip.chart-tooltip-light .chart-tooltip-desc {
2066
+ color: var(--semantic-text-subtle);
2067
+ }
2048
2068
  .lib-xplat-chart .chart-legend {
2049
2069
  display: flex;
2050
2070
  flex-wrap: wrap;
@@ -4435,50 +4455,50 @@
4435
4455
  }
4436
4456
 
4437
4457
  /* src/components/Tooltip/tooltip.scss */
4458
+ .lib-xplat-tooltip-trigger {
4459
+ display: inline-flex;
4460
+ }
4438
4461
  .lib-xplat-tooltip {
4439
- width: fit-content;
4440
- position: relative;
4462
+ z-index: 1100;
4463
+ padding: var(--spacing-space-3);
4464
+ border-radius: var(--spacing-radius-md);
4465
+ max-width: 240px;
4466
+ pointer-events: none;
4467
+ animation: tooltip-show 120ms ease-out;
4441
4468
  }
4442
- .lib-xplat-tooltip > .tooltip-content {
4443
- width: fit-content;
4444
- height: fit-content;
4469
+ .lib-xplat-tooltip .tooltip-title {
4470
+ font-size: 13px;
4471
+ line-height: 18px;
4472
+ font-weight: 400;
4445
4473
  }
4446
- .lib-xplat-tooltip > .tooltip-wrapper {
4447
- position: absolute;
4448
- transform: translateX(-50%) scale(0.5);
4449
- left: 50%;
4450
- box-shadow: 0 2px 6px rgba(0, 0, 0, 0.15);
4451
- white-space: nowrap;
4452
- border-radius: var(--spacing-radius-sm);
4453
- padding: var(--spacing-space-2) var(--spacing-space-2);
4454
- opacity: 0;
4455
- pointer-events: none;
4456
- bottom: 100%;
4457
- transition: opacity 0.12s ease, transform 0.15s cubic-bezier(0.16, 1, 0.3, 1);
4474
+ .lib-xplat-tooltip .tooltip-desc {
4475
+ font-size: 12px;
4476
+ line-height: 18px;
4477
+ font-weight: 400;
4458
4478
  }
4459
- .lib-xplat-tooltip > .tooltip-wrapper.primary {
4460
- color: var(--semantic-text-inverse);
4479
+ .lib-xplat-tooltip.dark {
4461
4480
  background-color: var(--semantic-surface-neutral-strong);
4481
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.15);
4462
4482
  }
4463
- .lib-xplat-tooltip > .tooltip-wrapper.secondary {
4464
- background-color: var(--semantic-surface-neutral-default);
4465
- color: var(--semantic-text-strong);
4483
+ .lib-xplat-tooltip.dark .tooltip-title,
4484
+ .lib-xplat-tooltip.dark .tooltip-desc {
4485
+ color: var(--semantic-text-inverse);
4466
4486
  }
4467
- .lib-xplat-tooltip.tooltip-bottom > .tooltip-wrapper {
4468
- top: 100%;
4469
- bottom: auto;
4470
- transform-origin: top center;
4487
+ .lib-xplat-tooltip.light {
4488
+ background-color: var(--semantic-surface-neutral-default);
4489
+ box-shadow: 0 4px 12px rgba(0, 0, 0, 0.08);
4471
4490
  }
4472
- .lib-xplat-tooltip.tooltip-top > .tooltip-wrapper {
4473
- bottom: 100%;
4474
- top: auto;
4475
- transform-origin: bottom center;
4491
+ .lib-xplat-tooltip.light .tooltip-title,
4492
+ .lib-xplat-tooltip.light .tooltip-desc {
4493
+ color: var(--semantic-text-subtle);
4476
4494
  }
4477
- .lib-xplat-tooltip:hover > .tooltip-content + .tooltip-wrapper,
4478
- .lib-xplat-tooltip > .tooltip-content:hover + .tooltip-wrapper {
4479
- opacity: 1;
4480
- pointer-events: auto;
4481
- transform: translateX(-50%) scale(1);
4495
+ @keyframes tooltip-show {
4496
+ from {
4497
+ opacity: 0;
4498
+ }
4499
+ to {
4500
+ opacity: 1;
4501
+ }
4482
4502
  }
4483
4503
 
4484
4504
  /* src/components/Video/video.scss */