@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
@@ -3,7 +3,7 @@ import {fireEvent} from "@testing-library/react-native";
3
3
  import {assert} from "chai";
4
4
  // Import Platform the same way the source modules do (ESM named import) so the web blur effect
5
5
  // (which reads Platform.OS directly in Modal.tsx) observes the value the test sets.
6
- import {Platform as ImportedPlatform} from "react-native";
6
+ import {Platform as ImportedPlatform, type ScaledSize, useWindowDimensions} from "react-native";
7
7
  import {Gesture} from "react-native-gesture-handler";
8
8
 
9
9
  import {Modal} from "./Modal";
@@ -21,6 +21,13 @@ interface PressableTestInstance {
21
21
  };
22
22
  }
23
23
 
24
+ interface ViewTestInstance {
25
+ props: {
26
+ style?: {cursor?: string} | {cursor?: string}[];
27
+ onClick?: (event: {stopPropagation: () => void}) => void;
28
+ };
29
+ }
30
+
24
31
  /**
25
32
  * Finds the web-only translucent backdrop Pressable in a rendered Modal tree.
26
33
  *
@@ -116,6 +123,26 @@ const restorePlatformOS = (): void => {
116
123
 
117
124
  let isNativeSpy: ReturnType<typeof spyOn> | undefined;
118
125
 
126
+ type WindowDimensionsImpl = () => ScaledSize;
127
+ type MockableUseWindowDimensions = WindowDimensionsImpl & {
128
+ mockImplementation?: (impl: WindowDimensionsImpl) => void;
129
+ };
130
+
131
+ const setWindowWidth = (width: number): (() => void) => {
132
+ const windowDimensions = useWindowDimensions as MockableUseWindowDimensions;
133
+ if (typeof windowDimensions.mockImplementation !== "function") {
134
+ return (): void => {};
135
+ }
136
+ windowDimensions.mockImplementation(
137
+ (): ScaledSize => ({fontScale: 1, height: 924, scale: 1, width})
138
+ );
139
+ return (): void => {
140
+ windowDimensions.mockImplementation?.(
141
+ (): ScaledSize => ({fontScale: 1, height: 924, scale: 1, width: 1024})
142
+ );
143
+ };
144
+ };
145
+
119
146
  /**
120
147
  * Forces `isNative()` to a fixed value so the Modal's platform branch is deterministic.
121
148
  *
@@ -474,6 +501,37 @@ describe("Modal web platform", () => {
474
501
  expect(findBackdropPressable(pressables)).toBeTruthy();
475
502
  });
476
503
 
504
+ it("stacks long modal actions at narrow web widths", () => {
505
+ const restoreWindowWidth = setWindowWidth(400);
506
+ try {
507
+ const {getByText, UNSAFE_root} = renderWithTheme(
508
+ <Modal
509
+ onDismiss={() => {}}
510
+ primaryButtonOnClick={() => {}}
511
+ primaryButtonText="Got it"
512
+ secondaryButtonOnClick={() => {}}
513
+ secondaryButtonText="Read the announcement docs"
514
+ title="Announcement"
515
+ visible
516
+ >
517
+ <Text>Launch details</Text>
518
+ </Modal>
519
+ );
520
+
521
+ assert.exists(getByText("Read the announcement docs"));
522
+ assert.exists(getByText("Got it"));
523
+ const stackedActionRows = UNSAFE_root.findAll(
524
+ (node) =>
525
+ node.props?.style?.alignSelf === "stretch" &&
526
+ node.props?.style?.flexDirection === "column" &&
527
+ node.props?.style?.gap === 12
528
+ );
529
+ assert.isAtLeast(stackedActionRows.length, 1);
530
+ } finally {
531
+ restoreWindowWidth();
532
+ }
533
+ });
534
+
477
535
  it("dismisses when the backdrop is pressed and persistOnBackgroundClick is false", () => {
478
536
  const handleDismiss = mock(() => {});
479
537
  const {UNSAFE_getAllByType} = renderWithTheme(
@@ -490,35 +548,70 @@ describe("Modal web platform", () => {
490
548
  expect(handleDismiss).toHaveBeenCalled();
491
549
  });
492
550
 
493
- it("stops propagation on the inner backdrop wrapper press", () => {
551
+ const findDialogShellView = (views: ViewTestInstance[]): ViewTestInstance | undefined => {
552
+ return views.find((node) => {
553
+ const style = node.props.style;
554
+ if (Array.isArray(style)) {
555
+ return style.some((entry) => entry?.cursor === "auto");
556
+ }
557
+ return style?.cursor === "auto";
558
+ });
559
+ };
560
+
561
+ it("stops propagation on the dialog shell click (web)", () => {
494
562
  const stopPropagation = mock(() => {});
495
563
  const {UNSAFE_getAllByType} = renderWithTheme(
496
564
  <Modal onDismiss={() => {}} title="Title" visible>
497
565
  <Text>Content</Text>
498
566
  </Modal>
499
567
  );
500
- const {Pressable} = require("react-native");
501
- const pressables: PressableTestInstance[] = UNSAFE_getAllByType(Pressable);
502
- // Inner wrapper is the pressable with style {cursor: "auto"}.
503
- const inner = pressables.find((node) => node.props.style?.cursor === "auto");
504
- expect(inner).toBeTruthy();
505
- inner?.props.onPress?.({stopPropagation});
568
+ const {View} = require("react-native");
569
+ const views: ViewTestInstance[] = UNSAFE_getAllByType(View);
570
+ const shell = findDialogShellView(views);
571
+ expect(shell).toBeTruthy();
572
+ shell?.props.onClick?.({stopPropagation});
506
573
  expect(stopPropagation).toHaveBeenCalled();
507
574
  });
508
575
 
509
- it("does not stop propagation on the inner wrapper when persistOnBackgroundClick is true", () => {
576
+ it("still stops dialog shell propagation when persistOnBackgroundClick is true", () => {
510
577
  const stopPropagation = mock(() => {});
578
+ const handleDismiss = mock(() => {});
511
579
  const {UNSAFE_getAllByType} = renderWithTheme(
512
- <Modal onDismiss={() => {}} persistOnBackgroundClick title="Title" visible>
580
+ <Modal onDismiss={handleDismiss} persistOnBackgroundClick title="Title" visible>
513
581
  <Text>Content</Text>
514
582
  </Modal>
515
583
  );
584
+ const {Pressable, View} = require("react-native");
585
+ const pressables: PressableTestInstance[] = UNSAFE_getAllByType(Pressable);
586
+ const backdrop = findBackdropPressable(pressables);
587
+ expect(backdrop?.props.onPress).toBeUndefined();
588
+
589
+ const views: ViewTestInstance[] = UNSAFE_getAllByType(View);
590
+ const shell = findDialogShellView(views);
591
+ expect(shell).toBeTruthy();
592
+ shell?.props.onClick?.({stopPropagation});
593
+ expect(stopPropagation).toHaveBeenCalled();
594
+ expect(handleDismiss).not.toHaveBeenCalled();
595
+ });
596
+
597
+ it("does not dismiss when a nested child action is pressed on web", () => {
598
+ const handleDismiss = mock(() => {});
599
+ const handleAction = mock(() => {});
600
+ const {UNSAFE_getAllByType, getByText} = renderWithTheme(
601
+ <Modal onDismiss={handleDismiss} title="Title" visible>
602
+ <Text onPress={handleAction}>Mark read</Text>
603
+ </Modal>
604
+ );
605
+ fireEvent.press(getByText("Mark read"));
606
+ expect(handleAction).toHaveBeenCalled();
607
+ expect(handleDismiss).not.toHaveBeenCalled();
608
+
516
609
  const {Pressable} = require("react-native");
517
610
  const pressables: PressableTestInstance[] = UNSAFE_getAllByType(Pressable);
518
- const inner = pressables.find((node) => node.props.style?.cursor === "auto");
519
- expect(inner).toBeTruthy();
520
- inner?.props.onPress?.({stopPropagation});
521
- expect(stopPropagation).not.toHaveBeenCalled();
611
+ const backdrop = findBackdropPressable(pressables);
612
+ expect(backdrop).toBeTruthy();
613
+ backdrop?.props.onPress?.();
614
+ expect(handleDismiss).toHaveBeenCalledTimes(1);
522
615
  });
523
616
 
524
617
  it("blurs the focused element when opened on web", () => {
package/src/Modal.tsx CHANGED
@@ -5,6 +5,7 @@ import {
5
5
  Platform,
6
6
  Pressable,
7
7
  Modal as RNModal,
8
+ useWindowDimensions,
8
9
  View,
9
10
  } from "react-native";
10
11
  import ActionSheet, {type ActionSheetRef} from "react-native-actions-sheet";
@@ -33,6 +34,10 @@ const getModalSize = (size: "sm" | "md" | "lg"): DimensionValue => {
33
34
  return sizePx;
34
35
  };
35
36
 
37
+ const stopWebClickPropagation = (event: {stopPropagation: () => void}): void => {
38
+ event.stopPropagation();
39
+ };
40
+
36
41
  const ModalContent: FC<{
37
42
  children?: ModalProps["children"];
38
43
  title?: ModalProps["title"];
@@ -47,6 +52,7 @@ const ModalContent: FC<{
47
52
  sizePx: DimensionValue;
48
53
  theme: TerrenoTheme;
49
54
  isMobile: boolean;
55
+ isNarrow: boolean;
50
56
  modalTestIDs: ReturnType<typeof resolveModalTestIDsFromProps>;
51
57
  }> = ({
52
58
  children,
@@ -62,6 +68,7 @@ const ModalContent: FC<{
62
68
  sizePx,
63
69
  theme,
64
70
  isMobile,
71
+ isNarrow,
65
72
  modalTestIDs,
66
73
  }) => {
67
74
  return (
@@ -150,14 +157,16 @@ const ModalContent: FC<{
150
157
  )}
151
158
  <View
152
159
  style={{
153
- alignSelf: "flex-end",
154
- flexDirection: "row",
160
+ alignSelf: isNarrow ? "stretch" : "flex-end",
161
+ flexDirection: isNarrow ? "column" : "row",
155
162
  marginTop: text && !children ? 20 : 32,
163
+ ...(isNarrow ? {gap: 12} : {}),
156
164
  }}
157
165
  >
158
166
  {Boolean(secondaryButtonText && secondaryButtonOnClick) && (
159
- <View style={{marginRight: primaryButtonText ? 20 : 0}}>
167
+ <View style={{marginRight: !isNarrow && primaryButtonText ? 20 : 0}}>
160
168
  <Button
169
+ fullWidth={isNarrow}
161
170
  onClick={secondaryButtonOnClick!}
162
171
  testID={modalTestIDs.secondaryButton}
163
172
  text={secondaryButtonText as string}
@@ -168,6 +177,7 @@ const ModalContent: FC<{
168
177
  {Boolean(primaryButtonText && primaryButtonOnClick) && (
169
178
  <Button
170
179
  disabled={primaryButtonDisabled}
180
+ fullWidth={isNarrow}
171
181
  onClick={primaryButtonOnClick!}
172
182
  testID={modalTestIDs.primaryButton}
173
183
  text={primaryButtonText as string}
@@ -197,6 +207,7 @@ export const Modal: FC<ModalProps> = ({
197
207
  }: ModalProps) => {
198
208
  const actionSheetRef = useRef<ActionSheetRef>(null);
199
209
  const {theme} = useTheme();
210
+ const {width: windowWidth} = useWindowDimensions();
200
211
  const modalTestIDs = resolveModalTestIDsFromProps({testID, testIDs});
201
212
 
202
213
  const handleDismiss = () => {
@@ -253,11 +264,13 @@ export const Modal: FC<ModalProps> = ({
253
264
  // fight over the touch responder, producing repeated press animations and a Confirm button that
254
265
  // never fires. All native devices (phones and tablets) use the ActionSheet presentation.
255
266
  const isMobile = isNative();
267
+ const isNarrow = !isMobile && windowWidth < 480;
256
268
  const sizePx = getModalSize(size);
257
269
 
258
270
  const modalContentProps = {
259
271
  children,
260
272
  isMobile,
273
+ isNarrow,
261
274
  modalTestIDs,
262
275
  onDismiss: handleDismiss,
263
276
  persistOnBackgroundClick,
@@ -321,14 +334,13 @@ export const Modal: FC<ModalProps> = ({
321
334
  justifyContent: "center",
322
335
  }}
323
336
  >
324
- <Pressable
325
- onPress={(e) => {
326
- persistOnBackgroundClick ? null : e.stopPropagation();
327
- }}
337
+ <View
338
+ // Web: nested Pressables bubble DOM clicks to the backdrop dismiss handler.
339
+ {...(Platform.OS === "web" ? {onClick: stopWebClickPropagation} : {})}
328
340
  style={{cursor: "auto"}}
329
341
  >
330
342
  <ModalContent {...modalContentProps}>{children}</ModalContent>
331
- </Pressable>
343
+ </View>
332
344
  </Pressable>
333
345
  </RNModal>
334
346
  );
@@ -1,18 +1,29 @@
1
- import {describe, expect, it, mock} from "bun:test";
2
- import {forwardRef, useRef} from "react";
3
- import {Text, View} from "react-native";
1
+ import {afterEach, beforeEach, describe, expect, it, mock, spyOn} from "bun:test";
2
+ import {act} from "@testing-library/react-native";
3
+ import {assert} from "chai";
4
+ import {createRef, forwardRef, useImperativeHandle, useRef} from "react";
5
+ import {Platform, Modal as RNModal, Text, View} from "react-native";
4
6
 
5
7
  import {SimpleContent, useCombinedRefs} from "./ModalSheet";
6
8
  import {renderWithTheme} from "./test-utils";
9
+ import * as Utilities from "./Utilities";
10
+
11
+ const openMock = mock(() => {});
12
+ const closeMock = mock(() => {});
7
13
 
8
- // Mock react-native-modalize
9
14
  mock.module("react-native-modalize", () => ({
10
15
  Modalize: forwardRef<React.ElementRef<typeof View>, {children: React.ReactNode}>(
11
- ({children}, ref) => (
12
- <View ref={ref} testID="modalize">
13
- {children}
14
- </View>
15
- )
16
+ ({children}, ref) => {
17
+ useImperativeHandle(ref, () => ({
18
+ close: closeMock,
19
+ open: openMock,
20
+ }));
21
+ return (
22
+ <View ref={ref} testID="modalize">
23
+ {children}
24
+ </View>
25
+ );
26
+ }
16
27
  ),
17
28
  }));
18
29
 
@@ -46,4 +57,105 @@ describe("ModalSheet", () => {
46
57
  const {getByTestId} = renderWithTheme(<TestComponent />);
47
58
  expect(getByTestId("combined-ref-view")).toBeTruthy();
48
59
  });
60
+
61
+ it("exposes open and close on the forwarded ref", () => {
62
+ const sheetRef = createRef<{close: () => void; open: () => void}>();
63
+ renderWithTheme(
64
+ <SimpleContent ref={sheetRef}>
65
+ <Text>Sheet body</Text>
66
+ </SimpleContent>
67
+ );
68
+ sheetRef.current?.open();
69
+ sheetRef.current?.close();
70
+ expect(openMock).toHaveBeenCalled();
71
+ expect(closeMock).toHaveBeenCalled();
72
+ });
73
+
74
+ it("useCombinedRefs forwards the node to callback refs, object refs, and skips undefined", () => {
75
+ const callbackRef = mock((_node: View | null) => {});
76
+ const objectRef: {current: View | null} = {current: null};
77
+ const TestComponent = () => {
78
+ const combinedRef = useCombinedRefs<View>(callbackRef, undefined, objectRef);
79
+ return <View ref={combinedRef} testID="combined-ref-view" />;
80
+ };
81
+
82
+ const {getByTestId} = renderWithTheme(<TestComponent />);
83
+ expect(getByTestId("combined-ref-view")).toBeTruthy();
84
+ expect(callbackRef).toHaveBeenCalledTimes(1);
85
+ expect(objectRef.current).toBe(callbackRef.mock.calls[0][0]);
86
+ });
87
+
88
+ it("SimpleContent forwards open and close through a callback ref", () => {
89
+ const forwarded = mock((_handle: {close: () => void; open: () => void} | null) => {});
90
+ renderWithTheme(
91
+ <SimpleContent ref={forwarded}>
92
+ <Text>Test Content</Text>
93
+ </SimpleContent>
94
+ );
95
+ expect(forwarded).toHaveBeenCalledTimes(1);
96
+ });
97
+ });
98
+
99
+ describe("ModalSheet on web", () => {
100
+ const globalScope = globalThis as {document?: unknown; HTMLElement?: unknown};
101
+ const originalOS = Platform.OS;
102
+ const originalDocument = globalScope.document;
103
+ const originalHTMLElement = globalScope.HTMLElement;
104
+
105
+ class FakeHTMLElement {
106
+ blur = mock(() => {});
107
+ }
108
+
109
+ let isNativeSpy: ReturnType<typeof spyOn> | undefined;
110
+
111
+ beforeEach(() => {
112
+ Platform.OS = "web";
113
+ isNativeSpy = spyOn(Utilities, "isNative").mockReturnValue(false);
114
+ globalScope.HTMLElement = FakeHTMLElement;
115
+ globalScope.document = {activeElement: null};
116
+ openMock.mockClear();
117
+ closeMock.mockClear();
118
+ });
119
+
120
+ afterEach(() => {
121
+ isNativeSpy?.mockRestore();
122
+ isNativeSpy = undefined;
123
+ Platform.OS = originalOS;
124
+ globalScope.document = originalDocument;
125
+ globalScope.HTMLElement = originalHTMLElement;
126
+ });
127
+
128
+ it("renders a hidden Modal instead of Modalize", () => {
129
+ const {queryByTestId, UNSAFE_getAllByType} = renderWithTheme(
130
+ <SimpleContent>
131
+ <Text>Web body</Text>
132
+ </SimpleContent>
133
+ );
134
+ assert.isNull(queryByTestId("modalize"));
135
+ const modals = UNSAFE_getAllByType(RNModal);
136
+ assert.lengthOf(modals, 1);
137
+ assert.isFalse(modals[0].props.visible);
138
+ });
139
+
140
+ it("toggles the Modal visibility through the forwarded open and close handles", () => {
141
+ const sheetRef = createRef<{close: () => void; open: () => void}>();
142
+ const {UNSAFE_getAllByType} = renderWithTheme(
143
+ <SimpleContent ref={sheetRef}>
144
+ <Text>Web body</Text>
145
+ </SimpleContent>
146
+ );
147
+
148
+ act(() => {
149
+ sheetRef.current?.open();
150
+ });
151
+ assert.isTrue(UNSAFE_getAllByType(RNModal)[0].props.visible);
152
+
153
+ act(() => {
154
+ sheetRef.current?.close();
155
+ });
156
+ assert.isFalse(UNSAFE_getAllByType(RNModal)[0].props.visible);
157
+
158
+ assert.equal(openMock.mock.calls.length, 0);
159
+ assert.equal(closeMock.mock.calls.length, 0);
160
+ });
49
161
  });
@@ -3,14 +3,24 @@ import {
3
3
  type MutableRefObject,
4
4
  type ReactNode,
5
5
  type Ref,
6
+ useCallback,
6
7
  useEffect,
8
+ useImperativeHandle,
7
9
  useRef,
10
+ useState,
8
11
  } from "react";
9
- import {Animated} from "react-native";
12
+ import {Animated, Platform} from "react-native";
10
13
  import {Modalize} from "react-native-modalize";
11
14
 
15
+ import {Box} from "./Box";
16
+ import {Modal} from "./Modal";
12
17
  import {Portal} from "./PortalHost";
13
18
 
19
+ export interface SimpleContentHandle {
20
+ close: () => void;
21
+ open: () => void;
22
+ }
23
+
14
24
  export const useCombinedRefs = <T,>(
15
25
  ...refs: Array<Ref<T> | undefined>
16
26
  ): MutableRefObject<T | null> => {
@@ -38,24 +48,47 @@ interface Props {
38
48
  children: ReactNode;
39
49
  }
40
50
 
41
- export const SimpleContent = forwardRef((props: Props, ref) => {
42
- const modalizeRef = useRef(null);
43
- const combinedRef = useCombinedRefs(ref, modalizeRef);
51
+ export const SimpleContent = forwardRef<SimpleContentHandle, Props>((props, ref) => {
52
+ const modalizeRef = useRef<SimpleContentHandle | null>(null);
44
53
  const animated = useRef(new Animated.Value(0)).current;
54
+ const [webVisible, setWebVisible] = useState(false);
55
+ const isWeb = Platform.OS === "web";
56
+
57
+ const openSheet = useCallback((): void => {
58
+ if (isWeb) {
59
+ setWebVisible(true);
60
+ return;
61
+ }
62
+ modalizeRef.current?.open();
63
+ }, [isWeb]);
45
64
 
46
- // const renderHeader = () => (
47
- // <Box paddingY={4} marginTop={4} marginBottom={4}>
48
- // <Text>50 users online</Text>
49
- // </Box>
50
- // );
65
+ const closeSheet = useCallback((): void => {
66
+ if (isWeb) {
67
+ setWebVisible(false);
68
+ return;
69
+ }
70
+ modalizeRef.current?.close();
71
+ }, [isWeb]);
72
+
73
+ useImperativeHandle(ref, () => ({
74
+ close: closeSheet,
75
+ open: openSheet,
76
+ }));
77
+
78
+ if (isWeb) {
79
+ return (
80
+ <Modal onDismiss={closeSheet} size="md" visible={webVisible}>
81
+ <Box>{props.children}</Box>
82
+ </Modal>
83
+ );
84
+ }
51
85
 
52
86
  return (
53
87
  <Portal>
54
88
  <Modalize
55
- // HeaderComponent={renderHeader}
56
89
  adjustToContentHeight
57
90
  panGestureAnimatedValue={animated}
58
- ref={combinedRef}
91
+ ref={modalizeRef}
59
92
  scrollViewProps={{
60
93
  showsVerticalScrollIndicator: false,
61
94
  stickyHeaderIndices: [0],
@@ -66,3 +99,5 @@ export const SimpleContent = forwardRef((props: Props, ref) => {
66
99
  </Portal>
67
100
  );
68
101
  });
102
+
103
+ SimpleContent.displayName = "SimpleContent";
@@ -56,6 +56,27 @@ describe("MultiselectField", () => {
56
56
  expect(handleChange).toHaveBeenCalledWith(["b"]);
57
57
  });
58
58
 
59
+ it("uses the latest controlled value when options are toggled in sequence", () => {
60
+ const handleChange = mock((_values: string[]) => {});
61
+ const {getByLabelText, rerender} = renderWithTheme(
62
+ <MultiselectField onChange={handleChange} options={defaultOptions} title="Title" value={[]} />
63
+ );
64
+
65
+ fireEvent.press(getByLabelText("Option A"));
66
+ expect(handleChange).toHaveBeenLastCalledWith(["a"]);
67
+
68
+ rerender(
69
+ <MultiselectField
70
+ onChange={handleChange}
71
+ options={defaultOptions}
72
+ title="Title"
73
+ value={["a"]}
74
+ />
75
+ );
76
+ fireEvent.press(getByLabelText("Option B"));
77
+ expect(handleChange).toHaveBeenLastCalledWith(["a", "b"]);
78
+ });
79
+
59
80
  it("removes option when deselected", () => {
60
81
  const handleChange = mock((_values: string[]) => {});
61
82
  const {getByLabelText} = renderWithTheme(
@@ -1,4 +1,4 @@
1
- import {type FC, useEffect, useState} from "react";
1
+ import {type FC, useCallback} from "react";
2
2
  import {TouchableOpacity, View} from "react-native";
3
3
 
4
4
  import {CheckBox} from "./CheckBox";
@@ -69,19 +69,17 @@ export const MultiselectField: FC<MultiselectFieldProps> = ({
69
69
  const isMobile = isMobileDevice();
70
70
  const isDefault = variant === "leftText";
71
71
  const fieldTestIDs = resolveFieldTestIDsFromProps({testID, testIDs});
72
- const [selectedItems, setSelectedItems] = useState<string[]>(value);
73
- // set the selected items to the value passed in the props
74
- useEffect(() => {
75
- setSelectedItems(value);
76
- }, [value]);
72
+ const selectedItems = value ?? [];
77
73
 
78
- const toggleItem = (item: string) => {
79
- const newSelectedItems = selectedItems.includes(item)
80
- ? selectedItems.filter((selected) => selected !== item)
81
- : [...selectedItems, item];
82
- setSelectedItems(newSelectedItems);
83
- onChange(newSelectedItems);
84
- };
74
+ const toggleItem = useCallback(
75
+ (item: string): void => {
76
+ const newSelectedItems = selectedItems.includes(item)
77
+ ? selectedItems.filter((selected) => selected !== item)
78
+ : [...selectedItems, item];
79
+ onChange(newSelectedItems);
80
+ },
81
+ [onChange, selectedItems]
82
+ );
85
83
  return (
86
84
  <View
87
85
  accessibilityHint="Contains a prompt and list of options to select"
@@ -0,0 +1,91 @@
1
+ import {describe, it} from "bun:test";
2
+ import {fireEvent} from "@testing-library/react-native";
3
+ import {assert} from "chai";
4
+ import {StyleSheet, Text} from "react-native";
5
+
6
+ import {NotificationBell} from "./NotificationBell";
7
+ import {renderWithTheme} from "./test-utils";
8
+
9
+ describe("NotificationBell", () => {
10
+ it("hides the badge when unreadCount is zero", () => {
11
+ const {queryByTestId} = renderWithTheme(
12
+ <NotificationBell onPress={() => {}} testID="bell" unreadCount={0} />
13
+ );
14
+ assert.isNull(queryByTestId("bell-badge"));
15
+ assert.isOk(queryByTestId("bell-button"));
16
+ });
17
+
18
+ it("shows a badge when unreadCount is positive", () => {
19
+ const {getByTestId} = renderWithTheme(
20
+ <NotificationBell onPress={() => {}} testID="bell" unreadCount={3} />
21
+ );
22
+ assert.isOk(getByTestId("bell-button"));
23
+ assert.isOk(getByTestId("bell-badge"));
24
+ assert.include(StyleSheet.flatten(getByTestId("bell").props.style), {
25
+ position: "relative",
26
+ });
27
+ assert.equal(
28
+ StyleSheet.flatten(getByTestId("bell-badge-container").props.style).pointerEvents,
29
+ "none"
30
+ );
31
+ });
32
+
33
+ it("keeps the badge inside the bell bounds so ancestors cannot clip it", () => {
34
+ const {getByTestId} = renderWithTheme(
35
+ <NotificationBell onPress={() => {}} testID="bell" unreadCount={3} />
36
+ );
37
+
38
+ const wrapper = StyleSheet.flatten(getByTestId("bell").props.style);
39
+ const badgeContainer = StyleSheet.flatten(getByTestId("bell-badge-container").props.style);
40
+
41
+ assert.isAtLeast(Number(wrapper.width), 40);
42
+ assert.isAtLeast(Number(wrapper.height), 40);
43
+ assert.include(badgeContainer, {position: "absolute", right: 0, top: 0});
44
+ });
45
+
46
+ it("announces the unread count to assistive technology", () => {
47
+ const {getByTestId, rerender} = renderWithTheme(
48
+ <NotificationBell onPress={() => {}} testID="bell" unreadCount={1} />
49
+ );
50
+ assert.equal(
51
+ getByTestId("bell-button").props.accessibilityLabel,
52
+ "Notifications, 1 unread notification"
53
+ );
54
+
55
+ rerender(<NotificationBell onPress={() => {}} testID="bell" unreadCount={0} />);
56
+ assert.equal(getByTestId("bell-button").props.accessibilityLabel, "Notifications");
57
+ });
58
+
59
+ it("calls onPress when tapped", () => {
60
+ let pressed = false;
61
+ const {getByTestId} = renderWithTheme(
62
+ <NotificationBell
63
+ onPress={() => {
64
+ pressed = true;
65
+ }}
66
+ testID="bell"
67
+ unreadCount={2}
68
+ />
69
+ );
70
+ fireEvent.press(getByTestId("bell-button"));
71
+ assert.isTrue(pressed);
72
+ });
73
+
74
+ it("passes stable props to custom icon and badge renderers", () => {
75
+ const {getByTestId, getByText, queryByTestId} = renderWithTheme(
76
+ <NotificationBell
77
+ onPress={() => {}}
78
+ renderBadge={({testID, unreadCount}) => <Text testID={testID}>{unreadCount} custom</Text>}
79
+ renderIcon={({testID}) => <Text testID={testID}>Custom icon</Text>}
80
+ testID="bell"
81
+ unreadCount={7}
82
+ />
83
+ );
84
+
85
+ assert.isOk(getByTestId("bell-icon"));
86
+ assert.isOk(getByTestId("bell-badge"));
87
+ assert.isOk(getByText("Custom icon"));
88
+ assert.isOk(getByText("7 custom"));
89
+ assert.isNull(queryByTestId("badge-text"));
90
+ });
91
+ });