@terreno/ui 57.9.0 → 57.11.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 (181) hide show
  1. package/LICENSE +1 -0
  2. package/README.md +2 -0
  3. package/dist/Button.d.ts.map +1 -1
  4. package/dist/Button.js +20 -5
  5. package/dist/Button.js.map +1 -1
  6. package/dist/Common.d.ts +74 -1
  7. package/dist/Common.d.ts.map +1 -1
  8. package/dist/Common.js.map +1 -1
  9. package/dist/DataTable.js +1 -1
  10. package/dist/DataTable.js.map +1 -1
  11. package/dist/DateTimeActionSheet.js +1 -1
  12. package/dist/DateTimeActionSheet.js.map +1 -1
  13. package/dist/DateTimeField.d.ts.map +1 -1
  14. package/dist/DateTimeField.js +91 -18
  15. package/dist/DateTimeField.js.map +1 -1
  16. package/dist/FilePickerButton.d.ts +15 -1
  17. package/dist/FilePickerButton.d.ts.map +1 -1
  18. package/dist/FilePickerButton.js +26 -9
  19. package/dist/FilePickerButton.js.map +1 -1
  20. package/dist/GPTChat.d.ts +57 -1
  21. package/dist/GPTChat.d.ts.map +1 -1
  22. package/dist/GPTChat.js +199 -7
  23. package/dist/GPTChat.js.map +1 -1
  24. package/dist/HtmlFrame.d.ts +11 -0
  25. package/dist/HtmlFrame.d.ts.map +1 -0
  26. package/dist/HtmlFrame.js +29 -0
  27. package/dist/HtmlFrame.js.map +1 -0
  28. package/dist/SplitPage.d.ts +2 -2
  29. package/dist/SplitPage.d.ts.map +1 -1
  30. package/dist/SplitPage.js +17 -5
  31. package/dist/SplitPage.js.map +1 -1
  32. package/dist/Text.d.ts +1 -1
  33. package/dist/Text.d.ts.map +1 -1
  34. package/dist/Text.js +2 -2
  35. package/dist/Text.js.map +1 -1
  36. package/dist/asks/AskCard.d.ts +34 -0
  37. package/dist/asks/AskCard.d.ts.map +1 -0
  38. package/dist/asks/AskCard.js +91 -0
  39. package/dist/asks/AskCard.js.map +1 -0
  40. package/dist/asks/AskChoice.d.ts +11 -0
  41. package/dist/asks/AskChoice.d.ts.map +1 -0
  42. package/dist/asks/AskChoice.js +146 -0
  43. package/dist/asks/AskChoice.js.map +1 -0
  44. package/dist/asks/AskConfirm.d.ts +15 -0
  45. package/dist/asks/AskConfirm.d.ts.map +1 -0
  46. package/dist/asks/AskConfirm.js +17 -0
  47. package/dist/asks/AskConfirm.js.map +1 -0
  48. package/dist/asks/AskFiles.d.ts +18 -0
  49. package/dist/asks/AskFiles.d.ts.map +1 -0
  50. package/dist/asks/AskFiles.js +149 -0
  51. package/dist/asks/AskFiles.js.map +1 -0
  52. package/dist/asks/AskForm.d.ts +27 -0
  53. package/dist/asks/AskForm.d.ts.map +1 -0
  54. package/dist/asks/AskForm.js +146 -0
  55. package/dist/asks/AskForm.js.map +1 -0
  56. package/dist/asks/AskMarkdown.d.ts +25 -0
  57. package/dist/asks/AskMarkdown.d.ts.map +1 -0
  58. package/dist/asks/AskMarkdown.js +73 -0
  59. package/dist/asks/AskMarkdown.js.map +1 -0
  60. package/dist/asks/SimpleAskCard.d.ts +23 -0
  61. package/dist/asks/SimpleAskCard.d.ts.map +1 -0
  62. package/dist/asks/SimpleAskCard.js +32 -0
  63. package/dist/asks/SimpleAskCard.js.map +1 -0
  64. package/dist/asks/askControls.d.ts +33 -0
  65. package/dist/asks/askControls.d.ts.map +1 -0
  66. package/dist/asks/askControls.js +30 -0
  67. package/dist/asks/askControls.js.map +1 -0
  68. package/dist/asks/askFileRefs.d.ts +26 -0
  69. package/dist/asks/askFileRefs.d.ts.map +1 -0
  70. package/dist/asks/askFileRefs.js +75 -0
  71. package/dist/asks/askFileRefs.js.map +1 -0
  72. package/dist/asks/askFormDraft.d.ts +60 -0
  73. package/dist/asks/askFormDraft.d.ts.map +1 -0
  74. package/dist/asks/askFormDraft.js +224 -0
  75. package/dist/asks/askFormDraft.js.map +1 -0
  76. package/dist/asks/askSummary.d.ts +10 -0
  77. package/dist/asks/askSummary.d.ts.map +1 -0
  78. package/dist/asks/askSummary.js +138 -0
  79. package/dist/asks/askSummary.js.map +1 -0
  80. package/dist/asks/askTypes.d.ts +21 -0
  81. package/dist/asks/askTypes.d.ts.map +1 -0
  82. package/dist/asks/askTypes.js +2 -0
  83. package/dist/asks/askTypes.js.map +1 -0
  84. package/dist/asks/simpleCardButtonVariants.d.ts +5 -0
  85. package/dist/asks/simpleCardButtonVariants.d.ts.map +1 -0
  86. package/dist/asks/simpleCardButtonVariants.js +8 -0
  87. package/dist/asks/simpleCardButtonVariants.js.map +1 -0
  88. package/dist/blocks/BlocksError.d.ts +8 -0
  89. package/dist/blocks/BlocksError.d.ts.map +1 -0
  90. package/dist/blocks/BlocksError.js +14 -0
  91. package/dist/blocks/BlocksError.js.map +1 -0
  92. package/dist/blocks/BlocksView.d.ts +10 -0
  93. package/dist/blocks/BlocksView.d.ts.map +1 -0
  94. package/dist/blocks/BlocksView.js +90 -0
  95. package/dist/blocks/BlocksView.js.map +1 -0
  96. package/dist/blocks/blockRenderers.d.ts +25 -0
  97. package/dist/blocks/blockRenderers.d.ts.map +1 -0
  98. package/dist/blocks/blockRenderers.js +136 -0
  99. package/dist/blocks/blockRenderers.js.map +1 -0
  100. package/dist/blocks/datasetToPoints.d.ts +22 -0
  101. package/dist/blocks/datasetToPoints.d.ts.map +1 -0
  102. package/dist/blocks/datasetToPoints.js +28 -0
  103. package/dist/blocks/datasetToPoints.js.map +1 -0
  104. package/dist/blocks/useBlockSelections.d.ts +6 -0
  105. package/dist/blocks/useBlockSelections.d.ts.map +1 -0
  106. package/dist/blocks/useBlockSelections.js +10 -0
  107. package/dist/blocks/useBlockSelections.js.map +1 -0
  108. package/dist/blocks/useResolvedDatasets.d.ts +18 -0
  109. package/dist/blocks/useResolvedDatasets.d.ts.map +1 -0
  110. package/dist/blocks/useResolvedDatasets.js +59 -0
  111. package/dist/blocks/useResolvedDatasets.js.map +1 -0
  112. package/dist/blocks/useResolvedImages.d.ts +15 -0
  113. package/dist/blocks/useResolvedImages.d.ts.map +1 -0
  114. package/dist/blocks/useResolvedImages.js +66 -0
  115. package/dist/blocks/useResolvedImages.js.map +1 -0
  116. package/dist/index.d.ts +6 -1
  117. package/dist/index.d.ts.map +1 -1
  118. package/dist/index.js +4 -1
  119. package/dist/index.js.map +1 -1
  120. package/dist/lazyBoundaries/heavyOptionalExports.d.ts +6 -0
  121. package/dist/lazyBoundaries/heavyOptionalExports.d.ts.map +1 -1
  122. package/dist/lazyBoundaries/heavyOptionalExports.js +4 -0
  123. package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
  124. package/dist/table/TableHeaderCell.js +1 -1
  125. package/dist/table/TableHeaderCell.js.map +1 -1
  126. package/package.json +2 -1
  127. package/src/Button.test.tsx +101 -0
  128. package/src/Button.tsx +35 -5
  129. package/src/Common.ts +73 -0
  130. package/src/DataTable.tsx +1 -1
  131. package/src/DateTimeActionSheet.tsx +1 -1
  132. package/src/DateTimeField.test.tsx +185 -2
  133. package/src/DateTimeField.tsx +107 -17
  134. package/src/DonutChart.test.tsx +5 -10
  135. package/src/FilePickerButton.test.tsx +56 -3
  136. package/src/FilePickerButton.tsx +83 -17
  137. package/src/GPTChat.test.tsx +758 -2
  138. package/src/GPTChat.tsx +517 -7
  139. package/src/HtmlFrame.tsx +60 -0
  140. package/src/LineChart.test.tsx +5 -10
  141. package/src/SplitPage.test.tsx +55 -0
  142. package/src/SplitPage.tsx +13 -7
  143. package/src/Text.test.tsx +22 -0
  144. package/src/Text.tsx +10 -1
  145. package/src/__snapshots__/Button.test.tsx.snap +1 -1
  146. package/src/__snapshots__/SplitPage.test.tsx.snap +14 -0
  147. package/src/asks/AskCard.test.tsx +1428 -0
  148. package/src/asks/AskCard.tsx +240 -0
  149. package/src/asks/AskChoice.tsx +368 -0
  150. package/src/asks/AskConfirm.tsx +42 -0
  151. package/src/asks/AskFiles.test.tsx +347 -0
  152. package/src/asks/AskFiles.tsx +246 -0
  153. package/src/asks/AskForm.tsx +334 -0
  154. package/src/asks/AskMarkdown.tsx +176 -0
  155. package/src/asks/SimpleAskCard.test.tsx +253 -0
  156. package/src/asks/SimpleAskCard.tsx +82 -0
  157. package/src/asks/askControls.tsx +98 -0
  158. package/src/asks/askFileRefs.test.ts +155 -0
  159. package/src/asks/askFileRefs.ts +98 -0
  160. package/src/asks/askFormDraft.test.ts +347 -0
  161. package/src/asks/askFormDraft.ts +309 -0
  162. package/src/asks/askSummary.test.ts +255 -0
  163. package/src/asks/askSummary.ts +160 -0
  164. package/src/asks/askTypes.ts +25 -0
  165. package/src/asks/asksUseTerrenoComponents.test.ts +55 -0
  166. package/src/asks/simpleCardButtonVariants.ts +14 -0
  167. package/src/blocks/BlocksError.tsx +28 -0
  168. package/src/blocks/BlocksView.test.tsx +607 -0
  169. package/src/blocks/BlocksView.tsx +125 -0
  170. package/src/blocks/blockRenderers.tsx +288 -0
  171. package/src/blocks/datasetToPoints.test.ts +31 -0
  172. package/src/blocks/datasetToPoints.ts +48 -0
  173. package/src/blocks/useBlockSelections.ts +13 -0
  174. package/src/blocks/useResolvedDatasets.ts +78 -0
  175. package/src/blocks/useResolvedImages.ts +81 -0
  176. package/src/bunSetup.ts +0 -6
  177. package/src/index.tsx +7 -0
  178. package/src/isolated/HtmlFrame.isolated.tsx +54 -0
  179. package/src/lazyBoundaries/heavyOptionalExports.test.tsx +2 -0
  180. package/src/lazyBoundaries/heavyOptionalExports.tsx +14 -0
  181. package/src/table/TableHeaderCell.tsx +1 -1
