@terreno/ui 57.3.0 → 57.4.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 (212) hide show
  1. package/dist/AnnouncementBanner.d.ts +12 -0
  2. package/dist/AnnouncementBanner.js +61 -0
  3. package/dist/AnnouncementBanner.js.map +1 -0
  4. package/dist/AnnouncementNavigator.d.ts +11 -0
  5. package/dist/AnnouncementNavigator.js +189 -0
  6. package/dist/AnnouncementNavigator.js.map +1 -0
  7. package/dist/AnnouncementScreen.d.ts +12 -0
  8. package/dist/AnnouncementScreen.js +28 -0
  9. package/dist/AnnouncementScreen.js.map +1 -0
  10. package/dist/AreaChart.d.ts +5 -0
  11. package/dist/AreaChart.js +69 -0
  12. package/dist/AreaChart.js.map +1 -0
  13. package/dist/BarChart.d.ts +5 -0
  14. package/dist/BarChart.js +89 -0
  15. package/dist/BarChart.js.map +1 -0
  16. package/dist/Button.js +17 -3
  17. package/dist/Button.js.map +1 -1
  18. package/dist/Common.d.ts +96 -0
  19. package/dist/Common.js.map +1 -1
  20. package/dist/DashboardGrid.d.ts +4 -0
  21. package/dist/DashboardGrid.js +38 -0
  22. package/dist/DashboardGrid.js.map +1 -0
  23. package/dist/DataTable.js +83 -11
  24. package/dist/DataTable.js.map +1 -1
  25. package/dist/DonutChart.d.ts +5 -0
  26. package/dist/DonutChart.js +84 -0
  27. package/dist/DonutChart.js.map +1 -0
  28. package/dist/Filter.js +12 -2
  29. package/dist/Filter.js.map +1 -1
  30. package/dist/GPTChat.d.ts +7 -1
  31. package/dist/GPTChat.js +28 -15
  32. package/dist/GPTChat.js.map +1 -1
  33. package/dist/LineChart.d.ts +5 -0
  34. package/dist/LineChart.js +68 -0
  35. package/dist/LineChart.js.map +1 -0
  36. package/dist/MarkdownEmbed.d.ts +6 -0
  37. package/dist/MarkdownEmbed.js +17 -0
  38. package/dist/MarkdownEmbed.js.map +1 -0
  39. package/dist/MarkdownView.js +38 -3
  40. package/dist/MarkdownView.js.map +1 -1
  41. package/dist/Modal.js +12 -10
  42. package/dist/Modal.js.map +1 -1
  43. package/dist/ModalSheet.d.ts +5 -1
  44. package/dist/ModalSheet.js +31 -13
  45. package/dist/ModalSheet.js.map +1 -1
  46. package/dist/MultiselectField.js +4 -9
  47. package/dist/MultiselectField.js.map +1 -1
  48. package/dist/NotificationBell.d.ts +16 -0
  49. package/dist/NotificationBell.js +15 -0
  50. package/dist/NotificationBell.js.map +1 -0
  51. package/dist/NotificationInbox.d.ts +21 -0
  52. package/dist/NotificationInbox.js +41 -0
  53. package/dist/NotificationInbox.js.map +1 -0
  54. package/dist/NotificationPreferences.d.ts +14 -0
  55. package/dist/NotificationPreferences.js +32 -0
  56. package/dist/NotificationPreferences.js.map +1 -0
  57. package/dist/TextField.js +83 -6
  58. package/dist/TextField.js.map +1 -1
  59. package/dist/announcementBuildVersion.d.ts +6 -0
  60. package/dist/announcementBuildVersion.js +21 -0
  61. package/dist/announcementBuildVersion.js.map +1 -0
  62. package/dist/announcementFrequency.d.ts +42 -0
  63. package/dist/announcementFrequency.js +163 -0
  64. package/dist/announcementFrequency.js.map +1 -0
  65. package/dist/announcementPlatform.d.ts +2 -0
  66. package/dist/announcementPlatform.js +11 -0
  67. package/dist/announcementPlatform.js.map +1 -0
  68. package/dist/charts/ChartFrame.d.ts +12 -0
  69. package/dist/charts/ChartFrame.js +13 -0
  70. package/dist/charts/ChartFrame.js.map +1 -0
  71. package/dist/charts/bars.d.ts +18 -0
  72. package/dist/charts/bars.js +29 -0
  73. package/dist/charts/bars.js.map +1 -0
  74. package/dist/charts/layout.d.ts +47 -0
  75. package/dist/charts/layout.js +56 -0
  76. package/dist/charts/layout.js.map +1 -0
  77. package/dist/charts/paths.d.ts +31 -0
  78. package/dist/charts/paths.js +52 -0
  79. package/dist/charts/paths.js.map +1 -0
  80. package/dist/charts/scales.d.ts +6 -0
  81. package/dist/charts/scales.js +43 -0
  82. package/dist/charts/scales.js.map +1 -0
  83. package/dist/charts/theme.d.ts +9 -0
  84. package/dist/charts/theme.js +15 -0
  85. package/dist/charts/theme.js.map +1 -0
  86. package/dist/charts/types/chartTypes.d.ts +17 -0
  87. package/dist/charts/types/chartTypes.js +2 -0
  88. package/dist/charts/types/chartTypes.js.map +1 -0
  89. package/dist/dashboardGridLayout.d.ts +22 -0
  90. package/dist/dashboardGridLayout.js +33 -0
  91. package/dist/dashboardGridLayout.js.map +1 -0
  92. package/dist/dataTableFilters.d.ts +33 -0
  93. package/dist/dataTableFilters.js +221 -0
  94. package/dist/dataTableFilters.js.map +1 -0
  95. package/dist/dataTableListQuery.d.ts +42 -0
  96. package/dist/dataTableListQuery.js +161 -0
  97. package/dist/dataTableListQuery.js.map +1 -0
  98. package/dist/index.d.ts +18 -1
  99. package/dist/index.js +11 -1
  100. package/dist/index.js.map +1 -1
  101. package/dist/lazyBoundaries/heavyOptionalExports.d.ts +12 -0
  102. package/dist/lazyBoundaries/heavyOptionalExports.js +8 -0
  103. package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
  104. package/dist/markdownEmbeds.d.ts +6 -0
  105. package/dist/markdownEmbeds.js +59 -0
  106. package/dist/markdownEmbeds.js.map +1 -0
  107. package/dist/testing/resolveTestId.js +2 -1
  108. package/dist/testing/resolveTestId.js.map +1 -1
  109. package/dist/testing/types.d.ts +3 -0
  110. package/dist/textFieldOscillationGuard.d.ts +25 -0
  111. package/dist/textFieldOscillationGuard.js +41 -0
  112. package/dist/textFieldOscillationGuard.js.map +1 -0
  113. package/dist/useAcknowledgeAnnouncement.d.ts +71 -0
  114. package/dist/useAcknowledgeAnnouncement.js +94 -0
  115. package/dist/useAcknowledgeAnnouncement.js.map +1 -0
  116. package/dist/useAnnouncements.d.ts +73 -0
  117. package/dist/useAnnouncements.js +66 -0
  118. package/dist/useAnnouncements.js.map +1 -0
  119. package/package.json +7 -18
  120. package/src/AnnouncementBanner.test.tsx +267 -0
  121. package/src/AnnouncementBanner.tsx +128 -0
  122. package/src/AnnouncementNavigator.test.tsx +759 -0
  123. package/src/AnnouncementNavigator.tsx +287 -0
  124. package/src/AnnouncementScreen.test.tsx +97 -0
  125. package/src/AnnouncementScreen.tsx +70 -0
  126. package/src/AreaChart.test.tsx +68 -0
  127. package/src/AreaChart.tsx +194 -0
  128. package/src/BarChart.test.tsx +96 -0
  129. package/src/BarChart.tsx +208 -0
  130. package/src/Button.test.tsx +66 -0
  131. package/src/Button.tsx +17 -2
  132. package/src/Common.ts +95 -0
  133. package/src/ConsentNavigator.test.tsx +55 -0
  134. package/src/DashboardGrid.test.tsx +75 -0
  135. package/src/DashboardGrid.tsx +69 -0
  136. package/src/DataTable.test.tsx +296 -1
  137. package/src/DataTable.tsx +210 -18
  138. package/src/DonutChart.test.tsx +121 -0
  139. package/src/DonutChart.tsx +160 -0
  140. package/src/EmojiSelector.test.tsx +51 -0
  141. package/src/Field.test.tsx +18 -0
  142. package/src/Filter.test.tsx +25 -0
  143. package/src/Filter.tsx +38 -7
  144. package/src/GPTChat.test.tsx +107 -0
  145. package/src/GPTChat.tsx +176 -86
  146. package/src/LineChart.test.tsx +166 -0
  147. package/src/LineChart.tsx +190 -0
  148. package/src/MarkdownEmbed.test.tsx +34 -0
  149. package/src/MarkdownEmbed.tsx +43 -0
  150. package/src/MarkdownView.test.tsx +59 -2
  151. package/src/MarkdownView.tsx +51 -3
  152. package/src/Modal.test.tsx +107 -14
  153. package/src/Modal.tsx +20 -8
  154. package/src/ModalSheet.test.tsx +121 -9
  155. package/src/ModalSheet.tsx +46 -11
  156. package/src/MultiselectField.test.tsx +21 -0
  157. package/src/MultiselectField.tsx +11 -13
  158. package/src/NotificationBell.test.tsx +91 -0
  159. package/src/NotificationBell.tsx +77 -0
  160. package/src/NotificationInbox.test.tsx +130 -0
  161. package/src/NotificationInbox.tsx +144 -0
  162. package/src/NotificationPreferences.test.tsx +25 -0
  163. package/src/NotificationPreferences.tsx +75 -0
  164. package/src/RootImportRegression.test.tsx +20 -0
  165. package/src/TextField.test.tsx +421 -0
  166. package/src/TextField.tsx +121 -4
  167. package/src/__snapshots__/Field.test.tsx.snap +22 -0
  168. package/src/__snapshots__/ModalSheet.test.tsx.snap +4 -1
  169. package/src/__snapshots__/TextArea.test.tsx.snap +5 -5
  170. package/src/__snapshots__/TextField.test.tsx.snap +5 -5
  171. package/src/announcementBuildVersion.test.ts +43 -0
  172. package/src/announcementBuildVersion.ts +21 -0
  173. package/src/announcementFrequency.test.ts +245 -0
  174. package/src/announcementFrequency.ts +246 -0
  175. package/src/announcementPlatform.test.ts +27 -0
  176. package/src/announcementPlatform.ts +13 -0
  177. package/src/charts/ChartFrame.tsx +67 -0
  178. package/src/charts/bars.test.ts +56 -0
  179. package/src/charts/bars.ts +53 -0
  180. package/src/charts/layout.test.ts +80 -0
  181. package/src/charts/layout.ts +99 -0
  182. package/src/charts/paths.test.ts +79 -0
  183. package/src/charts/paths.ts +100 -0
  184. package/src/charts/scales.test.ts +59 -0
  185. package/src/charts/scales.ts +60 -0
  186. package/src/charts/theme.test.ts +22 -0
  187. package/src/charts/theme.ts +24 -0
  188. package/src/charts/types/chartTypes.ts +19 -0
  189. package/src/dashboardGridLayout.test.ts +90 -0
  190. package/src/dashboardGridLayout.ts +60 -0
  191. package/src/dataTableFilters.test.tsx +552 -0
  192. package/src/dataTableFilters.tsx +441 -0
  193. package/src/dataTableListQuery.test.ts +220 -0
  194. package/src/dataTableListQuery.ts +201 -0
  195. package/src/index.tsx +21 -1
  196. package/src/lazyBoundaries/heavyOptionalExports.tsx +28 -0
  197. package/src/login/__snapshots__/LoginScreen.test.tsx.snap +22 -0
  198. package/src/markdownEmbeds.test.ts +53 -0
  199. package/src/markdownEmbeds.ts +62 -0
  200. package/src/pdfHtmlTemplate.test.ts +119 -0
  201. package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +22 -0
  202. package/src/testing/resolveTestId.test.ts +3 -0
  203. package/src/testing/resolveTestId.ts +1 -0
  204. package/src/testing/types.ts +3 -0
  205. package/src/textFieldOscillationGuard.test.ts +63 -0
  206. package/src/textFieldOscillationGuard.ts +89 -0
  207. package/src/types/react-native-markdown-display.d.ts +6 -0
  208. package/src/types/react-native-swiper-flatlist.d.ts +5 -5
  209. package/src/useAcknowledgeAnnouncement.test.ts +223 -0
  210. package/src/useAcknowledgeAnnouncement.ts +166 -0
  211. package/src/useAnnouncements.test.ts +226 -0
  212. package/src/useAnnouncements.ts +150 -0
