@terreno/ui 57.8.0 → 57.10.1

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 (269) hide show
  1. package/README.md +2 -0
  2. package/dist/AreaChart.d.ts +1 -1
  3. package/dist/AreaChart.d.ts.map +1 -1
  4. package/dist/AreaChart.js +70 -22
  5. package/dist/AreaChart.js.map +1 -1
  6. package/dist/BarChart.d.ts.map +1 -1
  7. package/dist/BarChart.js +55 -13
  8. package/dist/BarChart.js.map +1 -1
  9. package/dist/Button.d.ts.map +1 -1
  10. package/dist/Button.js +19 -4
  11. package/dist/Button.js.map +1 -1
  12. package/dist/ChartCard.d.ts +5 -0
  13. package/dist/ChartCard.d.ts.map +1 -0
  14. package/dist/ChartCard.js +18 -0
  15. package/dist/ChartCard.js.map +1 -0
  16. package/dist/Common.d.ts +147 -6
  17. package/dist/Common.d.ts.map +1 -1
  18. package/dist/Common.js.map +1 -1
  19. package/dist/DashboardGrid.d.ts +6 -2
  20. package/dist/DashboardGrid.d.ts.map +1 -1
  21. package/dist/DashboardGrid.js +43 -10
  22. package/dist/DashboardGrid.js.map +1 -1
  23. package/dist/DateTimeField.d.ts.map +1 -1
  24. package/dist/DateTimeField.js +90 -17
  25. package/dist/DateTimeField.js.map +1 -1
  26. package/dist/DonutChart.d.ts.map +1 -1
  27. package/dist/DonutChart.js +20 -10
  28. package/dist/DonutChart.js.map +1 -1
  29. package/dist/DropdownMenuItem.d.ts +16 -0
  30. package/dist/DropdownMenuItem.d.ts.map +1 -0
  31. package/dist/DropdownMenuItem.js +11 -0
  32. package/dist/DropdownMenuItem.js.map +1 -0
  33. package/dist/FilePickerButton.d.ts +15 -1
  34. package/dist/FilePickerButton.d.ts.map +1 -1
  35. package/dist/FilePickerButton.js +90 -13
  36. package/dist/FilePickerButton.js.map +1 -1
  37. package/dist/GPTChat.d.ts +57 -1
  38. package/dist/GPTChat.d.ts.map +1 -1
  39. package/dist/GPTChat.js +301 -20
  40. package/dist/GPTChat.js.map +1 -1
  41. package/dist/HtmlFrame.d.ts +11 -0
  42. package/dist/HtmlFrame.d.ts.map +1 -0
  43. package/dist/HtmlFrame.js +29 -0
  44. package/dist/HtmlFrame.js.map +1 -0
  45. package/dist/LineChart.d.ts +1 -1
  46. package/dist/LineChart.d.ts.map +1 -1
  47. package/dist/LineChart.js +62 -21
  48. package/dist/LineChart.js.map +1 -1
  49. package/dist/Scorecard.d.ts +5 -0
  50. package/dist/Scorecard.d.ts.map +1 -0
  51. package/dist/Scorecard.js +11 -0
  52. package/dist/Scorecard.js.map +1 -0
  53. package/dist/SparklineChart.d.ts +5 -0
  54. package/dist/SparklineChart.d.ts.map +1 -0
  55. package/dist/SparklineChart.js +35 -0
  56. package/dist/SparklineChart.js.map +1 -0
  57. package/dist/Text.d.ts +1 -1
  58. package/dist/Text.d.ts.map +1 -1
  59. package/dist/Text.js +2 -2
  60. package/dist/Text.js.map +1 -1
  61. package/dist/TextField.d.ts.map +1 -1
  62. package/dist/TextField.js +12 -4
  63. package/dist/TextField.js.map +1 -1
  64. package/dist/ToastNotifications.d.ts.map +1 -1
  65. package/dist/ToastNotifications.js +29 -6
  66. package/dist/ToastNotifications.js.map +1 -1
  67. package/dist/WebDropdownMenu.d.ts +2 -1
  68. package/dist/WebDropdownMenu.d.ts.map +1 -1
  69. package/dist/WebDropdownMenu.js +2 -6
  70. package/dist/WebDropdownMenu.js.map +1 -1
  71. package/dist/asks/AskCard.d.ts +34 -0
  72. package/dist/asks/AskCard.d.ts.map +1 -0
  73. package/dist/asks/AskCard.js +91 -0
  74. package/dist/asks/AskCard.js.map +1 -0
  75. package/dist/asks/AskChoice.d.ts +11 -0
  76. package/dist/asks/AskChoice.d.ts.map +1 -0
  77. package/dist/asks/AskChoice.js +146 -0
  78. package/dist/asks/AskChoice.js.map +1 -0
  79. package/dist/asks/AskConfirm.d.ts +15 -0
  80. package/dist/asks/AskConfirm.d.ts.map +1 -0
  81. package/dist/asks/AskConfirm.js +17 -0
  82. package/dist/asks/AskConfirm.js.map +1 -0
  83. package/dist/asks/AskFiles.d.ts +18 -0
  84. package/dist/asks/AskFiles.d.ts.map +1 -0
  85. package/dist/asks/AskFiles.js +149 -0
  86. package/dist/asks/AskFiles.js.map +1 -0
  87. package/dist/asks/AskForm.d.ts +27 -0
  88. package/dist/asks/AskForm.d.ts.map +1 -0
  89. package/dist/asks/AskForm.js +146 -0
  90. package/dist/asks/AskForm.js.map +1 -0
  91. package/dist/asks/AskMarkdown.d.ts +25 -0
  92. package/dist/asks/AskMarkdown.d.ts.map +1 -0
  93. package/dist/asks/AskMarkdown.js +73 -0
  94. package/dist/asks/AskMarkdown.js.map +1 -0
  95. package/dist/asks/SimpleAskCard.d.ts +23 -0
  96. package/dist/asks/SimpleAskCard.d.ts.map +1 -0
  97. package/dist/asks/SimpleAskCard.js +32 -0
  98. package/dist/asks/SimpleAskCard.js.map +1 -0
  99. package/dist/asks/askControls.d.ts +33 -0
  100. package/dist/asks/askControls.d.ts.map +1 -0
  101. package/dist/asks/askControls.js +30 -0
  102. package/dist/asks/askControls.js.map +1 -0
  103. package/dist/asks/askFileRefs.d.ts +26 -0
  104. package/dist/asks/askFileRefs.d.ts.map +1 -0
  105. package/dist/asks/askFileRefs.js +75 -0
  106. package/dist/asks/askFileRefs.js.map +1 -0
  107. package/dist/asks/askFormDraft.d.ts +60 -0
  108. package/dist/asks/askFormDraft.d.ts.map +1 -0
  109. package/dist/asks/askFormDraft.js +224 -0
  110. package/dist/asks/askFormDraft.js.map +1 -0
  111. package/dist/asks/askSummary.d.ts +10 -0
  112. package/dist/asks/askSummary.d.ts.map +1 -0
  113. package/dist/asks/askSummary.js +138 -0
  114. package/dist/asks/askSummary.js.map +1 -0
  115. package/dist/asks/askTypes.d.ts +21 -0
  116. package/dist/asks/askTypes.d.ts.map +1 -0
  117. package/dist/asks/askTypes.js +2 -0
  118. package/dist/asks/askTypes.js.map +1 -0
  119. package/dist/asks/simpleCardButtonVariants.d.ts +5 -0
  120. package/dist/asks/simpleCardButtonVariants.d.ts.map +1 -0
  121. package/dist/asks/simpleCardButtonVariants.js +8 -0
  122. package/dist/asks/simpleCardButtonVariants.js.map +1 -0
  123. package/dist/blocks/BlocksError.d.ts +8 -0
  124. package/dist/blocks/BlocksError.d.ts.map +1 -0
  125. package/dist/blocks/BlocksError.js +14 -0
  126. package/dist/blocks/BlocksError.js.map +1 -0
  127. package/dist/blocks/BlocksView.d.ts +10 -0
  128. package/dist/blocks/BlocksView.d.ts.map +1 -0
  129. package/dist/blocks/BlocksView.js +90 -0
  130. package/dist/blocks/BlocksView.js.map +1 -0
  131. package/dist/blocks/blockRenderers.d.ts +25 -0
  132. package/dist/blocks/blockRenderers.d.ts.map +1 -0
  133. package/dist/blocks/blockRenderers.js +136 -0
  134. package/dist/blocks/blockRenderers.js.map +1 -0
  135. package/dist/blocks/datasetToPoints.d.ts +22 -0
  136. package/dist/blocks/datasetToPoints.d.ts.map +1 -0
  137. package/dist/blocks/datasetToPoints.js +28 -0
  138. package/dist/blocks/datasetToPoints.js.map +1 -0
  139. package/dist/blocks/useBlockSelections.d.ts +6 -0
  140. package/dist/blocks/useBlockSelections.d.ts.map +1 -0
  141. package/dist/blocks/useBlockSelections.js +10 -0
  142. package/dist/blocks/useBlockSelections.js.map +1 -0
  143. package/dist/blocks/useResolvedDatasets.d.ts +18 -0
  144. package/dist/blocks/useResolvedDatasets.d.ts.map +1 -0
  145. package/dist/blocks/useResolvedDatasets.js +59 -0
  146. package/dist/blocks/useResolvedDatasets.js.map +1 -0
  147. package/dist/blocks/useResolvedImages.d.ts +15 -0
  148. package/dist/blocks/useResolvedImages.d.ts.map +1 -0
  149. package/dist/blocks/useResolvedImages.js +66 -0
  150. package/dist/blocks/useResolvedImages.js.map +1 -0
  151. package/dist/charts/ChartFacadeContainer.d.ts +10 -0
  152. package/dist/charts/ChartFacadeContainer.d.ts.map +1 -0
  153. package/dist/charts/ChartFacadeContainer.js +10 -0
  154. package/dist/charts/ChartFacadeContainer.js.map +1 -0
  155. package/dist/charts/ChartFrame.d.ts +4 -0
  156. package/dist/charts/ChartFrame.d.ts.map +1 -1
  157. package/dist/charts/ChartFrame.js +4 -2
  158. package/dist/charts/ChartFrame.js.map +1 -1
  159. package/dist/charts/layout.d.ts +9 -2
  160. package/dist/charts/layout.d.ts.map +1 -1
  161. package/dist/charts/layout.js +28 -6
  162. package/dist/charts/layout.js.map +1 -1
  163. package/dist/charts/scales.d.ts +3 -1
  164. package/dist/charts/scales.d.ts.map +1 -1
  165. package/dist/charts/scales.js +7 -7
  166. package/dist/charts/scales.js.map +1 -1
  167. package/dist/charts/series.d.ts +15 -0
  168. package/dist/charts/series.d.ts.map +1 -0
  169. package/dist/charts/series.js +19 -0
  170. package/dist/charts/series.js.map +1 -0
  171. package/dist/charts/types/chartTypes.d.ts +7 -0
  172. package/dist/charts/types/chartTypes.d.ts.map +1 -1
  173. package/dist/dashboardGridLayout.d.ts +6 -0
  174. package/dist/dashboardGridLayout.d.ts.map +1 -1
  175. package/dist/dashboardGridLayout.js +19 -3
  176. package/dist/dashboardGridLayout.js.map +1 -1
  177. package/dist/index.d.ts +9 -1
  178. package/dist/index.d.ts.map +1 -1
  179. package/dist/index.js +4 -1
  180. package/dist/index.js.map +1 -1
  181. package/dist/lazyBoundaries/heavyOptionalExports.d.ts +15 -0
  182. package/dist/lazyBoundaries/heavyOptionalExports.d.ts.map +1 -1
  183. package/dist/lazyBoundaries/heavyOptionalExports.js +10 -0
  184. package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
  185. package/dist/resolveDocumentBodyPortalTarget.d.ts +7 -0
  186. package/dist/resolveDocumentBodyPortalTarget.d.ts.map +1 -0
  187. package/dist/resolveDocumentBodyPortalTarget.js +12 -0
  188. package/dist/resolveDocumentBodyPortalTarget.js.map +1 -0
  189. package/package.json +2 -1
  190. package/src/AIRequestExplorer.test.tsx +2 -2
  191. package/src/AreaChart.test.tsx +81 -0
  192. package/src/AreaChart.tsx +171 -62
  193. package/src/BarChart.test.tsx +119 -0
  194. package/src/BarChart.tsx +94 -20
  195. package/src/Button.test.tsx +72 -0
  196. package/src/Button.tsx +34 -4
  197. package/src/ChartCard.test.tsx +79 -0
  198. package/src/ChartCard.tsx +80 -0
  199. package/src/Common.ts +136 -2
  200. package/src/DashboardGrid.test.tsx +98 -1
  201. package/src/DashboardGrid.tsx +71 -20
  202. package/src/DateTimeField.test.tsx +185 -2
  203. package/src/DateTimeField.tsx +106 -16
  204. package/src/DonutChart.test.tsx +78 -10
  205. package/src/DonutChart.tsx +87 -14
  206. package/src/DropdownMenuItem.tsx +48 -0
  207. package/src/FilePickerButton.test.tsx +116 -9
  208. package/src/FilePickerButton.tsx +177 -23
  209. package/src/GPTChat.test.tsx +891 -8
  210. package/src/GPTChat.tsx +713 -45
  211. package/src/HtmlFrame.tsx +60 -0
  212. package/src/LineChart.test.tsx +109 -10
  213. package/src/LineChart.tsx +154 -58
  214. package/src/Scorecard.test.tsx +65 -0
  215. package/src/Scorecard.tsx +45 -0
  216. package/src/SparklineChart.test.tsx +69 -0
  217. package/src/SparklineChart.tsx +85 -0
  218. package/src/Text.test.tsx +22 -0
  219. package/src/Text.tsx +10 -1
  220. package/src/TextField.test.tsx +16 -0
  221. package/src/TextField.tsx +13 -3
  222. package/src/ToastNotifications.tsx +33 -6
  223. package/src/ToastNotifications.webModal.test.tsx +285 -0
  224. package/src/WebDropdownMenu.tsx +3 -7
  225. package/src/asks/AskCard.test.tsx +1428 -0
  226. package/src/asks/AskCard.tsx +240 -0
  227. package/src/asks/AskChoice.tsx +368 -0
  228. package/src/asks/AskConfirm.tsx +42 -0
  229. package/src/asks/AskFiles.test.tsx +347 -0
  230. package/src/asks/AskFiles.tsx +246 -0
  231. package/src/asks/AskForm.tsx +334 -0
  232. package/src/asks/AskMarkdown.tsx +176 -0
  233. package/src/asks/SimpleAskCard.test.tsx +253 -0
  234. package/src/asks/SimpleAskCard.tsx +82 -0
  235. package/src/asks/askControls.tsx +98 -0
  236. package/src/asks/askFileRefs.test.ts +155 -0
  237. package/src/asks/askFileRefs.ts +98 -0
  238. package/src/asks/askFormDraft.test.ts +347 -0
  239. package/src/asks/askFormDraft.ts +309 -0
  240. package/src/asks/askSummary.test.ts +255 -0
  241. package/src/asks/askSummary.ts +160 -0
  242. package/src/asks/askTypes.ts +25 -0
  243. package/src/asks/asksUseTerrenoComponents.test.ts +55 -0
  244. package/src/asks/simpleCardButtonVariants.ts +14 -0
  245. package/src/blocks/BlocksError.tsx +28 -0
  246. package/src/blocks/BlocksView.test.tsx +607 -0
  247. package/src/blocks/BlocksView.tsx +125 -0
  248. package/src/blocks/blockRenderers.tsx +288 -0
  249. package/src/blocks/datasetToPoints.test.ts +31 -0
  250. package/src/blocks/datasetToPoints.ts +48 -0
  251. package/src/blocks/useBlockSelections.ts +13 -0
  252. package/src/blocks/useResolvedDatasets.ts +78 -0
  253. package/src/blocks/useResolvedImages.ts +81 -0
  254. package/src/bunSetup.ts +1 -0
  255. package/src/charts/ChartFacadeContainer.tsx +35 -0
  256. package/src/charts/ChartFrame.tsx +39 -1
  257. package/src/charts/layout.test.ts +22 -1
  258. package/src/charts/layout.ts +37 -4
  259. package/src/charts/scales.test.ts +33 -0
  260. package/src/charts/scales.ts +10 -6
  261. package/src/charts/series.ts +43 -0
  262. package/src/charts/types/chartTypes.ts +8 -0
  263. package/src/dashboardGridLayout.test.ts +59 -1
  264. package/src/dashboardGridLayout.ts +30 -3
  265. package/src/index.tsx +13 -0
  266. package/src/isolated/HtmlFrame.isolated.tsx +54 -0
  267. package/src/lazyBoundaries/heavyOptionalExports.test.tsx +2 -0
  268. package/src/lazyBoundaries/heavyOptionalExports.tsx +35 -0
  269. package/src/resolveDocumentBodyPortalTarget.ts +11 -0
