@expcat/tigercat-react 0.1.8 → 0.2.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.
Files changed (169) hide show
  1. package/dist/{chunk-TBIEWDY5.js → chunk-36RRHNZD.js} +13 -2
  2. package/dist/chunk-3CDAG4HD.mjs +151 -0
  3. package/dist/chunk-3QFHVAZT.js +68 -0
  4. package/dist/{chunk-ALP3KYYY.mjs → chunk-3XKBDV2Q.mjs} +5 -5
  5. package/dist/chunk-42UKIFFQ.js +278 -0
  6. package/dist/{chunk-K7ZMB2TH.mjs → chunk-5XKYWZZZ.mjs} +16 -22
  7. package/dist/chunk-677VSTPW.mjs +65 -0
  8. package/dist/chunk-6DYS4PJT.mjs +99 -0
  9. package/dist/chunk-6PBNFLM7.js +95 -0
  10. package/dist/{chunk-DCRVIDMY.mjs → chunk-6ZC7H22S.mjs} +1 -1
  11. package/dist/{chunk-WSCSDSV7.mjs → chunk-7IKJBQQV.mjs} +27 -5
  12. package/dist/{chunk-OTRGVENC.js → chunk-7SLNHUGJ.js} +1 -1
  13. package/dist/chunk-A2UW5OKX.mjs +415 -0
  14. package/dist/{chunk-NOOPXNR4.mjs → chunk-AGUPZEUL.mjs} +2 -3
  15. package/dist/chunk-AX5XRD2Q.js +35 -0
  16. package/dist/{chunk-BJU5N7WU.mjs → chunk-BAPR7UUR.mjs} +7 -7
  17. package/dist/chunk-CBALIFPW.mjs +275 -0
  18. package/dist/{chunk-BIWO5KB4.mjs → chunk-CJJ56NVL.mjs} +2 -2
  19. package/dist/{chunk-ENR3RIMM.js → chunk-DGBYGBLR.js} +72 -59
  20. package/dist/chunk-DUWAV47E.js +42 -0
  21. package/dist/chunk-E5GD3H7L.js +94 -0
  22. package/dist/chunk-EJLJYOO7.js +367 -0
  23. package/dist/{chunk-FQ6UHRAO.js → chunk-GQMYCYZ4.js} +6 -27
  24. package/dist/{chunk-G6FSHN2I.mjs → chunk-GW4EWT2K.mjs} +45 -31
  25. package/dist/{chunk-AQQRWISY.js → chunk-GXTBCX3M.js} +1 -1
  26. package/dist/{chunk-HQXZVTP4.mjs → chunk-HGF2EL25.mjs} +74 -61
  27. package/dist/{chunk-R5BQHZWB.js → chunk-HRYBEBZC.js} +15 -21
  28. package/dist/{chunk-PAD2DX5M.mjs → chunk-IIVRVCCP.mjs} +6 -24
  29. package/dist/chunk-IS467WAO.mjs +39 -0
  30. package/dist/{chunk-CTAMMQBC.mjs → chunk-IS7YOBR7.mjs} +16 -13
  31. package/dist/{chunk-ADOPAXPG.mjs → chunk-JI7SFMUT.mjs} +2 -2
  32. package/dist/chunk-KBGURVTD.mjs +282 -0
  33. package/dist/{chunk-O3EUFIOS.mjs → chunk-KELLYJZY.mjs} +36 -30
  34. package/dist/{chunk-XZDJ5FRB.js → chunk-KPZTGRNA.js} +5 -23
  35. package/dist/chunk-KQZ4F7FZ.js +153 -0
  36. package/dist/{chunk-XDKXL2BP.mjs → chunk-KV4LLPAY.mjs} +14 -3
  37. package/dist/{chunk-LNKI6HQ3.js → chunk-LIJLFLYE.js} +27 -5
  38. package/dist/chunk-LVC43YX2.mjs +72 -0
  39. package/dist/chunk-LZNG2HGC.mjs +227 -0
  40. package/dist/chunk-M375I56K.js +75 -0
  41. package/dist/{chunk-7OLWGHUR.mjs → chunk-MF3H7WWW.mjs} +13 -2
  42. package/dist/chunk-N32MAX4A.js +230 -0
  43. package/dist/{chunk-YYKJ63LD.mjs → chunk-NMDNLB3C.mjs} +7 -28
  44. package/dist/{chunk-77D7VQMG.js → chunk-OD2NNQD2.js} +2 -2
  45. package/dist/chunk-OONM7FO7.js +418 -0
  46. package/dist/{chunk-Q5Q7FG4U.js → chunk-OZLGNWET.js} +7 -7
  47. package/dist/{chunk-LAZGEMA2.mjs → chunk-P4EFJIXU.mjs} +1 -1
  48. package/dist/chunk-QI6WAP6Y.js +285 -0
  49. package/dist/{chunk-WK5HN4OH.js → chunk-QY6I7LU5.js} +43 -29
  50. package/dist/{chunk-KSW5JDIV.js → chunk-R7TOQU3U.js} +1 -1
  51. package/dist/chunk-RQSQXQN6.mjs +91 -0
  52. package/dist/chunk-SDLMB34Y.mjs +32 -0
  53. package/dist/chunk-UG3I4PCY.js +102 -0
  54. package/dist/chunk-VBSK4TGO.mjs +364 -0
  55. package/dist/{chunk-DZJUFU55.js → chunk-VXHBQTZS.js} +14 -11
  56. package/dist/chunk-WLIFEALE.mjs +111 -0
  57. package/dist/{chunk-AQ6DHCP6.js → chunk-XRFK2IXM.js} +4 -4
  58. package/dist/{chunk-5FRENLDC.js → chunk-Y2JOJ4D6.js} +14 -3
  59. package/dist/chunk-YER7IQF4.mjs +429 -0
  60. package/dist/{chunk-NI2WNZRT.js → chunk-YESS6YKC.js} +1 -2
  61. package/dist/chunk-Z6F67MJE.mjs +92 -0
  62. package/dist/{chunk-QORSSZX4.js → chunk-ZPFZMXA6.js} +34 -28
  63. package/dist/chunk-ZUUG3WOL.js +432 -0
  64. package/dist/chunk-ZYPEO2KY.js +115 -0
  65. package/dist/components/AreaChart.d.mts +19 -0
  66. package/dist/components/AreaChart.d.ts +19 -0
  67. package/dist/components/AreaChart.js +23 -0
  68. package/dist/components/AreaChart.mjs +8 -0
  69. package/dist/components/BarChart.d.mts +16 -0
  70. package/dist/components/BarChart.d.ts +16 -0
  71. package/dist/components/BarChart.js +23 -0
  72. package/dist/components/BarChart.mjs +8 -0
  73. package/dist/components/ChartAxis.d.mts +10 -0
  74. package/dist/components/ChartAxis.d.ts +10 -0
  75. package/dist/components/ChartAxis.js +16 -0
  76. package/dist/components/ChartAxis.mjs +1 -0
  77. package/dist/components/ChartCanvas.d.mts +9 -0
  78. package/dist/components/ChartCanvas.d.ts +9 -0
  79. package/dist/components/ChartCanvas.js +16 -0
  80. package/dist/components/ChartCanvas.mjs +1 -0
  81. package/dist/components/ChartGrid.d.mts +11 -0
  82. package/dist/components/ChartGrid.d.ts +11 -0
  83. package/dist/components/ChartGrid.js +16 -0
  84. package/dist/components/ChartGrid.mjs +1 -0
  85. package/dist/components/ChartLegend.d.mts +17 -0
  86. package/dist/components/ChartLegend.d.ts +17 -0
  87. package/dist/components/ChartLegend.js +16 -0
  88. package/dist/components/ChartLegend.mjs +1 -0
  89. package/dist/components/ChartSeries.d.mts +18 -0
  90. package/dist/components/ChartSeries.d.ts +18 -0
  91. package/dist/components/ChartSeries.js +16 -0
  92. package/dist/components/ChartSeries.mjs +1 -0
  93. package/dist/components/ChartTooltip.d.mts +12 -0
  94. package/dist/components/ChartTooltip.d.ts +12 -0
  95. package/dist/components/ChartTooltip.js +16 -0
  96. package/dist/components/ChartTooltip.mjs +1 -0
  97. package/dist/components/DonutChart.d.mts +14 -0
  98. package/dist/components/DonutChart.d.ts +14 -0
  99. package/dist/components/DonutChart.js +21 -0
  100. package/dist/components/DonutChart.mjs +6 -0
  101. package/dist/components/Drawer.js +3 -3
  102. package/dist/components/Drawer.mjs +2 -2
  103. package/dist/components/Dropdown.d.mts +12 -2
  104. package/dist/components/Dropdown.d.ts +12 -2
  105. package/dist/components/Dropdown.js +4 -4
  106. package/dist/components/Dropdown.mjs +2 -2
  107. package/dist/components/DropdownItem.js +4 -4
  108. package/dist/components/DropdownItem.mjs +3 -3
  109. package/dist/components/Icon.js +2 -2
  110. package/dist/components/Icon.mjs +1 -1
  111. package/dist/components/LineChart.d.mts +19 -0
  112. package/dist/components/LineChart.d.ts +19 -0
  113. package/dist/components/LineChart.js +23 -0
  114. package/dist/components/LineChart.mjs +8 -0
  115. package/dist/components/List.js +3 -3
  116. package/dist/components/List.mjs +2 -2
  117. package/dist/components/Message.js +4 -4
  118. package/dist/components/Message.mjs +1 -1
  119. package/dist/components/Modal.js +3 -3
  120. package/dist/components/Modal.mjs +2 -2
  121. package/dist/components/Notification.js +4 -4
  122. package/dist/components/Notification.mjs +1 -1
  123. package/dist/components/Pagination.d.mts +5 -1
  124. package/dist/components/Pagination.d.ts +5 -1
  125. package/dist/components/Pagination.js +3 -3
  126. package/dist/components/Pagination.mjs +1 -1
  127. package/dist/components/PieChart.d.mts +14 -0
  128. package/dist/components/PieChart.d.ts +14 -0
  129. package/dist/components/PieChart.js +20 -0
  130. package/dist/components/PieChart.mjs +5 -0
  131. package/dist/components/Popconfirm.d.mts +12 -2
  132. package/dist/components/Popconfirm.d.ts +12 -2
  133. package/dist/components/Popconfirm.js +3 -2
  134. package/dist/components/Popconfirm.mjs +2 -1
  135. package/dist/components/Popover.d.mts +12 -2
  136. package/dist/components/Popover.d.ts +12 -2
  137. package/dist/components/Popover.js +3 -2
  138. package/dist/components/Popover.mjs +2 -1
  139. package/dist/components/RadarChart.d.mts +20 -0
  140. package/dist/components/RadarChart.d.ts +20 -0
  141. package/dist/components/RadarChart.js +20 -0
  142. package/dist/components/RadarChart.mjs +5 -0
  143. package/dist/components/ScatterChart.d.mts +32 -0
  144. package/dist/components/ScatterChart.d.ts +32 -0
  145. package/dist/components/ScatterChart.js +23 -0
  146. package/dist/components/ScatterChart.mjs +8 -0
  147. package/dist/components/Select.js +2 -2
  148. package/dist/components/Select.mjs +1 -1
  149. package/dist/components/Slider.js +2 -2
  150. package/dist/components/Slider.mjs +1 -1
  151. package/dist/components/Space.js +2 -2
  152. package/dist/components/Space.mjs +1 -1
  153. package/dist/components/Steps.js +3 -3
  154. package/dist/components/Steps.mjs +1 -1
  155. package/dist/components/StepsItem.js +2 -2
  156. package/dist/components/StepsItem.mjs +1 -1
  157. package/dist/components/Table.js +2 -2
  158. package/dist/components/Table.mjs +1 -1
  159. package/dist/components/Tooltip.d.mts +12 -2
  160. package/dist/components/Tooltip.d.ts +12 -2
  161. package/dist/components/Tooltip.js +3 -2
  162. package/dist/components/Tooltip.mjs +2 -1
  163. package/dist/index.d.mts +97 -1
  164. package/dist/index.d.ts +97 -1
  165. package/dist/index.js +178 -108
  166. package/dist/index.mjs +41 -27
  167. package/package.json +2 -2
  168. package/dist/chunk-NEULKOYJ.js +0 -48
  169. package/dist/chunk-ZO4XVOHU.mjs +0 -45