@@ -0,0 +1,60 @@
1
+ import React, {useRef} from "react";
2
+ import {Platform} from "react-native";
3
+ import WebView from "react-native-webview";
4
+
5
+ import {Box} from "./Box";
6
+ import type {HtmlFrameProps} from "./Common";
7
+
8
+ export type {HtmlFrameProps} from "./Common";
9
+
10
+ const HTML_FRAME_HEIGHTS = {lg: 640, md: 400, sm: 240} as const;
11
+
12
+ const CSP =
13
+ "default-src 'none'; img-src data:; style-src 'unsafe-inline'; font-src data:; form-action 'none'; base-uri 'none'";
14
+
15
+ /** The document a frame loads. The CSP meta tag is first so it applies to the preview. */
16
+ export const htmlFrameSrcDoc = (html: string): string =>
17
+ `<meta http-equiv="Content-Security-Policy" content="${CSP}">${html}`;
18
+
19
+ /**
20
+ * Sandboxed preview of agent HTML. Web uses an iframe with an empty sandbox.
21
+ * Native uses a WebView with JavaScript off and navigation blocked after the first load.
22
+ */
23
+ export const HtmlFrame: React.FC<HtmlFrameProps> = ({height = "md", html, title}) => {
24
+ const srcDoc = htmlFrameSrcDoc(html);
25
+ const pixels = HTML_FRAME_HEIGHTS[height];
26
+ const didLoad = useRef(false);
27
+
28
+ if (Platform.OS === "web") {
29
+ return (
30
+ <Box height={pixels} testID="html-frame-web" width="100%">
31
+ <iframe
32
+ referrerPolicy="no-referrer"
33
+ sandbox=""
34
+ srcDoc={srcDoc}
35
+ style={{border: 0, height: "100%", width: "100%"}}
36
+ title={title ?? "Agent-generated preview"}
37
+ />
38
+ </Box>
39
+ );
40
+ }
41
+
42
+ return (
43
+ <Box height={pixels} testID="html-frame-native" width="100%">
44
+ <WebView
45
+ dataDetectorTypes="none"
46
+ incognito
47
+ javaScriptEnabled={false}
48
+ onShouldStartLoadWithRequest={() => {
49
+ if (didLoad.current) {
50
+ return false;
51
+ }
52
+ didLoad.current = true;
53
+ return true;
54
+ }}
55
+ source={{html: srcDoc}}
56
+ style={{flex: 1}}
57
+ />
58
+ </Box>
59
+ );
60
+ };
@@ -1,7 +1,6 @@
1
- import {describe, expect, it, spyOn} from "bun:test";
1
+ import {describe, expect, it} from "bun:test";
2
2
  import {act, fireEvent} from "@testing-library/react-native";
