@terreno/ui 57.8.0 → 57.9.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 (134) hide show
  1. package/dist/AreaChart.d.ts +1 -1
  2. package/dist/AreaChart.d.ts.map +1 -1
  3. package/dist/AreaChart.js +70 -22
  4. package/dist/AreaChart.js.map +1 -1
  5. package/dist/BarChart.d.ts.map +1 -1
  6. package/dist/BarChart.js +55 -13
  7. package/dist/BarChart.js.map +1 -1
  8. package/dist/ChartCard.d.ts +5 -0
  9. package/dist/ChartCard.d.ts.map +1 -0
  10. package/dist/ChartCard.js +18 -0
  11. package/dist/ChartCard.js.map +1 -0
  12. package/dist/Common.d.ts +79 -5
  13. package/dist/Common.d.ts.map +1 -1
  14. package/dist/Common.js.map +1 -1
  15. package/dist/DashboardGrid.d.ts +6 -2
  16. package/dist/DashboardGrid.d.ts.map +1 -1
  17. package/dist/DashboardGrid.js +43 -10
  18. package/dist/DashboardGrid.js.map +1 -1
  19. package/dist/DonutChart.d.ts.map +1 -1
  20. package/dist/DonutChart.js +20 -10
  21. package/dist/DonutChart.js.map +1 -1
  22. package/dist/DropdownMenuItem.d.ts +16 -0
  23. package/dist/DropdownMenuItem.d.ts.map +1 -0
  24. package/dist/DropdownMenuItem.js +11 -0
  25. package/dist/DropdownMenuItem.js.map +1 -0
  26. package/dist/FilePickerButton.d.ts.map +1 -1
  27. package/dist/FilePickerButton.js +70 -10
  28. package/dist/FilePickerButton.js.map +1 -1
  29. package/dist/GPTChat.d.ts.map +1 -1
  30. package/dist/GPTChat.js +103 -14
  31. package/dist/GPTChat.js.map +1 -1
  32. package/dist/LineChart.d.ts +1 -1
  33. package/dist/LineChart.d.ts.map +1 -1
  34. package/dist/LineChart.js +62 -21
  35. package/dist/LineChart.js.map +1 -1
  36. package/dist/Scorecard.d.ts +5 -0
  37. package/dist/Scorecard.d.ts.map +1 -0
  38. package/dist/Scorecard.js +11 -0
  39. package/dist/Scorecard.js.map +1 -0
  40. package/dist/SparklineChart.d.ts +5 -0
  41. package/dist/SparklineChart.d.ts.map +1 -0
  42. package/dist/SparklineChart.js +35 -0
  43. package/dist/SparklineChart.js.map +1 -0
  44. package/dist/TextField.d.ts.map +1 -1
  45. package/dist/TextField.js +12 -4
  46. package/dist/TextField.js.map +1 -1
  47. package/dist/ToastNotifications.d.ts.map +1 -1
  48. package/dist/ToastNotifications.js +29 -6
  49. package/dist/ToastNotifications.js.map +1 -1
  50. package/dist/WebDropdownMenu.d.ts +2 -1
  51. package/dist/WebDropdownMenu.d.ts.map +1 -1
  52. package/dist/WebDropdownMenu.js +2 -6
  53. package/dist/WebDropdownMenu.js.map +1 -1
  54. package/dist/charts/ChartFacadeContainer.d.ts +10 -0
  55. package/dist/charts/ChartFacadeContainer.d.ts.map +1 -0
  56. package/dist/charts/ChartFacadeContainer.js +10 -0
  57. package/dist/charts/ChartFacadeContainer.js.map +1 -0
  58. package/dist/charts/ChartFrame.d.ts +4 -0
  59. package/dist/charts/ChartFrame.d.ts.map +1 -1
  60. package/dist/charts/ChartFrame.js +4 -2
  61. package/dist/charts/ChartFrame.js.map +1 -1
  62. package/dist/charts/layout.d.ts +9 -2
  63. package/dist/charts/layout.d.ts.map +1 -1
  64. package/dist/charts/layout.js +28 -6
  65. package/dist/charts/layout.js.map +1 -1
  66. package/dist/charts/scales.d.ts +3 -1
  67. package/dist/charts/scales.d.ts.map +1 -1
  68. package/dist/charts/scales.js +7 -7
  69. package/dist/charts/scales.js.map +1 -1
  70. package/dist/charts/series.d.ts +15 -0
  71. package/dist/charts/series.d.ts.map +1 -0
  72. package/dist/charts/series.js +19 -0
  73. package/dist/charts/series.js.map +1 -0
  74. package/dist/charts/types/chartTypes.d.ts +7 -0
  75. package/dist/charts/types/chartTypes.d.ts.map +1 -1
  76. package/dist/dashboardGridLayout.d.ts +6 -0
  77. package/dist/dashboardGridLayout.d.ts.map +1 -1
  78. package/dist/dashboardGridLayout.js +19 -3
  79. package/dist/dashboardGridLayout.js.map +1 -1
  80. package/dist/index.d.ts +4 -1
  81. package/dist/index.d.ts.map +1 -1
  82. package/dist/index.js +1 -1
  83. package/dist/index.js.map +1 -1
  84. package/dist/lazyBoundaries/heavyOptionalExports.d.ts +9 -0
  85. package/dist/lazyBoundaries/heavyOptionalExports.d.ts.map +1 -1
  86. package/dist/lazyBoundaries/heavyOptionalExports.js +6 -0
  87. package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
  88. package/dist/resolveDocumentBodyPortalTarget.d.ts +7 -0
  89. package/dist/resolveDocumentBodyPortalTarget.d.ts.map +1 -0
  90. package/dist/resolveDocumentBodyPortalTarget.js +12 -0
  91. package/dist/resolveDocumentBodyPortalTarget.js.map +1 -0
  92. package/package.json +1 -1
  93. package/src/AIRequestExplorer.test.tsx +2 -2
  94. package/src/AreaChart.test.tsx +81 -0
  95. package/src/AreaChart.tsx +171 -62
  96. package/src/BarChart.test.tsx +119 -0
  97. package/src/BarChart.tsx +94 -20
  98. package/src/ChartCard.test.tsx +79 -0
  99. package/src/ChartCard.tsx +80 -0
  100. package/src/Common.ts +69 -2
  101. package/src/DashboardGrid.test.tsx +98 -1
  102. package/src/DashboardGrid.tsx +71 -20
  103. package/src/DonutChart.test.tsx +73 -0
  104. package/src/DonutChart.tsx +87 -14
  105. package/src/DropdownMenuItem.tsx +48 -0
  106. package/src/FilePickerButton.test.tsx +60 -6
  107. package/src/FilePickerButton.tsx +116 -28
  108. package/src/GPTChat.test.tsx +133 -6
  109. package/src/GPTChat.tsx +196 -38
  110. package/src/LineChart.test.tsx +104 -0
  111. package/src/LineChart.tsx +154 -58
  112. package/src/Scorecard.test.tsx +65 -0
  113. package/src/Scorecard.tsx +45 -0
  114. package/src/SparklineChart.test.tsx +69 -0
  115. package/src/SparklineChart.tsx +85 -0
  116. package/src/TextField.test.tsx +16 -0
  117. package/src/TextField.tsx +13 -3
  118. package/src/ToastNotifications.tsx +33 -6
  119. package/src/ToastNotifications.webModal.test.tsx +285 -0
  120. package/src/WebDropdownMenu.tsx +3 -7
  121. package/src/bunSetup.ts +1 -0
  122. package/src/charts/ChartFacadeContainer.tsx +35 -0
  123. package/src/charts/ChartFrame.tsx +39 -1
  124. package/src/charts/layout.test.ts +22 -1
  125. package/src/charts/layout.ts +37 -4
  126. package/src/charts/scales.test.ts +33 -0
  127. package/src/charts/scales.ts +10 -6
  128. package/src/charts/series.ts +43 -0
  129. package/src/charts/types/chartTypes.ts +8 -0
  130. package/src/dashboardGridLayout.test.ts +59 -1
  131. package/src/dashboardGridLayout.ts +30 -3
  132. package/src/index.tsx +6 -0
  133. package/src/lazyBoundaries/heavyOptionalExports.tsx +21 -0
  134. 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";
