@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
package/src/LineChart.tsx CHANGED
@@ -4,17 +4,21 @@ import {Circle, Path, Svg, Line as SvgLine} from "react-native-svg";
4
4
 
5
5
  import {Box} from "./Box";
6
6
  import type {LayoutChangeEvent, LineChartProps} from "./Common";
7
+ import {ChartFacadeContainer} from "./charts/ChartFacadeContainer";
7
8
  import {ChartFrame} from "./charts/ChartFrame";
8
9
  import {
10
+ CHART_ROTATED_X_AXIS_HEIGHT,
9
11
  CHART_X_AXIS_HEIGHT,
10
12
  getChartAxisWidth,
11
13
  getChartPlot,
12
14
  getPlotHeight,
13
15
  getXTickStyle,
14
16
  getYTickStyle,
17
+ shouldRotateChartXTicks,
15
18
  } from "./charts/layout";
16
19
  import {getLinePath} from "./charts/paths";
17
20
  import {createCartesianScales, getYTickValues} from "./charts/scales";
21
+ import {getAllSeriesPoints, getAxisPoints, resolveChartSeries} 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";
@@ -28,27 +32,41 @@ const MARK_HIT_SIZE = 24;
28
32
  const formatChartTooltip = ({
29
33
  formatValue,
30
34
  point,
35
+ seriesLabel,
31
36
  }: {
32
37
  formatValue: (value: number) => string;
33
38
  point: ChartPoint;
39
+ seriesLabel?: string;
34
40
  }): string => {
35
- return `${point.label}: ${formatValue(point.value)}`;
41
+ const prefix = seriesLabel ? `${seriesLabel} — ` : "";
42
+ return `${prefix}${point.label}: ${formatValue(point.value)}`;
36
43
  };
37
44
 