3
3
  import {assert} from "chai";
4
- import {Linking} from "react-native";
5
4
 
6
5
  import {LineChart} from "./LineChart";
7
6
  import {renderWithTheme} from "./test-utils";
@@ -254,17 +253,13 @@ describe("LineChart", () => {
254
253
  );
255
254
  });
256
255
 
257
- it("does not open URLs from x-axis labels", async () => {
258
- const openURLSpy = spyOn(Linking, "openURL").mockImplementation(() => Promise.resolve(true));
256
+ it("does not open URLs from x-axis labels", () => {
259
257
  const {getByText} = renderWithTheme(
260
258
  <LineChart data={[{label: "https://evil.example", value: 10}]} />
261
259
  );
262
260
 
263
- await act(async () => {
264
- fireEvent.press(getByText("https://evil.example"));
265
- });
266
-
267
- expect(openURLSpy).not.toHaveBeenCalled();
268
- openURLSpy.mockRestore();
261
+ // The suite shares one Linking mock, so a spy on openURL also records calls
262
+ // from other files. A label is inert when it has no press handler.
263
+ expect(getByText("https://evil.example").props.onPress).toBeUndefined();
269
264
  });
270
265
  });
@@ -4,6 +4,7 @@ import {forwardRef, type ReactNode, type Ref, useImperativeHandle} from "react";
4
4
  import {type ScaledSize, StyleSheet, useWindowDimensions, View} from "react-native";
