@terreno/ui 57.7.0 → 57.9.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/dist/AreaChart.d.ts +1 -1
- package/dist/AreaChart.d.ts.map +1 -1
- package/dist/AreaChart.js +70 -22
- package/dist/AreaChart.js.map +1 -1
- package/dist/Avatar.js +2 -2
- package/dist/Avatar.js.map +1 -1
- package/dist/BarChart.d.ts.map +1 -1
- package/dist/BarChart.js +55 -13
- package/dist/BarChart.js.map +1 -1
- package/dist/Button.js +2 -2
- package/dist/Button.js.map +1 -1
- package/dist/ChartCard.d.ts +5 -0
- package/dist/ChartCard.d.ts.map +1 -0
- package/dist/ChartCard.js +18 -0
- package/dist/ChartCard.js.map +1 -0
- package/dist/Common.d.ts +128 -5
- package/dist/Common.d.ts.map +1 -1
- package/dist/Common.js.map +1 -1
- package/dist/DashboardGrid.d.ts +6 -2
- package/dist/DashboardGrid.d.ts.map +1 -1
- package/dist/DashboardGrid.js +43 -10
- package/dist/DashboardGrid.js.map +1 -1
- package/dist/DateTimeActionSheet.js +2 -2
- package/dist/DateTimeActionSheet.js.map +1 -1
- package/dist/DateTimeField.js +3 -3
- package/dist/DateTimeField.js.map +1 -1
- package/dist/DonutChart.d.ts.map +1 -1
- package/dist/DonutChart.js +20 -10
- package/dist/DonutChart.js.map +1 -1
- package/dist/DropdownMenuItem.d.ts +16 -0
- package/dist/DropdownMenuItem.d.ts.map +1 -0
- package/dist/DropdownMenuItem.js +11 -0
- package/dist/DropdownMenuItem.js.map +1 -0
- package/dist/DropdownPanel.d.ts.map +1 -1
- package/dist/DropdownPanel.js +1 -1
- package/dist/DropdownPanel.js.map +1 -1
- package/dist/FilePickerButton.d.ts.map +1 -1
- package/dist/FilePickerButton.js +70 -10
- package/dist/FilePickerButton.js.map +1 -1
- package/dist/GPTChat.d.ts.map +1 -1
- package/dist/GPTChat.js +103 -14
- package/dist/GPTChat.js.map +1 -1
- package/dist/HeightField.js +2 -2
- package/dist/HeightField.js.map +1 -1
- package/dist/IconButton.d.ts.map +1 -1
- package/dist/IconButton.js +9 -6
- package/dist/IconButton.js.map +1 -1
- package/dist/LineChart.d.ts +1 -1
- package/dist/LineChart.d.ts.map +1 -1
- package/dist/LineChart.js +62 -21
- package/dist/LineChart.js.map +1 -1
- package/dist/MediaQuery.d.ts +10 -0
- package/dist/MediaQuery.d.ts.map +1 -1
- package/dist/MediaQuery.js +13 -1
- package/dist/MediaQuery.js.map +1 -1
- package/dist/MultiselectField.js +2 -2
- package/dist/MultiselectField.js.map +1 -1
- package/dist/RadioField.js +2 -2
- package/dist/RadioField.js.map +1 -1
- package/dist/Scorecard.d.ts +5 -0
- package/dist/Scorecard.d.ts.map +1 -0
- package/dist/Scorecard.js +11 -0
- package/dist/Scorecard.js.map +1 -0
- package/dist/SparklineChart.d.ts +5 -0
- package/dist/SparklineChart.d.ts.map +1 -0
- package/dist/SparklineChart.js +35 -0
- package/dist/SparklineChart.js.map +1 -0
- package/dist/SplitPage.d.ts +1 -1
- package/dist/SplitPage.d.ts.map +1 -1
- package/dist/SplitPage.js +126 -21
- package/dist/SplitPage.js.map +1 -1
- package/dist/TextField.d.ts.map +1 -1
- package/dist/TextField.js +12 -4
- package/dist/TextField.js.map +1 -1
- package/dist/ToastNotifications.d.ts.map +1 -1
- package/dist/ToastNotifications.js +29 -6
- package/dist/ToastNotifications.js.map +1 -1
- package/dist/UnifiedAddressAutoComplete.js +2 -2
- package/dist/UnifiedAddressAutoComplete.js.map +1 -1
- package/dist/WebDropdownMenu.d.ts +2 -1
- package/dist/WebDropdownMenu.d.ts.map +1 -1
- package/dist/WebDropdownMenu.js +2 -6
- package/dist/WebDropdownMenu.js.map +1 -1
- package/dist/charts/ChartFacadeContainer.d.ts +10 -0
- package/dist/charts/ChartFacadeContainer.d.ts.map +1 -0
- package/dist/charts/ChartFacadeContainer.js +10 -0
- package/dist/charts/ChartFacadeContainer.js.map +1 -0
- package/dist/charts/ChartFrame.d.ts +4 -0
- package/dist/charts/ChartFrame.d.ts.map +1 -1
- package/dist/charts/ChartFrame.js +4 -2
- package/dist/charts/ChartFrame.js.map +1 -1
- package/dist/charts/layout.d.ts +9 -2
- package/dist/charts/layout.d.ts.map +1 -1
- package/dist/charts/layout.js +28 -6
- package/dist/charts/layout.js.map +1 -1
- package/dist/charts/scales.d.ts +3 -1
- package/dist/charts/scales.d.ts.map +1 -1
- package/dist/charts/scales.js +7 -7
- package/dist/charts/scales.js.map +1 -1
- package/dist/charts/series.d.ts +15 -0
- package/dist/charts/series.d.ts.map +1 -0
- package/dist/charts/series.js +19 -0
- package/dist/charts/series.js.map +1 -0
- package/dist/charts/types/chartTypes.d.ts +7 -0
- package/dist/charts/types/chartTypes.d.ts.map +1 -1
- package/dist/dashboardGridLayout.d.ts +6 -0
- package/dist/dashboardGridLayout.d.ts.map +1 -1
- package/dist/dashboardGridLayout.js +19 -3
- package/dist/dashboardGridLayout.js.map +1 -1
- package/dist/fieldElements/FieldTitle.js +2 -2
- package/dist/fieldElements/FieldTitle.js.map +1 -1
- package/dist/index.d.ts +4 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +1 -1
- package/dist/index.js.map +1 -1
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts +9 -0
- package/dist/lazyBoundaries/heavyOptionalExports.d.ts.map +1 -1
- package/dist/lazyBoundaries/heavyOptionalExports.js +6 -0
- package/dist/lazyBoundaries/heavyOptionalExports.js.map +1 -1
- package/dist/resolveDocumentBodyPortalTarget.d.ts +7 -0
- package/dist/resolveDocumentBodyPortalTarget.d.ts.map +1 -0
- package/dist/resolveDocumentBodyPortalTarget.js +12 -0
- package/dist/resolveDocumentBodyPortalTarget.js.map +1 -0
- package/package.json +1 -1
- package/src/AIRequestExplorer.test.tsx +2 -2
- package/src/AreaChart.test.tsx +81 -0
- package/src/AreaChart.tsx +171 -62
- package/src/Avatar.tsx +2 -2
- package/src/BarChart.test.tsx +119 -0
- package/src/BarChart.tsx +94 -20
- package/src/Button.test.tsx +7 -7
- package/src/Button.tsx +2 -2
- package/src/ChartCard.test.tsx +79 -0
- package/src/ChartCard.tsx +80 -0
- package/src/Common.ts +119 -2
- package/src/DashboardGrid.test.tsx +98 -1
- package/src/DashboardGrid.tsx +71 -20
- package/src/DateTimeActionSheet.tsx +4 -4
- package/src/DateTimeField.test.tsx +5 -4
- package/src/DateTimeField.tsx +3 -3
- package/src/DonutChart.test.tsx +73 -0
- package/src/DonutChart.tsx +87 -14
- package/src/DropdownMenuItem.tsx +48 -0
- package/src/DropdownPanel.test.tsx +12 -0
- package/src/DropdownPanel.tsx +8 -1
- package/src/FilePickerButton.test.tsx +60 -6
- package/src/FilePickerButton.tsx +116 -28
- package/src/GPTChat.test.tsx +133 -6
- package/src/GPTChat.tsx +196 -38
- package/src/HeightField.tsx +2 -2
- package/src/IconButton.test.tsx +63 -0
- package/src/IconButton.tsx +10 -5
- package/src/LineChart.test.tsx +104 -0
- package/src/LineChart.tsx +154 -58
- package/src/MediaQuery.ts +14 -1
- package/src/MultiselectField.tsx +2 -2
- package/src/RadioField.tsx +2 -2
- package/src/Scorecard.test.tsx +65 -0
- package/src/Scorecard.tsx +45 -0
- package/src/SparklineChart.test.tsx +69 -0
- package/src/SparklineChart.tsx +85 -0
- package/src/SplitPage.test.tsx +449 -11
- package/src/SplitPage.tsx +255 -21
- package/src/TextField.test.tsx +16 -0
- package/src/TextField.tsx +13 -3
- package/src/ToastNotifications.tsx +33 -6
- package/src/ToastNotifications.webModal.test.tsx +285 -0
- package/src/UnifiedAddressAutoComplete.test.tsx +4 -4
- package/src/UnifiedAddressAutoComplete.tsx +2 -2
- package/src/WebDropdownMenu.tsx +3 -7
- package/src/__snapshots__/DropdownPanel.test.tsx.snap +3 -1
- package/src/bunSetup.ts +3 -1
- package/src/charts/ChartFacadeContainer.tsx +35 -0
- package/src/charts/ChartFrame.tsx +39 -1
- package/src/charts/layout.test.ts +22 -1
- package/src/charts/layout.ts +37 -4
- package/src/charts/scales.test.ts +33 -0
- package/src/charts/scales.ts +10 -6
- package/src/charts/series.ts +43 -0
- package/src/charts/types/chartTypes.ts +8 -0
- package/src/dashboardGridLayout.test.ts +59 -1
- package/src/dashboardGridLayout.ts +30 -3
- package/src/fieldElements/FieldTitle.tsx +2 -2
- package/src/index.tsx +6 -0
- package/src/lazyBoundaries/heavyOptionalExports.tsx +21 -0
- package/src/resolveDocumentBodyPortalTarget.ts +11 -0
|
@@ -0,0 +1,285 @@
|
|
|
1
|
+
import {afterEach, beforeAll, beforeEach, describe, expect, it, spyOn} from "bun:test";
|
|
2
|
+
import {act, render, waitFor} from "@testing-library/react-native";
|
|
3
|
+
import type {ReactElement} from "react";
|
|
4
|
+
import {
|
|
5
|
+
Platform as ImportedPlatform,
|
|
6
|
+
KeyboardAvoidingView,
|
|
7
|
+
Pressable,
|
|
8
|
+
StyleSheet,
|
|
9
|
+
Text,
|
|
10
|
+
} from "react-native";
|
|
11
|
+
import type {ReactTestInstance} from "react-test-renderer";
|
|
12
|
+
|
|
13
|
+
import {Modal} from "./Modal";
|
|
14
|
+
import {ToastProvider, type ToastType, useToastNotifications} from "./ToastNotifications";
|
|
15
|
+
import {renderWithTheme} from "./test-utils";
|
|
16
|
+
import * as Utilities from "./Utilities";
|
|
17
|
+
|
|
18
|
+
// react-native-web ModalAnimation paints the dialog layer at this z-index on document.body.
|
|
19
|
+
const REACT_NATIVE_WEB_MODAL_Z_INDEX = 9999;
|
|
20
|
+
|
|
21
|
+
const TOAST_MESSAGE = "Saved above the modal";
|
|
22
|
+
|
|
23
|
+
interface PortalFiber {
|
|
24
|
+
return: PortalFiber | null;
|
|
25
|
+
stateNode: {containerInfo?: unknown} | null;
|
|
26
|
+
tag: number;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
const HOST_PORTAL_TAG = 4;
|
|
30
|
+
|
|
31
|
+
const collectPlatformObjects = (): {OS: string}[] => {
|
|
32
|
+
const objects: {OS: string}[] = [];
|
|
33
|
+
const push = (candidate: unknown): void => {
|
|
34
|
+
if (
|
|
35
|
+
candidate &&
|
|
36
|
+
typeof candidate === "object" &&
|
|
37
|
+
"OS" in (candidate as Record<string, unknown>) &&
|
|
38
|
+
!objects.includes(candidate as {OS: string})
|
|
39
|
+
) {
|
|
40
|
+
objects.push(candidate as {OS: string});
|
|
41
|
+
}
|
|
42
|
+
};
|
|
43
|
+
push(ImportedPlatform);
|
|
44
|
+
const rn = require("react-native") as {Platform?: unknown; default?: {Platform?: unknown}};
|
|
45
|
+
push(rn.Platform);
|
|
46
|
+
push(rn.default?.Platform);
|
|
47
|
+
try {
|
|
48
|
+
const libPlatform = require("react-native/Libraries/Utilities/Platform") as {
|
|
49
|
+
default?: unknown;
|
|
50
|
+
};
|
|
51
|
+
push(libPlatform.default);
|
|
52
|
+
} catch {
|
|
53
|
+
// The internal Platform module may not be resolvable; the top-level mock still covers it.
|
|
54
|
+
}
|
|
55
|
+
return objects;
|
|
56
|
+
};
|
|
57
|
+
|
|
58
|
+
const platformObjects = collectPlatformObjects();
|
|
59
|
+
const originalPlatformOS = platformObjects.map((platform) => platform.OS);
|
|
60
|
+
|
|
61
|
+
const setPlatformOS = (os: string): void => {
|
|
62
|
+
for (const platform of platformObjects) {
|
|
63
|
+
try {
|
|
64
|
+
platform.OS = os;
|
|
65
|
+
} catch {
|
|
66
|
+
// Skip any binding that is not writable.
|
|
67
|
+
}
|
|
68
|
+
}
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
const restorePlatformOS = (): void => {
|
|
72
|
+
platformObjects.forEach((platform, index) => {
|
|
73
|
+
try {
|
|
74
|
+
platform.OS = originalPlatformOS[index] ?? "ios";
|
|
75
|
+
} catch {
|
|
76
|
+
// Skip any binding that is not writable.
|
|
77
|
+
}
|
|
78
|
+
});
|
|
79
|
+
};
|
|
80
|
+
|
|
81
|
+
const globalScope = globalThis as {document?: unknown; HTMLElement?: unknown};
|
|
82
|
+
const originalDocument = globalScope.document;
|
|
83
|
+
const originalHTMLElement = globalScope.HTMLElement;
|
|
84
|
+
|
|
85
|
+
class TestHTMLElement {
|
|
86
|
+
nodeType = 1;
|
|
87
|
+
// react-test-renderer commits a portal by appending host nodes onto `container.children`
|
|
88
|
+
// and reads `createNodeMock` from that container when attaching refs.
|
|
89
|
+
children: unknown[] = [];
|
|
90
|
+
createNodeMock = (): Record<string, never> => ({});
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const installDocumentBody = (): TestHTMLElement => {
|
|
94
|
+
const body = new TestHTMLElement();
|
|
95
|
+
globalScope.HTMLElement = TestHTMLElement;
|
|
96
|
+
globalScope.document = {activeElement: null, body};
|
|
97
|
+
return body;
|
|
98
|
+
};
|
|
99
|
+
|
|
100
|
+
const restoreDocument = (): void => {
|
|
101
|
+
globalScope.document = originalDocument;
|
|
102
|
+
globalScope.HTMLElement = originalHTMLElement;
|
|
103
|
+
};
|
|
104
|
+
|
|
105
|
+
const flattenStyle = (style: unknown): {pointerEvents?: string; zIndex?: number} => {
|
|
106
|
+
return StyleSheet.flatten(style) as {pointerEvents?: string; zIndex?: number};
|
|
107
|
+
};
|
|
108
|
+
|
|
109
|
+
const portalContainerFor = (node: ReactTestInstance): unknown => {
|
|
110
|
+
let fiber = (node as unknown as {_fiber?: PortalFiber})._fiber ?? null;
|
|
111
|
+
while (fiber) {
|
|
112
|
+
if (fiber.tag === HOST_PORTAL_TAG) {
|
|
113
|
+
return fiber.stateNode?.containerInfo;
|
|
114
|
+
}
|
|
115
|
+
fiber = fiber.return;
|
|
116
|
+
}
|
|
117
|
+
return undefined;
|
|
118
|
+
};
|
|
119
|
+
|
|
120
|
+
const isInside = (node: ReactTestInstance, ancestor: ReactTestInstance): boolean => {
|
|
121
|
+
let current: ReactTestInstance | null = node;
|
|
122
|
+
while (current) {
|
|
123
|
+
if (current === ancestor) {
|
|
124
|
+
return true;
|
|
125
|
+
}
|
|
126
|
+
current = current.parent;
|
|
127
|
+
}
|
|
128
|
+
return false;
|
|
129
|
+
};
|
|
130
|
+
|
|
131
|
+
const findBackdrop = (pressables: ReactTestInstance[]): ReactTestInstance | undefined => {
|
|
132
|
+
return pressables.find((node) => {
|
|
133
|
+
const style = node.props.style as {backgroundColor?: string} | {backgroundColor?: string}[];
|
|
134
|
+
if (Array.isArray(style)) {
|
|
135
|
+
return style.some((entry) => entry?.backgroundColor?.includes("rgba"));
|
|
136
|
+
}
|
|
137
|
+
return style?.backgroundColor?.includes("rgba");
|
|
138
|
+
});
|
|
139
|
+
};
|
|
140
|
+
|
|
141
|
+
const flushFrames = async (): Promise<void> => {
|
|
142
|
+
for (let i = 0; i < 5; i++) {
|
|
143
|
+
await act(async () => {
|
|
144
|
+
await new Promise((resolve) => setTimeout(resolve, 20));
|
|
145
|
+
});
|
|
146
|
+
}
|
|
147
|
+
};
|
|
148
|
+
|
|
149
|
+
beforeAll(() => {
|
|
150
|
+
global.requestAnimationFrame = (callback: FrameRequestCallback) => {
|
|
151
|
+
return setTimeout(() => callback(Date.now()), 0) as unknown as number;
|
|
152
|
+
};
|
|
153
|
+
global.cancelAnimationFrame = (id: number) => {
|
|
154
|
+
clearTimeout(id);
|
|
155
|
+
};
|
|
156
|
+
});
|
|
157
|
+
|
|
158
|
+
describe("Toast above an open web modal", () => {
|
|
159
|
+
let isNativeSpy: ReturnType<typeof spyOn> | undefined;
|
|
160
|
+
|
|
161
|
+
beforeEach(() => {
|
|
162
|
+
setPlatformOS("web");
|
|
163
|
+
isNativeSpy = spyOn(Utilities, "isNative").mockReturnValue(false);
|
|
164
|
+
installDocumentBody();
|
|
165
|
+
});
|
|
166
|
+
|
|
167
|
+
afterEach(() => {
|
|
168
|
+
isNativeSpy?.mockRestore();
|
|
169
|
+
restorePlatformOS();
|
|
170
|
+
restoreDocument();
|
|
171
|
+
});
|
|
172
|
+
|
|
173
|
+
it("portals the toast onto document.body above the modal backdrop", async () => {
|
|
174
|
+
const body = globalScope.document
|
|
175
|
+
? (globalScope.document as {body: TestHTMLElement}).body
|
|
176
|
+
: undefined;
|
|
177
|
+
let toastRef: ToastType | null = null;
|
|
178
|
+
|
|
179
|
+
const Harness = (): ReactElement => {
|
|
180
|
+
toastRef = useToastNotifications();
|
|
181
|
+
return (
|
|
182
|
+
<Modal onDismiss={() => {}} title="Confirm" visible>
|
|
183
|
+
<Text>Modal body</Text>
|
|
184
|
+
</Modal>
|
|
185
|
+
);
|
|
186
|
+
};
|
|
187
|
+
|
|
188
|
+
const {getByText, UNSAFE_getAllByType} = renderWithTheme(
|
|
189
|
+
<ToastProvider swipeEnabled={false}>
|
|
190
|
+
<Harness />
|
|
191
|
+
</ToastProvider>
|
|
192
|
+
);
|
|
193
|
+
|
|
194
|
+
await waitFor(() => {
|
|
195
|
+
expect(toastRef?.show).toBeDefined();
|
|
196
|
+
});
|
|
197
|
+
|
|
198
|
+
await act(async () => {
|
|
199
|
+
toastRef?.show(TOAST_MESSAGE, {duration: 0, id: "above-modal"});
|
|
200
|
+
});
|
|
201
|
+
await flushFrames();
|
|
202
|
+
|
|
203
|
+
const toastText = getByText(TOAST_MESSAGE);
|
|
204
|
+
const toastHost = UNSAFE_getAllByType(KeyboardAvoidingView).find((node) =>
|
|
205
|
+
isInside(toastText, node)
|
|
206
|
+
);
|
|
207
|
+
expect(toastHost).toBeTruthy();
|
|
208
|
+
|
|
209
|
+
const hostStyle = flattenStyle(toastHost?.props.style);
|
|
210
|
+
expect(hostStyle.pointerEvents).toBe("box-none");
|
|
211
|
+
expect(hostStyle.zIndex).toBeGreaterThan(REACT_NATIVE_WEB_MODAL_Z_INDEX);
|
|
212
|
+
|
|
213
|
+
expect(portalContainerFor(toastText)).toBe(body);
|
|
214
|
+
|
|
215
|
+
const backdrop = findBackdrop(UNSAFE_getAllByType(Pressable));
|
|
216
|
+
expect(backdrop).toBeTruthy();
|
|
217
|
+
expect(isInside(toastText, backdrop as ReactTestInstance)).toBe(false);
|
|
218
|
+
});
|
|
219
|
+
|
|
220
|
+
// Static export pre-renders in Node, where Dimensions reports a 0x0 window; a measured
|
|
221
|
+
// pixel width would bake a 0px container into the HTML and push the toast off-screen.
|
|
222
|
+
it("sizes the fixed container to the viewport instead of the measured window", async () => {
|
|
223
|
+
let toastRef: ToastType | null = null;
|
|
224
|
+
const Harness = (): ReactElement => {
|
|
225
|
+
toastRef = useToastNotifications();
|
|
226
|
+
return <Text>App</Text>;
|
|
227
|
+
};
|
|
228
|
+
|
|
229
|
+
const {getByText, UNSAFE_getAllByType} = renderWithTheme(
|
|
230
|
+
<ToastProvider swipeEnabled={false}>
|
|
231
|
+
<Harness />
|
|
232
|
+
</ToastProvider>
|
|
233
|
+
);
|
|
234
|
+
|
|
235
|
+
await waitFor(() => {
|
|
236
|
+
expect(toastRef?.show).toBeDefined();
|
|
237
|
+
});
|
|
238
|
+
await act(async () => {
|
|
239
|
+
toastRef?.show(TOAST_MESSAGE, {duration: 0, id: "static-export"});
|
|
240
|
+
});
|
|
241
|
+
await flushFrames();
|
|
242
|
+
|
|
243
|
+
const toastText = getByText(TOAST_MESSAGE);
|
|
244
|
+
const toastHost = UNSAFE_getAllByType(KeyboardAvoidingView).find((node) =>
|
|
245
|
+
isInside(toastText, node)
|
|
246
|
+
);
|
|
247
|
+
expect((StyleSheet.flatten(toastHost?.props.style) as {width?: unknown}).width).toBe("100%");
|
|
248
|
+
});
|
|
249
|
+
});
|
|
250
|
+
|
|
251
|
+
describe("Toast container on native", () => {
|
|
252
|
+
afterEach(() => {
|
|
253
|
+
restorePlatformOS();
|
|
254
|
+
restoreDocument();
|
|
255
|
+
});
|
|
256
|
+
|
|
257
|
+
it("keeps the toast in the tree when a document body exists", async () => {
|
|
258
|
+
setPlatformOS("ios");
|
|
259
|
+
installDocumentBody();
|
|
260
|
+
|
|
261
|
+
let toastRef: ToastType | null = null;
|
|
262
|
+
const Harness = (): ReactElement => {
|
|
263
|
+
toastRef = useToastNotifications();
|
|
264
|
+
return <Text>App</Text>;
|
|
265
|
+
};
|
|
266
|
+
|
|
267
|
+
const {getByText} = render(
|
|
268
|
+
<ToastProvider swipeEnabled={false}>
|
|
269
|
+
<Harness />
|
|
270
|
+
</ToastProvider>
|
|
271
|
+
);
|
|
272
|
+
|
|
273
|
+
await waitFor(() => {
|
|
274
|
+
expect(toastRef?.show).toBeDefined();
|
|
275
|
+
});
|
|
276
|
+
|
|
277
|
+
await act(async () => {
|
|
278
|
+
toastRef?.show(TOAST_MESSAGE, {duration: 0, id: "native-toast"});
|
|
279
|
+
});
|
|
280
|
+
await flushFrames();
|
|
281
|
+
|
|
282
|
+
const toastText = getByText(TOAST_MESSAGE);
|
|
283
|
+
expect(portalContainerFor(toastText)).toBeUndefined();
|
|
284
|
+
});
|
|
285
|
+
});
|
|
@@ -3,7 +3,7 @@ import {fireEvent} from "@testing-library/react-native";
|
|
|
3
3
|
import {forwardRef} from "react";
|
|
4
4
|
import {Text, View} from "react-native";
|
|
5
5
|
|
|
6
|
-
import {
|
|
6
|
+
import {isNarrowViewport} from "./MediaQuery";
|
|
7
7
|
import {renderWithTheme} from "./test-utils";
|
|
8
8
|
import {UnifiedAddressAutoCompleteField} from "./UnifiedAddressAutoComplete";
|
|
9
9
|
|
|
@@ -136,11 +136,11 @@ describe("UnifiedAddressAutoCompleteField", () => {
|
|
|
136
136
|
|
|
137
137
|
describe("mobile/native branch", () => {
|
|
138
138
|
afterEach(() => {
|
|
139
|
-
(
|
|
139
|
+
(isNarrowViewport as ReturnType<typeof mock>).mockImplementation(() => false);
|
|
140
140
|
});
|
|
141
141
|
|
|
142
|
-
it("renders MobileAddressAutocomplete when
|
|
143
|
-
(
|
|
142
|
+
it("renders MobileAddressAutocomplete when isNarrowViewport + isNative + valid key", () => {
|
|
143
|
+
(isNarrowViewport as ReturnType<typeof mock>).mockImplementation(() => true);
|
|
144
144
|
const {getByTestId} = renderWithTheme(
|
|
145
145
|
<UnifiedAddressAutoCompleteField
|
|
146
146
|
{...defaultProps}
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import {useMemo} from "react";
|
|
2
2
|
|
|
3
3
|
import type {AddressAutocompleteProps} from "./Common";
|
|
4
|
-
import {
|
|
4
|
+
import {isNarrowViewport} from "./MediaQuery";
|
|
5
5
|
import {MobileAddressAutocomplete} from "./MobileAddressAutoComplete";
|
|
6
6
|
import {TextField} from "./TextField";
|
|
7
7
|
import {isNative, isValidGoogleApiKey} from "./Utilities";
|
|
@@ -35,7 +35,7 @@ export const UnifiedAddressAutoCompleteField = ({
|
|
|
35
35
|
testID={testID}
|
|
36
36
|
/>
|
|
37
37
|
);
|
|
38
|
-
} else if (
|
|
38
|
+
} else if (isNarrowViewport() && isNative() && isValidatedGoogleApiKey) {
|
|
39
39
|
return (
|
|
40
40
|
<MobileAddressAutocomplete
|
|
41
41
|
disabled={disabled}
|
package/src/WebDropdownMenu.tsx
CHANGED
|
@@ -14,9 +14,12 @@ import {
|
|
|
14
14
|
} from "react-native";
|
|
15
15
|
|
|
16
16
|
import {createWebPortal} from "./createWebPortal";
|
|
17
|
+
import {resolveDocumentBodyPortalTarget} from "./resolveDocumentBodyPortalTarget";
|
|
17
18
|
import {useTheme} from "./Theme";
|
|
18
19
|
import {createBoxShadow} from "./Utilities";
|
|
19
20
|
|
|
21
|
+
export {resolveDocumentBodyPortalTarget};
|
|
22
|
+
|
|
20
23
|
export const scheduleAfterPaint = (callback: () => void): void => {
|
|
21
24
|
if (typeof requestAnimationFrame === "function") {
|
|
22
25
|
requestAnimationFrame(callback);
|
|
@@ -25,13 +28,6 @@ export const scheduleAfterPaint = (callback: () => void): void => {
|
|
|
25
28
|
}
|
|
26
29
|
};
|
|
27
30
|
|
|
28
|
-
export const resolveDocumentBodyPortalTarget = (): HTMLElement | null => {
|
|
29
|
-
if (typeof document === "undefined" || typeof HTMLElement === "undefined") {
|
|
30
|
-
return null;
|
|
31
|
-
}
|
|
32
|
-
return document.body instanceof HTMLElement ? document.body : null;
|
|
33
|
-
};
|
|
34
|
-
|
|
35
31
|
export interface WebDropdownMenuOption {
|
|
36
32
|
key?: string | number;
|
|
37
33
|
label: string;
|
package/src/bunSetup.ts
CHANGED
|
@@ -850,8 +850,9 @@ mock.module("react-native-actions-sheet", () => ({
|
|
|
850
850
|
|
|
851
851
|
// Mock MediaQuery
|
|
852
852
|
mock.module("./MediaQuery", () => ({
|
|
853
|
-
|
|
853
|
+
isNarrowViewport: mock(() => false),
|
|
854
854
|
mediaQueryLargerThan: mock(() => false),
|
|
855
|
+
mediaQuerySmallerThan: mock(() => false),
|
|
855
856
|
}));
|
|
856
857
|
|
|
857
858
|
// Mock expo-image-manipulator
|
|
@@ -895,6 +896,7 @@ mock.module("expo-haptics", () => ({
|
|
|
895
896
|
mock.module("expo-clipboard", () => ({
|
|
896
897
|
getStringAsync: mock(() => Promise.resolve("")),
|
|
897
898
|
hasStringAsync: mock(() => Promise.resolve(false)),
|
|
899
|
+
setImageAsync: mock(() => Promise.resolve(undefined)),
|
|
898
900
|
setStringAsync: mock(() => Promise.resolve(undefined)),
|
|
899
901
|
}));
|
|
900
902
|
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
import type {FC, ReactNode} from "react";
|
|
2
|
+
|
|
3
|
+
import {ChartCard} from "../ChartCard";
|
|
4
|
+
import {resolveTestID} from "../testing/resolveTestId";
|
|
5
|
+
|
|
6
|
+
export interface ChartFacadeContainerProps {
|
|
7
|
+
children: ReactNode;
|
|
8
|
+
onPeriodPress?: () => void;
|
|
9
|
+
periodLabel?: string;
|
|
10
|
+
testID?: string;
|
|
11
|
+
title?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export const ChartFacadeContainer: FC<ChartFacadeContainerProps> = ({
|
|
15
|
+
children,
|
|
16
|
+
onPeriodPress,
|
|
17
|
+
periodLabel,
|
|
18
|
+
testID,
|
|
19
|
+
title,
|
|
20
|
+
}) => {
|
|
21
|
+
if (!title) {
|
|
22
|
+
return children;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return (
|
|
26
|
+
<ChartCard
|
|
27
|
+
onPeriodPress={onPeriodPress}
|
|
28
|
+
periodLabel={periodLabel}
|
|
29
|
+
testID={resolveTestID(testID, "card")}
|
|
30
|
+
title={title}
|
|
31
|
+
>
|
|
32
|
+
{children}
|
|
33
|
+
</ChartCard>
|
|
34
|
+
);
|
|
35
|
+
};
|
|
@@ -11,6 +11,7 @@ export interface ChartFrameProps {
|
|
|
11
11
|
children: ReactNode;
|
|
12
12
|
emptyText: string;
|
|
13
13
|
isEmpty: boolean;
|
|
14
|
+
legendItems?: Array<{color: string; label: string}>;
|
|
14
15
|
legendLabel?: string;
|
|
15
16
|
loading?: boolean;
|
|
16
17
|
testID?: string;
|
|
@@ -22,6 +23,7 @@ export const ChartFrame: FC<ChartFrameProps> = ({
|
|
|
22
23
|
children,
|
|
23
24
|
emptyText,
|
|
24
25
|
isEmpty,
|
|
26
|
+
legendItems,
|
|
25
27
|
legendLabel,
|
|
26
28
|
loading = false,
|
|
27
29
|
testID,
|
|
@@ -55,7 +57,43 @@ export const ChartFrame: FC<ChartFrameProps> = ({
|
|
|
55
57
|
) : null}
|
|
56
58
|
</Box>
|
|
57
59
|
) : null}
|
|
58
|
-
{showPlot &&
|
|
60
|
+
{showPlot && legendItems && legendItems.length > 0 ? (
|
|
61
|
+
<Box
|
|
62
|
+
direction="row"
|
|
63
|
+
gap={3}
|
|
64
|
+
height={CHART_FOOTER_ROW_HEIGHT}
|
|
65
|
+
minWidth={0}
|
|
66
|
+
overflow="hidden"
|
|
67
|
+
>
|
|
68
|
+
{legendItems.map((item, index) => (
|
|
69
|
+
<Box
|
|
70
|
+
alignItems="center"
|
|
71
|
+
dangerouslySetInlineStyle={{__style: {flexBasis: 0, flexGrow: 1, flexShrink: 1}}}
|
|
72
|
+
direction="row"
|
|
73
|
+
gap={1}
|
|
74
|
+
key={`${item.label}-${index}`}
|
|
75
|
+
minWidth={0}
|
|
76
|
+
testID={resolveTestID(testID, `legend.${index}.item`)}
|
|
77
|
+
>
|
|
78
|
+
<Box
|
|
79
|
+
dangerouslySetInlineStyle={{
|
|
80
|
+
__style: {backgroundColor: item.color, height: 8, width: 8},
|
|
81
|
+
}}
|
|
82
|
+
testID={resolveTestID(testID, `legend.${index}.swatch`)}
|
|
83
|
+
/>
|
|
84
|
+
<Text
|
|
85
|
+
size="sm"
|
|
86
|
+
skipLinking
|
|
87
|
+
testID={resolveTestID(testID, `legend.${index}`)}
|
|
88
|
+
truncate
|
|
89
|
+
>
|
|
90
|
+
{item.label}
|
|
91
|
+
</Text>
|
|
92
|
+
</Box>
|
|
93
|
+
))}
|
|
94
|
+
</Box>
|
|
95
|
+
) : null}
|
|
96
|
+
{showPlot && (!legendItems || legendItems.length === 0) && legendLabel ? (
|
|
59
97
|
<Box height={CHART_FOOTER_ROW_HEIGHT} minWidth={0} overflow="hidden">
|
|
60
98
|
<Text size="sm" skipLinking testID={resolveTestID(testID, "legend")} truncate>
|
|
61
99
|
{legendLabel}
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {describe, expect, it} from "bun:test";
|
|
2
|
+
import {assert} from "chai";
|
|
2
3
|
|
|
3
4
|
import {
|
|
4
5
|
CHART_Y_AXIS_MAX_WIDTH,
|
|
@@ -8,6 +9,7 @@ import {
|
|
|
8
9
|
getPlotHeight,
|
|
9
10
|
getXTickStyle,
|
|
10
11
|
getYTickStyle,
|
|
12
|
+
shouldRotateChartXTicks,
|
|
11
13
|
} from "./layout";
|
|
12
14
|
|
|
13
15
|
describe("chart layout", () => {
|
|
@@ -19,8 +21,16 @@ describe("chart layout", () => {
|
|
|
19
21
|
expect(getPlotHeight({hasLegend: true, height: 200})).toBe(146);
|
|
20
22
|
});
|
|
21
23
|
|
|
24
|
+
it("reserves a custom x-axis height for rotated labels", () => {
|
|
25
|
+
assert.equal(getPlotHeight({hasLegend: false, height: 200, xAxisHeight: 72}), 110);
|
|
26
|
+
});
|
|
27
|
+
|
|
22
28
|
it("keeps a drawable plot when the requested height is smaller than the rows", () => {
|
|
23
|
-
expect(getPlotHeight({hasLegend: true, height: 20})).toBe(
|
|
29
|
+
expect(getPlotHeight({hasLegend: true, height: 20})).toBe(1);
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
it("keeps rotated charts inside the requested height", () => {
|
|
33
|
+
assert.equal(getPlotHeight({hasLegend: true, height: 140, xAxisHeight: 72}), 32);
|
|
24
34
|
});
|
|
25
35
|
|
|
26
36
|
it("fits a donut inside the height left by tooltip and padded, gapped legend rows", () => {
|
|
@@ -69,6 +79,17 @@ describe("chart layout", () => {
|
|
|
69
79
|
expect(getXTickStyle({bandwidth: 0, xCenter: 10}).width).toBe(1);
|
|
70
80
|
});
|
|
71
81
|
|
|
82
|
+
it("rotates dense auto ticks but respects explicit policies", () => {
|
|
83
|
+
assert.isFalse(shouldRotateChartXTicks({labelCount: 7, policy: "auto"}));
|
|
84
|
+
assert.isTrue(shouldRotateChartXTicks({labelCount: 8, policy: "auto"}));
|
|
85
|
+
assert.isTrue(shouldRotateChartXTicks({labelCount: 2, policy: "rotate"}));
|
|
86
|
+
assert.isFalse(shouldRotateChartXTicks({labelCount: 20, policy: "truncate"}));
|
|
87
|
+
assert.deepInclude(getXTickStyle({bandwidth: 10, isRotated: true, xCenter: 20}), {
|
|
88
|
+
transform: [{rotate: "45deg"}],
|
|
89
|
+
transformOrigin: "left top",
|
|
90
|
+
});
|
|
91
|
+
});
|
|
92
|
+
|
|
72
93
|
it("centers a y tick label on its value and spans the axis gutter", () => {
|
|
73
94
|
expect(getYTickStyle({axisWidth: 40, y: 50})).toEqual({
|
|
74
95
|
left: 0,
|
package/src/charts/layout.ts
CHANGED
|
@@ -2,6 +2,7 @@ import type {ChartPlot} from "./types/chartTypes";
|
|
|
2
2
|
|
|
3
3
|
export const CHART_Y_AXIS_MAX_WIDTH = 40;
|
|
4
4
|
export const CHART_X_AXIS_HEIGHT = 18;
|
|
5
|
+
export const CHART_ROTATED_X_AXIS_HEIGHT = 72;
|
|
5
6
|
export const CHART_FOOTER_ROW_HEIGHT = 18;
|
|
6
7
|
|
|
7
8
|
const Y_AXIS_WIDTH_RATIO = 0.3;
|
|
@@ -39,12 +40,18 @@ export const getChartAxisWidth = (chartWidth: number): number => {
|
|
|
39
40
|
export const getPlotHeight = ({
|
|
40
41
|
hasLegend,
|
|
41
42
|
height,
|
|
43
|
+
xAxisHeight = CHART_X_AXIS_HEIGHT,
|
|
42
44
|
}: {
|
|
43
45
|
hasLegend: boolean;
|
|
44
46
|
height: number;
|
|
47
|
+
xAxisHeight?: number;
|
|
45
48
|
}): number => {
|
|
46
|
-
const footer =
|
|
47
|
-
|
|
49
|
+
const footer = xAxisHeight + CHART_FOOTER_ROW_HEIGHT * (hasLegend ? 2 : 1);
|
|
50
|
+
const remaining = height - footer;
|
|
51
|
+
if (remaining >= MIN_PLOT_HEIGHT) {
|
|
52
|
+
return remaining;
|
|
53
|
+
}
|
|
54
|
+
return Math.max(remaining, 1);
|
|
48
55
|
};
|
|
49
56
|
|
|
50
57
|
export const getDonutSize = ({
|
|
@@ -85,13 +92,39 @@ export const getChartPlot = ({
|
|
|
85
92
|
*/
|
|
86
93
|
export const getXTickStyle = ({
|
|
87
94
|
bandwidth,
|
|
95
|
+
isRotated = false,
|
|
88
96
|
xCenter,
|
|
89
97
|
}: {
|
|
90
98
|
bandwidth: number;
|
|
99
|
+
isRotated?: boolean;
|
|
91
100
|
xCenter: number;
|
|
92
101
|
}): ChartTickStyle => {
|
|
93
|
-
const width =
|
|
94
|
-
|
|
102
|
+
const width = isRotated
|
|
103
|
+
? Math.max(bandwidth * 1.5, CHART_ROTATED_X_AXIS_HEIGHT)
|
|
104
|
+
: Math.max(bandwidth, 1);
|
|
105
|
+
return {
|
|
106
|
+
left: isRotated ? xCenter - bandwidth / 4 : xCenter - width / 2,
|
|
107
|
+
position: "absolute",
|
|
108
|
+
top: 0,
|
|
109
|
+
...(isRotated ? {transform: [{rotate: "45deg"}], transformOrigin: "left top"} : {}),
|
|
110
|
+
width,
|
|
111
|
+
};
|
|
112
|
+
};
|
|
113
|
+
|
|
114
|
+
export const shouldRotateChartXTicks = ({
|
|
115
|
+
labelCount,
|
|
116
|
+
policy = "auto",
|
|
117
|
+
}: {
|
|
118
|
+
labelCount: number;
|
|
119
|
+
policy?: "auto" | "rotate" | "truncate";
|
|
120
|
+
}): boolean => {
|
|
121
|
+
if (policy === "rotate") {
|
|
122
|
+
return true;
|
|
123
|
+
}
|
|
124
|
+
if (policy === "truncate") {
|
|
125
|
+
return false;
|
|
126
|
+
}
|
|
127
|
+
return labelCount > 7;
|
|
95
128
|
};
|
|
96
129
|
|
|
97
130
|
export const getYTickStyle = ({axisWidth, y}: {axisWidth: number; y: number}): ChartTickStyle => {
|
|
@@ -1,4 +1,5 @@
|
|
|
1
1
|
import {describe, expect, it} from "bun:test";
|
|
2
|
+
import {assert} from "chai";
|
|
2
3
|
|
|
3
4
|
import {createCartesianScales, getYTickValues} from "./scales";
|
|
4
5
|
import type {ChartPoint} from "./types/chartTypes";
|
|
@@ -27,6 +28,38 @@ describe("createCartesianScales", () => {
|
|
|
27
28
|
expect(scales.y(50)).toBe(50);
|
|
28
29
|
});
|
|
29
30
|
|
|
31
|
+
it("scales a sparkline to the data range instead of forcing zero", () => {
|
|
32
|
+
const points = [
|
|
33
|
+
{label: "A", value: 100},
|
|
34
|
+
{label: "B", value: 110},
|
|
35
|
+
];
|
|
36
|
+
const scales = createCartesianScales({
|
|
37
|
+
includeZero: false,
|
|
38
|
+
plot: PLOT,
|
|
39
|
+
points,
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
assert.equal(scales.y(100), 100);
|
|
43
|
+
assert.equal(scales.y(110), 0);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it("uses the explicit shared x labels while scaling all series values on y", () => {
|
|
47
|
+
const points = [
|
|
48
|
+
...FIXTURE_POINTS,
|
|
49
|
+
...FIXTURE_POINTS.map((point) => ({...point, value: point.value / 2})),
|
|
50
|
+
];
|
|
51
|
+
const scales = createCartesianScales({
|
|
52
|
+
plot: PLOT,
|
|
53
|
+
points,
|
|
54
|
+
xLabels: FIXTURE_POINTS.map((point) => point.label),
|
|
55
|
+
});
|
|
56
|
+
|
|
57
|
+
assert.equal(scales.bandwidth, 30);
|
|
58
|
+
assert.equal(scales.xCenter("C"), 85);
|
|
59
|
+
assert.equal(scales.y(100), 0);
|
|
60
|
+
assert.equal(scales.y(25), 75);
|
|
61
|
+
});
|
|
62
|
+
|
|
30
63
|
it("returns three ticks from the y domain including zero", () => {
|
|
31
64
|
expect(getYTickValues(FIXTURE_POINTS)).toEqual([0, 50, 100]);
|
|
32
65
|
});
|