@@ -0,0 +1,282 @@
1
+ import { useChartInteraction } from './chunk-3CDAG4HD.mjs';
2
+ import { ChartAxis } from './chunk-RQSQXQN6.mjs';
3
+ import { ChartCanvas } from './chunk-IS467WAO.mjs';
4
+ import { ChartGrid } from './chunk-677VSTPW.mjs';
5
+ import { ChartLegend } from './chunk-Z6F67MJE.mjs';
6
+ import { ChartSeries } from './chunk-SDLMB34Y.mjs';
7
+ import { ChartTooltip } from './chunk-LVC43YX2.mjs';
8
+ import { useMemo, useCallback } from 'react';
9
+ import { getChartInnerRect, createBandScale, getNumberExtent, createLinearScale, DEFAULT_CHART_COLORS, getChartElementOpacity, classNames } from '@expcat/tigercat-core';
10
+ import { jsxs, jsx } from 'react/jsx-runtime';
11
+
12
+ var BarChart = ({
13
+ width = 320,
14
+ height = 200,
15
+ padding = 24,
16
+ data,
17
+ xScale,
18
+ yScale,
19
+ barColor = "var(--tiger-primary,#2563eb)",
20
+ barRadius = 4,
21
+ barPaddingInner = 0.2,
22
+ barPaddingOuter = 0.1,
23
+ showGrid = true,
24
+ showAxis = true,
25
+ showXAxis = true,
26
+ showYAxis = true,
27
+ xAxisLabel,
28
+ yAxisLabel,
29
+ xTicks = 5,
30
+ yTicks = 5,
31
+ xTickValues,
32
+ yTickValues,
33
+ xTickFormat,
34
+ yTickFormat,
35
+ gridLineStyle = "solid",
36
+ gridStrokeWidth = 1,
37
+ colors,
38
+ hoverable = false,
39
+ hoveredIndex: hoveredIndexProp,
40
+ activeOpacity = 1,
41
+ inactiveOpacity = 0.25,
42
+ selectable = false,
43
+ selectedIndex: selectedIndexProp,
44
+ showLegend = false,
45
+ legendPosition = "bottom",
46
+ legendMarkerSize = 10,
47
+ legendGap = 8,
48
+ showTooltip = true,
49
+ tooltipFormatter,
50
+ legendFormatter,
51
+ title,
52
+ desc,
53
+ className,
54
+ onHoveredIndexChange,
55
+ onSelectedIndexChange,
56
+ onBarClick,
57
+ onBarHover
58
+ }) => {
59
+ const {
60
+ tooltipPosition,
61
+ resolvedHoveredIndex,
62
+ activeIndex,
63
+ handleMouseEnter,
64
+ handleMouseMove,
65
+ handleMouseLeave,
66
+ handleClick,
67
+ handleKeyDown,
68
+ handleLegendClick,
69
+ handleLegendHover,
70
+ handleLegendLeave,
71
+ wrapperClasses
72
+ } = useChartInteraction({
73
+ hoverable,
74
+ hoveredIndexProp,
75
+ selectable,
76
+ selectedIndexProp,
77
+ activeOpacity,
78
+ inactiveOpacity,
79
+ legendPosition,
80
+ getData: (index) => data[index],
81
+ onHoveredIndexChange: (index) => {
82
+ onHoveredIndexChange?.(index);
83
+ onBarHover?.(index, index !== null ? data[index] : null);
84
+ },
85
+ onSelectedIndexChange,
86
+ callbacks: {
87
+ onClick: onBarClick
88
+ }
89
+ });
90
+ const innerRect = useMemo(
91
+ () => getChartInnerRect(width, height, padding),
92
+ [width, height, padding]
93
+ );
94
+ const xDomain = useMemo(() => data.map((item) => String(item.x)), [data]);
95
+ const yValues = useMemo(() => data.map((item) => item.y), [data]);
96
+ const resolvedXScale = useMemo(() => {
97
+ if (xScale) return xScale;
98
+ return createBandScale(xDomain, [0, innerRect.width], {
99
+ paddingInner: barPaddingInner,
100
+ paddingOuter: barPaddingOuter
101
+ });
102
+ }, [xScale, xDomain, innerRect.width, barPaddingInner, barPaddingOuter]);
103
+ const resolvedYScale = useMemo(() => {
104
+ if (yScale) return yScale;
105
+ const extent = getNumberExtent(yValues, { includeZero: true });
106
+ return createLinearScale(extent, [innerRect.height, 0]);
107
+ }, [yScale, yValues, innerRect.height]);
108
+ const palette = useMemo(
109
+ () => colors && colors.length > 0 ? colors : barColor ? [barColor] : [...DEFAULT_CHART_COLORS],
110
+ [colors, barColor]
111
+ );
112
+ const bars = useMemo(() => {
113
+ const scale = resolvedXScale;
114
+ const bandWidth = scale.bandwidth ?? (scale.step ? scale.step * 0.7 : innerRect.width / Math.max(1, data.length) * 0.8);
115
+ const baseline = resolvedYScale.map(0);
116
+ return data.map((item, index) => {
117
+ const xKey = scale.type === "linear" ? Number(item.x) : String(item.x);
118
+ const xPos = scale.map(xKey);
119
+ const barX = scale.bandwidth ? xPos : xPos - bandWidth / 2;
120
+ const barYValue = resolvedYScale.map(item.y);
121
+ const barHeight = Math.abs(baseline - barYValue);
122
+ const barY = Math.min(baseline, barYValue);
123
+ const color = item.color ?? palette[index % palette.length];
124
+ const opacity = getChartElementOpacity(index, activeIndex, {
125
+ activeOpacity,
126
+ inactiveOpacity
127
+ });
128
+ return {
129
+ x: barX,
130
+ y: barY,
131
+ width: bandWidth,
132
+ height: barHeight,
133
+ color,
134
+ opacity,
135
+ datum: item,
136
+ index
137
+ };
138
+ });
139
+ }, [
140
+ resolvedXScale,
141
+ resolvedYScale,
142
+ data,
143
+ innerRect.width,
144
+ palette,
145
+ activeIndex,
146
+ activeOpacity,
147
+ inactiveOpacity
148
+ ]);
149
+ const legendItems = useMemo(
150
+ () => data.map((item, index) => ({
151
+ index,
152
+ label: legendFormatter ? legendFormatter(item, index) : item.label ?? String(item.x),
153
+ color: item.color ?? palette[index % palette.length],
154
+ active: activeIndex === null || activeIndex === index
155
+ })),
156
+ [data, legendFormatter, palette, activeIndex]
157
+ );
158
+ const formatTooltip = useCallback(
159
+ (datum, index) => {
160
+ if (tooltipFormatter) return tooltipFormatter(datum, index);
161
+ const label = datum.label ?? String(datum.x);
162
+ return `${label}: ${datum.y}`;
163
+ },
164
+ [tooltipFormatter]
165
+ );
166
+ const tooltipContent = useMemo(() => {
167
+ if (resolvedHoveredIndex === null) return "";
168
+ const datum = data[resolvedHoveredIndex];
169
+ return datum ? formatTooltip(datum, resolvedHoveredIndex) : "";
170
+ }, [resolvedHoveredIndex, data, formatTooltip]);
171
+ const shouldShowXAxis = showAxis && showXAxis;
172
+ const shouldShowYAxis = showAxis && showYAxis;
173
+ const chart = /* @__PURE__ */ jsxs(
174
+ ChartCanvas,
175
+ {
176
+ width,
177
+ height,
178
+ padding,
179
+ title,
180
+ desc,
181
+ className: classNames(className),
182
+ children: [
183
+ showGrid && /* @__PURE__ */ jsx(
184
+ ChartGrid,
185
+ {
186
+ xScale: resolvedXScale,
187
+ yScale: resolvedYScale,
188
+ show: "both",
189
+ xTicks,
190
+ yTicks,
191
+ xTickValues,
192
+ yTickValues,
193
+ lineStyle: gridLineStyle,
194
+ strokeWidth: gridStrokeWidth
195
+ }
196
+ ),
197
+ shouldShowXAxis && /* @__PURE__ */ jsx(
198
+ ChartAxis,
199
+ {
200
+ scale: resolvedXScale,
201
+ orientation: "bottom",
202
+ y: innerRect.height,
203
+ ticks: xTicks,
204
+ tickValues: xTickValues,
205
+ tickFormat: xTickFormat,
206
+ label: xAxisLabel
207
+ }
208
+ ),
209
+ shouldShowYAxis && /* @__PURE__ */ jsx(
210
+ ChartAxis,
211
+ {
212
+ scale: resolvedYScale,
213
+ orientation: "left",
214
+ ticks: yTicks,
215
+ tickValues: yTickValues,
216
+ tickFormat: yTickFormat,
217
+ label: yAxisLabel
218
+ }
219
+ ),
220
+ /* @__PURE__ */ jsx(ChartSeries, { data, type: "bar", children: bars.map((bar) => /* @__PURE__ */ jsx(
221
+ "rect",
222
+ {
223
+ x: bar.x,
224
+ y: bar.y,
225
+ width: bar.width,
226
+ height: bar.height,
227
+ rx: barRadius,
228
+ ry: barRadius,
229
+ fill: bar.color,
230
+ opacity: bar.opacity,
231
+ className: classNames(
232
+ "transition-opacity duration-150",
233
+ (hoverable || selectable) && "cursor-pointer"
234
+ ),
235
+ tabIndex: selectable ? 0 : void 0,
236
+ onMouseEnter: (e) => handleMouseEnter(bar.index, e),
237
+ onMouseMove: handleMouseMove,
238
+ onMouseLeave: handleMouseLeave,
239
+ onClick: () => handleClick(bar.index),
240
+ onKeyDown: (e) => handleKeyDown(e, bar.index)
241
+ },
242
+ `bar-${bar.index}`
243
+ )) })
244
+ ]
245
+ }
246
+ );
247
+ const tooltip = showTooltip && /* @__PURE__ */ jsx(
248
+ ChartTooltip,
249
+ {
250
+ content: tooltipContent,
251
+ visible: hoverable && resolvedHoveredIndex !== null && tooltipContent !== "",
252
+ x: tooltipPosition.x,
253
+ y: tooltipPosition.y
254
+ }
255
+ );
256
+ if (!showLegend) {
257
+ return /* @__PURE__ */ jsxs("div", { className: "inline-block relative", children: [
258
+ chart,
259
+ tooltip
260
+ ] });
261
+ }
262
+ return /* @__PURE__ */ jsxs("div", { className: wrapperClasses, children: [
263
+ chart,
264
+ /* @__PURE__ */ jsx(
265
+ ChartLegend,
266
+ {
267
+ items: legendItems,
268
+ position: legendPosition,
269
+ markerSize: legendMarkerSize,
270
+ gap: legendGap,
271
+ interactive: hoverable || selectable,
272
+ onItemClick: handleLegendClick,
273
+ onItemHover: handleLegendHover,
274
+ onItemLeave: handleLegendLeave
275
+ }
276
+ ),
277
+ tooltip
278
+ ] });
279
+ };
280
+ var BarChart_default = BarChart;
281
+
282
+ export { BarChart, BarChart_default };
@@ -1,8 +1,8 @@
1
- import { useState, useRef, useCallback, useEffect } from 'react';
2
- import { classNames, getPopoverContainerClasses, getPopoverTriggerClasses, getDropdownMenuWrapperClasses, getPopoverContentClasses, getPopoverTitleClasses, getPopoverContentTextClasses } from '@expcat/tigercat-core';
1
+ import { useFloating, useClickOutside, useEscapeKey } from './chunk-WLIFEALE.mjs';
2
+ import { useState, useRef, useCallback } from 'react';
3
+ import { classNames, getPopoverContainerClasses, getPopoverTriggerClasses, getPopoverContentClasses, getPopoverTitleClasses, getPopoverContentTextClasses, getTransformOrigin } from '@expcat/tigercat-core';
3
4
  import { jsxs, jsx } from 'react/jsx-runtime';
