@terreno/ui 57.2.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.
- package/.ai/guidelines/core.md +1 -1
- package/README.md +17 -8
- package/dist/ActionSheet.d.ts +3 -3
- package/dist/ActionSheet.js +2 -2
- package/dist/ActionSheet.js.map +1 -1
- package/dist/AnnouncementBanner.d.ts +12 -0
- package/dist/AnnouncementBanner.js +61 -0
- package/dist/AnnouncementBanner.js.map +1 -0
- package/dist/AnnouncementNavigator.d.ts +11 -0
- package/dist/AnnouncementNavigator.js +189 -0
- package/dist/AnnouncementNavigator.js.map +1 -0
- package/dist/AnnouncementScreen.d.ts +12 -0
- package/dist/AnnouncementScreen.js +28 -0
- package/dist/AnnouncementScreen.js.map +1 -0
- package/dist/AreaChart.d.ts +5 -0
- package/dist/AreaChart.js +69 -0
- package/dist/AreaChart.js.map +1 -0
- package/dist/BarChart.d.ts +5 -0
- package/dist/BarChart.js +89 -0
- package/dist/BarChart.js.map +1 -0
- package/dist/Box.d.ts +1 -1
- package/dist/Box.js +219 -177
- package/dist/Box.js.map +1 -1
- package/dist/Button.js +116 -35
- package/dist/Button.js.map +1 -1
- package/dist/Common.d.ts +215 -9
- package/dist/Common.js.map +1 -1
- package/dist/ConsentFormScreen.js +46 -12
- package/dist/ConsentFormScreen.js.map +1 -1
- package/dist/ConsentNavigator.d.ts +5 -1
- package/dist/ConsentNavigator.js.map +1 -1
- package/dist/DashboardGrid.d.ts +4 -0
- package/dist/DashboardGrid.js +38 -0
- package/dist/DashboardGrid.js.map +1 -0
- package/dist/DataTable.d.ts +2 -2
- package/dist/DataTable.js +278 -47
- package/dist/DataTable.js.map +1 -1
- package/dist/DataTableHeaderInfoMarkdown.d.ts +6 -0
- package/dist/DataTableHeaderInfoMarkdown.js +7 -0
- package/dist/DataTableHeaderInfoMarkdown.js.map +1 -0
- package/dist/DonutChart.d.ts +5 -0
- package/dist/DonutChart.js +84 -0
- package/dist/DonutChart.js.map +1 -0
- package/dist/EmojiSelector.d.ts +2 -46
- package/dist/EmojiSelector.js +46 -56
- package/dist/EmojiSelector.js.map +1 -1
- package/dist/Filter.js +12 -2
- package/dist/Filter.js.map +1 -1
- package/dist/GPTChat.d.ts +7 -1
- package/dist/GPTChat.js +28 -15
- package/dist/GPTChat.js.map +1 -1
- package/dist/Heading.d.ts +5 -2
- package/dist/Heading.js +6 -8
- package/dist/Heading.js.map +1 -1
- package/dist/Hyperlink.js.map +1 -1
- package/dist/Icon.d.ts +1 -2
- package/dist/Icon.js +4 -1
- package/dist/Icon.js.map +1 -1
- package/dist/LineChart.d.ts +5 -0
- package/dist/LineChart.js +68 -0
- package/dist/LineChart.js.map +1 -0
- package/dist/MarkdownEmbed.d.ts +6 -0
- package/dist/MarkdownEmbed.js +17 -0
- package/dist/MarkdownEmbed.js.map +1 -0
- package/dist/MarkdownView.d.ts +6 -3
- package/dist/MarkdownView.js +81 -44
- package/dist/MarkdownView.js.map +1 -1
- package/dist/MediaQuery.d.ts +5 -3
- package/dist/MediaQuery.js +9 -40
- package/dist/MediaQuery.js.map +1 -1
- package/dist/Modal.js +12 -10
- package/dist/Modal.js.map +1 -1
- package/dist/ModalSheet.d.ts +5 -1
- package/dist/ModalSheet.js +31 -13
- package/dist/ModalSheet.js.map +1 -1
- package/dist/MultiselectField.js +4 -9
- package/dist/MultiselectField.js.map +1 -1
- package/dist/NotificationBell.d.ts +16 -0
- package/dist/NotificationBell.js +15 -0
- package/dist/NotificationBell.js.map +1 -0
- package/dist/NotificationInbox.d.ts +21 -0
- package/dist/NotificationInbox.js +41 -0
- package/dist/NotificationInbox.js.map +1 -0
- package/dist/NotificationPreferences.d.ts +14 -0
- package/dist/NotificationPreferences.js +32 -0
- package/dist/NotificationPreferences.js.map +1 -0
- package/dist/OpenAPIContext.js +7 -6
- package/dist/OpenAPIContext.js.map +1 -1
- package/dist/Page.js +7 -1
- package/dist/Page.js.map +1 -1
- package/dist/PickerSelect.js +8 -1
- package/dist/PickerSelect.js.map +1 -1
- package/dist/Popover.d.ts +12 -0
- package/dist/Popover.js +37 -0
- package/dist/Popover.js.map +1 -0
- package/dist/PortalHost.js +10 -1
- package/dist/PortalHost.js.map +1 -1
- package/dist/ResponsiveBreakpoint.d.ts +65 -0
- package/dist/ResponsiveBreakpoint.js +111 -0
- package/dist/ResponsiveBreakpoint.js.map +1 -0
- package/dist/SplitPage.d.ts +2 -2
- package/dist/SplitPage.js +7 -12
- package/dist/SplitPage.js.map +1 -1
- package/dist/SplitPage.native.d.ts +2 -2
- package/dist/SplitPage.native.js +1 -6
- package/dist/SplitPage.native.js.map +1 -1
- package/dist/TapToEdit.js +12 -10
- package/dist/TapToEdit.js.map +1 -1
- package/dist/TerrenoFontProvider.d.ts +7 -0
- package/dist/TerrenoFontProvider.js +27 -0
- package/dist/TerrenoFontProvider.js.map +1 -0
- package/dist/TerrenoProvider.js +4 -2
- package/dist/TerrenoProvider.js.map +1 -1
- package/dist/Text.d.ts +5 -2
- package/dist/Text.js +6 -11
- package/dist/Text.js.map +1 -1
- package/dist/TextField.js +83 -6
- package/dist/TextField.js.map +1 -1
- package/dist/TextFieldNumberActionSheet.js +9 -2
- package/dist/TextFieldNumberActionSheet.js.map +1 -1
- package/dist/Theme.js +10 -8
- package/dist/Theme.js.map +1 -1
- package/dist/ToastNotifications.d.ts +4 -2
- package/dist/ToastNotifications.js.map +1 -1
- package/dist/Tooltip.d.ts +4 -3
- package/dist/Tooltip.js +14 -3
- package/dist/Tooltip.js.map +1 -1
- package/dist/Unifier.d.ts +26 -1
- package/dist/Unifier.js.map +1 -1
- package/dist/WebAddressAutocomplete.js +6 -1
- package/dist/WebAddressAutocomplete.js.map +1 -1
- package/dist/announcementBuildVersion.d.ts +6 -0
- package/dist/announcementBuildVersion.js +21 -0
- package/dist/announcementBuildVersion.js.map +1 -0
- package/dist/announcementFrequency.d.ts +42 -0
- package/dist/announcementFrequency.js +163 -0
- package/dist/announcementFrequency.js.map +1 -0
- package/dist/announcementPlatform.d.ts +2 -0
- package/dist/announcementPlatform.js +11 -0
- package/dist/announcementPlatform.js.map +1 -0
- package/dist/charts/ChartFrame.d.ts +12 -0
- package/dist/charts/ChartFrame.js +13 -0
- package/dist/charts/ChartFrame.js.map +1 -0
- package/dist/charts/bars.d.ts +18 -0
- package/dist/charts/bars.js +29 -0
- package/dist/charts/bars.js.map +1 -0
- package/dist/charts/layout.d.ts +47 -0
- package/dist/charts/layout.js +56 -0
- package/dist/charts/layout.js.map +1 -0
- package/dist/charts/paths.d.ts +31 -0
- package/dist/charts/paths.js +52 -0
- package/dist/charts/paths.js.map +1 -0
- package/dist/charts/scales.d.ts +6 -0
- package/dist/charts/scales.js +43 -0
- package/dist/charts/scales.js.map +1 -0
- package/dist/charts/theme.d.ts +9 -0
- package/dist/charts/theme.js +15 -0
- package/dist/charts/theme.js.map +1 -0
- package/dist/charts/types/chartTypes.d.ts +17 -0
- package/dist/charts/types/chartTypes.js +2 -0
- package/dist/charts/types/chartTypes.js.map +1 -0
- package/dist/dashboardGridLayout.d.ts +22 -0
- package/dist/dashboardGridLayout.js +33 -0
- package/dist/dashboardGridLayout.js.map +1 -0
- package/dist/dataTableFilters.d.ts +33 -0
- package/dist/dataTableFilters.js +221 -0
- package/dist/dataTableFilters.js.map +1 -0
- package/dist/dataTableListQuery.d.ts +42 -0
- package/dist/dataTableListQuery.js +161 -0
- package/dist/dataTableListQuery.js.map +1 -0
- package/dist/emojiCategories.d.ts +46 -0
- package/dist/emojiCategories.js +47 -0
- package/dist/emojiCategories.js.map +1 -0
- package/dist/index.d.ts +30 -13
- package/dist/index.js +12 -13
- package/dist/index.js.map +1 -1
- package/dist/lazyBoundaries/createLazyComponentExport.d.ts +6 -0
- package/dist/lazyBoundaries/createLazyComponentExport.js +35 -0
- package/dist/lazyBoundaries/createLazyComponentExport.js.map +1 -0
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts +53 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js +51 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -0
- package/dist/login/LoginScreen.d.ts +1 -0
- package/dist/login/LoginScreen.js +4 -2
- package/dist/login/LoginScreen.js.map +1 -1
- package/dist/login/loginTypes.d.ts +2 -0
- package/dist/markdownEmbeds.d.ts +6 -0
- package/dist/markdownEmbeds.js +59 -0
- package/dist/markdownEmbeds.js.map +1 -0
- package/dist/testing/resolveTestId.js +2 -1
- package/dist/testing/resolveTestId.js.map +1 -1
- package/dist/testing/types.d.ts +3 -0
- package/dist/textFieldOscillationGuard.d.ts +25 -0
- package/dist/textFieldOscillationGuard.js +41 -0
- package/dist/textFieldOscillationGuard.js.map +1 -0
- package/dist/useAcknowledgeAnnouncement.d.ts +71 -0
- package/dist/useAcknowledgeAnnouncement.js +94 -0
- package/dist/useAcknowledgeAnnouncement.js.map +1 -0
- package/dist/useAnnouncements.d.ts +73 -0
- package/dist/useAnnouncements.js +66 -0
- package/dist/useAnnouncements.js.map +1 -0
- package/package.json +46 -18
- package/src/AIRequestExplorer.test.tsx +141 -0
- package/src/ActionSheet.tsx +9 -7
- package/src/AnnouncementBanner.test.tsx +267 -0
- package/src/AnnouncementBanner.tsx +128 -0
- package/src/AnnouncementNavigator.test.tsx +759 -0
- package/src/AnnouncementNavigator.tsx +287 -0
- package/src/AnnouncementScreen.test.tsx +97 -0
- package/src/AnnouncementScreen.tsx +70 -0
- package/src/AreaChart.test.tsx +68 -0
- package/src/AreaChart.tsx +194 -0
- package/src/AttachmentPreview.test.tsx +80 -0
- package/src/BarChart.test.tsx +96 -0
- package/src/BarChart.tsx +208 -0
- package/src/Box.test.tsx +97 -10
- package/src/Box.tsx +263 -200
- package/src/Button.test.tsx +273 -0
- package/src/Button.tsx +163 -50
- package/src/Common.ts +219 -25
- package/src/ConsentFormScreen.markdownGate.test.tsx +129 -0
- package/src/ConsentFormScreen.test.tsx +145 -8
- package/src/ConsentFormScreen.tsx +74 -25
- package/src/ConsentNavigator.test.tsx +55 -0
- package/src/ConsentNavigator.tsx +13 -5
- package/src/DashboardGrid.test.tsx +75 -0
- package/src/DashboardGrid.tsx +69 -0
- package/src/DataTable.test.tsx +296 -1
- package/src/DataTable.tsx +623 -160
- package/src/DataTableHeaderInfoMarkdown.test.tsx +21 -0
- package/src/DataTableHeaderInfoMarkdown.tsx +17 -0
- package/src/DataTableVirtualizationRegression.test.tsx +266 -0
- package/src/DateTimeField.test.tsx +54 -0
- package/src/DonutChart.test.tsx +121 -0
- package/src/DonutChart.tsx +160 -0
- package/src/EmojiSelector.test.tsx +84 -42
- package/src/EmojiSelector.tsx +60 -57
- package/src/Field.test.tsx +18 -0
- package/src/FilePickerButton.test.tsx +167 -0
- package/src/Filter.test.tsx +25 -0
- package/src/Filter.tsx +38 -7
- package/src/FilterAccordion.test.tsx +37 -0
- package/src/FilterBoolean.test.tsx +96 -0
- package/src/FilterSelectMenu.test.tsx +23 -0
- package/src/GPTChat.test.tsx +803 -0
- package/src/GPTChat.tsx +177 -87
- package/src/GPTMemoryModal.test.tsx +67 -0
- package/src/Heading.tsx +8 -14
- package/src/HeightActionSheet.test.tsx +6 -9
- package/src/Hyperlink.tsx +5 -18
- package/src/Icon.tsx +6 -2
- package/src/LineChart.test.tsx +166 -0
- package/src/LineChart.tsx +190 -0
- package/src/MarkdownEditor.test.tsx +134 -0
- package/src/MarkdownEditorField.test.tsx +124 -0
- package/src/MarkdownEmbed.test.tsx +34 -0
- package/src/MarkdownEmbed.tsx +43 -0
- package/src/MarkdownView.test.tsx +112 -11
- package/src/MarkdownView.tsx +197 -150
- package/src/MediaQuery.ts +30 -34
- package/src/Modal.test.tsx +107 -14
- package/src/Modal.tsx +20 -8
- package/src/ModalSheet.test.tsx +121 -9
- package/src/ModalSheet.tsx +46 -11
- package/src/MultiselectField.test.tsx +21 -0
- package/src/MultiselectField.tsx +11 -13
- package/src/NotificationBell.test.tsx +91 -0
- package/src/NotificationBell.tsx +77 -0
- package/src/NotificationInbox.test.tsx +130 -0
- package/src/NotificationInbox.tsx +144 -0
- package/src/NotificationPreferences.test.tsx +25 -0
- package/src/NotificationPreferences.tsx +75 -0
- package/src/OpenAPIContext.tsx +36 -29
- package/src/OpenAPIRenderRegression.test.tsx +200 -0
- package/src/P0RenderRegression.test.tsx +214 -0
- package/src/P1RenderRegression.test.tsx +141 -0
- package/src/P2ButtonRenderRegression.test.tsx +158 -0
- package/src/Page.test.tsx +13 -0
- package/src/Page.tsx +25 -5
- package/src/PickerSelect.test.tsx +38 -0
- package/src/PickerSelect.tsx +7 -0
- package/src/Popover.test.tsx +151 -0
- package/src/Popover.tsx +211 -0
- package/src/PortalHost.tsx +12 -6
- package/src/ResponsiveBreakpoint.test.tsx +184 -0
- package/src/ResponsiveBreakpoint.tsx +195 -0
- package/src/RootImportRegression.test.tsx +82 -0
- package/src/SplitPage.native.tsx +5 -9
- package/src/SplitPage.tsx +16 -19
- package/src/TapToEdit.test.tsx +45 -0
- package/src/TapToEdit.tsx +23 -18
- package/src/TerrenoFontProvider.test.tsx +38 -0
- package/src/TerrenoFontProvider.tsx +50 -0
- package/src/TerrenoProvider.tsx +6 -1
- package/src/Text.tsx +8 -21
- package/src/TextField.test.tsx +421 -0
- package/src/TextField.tsx +121 -4
- package/src/TextFieldNumberActionSheet.test.tsx +100 -0
- package/src/TextFieldNumberActionSheet.tsx +11 -2
- package/src/Theme.test.tsx +27 -0
- package/src/Theme.tsx +15 -10
- package/src/Toast.tsx +1 -1
- package/src/ToastNotifications.tsx +4 -4
- package/src/Tooltip.test.tsx +64 -0
- package/src/Tooltip.tsx +18 -4
- package/src/Unifier.ts +26 -3
- package/src/WebAddressAutocomplete.tsx +6 -2
- package/src/__snapshots__/ActionSheet.test.tsx.snap +0 -36
- package/src/__snapshots__/AddressField.test.tsx.snap +1 -0
- package/src/__snapshots__/AttachmentPreview.test.tsx.snap +225 -0
- package/src/__snapshots__/CustomSelectField.test.tsx.snap +7 -0
- package/src/__snapshots__/DataTable.test.tsx.snap +793 -250
- package/src/__snapshots__/DecimalRangeActionSheet.test.tsx.snap +0 -8
- package/src/__snapshots__/EmojiSelector.test.tsx.snap +35555 -30
- package/src/__snapshots__/Field.test.tsx.snap +29 -0
- package/src/__snapshots__/FilterSelectMenu.test.tsx.snap +1 -0
- package/src/__snapshots__/HeightActionSheet.test.tsx.snap +0 -8
- package/src/__snapshots__/HeightField.test.tsx.snap +0 -20
- package/src/__snapshots__/ModalSheet.test.tsx.snap +4 -1
- package/src/__snapshots__/NumberPickerActionSheet.test.tsx.snap +0 -8
- package/src/__snapshots__/Page.test.tsx.snap +13 -1
- package/src/__snapshots__/PickerSelect.test.tsx.snap +7 -0
- package/src/__snapshots__/SelectField.test.tsx.snap +6 -0
- package/src/__snapshots__/TextArea.test.tsx.snap +5 -5
- package/src/__snapshots__/TextField.test.tsx.snap +5 -5
- package/src/__snapshots__/TimezonePicker.test.tsx.snap +6 -0
- package/src/announcementBuildVersion.test.ts +43 -0
- package/src/announcementBuildVersion.ts +21 -0
- package/src/announcementFrequency.test.ts +245 -0
- package/src/announcementFrequency.ts +246 -0
- package/src/announcementPlatform.test.ts +27 -0
- package/src/announcementPlatform.ts +13 -0
- package/src/benchmarks/importGraph.test.ts +71 -0
- package/src/benchmarks/importGraph.ts +136 -0
- package/src/benchmarks/importTiming.test.ts +42 -0
- package/src/benchmarks/importTiming.ts +86 -0
- package/src/bunSetup.ts +174 -32
- package/src/charts/ChartFrame.tsx +67 -0
- package/src/charts/bars.test.ts +56 -0
- package/src/charts/bars.ts +53 -0
- package/src/charts/layout.test.ts +80 -0
- package/src/charts/layout.ts +99 -0
- package/src/charts/paths.test.ts +79 -0
- package/src/charts/paths.ts +100 -0
- package/src/charts/scales.test.ts +59 -0
- package/src/charts/scales.ts +60 -0
- package/src/charts/theme.test.ts +22 -0
- package/src/charts/theme.ts +24 -0
- package/src/charts/types/chartTypes.ts +19 -0
- package/src/dashboardGridLayout.test.ts +90 -0
- package/src/dashboardGridLayout.ts +60 -0
- package/src/dataTableFilters.test.tsx +552 -0
- package/src/dataTableFilters.tsx +441 -0
- package/src/dataTableListQuery.test.ts +220 -0
- package/src/dataTableListQuery.ts +201 -0
- package/src/emojiCategories.test.ts +23 -0
- package/src/emojiCategories.ts +46 -0
- package/src/index.tsx +48 -14
- package/src/lazyBoundaries/createLazyComponentExport.test.tsx +104 -0
- package/src/lazyBoundaries/createLazyComponentExport.tsx +63 -0
- package/src/lazyBoundaries/heavyOptionalExports.test.tsx +33 -0
- package/src/lazyBoundaries/heavyOptionalExports.tsx +134 -0
- package/src/login/LoginScreen.test.tsx +9 -2
- package/src/login/LoginScreen.tsx +6 -2
- package/src/login/__snapshots__/LoginScreen.test.tsx.snap +22 -0
- package/src/login/loginTypes.ts +2 -0
- package/src/markdownEmbeds.test.ts +53 -0
- package/src/markdownEmbeds.ts +62 -0
- package/src/pdfHtmlTemplate.test.ts +119 -0
- package/src/signUp/__snapshots__/SignUpScreen.test.tsx.snap +22 -0
- package/src/table/TableDate.test.tsx +35 -1
- package/src/table/__snapshots__/TableBadge.test.tsx.snap +1 -0
- package/src/testing/resolveTestId.test.ts +3 -0
- package/src/testing/resolveTestId.ts +1 -0
- package/src/testing/types.ts +3 -0
- package/src/textFieldOscillationGuard.test.ts +63 -0
- package/src/textFieldOscillationGuard.ts +89 -0
- package/src/types/react-native-markdown-display.d.ts +6 -0
- package/src/types/react-native-swiper-flatlist.d.ts +5 -5
- package/src/useAcknowledgeAnnouncement.test.ts +223 -0
- package/src/useAcknowledgeAnnouncement.ts +166 -0
- package/src/useAnnouncements.test.ts +226 -0
- package/src/useAnnouncements.ts +150 -0
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
import {act, fireEvent, render} from "@testing-library/react-native";
|
|
2
|
+
import {assert} from "chai";
|
|
3
|
+
import type React from "react";
|
|
4
|
+
import {useEffect} from "react";
|
|
5
|
+
import {View} from "react-native";
|
|
6
|
+
|
|
7
|
+
import {Button} from "./Button";
|
|
8
|
+
import type {CustomIconProps, IconRegistryMap} from "./Common";
|
|
9
|
+
import {IconRegistryProvider} from "./IconRegistry";
|
|
10
|
+
import {ThemeProvider, useTheme} from "./Theme";
|
|
11
|
+
|
|
12
|
+
interface ThemeMutationProps {
|
|
13
|
+
surfaceSecondaryDark: "secondary800" | "error100";
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
const handlePress = async (): Promise<void> => {};
|
|
17
|
+
|
|
18
|
+
const ThemeMutation: React.FC<ThemeMutationProps> = ({surfaceSecondaryDark}) => {
|
|
19
|
+
const {setTheme, theme} = useTheme();
|
|
20
|
+
|
|
21
|
+
// Drive the theme from props so memoized buttons must still follow context updates.
|
|
22
|
+
useEffect((): void => {
|
|
23
|
+
const desiredColor = surfaceSecondaryDark === "secondary800" ? "#092E3A" : "#D33232";
|
|
24
|
+
if (theme.surface.secondaryDark === desiredColor) {
|
|
25
|
+
return;
|
|
26
|
+
}
|
|
27
|
+
setTheme({surface: {secondaryDark: surfaceSecondaryDark}});
|
|
28
|
+
}, [setTheme, surfaceSecondaryDark, theme.surface.secondaryDark]);
|
|
29
|
+
|
|
30
|
+
return null;
|
|
31
|
+
};
|
|
32
|
+
|
|
33
|
+
describe("P2 Button rerender regression coverage", () => {
|
|
34
|
+
it("skips equivalent renders and preserves changed button props", () => {
|
|
35
|
+
let renderCount = 0;
|
|
36
|
+
const CountedIcon: React.FC<CustomIconProps> = ({color, size, testID}) => {
|
|
37
|
+
renderCount += 1;
|
|
38
|
+
return <View accessibilityLabel={`${color}:${size}`} testID={testID} />;
|
|
39
|
+
};
|
|
40
|
+
const icons: IconRegistryMap = {testCustomIcon: CountedIcon};
|
|
41
|
+
const result = render(
|
|
42
|
+
<ThemeProvider>
|
|
43
|
+
<IconRegistryProvider icons={icons}>
|
|
44
|
+
<Button
|
|
45
|
+
iconName="testCustomIcon"
|
|
46
|
+
onClick={handlePress}
|
|
47
|
+
testID="counted-button"
|
|
48
|
+
text="Initial"
|
|
49
|
+
/>
|
|
50
|
+
</IconRegistryProvider>
|
|
51
|
+
</ThemeProvider>
|
|
52
|
+
);
|
|
53
|
+
|
|
54
|
+
assert.equal(renderCount, 1);
|
|
55
|
+
result.rerender(
|
|
56
|
+
<ThemeProvider>
|
|
57
|
+
<IconRegistryProvider icons={icons}>
|
|
58
|
+
<Button
|
|
59
|
+
iconName="testCustomIcon"
|
|
60
|
+
onClick={handlePress}
|
|
61
|
+
testID="counted-button"
|
|
62
|
+
text="Initial"
|
|
63
|
+
/>
|
|
64
|
+
</IconRegistryProvider>
|
|
65
|
+
</ThemeProvider>
|
|
66
|
+
);
|
|
67
|
+
assert.equal(renderCount, 1);
|
|
68
|
+
|
|
69
|
+
result.rerender(
|
|
70
|
+
<ThemeProvider>
|
|
71
|
+
<IconRegistryProvider icons={icons}>
|
|
72
|
+
<Button
|
|
73
|
+
iconName="testCustomIcon"
|
|
74
|
+
onClick={handlePress}
|
|
75
|
+
testID="counted-button"
|
|
76
|
+
text="Changed"
|
|
77
|
+
/>
|
|
78
|
+
</IconRegistryProvider>
|
|
79
|
+
</ThemeProvider>
|
|
80
|
+
);
|
|
81
|
+
assert.equal(renderCount, 2);
|
|
82
|
+
assert.exists(result.getByText("Changed"));
|
|
83
|
+
assert.isNull(result.queryByText("Initial"));
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
it("propagates theme changes through the memoized Button boundary", async () => {
|
|
87
|
+
const ThemeAwareIcon: React.FC<CustomIconProps> = ({color, testID}) => {
|
|
88
|
+
return <View accessibilityLabel={color} testID={testID} />;
|
|
89
|
+
};
|
|
90
|
+
const icons: IconRegistryMap = {testCustomIcon: ThemeAwareIcon};
|
|
91
|
+
const result = render(
|
|
92
|
+
<ThemeProvider>
|
|
93
|
+
<ThemeMutation surfaceSecondaryDark="secondary800" />
|
|
94
|
+
<IconRegistryProvider icons={icons}>
|
|
95
|
+
<Button
|
|
96
|
+
iconName="testCustomIcon"
|
|
97
|
+
onClick={handlePress}
|
|
98
|
+
testID="themed-button"
|
|
99
|
+
text="Themed"
|
|
100
|
+
variant="ghost"
|
|
101
|
+
/>
|
|
102
|
+
</IconRegistryProvider>
|
|
103
|
+
</ThemeProvider>
|
|
104
|
+
);
|
|
105
|
+
const initialColor = result.UNSAFE_getByType(ThemeAwareIcon).props.color;
|
|
106
|
+
|
|
107
|
+
result.rerender(
|
|
108
|
+
<ThemeProvider>
|
|
109
|
+
<ThemeMutation surfaceSecondaryDark="error100" />
|
|
110
|
+
<IconRegistryProvider icons={icons}>
|
|
111
|
+
<Button
|
|
112
|
+
iconName="testCustomIcon"
|
|
113
|
+
onClick={handlePress}
|
|
114
|
+
testID="themed-button"
|
|
115
|
+
text="Themed"
|
|
116
|
+
variant="ghost"
|
|
117
|
+
/>
|
|
118
|
+
</IconRegistryProvider>
|
|
119
|
+
</ThemeProvider>
|
|
120
|
+
);
|
|
121
|
+
await act(async (): Promise<void> => {});
|
|
122
|
+
|
|
123
|
+
const changedColor = result.UNSAFE_getByType(ThemeAwareIcon).props.color;
|
|
124
|
+
assert.notEqual(changedColor, initialColor);
|
|
125
|
+
assert.equal(changedColor, "#D33232");
|
|
126
|
+
});
|
|
127
|
+
|
|
128
|
+
it("uses the latest confirmation props after a changed-prop update", async () => {
|
|
129
|
+
const result = render(
|
|
130
|
+
<ThemeProvider>
|
|
131
|
+
<Button
|
|
132
|
+
confirmationText="Initial confirmation"
|
|
133
|
+
onClick={handlePress}
|
|
134
|
+
text="Confirm"
|
|
135
|
+
withConfirmation
|
|
136
|
+
/>
|
|
137
|
+
</ThemeProvider>
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
result.rerender(
|
|
141
|
+
<ThemeProvider>
|
|
142
|
+
<Button
|
|
143
|
+
confirmationText="Changed confirmation"
|
|
144
|
+
onClick={handlePress}
|
|
145
|
+
text="Confirm"
|
|
146
|
+
withConfirmation
|
|
147
|
+
/>
|
|
148
|
+
</ThemeProvider>
|
|
149
|
+
);
|
|
150
|
+
await act(async () => {
|
|
151
|
+
fireEvent.press(result.getByText("Confirm"));
|
|
152
|
+
await Promise.resolve();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
assert.exists(await result.findByText("Changed confirmation"));
|
|
156
|
+
assert.isNull(result.queryByText("Initial confirmation"));
|
|
157
|
+
});
|
|
158
|
+
});
|
package/src/Page.test.tsx
CHANGED
|
@@ -263,6 +263,19 @@ describe("Page", () => {
|
|
|
263
263
|
expect(routerBack).toHaveBeenCalled();
|
|
264
264
|
});
|
|
265
265
|
|
|
266
|
+
it("invokes onBack instead of router.back when provided", () => {
|
|
267
|
+
const onBack = mock(() => {});
|
|
268
|
+
routerBack.mockClear();
|
|
269
|
+
const {getByTestId} = renderWithTheme(
|
|
270
|
+
<Page backButton navigation={mockNavigation} onBack={onBack} title="Page">
|
|
271
|
+
<Text>Content</Text>
|
|
272
|
+
</Page>
|
|
273
|
+
);
|
|
274
|
+
fireEvent.press(getByTestId("icon-button-chevron-left"));
|
|
275
|
+
expect(onBack).toHaveBeenCalled();
|
|
276
|
+
expect(routerBack).not.toHaveBeenCalled();
|
|
277
|
+
});
|
|
278
|
+
|
|
266
279
|
it("invokes router.back when the close button is pressed", () => {
|
|
267
280
|
routerBack.mockClear();
|
|
268
281
|
const {getByTestId} = renderWithTheme(
|
package/src/Page.tsx
CHANGED
|
@@ -20,14 +20,28 @@ export class Page extends React.Component<PageProps, {}> {
|
|
|
20
20
|
return null;
|
|
21
21
|
}
|
|
22
22
|
return (
|
|
23
|
-
<Box direction="row" display="flex" width="100%">
|
|
23
|
+
<Box direction="row" display="flex" position="relative" width="100%">
|
|
24
24
|
{this.props.backButton && (
|
|
25
|
-
<Box
|
|
25
|
+
<Box
|
|
26
|
+
alignItems="center"
|
|
27
|
+
display="block"
|
|
28
|
+
justifyContent="center"
|
|
29
|
+
paddingX={4}
|
|
30
|
+
paddingY={3}
|
|
31
|
+
position="relative"
|
|
32
|
+
zIndex={1}
|
|
33
|
+
>
|
|
26
34
|
<IconButton
|
|
27
35
|
accessibilityHint="Navigate back"
|
|
28
|
-
accessibilityLabel=""
|
|
36
|
+
accessibilityLabel="Back"
|
|
29
37
|
iconName="chevron-left"
|
|
30
|
-
onClick={() =>
|
|
38
|
+
onClick={() => {
|
|
39
|
+
if (this.props.onBack) {
|
|
40
|
+
this.props.onBack();
|
|
41
|
+
return;
|
|
42
|
+
}
|
|
43
|
+
router.back();
|
|
44
|
+
}}
|
|
31
45
|
/>
|
|
32
46
|
</Box>
|
|
33
47
|
)}
|
|
@@ -42,7 +56,13 @@ export class Page extends React.Component<PageProps, {}> {
|
|
|
42
56
|
</Box>
|
|
43
57
|
)}
|
|
44
58
|
{Boolean(this.props.title) && (
|
|
45
|
-
<Box
|
|
59
|
+
<Box
|
|
60
|
+
dangerouslySetInlineStyle={{__style: {pointerEvents: "box-none"}}}
|
|
61
|
+
direction="column"
|
|
62
|
+
display="flex"
|
|
63
|
+
flex="grow"
|
|
64
|
+
justifyContent="center"
|
|
65
|
+
>
|
|
46
66
|
<Heading align="center">{this.props.title}</Heading>
|
|
47
67
|
</Box>
|
|
48
68
|
)}
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
import {describe, expect, it, mock} from "bun:test";
|
|
2
2
|
import {act, fireEvent} from "@testing-library/react-native";
|
|
3
3
|
import {assert} from "chai";
|
|
4
|
+
import {StyleSheet} from "react-native";
|
|
4
5
|
import type {ReactTestInstance} from "react-test-renderer";
|
|
5
6
|
|
|
6
7
|
import {RNPickerSelect} from "./PickerSelect";
|
|
@@ -522,6 +523,43 @@ describe("PickerSelect", () => {
|
|
|
522
523
|
}
|
|
523
524
|
});
|
|
524
525
|
|
|
526
|
+
// A trigger label that cannot shrink below its intrinsic width overflows narrow
|
|
527
|
+
// fields (e.g. the am/pm and timezone pickers in DateTimeField) and pushes the
|
|
528
|
+
// chevron outside the field border.
|
|
529
|
+
it("lets the searchable trigger input shrink inside a narrow field", () => {
|
|
530
|
+
ensureDocument();
|
|
531
|
+
savedOS = PlatformModule.OS;
|
|
532
|
+
try {
|
|
533
|
+
PlatformModule.OS = "web";
|
|
534
|
+
const {getByTestId} = renderWithTheme(
|
|
535
|
+
<RNPickerSelect {...searchEnabledWebProps} value="1" />
|
|
536
|
+
);
|
|
537
|
+
const style = StyleSheet.flatten(getByTestId("text_input").props.style);
|
|
538
|
+
expect(style.minWidth).toBe(0);
|
|
539
|
+
expect(style.flex).toBe(1);
|
|
540
|
+
} finally {
|
|
541
|
+
PlatformModule.OS = savedOS;
|
|
542
|
+
restoreDocument();
|
|
543
|
+
}
|
|
544
|
+
});
|
|
545
|
+
|
|
546
|
+
it("lets the non-searchable trigger label shrink inside a narrow field", () => {
|
|
547
|
+
ensureDocument();
|
|
548
|
+
savedOS = PlatformModule.OS;
|
|
549
|
+
try {
|
|
550
|
+
PlatformModule.OS = "web";
|
|
551
|
+
const {getByTestId} = renderWithTheme(
|
|
552
|
+
<RNPickerSelect {...defaultProps} disableSearch value="1" />
|
|
553
|
+
);
|
|
554
|
+
const style = StyleSheet.flatten(getByTestId("text_input").props.style);
|
|
555
|
+
expect(style.minWidth).toBe(0);
|
|
556
|
+
expect(style.flex).toBe(1);
|
|
557
|
+
} finally {
|
|
558
|
+
PlatformModule.OS = savedOS;
|
|
559
|
+
restoreDocument();
|
|
560
|
+
}
|
|
561
|
+
});
|
|
562
|
+
|
|
525
563
|
it("selects a filtered option and reports the original option index", async () => {
|
|
526
564
|
ensureDocument();
|
|
527
565
|
savedOS = PlatformModule.OS;
|
package/src/PickerSelect.tsx
CHANGED
|
@@ -435,6 +435,9 @@ export const RNPickerSelect = ({
|
|
|
435
435
|
const baseTextInputStyle = {
|
|
436
436
|
color: disabled ? theme.text.secondaryLight : theme.text.primary,
|
|
437
437
|
flex: 1,
|
|
438
|
+
// Text inputs have an intrinsic width; without this they refuse to shrink inside
|
|
439
|
+
// narrow triggers and push the chevron outside the field border on web.
|
|
440
|
+
minWidth: 0,
|
|
438
441
|
};
|
|
439
442
|
return (
|
|
440
443
|
<View
|
|
@@ -724,6 +727,9 @@ export const RNPickerSelect = ({
|
|
|
724
727
|
flex: 1,
|
|
725
728
|
fontFamily: "text" as const,
|
|
726
729
|
fontSize: 16,
|
|
730
|
+
// Text inputs have an intrinsic width; without this they refuse to shrink inside
|
|
731
|
+
// narrow triggers and push the chevron outside the field border on web.
|
|
732
|
+
minWidth: 0,
|
|
727
733
|
paddingLeft: 0,
|
|
728
734
|
paddingRight: 8,
|
|
729
735
|
paddingVertical: 0,
|
|
@@ -804,6 +810,7 @@ export const RNPickerSelect = ({
|
|
|
804
810
|
flex: 1,
|
|
805
811
|
fontFamily: "text",
|
|
806
812
|
fontSize: 16,
|
|
813
|
+
minWidth: 0,
|
|
807
814
|
paddingRight: 8,
|
|
808
815
|
}}
|
|
809
816
|
testID="text_input"
|
|
@@ -0,0 +1,151 @@
|
|
|
1
|
+
import {describe, expect, it, jest} from "bun:test";
|
|
2
|
+
import {fireEvent, waitFor} from "@testing-library/react-native";
|
|
3
|
+
|
|
4
|
+
import {Popover} from "./Popover";
|
|
5
|
+
import {Text} from "./Text";
|
|
6
|
+
import {renderWithTheme} from "./test-utils";
|
|
7
|
+
|
|
8
|
+
describe("Popover", () => {
|
|
9
|
+
it("renders the title, date and body when loaded", () => {
|
|
10
|
+
const {getByTestId, getByText} = renderWithTheme(
|
|
11
|
+
<Popover
|
|
12
|
+
onClose={jest.fn()}
|
|
13
|
+
subtitle="11/20/2026"
|
|
14
|
+
testID="popover"
|
|
15
|
+
text="Summary of Patient History."
|
|
16
|
+
title="Document Title"
|
|
17
|
+
/>
|
|
18
|
+
);
|
|
19
|
+
expect(getByTestId("popover-title")).toBeTruthy();
|
|
20
|
+
expect(getByTestId("popover-subtitle")).toBeTruthy();
|
|
21
|
+
expect(getByText("Summary of Patient History.")).toBeTruthy();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("prefers children over text for the body", () => {
|
|
25
|
+
const {getByText, queryByText} = renderWithTheme(
|
|
26
|
+
<Popover onClose={jest.fn()} text="Plain summary">
|
|
27
|
+
<Text>Rich body</Text>
|
|
28
|
+
</Popover>
|
|
29
|
+
);
|
|
30
|
+
expect(getByText("Rich body")).toBeTruthy();
|
|
31
|
+
expect(queryByText("Plain summary")).toBeNull();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("calls onClose when the close button is pressed", () => {
|
|
35
|
+
const onClose = jest.fn();
|
|
36
|
+
const {getByLabelText} = renderWithTheme(<Popover onClose={onClose} title="Doc" />);
|
|
37
|
+
fireEvent.press(getByLabelText("Close document"));
|
|
38
|
+
expect(onClose).toHaveBeenCalled();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("calls onOpen from the footer action", () => {
|
|
42
|
+
const onOpen = jest.fn();
|
|
43
|
+
const {getByTestId} = renderWithTheme(
|
|
44
|
+
<Popover onClose={jest.fn()} onOpen={onOpen} testID="popover" title="Doc" />
|
|
45
|
+
);
|
|
46
|
+
fireEvent.press(getByTestId("popover-open"));
|
|
47
|
+
expect(onOpen).toHaveBeenCalled();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("passes feedback selections through", () => {
|
|
51
|
+
const onFeedbackChange = jest.fn();
|
|
52
|
+
const {getByTestId} = renderWithTheme(
|
|
53
|
+
<Popover
|
|
54
|
+
onClose={jest.fn()}
|
|
55
|
+
onFeedbackChange={onFeedbackChange}
|
|
56
|
+
testID="popover"
|
|
57
|
+
title="Doc"
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
fireEvent.press(getByTestId("popover-feedback-positive"));
|
|
61
|
+
expect(onFeedbackChange).toHaveBeenCalledWith("positive");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("hides the footer when there are no footer actions", () => {
|
|
65
|
+
const {queryByTestId} = renderWithTheme(
|
|
66
|
+
<Popover onClose={jest.fn()} testID="popover" title="Doc" />
|
|
67
|
+
);
|
|
68
|
+
expect(queryByTestId("popover-open")).toBeNull();
|
|
69
|
+
expect(queryByTestId("popover-feedback")).toBeNull();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("shows the loading header instead of the document while loading", () => {
|
|
73
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
74
|
+
<Popover onClose={jest.fn()} status="loading" testID="popover" title="Doc" />
|
|
75
|
+
);
|
|
76
|
+
expect(getByTestId("popover-loading-text")).toBeTruthy();
|
|
77
|
+
expect(queryByTestId("popover-title")).toBeNull();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("shows a retryable error message when loading fails", async () => {
|
|
81
|
+
const onRetry = jest.fn();
|
|
82
|
+
const {getByTestId} = renderWithTheme(
|
|
83
|
+
<Popover onClose={jest.fn()} onRetry={onRetry} status="error" testID="popover" title="Doc" />
|
|
84
|
+
);
|
|
85
|
+
expect(getByTestId("popover-error-title")).toBeTruthy();
|
|
86
|
+
fireEvent.press(getByTestId("popover-retry"));
|
|
87
|
+
await waitFor(() => {
|
|
88
|
+
expect(onRetry).toHaveBeenCalled();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("hides the retry button when there is no retry handler", () => {
|
|
93
|
+
const {queryByTestId} = renderWithTheme(
|
|
94
|
+
<Popover onClose={jest.fn()} status="error" testID="popover" />
|
|
95
|
+
);
|
|
96
|
+
expect(queryByTestId("popover-retry")).toBeNull();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("lets the body fill the card instead of pinning its content height", () => {
|
|
100
|
+
const {getByTestId} = renderWithTheme(
|
|
101
|
+
<Popover
|
|
102
|
+
height={240}
|
|
103
|
+
onClose={jest.fn()}
|
|
104
|
+
testID="popover"
|
|
105
|
+
text={"Summary of patient history. ".repeat(40)}
|
|
106
|
+
title="Doc"
|
|
107
|
+
/>
|
|
108
|
+
);
|
|
109
|
+
const scrollView = getByTestId("popover-content");
|
|
110
|
+
expect(scrollView.props.style).toEqual(
|
|
111
|
+
expect.objectContaining({flexBasis: 0, flexGrow: 1, flexShrink: 1, minHeight: 0})
|
|
112
|
+
);
|
|
113
|
+
const content = scrollView.findByType("View");
|
|
114
|
+
expect(content.props.style?.height).toBeUndefined();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("defaults to the 480x480 design size", () => {
|
|
118
|
+
const {getByTestId} = renderWithTheme(
|
|
119
|
+
<Popover onClose={jest.fn()} testID="popover" title="Doc" />
|
|
120
|
+
);
|
|
121
|
+
expect(getByTestId("popover").props.style).toEqual(
|
|
122
|
+
expect.objectContaining({height: 480, width: 480})
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("keeps the same height in every status", () => {
|
|
127
|
+
const heights = (["loaded", "loading", "error"] as const).map((status) => {
|
|
128
|
+
const {getByTestId} = renderWithTheme(
|
|
129
|
+
<Popover height={280} onClose={jest.fn()} status={status} testID={status} title="Doc" />
|
|
130
|
+
);
|
|
131
|
+
return getByTestId(status).props.style.height;
|
|
132
|
+
});
|
|
133
|
+
expect(heights).toEqual([280, 280, 280]);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("drops the header and footer in the error status", () => {
|
|
137
|
+
const {queryByTestId} = renderWithTheme(
|
|
138
|
+
<Popover
|
|
139
|
+
onClose={jest.fn()}
|
|
140
|
+
onOpen={jest.fn()}
|
|
141
|
+
status="error"
|
|
142
|
+
subtitle="11/20/2026"
|
|
143
|
+
testID="popover"
|
|
144
|
+
title="Doc"
|
|
145
|
+
/>
|
|
146
|
+
);
|
|
147
|
+
expect(queryByTestId("popover-title")).toBeNull();
|
|
148
|
+
expect(queryByTestId("popover-subtitle")).toBeNull();
|
|
149
|
+
expect(queryByTestId("popover-open")).toBeNull();
|
|
150
|
+
});
|
|
151
|
+
});
|
package/src/Popover.tsx
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import type {FC, ReactNode} from "react";
|
|
2
|
+
import {Pressable, ScrollView} from "react-native";
|
|
3
|
+
|
|
4
|
+
import {Box} from "./Box";
|
|
5
|
+
import {Button} from "./Button";
|
|
6
|
+
import type {PopoverProps} from "./Common";
|
|
7
|
+
import {DismissButton} from "./DismissButton";
|
|
8
|
+
import {Heading} from "./Heading";
|
|
9
|
+
import {Icon} from "./Icon";
|
|
10
|
+
import {Spinner} from "./Spinner";
|
|
11
|
+
import {Text} from "./Text";
|
|
12
|
+
import {ThumbsUpDownFeedback} from "./ThumbsUpDownFeedback";
|
|
13
|
+
|
|
14
|
+
const DEFAULT_HEIGHT = 480;
|
|
15
|
+
const DEFAULT_WIDTH = 480;
|
|
16
|
+
const ERROR_ICON_SIZE = 64;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A popover that previews a single document: a header with the document's title and date, the
|
|
20
|
+
* document body, and a footer with an "Open" action and optional thumbs up/down feedback.
|
|
21
|
+
*
|
|
22
|
+
* Rendering is driven by `status`: "loading" shows a centered spinner under a loading header,
|
|
23
|
+
* "error" shows a retryable error message centered in the card, and "loaded" shows the document
|
|
24
|
+
* itself. The popover keeps the same size in every state, and is a plain card, so the consumer is
|
|
25
|
+
* responsible for positioning it next to its anchor.
|
|
26
|
+
*/
|
|
27
|
+
export const Popover: FC<PopoverProps> = ({
|
|
28
|
+
children,
|
|
29
|
+
errorText = "Something went wrong while loading this document. Check your connection and try again.",
|
|
30
|
+
errorTitle = "Couldn't load this document",
|
|
31
|
+
feedback,
|
|
32
|
+
height = DEFAULT_HEIGHT,
|
|
33
|
+
loadingText = "Loading document...",
|
|
34
|
+
onClose,
|
|
35
|
+
onFeedbackChange,
|
|
36
|
+
onOpen,
|
|
37
|
+
onRetry,
|
|
38
|
+
openText = "Open",
|
|
39
|
+
retryText = "Try again",
|
|
40
|
+
status = "loaded",
|
|
41
|
+
subtitle,
|
|
42
|
+
testID,
|
|
43
|
+
text,
|
|
44
|
+
title,
|
|
45
|
+
width = DEFAULT_WIDTH,
|
|
46
|
+
}) => {
|
|
47
|
+
const childTestID = (suffix: string) => (testID ? `${testID}-${suffix}` : undefined);
|
|
48
|
+
|
|
49
|
+
const closeButton = (
|
|
50
|
+
<DismissButton
|
|
51
|
+
accessibilityHint="Closes the document preview"
|
|
52
|
+
accessibilityLabel="Close document"
|
|
53
|
+
color="link"
|
|
54
|
+
onClick={() => {
|
|
55
|
+
void onClose();
|
|
56
|
+
}}
|
|
57
|
+
/>
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const card = (content: ReactNode) => (
|
|
61
|
+
<Box
|
|
62
|
+
color="base"
|
|
63
|
+
height={height}
|
|
64
|
+
overflow="hidden"
|
|
65
|
+
rounding="md"
|
|
66
|
+
shadow
|
|
67
|
+
testID={testID}
|
|
68
|
+
width={width}
|
|
69
|
+
>
|
|
70
|
+
{content}
|
|
71
|
+
</Box>
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
// The error state has no header or footer: the close button floats over a centered message.
|
|
75
|
+
if (status === "error") {
|
|
76
|
+
return card(
|
|
77
|
+
<>
|
|
78
|
+
<Box paddingX={4} paddingY={4} position="absolute" right top zIndex={1}>
|
|
79
|
+
{closeButton}
|
|
80
|
+
</Box>
|
|
81
|
+
<Box
|
|
82
|
+
alignItems="center"
|
|
83
|
+
flex="grow"
|
|
84
|
+
gap={4}
|
|
85
|
+
justifyContent="center"
|
|
86
|
+
paddingX={6}
|
|
87
|
+
width="100%"
|
|
88
|
+
>
|
|
89
|
+
<Box
|
|
90
|
+
alignItems="center"
|
|
91
|
+
color="errorLight"
|
|
92
|
+
height={ERROR_ICON_SIZE}
|
|
93
|
+
justifyContent="center"
|
|
94
|
+
rounding="circle"
|
|
95
|
+
width={ERROR_ICON_SIZE}
|
|
96
|
+
>
|
|
97
|
+
<Icon color="error" iconName="triangle-exclamation" size="xl" type="solid" />
|
|
98
|
+
</Box>
|
|
99
|
+
<Heading align="center" size="md" testID={childTestID("error-title")}>
|
|
100
|
+
{errorTitle}
|
|
101
|
+
</Heading>
|
|
102
|
+
<Text align="center">{errorText}</Text>
|
|
103
|
+
{Boolean(onRetry) && (
|
|
104
|
+
// Button pins itself to flex-start, so center it on the row's main axis instead.
|
|
105
|
+
<Box direction="row" justifyContent="center" width="100%">
|
|
106
|
+
<Button
|
|
107
|
+
onClick={onRetry!}
|
|
108
|
+
testID={childTestID("retry")}
|
|
109
|
+
text={retryText}
|
|
110
|
+
variant="primary"
|
|
111
|
+
/>
|
|
112
|
+
</Box>
|
|
113
|
+
)}
|
|
114
|
+
</Box>
|
|
115
|
+
</>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const body =
|
|
120
|
+
status === "loading" ? (
|
|
121
|
+
<Box alignItems="center" flex="grow" justifyContent="center" width="100%">
|
|
122
|
+
<Spinner color="secondary" testID={childTestID("spinner")} />
|
|
123
|
+
</Box>
|
|
124
|
+
) : (
|
|
125
|
+
<ScrollView
|
|
126
|
+
keyboardShouldPersistTaps="handled"
|
|
127
|
+
nestedScrollEnabled
|
|
128
|
+
style={{flexBasis: 0, flexGrow: 1, flexShrink: 1, minHeight: 0, width: "100%"}}
|
|
129
|
+
testID={childTestID("content")}
|
|
130
|
+
>
|
|
131
|
+
<Box paddingX={4} paddingY={3} width="100%">
|
|
132
|
+
{children ?? (Boolean(text) && <Text>{text}</Text>)}
|
|
133
|
+
</Box>
|
|
134
|
+
</ScrollView>
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
const showFooter = status === "loaded" && (Boolean(onOpen) || Boolean(onFeedbackChange));
|
|
138
|
+
|
|
139
|
+
return card(
|
|
140
|
+
<>
|
|
141
|
+
<Box
|
|
142
|
+
alignItems="center"
|
|
143
|
+
borderBottom="default"
|
|
144
|
+
direction="row"
|
|
145
|
+
gap={2}
|
|
146
|
+
paddingX={4}
|
|
147
|
+
paddingY={4}
|
|
148
|
+
>
|
|
149
|
+
<Box flex="grow" minWidth={0}>
|
|
150
|
+
{status === "loaded" ? (
|
|
151
|
+
<>
|
|
152
|
+
{Boolean(title) && (
|
|
153
|
+
<Heading size="sm" testID={childTestID("title")}>
|
|
154
|
+
{title}
|
|
155
|
+
</Heading>
|
|
156
|
+
)}
|
|
157
|
+
{Boolean(subtitle) && (
|
|
158
|
+
<Text size="sm" testID={childTestID("subtitle")}>
|
|
159
|
+
{subtitle}
|
|
160
|
+
</Text>
|
|
161
|
+
)}
|
|
162
|
+
</>
|
|
163
|
+
) : (
|
|
164
|
+
<Text color="secondaryLight" testID={childTestID("loading-text")}>
|
|
165
|
+
{loadingText}
|
|
166
|
+
</Text>
|
|
167
|
+
)}
|
|
168
|
+
</Box>
|
|
169
|
+
{closeButton}
|
|
170
|
+
</Box>
|
|
171
|
+
|
|
172
|
+
{body}
|
|
173
|
+
|
|
174
|
+
{showFooter && (
|
|
175
|
+
<Box
|
|
176
|
+
alignItems="center"
|
|
177
|
+
borderTop="default"
|
|
178
|
+
direction="row"
|
|
179
|
+
justifyContent="between"
|
|
180
|
+
paddingX={4}
|
|
181
|
+
paddingY={3}
|
|
182
|
+
>
|
|
183
|
+
{onOpen ? (
|
|
184
|
+
<Pressable
|
|
185
|
+
accessibilityRole="button"
|
|
186
|
+
aria-label={openText}
|
|
187
|
+
onPress={onOpen}
|
|
188
|
+
testID={childTestID("open")}
|
|
189
|
+
>
|
|
190
|
+
<Box alignItems="center" direction="row" gap={2}>
|
|
191
|
+
<Text bold color="link">
|
|
192
|
+
{openText}
|
|
193
|
+
</Text>
|
|
194
|
+
<Icon color="link" iconName="arrow-up-right-from-square" size="md" type="regular" />
|
|
195
|
+
</Box>
|
|
196
|
+
</Pressable>
|
|
197
|
+
) : (
|
|
198
|
+
<Box />
|
|
199
|
+
)}
|
|
200
|
+
{Boolean(onFeedbackChange) && (
|
|
201
|
+
<ThumbsUpDownFeedback
|
|
202
|
+
onChange={onFeedbackChange!}
|
|
203
|
+
testID={childTestID("feedback")}
|
|
204
|
+
value={feedback}
|
|
205
|
+
/>
|
|
206
|
+
)}
|
|
207
|
+
</Box>
|
|
208
|
+
)}
|
|
209
|
+
</>
|
|
210
|
+
);
|
|
211
|
+
};
|