@@ -0,0 +1,194 @@
1
+ import type {FC} from "react";
2
+ import {useCallback, useState} from "react";
3
+ import {Circle, Path, Svg, Line as SvgLine} from "react-native-svg";
4
+
5
+ import {Box} from "./Box";
6
+ import type {AreaChartProps, LayoutChangeEvent} from "./Common";
7
+ import {ChartFrame} from "./charts/ChartFrame";
8
+ import {
9
+ CHART_X_AXIS_HEIGHT,
10
+ getChartAxisWidth,
11
+ getChartPlot,
12
+ getPlotHeight,
13
+ getXTickStyle,
14
+ getYTickStyle,
15
+ } from "./charts/layout";
16
+ import {getAreaPath, getLinePath} from "./charts/paths";
17
+ import {createCartesianScales, getYTickValues} from "./charts/scales";
18
+ import {getChartPaint} from "./charts/theme";
19
+ import type {ChartPoint} from "./charts/types/chartTypes";
20
+ import {Text} from "./Text";
21
+ import {useTheme} from "./Theme";
22
+ import {resolveTestID} from "./testing/resolveTestId";
23
+
24
+ const DEFAULT_HEIGHT = 200;
25
+ const DEFAULT_WIDTH = 300;
26
+ const MARK_HIT_SIZE = 24;
27
+
28
+ const formatChartTooltip = ({
29
+ formatValue,
30
+ point,
31
+ }: {
32
+ formatValue: (value: number) => string;
33
+ point: ChartPoint;
34
+ }): string => {
35
+ return `${point.label}: ${formatValue(point.value)}`;
36
+ };
37
+
38
+ export const AreaChart: FC<AreaChartProps> = ({
39
+ accessibilityLabel,
40
+ data,
41
+ emptyText = "No data",
42
+ formatValue = String,
43
+ height = DEFAULT_HEIGHT,
44
+ legendLabel,
45
+ loading = false,
46
+ testID,
47
+ }) => {
48
+ const {theme} = useTheme();
49
+ const paint = getChartPaint(theme);
50
+ const [chartWidth, setChartWidth] = useState(DEFAULT_WIDTH);
51
+ const [activePointIndex, setActivePointIndex] = useState<number | undefined>(undefined);
52
+
53
+ const handleLayout = useCallback((event: LayoutChangeEvent): void => {
54
+ const nextWidth = event.nativeEvent.layout.width;
55
+ if (nextWidth > 0) {
56
+ setChartWidth(nextWidth);
57
+ }
58
+ }, []);
59
+
60
+ const handleMarkPress = useCallback((pointIndex: number): void => {
61
+ setActivePointIndex(pointIndex);
62
+ }, []);
63
+
64
+ const axisWidth = getChartAxisWidth(chartWidth);
65
+ const plotHeight = getPlotHeight({hasLegend: Boolean(legendLabel), height});
66
+ const plot = getChartPlot({chartWidth, height: plotHeight});
67
+ const plotWidth = chartWidth - axisWidth;
68
+ const scales = createCartesianScales({plot, points: data});
69
+ const linePath = getLinePath({points: data, scales});
70
+ const areaPath = getAreaPath({baselineY: scales.y(0), points: data, scales});
71
+ const yTicks = getYTickValues(data);
72
+ const activePoint = activePointIndex === undefined ? undefined : data[activePointIndex];
73
+ const tooltipText = activePoint
74
+ ? formatChartTooltip({formatValue, point: activePoint})
75
+ : undefined;
76
+ const summaryLabel =
77
+ accessibilityLabel ?? (legendLabel ? `${legendLabel} area chart` : "Area chart");
78
+
79
+ return (
80
+ <ChartFrame
81
+ accessibilityLabel={summaryLabel}
82
+ emptyText={emptyText}
83
+ isEmpty={data.length === 0}
84
+ legendLabel={legendLabel}
85
+ loading={loading}
86
+ testID={testID}
87
+ tooltipText={tooltipText}
88
+ >
89
+ <Box minWidth={0} onLayout={handleLayout} testID={resolveTestID(testID, "plot")} width="100%">
90
+ <Box direction="row" height={plotHeight}>
91
+ <Box height={plotHeight} position="relative" width={axisWidth}>
92
+ {yTicks.map((tick) => (
93
+ <Box
94
+ dangerouslySetInlineStyle={{__style: getYTickStyle({axisWidth, y: scales.y(tick)})}}
95
+ key={`ytick-${tick}`}
96
+ >
97
+ <Text align="right" color="secondaryDark" size="sm" skipLinking truncate>
98
+ {formatValue(tick)}
99
+ </Text>
100
+ </Box>
101
+ ))}
102
+ </Box>
103
+ <Box flex="grow" height={plotHeight} minWidth={0} overflow="hidden" position="relative">
104
+ <Svg height={plotHeight} width={plotWidth}>
105
+ {yTicks.map((tick) => {
106
+ const y = scales.y(tick);
107
+ return (
108
+ <SvgLine
109
+ key={`grid-${tick}`}
110
+ stroke={paint.grid}
111
+ strokeWidth={1}
112
+ x1={plot.left}
113
+ x2={plot.left + plot.width}
114
+ y1={y}
115
+ y2={y}
116
+ />
117
+ );
118
+ })}
119
+ {areaPath ? (
120
+ <Path d={areaPath} fill={paint.seriesFill} fillOpacity={0.25} stroke="none" />
121
+ ) : null}
122
+ {linePath ? (
123
+ <Path d={linePath} fill="none" stroke={paint.series} strokeWidth={2} />
124
+ ) : null}
125
+ {data.map((point) => (
126
+ <Circle
127
+ cx={scales.xCenter(point.label)}
128
+ cy={scales.y(point.value)}
129
+ fill={paint.series}
130
+ key={`dot-${point.label}`}
131
+ r={4}
132
+ />
133
+ ))}
134
+ </Svg>
135
+ {data.map((point, index) => {
136
+ const onPress = (): void => {
137
+ handleMarkPress(index);
138
+ };
139
+ return (
140
+ <Box
141
+ accessibilityHint={`Show value for ${point.label}`}
142
+ accessibilityLabel={`${point.label}: ${formatValue(point.value)}`}
143
+ dangerouslySetInlineStyle={{
144
+ __style: {
145
+ height: MARK_HIT_SIZE,
146
+ left: scales.xCenter(point.label) - MARK_HIT_SIZE / 2,
147
+ position: "absolute",
148
+ top: scales.y(point.value) - MARK_HIT_SIZE / 2,
149
+ width: MARK_HIT_SIZE,
150
+ },
151
+ }}
152
+ key={`mark-${point.label}`}
153
+ onClick={onPress}
154
+ onHoverStart={onPress}
155
+ testID={resolveTestID(testID, `point.${index}`)}
156
+ />
157
+ );
158
+ })}
159
+ </Box>
160
+ </Box>
161
+ <Box direction="row">
162
+ <Box width={axisWidth} />
163
+ <Box
164
+ flex="grow"
165
+ height={CHART_X_AXIS_HEIGHT}
166
+ minWidth={0}
167
+ overflow="hidden"
168
+ position="relative"
169
+ >
170
+ {data.map((point, index) => (
171
+ <Box
172
+ dangerouslySetInlineStyle={{
173
+ __style: getXTickStyle({
174
+ bandwidth: scales.bandwidth,
175
+ xCenter: scales.xCenter(point.label),
176
+ }),
177
+ }}
178
+ key={`xtick-${point.label}`}
179
+ testID={resolveTestID(testID, `xtick.${index}`)}
180
+ >
181
+ <Text align="center" color="secondaryDark" size="sm" skipLinking truncate>
182
+ {point.label}
183
+ </Text>
184
+ </Box>
185
+ ))}
186
+ </Box>
187
+ </Box>
188
+ </Box>
189
+ </ChartFrame>
190
+ );
191
+ };
192
+
193
+ export type {AreaChartProps} from "./Common";
194
+ export type {ChartPoint} from "./charts/types/chartTypes";
@@ -0,0 +1,96 @@
1
+ import {describe, expect, it} from "bun:test";
2
+ import {act, fireEvent} from "@testing-library/react-native";
3
+
4
+ import {BarChart} from "./BarChart";
5
+ import {renderWithTheme} from "./test-utils";
6
+
7
+ const POINTS = [
8
+ {label: "A", value: 0},
9
+ {label: "B", value: 50},
10
+ {label: "C", value: 100},
11
+ ];
12
+
13
+ describe("BarChart", () => {
14
+ it("renders one mark testID per point", () => {
15
+ const {getByTestId, queryByTestId} = renderWithTheme(<BarChart data={POINTS} testID="chart" />);
16
+
17
+ expect(getByTestId("chart.point.0-clickable")).toBeTruthy();
18
+ expect(getByTestId("chart.point.1-clickable")).toBeTruthy();
19
+ expect(getByTestId("chart.point.2-clickable")).toBeTruthy();
20
+ expect(queryByTestId("chart.point.3-clickable")).toBeNull();
21
+ });
22
+
23
+ it("shows emptyText when data is empty", () => {
24
+ const {getByText} = renderWithTheme(<BarChart data={[]} emptyText="Nothing yet" />);
25
+
26
+ expect(getByText("Nothing yet")).toBeTruthy();
27
+ });
28
+
29
+ it("shows tooltip copy after pressing a mark", async () => {
30
+ const {getByTestId, getByText, queryByTestId} = renderWithTheme(
31
+ <BarChart data={POINTS} testID="chart" />
32
+ );
33
+
34
+ expect(queryByTestId("chart.tooltip")).toBeNull();
35
+
36
+ await act(async () => {
37
+ fireEvent.press(getByTestId("chart.point.1-clickable"));
38
+ });
39
+
40
+ expect(getByTestId("chart.tooltip")).toBeTruthy();
41
+ expect(getByText("B: 50")).toBeTruthy();
42
+ });
43
+
44
+ it("updates or clears the active tooltip when data changes", async () => {
45
+ const {getByTestId, getByText, queryByTestId, rerender} = renderWithTheme(
46
+ <BarChart data={POINTS} testID="chart" />
47
+ );
48
+
49
+ await act(async () => {
50
+ fireEvent.press(getByTestId("chart.point.1-clickable"));
51
+ });
52
+ rerender(
53
+ <BarChart
54
+ data={[
55
+ {label: "A", value: 0},
56
+ {label: "B", value: 75},
57
+ ]}
58
+ testID="chart"
59
+ />
60
+ );
61
+ expect(getByText("B: 75")).toBeTruthy();
62
+
63
+ rerender(<BarChart data={[{label: "A", value: 0}]} testID="chart" />);
64
+ expect(queryByTestId("chart.tooltip")).toBeNull();
65
+ });
66
+
67
+ it("shows tooltip copy after pressing a zero-value bar", async () => {
68
+ const {getByTestId, getByText} = renderWithTheme(<BarChart data={POINTS} testID="chart" />);
69
+
70
+ await act(async () => {
71
+ fireEvent.press(getByTestId("chart.point.0-clickable"));
72
+ });
73
+
74
+ expect(getByTestId("chart.tooltip")).toBeTruthy();
75
+ expect(getByText("A: 0")).toBeTruthy();
76
+ });
77
+
78
+ it("shows tooltip copy after pressing a negative-value bar", async () => {
79
+ const {getByTestId, getByText} = renderWithTheme(
80
+ <BarChart
81
+ data={[
82
+ {label: "Loss", value: -20},
83
+ {label: "Gain", value: 10},
84
+ ]}
85
+ testID="chart"
86
+ />
87
+ );
88
+
89
+ await act(async () => {
90
+ fireEvent.press(getByTestId("chart.point.0-clickable"));
91
+ });
92
+
93
+ expect(getByTestId("chart.tooltip")).toBeTruthy();
94
+ expect(getByText("Loss: -20")).toBeTruthy();
95
+ });
96
+ });
@@ -0,0 +1,208 @@
1
+ import type {FC} from "react";
2
+ import {useCallback, useState} from "react";
3
+ import {Rect, Svg, Line as SvgLine} from "react-native-svg";
4
+
5
+ import {Box} from "./Box";
6
+ import type {BarChartProps, LayoutChangeEvent} from "./Common";
7
+ import {getBarLayout} from "./charts/bars";
8
+ import {ChartFrame} from "./charts/ChartFrame";
9
+ import {
10
+ CHART_X_AXIS_HEIGHT,
11
+ getChartAxisWidth,
12
+ getChartPlot,
13
+ getPlotHeight,
14
+ getXTickStyle,
15
+ getYTickStyle,
16
+ } from "./charts/layout";
17
+ import {createCartesianScales, getYTickValues} from "./charts/scales";
18
+ import {getChartPaint} from "./charts/theme";
19
+ import type {ChartPoint} from "./charts/types/chartTypes";
20
+ import {Text} from "./Text";
21
+ import {useTheme} from "./Theme";
22
+ import {resolveTestID} from "./testing/resolveTestId";
23
+
24
+ const DEFAULT_HEIGHT = 200;
25
+ const DEFAULT_WIDTH = 300;
26
+ const BAR_FILL = 0.7;
27
+
28
+ const formatChartTooltip = ({
29
+ formatValue,
30
+ point,
31
+ }: {
32
+ formatValue: (value: number) => string;
33
+ point: ChartPoint;
34
+ }): string => {
35
+ return `${point.label}: ${formatValue(point.value)}`;
36
+ };
37
+
38
+ export const BarChart: FC<BarChartProps> = ({
39
+ accessibilityLabel,
40
+ data,
41
+ emptyText = "No data",
42
+ formatValue = String,
43
+ height = DEFAULT_HEIGHT,
44
+ legendLabel,
45
+ loading = false,
46
+ testID,
47
+ }) => {
48
+ const {theme} = useTheme();
49
+ const paint = getChartPaint(theme);
50
+ const [chartWidth, setChartWidth] = useState(DEFAULT_WIDTH);
51
+ const [activePointIndex, setActivePointIndex] = useState<number | undefined>(undefined);
52
+
53
+ const handleLayout = useCallback((event: LayoutChangeEvent): void => {
54
+ const nextWidth = event.nativeEvent.layout.width;
55
+ if (nextWidth > 0) {
56
+ setChartWidth(nextWidth);
57
+ }
58
+ }, []);
59
+
60
+ const handleMarkPress = useCallback((pointIndex: number): void => {
61
+ setActivePointIndex(pointIndex);
62
+ }, []);
63
+
64
+ const axisWidth = getChartAxisWidth(chartWidth);
65
+ const plotHeight = getPlotHeight({hasLegend: Boolean(legendLabel), height});
66
+ const plot = getChartPlot({chartWidth, height: plotHeight});
67
+ const plotWidth = chartWidth - axisWidth;
68
+ const scales = createCartesianScales({plot, points: data});
69
+ const yTicks = getYTickValues(data);
70
+ const baselineY = scales.y(0);
71
+ const barWidth = Math.max(scales.bandwidth * BAR_FILL, 1);
72
+ const activePoint = activePointIndex === undefined ? undefined : data[activePointIndex];
73
+ const tooltipText = activePoint
74
+ ? formatChartTooltip({formatValue, point: activePoint})
75
+ : undefined;
76
+ const summaryLabel =
77
+ accessibilityLabel ?? (legendLabel ? `${legendLabel} bar chart` : "Bar chart");
78
+
79
+ return (
80
+ <ChartFrame
81
+ accessibilityLabel={summaryLabel}
82
+ emptyText={emptyText}
83
+ isEmpty={data.length === 0}
84
+ legendLabel={legendLabel}
85
+ loading={loading}
86
+ testID={testID}
87
+ tooltipText={tooltipText}
88
+ >
89
+ <Box minWidth={0} onLayout={handleLayout} testID={resolveTestID(testID, "plot")} width="100%">
90
+ <Box direction="row" height={plotHeight}>
91
+ <Box height={plotHeight} position="relative" width={axisWidth}>
92
+ {yTicks.map((tick) => (
93
+ <Box
94
+ dangerouslySetInlineStyle={{__style: getYTickStyle({axisWidth, y: scales.y(tick)})}}
95
+ key={`ytick-${tick}`}
96
+ >
97
+ <Text align="right" color="secondaryDark" size="sm" skipLinking truncate>
98
+ {formatValue(tick)}
99
+ </Text>
100
+ </Box>
101
+ ))}
102
+ </Box>
103
+ <Box flex="grow" height={plotHeight} minWidth={0} overflow="hidden" position="relative">
104
+ <Svg height={plotHeight} width={plotWidth}>
105
+ {yTicks.map((tick) => {
106
+ const y = scales.y(tick);
107
+ return (
108
+ <SvgLine
109
+ key={`grid-${tick}`}
110
+ stroke={paint.grid}
111
+ strokeWidth={1}
112
+ x1={plot.left}
113
+ x2={plot.left + plot.width}
114
+ y1={y}
115
+ y2={y}
116
+ />
117
+ );
118
+ })}
119
+ {data.map((point) => {
120
+ const layout = getBarLayout({
121
+ barWidth,
122
+ baselineY,
123
+ value: point.value,
124
+ xCenter: scales.xCenter(point.label),
125
+ y: scales.y,
126
+ });
127
+ if (layout.height === 0) {
128
+ return null;
129
+ }
130
+ return (
131
+ <Rect
132
+ fill={point.color ?? paint.series}
133
+ height={layout.height}
134
+ key={`bar-${point.label}`}
135
+ width={layout.width}
136
+ x={layout.x}
137
+ y={layout.y}
138
+ />
139
+ );
140
+ })}
141
+ </Svg>
142
+ {data.map((point, index) => {
143
+ const onPress = (): void => {
144
+ handleMarkPress(index);
145
+ };
146
+ const layout = getBarLayout({
147
+ barWidth,
148
+ baselineY,
149
+ value: point.value,
150
+ xCenter: scales.xCenter(point.label),
151
+ y: scales.y,
152
+ });
153
+ return (
154
+ <Box
155
+ accessibilityHint={`Show value for ${point.label}`}
156
+ accessibilityLabel={`${point.label}: ${formatValue(point.value)}`}
157
+ dangerouslySetInlineStyle={{
158
+ __style: {
159
+ height: layout.hitHeight,
160
+ left: layout.hitX,
161
+ position: "absolute",
162
+ top: layout.hitY,
163
+ width: layout.hitWidth,
164
+ },
165
+ }}
166
+ key={`mark-${point.label}`}
167
+ onClick={onPress}
168
+ onHoverStart={onPress}
169
+ testID={resolveTestID(testID, `point.${index}`)}
170
+ />
171
+ );
172
+ })}
173
+ </Box>
174
+ </Box>
175
+ <Box direction="row">
176
+ <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) => (
185
+ <Box
186
+ dangerouslySetInlineStyle={{
187
+ __style: getXTickStyle({
188
+ bandwidth: scales.bandwidth,
189
+ xCenter: scales.xCenter(point.label),
190
+ }),
191
+ }}
192
+ key={`xtick-${point.label}`}
193
+ testID={resolveTestID(testID, `xtick.${index}`)}
194
+ >
195
+ <Text align="center" color="secondaryDark" size="sm" skipLinking truncate>
196
+ {point.label}
197
+ </Text>
198
+ </Box>
199
+ ))}
200
+ </Box>
201
+ </Box>
202
+ </Box>
203
+ </ChartFrame>
204
+ );
205
+ };
206
+
207
+ export type {BarChartProps} from "./Common";
208
+ export type {ChartPoint} from "./charts/types/chartTypes";
@@ -3,12 +3,25 @@ import {act, fireEvent, render, waitFor} from "@testing-library/react-native";
3
3
  import {assert} from "chai";
