@terreno/ui 57.8.0 → 57.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (269) hide show
  1. package/README.md +2 -0
  2. package/dist/AreaChart.d.ts +1 -1
  3. package/dist/AreaChart.d.ts.map +1 -1
  4. package/dist/AreaChart.js +70 -22
  5. package/dist/AreaChart.js.map +1 -1
  6. package/dist/BarChart.d.ts.map +1 -1
  7. package/dist/BarChart.js +55 -13
  8. package/dist/BarChart.js.map +1 -1
  9. package/dist/Button.d.ts.map +1 -1
  10. package/dist/Button.js +19 -4
  11. package/dist/Button.js.map +1 -1
  12. package/dist/ChartCard.d.ts +5 -0
  13. package/dist/ChartCard.d.ts.map +1 -0
  14. package/dist/ChartCard.js +18 -0
  15. package/dist/ChartCard.js.map +1 -0
  16. package/dist/Common.d.ts +147 -6
  17. package/dist/Common.d.ts.map +1 -1
  18. package/dist/Common.js.map +1 -1
  19. package/dist/DashboardGrid.d.ts +6 -2
  20. package/dist/DashboardGrid.d.ts.map +1 -1
  21. package/dist/DashboardGrid.js +43 -10
  22. package/dist/DashboardGrid.js.map +1 -1
  23. package/dist/DateTimeField.d.ts.map +1 -1
  24. package/dist/DateTimeField.js +90 -17
  25. package/dist/DateTimeField.js.map +1 -1
  26. package/dist/DonutChart.d.ts.map +1 -1
  27. package/dist/DonutChart.js +20 -10
  28. package/dist/DonutChart.js.map +1 -1
  29. package/dist/DropdownMenuItem.d.ts +16 -0
  30. package/dist/DropdownMenuItem.d.ts.map +1 -0
  31. package/dist/DropdownMenuItem.js +11 -0
  32. package/dist/DropdownMenuItem.js.map +1 -0
  33. package/dist/FilePickerButton.d.ts +15 -1
  34. package/dist/FilePickerButton.d.ts.map +1 -1
  35. package/dist/FilePickerButton.js +90 -13
  36. package/dist/FilePickerButton.js.map +1 -1
  37. package/dist/GPTChat.d.ts +57 -1
  38. package/dist/GPTChat.d.ts.map +1 -1
  39. package/dist/GPTChat.js +301 -20
  40. package/dist/GPTChat.js.map +1 -1
  41. package/dist/HtmlFrame.d.ts +11 -0
  42. package/dist/HtmlFrame.d.ts.map +1 -0
  43. package/dist/HtmlFrame.js +29 -0
  44. package/dist/HtmlFrame.js.map +1 -0
  45. package/dist/LineChart.d.ts +1 -1
  46. package/dist/LineChart.d.ts.map +1 -1
  47. package/dist/LineChart.js +62 -21
  48. package/dist/LineChart.js.map +1 -1
  49. package/dist/Scorecard.d.ts +5 -0
  50. package/dist/Scorecard.d.ts.map +1 -0
  51. package/dist/Scorecard.js +11 -0
  52. package/dist/Scorecard.js.map +1 -0
  53. package/dist/SparklineChart.d.ts +5 -0
  54. package/dist/SparklineChart.d.ts.map +1 -0
  55. package/dist/SparklineChart.js +35 -0
  56. package/dist/SparklineChart.js.map +1 -0
  57. package/dist/Text.d.ts +1 -1
  58. package/dist/Text.d.ts.map +1 -1
  59. package/dist/Text.js +2 -2
  60. package/dist/Text.js.map +1 -1
  61. package/dist/TextField.d.ts.map +1 -1
  62. package/dist/TextField.js +12 -4
  63. package/dist/TextField.js.map +1 -1
  64. package/dist/ToastNotifications.d.ts.map +1 -1
  65. package/dist/ToastNotifications.js +29 -6
  66. package/dist/ToastNotifications.js.map +1 -1
  67. package/dist/WebDropdownMenu.d.ts +2 -1
  68. package/dist/WebDropdownMenu.d.ts.map +1 -1
  69. package/dist/WebDropdownMenu.js +2 -6
  70. package/dist/WebDropdownMenu.js.map +1 -1
  71. package/dist/asks/AskCard.d.ts +34 -0
  72. package/dist/asks/AskCard.d.ts.map +1 -0
  73. package/dist/asks/AskCard.js +91 -0
  74. package/dist/asks/AskCard.js.map +1 -0
  75. package/dist/asks/AskChoice.d.ts +11 -0
  76. package/dist/asks/AskChoice.d.ts.map +1 -0
  77. package/dist/asks/AskChoice.js +146 -0
  78. package/dist/asks/AskChoice.js.map +1 -0
  79. package/dist/asks/AskConfirm.d.ts +15 -0
  80. package/dist/asks/AskConfirm.d.ts.map +1 -0
  81. package/dist/asks/AskConfirm.js +17 -0
  82. package/dist/asks/AskConfirm.js.map +1 -0
  83. package/dist/asks/AskFiles.d.ts +18 -0
  84. package/dist/asks/AskFiles.d.ts.map +1 -0
  85. package/dist/asks/AskFiles.js +149 -0
  86. package/dist/asks/AskFiles.js.map +1 -0
  87. package/dist/asks/AskForm.d.ts +27 -0
  88. package/dist/asks/AskForm.d.ts.map +1 -0
  89. package/dist/asks/AskForm.js +146 -0
  90. package/dist/asks/AskForm.js.map +1 -0
  91. package/dist/asks/AskMarkdown.d.ts +25 -0
  92. package/dist/asks/AskMarkdown.d.ts.map +1 -0
  93. package/dist/asks/AskMarkdown.js +73 -0
  94. package/dist/asks/AskMarkdown.js.map +1 -0
  95. package/dist/asks/SimpleAskCard.d.ts +23 -0
  96. package/dist/asks/SimpleAskCard.d.ts.map +1 -0
  97. package/dist/asks/SimpleAskCard.js +32 -0
  98. package/dist/asks/SimpleAskCard.js.map +1 -0
  99. package/dist/asks/askControls.d.ts +33 -0
  100. package/dist/asks/askControls.d.ts.map +1 -0
  101. package/dist/asks/askControls.js +30 -0
  102. package/dist/asks/askControls.js.map +1 -0
  103. package/dist/asks/askFileRefs.d.ts +26 -0
  104. package/dist/asks/askFileRefs.d.ts.map +1 -0
  105. package/dist/asks/askFileRefs.js +75 -0
  106. package/dist/asks/askFileRefs.js.map +1 -0
  107. package/dist/asks/askFormDraft.d.ts +60 -0
  108. package/dist/asks/askFormDraft.d.ts.map +1 -0
  109. package/dist/asks/askFormDraft.js +224 -0
  110. package/dist/asks/askFormDraft.js.map +1 -0
  111. package/dist/asks/askSummary.d.ts +10 -0
  112. package/dist/asks/askSummary.d.ts.map +1 -0
  113. package/dist/asks/askSummary.js +138 -0
  114. package/dist/asks/askSummary.js.map +1 -0
  115. package/dist/asks/askTypes.d.ts +21 -0
  116. package/dist/asks/askTypes.d.ts.map +1 -0
  117. package/dist/asks/askTypes.js +2 -0
  118. package/dist/asks/askTypes.js.map +1 -0
  119. package/dist/asks/simpleCardButtonVariants.d.ts +5 -0
  120. package/dist/asks/simpleCardButtonVariants.d.ts.map +1 -0
  121. package/dist/asks/simpleCardButtonVariants.js +8 -0
  122. package/dist/asks/simpleCardButtonVariants.js.map +1 -0
  123. package/dist/blocks/BlocksError.d.ts +8 -0
  124. package/dist/blocks/BlocksError.d.ts.map +1 -0
  125. package/dist/blocks/BlocksError.js +14 -0
  126. package/dist/blocks/BlocksError.js.map +1 -0
  127. package/dist/blocks/BlocksView.d.ts +10 -0
  128. package/dist/blocks/BlocksView.d.ts.map +1 -0
  129. package/dist/blocks/BlocksView.js +90 -0
  130. package/dist/blocks/BlocksView.js.map +1 -0
  131. package/dist/blocks/blockRenderers.d.ts +25 -0
  132. package/dist/blocks/blockRenderers.d.ts.map +1 -0
  133. package/dist/blocks/blockRenderers.js +136 -0
  134. package/dist/blocks/blockRenderers.js.map +1 -0
  135. package/dist/blocks/datasetToPoints.d.ts +22 -0
  136. package/dist/blocks/datasetToPoints.d.ts.map +1 -0
  137. package/dist/blocks/datasetToPoints.js +28 -0
  138. package/dist/blocks/datasetToPoints.js.map +1 -0
  139. package/dist/blocks/useBlockSelections.d.ts +6 -0
  140. package/dist/blocks/useBlockSelections.d.ts.map +1 -0
  141. package/dist/blocks/useBlockSelections.js +10 -0
  142. package/dist/blocks/useBlockSelections.js.map +1 -0
  143. package/dist/blocks/useResolvedDatasets.d.ts +18 -0
  144. package/dist/blocks/useResolvedDatasets.d.ts.map +1 -0
  145. package/dist/blocks/useResolvedDatasets.js +59 -0
  146. package/dist/blocks/useResolvedDatasets.js.map +1 -0
  147. package/dist/blocks/useResolvedImages.d.ts +15 -0
  148. package/dist/blocks/useResolvedImages.d.ts.map +1 -0
  149. package/dist/blocks/useResolvedImages.js +66 -0
  150. package/dist/blocks/useResolvedImages.js.map +1 -0
  151. package/dist/charts/ChartFacadeContainer.d.ts +10 -0
  152. package/dist/charts/ChartFacadeContainer.d.ts.map +1 -0
  153. package/dist/charts/ChartFacadeContainer.js +10 -0
  154. package/dist/charts/ChartFacadeContainer.js.map +1 -0
  155. package/dist/charts/ChartFrame.d.ts +4 -0
  156. package/dist/charts/ChartFrame.d.ts.map +1 -1
  157. package/dist/charts/ChartFrame.js +4 -2
  158. package/dist/charts/ChartFrame.js.map +1 -1
  159. package/dist/charts/layout.d.ts +9 -2
  160. package/dist/charts/layout.d.ts.map +1 -1
  161. package/dist/charts/layout.js +28 -6
  162. package/dist/charts/layout.js.map +1 -1
  163. package/dist/charts/scales.d.ts +3 -1
  164. package/dist/charts/scales.d.ts.map +1 -1
  165. package/dist/charts/scales.js +7 -7
  166. package/dist/charts/scales.js.map +1 -1
  167. package/dist/charts/series.d.ts +15 -0
  168. package/dist/charts/series.d.ts.map +1 -0
  169. package/dist/charts/series.js +19 -0
  170. package/dist/charts/series.js.map +1 -0
  171. package/dist/charts/types/chartTypes.d.ts +7 -0
  172. package/dist/charts/types/chartTypes.d.ts.map +1 -1
  173. package/dist/dashboardGridLayout.d.ts +6 -0
  174. package/dist/dashboardGridLayout.d.ts.map +1 -1
  175. package/dist/dashboardGridLayout.js +19 -3
  176. package/dist/dashboardGridLayout.js.map +1 -1
  177. package/dist/index.d.ts +9 -1
  178. package/dist/index.d.ts.map +1 -1
  179. package/dist/index.js +4 -1
  180. package/dist/index.js.map +1 -1
  181. package/dist/lazyBoundaries/heavyOptionalExports.d.ts +15 -0
  182. package/dist/lazyBoundaries/heavyOptionalExports.d.ts.map +1 -1
  183. package/dist/lazyBoundaries/heavyOptionalExports.js +10 -0
  184. package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
  185. package/dist/resolveDocumentBodyPortalTarget.d.ts +7 -0
  186. package/dist/resolveDocumentBodyPortalTarget.d.ts.map +1 -0
  187. package/dist/resolveDocumentBodyPortalTarget.js +12 -0
  188. package/dist/resolveDocumentBodyPortalTarget.js.map +1 -0
  189. package/package.json +2 -1
  190. package/src/AIRequestExplorer.test.tsx +2 -2
  191. package/src/AreaChart.test.tsx +81 -0
  192. package/src/AreaChart.tsx +171 -62
  193. package/src/BarChart.test.tsx +119 -0
  194. package/src/BarChart.tsx +94 -20
  195. package/src/Button.test.tsx +72 -0
  196. package/src/Button.tsx +34 -4
  197. package/src/ChartCard.test.tsx +79 -0
  198. package/src/ChartCard.tsx +80 -0
  199. package/src/Common.ts +136 -2
  200. package/src/DashboardGrid.test.tsx +98 -1
  201. package/src/DashboardGrid.tsx +71 -20
  202. package/src/DateTimeField.test.tsx +185 -2
  203. package/src/DateTimeField.tsx +106 -16
  204. package/src/DonutChart.test.tsx +78 -10
  205. package/src/DonutChart.tsx +87 -14
  206. package/src/DropdownMenuItem.tsx +48 -0
  207. package/src/FilePickerButton.test.tsx +116 -9
  208. package/src/FilePickerButton.tsx +177 -23
  209. package/src/GPTChat.test.tsx +891 -8
  210. package/src/GPTChat.tsx +713 -45
  211. package/src/HtmlFrame.tsx +60 -0
  212. package/src/LineChart.test.tsx +109 -10
  213. package/src/LineChart.tsx +154 -58
  214. package/src/Scorecard.test.tsx +65 -0
  215. package/src/Scorecard.tsx +45 -0
  216. package/src/SparklineChart.test.tsx +69 -0
  217. package/src/SparklineChart.tsx +85 -0
  218. package/src/Text.test.tsx +22 -0
  219. package/src/Text.tsx +10 -1
  220. package/src/TextField.test.tsx +16 -0
  221. package/src/TextField.tsx +13 -3
  222. package/src/ToastNotifications.tsx +33 -6
  223. package/src/ToastNotifications.webModal.test.tsx +285 -0
  224. package/src/WebDropdownMenu.tsx +3 -7
  225. package/src/asks/AskCard.test.tsx +1428 -0
  226. package/src/asks/AskCard.tsx +240 -0
  227. package/src/asks/AskChoice.tsx +368 -0
  228. package/src/asks/AskConfirm.tsx +42 -0
  229. package/src/asks/AskFiles.test.tsx +347 -0
  230. package/src/asks/AskFiles.tsx +246 -0
  231. package/src/asks/AskForm.tsx +334 -0
  232. package/src/asks/AskMarkdown.tsx +176 -0
  233. package/src/asks/SimpleAskCard.test.tsx +253 -0
  234. package/src/asks/SimpleAskCard.tsx +82 -0
  235. package/src/asks/askControls.tsx +98 -0
  236. package/src/asks/askFileRefs.test.ts +155 -0
  237. package/src/asks/askFileRefs.ts +98 -0
  238. package/src/asks/askFormDraft.test.ts +347 -0
  239. package/src/asks/askFormDraft.ts +309 -0
  240. package/src/asks/askSummary.test.ts +255 -0
  241. package/src/asks/askSummary.ts +160 -0
  242. package/src/asks/askTypes.ts +25 -0
  243. package/src/asks/asksUseTerrenoComponents.test.ts +55 -0
  244. package/src/asks/simpleCardButtonVariants.ts +14 -0
  245. package/src/blocks/BlocksError.tsx +28 -0
  246. package/src/blocks/BlocksView.test.tsx +607 -0
  247. package/src/blocks/BlocksView.tsx +125 -0
  248. package/src/blocks/blockRenderers.tsx +288 -0
  249. package/src/blocks/datasetToPoints.test.ts +31 -0
  250. package/src/blocks/datasetToPoints.ts +48 -0
  251. package/src/blocks/useBlockSelections.ts +13 -0
  252. package/src/blocks/useResolvedDatasets.ts +78 -0
  253. package/src/blocks/useResolvedImages.ts +81 -0
  254. package/src/bunSetup.ts +1 -0
  255. package/src/charts/ChartFacadeContainer.tsx +35 -0
  256. package/src/charts/ChartFrame.tsx +39 -1
  257. package/src/charts/layout.test.ts +22 -1
  258. package/src/charts/layout.ts +37 -4
  259. package/src/charts/scales.test.ts +33 -0
  260. package/src/charts/scales.ts +10 -6
  261. package/src/charts/series.ts +43 -0
  262. package/src/charts/types/chartTypes.ts +8 -0
  263. package/src/dashboardGridLayout.test.ts +59 -1
  264. package/src/dashboardGridLayout.ts +30 -3
  265. package/src/index.tsx +13 -0
  266. package/src/isolated/HtmlFrame.isolated.tsx +54 -0
  267. package/src/lazyBoundaries/heavyOptionalExports.test.tsx +2 -0
  268. package/src/lazyBoundaries/heavyOptionalExports.tsx +35 -0
  269. package/src/resolveDocumentBodyPortalTarget.ts +11 -0