5
5
  import type {ReactTestInstance} from "react-test-renderer";
6
6
 
7
+ import {getRounding} from "./Common";
7
8
  import {SplitPage} from "./SplitPage";
8
9
  import {renderWithTheme} from "./test-utils";
9
10
 
@@ -50,6 +51,8 @@ const setWindowWidth = (width: number): (() => void) => {
50
51
 
51
52
  const styleWidth = (style: unknown): unknown => StyleSheet.flatten(style)?.width;
52
53
 
54
+ const styleBorderRadius = (style: unknown): unknown => StyleSheet.flatten(style)?.borderRadius;
55
+
53
56
  const setDesktop = () => {
54
57
  mock.module("./MediaQuery", () => ({
55
58
  isNarrowViewport: () => false,
@@ -1018,5 +1021,57 @@ describe("SplitPage", () => {
1018
1021
  expect(paginated.length).toBeGreaterThan(0);
1019
1022
  warnSpy.mockRestore();
1020
1023
  });
1024
+
1025
+ it("applies the default md border radius to desktop child columns but not the list column", () => {
1026
+ setDesktop();
1027
+ const {getByTestId, UNSAFE_root} = renderWithTheme(
1028
+ <SplitPage {...defaultProps} desktopChildrenMinWidth={200}>
1029
+ <View testID="child-1" />
1030
+ <View testID="child-2" />
1031
+ </SplitPage>
1032
+ );
1033
+ expect(styleBorderRadius(getByTestId("split-page-desktop-child-0").props.style)).toBe(
1034
+ getRounding("md")
1035
+ );
1036
+ expect(styleBorderRadius(getByTestId("split-page-desktop-child-1").props.style)).toBe(
1037
+ getRounding("md")
1038
+ );
1039
+ const listColumn = UNSAFE_root.findAll(
1040
+ (node: ReactTestInstance) =>
1041
+ styleWidth(node.props?.style) === 300 && node.props?.style?.maxWidth === 300
1042
+ )[0];
1043
+ expect(listColumn).toBeTruthy();
1044
+ expect(styleBorderRadius(listColumn?.props?.style)).toBeUndefined();
1045
+ });
1046
+
1047
+ it("allows childColumnRounding to override the desktop child column border radius", () => {
1048
+ setDesktop();
1049
+ const {getByTestId} = renderWithTheme(
1050
+ <SplitPage {...defaultProps} childColumnRounding="lg" desktopChildrenMinWidth={200}>
1051
+ <View testID="child-1" />
1052
+ <View testID="child-2" />
1053
+ </SplitPage>
1054
+ );
1055
+ expect(styleBorderRadius(getByTestId("split-page-desktop-child-0").props.style)).toBe(
1056
+ getRounding("lg")
1057
+ );
1058
+ });
1059
+
1060
+ it("applies child column border radius on the labeled narrow pager child containers", async () => {
1061
+ setMobile();
1062
+ const {getAllByLabelText, getByTestId} = renderWithTheme(
1063
+ <SplitPage {...defaultProps} narrowViewportChildLabels={["Summary", "Notes"]}>
1064
+ <View testID="child-1" />
1065
+ <View testID="child-2" />
1066
+ </SplitPage>
1067
+ );
1068
+ await selectFirst(getAllByLabelText);
1069
+ expect(styleBorderRadius(getByTestId("split-page-mobile-child-0").props.style)).toBe(
1070
+ getRounding("md")
1071
+ );
1072
+ expect(styleBorderRadius(getByTestId("split-page-mobile-child-1").props.style)).toBe(
1073
+ getRounding("md")
1074
+ );
1075
+ });
1021
1076
  });
1022
1077
  });
package/src/SplitPage.tsx CHANGED
@@ -17,7 +17,7 @@ import {
17
17
  import {SwiperFlatList} from "react-native-swiper-flatlist";
18
18
 
19
19
  import {Box} from "./Box";
20
- import type {SplitPageListItem, SplitPageProps} from "./Common";
20
+ import {getRounding, type SplitPageListItem, type SplitPageProps} from "./Common";
21
21
  import {FlatList} from "./FlatList";
22
22
  import {IconButton} from "./IconButton";
23
23
  import {isNarrowViewport} from "./MediaQuery";
@@ -51,6 +51,7 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
51
51
  narrowViewportListButtonLabel,
52
52
  narrowViewportSelectionActive,
53
53
  narrowViewportSelectionKey,
54
+ childColumnRounding = "md",
54
55
  showItemList,
55
56
  }: SplitPageProps<TItem>) => {
56
57
  const {theme} = useTheme();
@@ -67,6 +68,7 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
67
68
  const isNarrowLayout =
68
69
  narrowBelowWidth === undefined ? isNarrowViewport() : windowWidth <= narrowBelowWidth;
69
70
  const isDetailActive = selectedId !== undefined || narrowViewportSelectionActive === true;
71
+ const childColumnBorderRadius = getRounding(childColumnRounding);
70
72
 
71
73
  const elementArray = Children.toArray(children).filter((c) => c !== null);
72
74
 
@@ -210,8 +212,10 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
210
212
  }}