@@ -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";
package/src/Common.ts CHANGED
@@ -19,6 +19,7 @@ import type {
19
19
  FontAwesome6RegularNames,
20
20
  FontAwesome6SolidNames,
21
21
  } from "./CommonIconTypes";
22
+ import type {ChartPoint, ChartSeries} from "./charts/types/chartTypes";
22
23
  import type {DropdownPanelAlign} from "./dropdownPanelLayout";
23
24
  import type {
24
25
  DataTableTestIDs,
@@ -993,6 +994,11 @@ export interface TextFieldProps extends BaseFieldProps, HelperTextProps, ErrorTe
993
994
  returnKeyType?: "done" | "go" | "next" | "search" | "send";
994
995
 
995
996
  grow?: boolean;
997
+ /**
998
+ * Caps the height (in pixels) a `grow` field expands to. Past the cap the field
999
+ * stops growing and its content scrolls.
1000
+ */
1001
+ maxHeight?: number;
996
1002
  multiline?: boolean;
997
1003
  rows?: number;
998
1004
 
@@ -2734,8 +2740,10 @@ export interface PaginationProps extends WithTestID {
2734
2740
  export interface LineChartProps extends WithTestID {
2735
2741
  /** Summary announced for the whole chart. */
2736
2742
  accessibilityLabel?: string;
2743
+ /** Optional previous-period values drawn as a dotted overlay. */
2744
+ comparisonData?: ChartPoint[];
2737
2745
  /** Single series of labeled numeric points. */
2738
- data: Array<{color?: string; label: string; value: number}>;
2746
+ data: ChartPoint[];
2739
2747
  /** Copy shown when `data` is empty. */
2740
2748
  emptyText?: string;
2741
2749
  /** Formats the numeric value in tooltips. */
@@ -2746,12 +2754,65 @@ export interface LineChartProps extends WithTestID {
2746
2754
  legendLabel?: string;
2747
2755
  /** When true, shows a spinner instead of the plot. */
2748
2756
  loading?: boolean;
2757
+ /** Makes `periodLabel` pressable when provided. */
2758
+ onPeriodPress?: () => void;
2759
+ /** Relative or absolute reporting period shown with `title`. */
2760
+ periodLabel?: string;
2761
+ /** Named series. When non-empty, these replace the single `data` series. */
2762
+ series?: ChartSeries[];
2763
+ /** Optional chart-card title shortcut. */
2764
+ title?: string;
2765
+ /** X-label collision policy. `auto` rotates when more than seven labels are present. */
2766
+ xTickPolicy?: "auto" | "rotate" | "truncate";
2767
+ }
2768
+
2769
+ export interface SparklineChartProps extends WithTestID {
2770
+ /** Summary announced for the whole sparkline. */
2771
+ accessibilityLabel?: string;
2772
+ /** Optional previous-period values drawn as a dotted line. */
2773
+ comparisonData?: Array<{label: string; value: number}>;
2774
+ /** Current labeled numeric values. */
2775
+ data: Array<{label: string; value: number}>;
2776
+ /** Whole sparkline height in pixels. */
2777
+ height?: number;
2778
+ }
2779
+
2780
+ export interface ChartCardProps extends WithTestID {
2781
+ children: React.ReactNode;
2782
+ /** Optional context shown below the title row. */
2783
+ filterSummary?: string;
2784
+ /** Makes the period badge pressable when provided. */
2785
+ onPeriodPress?: () => void;
2786
+ /** Date range or relative period shown in the header. */
2787
+ periodLabel?: string;
2788
+ /** Card heading. */
2789
+ title: string;
2790
+ }
2791
+
2792
+ export interface ScorecardProps extends WithTestID {
2793
+ /** Optional previous-period sparkline values. */
2794
+ comparisonData?: Array<{label: string; value: number}>;
2795
+ /** Formats numeric values. String values render unchanged. */
2796
+ formatValue?: (value: number) => string;
2797
+ onPeriodPress?: () => void;
2798
+ periodLabel?: string;
2799
+ /** Current-period sparkline values. */
2800
+ sparklineData?: Array<{label: string; value: number}>;
2801
+ title: string;
2802
+ value: number | string;
2749
2803
  }
2750
2804
 
2751
2805
  export interface AreaChartProps extends LineChartProps {}
2752
2806
  export interface BarChartProps extends LineChartProps {}
2753
2807
 
2754
- export interface DonutChartProps extends LineChartProps {}
2808
+ export interface DonutChartProps extends LineChartProps {
2809
+ /** Small copy below the center value. */
2810
+ centerTitle?: string;
2811
+ /** Primary copy inside the donut hole. */
2812
+ centerValue?: string;
2813
+ /** Formats each slice's legend share. Defaults to a rounded percentage. */
2814
+ formatShare?: (value: number, total: number) => string;
2815
+ }
2755
2816
 
2756
2817
  export interface DashboardGridProps extends WithTestID {
2757
2818
  children?: React.ReactNode;
@@ -2760,6 +2821,12 @@ export interface DashboardGridProps extends WithTestID {
2760
2821
  gap?: UnsignedUpTo12;
2761
2822
  }
2762
2823
 
2824
+ export interface DashboardGridItemProps extends WithTestID {
2825
+ children?: React.ReactNode;
2826
+ /** Number of grid columns occupied at each breakpoint. Defaults to one. */
2827
+ span?: {lg?: number; md?: number; sm?: number};
2828
+ }
2829
+
2763
2830
  /**
2764
2831
  * Data Table
2765
2832
  */