@terreno/ui 57.2.0 → 57.3.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/Box.d.ts +1 -1
- package/dist/Box.js +219 -177
- package/dist/Box.js.map +1 -1
- package/dist/Button.js +101 -34
- package/dist/Button.js.map +1 -1
- package/dist/Common.d.ts +119 -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/DataTable.d.ts +2 -2
- package/dist/DataTable.js +203 -44
- 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/EmojiSelector.d.ts +2 -46
- package/dist/EmojiSelector.js +46 -56
- package/dist/EmojiSelector.js.map +1 -1
- package/dist/GPTChat.js +1 -1
- 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/MarkdownView.d.ts +6 -3
- package/dist/MarkdownView.js +45 -43
- 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/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/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/emojiCategories.d.ts +46 -0
- package/dist/emojiCategories.js +47 -0
- package/dist/emojiCategories.js.map +1 -0
- package/dist/index.d.ts +13 -13
- package/dist/index.js +2 -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 +41 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js +43 -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/package.json +40 -1
- package/src/AIRequestExplorer.test.tsx +141 -0
- package/src/ActionSheet.tsx +9 -7
- package/src/AttachmentPreview.test.tsx +80 -0
- package/src/Box.test.tsx +97 -10
- package/src/Box.tsx +263 -200
- package/src/Button.test.tsx +207 -0
- package/src/Button.tsx +146 -48
- package/src/Common.ts +124 -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.tsx +13 -5
- package/src/DataTable.tsx +418 -147
- 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/EmojiSelector.test.tsx +33 -42
- package/src/EmojiSelector.tsx +60 -57
- package/src/FilePickerButton.test.tsx +167 -0
- 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 +696 -0
- package/src/GPTChat.tsx +2 -2
- 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/MarkdownEditor.test.tsx +134 -0
- package/src/MarkdownEditorField.test.tsx +124 -0
- package/src/MarkdownView.test.tsx +55 -11
- package/src/MarkdownView.tsx +149 -150
- package/src/MediaQuery.ts +30 -34
- 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 +62 -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/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 +7 -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__/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__/TimezonePicker.test.tsx.snap +6 -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/emojiCategories.test.ts +23 -0
- package/src/emojiCategories.ts +46 -0
- package/src/index.tsx +27 -13
- 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 +106 -0
- package/src/login/LoginScreen.test.tsx +9 -2
- package/src/login/LoginScreen.tsx +6 -2
- package/src/login/loginTypes.ts +2 -0
- package/src/table/TableDate.test.tsx +35 -1
- package/src/table/__snapshots__/TableBadge.test.tsx.snap +1 -0
|
@@ -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,62 @@
|
|
|
1
|
+
import {describe, expect, it} from "bun:test";
|
|
2
|
+
|
|
3
|
+
import {
|
|
4
|
+
AIRequestExplorer,
|
|
5
|
+
Button,
|
|
6
|
+
ConsentNavigator,
|
|
7
|
+
DraggableList,
|
|
8
|
+
EmojiSelector,
|
|
9
|
+
GPTChat,
|
|
10
|
+
MarkdownEditor,
|
|
11
|
+
} from "@terreno/ui";
|
|
12
|
+
import {Box} from "@terreno/ui/Box";
|
|
13
|
+
import EmojiSelectorSubpath from "@terreno/ui/EmojiSelector";
|
|
14
|
+
import {GPTChat as GPTChatSubpath} from "@terreno/ui/GPTChat";
|
|
15
|
+
import {MarkdownView} from "@terreno/ui/MarkdownView";
|
|
16
|
+
|
|
17
|
+
import {Categories} from "./emojiCategories";
|
|
18
|
+
import {EmojiSelector as LazyEmojiSelector} from "./lazyBoundaries/heavyOptionalExports";
|
|
19
|
+
|
|
20
|
+
const ROOT_IMPORT_PATHS = [
|
|
21
|
+
"@terreno/ui",
|
|
22
|
+
"@terreno/ui/Button",
|
|
23
|
+
"@terreno/ui/Box",
|
|
24
|
+
"@terreno/ui/dist/Button.js",
|
|
25
|
+
"@terreno/ui/src/Button.tsx",
|
|
26
|
+
"@terreno/ui/GPTChat",
|
|
27
|
+
"@terreno/ui/EmojiSelector",
|
|
28
|
+
"@terreno/ui/MarkdownView",
|
|
29
|
+
];
|
|
30
|
+
|
|
31
|
+
describe("root import compatibility", () => {
|
|
32
|
+
it("keeps root Button export available", () => {
|
|
33
|
+
expect(Button).toBeTruthy();
|
|
34
|
+
});
|
|
35
|
+
|
|
36
|
+
it("resolves public subpath imports", () => {
|
|
37
|
+
expect(Box).toBeTruthy();
|
|
38
|
+
expect(GPTChatSubpath).toBeTruthy();
|
|
39
|
+
expect(EmojiSelectorSubpath).toBeTruthy();
|
|
40
|
+
expect(MarkdownView).toBeTruthy();
|
|
41
|
+
});
|
|
42
|
+
|
|
43
|
+
it("exposes lazy root exports for measured heavy optional widgets", () => {
|
|
44
|
+
expect(AIRequestExplorer).toBeTruthy();
|
|
45
|
+
expect(ConsentNavigator).toBeTruthy();
|
|
46
|
+
expect(DraggableList).toBeTruthy();
|
|
47
|
+
expect(EmojiSelector).toBeTruthy();
|
|
48
|
+
expect(GPTChat).toBeTruthy();
|
|
49
|
+
expect(MarkdownEditor).toBeTruthy();
|
|
50
|
+
expect(
|
|
51
|
+
(LazyEmojiSelector as unknown as {defaultProps?: {category?: typeof Categories.all}})
|
|
52
|
+
.defaultProps?.category
|
|
53
|
+
).toBe(Categories.all);
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("resolves documented package entrypoints", async () => {
|
|
57
|
+
for (const importPath of ROOT_IMPORT_PATHS) {
|
|
58
|
+
const moduleNamespace = await import(importPath);
|
|
59
|
+
expect(Object.keys(moduleNamespace).length).toBeGreaterThan(0);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
});
|
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
|
});
|
package/src/TapToEdit.tsx
CHANGED
|
@@ -8,6 +8,7 @@ import {Field} from "./Field";
|
|
|
8
8
|
import {Icon} from "./Icon";
|
|
9
9
|
// import {useOpenAPISpec} from "./OpenAPIContext";
|
|
10
10
|
import {Text} from "./Text";
|
|
11
|
+
import {resolveTestID} from "./testing/resolveTestId";
|
|
11
12
|
|
|
12
13
|
const TapToEditTitle: FC<{
|
|
13
14
|
onlyShowHelperTextWhileEditing?: boolean;
|
|
@@ -77,6 +78,7 @@ export const TapToEdit: FC<TapToEditProps> = ({
|
|
|
77
78
|
helperText: propsHelperText,
|
|
78
79
|
onlyShowHelperTextWhileEditing = true,
|
|
79
80
|
showClearButton = false,
|
|
81
|
+
testID,
|
|
80
82
|
...fieldProps
|
|
81
83
|
}) => {
|
|
82
84
|
const [editing, setEditing] = useState(false);
|
|
@@ -102,30 +104,29 @@ export const TapToEdit: FC<TapToEditProps> = ({
|
|
|
102
104
|
}
|
|
103
105
|
|
|
104
106
|
if (editable && (editing || isEditing)) {
|
|
107
|
+
const editableFieldProps = {
|
|
108
|
+
grow: fieldProps?.type === "textarea" ? (fieldProps.grow ?? true) : undefined,
|
|
109
|
+
helperText,
|
|
110
|
+
inputRef: ["text", "textarea", "url", "email", "number"].includes(fieldProps?.type)
|
|
111
|
+
? (ref: unknown): void => {
|
|
112
|
+
inputRef.current = ref as FocusableInput | null;
|
|
113
|
+
}
|
|
114
|
+
: undefined,
|
|
115
|
+
onChange: setValue as NonNullable<typeof setValue>,
|
|
116
|
+
row: fieldProps?.type === "textarea" ? 5 : undefined,
|
|
117
|
+
value,
|
|
118
|
+
...fieldProps,
|
|
119
|
+
testID,
|
|
120
|
+
type: (fieldProps?.type ?? "text") as NonNullable<FieldProps["type"]>,
|
|
121
|
+
} as unknown as FieldProps;
|
|
122
|
+
|
|
105
123
|
return (
|
|
106
124
|
<View style={{flexDirection: "column", width: "100%"}}>
|
|
107
125
|
<View style={{flex: 1, justifyContent: "center"}}>
|
|
108
126
|
<Text bold>{title}</Text>
|
|
109
127
|
</View>
|
|
110
128
|
<View style={{gap: 16}}>
|
|
111
|
-
<Field
|
|
112
|
-
grow={fieldProps?.type === "textarea" ? (fieldProps.grow ?? true) : undefined}
|
|
113
|
-
helperText={helperText}
|
|
114
|
-
inputRef={
|
|
115
|
-
["text", "textarea", "url", "email", "number"].includes(fieldProps?.type)
|
|
116
|
-
? (ref: unknown) => {
|
|
117
|
-
inputRef.current = ref as FocusableInput | null;
|
|
118
|
-
}
|
|
119
|
-
: undefined
|
|
120
|
-
}
|
|
121
|
-
onChange={setValue as NonNullable<typeof setValue>}
|
|
122
|
-
row={fieldProps?.type === "textarea" ? 5 : undefined}
|
|
123
|
-
type={(fieldProps?.type ?? "text") as NonNullable<FieldProps["type"]>}
|
|
124
|
-
value={value}
|
|
125
|
-
// noExplicitAny: fieldProps is a discriminated union (FieldProps) but the spread loses narrowing; type-checking each variant individually is impractical here
|
|
126
|
-
// biome-ignore lint/suspicious/noExplicitAny: fieldProps is a discriminated union (FieldProps) but the spread loses narrowing; type-checking each variant individually is impractical here
|
|
127
|
-
{...(fieldProps as any)}
|
|
128
|
-
/>
|
|
129
|
+
<Field {...editableFieldProps} />
|
|
129
130
|
{editing && !isEditing && (
|
|
130
131
|
<View style={{flexDirection: "row", gap: 16, justifyContent: "flex-end"}}>
|
|
131
132
|
<Button
|
|
@@ -135,6 +136,7 @@ export const TapToEdit: FC<TapToEditProps> = ({
|
|
|
135
136
|
}
|
|
136
137
|
setEditing(false);
|
|
137
138
|
}}
|
|
139
|
+
testID={resolveTestID(testID, "cancel")}
|
|
138
140
|
text="Cancel"
|
|
139
141
|
variant="muted"
|
|
140
142
|
/>
|
|
@@ -149,6 +151,7 @@ export const TapToEdit: FC<TapToEditProps> = ({
|
|
|
149
151
|
}
|
|
150
152
|
setEditing(false);
|
|
151
153
|
}}
|
|
154
|
+
testID={resolveTestID(testID, "clear")}
|
|
152
155
|
text="Clear"
|
|
153
156
|
variant="muted"
|
|
154
157
|
/>
|
|
@@ -165,6 +168,7 @@ export const TapToEdit: FC<TapToEditProps> = ({
|
|
|
165
168
|
}
|
|
166
169
|
setEditing(false);
|
|
167
170
|
}}
|
|
171
|
+
testID={resolveTestID(testID, "save")}
|
|
168
172
|
text="Save"
|
|
169
173
|
withConfirmation={withConfirmation}
|
|
170
174
|
/>
|
|
@@ -274,6 +278,7 @@ export const TapToEdit: FC<TapToEditProps> = ({
|
|
|
274
278
|
initialValueRef.current = value;
|
|
275
279
|
setEditing(true);
|
|
276
280
|
}}
|
|
281
|
+
testID={resolveTestID(testID, "edit")}
|
|
277
282
|
width={16}
|
|
278
283
|
>
|
|
279
284
|
<Icon iconName="pencil" size="md" />
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import type {mock} from "bun:test";
|
|
2
|
+
import {useFonts as useTextFonts} from "@expo-google-fonts/nunito";
|
|
3
|
+
import {useFonts as useHeadingFonts} from "@expo-google-fonts/titillium-web";
|
|
4
|
+
import {render} from "@testing-library/react-native";
|
|
5
|
+
import {assert} from "chai";
|
|
6
|
+
import type React from "react";
|
|
7
|
+
import {Text as NativeText} from "react-native";
|
|
8
|
+
|
|
9
|
+
import {TerrenoFontProvider, useTerrenoFontsLoaded} from "./TerrenoFontProvider";
|
|
10
|
+
|
|
11
|
+
const FontStatus: React.FC = () => {
|
|
12
|
+
const areFontsLoaded = useTerrenoFontsLoaded();
|
|
13
|
+
return <NativeText testID="font-status">{String(areFontsLoaded)}</NativeText>;
|
|
14
|
+
};
|
|
15
|
+
|
|
16
|
+
describe("TerrenoFontProvider", () => {
|
|
17
|
+
it("publishes font-load completion so memoized typography redraws", () => {
|
|
18
|
+
(useTextFonts as ReturnType<typeof mock>).mockReturnValue([false, null]);
|
|
19
|
+
(useHeadingFonts as ReturnType<typeof mock>).mockReturnValue([false, null]);
|
|
20
|
+
const result = render(
|
|
21
|
+
<TerrenoFontProvider>
|
|
22
|
+
<FontStatus />
|
|
23
|
+
</TerrenoFontProvider>
|
|
24
|
+
);
|
|
25
|
+
|
|
26
|
+
assert.equal(result.getByTestId("font-status").children[0], "false");
|
|
27
|
+
|
|
28
|
+
(useTextFonts as ReturnType<typeof mock>).mockReturnValue([true, null]);
|
|
29
|
+
(useHeadingFonts as ReturnType<typeof mock>).mockReturnValue([true, null]);
|
|
30
|
+
result.rerender(
|
|
31
|
+
<TerrenoFontProvider>
|
|
32
|
+
<FontStatus />
|
|
33
|
+
</TerrenoFontProvider>
|
|
34
|
+
);
|
|
35
|
+
|
|
36
|
+
assert.equal(result.getByTestId("font-status").children[0], "true");
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
import {
|
|
2
|
+
Nunito_400Regular,
|
|
3
|
+
Nunito_400Regular_Italic,
|
|
4
|
+
Nunito_500Medium,
|
|
5
|
+
Nunito_500Medium_Italic,
|
|
6
|
+
Nunito_700Bold,
|
|
7
|
+
Nunito_700Bold_Italic,
|
|
8
|
+
useFonts as useTextFonts,
|
|
9
|
+
} from "@expo-google-fonts/nunito";
|
|
10
|
+
import {
|
|
11
|
+
TitilliumWeb_600SemiBold,
|
|
12
|
+
TitilliumWeb_700Bold,
|
|
13
|
+
useFonts as useHeadingFonts,
|
|
14
|
+
} from "@expo-google-fonts/titillium-web";
|
|
15
|
+
import {createContext, type FC, type ReactNode, useContext} from "react";
|
|
16
|
+
|
|
17
|
+
interface TerrenoFontProviderProps {
|
|
18
|
+
children: ReactNode;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
const TerrenoFontLoadContext = createContext(true);
|
|
22
|
+
|
|
23
|
+
export const TerrenoFontProvider: FC<TerrenoFontProviderProps> = ({children}) => {
|
|
24
|
+
const [areTextFontsLoaded] = useTextFonts({
|
|
25
|
+
text: Nunito_400Regular,
|
|
26
|
+
"text-bold": Nunito_700Bold,
|
|
27
|
+
"text-bold-italic": Nunito_700Bold_Italic,
|
|
28
|
+
"text-medium": Nunito_500Medium,
|
|
29
|
+
"text-medium-italic": Nunito_500Medium_Italic,
|
|
30
|
+
"text-regular": Nunito_400Regular,
|
|
31
|
+
"text-regular-italic": Nunito_400Regular_Italic,
|
|
32
|
+
});
|
|
33
|
+
const [areHeadingFontsLoaded] = useHeadingFonts({
|
|
34
|
+
heading: TitilliumWeb_600SemiBold,
|
|
35
|
+
"heading-bold": TitilliumWeb_700Bold,
|
|
36
|
+
"heading-semibold": TitilliumWeb_600SemiBold,
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
const areFontsLoaded = areTextFontsLoaded && areHeadingFontsLoaded;
|
|
40
|
+
|
|
41
|
+
return (
|
|
42
|
+
<TerrenoFontLoadContext.Provider value={areFontsLoaded}>
|
|
43
|
+
{children}
|
|
44
|
+
</TerrenoFontLoadContext.Provider>
|
|
45
|
+
);
|
|
46
|
+
};
|
|
47
|
+
|
|
48
|
+
export const useTerrenoFontsLoaded = (): boolean => {
|
|
49
|
+
return useContext(TerrenoFontLoadContext);
|
|
50
|
+
};
|
package/src/TerrenoProvider.tsx
CHANGED
|
@@ -36,7 +36,12 @@ export const TerrenoProvider: FC<{
|
|
|
36
36
|
providerOnHide?.();
|
|
37
37
|
};
|
|
38
38
|
|
|
39
|
-
|
|
39
|
+
const toastData = toastOptions?.data;
|
|
40
|
+
const title =
|
|
41
|
+
toastData?.title ??
|
|
42
|
+
(typeof toastOptions?.message === "string" ? toastOptions.message : "");
|
|
43
|
+
|
|
44
|
+
return <Toast {...toastData} onDismiss={handleDismiss} title={title} />;
|
|
40
45
|
}}
|
|
41
46
|
swipeEnabled
|
|
42
47
|
>
|