211
213
  key={tabIndex}
212
214
  style={{
215
+ borderRadius: childColumnBorderRadius,
213
216
  flex: 1,
214
217
  height: "100%",
218
+ overflow: "hidden",
215
219
  paddingLeft: i ? 16 : 0,
216
220
  paddingRight: i ? 0 : 16,
217
221
  width: "60%",
@@ -259,10 +263,12 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
259
263
  contentContainerStyle={{flexGrow: 1}}
260
264
  key={index}
261
265
  style={{
266
+ borderRadius: childColumnBorderRadius,
262
267
  flexGrow: 0,
263
268
  flexShrink: 0,
264
269
  height: "100%",
265
270
  maxWidth: childWidth,
271
+ overflow: "hidden",
266
272
  width: childWidth,
267
273
  }}
268
274
  testID={`split-page-desktop-child-${index}`}
@@ -285,8 +291,10 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
285
291
  }}
286
292
  key={index}
287
293
  style={{
294
+ borderRadius: childColumnBorderRadius,
288
295
  flex: 1,
289
296
  height: "100%",
297
+ overflow: "hidden",
290
298
  width: "60%",
291
299
  }}
292
300
  >
@@ -386,7 +394,9 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
386
394
  <View
387
395
  key={index}
388
396
  style={{
397
+ borderRadius: childColumnBorderRadius,
389
398
  height: "100%",
399
+ overflow: "hidden",
390
400
  padding: 0,
391
401
  paddingBottom: bottomNavBarHeight,
392
402
  width: pageWidth,
@@ -410,11 +420,9 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
410
420
  <IconButton
411
421
  accessibilityHint={narrowViewportListButtonLabel}
412
422
  accessibilityLabel={narrowViewportListButtonLabel}
413
- backgroundOpacity={0.88}
414
423
  iconName="arrow-left"
415
424
  onClick={() => onItemDeselect()}
416
425
  testID="split-page-back-to-list"
417
- variant="muted"
418
426
  />
419
427
  </View>
420
428
  ) : null}
