@terreno/ui 57.7.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 (186) 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/Avatar.js +2 -2
  6. package/dist/Avatar.js.map +1 -1
  7. package/dist/BarChart.d.ts.map +1 -1
  8. package/dist/BarChart.js +55 -13
  9. package/dist/BarChart.js.map +1 -1
  10. package/dist/Button.js +2 -2
  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 +128 -5
  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/DateTimeActionSheet.js +2 -2
  24. package/dist/DateTimeActionSheet.js.map +1 -1
  25. package/dist/DateTimeField.js +3 -3
  26. package/dist/DateTimeField.js.map +1 -1
  27. package/dist/DonutChart.d.ts.map +1 -1
  28. package/dist/DonutChart.js +20 -10
  29. package/dist/DonutChart.js.map +1 -1
  30. package/dist/DropdownMenuItem.d.ts +16 -0
  31. package/dist/DropdownMenuItem.d.ts.map +1 -0
  32. package/dist/DropdownMenuItem.js +11 -0
  33. package/dist/DropdownMenuItem.js.map +1 -0
  34. package/dist/DropdownPanel.d.ts.map +1 -1
  35. package/dist/DropdownPanel.js +1 -1
  36. package/dist/DropdownPanel.js.map +1 -1
  37. package/dist/FilePickerButton.d.ts.map +1 -1
  38. package/dist/FilePickerButton.js +70 -10
  39. package/dist/FilePickerButton.js.map +1 -1
  40. package/dist/GPTChat.d.ts.map +1 -1
  41. package/dist/GPTChat.js +103 -14
  42. package/dist/GPTChat.js.map +1 -1
  43. package/dist/HeightField.js +2 -2
  44. package/dist/HeightField.js.map +1 -1
  45. package/dist/IconButton.d.ts.map +1 -1
  46. package/dist/IconButton.js +9 -6
  47. package/dist/IconButton.js.map +1 -1
  48. package/dist/LineChart.d.ts +1 -1
  49. package/dist/LineChart.d.ts.map +1 -1
  50. package/dist/LineChart.js +62 -21
  51. package/dist/LineChart.js.map +1 -1
  52. package/dist/MediaQuery.d.ts +10 -0
  53. package/dist/MediaQuery.d.ts.map +1 -1
  54. package/dist/MediaQuery.js +13 -1
  55. package/dist/MediaQuery.js.map +1 -1
  56. package/dist/MultiselectField.js +2 -2
  57. package/dist/MultiselectField.js.map +1 -1
  58. package/dist/RadioField.js +2 -2
  59. package/dist/RadioField.js.map +1 -1
  60. package/dist/Scorecard.d.ts +5 -0
  61. package/dist/Scorecard.d.ts.map +1 -0
  62. package/dist/Scorecard.js +11 -0
  63. package/dist/Scorecard.js.map +1 -0
  64. package/dist/SparklineChart.d.ts +5 -0
  65. package/dist/SparklineChart.d.ts.map +1 -0
  66. package/dist/SparklineChart.js +35 -0
  67. package/dist/SparklineChart.js.map +1 -0
  68. package/dist/SplitPage.d.ts +1 -1
  69. package/dist/SplitPage.d.ts.map +1 -1
  70. package/dist/SplitPage.js +126 -21
  71. package/dist/SplitPage.js.map +1 -1
  72. package/dist/TextField.d.ts.map +1 -1
  73. package/dist/TextField.js +12 -4
  74. package/dist/TextField.js.map +1 -1
  75. package/dist/ToastNotifications.d.ts.map +1 -1
  76. package/dist/ToastNotifications.js +29 -6
  77. package/dist/ToastNotifications.js.map +1 -1
  78. package/dist/UnifiedAddressAutoComplete.js +2 -2
  79. package/dist/UnifiedAddressAutoComplete.js.map +1 -1
  80. package/dist/WebDropdownMenu.d.ts +2 -1
  81. package/dist/WebDropdownMenu.d.ts.map +1 -1
  82. package/dist/WebDropdownMenu.js +2 -6
  83. package/dist/WebDropdownMenu.js.map +1 -1
  84. package/dist/charts/ChartFacadeContainer.d.ts +10 -0
  85. package/dist/charts/ChartFacadeContainer.d.ts.map +1 -0
  86. package/dist/charts/ChartFacadeContainer.js +10 -0
  87. package/dist/charts/ChartFacadeContainer.js.map +1 -0
  88. package/dist/charts/ChartFrame.d.ts +4 -0
  89. package/dist/charts/ChartFrame.d.ts.map +1 -1
  90. package/dist/charts/ChartFrame.js +4 -2
  91. package/dist/charts/ChartFrame.js.map +1 -1
  92. package/dist/charts/layout.d.ts +9 -2
  93. package/dist/charts/layout.d.ts.map +1 -1
  94. package/dist/charts/layout.js +28 -6
  95. package/dist/charts/layout.js.map +1 -1
  96. package/dist/charts/scales.d.ts +3 -1
  97. package/dist/charts/scales.d.ts.map +1 -1
  98. package/dist/charts/scales.js +7 -7
  99. package/dist/charts/scales.js.map +1 -1
  100. package/dist/charts/series.d.ts +15 -0
  101. package/dist/charts/series.d.ts.map +1 -0
  102. package/dist/charts/series.js +19 -0
  103. package/dist/charts/series.js.map +1 -0
  104. package/dist/charts/types/chartTypes.d.ts +7 -0
  105. package/dist/charts/types/chartTypes.d.ts.map +1 -1
  106. package/dist/dashboardGridLayout.d.ts +6 -0
  107. package/dist/dashboardGridLayout.d.ts.map +1 -1
  108. package/dist/dashboardGridLayout.js +19 -3
  109. package/dist/dashboardGridLayout.js.map +1 -1
  110. package/dist/fieldElements/FieldTitle.js +2 -2
  111. package/dist/fieldElements/FieldTitle.js.map +1 -1
  112. package/dist/index.d.ts +4 -1
  113. package/dist/index.d.ts.map +1 -1
  114. package/dist/index.js +1 -1
  115. package/dist/index.js.map +1 -1
  116. package/dist/lazyBoundaries/heavyOptionalExports.d.ts +9 -0
  117. package/dist/lazyBoundaries/heavyOptionalExports.d.ts.map +1 -1
  118. package/dist/lazyBoundaries/heavyOptionalExports.js +6 -0
  119. package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
  120. package/dist/resolveDocumentBodyPortalTarget.d.ts +7 -0
  121. package/dist/resolveDocumentBodyPortalTarget.d.ts.map +1 -0
  122. package/dist/resolveDocumentBodyPortalTarget.js +12 -0
  123. package/dist/resolveDocumentBodyPortalTarget.js.map +1 -0
  124. package/package.json +1 -1
  125. package/src/AIRequestExplorer.test.tsx +2 -2
  126. package/src/AreaChart.test.tsx +81 -0
  127. package/src/AreaChart.tsx +171 -62
  128. package/src/Avatar.tsx +2 -2
  129. package/src/BarChart.test.tsx +119 -0
  130. package/src/BarChart.tsx +94 -20
  131. package/src/Button.test.tsx +7 -7
  132. package/src/Button.tsx +2 -2
  133. package/src/ChartCard.test.tsx +79 -0
  134. package/src/ChartCard.tsx +80 -0
  135. package/src/Common.ts +119 -2
  136. package/src/DashboardGrid.test.tsx +98 -1
  137. package/src/DashboardGrid.tsx +71 -20
  138. package/src/DateTimeActionSheet.tsx +4 -4
  139. package/src/DateTimeField.test.tsx +5 -4
  140. package/src/DateTimeField.tsx +3 -3
  141. package/src/DonutChart.test.tsx +73 -0
  142. package/src/DonutChart.tsx +87 -14
  143. package/src/DropdownMenuItem.tsx +48 -0
  144. package/src/DropdownPanel.test.tsx +12 -0
  145. package/src/DropdownPanel.tsx +8 -1
  146. package/src/FilePickerButton.test.tsx +60 -6
  147. package/src/FilePickerButton.tsx +116 -28
  148. package/src/GPTChat.test.tsx +133 -6
  149. package/src/GPTChat.tsx +196 -38
  150. package/src/HeightField.tsx +2 -2
  151. package/src/IconButton.test.tsx +63 -0
  152. package/src/IconButton.tsx +10 -5
  153. package/src/LineChart.test.tsx +104 -0
  154. package/src/LineChart.tsx +154 -58
  155. package/src/MediaQuery.ts +14 -1
  156. package/src/MultiselectField.tsx +2 -2
  157. package/src/RadioField.tsx +2 -2
  158. package/src/Scorecard.test.tsx +65 -0
  159. package/src/Scorecard.tsx +45 -0
  160. package/src/SparklineChart.test.tsx +69 -0
  161. package/src/SparklineChart.tsx +85 -0
  162. package/src/SplitPage.test.tsx +449 -11
  163. package/src/SplitPage.tsx +255 -21
  164. package/src/TextField.test.tsx +16 -0
  165. package/src/TextField.tsx +13 -3
  166. package/src/ToastNotifications.tsx +33 -6
  167. package/src/ToastNotifications.webModal.test.tsx +285 -0
  168. package/src/UnifiedAddressAutoComplete.test.tsx +4 -4
  169. package/src/UnifiedAddressAutoComplete.tsx +2 -2
  170. package/src/WebDropdownMenu.tsx +3 -7
  171. package/src/__snapshots__/DropdownPanel.test.tsx.snap +3 -1
  172. package/src/bunSetup.ts +3 -1
  173. package/src/charts/ChartFacadeContainer.tsx +35 -0
  174. package/src/charts/ChartFrame.tsx +39 -1
  175. package/src/charts/layout.test.ts +22 -1
  176. package/src/charts/layout.ts +37 -4
  177. package/src/charts/scales.test.ts +33 -0
  178. package/src/charts/scales.ts +10 -6
  179. package/src/charts/series.ts +43 -0
  180. package/src/charts/types/chartTypes.ts +8 -0
  181. package/src/dashboardGridLayout.test.ts +59 -1
  182. package/src/dashboardGridLayout.ts +30 -3
  183. package/src/fieldElements/FieldTitle.tsx +2 -2
  184. package/src/index.tsx +6 -0
  185. package/src/lazyBoundaries/heavyOptionalExports.tsx +21 -0
  186. package/src/resolveDocumentBodyPortalTarget.ts +11 -0