4
4
 
5
5
  import {Button} from "./Button";
6
+ import type {ButtonProps} from "./Common";
6
7
  import {isMobileDevice} from "./MediaQuery";
7
8
  import * as ThemeModule from "./Theme";
8
9
  import {renderWithIcons, renderWithTheme, TEST_CUSTOM_ICON_TEST_ID} from "./test-utils";
9
10
  import {Unifier} from "./Unifier";
10
11
  import * as Utilities from "./Utilities";
11
12
 
13
+ const ACTIVE_BUTTON_VARIANTS: {
14
+ backgroundColor: string;
15
+ variant: NonNullable<ButtonProps["variant"]>;
16
+ }[] = [
17
+ {backgroundColor: "#2B6072", variant: "primary"},
18
+ {backgroundColor: "#0E9DCD", variant: "secondary"},
19
+ {backgroundColor: "#0E9DCD", variant: "muted"},
20
+ {backgroundColor: "#0E9DCD", variant: "outline"},
21
+ {backgroundColor: "#BD1111", variant: "destructive"},
22
+ {backgroundColor: "#0E9DCD", variant: "ghost"},
23
+ ];
24
+
12
25
  interface PressableTestProps {
13
26
  onPress: () => Promise<void>;
14
27
  }
@@ -36,6 +49,13 @@ describe("Button", () => {
36
49
  expect(getByTestId("test-button")).toBeTruthy();
37
50
  });