@@ -1,5 +1,6 @@
1
1
  import {describe, expect, it} from "bun:test";
2
2
  import {act, fireEvent} from "@testing-library/react-native";
3
+ import {assert} from "chai";
3
4
 
4
5
  import {BarChart} from "./BarChart";
5
6
  import {renderWithTheme} from "./test-utils";
@@ -10,7 +11,125 @@ const POINTS = [
10
11
  {label: "C", value: 100},
11
12
  ];
12
13
 
14
+ const DATE_POINTS = Array.from({length: 14}, (_, index) => ({
15
+ label: `Sep ${index + 1}, 2026`,
16
+ value: index + 1,
17
+ }));
18
+
19
+ const WEEKDAY_POINTS = [
20
+ "Monday",
21
+ "Tuesday",
22
+ "Wednesday",
23
+ "Thursday",
24
+ "Friday",
25
+ "Saturday",
26
+ "Sunday",
27
+ ].map((label, index) => ({label, value: index + 1}));
28
+
13
29
  describe("BarChart", () => {
30
+ it("rotates dense time labels in auto mode and keeps seven categories horizontal", () => {
31
+ const dense = renderWithTheme(<BarChart data={DATE_POINTS} testID="dense-chart" />);
32
+ const denseStyle = dense.getByTestId("dense-chart.xtick.0").props.style;
33
+ const denseStyles = Array.isArray(denseStyle) ? denseStyle : [denseStyle];
34
+ assert.isTrue(denseStyles.some((style) => Array.isArray(style?.transform)));
35
+
36
+ const categorical = renderWithTheme(<BarChart data={WEEKDAY_POINTS} testID="weekday-chart" />);
37
+ const categoryStyle = categorical.getByTestId("weekday-chart.xtick.0").props.style;
38
+ const categoryStyles = Array.isArray(categoryStyle) ? categoryStyle : [categoryStyle];
39
+ assert.isFalse(categoryStyles.some((style) => Array.isArray(style?.transform)));
40
+ });
41
+
42
+ it("draws lighter comparison bars on the shared scale", () => {
43
+ const comparisonData = POINTS.map((point) => ({...point, value: point.value + 10}));
44
+ const {getByTestId} = renderWithTheme(
45
+ <BarChart comparisonData={comparisonData} data={POINTS} testID="chart" />
46
+ );
47
+
48
+ assert.exists(getByTestId("chart.comparison.1"));
49
+ assert.isBelow(getByTestId("chart.comparison.1").props.opacity, 1);
50
+ });
51
+
52
+ it("scales current and comparison bars against the same y domain", () => {
53
+ const currentOnly = renderWithTheme(
54
+ <BarChart data={[{label: "A", value: 10}]} testID="current-only" />
55
+ );
56
+ const compared = renderWithTheme(
57
+ <BarChart
58
+ comparisonData={[{label: "A", value: 100}]}
59
+ data={[{label: "A", value: 10}]}
60
+ testID="compared"
61
+ />
62
+ );
63
+
64
+ assert.isAbove(
65
+ currentOnly.getByTestId("current-only.current.0").props.height,
66
+ compared.getByTestId("compared.current.0").props.height
67
+ );
68
+ assert.isAbove(
69
+ compared.getByTestId("compared.comparison.0").props.height,
70
+ compared.getByTestId("compared.current.0").props.height
71
+ );
72
+ });
73
+
74
+ it("uses only the first named series for bars and legend", () => {
75
+ const firstSeries = [
76
+ {label: "A", value: 10},
77
+ {label: "B", value: 20},
78
+ ];
79
+ const {getByTestId, getByText, queryByTestId, queryByText} = renderWithTheme(
80
+ <BarChart
81
+ data={POINTS}
82
+ series={[
83
+ {data: firstSeries, id: "first", label: "Series A"},
84
+ {data: [{label: "C", value: 30}], id: "second", label: "Series B"},
85
+ ]}
86
+ testID="chart"
87
+ />
88
+ );
89
+
90
+ assert.exists(getByText("Series A"));
91
+ assert.notExists(queryByText("Series B"));
92
+ assert.exists(getByTestId("chart.point.1-clickable"));
93
+ assert.notExists(queryByTestId("chart.point.2-clickable"));
94
+ });
95
+
96
+ it("renders comparison-only data instead of the empty state", () => {
97
+ const {getByTestId, queryByText} = renderWithTheme(
98
+ <BarChart comparisonData={POINTS} data={[]} testID="chart" />
99
+ );
100
+
101
+ assert.exists(getByTestId("chart.comparison.1"));
102
+ assert.notExists(queryByText("No data"));
103
+ });
104
+
105
+ it("renders chart-card header shortcuts and invokes the period action", async (): Promise<void> => {
106
+ let pressCount = 0;
107
+ const handlePeriodPress = (): void => {
108
+ pressCount += 1;
109
+ };
110
+ const {getByTestId, getByText} = renderWithTheme(
111
+ <BarChart
112
+ data={POINTS}
113
+ onPeriodPress={handlePeriodPress}
114
+ periodLabel="Last 14 days"
115
+ testID="chart"
116
+ title="Cost / conv. over time"
117
+ />
118
+ );
119
+
120
+ assert.exists(getByText("Cost / conv. over time"));
121
+ assert.exists(getByText("Last 14 days"));
122
+ fireEvent.press(getByTestId("chart.card.period-clickable"));
123
+ await new Promise((resolve) => setTimeout(resolve, 0));
124
+ assert.equal(pressCount, 1);
125
+ });
126
+
127
+ it("does not add ChartCard chrome when title is omitted", () => {
128
+ const {queryByTestId} = renderWithTheme(<BarChart data={POINTS} testID="chart" />);
129
+
130
+ assert.notExists(queryByTestId("chart.card"));
131
+ });
132
+
14
133
  it("renders one mark testID per point", () => {
15
134
  const {getByTestId, queryByTestId} = renderWithTheme(<BarChart data={POINTS} testID="chart" />);
16
135
 
package/src/BarChart.tsx CHANGED
@@ -5,16 +5,20 @@ import {Rect, Svg, Line as SvgLine} from "react-native-svg";
5
5
  import {Box} from "./Box";
6
6
  import type {BarChartProps, LayoutChangeEvent} from "./Common";
7
7
  import {getBarLayout} from "./charts/bars";
8
+ import {ChartFacadeContainer} from "./charts/ChartFacadeContainer";
8
9
  import {ChartFrame} from "./charts/ChartFrame";
9
10
  import {
11
+ CHART_ROTATED_X_AXIS_HEIGHT,
10
12
  CHART_X_AXIS_HEIGHT,
11
13
  getChartAxisWidth,
12
14
  getChartPlot,
13
15
  getPlotHeight,
14
16
  getXTickStyle,
15
17
  getYTickStyle,
18
+ shouldRotateChartXTicks,
16
19
  } from "./charts/layout";
17
20
  import {createCartesianScales, getYTickValues} from "./charts/scales";
21
+ import {getAxisPoints} from "./charts/series";
18
22
  import {getChartPaint} from "./charts/theme";
19
23
  import type {ChartPoint} from "./charts/types/chartTypes";
20
24
  import {Text} from "./Text";
@@ -37,13 +41,19 @@ const formatChartTooltip = ({
37
41
 
38
42
  export const BarChart: FC<BarChartProps> = ({
39
43
  accessibilityLabel,
44
+ comparisonData = [],
40
45
  data,
41
46
  emptyText = "No data",
42
47
  formatValue = String,
43
48
  height = DEFAULT_HEIGHT,
44
49
  legendLabel,
45
50
  loading = false,
51
+ onPeriodPress,
52
+ periodLabel,
53
+ series,
46
54
  testID,
55
+ title,
56
+ xTickPolicy = "auto",
47
57
  }) => {
48
58
  const {theme} = useTheme();
49
59
  const paint = getChartPaint(theme);
@@ -61,27 +71,53 @@ export const BarChart: FC<BarChartProps> = ({
61
71
  setActivePointIndex(pointIndex);
62
72
  }, []);
63
73
 
74
+ const primarySeries = series && series.length > 0 ? series[0] : undefined;
75
+ const chartData = primarySeries?.data ?? data;
76
+ const seriesColor = primarySeries?.color ?? paint.series;
77
+ const effectiveLegendLabel = primarySeries?.label ?? legendLabel;
78
+ const axisPoints = getAxisPoints({
79
+ comparisonData,
80
+ series: [
81
+ {data: chartData, id: primarySeries?.id ?? "default", label: effectiveLegendLabel ?? ""},
82
+ ],
83
+ });
84
+ const allPoints = [...chartData, ...comparisonData];
85
+ const isXTickRotated = shouldRotateChartXTicks({
86
+ labelCount: axisPoints.length,
87
+ policy: xTickPolicy,
88
+ });
89
+ const xAxisHeight = isXTickRotated ? CHART_ROTATED_X_AXIS_HEIGHT : CHART_X_AXIS_HEIGHT;
64
90
  const axisWidth = getChartAxisWidth(chartWidth);
65
- const plotHeight = getPlotHeight({hasLegend: Boolean(legendLabel), height});
91
+ const plotHeight = getPlotHeight({
92
+ hasLegend: Boolean(effectiveLegendLabel),
93
+ height,
94
+ xAxisHeight,
95
+ });
66
96
  const plot = getChartPlot({chartWidth, height: plotHeight});
67
97
  const plotWidth = chartWidth - axisWidth;
68
- const scales = createCartesianScales({plot, points: data});
69
- const yTicks = getYTickValues(data);
98
+ const scales = createCartesianScales({
99
+ plot,
100
+ points: allPoints,
101
+ xLabels: axisPoints.map((point) => point.label),
102
+ });
103
+ const yTicks = getYTickValues(allPoints);
70
104
  const baselineY = scales.y(0);
71
105
  const barWidth = Math.max(scales.bandwidth * BAR_FILL, 1);
72
- const activePoint = activePointIndex === undefined ? undefined : data[activePointIndex];
106
+ const comparisonBarWidth = Math.max(scales.bandwidth * 0.9, 1);
107
+ const activePoint = activePointIndex === undefined ? undefined : chartData[activePointIndex];
73
108
  const tooltipText = activePoint
74
109
  ? formatChartTooltip({formatValue, point: activePoint})
75
110
  : undefined;
76
111
  const summaryLabel =
77
- accessibilityLabel ?? (legendLabel ? `${legendLabel} bar chart` : "Bar chart");
112
+ accessibilityLabel ??
113
+ (effectiveLegendLabel ? `${effectiveLegendLabel} bar chart` : "Bar chart");
78
114
 
79
- return (
115
+ const chart = (
80
116
  <ChartFrame
81
117
  accessibilityLabel={summaryLabel}
82
118
  emptyText={emptyText}
83
- isEmpty={data.length === 0}
84
- legendLabel={legendLabel}
119
+ isEmpty={allPoints.length === 0}
120
+ legendLabel={effectiveLegendLabel}
85
121
  loading={loading}
86
122
  testID={testID}
87
123
  tooltipText={tooltipText}
@@ -116,7 +152,31 @@ export const BarChart: FC<BarChartProps> = ({
116
152
  />
117
153
  );
118
154
  })}
119
- {data.map((point) => {
155
+ {comparisonData.map((point, index) => {
156
+ const layout = getBarLayout({
157
+ barWidth: comparisonBarWidth,
158
+ baselineY,
159
+ value: point.value,
160
+ xCenter: scales.xCenter(point.label),
161
+ y: scales.y,
162
+ });
163
+ if (layout.height === 0) {
164
+ return null;
165
+ }
166
+ return (
167
+ <Rect
168
+ fill={seriesColor}
169
+ height={layout.height}
170
+ key={`comparison-${point.label}`}
171
+ opacity={0.3}
172
+ testID={resolveTestID(testID, `comparison.${index}`)}
173
+ width={layout.width}
174
+ x={layout.x}
175
+ y={layout.y}
176
+ />
177
+ );
178
+ })}
179
+ {chartData.map((point, index) => {
120
180
  const layout = getBarLayout({
121
181
  barWidth,
122
182
  baselineY,
@@ -129,9 +189,10 @@ export const BarChart: FC<BarChartProps> = ({
129
189
  }
130
190
  return (
131
191
  <Rect
132
- fill={point.color ?? paint.series}
192
+ fill={point.color ?? seriesColor}
133
193
  height={layout.height}
134
194
  key={`bar-${point.label}`}
195
+ testID={resolveTestID(testID, `current.${index}`)}
135
196
  width={layout.width}
136
197
  x={layout.x}
137
198
  y={layout.y}
@@ -139,7 +200,7 @@ export const BarChart: FC<BarChartProps> = ({
139
200
  );
140
201
  })}
141
202
  </Svg>
142
- {data.map((point, index) => {
203
+ {chartData.map((point, index) => {
143
204
  const onPress = (): void => {
144
205
  handleMarkPress(index);
145
206
  };
@@ -174,25 +235,27 @@ export const BarChart: FC<BarChartProps> = ({
174
235
  </Box>
175
236
  <Box direction="row">
176
237
  <Box width={axisWidth} />
177
- <Box
178
- flex="grow"
179
- height={CHART_X_AXIS_HEIGHT}
180
- minWidth={0}
181
- overflow="hidden"
182
- position="relative"
183
- >
184
- {data.map((point, index) => (
238
+ <Box flex="grow" height={xAxisHeight} minWidth={0} overflow="hidden" position="relative">
239
+ {axisPoints.map((point, index) => (
185
240
  <Box
186
241
  dangerouslySetInlineStyle={{
187
242
  __style: getXTickStyle({
188
243
  bandwidth: scales.bandwidth,
244
+ isRotated: isXTickRotated,
189
245
  xCenter: scales.xCenter(point.label),
190
246
  }),
191
247
  }}
192
248
  key={`xtick-${point.label}`}
193
249
  testID={resolveTestID(testID, `xtick.${index}`)}
194
250
  >
195
- <Text align="center" color="secondaryDark" size="sm" skipLinking truncate>
251
+ <Text
252
+ align="center"
253
+ color="secondaryDark"
254
+ numberOfLines={1}
255
+ size="sm"
256
+ skipLinking
257
+ truncate={!isXTickRotated}
258
+ >
196
259
  {point.label}
197
260
  </Text>
198
261
  </Box>
@@ -202,6 +265,17 @@ export const BarChart: FC<BarChartProps> = ({
202
265
  </Box>
203
266
  </ChartFrame>
204
267
  );
268
+
269
+ return (
270
+ <ChartFacadeContainer
271
+ onPeriodPress={onPeriodPress}
272
+ periodLabel={periodLabel}
273
+ testID={testID}
274
+ title={title}
275
+ >
276
+ {chart}
277
+ </ChartFacadeContainer>
278
+ );
205
279
  };
206
280
 
207
281
  export type {BarChartProps} from "./Common";
@@ -1,6 +1,7 @@
1
1
  import {describe, expect, it, mock, spyOn} from "bun:test";
2
2
  import {act, fireEvent, render, waitFor} from "@testing-library/react-native";
3
3
  import {assert} from "chai";
4
+ import type {ReactTestInstance} from "react-test-renderer";
4
5
 
5
6
  import {Button} from "./Button";
6
7
  import type {ButtonProps} from "./Common";
@@ -31,6 +32,22 @@ interface CancelablePress {
31
32
  cancel: () => void;
32
33
  }
33
34
 
35
+ const LONG_LABEL = "Go team 🎉🎉🎉🎉🎉…";
36
+
37
+ const hostParentOf = (node: ReactTestInstance | null): ReactTestInstance | null => {
38
+ let parent = node?.parent ?? null;
39
+ while (parent && typeof parent.type !== "string") {
40
+ parent = parent.parent;
41
+ }
42
+ return parent;
43
+ };
44
+
45
+ /** The label and the icon and spinner rows around it, innermost first. */
46
+ const labelAndRows = (label: ReactTestInstance): (ReactTestInstance | null)[] => {
47
+ const iconRow = hostParentOf(label);
48
+ return [label, iconRow, hostParentOf(iconRow)];
49
+ };
50
+
34
51
  describe("Button", () => {
35
52
  it("renders correctly with default props", () => {
36
53
  const {toJSON} = renderWithTheme(<Button onClick={() => {}} text="Click me" />);
@@ -49,6 +66,61 @@ describe("Button", () => {
49
66
  expect(getByTestId("test-button")).toBeTruthy();
50
67
  });
51
68
 
69
+ it("keeps a long label on one line by default", () => {
70
+ const {getByTestId, getByText} = renderWithTheme(
71
+ <Button onClick={() => {}} size="sm" testID="one-line" text={LONG_LABEL} />
72
+ );
73
+
74
+ const [label, iconRow, spinnerRow] = labelAndRows(getByText(LONG_LABEL));
75
+ for (const node of [label, iconRow, spinnerRow]) {
76
+ expect(node?.props.style).not.toHaveProperty("flexShrink");
77
+ }
78
+ expect(label?.props.style).not.toHaveProperty("textAlign");
79
+ const style = getByTestId("one-line").props.style;
80
+ expect(style).toMatchObject({height: 28, paddingVertical: 0});
81
+ expect(style).not.toHaveProperty("maxWidth");
82
+ expect(style).not.toHaveProperty("minHeight");
83
+ });
84
+
85
+ it("fits its container and wraps a long label onto centered lines with wrapText", () => {
86
+ const {getByTestId, getByText} = renderWithTheme(
87
+ <Button onClick={() => {}} testID="wrapping" text={LONG_LABEL} wrapText />
88
+ );
89
+
90
+ const [label, iconRow, spinnerRow] = labelAndRows(getByText(LONG_LABEL));
91
+ expect(label?.props.style).toMatchObject({flexShrink: 1, textAlign: "center"});
92
+ for (const row of [iconRow, spinnerRow]) {
93
+ expect(row?.props.style).toMatchObject({flexShrink: 1});
94
+ }
95
+ const style = getByTestId("wrapping").props.style;
96
+ expect(style).toMatchObject({maxWidth: "100%", paddingVertical: 8});
97
+ expect(style.height).toBeUndefined();
98
+ expect(style).not.toHaveProperty("minHeight");
99
+ });
100
+
101
+ for (const {paddingVertical, variant} of [
102
+ {paddingVertical: 4, variant: "primary"},
103
+ {paddingVertical: 2, variant: "outline"},
104
+ ] as const) {
105
+ it(`grows a sm ${variant} button from 28px instead of clipping a wrapped label`, () => {
106
+ const {getByTestId, getByText} = renderWithTheme(
107
+ <Button
108
+ onClick={() => {}}
109
+ size="sm"
110
+ testID="sm-wrap"
111
+ text={LONG_LABEL}
112
+ variant={variant}
113
+ wrapText
114
+ />
115
+ );
116
+
117
+ const style = getByTestId("sm-wrap").props.style;
118
+ expect(style.height).toBeUndefined();
119
+ expect(style).toMatchObject({maxWidth: "100%", minHeight: 28, paddingVertical});
120
+ expect(getByText(LONG_LABEL).props.style).toMatchObject({flexShrink: 1, fontSize: 14});
121
+ });
122
+ }
123
+
52
124
  it("supports an accessible name distinct from visible text", () => {
53
125
  const {getByTestId} = renderWithTheme(
54
126
  <Button accessibilityLabel="Filter Name" onClick={() => {}} testID="filter-button" text="" />
package/src/Button.tsx CHANGED
@@ -8,7 +8,15 @@ import {
8
8
  } from "pressto";
9
9
  import type React from "react";
10
10
  import {lazy, memo, Suspense, useCallback, useEffect, useMemo, useRef, useState} from "react";
11
- import {ActivityIndicator, Pressable, type PressableProps, Text, View} from "react-native";
11
+ import {
12
+ ActivityIndicator,
13
+ Pressable,
14
+ type PressableProps,
15
+ Text,
16
+ type TextStyle,
17
+ View,
18
+ type ViewStyle,
19
+ } from "react-native";
12
20
 
13
21
  import {Box} from "./Box";
14
22
  import type {ButtonPressAnimation, ButtonProps} from "./Common";
@@ -95,6 +103,7 @@ const ButtonVisual: React.FC<ButtonVisualProps> = ({
95
103
  text,
96
104
  variant = "primary",
97
105
  withConfirmation = false,
106
+ wrapText = false,
98
107
  }) => {
99
108
  const {theme} = useTheme();
100
109
  const CustomIcon = useCustomIcon(iconName);
@@ -157,6 +166,20 @@ const ButtonVisual: React.FC<ButtonVisualProps> = ({
157
166
  isPressDisabled ? Pressable : PRESSABLE_BY_ANIMATION[pressAnimation]
158
167
  ) as React.ComponentType<ButtonPressableProps>;
159
168
  const pressableInteractionProps = isPressDisabled ? {disabled: true} : {enabled: true};
169
+ // `maxWidth` lets a button in a row fit the row instead of its one-line label. The fixed `sm`
170
+ // height would clip a wrapped second line, so a wrapping `sm` button grows from 28px instead.
171
+ const wrapBoxStyle: ViewStyle | undefined = wrapText
172
+ ? {
173
+ maxWidth: "100%",
174
+ ...(size === "sm"
175
+ ? {height: undefined, minHeight: 28, paddingVertical: 4 - (borderWidth ?? 0)}
176
+ : undefined),
177
+ }
178
+ : undefined;
179
+ const wrapRowStyle: ViewStyle | undefined = wrapText ? {flexShrink: 1} : undefined;
180
+ const wrapLabelStyle: TextStyle | undefined = wrapText
181
+ ? {flexShrink: 1, textAlign: "center"}
182
+ : undefined;
160
183
 
161
184
  return (
162
185
  <PressableComponent
@@ -181,11 +204,14 @@ const ButtonVisual: React.FC<ButtonVisualProps> = ({
181
204
  paddingHorizontal: size === "sm" ? 16 : 20,
182
205
  paddingVertical: size === "sm" ? 0 : 8 - (borderWidth ?? 0),
183
206
  width: fullWidth ? "100%" : "auto",
207
+ ...wrapBoxStyle,
184
208
  }}
185
209
  testID={testID}
186
210
  >
187
- <View style={{flexDirection: "row"}}>
188
- <View style={{flexDirection: iconPosition === "left" ? "row" : "row-reverse"}}>
211
+ <View style={{flexDirection: "row", ...wrapRowStyle}}>
212
+ <View
213
+ style={{flexDirection: iconPosition === "left" ? "row" : "row-reverse", ...wrapRowStyle}}
214
+ >
189
215
  {Boolean(iconName) && (
190
216
  <View
191
217
  style={{
@@ -201,7 +227,11 @@ const ButtonVisual: React.FC<ButtonVisualProps> = ({
201
227
  )}
202
228
  </View>
203
229
  )}
204
- <Text style={{color, fontSize: size === "sm" ? 14 : 16, fontWeight: "700"}}>{text}</Text>
230
+ <Text
231
+ style={{color, fontSize: size === "sm" ? 14 : 16, fontWeight: "700", ...wrapLabelStyle}}
232
+ >
233
+ {text}
234
+ </Text>
205
235
  </View>
206
236
  {isLoading && (
207
237
  <Box marginLeft={2}>
@@ -0,0 +1,79 @@
1
+ import {describe, it} from "bun:test";
2
+ import {fireEvent} from "@testing-library/react-native";
3
+ import {assert} from "chai";
4
+
5
+ import {ChartCard} from "./ChartCard";
6
+ import {ChartCard as RootChartCard} from "./index";
7
+ import {Text} from "./Text";
8
+ import {renderWithTheme} from "./test-utils";
9
+
10
+ describe("ChartCard", () => {
11
+ it("renders title, filter summary, period badge, and children", () => {
12
+ const {getByText} = renderWithTheme(
13
+ <ChartCard
14
+ filterSummary="Report filters: status is Eligible"
15
+ periodLabel="Last 30 days"
16
+ title="Cost by Device"
17
+ >
18
+ <Text>Chart body</Text>
19
+ </ChartCard>
20
+ );
21
+
22
+ assert.exists(getByText("Cost by Device"));
23
+ assert.exists(getByText("Report filters: status is Eligible"));
24
+ assert.exists(getByText("Last 30 days"));
25
+ assert.exists(getByText("Chart body"));
26
+ });
27
+
28
+ it("makes the period badge pressable only when a handler is provided", async (): Promise<void> => {
29
+ let pressCount = 0;
30
+ const handlePeriodPress = (): void => {
31
+ pressCount += 1;
32
+ };
33
+ const interactive = renderWithTheme(
34
+ <ChartCard
35
+ onPeriodPress={handlePeriodPress}
36
+ periodLabel="Last 14 days"
37
+ testID="cost-card"
38
+ title="Cost"
39
+ >
40
+ <Text>Body</Text>
41
+ </ChartCard>
42
+ );
43
+
44
+ const periodButton = interactive.getByTestId("cost-card.period-clickable");
45
+ assert.equal(periodButton.props.accessibilityRole, "button");
46
+ assert.equal(periodButton.props["aria-label"], "Last 14 days");
47
+ assert.equal(periodButton.props.accessibilityHint, "Change reporting period");
48
+ fireEvent.press(periodButton);
49
+ await new Promise((resolve) => setTimeout(resolve, 0));
50
+ assert.equal(pressCount, 1);
51
+
52
+ const displayOnly = renderWithTheme(
53
+ <ChartCard periodLabel="Previous period" testID="display-card" title="Cost">
54
+ <Text>Body</Text>
55
+ </ChartCard>
56
+ );
57
+ assert.notExists(displayOnly.queryByTestId("display-card.period-clickable"));
58
+ assert.notEqual(
59
+ displayOnly.getByTestId("display-card.period").props.accessibilityRole,
60
+ "button"
61
+ );
62
+ });
63
+
64
+ it("omits optional period and filter chrome", () => {
65
+ const {queryByTestId, queryByText} = renderWithTheme(
66
+ <ChartCard testID="plain-card" title="Conversions">
67
+ <Text>Body</Text>
68
+ </ChartCard>
69
+ );
70
+
71
+ assert.notExists(queryByTestId("plain-card.period"));
72
+ assert.notExists(queryByTestId("plain-card.filter-summary"));
73
+ assert.notExists(queryByText("Last 30 days"));
74
+ });
75
+
76
+ it("is available from the package root lazy boundary", () => {
77
+ assert.isFunction(RootChartCard);
78
+ });
79
+ });
@@ -0,0 +1,80 @@
1
+ import type {FC} from "react";
2
+
3
+ import {Badge} from "./Badge";
4
+ import {Box} from "./Box";
5
+ import {Card} from "./Card";
6
+ import type {ChartCardProps} from "./Common";
7
+ import {Heading} from "./Heading";
8
+ import {Text} from "./Text";
9
+ import {resolveTestID} from "./testing/resolveTestId";
10
+
11
+ interface PeriodBadgeProps {
12
+ label: string;
13
+ onPress?: () => void;
14
+ testID?: string;
15
+ }
16
+
17
+ const PeriodBadge: FC<PeriodBadgeProps> = ({label, onPress, testID}) => {
18
+ const badge = (
19
+ <Badge
20
+ secondary
21
+ status="active"
22
+ testID={onPress ? resolveTestID(testID, "badge") : testID}
23
+ value={label}
24
+ />
25
+ );
26
+
27
+ if (onPress) {
28
+ return (
29
+ <Box
30
+ accessibilityHint="Change reporting period"
31
+ accessibilityLabel={label}
32
+ accessibilityRole="button"
33
+ onClick={onPress}
34
+ testID={testID}
35
+ >
36
+ {badge}
37
+ </Box>
38
+ );
39
+ }
40
+
41
+ return badge;
42
+ };
43
+
44
+ export const ChartCard: FC<ChartCardProps> = ({
45
+ children,
46
+ filterSummary,
47
+ onPeriodPress,
48
+ periodLabel,
49
+ testID,
50
+ title,
51
+ }) => {
52
+ return (
53
+ <Card gap={3} padding={4} testID={testID}>
54
+ <Box alignItems="start" direction="row" gap={2} justifyContent="between" width="100%">
55
+ <Box flex="grow" minWidth={0}>
56
+ <Heading size="sm" testID={resolveTestID(testID, "title")}>
57
+ {title}
58
+ </Heading>
59
+ </Box>
60
+ {periodLabel ? (
61
+ <PeriodBadge
62
+ label={periodLabel}
63
+ onPress={onPeriodPress}
64
+ testID={resolveTestID(testID, "period")}
65
+ />
66
+ ) : null}
67
+ </Box>
68
+ {filterSummary ? (
69
+ <Text color="secondaryDark" size="sm" testID={resolveTestID(testID, "filter-summary")}>
70
+ {filterSummary}
71
+ </Text>
72
+ ) : null}
73
+ <Box minWidth={0} width="100%">
74
+ {children}
75
+ </Box>
76
+ </Card>
77
+ );
78
+ };
79
+
80
+ export type {ChartCardProps} from "./Common";