@@ -5,13 +5,13 @@ import {ActivityIndicator, Text as NativeText, Pressable, View} from "react-nati
5
5
 
6
6
  import type {IconButtonProps} from "./Common";
7
7
  import {useCustomIcon} from "./IconRegistry";
8
- import {isMobileDevice} from "./MediaQuery";
8
+ import {isNarrowViewport} from "./MediaQuery";
9
9
  import {Modal} from "./Modal";
10
10
  import {Text} from "./Text";
11
11
  import {useTheme} from "./Theme";
12
12
  import {Tooltip} from "./Tooltip";
13
13
  import {Unifier} from "./Unifier";
14
- import {isNative} from "./Utilities";
14
+ import {applyColorOpacity, isNative} from "./Utilities";
15
15
 
16
16
  interface ConfirmationModalProps {
17
17
  visible: boolean;
@@ -56,6 +56,7 @@ const IconButtonComponent: FC<IconButtonProps> = ({
56
56
  indicator,
57
57
  indicatorText,
58
58
  loading: propsLoading = false,
59
+ backgroundOpacity,
59
60
  size = "default",
60
61
  state = "default",
61
62
  testID,
@@ -109,14 +110,18 @@ const IconButtonComponent: FC<IconButtonProps> = ({
109
110
  }
110
111
  }
111
112
 
113
+ if (typeof backgroundOpacity === "number") {
114
+ backgroundColor = applyColorOpacity({color: backgroundColor, opacity: backgroundOpacity});
115
+ }
116
+
112
117
  const indicatorColor = indicator ? theme.surface[indicator] : undefined;
113
118
 
114
119
  return (
115
120
  <Pressable
116
121
  accessibilityHint={
117
- (accessibilityHint ?? withConfirmation)
122
+ withConfirmation
118
123
  ? `Opens a confirmation dialog to confirm ${accessLabel}`
119
- : `Press to perform ${accessLabel} action`
124
+ : (accessibilityHint ?? `Press to perform ${accessLabel} action`)
120
125
  }
121
126
  aria-label={accessLabel}
122
127
  aria-role="button"
@@ -218,7 +223,7 @@ const IconButtonComponent: FC<IconButtonProps> = ({
218
223
 
219
224
  export const IconButton: FC<IconButtonProps> = (props) => {
220
225
  const {tooltipText, tooltipIdealPosition, tooltipIncludeArrow = false} = props;
221
- const isMobileOrNative = isMobileDevice() || isNative();
226
+ const isMobileOrNative = isNarrowViewport() || isNative();
222
227
 
223
228
  if (tooltipText && !isMobileOrNative) {
224
229
  return (
@@ -1,5 +1,6 @@
1
1
  import {describe, expect, it, spyOn} from "bun:test";
2
2
  import {act, fireEvent} from "@testing-library/react-native";
3
+ import {assert} from "chai";
3
4
  import {Linking} from "react-native";
4
5
 
5
6
  import {LineChart} from "./LineChart";
@@ -11,7 +12,110 @@ const POINTS = [
11
12
  {label: "C", value: 100},
12
13
  ];
13
14
 
15
+ const SERIES = [
16
+ {data: POINTS, id: "rank", label: "Search lost IS (rank)"},
17
+ {
18
+ data: POINTS.map((point) => ({...point, value: point.value / 2})),
19
+ id: "share",
20
+ label: "Search impr. share",
21
+ },
22
+ {
23
+ data: POINTS.map((point) => ({...point, value: point.value / 4})),
24
+ id: "budget",
25
+ label: "Search lost IS (budget)",
26
+ },
27
+ ];
28
+
14
29
  describe("LineChart", () => {
30
+ it("applies explicit tick rotation and chart-card header shortcuts", async (): Promise<void> => {
31
+ let pressCount = 0;
32
+ const {getByTestId, getByText} = renderWithTheme(
33
+ <LineChart
34
+ data={POINTS}
35
+ onPeriodPress={(): void => {
36
+ pressCount += 1;
37
+ }}
38
+ periodLabel="Last 30 days"
39
+ testID="chart"
40
+ title="Search share"
41
+ xTickPolicy="rotate"
42
+ />
43
+ );
44
+ const tickStyle = getByTestId("chart.xtick.0").props.style;
45
+ const tickStyles = Array.isArray(tickStyle) ? tickStyle : [tickStyle];
46
+
47
+ assert.isTrue(tickStyles.some((style) => Array.isArray(style?.transform)));
48
+ assert.exists(getByText("Search share"));
49
+ assert.exists(getByText("Last 30 days"));
50
+ fireEvent.press(getByTestId("chart.card.period-clickable"));
51
+ await new Promise((resolve) => setTimeout(resolve, 0));
52
+ assert.equal(pressCount, 1);
53
+ });
54
+
55
+ it("renders one path and legend item per named series", () => {
56
+ const {getByTestId, getByText} = renderWithTheme(
57
+ <LineChart data={[]} series={SERIES} testID="chart" />
58
+ );
59
+
60
+ for (let index = 0; index < SERIES.length; index += 1) {
61
+ assert.exists(getByTestId(`chart.series.${index}.path`));
62
+ assert.exists(getByTestId(`chart.series.${index}.marker.0`));
63
+ assert.exists(getByTestId(`chart.legend.${index}`));
64
+ assert.exists(getByTestId(`chart.legend.${index}.swatch`));
65
+ const legendStyle = getByTestId(`chart.legend.${index}.item`).props.style;
66
+ const legendStyles = Array.isArray(legendStyle) ? legendStyle : [legendStyle];
67
+ assert.isTrue(
68
+ legendStyles.some(
69
+ (style: {flexGrow?: number; minWidth?: number} | undefined) =>
70
+ style?.flexGrow === 1 && style.minWidth === 0
71
+ )
72
+ );
73
+ assert.exists(getByText(SERIES[index]?.label ?? ""));
74
+ }
75
+ assert.isBelow(
76
+ getByTestId("chart.series.0.marker.2").props.cy,
77
+ getByTestId("chart.series.2.marker.2").props.cy
78
+ );
79
+ });
80
+
81
+ it("identifies the active series in a multi-series tooltip", async (): Promise<void> => {
82
+ const {getByTestId, getByText} = renderWithTheme(
83
+ <LineChart data={[]} series={SERIES} testID="chart" />
84
+ );
85
+
86
+ await act(async () => {
87
+ fireEvent.press(getByTestId("chart.series.1.point.1-clickable"));
88
+ await new Promise((resolve) => setTimeout(resolve, 0));
89
+ });
90
+
91
+ assert.exists(getByText("Search impr. share — B: 25"));
92
+ });
93
+
94
+ it("renders a dotted comparison path on the shared scale", () => {
95
+ const {getByTestId} = renderWithTheme(
96
+ <LineChart comparisonData={POINTS} data={POINTS} testID="chart" />
97
+ );
98
+
99
+ assert.isString(getByTestId("chart.comparison").props.strokeDasharray);
100
+ });
101
+
102
+ it("renders comparison-only data instead of the empty state", () => {
103
+ const {getByTestId, queryByText} = renderWithTheme(
104
+ <LineChart comparisonData={POINTS} data={[]} testID="chart" />
105
+ );
106
+
107
+ assert.exists(getByTestId("chart.comparison"));
108
+ assert.notExists(queryByText("No data"));
109
+ });
110
+
111
+ it("shows the empty state when every named series is empty", () => {
112
+ const {getByText} = renderWithTheme(
113
+ <LineChart data={POINTS} series={[{data: [], id: "empty", label: "Empty"}]} />
114
+ );
115
+
116
+ assert.exists(getByText("No data"));
117
+ });
118
+
15
119
  it("renders one mark testID per point", () => {
16
120
  const {getByTestId, queryByTestId} = renderWithTheme(
17
121
  <LineChart data={POINTS} testID="chart" />
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";
package/src/MediaQuery.ts CHANGED
@@ -34,9 +34,22 @@ export const mediaQuerySmallerThan = (size: ResponsiveBreakpoint): boolean => {
34
34
  return !isBreakpointAtLeast({breakpoint: media, minimum: size}) || media === size;
35
35
  };
36
36
 
37
- export const isMobileDevice = (): boolean => {
37
+ /**
38
+ * True when the current window is below the desktop breakpoint.
39
+ * On web that floor is `lg` (1024). On native that floor is `xl`.
40
+ * Reads the window size at call time and does not subscribe to resize.
41
+ */
42
+ export const isNarrowViewport = (): boolean => {
38
43
  return !isSupportedDesktopViewport({
39
44
  breakpoint: mediaQuery(),
40
45
  surface: getBreakpointSurface(),
41
46
  });
42
47
  };
48
+
49
+ /**
50
+ * @deprecated Use `isNarrowViewport`. Supported while callers migrate.
51
+ * Same result as `isNarrowViewport`.
52
+ */
53
+ export const isMobileDevice = (): boolean => {
54
+ return isNarrowViewport();
55
+ };
@@ -6,7 +6,7 @@ import type {MultiselectFieldProps} from "./Common";
6
6
  import {FieldError} from "./fieldElements/FieldError";
7
7
  import {FieldHelperText} from "./fieldElements/FieldHelperText";
8
8
  import {Heading} from "./Heading";
9
- import {isMobileDevice} from "./MediaQuery";
9
+ import {isNarrowViewport} from "./MediaQuery";
10
10
  import {Text} from "./Text";
11
11
  import {resolveFieldTestIDsFromProps} from "./testing/resolveTestId";
12
12
 
@@ -66,7 +66,7 @@ export const MultiselectField: FC<MultiselectFieldProps> = ({
66
66
  testID,
67
67
  testIDs,
68
68
  }) => {
69
- const isMobile = isMobileDevice();
69
+ const isMobile = isNarrowViewport();
70
70
  const isDefault = variant === "leftText";
71
71
  const fieldTestIDs = resolveFieldTestIDsFromProps({testID, testIDs});
72
72
  const selectedItems = value ?? [];
@@ -3,7 +3,7 @@ import {TouchableOpacity, View} from "react-native";
3
3
 
4
4
  import type {RadioFieldProps} from "./Common";
5
5
  import {Heading} from "./Heading";
6
- import {isMobileDevice} from "./MediaQuery";
6
+ import {isNarrowViewport} from "./MediaQuery";
7
7
  import {Radio} from "./Radio";
8
8
  import {Text} from "./Text";
9
9
 
@@ -15,7 +15,7 @@ export const RadioField = ({
15
15
  variant = "rightText",
16
16
  }: RadioFieldProps): React.ReactElement => {
17
17
  return (
18
- <View style={{gap: isMobileDevice() ? 16 : 8}}>
18
+ <View style={{gap: isNarrowViewport() ? 16 : 8}}>
19
19
  <Heading size="sm">{title}</Heading>
20
20
  {options.map((option) => (
21
21
  <TouchableOpacity
@@ -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";