@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
package/src/PortalHost.tsx
CHANGED
|
@@ -22,6 +22,16 @@ interface PortalEntry {
|
|
|
22
22
|
key: string;
|
|
23
23
|
}
|
|
24
24
|
|
|
25
|
+
// react-native-web only polyfills the React Native `pointerEvents` values
|
|
26
|
+
// ("box-none", "box-only") for styles registered through StyleSheet.create, and
|
|
27
|
+
// silently drops `pointerEvents` from inline style objects. Registering here keeps
|
|
28
|
+
// the portal layer transparent to hover and touch instead of covering the app with
|
|
29
|
+
// an event-swallowing overlay whenever a portal is mounted.
|
|
30
|
+
const styles = StyleSheet.create({
|
|
31
|
+
content: {flex: 1, pointerEvents: "box-none"},
|
|
32
|
+
portal: {bottom: 0, left: 0, pointerEvents: "box-none", position: "absolute", right: 0, top: 0},
|
|
33
|
+
});
|
|
34
|
+
|
|
25
35
|
export const PortalContext = createContext<PortalManager | null>(null);
|
|
26
36
|
|
|
27
37
|
/**
|
|
@@ -58,15 +68,11 @@ export const Host: FC<{children?: ReactNode; style?: StyleProp<ViewStyle>}> = ({
|
|
|
58
68
|
|
|
59
69
|
return (
|
|
60
70
|
<PortalContext.Provider value={manager}>
|
|
61
|
-
<View collapsable={false} style={[
|
|
71
|
+
<View collapsable={false} style={[styles.content, style]}>
|
|
62
72
|
{children}
|
|
63
73
|
</View>
|
|
64
74
|
{portals.map(({children: portalChildren, key}) => (
|
|
65
|
-
<View
|
|
66
|
-
collapsable={false}
|
|
67
|
-
key={key}
|
|
68
|
-
style={[StyleSheet.absoluteFill, {pointerEvents: "box-none"}]}
|
|
69
|
-
>
|
|
75
|
+
<View collapsable={false} key={key} style={styles.portal}>
|
|
70
76
|
{portalChildren}
|
|
71
77
|
</View>
|
|
72
78
|
))}
|
|
@@ -0,0 +1,184 @@
|
|
|
1
|
+
import {describe, it, mock} from "bun:test";
|
|
2
|
+
import {render} from "@testing-library/react-native";
|
|
3
|
+
import {assert} from "chai";
|
|
4
|
+
import type React from "react";
|
|
5
|
+
import {renderToString} from "react-dom/server";
|
|
6
|
+
import {View} from "react-native";
|
|
7
|
+
|
|
8
|
+
import {
|
|
9
|
+
createNativeResponsiveBreakpointStore,
|
|
10
|
+
createResponsiveBreakpointStore,
|
|
11
|
+
getBreakpointForWidth,
|
|
12
|
+
isBreakpointAtLeast,
|
|
13
|
+
isSupportedDesktopViewport,
|
|
14
|
+
type ResponsiveBreakpointStore,
|
|
15
|
+
useResponsiveBreakpoint,
|
|
16
|
+
} from "./ResponsiveBreakpoint";
|
|
17
|
+
|
|
18
|
+
interface BreakpointConsumerProps {
|
|
19
|
+
enabled?: boolean;
|
|
20
|
+
store: ResponsiveBreakpointStore;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const BreakpointConsumer: React.FC<BreakpointConsumerProps> = ({
|
|
24
|
+
enabled = true,
|
|
25
|
+
store,
|
|
26
|
+
}): React.ReactElement => {
|
|
27
|
+
const breakpoint = useResponsiveBreakpoint({enabled, store});
|
|
28
|
+
return <span>{breakpoint}</span>;
|
|
29
|
+
};
|
|
30
|
+
|
|
31
|
+
const BreakpointSubscriber: React.FC<BreakpointConsumerProps> = ({enabled = true, store}): null => {
|
|
32
|
+
useResponsiveBreakpoint({enabled, store});
|
|
33
|
+
return null;
|
|
34
|
+
};
|
|
35
|
+
|
|
36
|
+
describe("ResponsiveBreakpoint", () => {
|
|
37
|
+
it("keeps native mobile breakpoint boundaries", () => {
|
|
38
|
+
assert.equal(getBreakpointForWidth(319, "native"), "xs");
|
|
39
|
+
assert.equal(getBreakpointForWidth(320, "native"), "sm");
|
|
40
|
+
assert.equal(getBreakpointForWidth(374, "native"), "sm");
|
|
41
|
+
assert.equal(getBreakpointForWidth(375, "native"), "md");
|
|
42
|
+
assert.equal(getBreakpointForWidth(599, "native"), "md");
|
|
43
|
+
assert.equal(getBreakpointForWidth(600, "native"), "lg");
|
|
44
|
+
assert.equal(getBreakpointForWidth(1023, "native"), "lg");
|
|
45
|
+
assert.equal(getBreakpointForWidth(1024, "native"), "xl");
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
it("keeps web desktop breakpoint boundaries", () => {
|
|
49
|
+
assert.equal(getBreakpointForWidth(319, "web"), "xs");
|
|
50
|
+
assert.equal(getBreakpointForWidth(320, "web"), "sm");
|
|
51
|
+
assert.equal(getBreakpointForWidth(374, "web"), "sm");
|
|
52
|
+
assert.equal(getBreakpointForWidth(375, "web"), "md");
|
|
53
|
+
assert.equal(getBreakpointForWidth(1023, "web"), "md");
|
|
54
|
+
assert.equal(getBreakpointForWidth(1024, "web"), "lg");
|
|
55
|
+
assert.equal(getBreakpointForWidth(1279, "web"), "lg");
|
|
56
|
+
assert.equal(getBreakpointForWidth(1280, "web"), "xl");
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it("treats native xl and web lg as the supported desktop floor", () => {
|
|
60
|
+
assert.isFalse(isSupportedDesktopViewport({breakpoint: "lg", surface: "native"}));
|
|
61
|
+
assert.isTrue(isSupportedDesktopViewport({breakpoint: "xl", surface: "native"}));
|
|
62
|
+
assert.isFalse(isSupportedDesktopViewport({breakpoint: "md", surface: "web"}));
|
|
63
|
+
assert.isTrue(isSupportedDesktopViewport({breakpoint: "lg", surface: "web"}));
|
|
64
|
+
});
|
|
65
|
+
|
|
66
|
+
it("compares breakpoints without reading Dimensions", () => {
|
|
67
|
+
assert.isFalse(isBreakpointAtLeast({breakpoint: "xs", minimum: "sm"}));
|
|
68
|
+
assert.isTrue(isBreakpointAtLeast({breakpoint: "sm", minimum: "sm"}));
|
|
69
|
+
assert.isTrue(isBreakpointAtLeast({breakpoint: "lg", minimum: "md"}));
|
|
70
|
+
assert.isTrue(isBreakpointAtLeast({breakpoint: "xl", minimum: "lg"}));
|
|
71
|
+
});
|
|
72
|
+
|
|
73
|
+
it("maps native resize and rotation events into shared breakpoint updates", () => {
|
|
74
|
+
let dimensionListener: ((event: {window: {width: number}}) => void) | undefined;
|
|
75
|
+
const removeListener = mock((): void => {});
|
|
76
|
+
const subscriber = mock((): void => {});
|
|
77
|
+
const store = createNativeResponsiveBreakpointStore({
|
|
78
|
+
addEventListener: (_eventType, listener): {remove: () => void} => {
|
|
79
|
+
dimensionListener = listener;
|
|
80
|
+
return {remove: removeListener};
|
|
81
|
+
},
|
|
82
|
+
get: (): {width: number} => ({width: 319}),
|
|
83
|
+
});
|
|
84
|
+
const unsubscribe = store.subscribe(subscriber);
|
|
85
|
+
|
|
86
|
+
assert.equal(store.getSnapshot(), "xs");
|
|
87
|
+
dimensionListener?.({window: {width: 375}});
|
|
88
|
+
assert.equal(store.getSnapshot(), "md");
|
|
89
|
+
assert.lengthOf(subscriber.mock.calls, 1);
|
|
90
|
+
|
|
91
|
+
unsubscribe();
|
|
92
|
+
assert.lengthOf(removeListener.mock.calls, 1);
|
|
93
|
+
});
|
|
94
|
+
|
|
95
|
+
it("uses the xs server snapshot before client hydration", () => {
|
|
96
|
+
const store = createResponsiveBreakpointStore({
|
|
97
|
+
getSurface: (): "native" => "native",
|
|
98
|
+
getWindowWidth: (): number => 1024,
|
|
99
|
+
subscribeToDimensions: (): {remove: () => void} => ({remove: (): void => {}}),
|
|
100
|
+
});
|
|
101
|
+
|
|
102
|
+
const html = renderToString(<BreakpointConsumer store={store} />);
|
|
103
|
+
|
|
104
|
+
assert.include(html, ">xs<");
|
|
105
|
+
assert.equal(store.getSnapshot(), "xl");
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it("shares one dimensions listener across a responsive tree", () => {
|
|
109
|
+
let dimensionReadCount = 0;
|
|
110
|
+
let listenerCount = 0;
|
|
111
|
+
let removeCount = 0;
|
|
112
|
+
const store = createResponsiveBreakpointStore({
|
|
113
|
+
getWindowWidth: (): number => {
|
|
114
|
+
dimensionReadCount += 1;
|
|
115
|
+
return 375;
|
|
116
|
+
},
|
|
117
|
+
subscribeToDimensions: (): {remove: () => void} => {
|
|
118
|
+
listenerCount += 1;
|
|
119
|
+
return {
|
|
120
|
+
remove: (): void => {
|
|
121
|
+
removeCount += 1;
|
|
122
|
+
},
|
|
123
|
+
};
|
|
124
|
+
},
|
|
125
|
+
});
|
|
126
|
+
const result = render(
|
|
127
|
+
<View>
|
|
128
|
+
{Array.from(
|
|
129
|
+
{length: 100},
|
|
130
|
+
(_, index): React.ReactElement => (
|
|
131
|
+
<BreakpointSubscriber key={index} store={store} />
|
|
132
|
+
)
|
|
133
|
+
)}
|
|
134
|
+
</View>
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
assert.equal(dimensionReadCount, 2);
|
|
138
|
+
assert.equal(listenerCount, 1);
|
|
139
|
+
|
|
140
|
+
result.unmount();
|
|
141
|
+
assert.equal(removeCount, 1);
|
|
142
|
+
});
|
|
143
|
+
|
|
144
|
+
it("does not subscribe when responsive behavior is disabled", () => {
|
|
145
|
+
let listenerCount = 0;
|
|
146
|
+
const store = createResponsiveBreakpointStore({
|
|
147
|
+
getWindowWidth: (): number => 375,
|
|
148
|
+
subscribeToDimensions: (): {remove: () => void} => {
|
|
149
|
+
listenerCount += 1;
|
|
150
|
+
return {remove: (): void => {}};
|
|
151
|
+
},
|
|
152
|
+
});
|
|
153
|
+
const result = render(
|
|
154
|
+
<View>
|
|
155
|
+
{Array.from(
|
|
156
|
+
{length: 100},
|
|
157
|
+
(_, index): React.ReactElement => (
|
|
158
|
+
<BreakpointSubscriber enabled={false} key={index} store={store} />
|
|
159
|
+
)
|
|
160
|
+
)}
|
|
161
|
+
</View>
|
|
162
|
+
);
|
|
163
|
+
|
|
164
|
+
assert.equal(listenerCount, 0);
|
|
165
|
+
result.unmount();
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
it("notifies on remount after a resize while no Boxes were subscribed", () => {
|
|
169
|
+
let windowWidth = 375;
|
|
170
|
+
const store = createResponsiveBreakpointStore({
|
|
171
|
+
getSurface: (): "native" => "native",
|
|
172
|
+
getWindowWidth: (): number => windowWidth,
|
|
173
|
+
subscribeToDimensions: (): {remove: () => void} => ({remove: (): void => {}}),
|
|
174
|
+
});
|
|
175
|
+
const first = render(<BreakpointConsumer store={store} />);
|
|
176
|
+
assert.equal(first.UNSAFE_root.findByType("span").props.children, "md");
|
|
177
|
+
first.unmount();
|
|
178
|
+
|
|
179
|
+
windowWidth = 1024;
|
|
180
|
+
const second = render(<BreakpointConsumer store={store} />);
|
|
181
|
+
assert.equal(second.UNSAFE_root.findByType("span").props.children, "xl");
|
|
182
|
+
second.unmount();
|
|
183
|
+
});
|
|
184
|
+
});
|
|
@@ -0,0 +1,195 @@
|
|
|
1
|
+
import {useSyncExternalStore} from "react";
|
|
2
|
+
import {Dimensions, Platform} from "react-native";
|
|
3
|
+
|
|
4
|
+
export type ResponsiveBreakpoint = "xs" | "sm" | "md" | "lg" | "xl";
|
|
5
|
+
export type BreakpointSurface = "native" | "web";
|
|
6
|
+
|
|
7
|
+
interface UseResponsiveBreakpointOptions {
|
|
8
|
+
enabled?: boolean;
|
|
9
|
+
store?: ResponsiveBreakpointStore;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
interface CreateResponsiveBreakpointStoreOptions {
|
|
13
|
+
getSurface?: () => BreakpointSurface;
|
|
14
|
+
getWindowWidth: () => number;
|
|
15
|
+
subscribeToDimensions: (listener: (width: number) => void) => {remove: () => void};
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
interface ResponsiveDimensionsSource {
|
|
19
|
+
addEventListener: (
|
|
20
|
+
eventType: "change",
|
|
21
|
+
listener: (event: {window: {width: number}}) => void
|
|
22
|
+
) => {remove: () => void};
|
|
23
|
+
get: (dimension: "window") => {width: number};
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
export interface ResponsiveBreakpointStore {
|
|
27
|
+
getServerSnapshot: () => ResponsiveBreakpoint;
|
|
28
|
+
getSnapshot: () => ResponsiveBreakpoint;
|
|
29
|
+
subscribe: (subscriber: () => void) => () => void;
|
|
30
|
+
updateWidth: (width: number) => void;
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export const NATIVE_BREAKPOINT_MIN_WIDTH = {
|
|
34
|
+
lg: 600,
|
|
35
|
+
md: 375,
|
|
36
|
+
sm: 320,
|
|
37
|
+
xl: 1024,
|
|
38
|
+
} as const;
|
|
39
|
+
|
|
40
|
+
export const WEB_BREAKPOINT_MIN_WIDTH = {
|
|
41
|
+
lg: 1024,
|
|
42
|
+
md: 375,
|
|
43
|
+
sm: 320,
|
|
44
|
+
xl: 1280,
|
|
45
|
+
} as const;
|
|
46
|
+
|
|
47
|
+
const BREAKPOINT_ORDER: Record<ResponsiveBreakpoint, number> = {
|
|
48
|
+
lg: 3,
|
|
49
|
+
md: 2,
|
|
50
|
+
sm: 1,
|
|
51
|
+
xl: 4,
|
|
52
|
+
xs: 0,
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
export const getBreakpointSurface = (os: string = Platform.OS): BreakpointSurface => {
|
|
56
|
+
if (os === "web") {
|
|
57
|
+
return "web";
|
|
58
|
+
}
|
|
59
|
+
return "native";
|
|
60
|
+
};
|
|
61
|
+
|
|
62
|
+
export interface BreakpointMinWidths {
|
|
63
|
+
lg: number;
|
|
64
|
+
md: number;
|
|
65
|
+
sm: number;
|
|
66
|
+
xl: number;
|
|
67
|
+
}
|
|
68
|
+
|
|
69
|
+
export const getBreakpointMinWidths = (surface: BreakpointSurface): BreakpointMinWidths => {
|
|
70
|
+
if (surface === "web") {
|
|
71
|
+
return WEB_BREAKPOINT_MIN_WIDTH;
|
|
72
|
+
}
|
|
73
|
+
return NATIVE_BREAKPOINT_MIN_WIDTH;
|
|
74
|
+
};
|
|
75
|
+
|
|
76
|
+
export const isBreakpointAtLeast = ({
|
|
77
|
+
breakpoint,
|
|
78
|
+
minimum,
|
|
79
|
+
}: {
|
|
80
|
+
breakpoint: ResponsiveBreakpoint;
|
|
81
|
+
minimum: ResponsiveBreakpoint;
|
|
82
|
+
}): boolean => {
|
|
83
|
+
return BREAKPOINT_ORDER[breakpoint] >= BREAKPOINT_ORDER[minimum];
|
|
84
|
+
};
|
|
85
|
+
|
|
86
|
+
export const getBreakpointForWidth = (
|
|
87
|
+
width: number,
|
|
88
|
+
surface: BreakpointSurface = getBreakpointSurface()
|
|
89
|
+
): ResponsiveBreakpoint => {
|
|
90
|
+
const mins = getBreakpointMinWidths(surface);
|
|
91
|
+
if (width < mins.sm) {
|
|
92
|
+
return "xs";
|
|
93
|
+
}
|
|
94
|
+
if (width < mins.md) {
|
|
95
|
+
return "sm";
|
|
96
|
+
}
|
|
97
|
+
if (width < mins.lg) {
|
|
98
|
+
return "md";
|
|
99
|
+
}
|
|
100
|
+
if (width < mins.xl) {
|
|
101
|
+
return "lg";
|
|
102
|
+
}
|
|
103
|
+
return "xl";
|
|
104
|
+
};
|
|
105
|
+
|
|
106
|
+
export const isSupportedDesktopViewport = ({
|
|
107
|
+
breakpoint,
|
|
108
|
+
surface,
|
|
109
|
+
}: {
|
|
110
|
+
breakpoint: ResponsiveBreakpoint;
|
|
111
|
+
surface: BreakpointSurface;
|
|
112
|
+
}): boolean => {
|
|
113
|
+
if (surface === "web") {
|
|
114
|
+
return isBreakpointAtLeast({breakpoint, minimum: "lg"});
|
|
115
|
+
}
|
|
116
|
+
return isBreakpointAtLeast({breakpoint, minimum: "xl"});
|
|
117
|
+
};
|
|
118
|
+
|
|
119
|
+
const getServerBreakpointSnapshot = (): ResponsiveBreakpoint => {
|
|
120
|
+
return "xs";
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
export const createResponsiveBreakpointStore = ({
|
|
124
|
+
getSurface = getBreakpointSurface,
|
|
125
|
+
getWindowWidth,
|
|
126
|
+
subscribeToDimensions,
|
|
127
|
+
}: CreateResponsiveBreakpointStoreOptions): ResponsiveBreakpointStore => {
|
|
128
|
+
const subscribers = new Set<() => void>();
|
|
129
|
+
let currentWindowWidth = getWindowWidth();
|
|
130
|
+
let dimensionSubscription: {remove: () => void} | undefined;
|
|
131
|
+
|
|
132
|
+
const updateWidth = (width: number): void => {
|
|
133
|
+
if (width === currentWindowWidth) {
|
|
134
|
+
return;
|
|
135
|
+
}
|
|
136
|
+
currentWindowWidth = width;
|
|
137
|
+
for (const notifySubscriber of subscribers) {
|
|
138
|
+
notifySubscriber();
|
|
139
|
+
}
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const subscribe = (subscriber: () => void): (() => void) => {
|
|
143
|
+
subscribers.add(subscriber);
|
|
144
|
+
|
|
145
|
+
if (!dimensionSubscription) {
|
|
146
|
+
dimensionSubscription = subscribeToDimensions(updateWidth);
|
|
147
|
+
updateWidth(getWindowWidth());
|
|
148
|
+
}
|
|
149
|
+
|
|
150
|
+
return (): void => {
|
|
151
|
+
subscribers.delete(subscriber);
|
|
152
|
+
if (subscribers.size === 0) {
|
|
153
|
+
dimensionSubscription?.remove();
|
|
154
|
+
dimensionSubscription = undefined;
|
|
155
|
+
}
|
|
156
|
+
};
|
|
157
|
+
};
|
|
158
|
+
|
|
159
|
+
return {
|
|
160
|
+
getServerSnapshot: getServerBreakpointSnapshot,
|
|
161
|
+
getSnapshot: (): ResponsiveBreakpoint =>
|
|
162
|
+
getBreakpointForWidth(currentWindowWidth, getSurface()),
|
|
163
|
+
subscribe,
|
|
164
|
+
updateWidth,
|
|
165
|
+
};
|
|
166
|
+
};
|
|
167
|
+
|
|
168
|
+
export const createNativeResponsiveBreakpointStore = (
|
|
169
|
+
dimensions: ResponsiveDimensionsSource
|
|
170
|
+
): ResponsiveBreakpointStore => {
|
|
171
|
+
return createResponsiveBreakpointStore({
|
|
172
|
+
getWindowWidth: (): number => dimensions.get("window").width,
|
|
173
|
+
subscribeToDimensions: (listener): {remove: () => void} =>
|
|
174
|
+
dimensions.addEventListener("change", ({window}): void => {
|
|
175
|
+
listener(window.width);
|
|
176
|
+
}),
|
|
177
|
+
});
|
|
178
|
+
};
|
|
179
|
+
|
|
180
|
+
export const sharedResponsiveBreakpointStore = createNativeResponsiveBreakpointStore(Dimensions);
|
|
181
|
+
|
|
182
|
+
const subscribeToNothing = (): (() => void) => {
|
|
183
|
+
return (): void => {};
|
|
184
|
+
};
|
|
185
|
+
|
|
186
|
+
export const useResponsiveBreakpoint = ({
|
|
187
|
+
enabled = true,
|
|
188
|
+
store = sharedResponsiveBreakpointStore,
|
|
189
|
+
}: UseResponsiveBreakpointOptions = {}): ResponsiveBreakpoint => {
|
|
190
|
+
return useSyncExternalStore(
|
|
191
|
+
enabled ? store.subscribe : subscribeToNothing,
|
|
192
|
+
store.getSnapshot,
|
|
193
|
+
store.getServerSnapshot
|
|
194
|
+
);
|
|
195
|
+
};
|
|
@@ -0,0 +1,82 @@
|
|
|
1
|
+
import {describe, expect, it} from "bun:test";
|
|
2
|
+
import {resolve} from "node:path";
|
|
3
|
+
|
|
4
|
+
import {
|
|
5
|
+
AIRequestExplorer,
|
|
6
|
+
Button,
|
|
7
|
+
ConsentNavigator,
|
|
8
|
+
DashboardGrid,
|
|
9
|
+
DraggableList,
|
|
10
|
+
EmojiSelector,
|
|
11
|
+
GPTChat,
|
|
12
|
+
LineChart,
|
|
13
|
+
MarkdownEditor,
|
|
14
|
+
} from "@terreno/ui";
|
|
15
|
+
import {Box} from "@terreno/ui/Box";
|
|
16
|
+
import EmojiSelectorSubpath from "@terreno/ui/EmojiSelector";
|
|
17
|
+
import {GPTChat as GPTChatSubpath} from "@terreno/ui/GPTChat";
|
|
18
|
+
import {LineChart as LineChartSubpath} from "@terreno/ui/LineChart";
|
|
19
|
+
import {MarkdownView} from "@terreno/ui/MarkdownView";
|
|
20
|
+
|
|
21
|
+
import {measureImportGraph} from "./benchmarks/importGraph";
|
|
22
|
+
import {Categories} from "./emojiCategories";
|
|
23
|
+
import {EmojiSelector as LazyEmojiSelector} from "./lazyBoundaries/heavyOptionalExports";
|
|
24
|
+
|
|
25
|
+
const ROOT_IMPORT_PATHS = [
|
|
26
|
+
"@terreno/ui",
|
|
27
|
+
"@terreno/ui/Button",
|
|
28
|
+
"@terreno/ui/Box",
|
|
29
|
+
"@terreno/ui/dist/Button.js",
|
|
30
|
+
"@terreno/ui/src/Button.tsx",
|
|
31
|
+
"@terreno/ui/GPTChat",
|
|
32
|
+
"@terreno/ui/EmojiSelector",
|
|
33
|
+
"@terreno/ui/MarkdownView",
|
|
34
|
+
"@terreno/ui/LineChart",
|
|
35
|
+
];
|
|
36
|
+
|
|
37
|
+
describe("root import compatibility", () => {
|
|
38
|
+
it("keeps root Button export available", () => {
|
|
39
|
+
expect(Button).toBeTruthy();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("resolves public subpath imports", () => {
|
|
43
|
+
expect(Box).toBeTruthy();
|
|
44
|
+
expect(GPTChatSubpath).toBeTruthy();
|
|
45
|
+
expect(EmojiSelectorSubpath).toBeTruthy();
|
|
46
|
+
expect(MarkdownView).toBeTruthy();
|
|
47
|
+
expect(LineChartSubpath).toBeTruthy();
|
|
48
|
+
expect(DashboardGrid).toBeTruthy();
|
|
49
|
+
expect(LineChart).toBeTruthy();
|
|
50
|
+
});
|
|
51
|
+
|
|
52
|
+
it("keeps chart implementations off the cold root graph", () => {
|
|
53
|
+
const graph = measureImportGraph(resolve(import.meta.dir, "./index.tsx"));
|
|
54
|
+
const modulePaths = graph.modulePaths.join("\n");
|
|
55
|
+
|
|
56
|
+
expect(modulePaths.includes("/LineChart.tsx")).toBe(false);
|
|
57
|
+
expect(modulePaths.includes("/BarChart.tsx")).toBe(false);
|
|
58
|
+
expect(modulePaths.includes("/AreaChart.tsx")).toBe(false);
|
|
59
|
+
expect(modulePaths.includes("/DonutChart.tsx")).toBe(false);
|
|
60
|
+
expect(modulePaths.includes("/DashboardGrid.tsx")).toBe(true);
|
|
61
|
+
});
|
|
62
|
+
|
|
63
|
+
it("exposes lazy root exports for measured heavy optional widgets", () => {
|
|
64
|
+
expect(AIRequestExplorer).toBeTruthy();
|
|
65
|
+
expect(ConsentNavigator).toBeTruthy();
|
|
66
|
+
expect(DraggableList).toBeTruthy();
|
|
67
|
+
expect(EmojiSelector).toBeTruthy();
|
|
68
|
+
expect(GPTChat).toBeTruthy();
|
|
69
|
+
expect(MarkdownEditor).toBeTruthy();
|
|
70
|
+
expect(
|
|
71
|
+
(LazyEmojiSelector as unknown as {defaultProps?: {category?: typeof Categories.all}})
|
|
72
|
+
.defaultProps?.category
|
|
73
|
+
).toBe(Categories.all);
|
|
74
|
+
});
|
|
75
|
+
|
|
76
|
+
it("resolves documented package entrypoints", async () => {
|
|
77
|
+
for (const importPath of ROOT_IMPORT_PATHS) {
|
|
78
|
+
const moduleNamespace = await import(importPath);
|
|
79
|
+
expect(Object.keys(moduleNamespace).length).toBeGreaterThan(0);
|
|
80
|
+
}
|
|
81
|
+
});
|
|
82
|
+
});
|
package/src/SplitPage.native.tsx
CHANGED
|
@@ -5,13 +5,13 @@ import {Dimensions, type ListRenderItemInfo, View} from "react-native";
|
|
|
5
5
|
import {SwiperFlatList} from "react-native-swiper-flatlist";
|
|
6
6
|
|
|
7
7
|
import {Box} from "./Box";
|
|
8
|
-
import type {SplitPageProps} from "./Common";
|
|
8
|
+
import type {SplitPageListItem, SplitPageProps} from "./Common";
|
|
9
9
|
import {FlatList} from "./FlatList";
|
|
10
10
|
import {IconButton} from "./IconButton";
|
|
11
11
|
import {Spinner} from "./Spinner";
|
|
12
12
|
import {Unifier} from "./Unifier";
|
|
13
13
|
|
|
14
|
-
export const SplitPage = ({
|
|
14
|
+
export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
|
|
15
15
|
children,
|
|
16
16
|
loading = false,
|
|
17
17
|
color,
|
|
@@ -24,7 +24,7 @@ export const SplitPage = ({
|
|
|
24
24
|
listViewExtraData,
|
|
25
25
|
bottomNavBarHeight,
|
|
26
26
|
showItemList,
|
|
27
|
-
}: SplitPageProps) => {
|
|
27
|
+
}: SplitPageProps<TItem>) => {
|
|
28
28
|
const [selectedId, setSelectedId] = useState<number | undefined>(undefined);
|
|
29
29
|
|
|
30
30
|
// flattenChildren is necessary to pull children from a React Fragment. Without this,
|
|
@@ -34,9 +34,7 @@ export const SplitPage = ({
|
|
|
34
34
|
const {width} = Dimensions.get("window");
|
|
35
35
|
|
|
36
36
|
const onItemSelect = useCallback(
|
|
37
|
-
|
|
38
|
-
// biome-ignore lint/suspicious/noExplicitAny: SplitPage accepts heterogeneous list item shapes from consumers; the generic propagates from listViewData
|
|
39
|
-
async (item: ListRenderItemInfo<any>) => {
|
|
37
|
+
async (item: ListRenderItemInfo<TItem>): Promise<void> => {
|
|
40
38
|
setSelectedId(item.index);
|
|
41
39
|
await onSelectionChange(item);
|
|
42
40
|
},
|
|
@@ -60,9 +58,7 @@ export const SplitPage = ({
|
|
|
60
58
|
return null;
|
|
61
59
|
}
|
|
62
60
|
|
|
63
|
-
|
|
64
|
-
// biome-ignore lint/suspicious/noExplicitAny: SplitPage accepts heterogeneous list item shapes from consumers; the generic propagates from listViewData
|
|
65
|
-
const renderItem = (itemInfo: ListRenderItemInfo<any>) => {
|
|
61
|
+
const renderItem = (itemInfo: ListRenderItemInfo<TItem>) => {
|
|
66
62
|
return (
|
|
67
63
|
<Box
|
|
68
64
|
accessibilityHint=""
|
package/src/SplitPage.tsx
CHANGED
|
@@ -1,19 +1,19 @@
|
|
|
1
|
-
import {Children, useCallback, useEffect, useState} from "react";
|
|
1
|
+
import {Children, type ComponentProps, useCallback, useEffect, useState} from "react";
|
|
2
2
|
import {Dimensions, type ListRenderItemInfo, ScrollView, View} from "react-native";
|
|
3
3
|
import {SwiperFlatList} from "react-native-swiper-flatlist";
|
|
4
4
|
|
|
5
5
|
import {Box} from "./Box";
|
|
6
|
-
import type {SplitPageProps} from "./Common";
|
|
6
|
+
import type {SplitPageListItem, SplitPageProps} from "./Common";
|
|
7
7
|
import {FlatList} from "./FlatList";
|
|
8
8
|
import {IconButton} from "./IconButton";
|
|
9
|
-
import {
|
|
9
|
+
import {isMobileDevice} from "./MediaQuery";
|
|
10
10
|
import {SegmentedControl} from "./SegmentedControl";
|
|
11
11
|
import {Spinner} from "./Spinner";
|
|
12
12
|
import {useTheme} from "./Theme";
|
|
13
13
|
|
|
14
14
|
// A component for rendering a list on one side and a details view on the right for large screens,
|
|
15
15
|
// and a scrollable list where clicking an item takes you the details view.
|
|
16
|
-
export const SplitPage = ({
|
|
16
|
+
export const SplitPage = <TItem extends SplitPageListItem = SplitPageListItem>({
|
|
17
17
|
children,
|
|
18
18
|
tabs = [],
|
|
19
19
|
loading = false,
|
|
@@ -29,20 +29,18 @@ export const SplitPage = ({
|
|
|
29
29
|
listViewMaxWidth,
|
|
30
30
|
bottomNavBarHeight,
|
|
31
31
|
showItemList,
|
|
32
|
-
}: SplitPageProps) => {
|
|
32
|
+
}: SplitPageProps<TItem>) => {
|
|
33
33
|
const {theme} = useTheme();
|
|
34
34
|
const [selectedId, setSelectedId] = useState<number | undefined>(undefined);
|
|
35
35
|
const [activeTabs, setActiveTabs] = useState<number[]>([0, 1]);
|
|
36
36
|
const {width} = Dimensions.get("window");
|
|
37
37
|
|
|
38
|
-
const
|
|
38
|
+
const isMobileLayout = isMobileDevice();
|
|
39
39
|
|
|
40
40
|
const elementArray = Children.toArray(children).filter((c) => c !== null);
|
|
41
41
|
|
|
42
42
|
const onItemSelect = useCallback(
|
|
43
|
-
|
|
44
|
-
// biome-ignore lint/suspicious/noExplicitAny: SplitPage accepts heterogeneous list item shapes from consumers; the generic propagates from listViewData
|
|
45
|
-
async (item: ListRenderItemInfo<any>): Promise<void> => {
|
|
43
|
+
async (item: ListRenderItemInfo<TItem>): Promise<void> => {
|
|
46
44
|
setSelectedId(item.index);
|
|
47
45
|
await onSelectionChange(item);
|
|
48
46
|
},
|
|
@@ -71,9 +69,7 @@ export const SplitPage = ({
|
|
|
71
69
|
return null;
|
|
72
70
|
}
|
|
73
71
|
|
|
74
|
-
|
|
75
|
-
// biome-ignore lint/suspicious/noExplicitAny: SplitPage accepts heterogeneous list item shapes from consumers; the generic propagates from listViewData
|
|
76
|
-
const renderItem = (itemInfo: ListRenderItemInfo<any>) => {
|
|
72
|
+
const renderItem = (itemInfo: ListRenderItemInfo<TItem>) => {
|
|
77
73
|
return (
|
|
78
74
|
<Box
|
|
79
75
|
accessibilityHint=""
|
|
@@ -193,7 +189,7 @@ export const SplitPage = ({
|
|
|
193
189
|
};
|
|
194
190
|
|
|
195
191
|
const renderMobileList = () => {
|
|
196
|
-
if (
|
|
192
|
+
if (isMobileLayout && selectedId !== undefined) {
|
|
197
193
|
return null;
|
|
198
194
|
}
|
|
199
195
|
|
|
@@ -222,13 +218,13 @@ export const SplitPage = ({
|
|
|
222
218
|
};
|
|
223
219
|
|
|
224
220
|
const renderMobileListContent = () => {
|
|
225
|
-
if (
|
|
221
|
+
if (isMobileLayout && selectedId === undefined) {
|
|
226
222
|
return null;
|
|
227
223
|
}
|
|
228
224
|
|
|
229
225
|
return (
|
|
230
226
|
<Box flex="grow" padding={2}>
|
|
231
|
-
{
|
|
227
|
+
{isMobileLayout && (
|
|
232
228
|
<Box width="100%">
|
|
233
229
|
<IconButton
|
|
234
230
|
accessibilityHint="close split page"
|
|
@@ -302,11 +298,12 @@ export const SplitPage = ({
|
|
|
302
298
|
width="100%"
|
|
303
299
|
>
|
|
304
300
|
{loading === true && (
|
|
305
|
-
|
|
306
|
-
|
|
307
|
-
|
|
301
|
+
<Spinner
|
|
302
|
+
color={theme.text.primary as unknown as ComponentProps<typeof Spinner>["color"]}
|
|
303
|
+
size="md"
|
|
304
|
+
/>
|
|
308
305
|
)}
|
|
309
|
-
{
|
|
306
|
+
{isMobileLayout ? renderMobileSplitPage() : renderSplitPage()}
|
|
310
307
|
</Box>
|
|
311
308
|
);
|
|
312
309
|
};
|
package/src/TapToEdit.test.tsx
CHANGED
|
@@ -403,4 +403,49 @@ describe("TapToEdit - additional function coverage", () => {
|
|
|
403
403
|
expect(getByText("Bio")).toBeTruthy();
|
|
404
404
|
expect(getByText("A long bio text")).toBeTruthy();
|
|
405
405
|
});
|
|
406
|
+
|
|
407
|
+
it("forwards testID to the edit control", () => {
|
|
408
|
+
const {getByTestId} = renderWithTheme(
|
|
409
|
+
<TapToEdit setValue={() => {}} testID="profile.name" title="Name" value="Jane" />
|
|
410
|
+
);
|
|
411
|
+
expect(getByTestId("profile.name.edit-clickable")).toBeTruthy();
|
|
412
|
+
});
|
|
413
|
+
|
|
414
|
+
it("forwards testID to cancel, clear, and save buttons while editing", async () => {
|
|
415
|
+
const {getByTestId} = renderWithTheme(
|
|
416
|
+
<TapToEdit
|
|
417
|
+
onSave={async () => {}}
|
|
418
|
+
setValue={() => {}}
|
|
419
|
+
showClearButton
|
|
420
|
+
testID="profile.name"
|
|
421
|
+
title="Name"
|
|
422
|
+
value="Jane"
|
|
423
|
+
/>
|
|
424
|
+
);
|
|
425
|
+
|
|
426
|
+
await act(async () => {
|
|
427
|
+
fireEvent.press(getByTestId("profile.name.edit-clickable"));
|
|
428
|
+
});
|
|
429
|
+
|
|
430
|
+
expect(getByTestId("profile.name")).toBeTruthy();
|
|
431
|
+
expect(getByTestId("profile.name.cancel")).toBeTruthy();
|
|
432
|
+
expect(getByTestId("profile.name.clear")).toBeTruthy();
|
|
433
|
+
expect(getByTestId("profile.name.save")).toBeTruthy();
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
it("does not set action testIDs when testID is omitted", async () => {
|
|
437
|
+
const {getByLabelText, queryByTestId} = renderWithTheme(
|
|
438
|
+
<TapToEdit setValue={() => {}} showClearButton title="Name" value="Jane" />
|
|
439
|
+
);
|
|
440
|
+
|
|
441
|
+
expect(queryByTestId("undefined.edit-clickable")).toBeNull();
|
|
442
|
+
|
|
443
|
+
await act(async () => {
|
|
444
|
+
fireEvent.press(getByLabelText("Edit"));
|
|
445
|
+
});
|
|
446
|
+
|
|
447
|
+
expect(queryByTestId("undefined.cancel")).toBeNull();
|
|
448
|
+
expect(queryByTestId("undefined.clear")).toBeNull();
|
|
449
|
+
expect(queryByTestId("undefined.save")).toBeNull();
|
|
450
|
+
});
|
|
406
451
|
});
|