38
51
 
52
+ it("supports an accessible name distinct from visible text", () => {
53
+ const {getByTestId} = renderWithTheme(
54
+ <Button accessibilityLabel="Filter Name" onClick={() => {}} testID="filter-button" text="" />
55
+ );
56
+ expect(getByTestId("filter-button").props.accessibilityLabel).toBe("Filter Name");
57
+ });
58
+
39
59
  // Variant tests
40
60
  it("renders primary variant", () => {
41
61
  const {toJSON} = renderWithTheme(
@@ -70,6 +90,52 @@ describe("Button", () => {
70
90
  expect(toJSON()).toMatchSnapshot();
71
91
  });
72
92
 
93
+ for (const {backgroundColor, variant} of ACTIVE_BUTTON_VARIANTS) {
94
+ it(`renders ${variant} variant in active state`, () => {
95
+ const {getByTestId, getByText} = renderWithTheme(
96
+ <Button
97
+ onClick={() => {}}
98
+ state="active"
99
+ testID={`${variant}-active`}
100
+ text={`${variant} active`}
101
+ variant={variant}
102
+ />
103
+ );
104
+
105
+ expect(getByTestId(`${variant}-active`)).toHaveStyle({backgroundColor});
106
+ expect(getByText(`${variant} active`)).toHaveStyle({color: "#FFFFFF"});
107
+ });
108
+ }
109
+
110
+ it("removes the outline border in active state", () => {
111
+ const {getByTestId} = renderWithTheme(
112
+ <Button
113
+ onClick={() => {}}
114
+ state="active"
115
+ testID="outline-active"
116
+ text="Outline active"
117
+ variant="outline"
118
+ />
119
+ );
120
+
121
+ expect(getByTestId("outline-active").props.style.borderColor).toBeUndefined();
122
+ expect(getByTestId("outline-active").props.style.borderWidth).toBeUndefined();
123
+ });
124
+
125
+ it("keeps disabled styling when state is active", () => {
126
+ const {getByTestId} = renderWithTheme(
127
+ <Button
128
+ disabled
129
+ onClick={() => {}}
130
+ state="active"
131
+ testID="disabled-active"
132
+ text="Disabled active"
133
+ />
134
+ );
135
+
136
+ expect(getByTestId("disabled-active")).toHaveStyle({backgroundColor: "#9A9A9A"});
137
+ });
138
+
73
139
  it("defaults to scale press animation", () => {
74
140
  const tree = renderWithTheme(<Button onClick={() => {}} text="Default animation" />).toJSON();
75
141
  expect(Array.isArray(tree)).toBe(false);
package/src/Button.tsx CHANGED
@@ -80,6 +80,7 @@ const useMountedRef = (): React.RefObject<boolean> => {
80
80
  };
81
81
 
82
82
  const ButtonVisual: React.FC<ButtonVisualProps> = ({
83
+ accessibilityLabel,
83
84
  children,
84
85
  disabled = false,
85
86
  fullWidth = false,
@@ -89,6 +90,7 @@ const ButtonVisual: React.FC<ButtonVisualProps> = ({
89
90
  onPress,
90
91
  pressAnimation = DEFAULT_BUTTON_PRESS_ANIMATION,
91
92
  size = "default",
93
+ state = "default",
92
94
  testID,
93
95
  text,
94
96
  variant = "primary",
@@ -125,13 +127,26 @@ const ButtonVisual: React.FC<ButtonVisualProps> = ({
125
127
  textColor = theme.surface.secondaryDark;
126
128
  }
127
129
 
130
+ if (!disabled && state === "active") {
131
+ if (variant === "primary") {
132
+ bgColor = theme.surface.secondaryDark;
133
+ } else if (variant === "destructive") {
134
+ bgColor = theme.surface.error;
135
+ } else {
136
+ bgColor = theme.surface.primary;
137
+ }
138
+ bColor = undefined;
139
+ bWidth = undefined;
140
+ textColor = theme.surface.base;
141
+ }
142
+
128
143
  return {
129
144
  backgroundColor: bgColor,
130
145
  borderColor: bColor,
131
146
  borderWidth: bWidth,
132
147
  color: textColor,
133
148
  };
134
- }, [disabled, variant, theme]);
149
+ }, [disabled, state, variant, theme]);
135
150
 
136
151
  if (!theme) {
137
152
  return null;
@@ -148,7 +163,7 @@ const ButtonVisual: React.FC<ButtonVisualProps> = ({
148
163
  accessibilityHint={
149
164
  withConfirmation ? "Opens a confirmation dialog" : "Press to perform action"
150
165
  }
151
- accessibilityLabel={text}
166
+ accessibilityLabel={accessibilityLabel ?? text}
152
167
  accessibilityRole="button"
153
168
  accessibilityState={{disabled: isPressDisabled}}
154
169
  {...pressableInteractionProps}