@@ -431,25 +439,21 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
431
439
  {activeChildIndex > 0 ? (
432
440
  <IconButton
433
441
  accessibilityLabel={`Show previous column: ${labels[activeChildIndex - 1]}`}
434
- backgroundOpacity={0.88}
435
442
  iconName="chevron-left"
436
443
  onClick={() => {
437
444
  showMobileChild(activeChildIndex - 1);
438
445
  }}
439
446
  testID="split-page-column-previous"
440
- variant="muted"
441
447
  />
442
448
  ) : null}
443
449
  {activeChildIndex < lastIndex ? (
444
450
  <IconButton
445
451
  accessibilityLabel={`Show next column: ${labels[activeChildIndex + 1]}`}
446
- backgroundOpacity={0.88}
447
452
  iconName="chevron-right"
448
453
  onClick={() => {
449
454
  showMobileChild(activeChildIndex + 1);
450
455
  }}
451
456
  testID="split-page-column-next"
452
- variant="muted"
453
457
  />
454
458
  ) : null}
455
459
  </View>
@@ -482,7 +486,9 @@ export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
482
486
  <View
483
487
  key={i}
484
488
  style={{
489
+ borderRadius: childColumnBorderRadius,
485
490
  height: elementArray.length > 1 ? "90%" : "100%",
491
+ overflow: "hidden",
486
492
  padding: 4,
487
493
  paddingBottom: bottomNavBarHeight,
488
494
  width: windowWidth - 8,
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
  );
@@ -350,7 +350,7 @@ exports[`Button renders outline variant 1`] = `
350
350
  "flexDirection": "column",
351
351
  "height": undefined,
352
352
  "justifyContent": "center",
353
- "paddingHorizontal": 20,
353
+ "paddingHorizontal": 18,
354
354
  "paddingVertical": 6,
355
355
  "width": "auto",
356
356
  },
@@ -262,8 +262,10 @@ exports[`SplitPage renders correctly with children 1`] = `
262
262
  "flex": 1,
263
263
  },