45
+ interface ActivePoint {
46
+ pointIndex: number;
47
+ seriesIndex: number;
48
+ }
49
+
38
50
  export const LineChart: FC<LineChartProps> = ({
39
51
  accessibilityLabel,
52
+ comparisonData = [],
40
53
  data,
41
54
  emptyText = "No data",
42
55
  formatValue = String,
43
56
  height = DEFAULT_HEIGHT,
44
57
  legendLabel,
45
58
  loading = false,
59
+ onPeriodPress,
60
+ periodLabel,
61
+ series,
46
62
  testID,
63
+ title,
64
+ xTickPolicy = "auto",
47
65
  }) => {
48
66
  const {theme} = useTheme();
49
67
  const paint = getChartPaint(theme);
50
68
  const [chartWidth, setChartWidth] = useState(DEFAULT_WIDTH);
51
- const [activePointIndex, setActivePointIndex] = useState<number | undefined>(undefined);
69
+ const [activePoint, setActivePoint] = useState<ActivePoint | undefined>(undefined);
52
70
 
53
71
  const handleLayout = useCallback((event: LayoutChangeEvent): void => {
54
72
  const nextWidth = event.nativeEvent.layout.width;
@@ -57,29 +75,59 @@ export const LineChart: FC<LineChartProps> = ({
57
75
  }
58
76
  }, []);
59
77
 
60
- const handleMarkPress = useCallback((pointIndex: number): void => {
61
- setActivePointIndex(pointIndex);
78
+ const handleMarkPress = useCallback((seriesIndex: number, pointIndex: number): void => {
79
+ setActivePoint({pointIndex, seriesIndex});
62
80
  }, []);
63
81
 
82
+ const resolvedSeries = resolveChartSeries({data, legendLabel, series});
83
+ const allPoints = getAllSeriesPoints({comparisonData, series: resolvedSeries});
84
+ const axisPoints = getAxisPoints({comparisonData, series: resolvedSeries});
85
+ const coloredSeries = resolvedSeries.map((entry, index) => ({
86
+ ...entry,
87
+ color: entry.color ?? paint.slices[index % paint.slices.length] ?? paint.series,
88
+ }));
64
89
  const axisWidth = getChartAxisWidth(chartWidth);
65
- const plotHeight = getPlotHeight({hasLegend: Boolean(legendLabel), height});
90
+ const legendItems =
91
+ series && series.length > 0
92
+ ? coloredSeries.map((entry) => ({color: entry.color, label: entry.label}))
93
+ : undefined;
94
+ const isXTickRotated = shouldRotateChartXTicks({
95
+ labelCount: axisPoints.length,
96
+ policy: xTickPolicy,
97
+ });
98
+ const xAxisHeight = isXTickRotated ? CHART_ROTATED_X_AXIS_HEIGHT : CHART_X_AXIS_HEIGHT;
99
+ const plotHeight = getPlotHeight({
100
+ hasLegend: Boolean(legendLabel) || Boolean(legendItems?.length),
101
+ height,
102
+ xAxisHeight,
103
+ });
66
104
  const plot = getChartPlot({chartWidth, height: plotHeight});
67
105
  const plotWidth = chartWidth - axisWidth;
68
- const scales = createCartesianScales({plot, points: data});
69
- const linePath = getLinePath({points: data, scales});
70
- const yTicks = getYTickValues(data);
71
- const activePoint = activePointIndex === undefined ? undefined : data[activePointIndex];
72
- const tooltipText = activePoint
73
- ? formatChartTooltip({formatValue, point: activePoint})
106
+ const scales = createCartesianScales({
107
+ plot,
108
+ points: allPoints,
109
+ xLabels: axisPoints.map((point) => point.label),
110
+ });
111
+ const comparisonPath = getLinePath({points: comparisonData, scales});
112
+ const yTicks = getYTickValues(allPoints);
113
+ const activeSeries = activePoint ? coloredSeries[activePoint.seriesIndex] : undefined;
114
+ const selectedPoint = activePoint ? activeSeries?.data[activePoint.pointIndex] : undefined;
115
+ const tooltipText = selectedPoint
116
+ ? formatChartTooltip({
117
+ formatValue,
118
+ point: selectedPoint,
119
+ seriesLabel: series && series.length > 0 ? activeSeries?.label : undefined,
120
+ })
74
121
  : undefined;
75
122
  const summaryLabel =
76
123
  accessibilityLabel ?? (legendLabel ? `${legendLabel} line chart` : "Line chart");
77
124
 
78
- return (
125
+ const chart = (
79
126
  <ChartFrame
80
127
  accessibilityLabel={summaryLabel}
81
128
  emptyText={emptyText}
82
- isEmpty={data.length === 0}
129
+ isEmpty={allPoints.length === 0}
130
+ legendItems={legendItems}
83
131
  legendLabel={legendLabel}
84
132
  loading={loading}
85
133
  testID={testID}
@@ -115,66 +163,103 @@ export const LineChart: FC<LineChartProps> = ({
115
163
  />
116
164
  );
117
165
  })}
118
- {linePath ? (
119
- <Path d={linePath} fill="none" stroke={paint.series} strokeWidth={2} />
120
- ) : null}
121
- {data.map((point) => (
122
- <Circle
123
- cx={scales.xCenter(point.label)}
124
- cy={scales.y(point.value)}
125
- fill={paint.series}
126
- key={`dot-${point.label}`}
127
- r={4}
166
+ {comparisonPath ? (
167
+ <Path
168
+ d={comparisonPath}
169
+ fill="none"
170
+ opacity={0.6}
171
+ stroke={paint.series}
172
+ strokeDasharray="4 4"
173
+ strokeWidth={2}
174
+ testID={resolveTestID(testID, "comparison")}
128
175
  />
129
- ))}
176
+ ) : null}
177
+ {coloredSeries.map((entry, seriesIndex) => {
178
+ const linePath = getLinePath({points: entry.data, scales});
179
+ return linePath ? (
180
+ <Path
181
+ d={linePath}
182
+ fill="none"
183
+ key={`line-${entry.id}`}
184
+ stroke={entry.color}
185
+ strokeDasharray={entry.stroke === "dotted" ? "4 4" : undefined}
186
+ strokeWidth={2}
187
+ testID={resolveTestID(testID, `series.${seriesIndex}.path`)}
188
+ />
189
+ ) : null;
190
+ })}
191
+ {coloredSeries.flatMap((entry, seriesIndex) =>
192
+ entry.data.map((point, pointIndex) => (
193
+ <Circle
194
+ cx={scales.xCenter(point.label)}
195
+ cy={scales.y(point.value)}
196
+ fill={entry.color}
197
+ key={`dot-${entry.id}-${point.label}`}
198
+ r={4}
199
+ testID={resolveTestID(testID, `series.${seriesIndex}.marker.${pointIndex}`)}
200
+ />
201
+ ))
202
+ )}
130
203
  </Svg>
131
- {data.map((point, index) => {
132
- const onPress = (): void => {
133
- handleMarkPress(index);
134
- };
135
- return (
136
- <Box
137
- accessibilityHint={`Show value for ${point.label}`}
138
- accessibilityLabel={`${point.label}: ${formatValue(point.value)}`}
139
- dangerouslySetInlineStyle={{
140
- __style: {
141
- height: MARK_HIT_SIZE,
142
- left: scales.xCenter(point.label) - MARK_HIT_SIZE / 2,
143
- position: "absolute",
144
- top: scales.y(point.value) - MARK_HIT_SIZE / 2,
145
- width: MARK_HIT_SIZE,
146
- },
147
- }}
148
- key={`mark-${point.label}`}
149
- onClick={onPress}
150
- onHoverStart={onPress}
151
- testID={resolveTestID(testID, `point.${index}`)}
152
- />
153
- );
154
- })}
204
+ {coloredSeries.flatMap((entry, seriesIndex) =>
205
+ entry.data.map((point, pointIndex) => {
206
+ const onPress = (): void => {
207
+ handleMarkPress(seriesIndex, pointIndex);
208
+ };
209
+ const markTestID =
210
+ series && series.length > 0
211
+ ? `series.${seriesIndex}.point.${pointIndex}`
212
+ : `point.${pointIndex}`;
213
+ return (
214
+ <Box
215
+ accessibilityHint={`Show value for ${point.label}`}
216
+ accessibilityLabel={
217
+ series && series.length > 0
218
+ ? `${entry.label} — ${point.label}: ${formatValue(point.value)}`
219
+ : `${point.label}: ${formatValue(point.value)}`
220
+ }
221
+ dangerouslySetInlineStyle={{
222
+ __style: {
223
+ height: MARK_HIT_SIZE,
224
+ left: scales.xCenter(point.label) - MARK_HIT_SIZE / 2,
225
+ position: "absolute",
226
+ top: scales.y(point.value) - MARK_HIT_SIZE / 2,
227
+ width: MARK_HIT_SIZE,
228
+ },
229
+ }}
230
+ key={`mark-${entry.id}-${point.label}`}
231
+ onClick={onPress}
232
+ onHoverStart={onPress}
233
+ testID={resolveTestID(testID, markTestID)}
234
+ />
235
+ );
236
+ })
237
+ )}
155
238
  </Box>
156
239
  </Box>
157
240
  <Box direction="row">
158
241
  <Box width={axisWidth} />
159
- <Box
160
- flex="grow"
161
- height={CHART_X_AXIS_HEIGHT}
162
- minWidth={0}
163
- overflow="hidden"
164
- position="relative"
165
- >
166
- {data.map((point, index) => (
242
+ <Box flex="grow" height={xAxisHeight} minWidth={0} overflow="hidden" position="relative">
243
+ {axisPoints.map((point, index) => (
167
244
  <Box
168
245
  dangerouslySetInlineStyle={{
169
246
  __style: getXTickStyle({
170
247
  bandwidth: scales.bandwidth,
248
+ isRotated: isXTickRotated,
171
249
  xCenter: scales.xCenter(point.label),
172
250
  }),
173
251
  }}
174
252
  key={`xtick-${point.label}`}
175
253
  testID={resolveTestID(testID, `xtick.${index}`)}
176
254
  >
177
- <Text align="center" color="secondaryDark" size="sm" skipLinking truncate>
255
+ <Text
256
+ align="center"
257
+ color="secondaryDark"
258
+ numberOfLines={1}
259
+ size="sm"
260
+ skipLinking
261
+ truncate={!isXTickRotated}
262
+ >
178
263
  {point.label}
179
264
  </Text>
180
265
  </Box>
@@ -184,7 +269,18 @@ export const LineChart: FC<LineChartProps> = ({
184
269
  </Box>
185
270
  </ChartFrame>
186
271
  );
272
+
273
+ return (
274
+ <ChartFacadeContainer
275
+ onPeriodPress={onPeriodPress}
276
+ periodLabel={periodLabel}
277
+ testID={testID}
278
+ title={title}
279
+ >
280
+ {chart}
281
+ </ChartFacadeContainer>
282
+ );
187
283
  };
188
284
 
189
285
  export type {LineChartProps} from "./Common";
190
- export type {ChartPoint} from "./charts/types/chartTypes";
286
+ export type {ChartPoint, ChartSeries} from "./charts/types/chartTypes";
@@ -0,0 +1,65 @@
1
+ import {describe, it} from "bun:test";
2
+ import {assert} from "chai";
3
+ import {Scorecard as RootScorecard} from "./index";
4
+ import {Scorecard} from "./Scorecard";
5
+ import {renderWithTheme} from "./test-utils";
6
+
7
+ const CURRENT = [
8
+ {label: "Mon", value: 12},
9
+ {label: "Tue", value: 18},
10
+ {label: "Wed", value: 9},
11
+ ];
12
+
13
+ const COMPARISON = [
14
+ {label: "Mon", value: 10},
15
+ {label: "Tue", value: 11},
16
+ {label: "Wed", value: 15},
17
+ ];
18
+
19
+ describe("Scorecard", () => {
20
+ it("renders a formatted metric with current and comparison sparkline paths", () => {
21
+ const {getByTestId, getByText} = renderWithTheme(
22
+ <Scorecard
23
+ comparisonData={COMPARISON}
24
+ formatValue={(value): string => `$${value}`}
25
+ sparklineData={CURRENT}
26
+ testID="cost-scorecard"
27
+ title="Cost"
28
+ value={569}
29
+ />
30
+ );
31
+
32
+ assert.exists(getByText("Cost"));
33
+ assert.exists(getByText("$569"));
34
+ assert.exists(getByTestId("cost-scorecard.sparkline.current"));
35
+ assert.exists(getByTestId("cost-scorecard.sparkline.comparison"));
36
+ });
37
+
38
+ it("renders a string metric without requiring sparkline data", () => {
39
+ const {getByText, queryByTestId} = renderWithTheme(
40
+ <Scorecard sparklineData={[]} testID="status-scorecard" title="Status" value="Healthy" />
41
+ );
42
+
43
+ assert.exists(getByText("Healthy"));
44
+ assert.notExists(queryByTestId("status-scorecard.sparkline"));
45
+ });
46
+
47
+ it("uses default numeric formatting and omits comparison when it is not provided", () => {
48
+ const {getByText, getByTestId, queryByTestId} = renderWithTheme(
49
+ <Scorecard
50
+ sparklineData={CURRENT}
51
+ testID="conversion-scorecard"
52
+ title="Conversions"
53
+ value={7}
54
+ />
55
+ );
56
+
57
+ assert.exists(getByText("7"));
58
+ assert.exists(getByTestId("conversion-scorecard.sparkline.current"));
59
+ assert.notExists(queryByTestId("conversion-scorecard.sparkline.comparison"));
60
+ });
61
+
62
+ it("is available from the package root lazy boundary", () => {
63
+ assert.isFunction(RootScorecard);
64
+ });
65
+ });
@@ -0,0 +1,45 @@
1
+ import type {FC} from "react";
2
+
3
+ import {Box} from "./Box";
4
+ import {ChartCard} from "./ChartCard";
5
+ import type {ScorecardProps} from "./Common";
6
+ import {Heading} from "./Heading";
7
+ import {SparklineChart} from "./SparklineChart";
8
+ import {resolveTestID} from "./testing/resolveTestId";
9
+
10
+ export const Scorecard: FC<ScorecardProps> = ({
11
+ comparisonData,
12
+ formatValue = String,
13
+ onPeriodPress,
14
+ periodLabel,
15
+ sparklineData,
16
+ testID,
17
+ title,
18
+ value,
19
+ }) => {
20
+ const displayValue = typeof value === "number" ? formatValue(value) : value;
21
+
22
+ return (
23
+ <ChartCard
24
+ onPeriodPress={onPeriodPress}
25
+ periodLabel={periodLabel}
26
+ testID={testID}
27
+ title={title}
28
+ >
29
+ <Box gap={2} minWidth={0} width="100%">
30
+ <Heading size="xl" testID={resolveTestID(testID, "value")}>
31
+ {displayValue}
32
+ </Heading>
33
+ {sparklineData && sparklineData.length > 0 ? (
34
+ <SparklineChart
35
+ comparisonData={comparisonData}
36
+ data={sparklineData}
37
+ testID={resolveTestID(testID, "sparkline")}
38
+ />
39
+ ) : null}
40
+ </Box>
41
+ </ChartCard>
42
+ );
43
+ };
44
+
45
+ export type {ScorecardProps} from "./Common";
@@ -0,0 +1,69 @@
1
+ import {describe, it} from "bun:test";
2
+ import {fireEvent} from "@testing-library/react-native";
3
+ import {assert} from "chai";
4
+
5
+ import {SparklineChart as RootSparklineChart} from "./index";
6
+ import {SparklineChart} from "./SparklineChart";
7
+ import {Text} from "./Text";
8
+ import {renderWithTheme} from "./test-utils";
9
+
10
+ const CURRENT = [
11
+ {label: "Mon", value: 12},
12
+ {label: "Tue", value: 18},
13
+ {label: "Wed", value: 9},
14
+ ];
15
+
16
+ const COMPARISON = [
17
+ {label: "Mon", value: 10},
18
+ {label: "Tue", value: 11},
19
+ {label: "Wed", value: 15},
20
+ ];
21
+
22
+ const getPathXCoordinates = (path: string): number[] => {
23
+ return Array.from(path.matchAll(/[ML]([0-9.]+),/g), (match) => Number(match[1]));
24
+ };
25
+
26
+ describe("SparklineChart", () => {
27
+ it("renders current and dotted comparison paths without chart chrome", () => {
28
+ const {getByTestId, queryByTestId, UNSAFE_queryAllByType} = renderWithTheme(
29
+ <SparklineChart comparisonData={COMPARISON} data={CURRENT} testID="revenue-sparkline" />
30
+ );
31
+
32
+ const current = getByTestId("revenue-sparkline.current");
33
+ const comparison = getByTestId("revenue-sparkline.comparison");
34
+
35
+ assert.isUndefined(current.props.strokeDasharray);
36
+ assert.isString(comparison.props.strokeDasharray);
37
+ assert.deepEqual(getPathXCoordinates(current.props.d), getPathXCoordinates(comparison.props.d));
38
+ assert.lengthOf(getPathXCoordinates(current.props.d), CURRENT.length);
39
+ assert.lengthOf(UNSAFE_queryAllByType(Text), 0);
40
+ assert.notExists(queryByTestId("revenue-sparkline.tooltip"));
41
+ assert.notExists(queryByTestId("revenue-sparkline.legend"));
42
+ });
43
+
44
+ it("renders an empty frame without throwing", () => {
45
+ const {getByTestId, queryByTestId} = renderWithTheme(
46
+ <SparklineChart data={[]} testID="empty-sparkline" />
47
+ );
48
+
49
+ assert.exists(getByTestId("empty-sparkline"));
50
+ assert.notExists(queryByTestId("empty-sparkline.current"));
51
+ assert.notExists(queryByTestId("empty-sparkline.comparison"));
52
+ });
53
+
54
+ it("is available from the package root lazy boundary", () => {
55
+ assert.isFunction(RootSparklineChart);
56
+ });
57
+
58
+ it("redraws from the measured container width", () => {
59
+ const {getByTestId} = renderWithTheme(
60
+ <SparklineChart comparisonData={COMPARISON} data={CURRENT} testID="measured-sparkline" />
61
+ );
62
+
63
+ fireEvent(getByTestId("measured-sparkline"), "layout", {
64
+ nativeEvent: {layout: {height: 48, width: 80}},
65
+ });
66
+
67
+ assert.exists(getByTestId("measured-sparkline.current"));
68
+ });
69
+ });
@@ -0,0 +1,85 @@
1
+ import type {FC} from "react";
2
+ import {useCallback, useState} from "react";
3
+ import {Path, Svg} from "react-native-svg";
4
+
5
+ import {Box} from "./Box";
6
+ import type {LayoutChangeEvent, SparklineChartProps} from "./Common";
7
+ import {getLinePath} from "./charts/paths";
8
+ import {createCartesianScales} from "./charts/scales";
9
+ import {getChartPaint} from "./charts/theme";
10
+ import type {ChartPlot} from "./charts/types/chartTypes";
11
+ import {useTheme} from "./Theme";
12
+ import {resolveTestID, toTestProps} from "./testing/resolveTestId";
13
+
14
+ const DEFAULT_HEIGHT = 48;
15
+ const DEFAULT_WIDTH = 200;
16
+ const PLOT_INSET = 4;
17
+
18
+ export const SparklineChart: FC<SparklineChartProps> = ({
19
+ accessibilityLabel = "Sparkline chart",
20
+ comparisonData = [],
21
+ data,
22
+ height = DEFAULT_HEIGHT,
23
+ testID,
24
+ }) => {
25
+ const {theme} = useTheme();
26
+ const paint = getChartPaint(theme);
27
+ const [chartWidth, setChartWidth] = useState(DEFAULT_WIDTH);
28
+
29
+ const handleLayout = useCallback((event: LayoutChangeEvent): void => {
30
+ const nextWidth = event.nativeEvent.layout.width;
31
+ if (nextWidth > 0) {
32
+ setChartWidth(nextWidth);
33
+ }
34
+ }, []);
35
+
36
+ const allPoints = [...data, ...comparisonData];
37
+ const plot: ChartPlot = {
38
+ height: Math.max(height - PLOT_INSET * 2, 1),
39
+ left: PLOT_INSET,
40
+ top: PLOT_INSET,
41
+ width: Math.max(chartWidth - PLOT_INSET * 2, 1),
42
+ };
43
+ const scales = createCartesianScales({includeZero: false, plot, points: allPoints});
44
+ const currentPath = getLinePath({points: data, scales});
45
+ const comparisonPath = getLinePath({points: comparisonData, scales});
46
+
47
+ return (
48
+ <Box
49
+ accessibilityLabel={accessibilityLabel}
50
+ height={height}
51
+ minWidth={0}
52
+ onLayout={handleLayout}
53
+ overflow="hidden"
54
+ width="100%"
55
+ {...toTestProps(testID)}
56
+ >
57
+ {allPoints.length > 0 ? (
58
+ <Svg height={height} width={chartWidth}>
59
+ {comparisonPath ? (
60
+ <Path
61
+ d={comparisonPath}
62
+ fill="none"
63
+ opacity={0.6}
64
+ stroke={paint.series}
65
+ strokeDasharray="4 4"
66
+ strokeWidth={2}
67
+ testID={resolveTestID(testID, "comparison")}
68
+ />
69
+ ) : null}
70
+ {currentPath ? (
71
+ <Path
72
+ d={currentPath}
73
+ fill="none"
74
+ stroke={paint.series}
75
+ strokeWidth={2}
76
+ testID={resolveTestID(testID, "current")}
77
+ />
78
+ ) : null}
79
+ </Svg>
80
+ ) : null}
81
+ </Box>
82
+ );
83
+ };
84
+
85
+ export type {SparklineChartProps} from "./Common";
@@ -790,6 +790,22 @@ describe("TextField", () => {
790
790
  ).not.toThrow();
791
791
  });
792
792
 
793
+ it("clears the measured grow height after the controlled value is emptied", async () => {
794
+ const {getByDisplayValue, rerender} = renderWithTheme(
795
+ <TextField grow multiline onChange={mockOnChange} value="long note" />
796
+ );
797
+ fireEvent(getByDisplayValue("long note"), "contentSizeChange", {
798
+ nativeEvent: {contentSize: {height: 120}},
799
+ });
800
+
801
+ rerender(<TextField grow multiline onChange={mockOnChange} value="" />);
802
+ await act(async () => {});
803
+ rerender(<TextField grow multiline onChange={mockOnChange} value="n" />);
804
+
805
+ const styles = [getByDisplayValue("n").props.style].flat(Infinity);
806
+ assert.isTrue(styles.some((style) => style?.height === 40));
807
+ });
808
+
793
809
  it("invokes the onFocus callback when the input is focused", () => {
794
810
  const {getByDisplayValue} = renderWithTheme(
795
811
  <TextField onChange={mockOnChange} onFocus={mockOnFocus} value="" />
package/src/TextField.tsx CHANGED
@@ -1,5 +1,5 @@
1
1
  import {getCalendars} from "expo-localization";
2
- import {type FC, useCallback, useMemo, useRef, useState} from "react";
2
+ import {type FC, useCallback, useEffect, useMemo, useRef, useState} from "react";
3
3
  import {
4
4
  type DimensionValue,
5
5
  type KeyboardTypeOptions,
@@ -89,6 +89,7 @@ export const TextField: FC<TextFieldProps> = ({
89
89
  multiline,
90
90
  rows = 1,
91
91
  grow,
92
+ maxHeight,
92
93
  returnKeyType,
93
94
  onBlur,
94
95
  onFocus,
@@ -113,6 +114,13 @@ export const TextField: FC<TextFieldProps> = ({
113
114
  const [isValueRevealed, setIsValueRevealed] = useState(false);
114
115
  const textInputRef = useRef<TextInput | null>(null);
115
116
 
117
+ // Clear stale measured height so the next typed character starts at the default row height.
118
+ useEffect(() => {
119
+ if (grow && !value) {
120
+ setHeight(rows * 40);
121
+ }
122
+ }, [grow, rows, value]);
123
+
116
124
  const isPasswordField = type === "password";
117
125
  const hasVisibilityToggle = isPasswordField && showVisibilityToggle;
118
126
 
@@ -164,7 +172,9 @@ export const TextField: FC<TextFieldProps> = ({
164
172
 
165
173
  const calculatedHeight: DimensionValue = useMemo(() => {
166
174
  if (grow) {
167
- return Math.max(40, height);
175
+ // React Native Web never reports a smaller content size, so an emptied field resets.
176
+ const grownHeight = value ? Math.max(40, height) : rows * 40;
177
+ return maxHeight ? Math.min(grownHeight, maxHeight) : grownHeight;
168
178
  } else if (multiline) {
169
179
  return height || "100%";
170
180
  } else {
@@ -172,7 +182,7 @@ export const TextField: FC<TextFieldProps> = ({
172
182
  // single-line inputs need extra vertical room beyond 16px text.
173
183
  return Platform.OS === "ios" ? 24 : 22;
174
184
  }
175
- }, [grow, height, multiline]);
185
+ }, [grow, height, maxHeight, multiline, rows, value]);
176
186
 
177
187
  const defaultTextInputStyles = useMemo(() => {
178
188
  const style: StyleProp<TextStyleWithOutline> = {