@@ -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";
package/src/Text.test.tsx CHANGED
@@ -1,6 +1,10 @@
1
1
  import {describe, expect, it, spyOn} from "bun:test";
2
+ import {render} from "@testing-library/react-native";
3
+ import {createRef} from "react";
4
+ import type {Text as NativeText} from "react-native";
2
5
 
3
6
  import {Text} from "./Text";
7
+ import {ThemeProvider} from "./Theme";
4
8
  import {renderWithTheme} from "./test-utils";
5
9
 
6
10
  describe("Text", () => {
@@ -164,6 +168,24 @@ describe("Text", () => {
164
168
  expect(getByTestId("test-text")).toBeTruthy();
165
169
  });
166
170
 
171
+ it("marks a header for screen readers and exposes its native text to a ref", () => {
172
+ const ref = createRef<NativeText>();
173
+ const nativeText = {focus: (): void => {}};
174
+ const {getByRole} = render(
175
+ <Text accessibilityRole="header" ref={ref}>
176
+ Which plan?
177
+ </Text>,
178
+ {
179
+ createNodeMock: (element) =>
180
+ element.props.accessibilityRole === "header" ? nativeText : null,
181
+ wrapper: ThemeProvider,
182
+ }
183
+ );
184
+
185
+ expect(getByRole("header", {name: "Which plan?"})).toBeTruthy();
186
+ expect(ref.current).toBe(nativeText as unknown as NativeText);
187
+ });
188
+
167
189
  // Combined style tests
168
190
  it("renders with multiple style props", () => {
169
191
  const {toJSON} = renderWithTheme(
package/src/Text.tsx CHANGED
@@ -25,6 +25,7 @@ const fontSizeAndWeighMobile = {
25
25
  const fontSizes = Platform.OS === "web" ? fontSizeAndWeightWeb : fontSizeAndWeighMobile;
26
26
 
27
27
  const TextComponent = ({
28
+ accessibilityRole,
28
29
  align = "left",
29
30
  bold,
30
31
  children,
@@ -34,6 +35,7 @@ const TextComponent = ({
34
35
  truncate = false,
35
36
  underline,
36
37
  numberOfLines,
38
+ ref,
37
39
  skipLinking,
38
40
  testID,
39
41
  }: TextProps): React.ReactElement => {
@@ -93,7 +95,14 @@ const TextComponent = ({
93
95
  lines = 1;
94
96
  }
95
97
  const inner = (
96
- <NativeText numberOfLines={lines} selectable={undefined} style={style} testID={testID}>
98
+ <NativeText
99
+ numberOfLines={lines}
100
+ selectable={undefined}
101
+ style={style}
102
+ testID={testID}
103
+ {...(accessibilityRole ? {accessibilityRole} : {})}
104
+ {...(ref ? {ref} : {})}
105
+ >
97
106
  {children}
98
107
  </NativeText>
99
108
  );
@@ -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> = {
@@ -57,6 +57,8 @@ import {
57
57
  type ViewStyle,
58
58
  } from "react-native";
59
59
  import type {ToastProps as TerrenoToastPayload} from "./Common";
60
+ import {createWebPortal} from "./createWebPortal";
61
+ import {resolveDocumentBodyPortalTarget} from "./resolveDocumentBodyPortalTarget";
60
62
 
61
63
  // ============================================================================
62
64
  // useDimensions hook
@@ -451,7 +453,16 @@ const toastStyles = StyleSheet.create({
451
453
  // Toast Container
452
454
  // ============================================================================
453
455
 
454
- const {height, width} = Dimensions.get("window");
456
+ const {height: windowHeight, width: windowWidth} = Dimensions.get("window");
457
+
458
+ // Static web export renders in Node, where Dimensions reports 0x0 and that size is baked into
459
+ // the HTML. The web container is position:fixed, so percentages track the viewport instead.
460
+ const getContainerSize = (): {height: ViewStyle["height"]; width: ViewStyle["width"]} => {
461
+ if (Platform.OS === "web") {
462
+ return {height: "100%", width: "100%"};
463
+ }
464
+ return {height: windowHeight, width: windowWidth};
465
+ };
455
466
 
456
467
  export interface ToastContainerProps extends ToastOptions {
457
468
  renderToast?(toast: ToastProps): ReactElement;
@@ -634,7 +645,7 @@ const ToastContainer = forwardRef<ToastContainerRef, ToastContainerProps>((props
634
645
  bottom: offsetBottom || offset,
635
646
  flexDirection: "column",
636
647
  justifyContent: "flex-end",
637
- width: width,
648
+ width: getContainerSize().width,
638
649
  };
639
650
  return (
640
651
  <KeyboardAvoidingView
@@ -657,7 +668,7 @@ const ToastContainer = forwardRef<ToastContainerRef, ToastContainerProps>((props
657
668
  flexDirection: "column-reverse",
658
669
  justifyContent: "flex-start",
659
670
  top: offsetTop || offset,
660
- width: width,
671
+ width: getContainerSize().width,
661
672
  };
662
673
  return (
663
674
  <KeyboardAvoidingView
@@ -676,12 +687,13 @@ const ToastContainer = forwardRef<ToastContainerRef, ToastContainerProps>((props
676
687
  }, [toasts, offset, offsetTop]);
677
688
 
678
689
  const renderCenterToasts = useCallback(() => {
690
+ const {height, width} = getContainerSize();
679
691
  const style: ViewStyle = {
680
692
  flexDirection: "column-reverse",
681
- height: height,
693
+ height,
682
694
  justifyContent: "center",
683
695
  top: offsetTop || offset,
684
- width: width,
696
+ width,
685
697
  };
686
698
 
687
699
  const data = toasts.filter((t) => t.placement === "center");
@@ -703,13 +715,28 @@ const ToastContainer = forwardRef<ToastContainerRef, ToastContainerProps>((props
703
715
  );
704
716
  }, [toasts, offset, offsetTop]);
705
717
 
706
- return (
718
+ const toastStack = (
707
719
  <>
708
720
  {renderTopToasts()}
709
721
  {renderBottomToasts()}
710
722
  {renderCenterToasts()}
711
723
  </>
712
724
  );
725
+
726
+ // react-native-web Modal appends its own node to document.body (z-index 9999).
727
+ // A position:fixed toast left in the app tree stays behind that layer and inherits
728
+ // the backdrop dim. Portal the same container to document.body so its z-index wins.
729
+ // Native keeps the in-tree absolute container.
730
+ if (Platform.OS !== "web") {
731
+ return toastStack;
732
+ }
733
+
734
+ const portalTarget = resolveDocumentBodyPortalTarget();
735
+ if (!portalTarget) {
736
+ return toastStack;
737
+ }
738
+
739
+ return createWebPortal({children: toastStack, container: portalTarget});
713
740
  });
714
741
 
715
742
  ToastContainer.displayName = "ToastContainer";
@@ -0,0 +1,285 @@
1
+ import {afterEach, beforeAll, beforeEach, describe, expect, it, spyOn} from "bun:test";
2
+ import {act, render, waitFor} from "@testing-library/react-native";
3
+ import type {ReactElement} from "react";
4
+ import {
5
+ Platform as ImportedPlatform,
6
+ KeyboardAvoidingView,
7
+ Pressable,
8
+ StyleSheet,
9
+ Text,
10
+ } from "react-native";
11
+ import type {ReactTestInstance} from "react-test-renderer";
12
+
13
+ import {Modal} from "./Modal";
14
+ import {ToastProvider, type ToastType, useToastNotifications} from "./ToastNotifications";
15
+ import {renderWithTheme} from "./test-utils";
16
+ import * as Utilities from "./Utilities";
17
+
18
+ // react-native-web ModalAnimation paints the dialog layer at this z-index on document.body.
19
+ const REACT_NATIVE_WEB_MODAL_Z_INDEX = 9999;
20
+
21
+ const TOAST_MESSAGE = "Saved above the modal";
22
+
23
+ interface PortalFiber {
24
+ return: PortalFiber | null;
25
+ stateNode: {containerInfo?: unknown} | null;
26
+ tag: number;
27
+ }
28
+
29
+ const HOST_PORTAL_TAG = 4;
30
+
31
+ const collectPlatformObjects = (): {OS: string}[] => {
32
+ const objects: {OS: string}[] = [];
33
+ const push = (candidate: unknown): void => {
34
+ if (
35
+ candidate &&
36
+ typeof candidate === "object" &&
37
+ "OS" in (candidate as Record<string, unknown>) &&
38
+ !objects.includes(candidate as {OS: string})
39
+ ) {
40
+ objects.push(candidate as {OS: string});
41
+ }
42
+ };
43
+ push(ImportedPlatform);
44
+ const rn = require("react-native") as {Platform?: unknown; default?: {Platform?: unknown}};
45
+ push(rn.Platform);
46
+ push(rn.default?.Platform);
47
+ try {
48
+ const libPlatform = require("react-native/Libraries/Utilities/Platform") as {
49
+ default?: unknown;
50
+ };
51
+ push(libPlatform.default);
52
+ } catch {
53
+ // The internal Platform module may not be resolvable; the top-level mock still covers it.
54
+ }
55
+ return objects;
56
+ };
57
+
58
+ const platformObjects = collectPlatformObjects();
59
+ const originalPlatformOS = platformObjects.map((platform) => platform.OS);
60
+
61
+ const setPlatformOS = (os: string): void => {
62
+ for (const platform of platformObjects) {
63
+ try {
64
+ platform.OS = os;
65
+ } catch {
66
+ // Skip any binding that is not writable.
67
+ }
68
+ }
69
+ };
70
+
71
+ const restorePlatformOS = (): void => {
72
+ platformObjects.forEach((platform, index) => {
73
+ try {
74
+ platform.OS = originalPlatformOS[index] ?? "ios";
75
+ } catch {
76
+ // Skip any binding that is not writable.
77
+ }
78
+ });
79
+ };
80
+
81
+ const globalScope = globalThis as {document?: unknown; HTMLElement?: unknown};
82
+ const originalDocument = globalScope.document;
83
+ const originalHTMLElement = globalScope.HTMLElement;
84
+
85
+ class TestHTMLElement {
86
+ nodeType = 1;
87
+ // react-test-renderer commits a portal by appending host nodes onto `container.children`
88
+ // and reads `createNodeMock` from that container when attaching refs.
89
+ children: unknown[] = [];
90
+ createNodeMock = (): Record<string, never> => ({});
91
+ }
92
+
93
+ const installDocumentBody = (): TestHTMLElement => {
94
+ const body = new TestHTMLElement();
95
+ globalScope.HTMLElement = TestHTMLElement;
96
+ globalScope.document = {activeElement: null, body};
97
+ return body;
98
+ };
99
+
100
+ const restoreDocument = (): void => {
101
+ globalScope.document = originalDocument;
102
+ globalScope.HTMLElement = originalHTMLElement;
103
+ };
104
+
105
+ const flattenStyle = (style: unknown): {pointerEvents?: string; zIndex?: number} => {
106
+ return StyleSheet.flatten(style) as {pointerEvents?: string; zIndex?: number};
107
+ };
108
+
109
+ const portalContainerFor = (node: ReactTestInstance): unknown => {
110
+ let fiber = (node as unknown as {_fiber?: PortalFiber})._fiber ?? null;
111
+ while (fiber) {
112
+ if (fiber.tag === HOST_PORTAL_TAG) {
113
+ return fiber.stateNode?.containerInfo;
114
+ }
115
+ fiber = fiber.return;
116
+ }
117
+ return undefined;
118
+ };
119
+
120
+ const isInside = (node: ReactTestInstance, ancestor: ReactTestInstance): boolean => {
121
+ let current: ReactTestInstance | null = node;
122
+ while (current) {
123
+ if (current === ancestor) {
124
+ return true;
125
+ }
126
+ current = current.parent;
127
+ }
128
+ return false;
129
+ };
130
+
131
+ const findBackdrop = (pressables: ReactTestInstance[]): ReactTestInstance | undefined => {
132
+ return pressables.find((node) => {
133
+ const style = node.props.style as {backgroundColor?: string} | {backgroundColor?: string}[];
134
+ if (Array.isArray(style)) {
135
+ return style.some((entry) => entry?.backgroundColor?.includes("rgba"));
136
+ }
137
+ return style?.backgroundColor?.includes("rgba");
138
+ });
139
+ };
140
+
141
+ const flushFrames = async (): Promise<void> => {
142
+ for (let i = 0; i < 5; i++) {
143
+ await act(async () => {
144
+ await new Promise((resolve) => setTimeout(resolve, 20));
145
+ });
146
+ }
147
+ };
148
+
149
+ beforeAll(() => {
150
+ global.requestAnimationFrame = (callback: FrameRequestCallback) => {
151
+ return setTimeout(() => callback(Date.now()), 0) as unknown as number;
152
+ };
153
+ global.cancelAnimationFrame = (id: number) => {
154
+ clearTimeout(id);
155
+ };
156
+ });
157
+
158
+ describe("Toast above an open web modal", () => {
159
+ let isNativeSpy: ReturnType<typeof spyOn> | undefined;
160
+
161
+ beforeEach(() => {
162
+ setPlatformOS("web");
163
+ isNativeSpy = spyOn(Utilities, "isNative").mockReturnValue(false);
164
+ installDocumentBody();
165
+ });
166
+
167
+ afterEach(() => {
168
+ isNativeSpy?.mockRestore();
169
+ restorePlatformOS();
170
+ restoreDocument();
171
+ });
172
+
173
+ it("portals the toast onto document.body above the modal backdrop", async () => {
174
+ const body = globalScope.document
175
+ ? (globalScope.document as {body: TestHTMLElement}).body
176
+ : undefined;
177
+ let toastRef: ToastType | null = null;
178
+
179
+ const Harness = (): ReactElement => {
180
+ toastRef = useToastNotifications();
181
+ return (
182
+ <Modal onDismiss={() => {}} title="Confirm" visible>
183
+ <Text>Modal body</Text>
184
+ </Modal>
185
+ );
186
+ };
187
+
188
+ const {getByText, UNSAFE_getAllByType} = renderWithTheme(
189
+ <ToastProvider swipeEnabled={false}>
190
+ <Harness />
191
+ </ToastProvider>
192
+ );
193
+
194
+ await waitFor(() => {
195
+ expect(toastRef?.show).toBeDefined();
196
+ });
197
+
198
+ await act(async () => {
199
+ toastRef?.show(TOAST_MESSAGE, {duration: 0, id: "above-modal"});
200
+ });
201
+ await flushFrames();
202
+
203
+ const toastText = getByText(TOAST_MESSAGE);
204
+ const toastHost = UNSAFE_getAllByType(KeyboardAvoidingView).find((node) =>
205
+ isInside(toastText, node)
206
+ );
207
+ expect(toastHost).toBeTruthy();
208
+
209
+ const hostStyle = flattenStyle(toastHost?.props.style);
210
+ expect(hostStyle.pointerEvents).toBe("box-none");
211
+ expect(hostStyle.zIndex).toBeGreaterThan(REACT_NATIVE_WEB_MODAL_Z_INDEX);
212
+
213
+ expect(portalContainerFor(toastText)).toBe(body);
214
+
215
+ const backdrop = findBackdrop(UNSAFE_getAllByType(Pressable));
216
+ expect(backdrop).toBeTruthy();
217
+ expect(isInside(toastText, backdrop as ReactTestInstance)).toBe(false);
218
+ });
219
+
220
+ // Static export pre-renders in Node, where Dimensions reports a 0x0 window; a measured
221
+ // pixel width would bake a 0px container into the HTML and push the toast off-screen.
222
+ it("sizes the fixed container to the viewport instead of the measured window", async () => {
223
+ let toastRef: ToastType | null = null;
224
+ const Harness = (): ReactElement => {
225
+ toastRef = useToastNotifications();
226
+ return <Text>App</Text>;
227
+ };
228
+
229
+ const {getByText, UNSAFE_getAllByType} = renderWithTheme(
230
+ <ToastProvider swipeEnabled={false}>
231
+ <Harness />
232
+ </ToastProvider>
233
+ );
234
+
235
+ await waitFor(() => {
236
+ expect(toastRef?.show).toBeDefined();
237
+ });
238
+ await act(async () => {
239
+ toastRef?.show(TOAST_MESSAGE, {duration: 0, id: "static-export"});
240
+ });
241
+ await flushFrames();
242
+
243
+ const toastText = getByText(TOAST_MESSAGE);
244
+ const toastHost = UNSAFE_getAllByType(KeyboardAvoidingView).find((node) =>
245
+ isInside(toastText, node)
246
+ );
247
+ expect((StyleSheet.flatten(toastHost?.props.style) as {width?: unknown}).width).toBe("100%");
248
+ });
249
+ });
250
+
251
+ describe("Toast container on native", () => {
252
+ afterEach(() => {
253
+ restorePlatformOS();
254
+ restoreDocument();
255
+ });
256
+
257
+ it("keeps the toast in the tree when a document body exists", async () => {
258
+ setPlatformOS("ios");
259
+ installDocumentBody();
260
+
261
+ let toastRef: ToastType | null = null;
262
+ const Harness = (): ReactElement => {
263
+ toastRef = useToastNotifications();
264
+ return <Text>App</Text>;
265
+ };
266
+
267
+ const {getByText} = render(
268
+ <ToastProvider swipeEnabled={false}>
269
+ <Harness />
270
+ </ToastProvider>
271
+ );
272
+
273
+ await waitFor(() => {
274
+ expect(toastRef?.show).toBeDefined();
275
+ });
276
+
277
+ await act(async () => {
278
+ toastRef?.show(TOAST_MESSAGE, {duration: 0, id: "native-toast"});
279
+ });
280
+ await flushFrames();
281
+
282
+ const toastText = getByText(TOAST_MESSAGE);
283
+ expect(portalContainerFor(toastText)).toBeUndefined();
284
+ });
285
+ });
@@ -14,9 +14,12 @@ import {
14
14
  } from "react-native";
15
15
 
16
16
  import {createWebPortal} from "./createWebPortal";
17
+ import {resolveDocumentBodyPortalTarget} from "./resolveDocumentBodyPortalTarget";
17
18
  import {useTheme} from "./Theme";
18
19
  import {createBoxShadow} from "./Utilities";
19
20
 
21
+ export {resolveDocumentBodyPortalTarget};
22
+
20
23
  export const scheduleAfterPaint = (callback: () => void): void => {
21
24
  if (typeof requestAnimationFrame === "function") {
22
25
  requestAnimationFrame(callback);
@@ -25,13 +28,6 @@ export const scheduleAfterPaint = (callback: () => void): void => {
25
28
  }
26
29
  };
27
30
 
28
- export const resolveDocumentBodyPortalTarget = (): HTMLElement | null => {
29
- if (typeof document === "undefined" || typeof HTMLElement === "undefined") {
30
- return null;
31
- }
32
- return document.body instanceof HTMLElement ? document.body : null;
33
- };
34
-
35
31
  export interface WebDropdownMenuOption {
36
32
  key?: string | number;
37
33
  label: string;