4
5
 
5
- // src/components/Popover.tsx
6
6
  var popoverIdCounter = 0;
7
7
  var createPopoverId = () => `tiger-popover-${++popoverIdCounter}`;
8
8
  var Popover = ({
@@ -14,6 +14,7 @@ var Popover = ({
14
14
  placement = "top",
15
15
  disabled = false,
16
16
  width,
17
+ offset = 8,
17
18
  className,
18
19
  style,
19
20
  children,
@@ -26,6 +27,8 @@ var Popover = ({
26
27
  const [internalVisible, setInternalVisible] = useState(defaultVisible);
27
28
  const currentVisible = isControlled ? visible : internalVisible;
28
29
  const containerRef = useRef(null);
30
+ const triggerRef = useRef(null);
31
+ const floatingRef = useRef(null);
29
32
  const popoverIdRef = useRef(null);
30
33
  if (!popoverIdRef.current) {
31
34
  popoverIdRef.current = createPopoverId();
@@ -33,6 +36,17 @@ var Popover = ({
33
36
  const popoverId = popoverIdRef.current;
34
37
  const titleId = `${popoverId}-title`;
35
38
  const contentId = `${popoverId}-content`;
39
+ const {
40
+ x,
41
+ y,
42
+ placement: actualPlacement
43
+ } = useFloating({
44
+ referenceRef: triggerRef,
45
+ floatingRef,
46
+ enabled: currentVisible,
47
+ placement,
48
+ offset
49
+ });
36
50
  const setVisible = useCallback(
37
51
  (nextVisible) => {
38
52
  if (disabled && nextVisible) return;
@@ -63,37 +77,28 @@ var Popover = ({
63
77
  if (disabled || trigger !== "focus") return;
64
78
  setVisible(false);
65
79
  };
66
- useEffect(() => {
67
- if (!currentVisible || trigger !== "click") return;
68
- const handleClickOutside = (event) => {
69
- const target = event.target;
70
- if (!target) return;
71
- if (containerRef.current?.contains(target)) return;
72
- setVisible(false);
73
- };
74
- const timeoutId = setTimeout(() => {
75
- document.addEventListener("click", handleClickOutside);
76
- }, 0);
77
- return () => {
78
- clearTimeout(timeoutId);
79
- document.removeEventListener("click", handleClickOutside);
80
- };
81
- }, [currentVisible, trigger, setVisible]);
82
- useEffect(() => {
83
- if (!currentVisible || trigger === "manual") return;
84
- const handleKeyDown = (event) => {
85
- if (event.key !== "Escape") return;
86
- setVisible(false);
87
- };
88
- document.addEventListener("keydown", handleKeyDown);
89
- return () => document.removeEventListener("keydown", handleKeyDown);
90
- }, [currentVisible, trigger, setVisible]);
80
+ useClickOutside({
81
+ enabled: currentVisible && trigger === "click",
82
+ refs: [containerRef],
83
+ onOutsideClick: () => setVisible(false),
84
+ defer: true
85
+ });
86
+ useEscapeKey({
87
+ enabled: currentVisible && trigger !== "manual",
88
+ onEscape: () => setVisible(false)
89
+ });
91
90
  const containerClasses = classNames(getPopoverContainerClasses(), className);
92
91
  const triggerClasses = getPopoverTriggerClasses(disabled);
93
- const contentWrapperClasses = getDropdownMenuWrapperClasses(currentVisible, placement);
94
92
  const contentClasses = getPopoverContentClasses(width);
95
93
  const titleClasses = getPopoverTitleClasses();
96
94
  const contentTextClasses = getPopoverContentTextClasses();
95
+ const floatingStyles = {
96
+ position: "absolute",
97
+ left: x,
98
+ top: y,
99
+ transformOrigin: getTransformOrigin(actualPlacement),
100
+ zIndex: 1e3
101
+ };
97
102
  const triggerHandlers = {};
98
103
  if (trigger === "click") {
99
104
  triggerHandlers.onClick = handleTriggerClick;
@@ -114,6 +119,7 @@ var Popover = ({
114
119
  /* @__PURE__ */ jsx(
115
120
  "div",
116
121
  {
122
+ ref: triggerRef,
117
123
  className: triggerClasses,
118
124
  "aria-haspopup": "dialog",
119
125
  "aria-disabled": disabled ? "true" : void 0,
@@ -121,7 +127,7 @@ var Popover = ({
121
127
  children
122
128
  }
123
129
  ),
124
- /* @__PURE__ */ jsx("div", { className: contentWrapperClasses, hidden: !currentVisible, "aria-hidden": !currentVisible, children: /* @__PURE__ */ jsxs(
130
+ currentVisible && /* @__PURE__ */ jsx("div", { ref: floatingRef, style: floatingStyles, "aria-hidden": false, children: /* @__PURE__ */ jsxs(
125
131
  "div",
126
132
  {
127
133
  id: popoverId,
@@ -94,16 +94,11 @@ var Slider = ({
94
94
  }
95
95
  }, [controlledValue]);
96
96
  const normalizeValue = react.useCallback(
97
- (val) => {
98
- const steps = Math.round((val - min) / step);
99
- return Math.min(Math.max(min + steps * step, min), max);
100
- },
97
+ (val) => tigercatCore.sliderNormalizeValue(val, min, max, step),
101
98
  [min, max, step]
102
99
  );
103
100
  const getPercentage = react.useCallback(
104
- (val) => {
105
- return (val - min) / (max - min) * 100;
106
- },
101
+ (val) => tigercatCore.sliderGetPercentage(val, min, max),
107
102
  [min, max]
108
103
  );
109
104
  const getValueFromPosition = react.useCallback(
@@ -187,22 +182,9 @@ var Slider = ({
187
182
  };
188
183
  const handleKeyDown = (e, value, thumbType) => {
189
184
  if (disabled) return;
190
- let newValue = value;
191
- if (e.key === "ArrowRight" || e.key === "ArrowUp") {
192
- e.preventDefault();
193
- newValue = normalizeValue(value + step);
194
- } else if (e.key === "ArrowLeft" || e.key === "ArrowDown") {
195
- e.preventDefault();
196
- newValue = normalizeValue(value - step);
197
- } else if (e.key === "Home") {
198
- e.preventDefault();
199
- newValue = min;
200
- } else if (e.key === "End") {
201
- e.preventDefault();
202
- newValue = max;
203
- } else {
204
- return;
205
- }
185
+ const newValue = tigercatCore.sliderGetKeyboardValue(e.key, value, min, max, step);
186
+ if (newValue === null) return;
187
+ e.preventDefault();
206
188
  if (range && Array.isArray(internalValue)) {
207
189
  const [minVal, maxVal] = internalValue;
208
190
  if (thumbType === "min") {
@@ -0,0 +1,153 @@
1
+ 'use strict';
2
+
3
+ var react = require('react');
4
+ var tigercatCore = require('@expcat/tigercat-core');
5
+
6
+ // src/hooks/useChartInteraction.ts
7
+ function useChartInteraction(options) {
8
+ const {
9
+ hoverable,
10
+ hoveredIndexProp,
11
+ selectable,
12
+ selectedIndexProp,
13
+ activeOpacity,
14
+ inactiveOpacity,
15
+ legendPosition = "bottom",
16
+ onHoveredIndexChange,
17
+ onSelectedIndexChange,
18
+ getData,
19
+ callbacks
20
+ } = options;
21
+ const [localHoveredIndex, setLocalHoveredIndex] = react.useState(null);
22
+ const [localSelectedIndex, setLocalSelectedIndex] = react.useState(null);
23
+ const [tooltipPosition, setTooltipPosition] = react.useState({ x: 0, y: 0 });
24
+ const resolvedHoveredIndex = hoveredIndexProp !== void 0 ? hoveredIndexProp : localHoveredIndex;
25
+ const resolvedSelectedIndex = selectedIndexProp !== void 0 ? selectedIndexProp : localSelectedIndex;
26
+ const activeIndex = react.useMemo(() => {
27
+ if (resolvedSelectedIndex !== null) return resolvedSelectedIndex;
28
+ if (hoverable && resolvedHoveredIndex !== null) return resolvedHoveredIndex;
29
+ return null;
30
+ }, [resolvedSelectedIndex, hoverable, resolvedHoveredIndex]);
31
+ const getElementOpacity = react.useCallback(
32
+ (index) => {
33
+ return tigercatCore.getChartElementOpacity(index, activeIndex, {
34
+ activeOpacity,
35
+ inactiveOpacity
36
+ });
37
+ },
38
+ [activeIndex, activeOpacity, inactiveOpacity]
39
+ );
40
+ const handleMouseEnter = react.useCallback(
41
+ (index, event) => {
42
+ if (!hoverable) return;
43
+ if (hoveredIndexProp === void 0) {
44
+ setLocalHoveredIndex(index);
45
+ }
46
+ setTooltipPosition({ x: event.clientX, y: event.clientY });
47
+ onHoveredIndexChange?.(index);
48
+ if (callbacks?.onHover && getData) {
49
+ callbacks.onHover(index, getData(index) ?? null);
50
+ }
51
+ },
52
+ [hoverable, hoveredIndexProp, onHoveredIndexChange, callbacks, getData]
53
+ );
54
+ const handleMouseMove = react.useCallback((event) => {
55
+ setTooltipPosition({ x: event.clientX, y: event.clientY });
56
+ }, []);
57
+ const handleMouseLeave = react.useCallback(() => {
58
+ if (!hoverable) return;
59
+ if (hoveredIndexProp === void 0) {
60
+ setLocalHoveredIndex(null);
61
+ }
62
+ onHoveredIndexChange?.(null);
63
+ callbacks?.onHover?.(null, null);
64
+ }, [hoverable, hoveredIndexProp, onHoveredIndexChange, callbacks]);
65
+ const handleClick = react.useCallback(
66
+ (index) => {
67
+ if (!selectable) return;
68
+ const nextIndex = resolvedSelectedIndex === index ? null : index;
69
+ if (selectedIndexProp === void 0) {
70
+ setLocalSelectedIndex(nextIndex);
71
+ }
72
+ onSelectedIndexChange?.(nextIndex);
73
+ if (callbacks?.onClick && getData) {
74
+ const datum = getData(index);
75
+ if (datum) callbacks.onClick(index, datum);
76
+ }
77
+ },
78
+ [
79
+ selectable,
80
+ resolvedSelectedIndex,
81
+ selectedIndexProp,
82
+ onSelectedIndexChange,
83
+ callbacks,
84
+ getData
85
+ ]
86
+ );
87
+ const handleKeyDown = react.useCallback(
88
+ (event, index) => {
89
+ if (!selectable) return;
90
+ if (event.key !== "Enter" && event.key !== " ") return;
91
+ event.preventDefault();
92
+ handleClick(index);
93
+ },
94
+ [selectable, handleClick]
95
+ );
96
+ const handleLegendClick = react.useCallback(
97
+ (index) => {
98
+ handleClick(index);
99
+ },
100
+ [handleClick]
101
+ );
102
+ const handleLegendHover = react.useCallback(
103
+ (index) => {
104
+ if (!hoverable) return;
105
+ if (hoveredIndexProp === void 0) {
106
+ setLocalHoveredIndex(index);
107
+ }
108
+ onHoveredIndexChange?.(index);
109
+ },
110
+ [hoverable, hoveredIndexProp, onHoveredIndexChange]
111
+ );
112
+ const handleLegendLeave = react.useCallback(() => {
113
+ handleMouseLeave();
114
+ }, [handleMouseLeave]);
115
+ const wrapperClasses = react.useMemo(() => {
116
+ return tigercatCore.classNames(
117
+ "inline-flex",
118
+ legendPosition === "right" ? "flex-row items-start gap-4" : legendPosition === "left" ? "flex-row-reverse items-start gap-4" : legendPosition === "top" ? "flex-col-reverse gap-2" : "flex-col gap-2"
119
+ );
120
+ }, [legendPosition]);
121
+ const createLegendItems = react.useCallback(
122
+ (items, palette, labelFormatter) => {
123
+ return items.map((item, index) => ({
124
+ index,
125
+ label: labelFormatter ? labelFormatter(item, index) : item.label ?? String(item.x ?? index),
126
+ color: item.color ?? palette[index % palette.length],
127
+ active: activeIndex === null || activeIndex === index
128
+ }));
129
+ },
130
+ [activeIndex]
131
+ );
132
+ return {
133
+ localHoveredIndex,
134
+ localSelectedIndex,
135
+ tooltipPosition,
136
+ resolvedHoveredIndex,
137
+ resolvedSelectedIndex,
138
+ activeIndex,
139
+ getElementOpacity,
140
+ handleMouseEnter,
141
+ handleMouseMove,
142
+ handleMouseLeave,
143
+ handleClick,
144
+ handleKeyDown,
145
+ handleLegendClick,
146
+ handleLegendHover,
147
+ handleLegendLeave,
148
+ wrapperClasses,
149
+ createLegendItems
150
+ };
151
+ }
152
+
153
+ exports.useChartInteraction = useChartInteraction;
@@ -1,7 +1,7 @@
1
- import { useEscapeKey } from './chunk-ZO4XVOHU.mjs';
1
+ import { useEscapeKey } from './chunk-WLIFEALE.mjs';
2
2
  import React, { useEffect, useCallback, useRef, useId, useMemo } from 'react';
3
3
  import { createPortal } from 'react-dom';
4
- import { resolveLocaleText, captureActiveElement, focusFirst, restoreFocus, classNames, getDrawerContainerClasses, getDrawerMaskClasses, getDrawerPanelClasses, getDrawerHeaderClasses, getDrawerBodyClasses, getDrawerFooterClasses, getDrawerCloseButtonClasses, getDrawerTitleClasses, closeIconViewBox, closeIconPathD, closeIconPathStrokeWidth, closeIconPathStrokeLinejoin, closeIconPathStrokeLinecap } from '@expcat/tigercat-core';
4
+ import { ANIMATION_DURATION_MS, resolveLocaleText, captureActiveElement, focusFirst, restoreFocus, getFocusableElements, getFocusTrapNavigation, classNames, getDrawerContainerClasses, getDrawerMaskClasses, getDrawerPanelClasses, getDrawerHeaderClasses, getDrawerBodyClasses, getDrawerFooterClasses, getDrawerCloseButtonClasses, getDrawerTitleClasses, closeIconViewBox, closeIconPathD, closeIconPathStrokeWidth, closeIconPathStrokeLinejoin, closeIconPathStrokeLinecap } from '@expcat/tigercat-core';
5
5
  import { jsxs, jsx } from 'react/jsx-runtime';
6
6
 
7
7
  var CloseIcon = () => /* @__PURE__ */ jsx(
@@ -74,7 +74,7 @@ var Drawer = ({
74
74
  } else {
75
75
  onAfterLeave?.();
76
76
  }
77
- }, 300);
77
+ }, ANIMATION_DURATION_MS);
78
78
  return () => window.clearTimeout(timer);
79
79
  }, [visible, onAfterEnter, onAfterLeave]);
80
80
  const reactId = useId();
@@ -108,6 +108,16 @@ var Drawer = ({
108
108
  if (visible) return;
109
109
  restoreFocus(previousActiveElementRef.current);
110
110
  }, [visible]);
111
+ const handleKeyDown = useCallback((event) => {
112
+ if (event.key === "Tab" && dialogRef.current) {
113
+ const focusables = getFocusableElements(dialogRef.current);
114
+ const result = getFocusTrapNavigation(event.nativeEvent, focusables, document.activeElement);
115
+ if (result.shouldHandle && result.next) {
116
+ event.preventDefault();
117
+ result.next.focus();
118
+ }
119
+ }
120
+ }, []);
111
121
  const containerClasses = classNames(
112
122
  getDrawerContainerClasses(zIndex),
113
123
  !visible && "pointer-events-none"
@@ -155,6 +165,7 @@ var Drawer = ({
155
165
  "aria-labelledby": ariaLabelledby,
156
166
  tabIndex: -1,
157
167
  ref: dialogRef,
168
+ onKeyDown: handleKeyDown,
158
169
  "data-tiger-drawer": "",
159
170
  children: [
160
171
  (title || header || closable) && /* @__PURE__ */ jsxs("div", { className: headerClasses, children: [