264
264
  "style": {
265
+ "borderRadius": 4,
265
266
  "flex": 1,
266
267
  "height": "100%",
268
+ "overflow": "hidden",
267
269
  "width": "60%",
268
270
  },
269
271
  },
@@ -287,8 +289,10 @@ exports[`SplitPage renders correctly with children 1`] = `
287
289
  "flex": 1,
288
290
  },
289
291
  "style": {
292
+ "borderRadius": 4,
290
293
  "flex": 1,
291
294
  "height": "100%",
295
+ "overflow": "hidden",
292
296
  "width": "60%",
293
297
  },
294
298
  },
@@ -959,8 +963,10 @@ exports[`SplitPage renders with tabs when more than 2 children 1`] = `
959
963
  "flex": 1,
960
964
  },
961
965
  "style": {
966
+ "borderRadius": 4,
962
967
  "flex": 1,
963
968
  "height": "100%",
969
+ "overflow": "hidden",
964
970
  "paddingLeft": 0,
965
971
  "paddingRight": 16,
966
972
  "width": "60%",
@@ -986,8 +992,10 @@ exports[`SplitPage renders with tabs when more than 2 children 1`] = `
986
992
  "flex": 1,
987
993
  },
988
994
  "style": {
995
+ "borderRadius": 4,
989
996
  "flex": 1,
990
997
  "height": "100%",
998
+ "overflow": "hidden",
991
999
  "paddingLeft": 16,
992
1000
  "paddingRight": 0,
993
1001
  "width": "60%",
@@ -1796,8 +1804,10 @@ exports[`SplitPage filters out null children 1`] = `
1796
1804
  "flex": 1,
1797
1805
  },
1798
1806
  "style": {
1807
+ "borderRadius": 4,
1799
1808
  "flex": 1,
1800
1809
  "height": "100%",
1810
+ "overflow": "hidden",
1801
1811
  "width": "60%",
1802
1812
  },
1803
1813
  },
@@ -1821,8 +1831,10 @@ exports[`SplitPage filters out null children 1`] = `
1821
1831
  "flex": 1,
1822
1832
  },
1823
1833
  "style": {
1834
+ "borderRadius": 4,
1824
1835
  "flex": 1,
1825
1836
  "height": "100%",
1837
+ "overflow": "hidden",
1826
1838
  "width": "60%",
1827
1839
  },
1828
1840
  },
@@ -2147,8 +2159,10 @@ exports[`SplitPage renders with bottomNavBarHeight 1`] = `
2147
2159
  "flex": 1,
2148
2160
  },
2149
2161
  "style": {
2162
+ "borderRadius": 4,
2150
2163
  "flex": 1,
2151
2164
  "height": "100%",
2165
+ "overflow": "hidden",
2152
2166
  "width": "60%",
2153
2167
  },
2154
2168
  },