@terreno/ui 57.1.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 +41 -2
- 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,151 @@
|
|
|
1
|
+
import {describe, expect, it, jest} from "bun:test";
|
|
2
|
+
import {fireEvent, waitFor} from "@testing-library/react-native";
|
|
3
|
+
|
|
4
|
+
import {Popover} from "./Popover";
|
|
5
|
+
import {Text} from "./Text";
|
|
6
|
+
import {renderWithTheme} from "./test-utils";
|
|
7
|
+
|
|
8
|
+
describe("Popover", () => {
|
|
9
|
+
it("renders the title, date and body when loaded", () => {
|
|
10
|
+
const {getByTestId, getByText} = renderWithTheme(
|
|
11
|
+
<Popover
|
|
12
|
+
onClose={jest.fn()}
|
|
13
|
+
subtitle="11/20/2026"
|
|
14
|
+
testID="popover"
|
|
15
|
+
text="Summary of Patient History."
|
|
16
|
+
title="Document Title"
|
|
17
|
+
/>
|
|
18
|
+
);
|
|
19
|
+
expect(getByTestId("popover-title")).toBeTruthy();
|
|
20
|
+
expect(getByTestId("popover-subtitle")).toBeTruthy();
|
|
21
|
+
expect(getByText("Summary of Patient History.")).toBeTruthy();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("prefers children over text for the body", () => {
|
|
25
|
+
const {getByText, queryByText} = renderWithTheme(
|
|
26
|
+
<Popover onClose={jest.fn()} text="Plain summary">
|
|
27
|
+
<Text>Rich body</Text>
|
|
28
|
+
</Popover>
|
|
29
|
+
);
|
|
30
|
+
expect(getByText("Rich body")).toBeTruthy();
|
|
31
|
+
expect(queryByText("Plain summary")).toBeNull();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
it("calls onClose when the close button is pressed", () => {
|
|
35
|
+
const onClose = jest.fn();
|
|
36
|
+
const {getByLabelText} = renderWithTheme(<Popover onClose={onClose} title="Doc" />);
|
|
37
|
+
fireEvent.press(getByLabelText("Close document"));
|
|
38
|
+
expect(onClose).toHaveBeenCalled();
|
|
39
|
+
});
|
|
40
|
+
|
|
41
|
+
it("calls onOpen from the footer action", () => {
|
|
42
|
+
const onOpen = jest.fn();
|
|
43
|
+
const {getByTestId} = renderWithTheme(
|
|
44
|
+
<Popover onClose={jest.fn()} onOpen={onOpen} testID="popover" title="Doc" />
|
|
45
|
+
);
|
|
46
|
+
fireEvent.press(getByTestId("popover-open"));
|
|
47
|
+
expect(onOpen).toHaveBeenCalled();
|
|
48
|
+
});
|
|
49
|
+
|
|
50
|
+
it("passes feedback selections through", () => {
|
|
51
|
+
const onFeedbackChange = jest.fn();
|
|
52
|
+
const {getByTestId} = renderWithTheme(
|
|
53
|
+
<Popover
|
|
54
|
+
onClose={jest.fn()}
|
|
55
|
+
onFeedbackChange={onFeedbackChange}
|
|
56
|
+
testID="popover"
|
|
57
|
+
title="Doc"
|
|
58
|
+
/>
|
|
59
|
+
);
|
|
60
|
+
fireEvent.press(getByTestId("popover-feedback-positive"));
|
|
61
|
+
expect(onFeedbackChange).toHaveBeenCalledWith("positive");
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it("hides the footer when there are no footer actions", () => {
|
|
65
|
+
const {queryByTestId} = renderWithTheme(
|
|
66
|
+
<Popover onClose={jest.fn()} testID="popover" title="Doc" />
|
|
67
|
+
);
|
|
68
|
+
expect(queryByTestId("popover-open")).toBeNull();
|
|
69
|
+
expect(queryByTestId("popover-feedback")).toBeNull();
|
|
70
|
+
});
|
|
71
|
+
|
|
72
|
+
it("shows the loading header instead of the document while loading", () => {
|
|
73
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
74
|
+
<Popover onClose={jest.fn()} status="loading" testID="popover" title="Doc" />
|
|
75
|
+
);
|
|
76
|
+
expect(getByTestId("popover-loading-text")).toBeTruthy();
|
|
77
|
+
expect(queryByTestId("popover-title")).toBeNull();
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
it("shows a retryable error message when loading fails", async () => {
|
|
81
|
+
const onRetry = jest.fn();
|
|
82
|
+
const {getByTestId} = renderWithTheme(
|
|
83
|
+
<Popover onClose={jest.fn()} onRetry={onRetry} status="error" testID="popover" title="Doc" />
|
|
84
|
+
);
|
|
85
|
+
expect(getByTestId("popover-error-title")).toBeTruthy();
|
|
86
|
+
fireEvent.press(getByTestId("popover-retry"));
|
|
87
|
+
await waitFor(() => {
|
|
88
|
+
expect(onRetry).toHaveBeenCalled();
|
|
89
|
+
});
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("hides the retry button when there is no retry handler", () => {
|
|
93
|
+
const {queryByTestId} = renderWithTheme(
|
|
94
|
+
<Popover onClose={jest.fn()} status="error" testID="popover" />
|
|
95
|
+
);
|
|
96
|
+
expect(queryByTestId("popover-retry")).toBeNull();
|
|
97
|
+
});
|
|
98
|
+
|
|
99
|
+
it("lets the body fill the card instead of pinning its content height", () => {
|
|
100
|
+
const {getByTestId} = renderWithTheme(
|
|
101
|
+
<Popover
|
|
102
|
+
height={240}
|
|
103
|
+
onClose={jest.fn()}
|
|
104
|
+
testID="popover"
|
|
105
|
+
text={"Summary of patient history. ".repeat(40)}
|
|
106
|
+
title="Doc"
|
|
107
|
+
/>
|
|
108
|
+
);
|
|
109
|
+
const scrollView = getByTestId("popover-content");
|
|
110
|
+
expect(scrollView.props.style).toEqual(
|
|
111
|
+
expect.objectContaining({flexBasis: 0, flexGrow: 1, flexShrink: 1, minHeight: 0})
|
|
112
|
+
);
|
|
113
|
+
const content = scrollView.findByType("View");
|
|
114
|
+
expect(content.props.style?.height).toBeUndefined();
|
|
115
|
+
});
|
|
116
|
+
|
|
117
|
+
it("defaults to the 480x480 design size", () => {
|
|
118
|
+
const {getByTestId} = renderWithTheme(
|
|
119
|
+
<Popover onClose={jest.fn()} testID="popover" title="Doc" />
|
|
120
|
+
);
|
|
121
|
+
expect(getByTestId("popover").props.style).toEqual(
|
|
122
|
+
expect.objectContaining({height: 480, width: 480})
|
|
123
|
+
);
|
|
124
|
+
});
|
|
125
|
+
|
|
126
|
+
it("keeps the same height in every status", () => {
|
|
127
|
+
const heights = (["loaded", "loading", "error"] as const).map((status) => {
|
|
128
|
+
const {getByTestId} = renderWithTheme(
|
|
129
|
+
<Popover height={280} onClose={jest.fn()} status={status} testID={status} title="Doc" />
|
|
130
|
+
);
|
|
131
|
+
return getByTestId(status).props.style.height;
|
|
132
|
+
});
|
|
133
|
+
expect(heights).toEqual([280, 280, 280]);
|
|
134
|
+
});
|
|
135
|
+
|
|
136
|
+
it("drops the header and footer in the error status", () => {
|
|
137
|
+
const {queryByTestId} = renderWithTheme(
|
|
138
|
+
<Popover
|
|
139
|
+
onClose={jest.fn()}
|
|
140
|
+
onOpen={jest.fn()}
|
|
141
|
+
status="error"
|
|
142
|
+
subtitle="11/20/2026"
|
|
143
|
+
testID="popover"
|
|
144
|
+
title="Doc"
|
|
145
|
+
/>
|
|
146
|
+
);
|
|
147
|
+
expect(queryByTestId("popover-title")).toBeNull();
|
|
148
|
+
expect(queryByTestId("popover-subtitle")).toBeNull();
|
|
149
|
+
expect(queryByTestId("popover-open")).toBeNull();
|
|
150
|
+
});
|
|
151
|
+
});
|
package/src/Popover.tsx
ADDED
|
@@ -0,0 +1,211 @@
|
|
|
1
|
+
import type {FC, ReactNode} from "react";
|
|
2
|
+
import {Pressable, ScrollView} from "react-native";
|
|
3
|
+
|
|
4
|
+
import {Box} from "./Box";
|
|
5
|
+
import {Button} from "./Button";
|
|
6
|
+
import type {PopoverProps} from "./Common";
|
|
7
|
+
import {DismissButton} from "./DismissButton";
|
|
8
|
+
import {Heading} from "./Heading";
|
|
9
|
+
import {Icon} from "./Icon";
|
|
10
|
+
import {Spinner} from "./Spinner";
|
|
11
|
+
import {Text} from "./Text";
|
|
12
|
+
import {ThumbsUpDownFeedback} from "./ThumbsUpDownFeedback";
|
|
13
|
+
|
|
14
|
+
const DEFAULT_HEIGHT = 480;
|
|
15
|
+
const DEFAULT_WIDTH = 480;
|
|
16
|
+
const ERROR_ICON_SIZE = 64;
|
|
17
|
+
|
|
18
|
+
/**
|
|
19
|
+
* A popover that previews a single document: a header with the document's title and date, the
|
|
20
|
+
* document body, and a footer with an "Open" action and optional thumbs up/down feedback.
|
|
21
|
+
*
|
|
22
|
+
* Rendering is driven by `status`: "loading" shows a centered spinner under a loading header,
|
|
23
|
+
* "error" shows a retryable error message centered in the card, and "loaded" shows the document
|
|
24
|
+
* itself. The popover keeps the same size in every state, and is a plain card, so the consumer is
|
|
25
|
+
* responsible for positioning it next to its anchor.
|
|
26
|
+
*/
|
|
27
|
+
export const Popover: FC<PopoverProps> = ({
|
|
28
|
+
children,
|
|
29
|
+
errorText = "Something went wrong while loading this document. Check your connection and try again.",
|
|
30
|
+
errorTitle = "Couldn't load this document",
|
|
31
|
+
feedback,
|
|
32
|
+
height = DEFAULT_HEIGHT,
|
|
33
|
+
loadingText = "Loading document...",
|
|
34
|
+
onClose,
|
|
35
|
+
onFeedbackChange,
|
|
36
|
+
onOpen,
|
|
37
|
+
onRetry,
|
|
38
|
+
openText = "Open",
|
|
39
|
+
retryText = "Try again",
|
|
40
|
+
status = "loaded",
|
|
41
|
+
subtitle,
|
|
42
|
+
testID,
|
|
43
|
+
text,
|
|
44
|
+
title,
|
|
45
|
+
width = DEFAULT_WIDTH,
|
|
46
|
+
}) => {
|
|
47
|
+
const childTestID = (suffix: string) => (testID ? `${testID}-${suffix}` : undefined);
|
|
48
|
+
|
|
49
|
+
const closeButton = (
|
|
50
|
+
<DismissButton
|
|
51
|
+
accessibilityHint="Closes the document preview"
|
|
52
|
+
accessibilityLabel="Close document"
|
|
53
|
+
color="link"
|
|
54
|
+
onClick={() => {
|
|
55
|
+
void onClose();
|
|
56
|
+
}}
|
|
57
|
+
/>
|
|
58
|
+
);
|
|
59
|
+
|
|
60
|
+
const card = (content: ReactNode) => (
|
|
61
|
+
<Box
|
|
62
|
+
color="base"
|
|
63
|
+
height={height}
|
|
64
|
+
overflow="hidden"
|
|
65
|
+
rounding="md"
|
|
66
|
+
shadow
|
|
67
|
+
testID={testID}
|
|
68
|
+
width={width}
|
|
69
|
+
>
|
|
70
|
+
{content}
|
|
71
|
+
</Box>
|
|
72
|
+
);
|
|
73
|
+
|
|
74
|
+
// The error state has no header or footer: the close button floats over a centered message.
|
|
75
|
+
if (status === "error") {
|
|
76
|
+
return card(
|
|
77
|
+
<>
|
|
78
|
+
<Box paddingX={4} paddingY={4} position="absolute" right top zIndex={1}>
|
|
79
|
+
{closeButton}
|
|
80
|
+
</Box>
|
|
81
|
+
<Box
|
|
82
|
+
alignItems="center"
|
|
83
|
+
flex="grow"
|
|
84
|
+
gap={4}
|
|
85
|
+
justifyContent="center"
|
|
86
|
+
paddingX={6}
|
|
87
|
+
width="100%"
|
|
88
|
+
>
|
|
89
|
+
<Box
|
|
90
|
+
alignItems="center"
|
|
91
|
+
color="errorLight"
|
|
92
|
+
height={ERROR_ICON_SIZE}
|
|
93
|
+
justifyContent="center"
|
|
94
|
+
rounding="circle"
|
|
95
|
+
width={ERROR_ICON_SIZE}
|
|
96
|
+
>
|
|
97
|
+
<Icon color="error" iconName="triangle-exclamation" size="xl" type="solid" />
|
|
98
|
+
</Box>
|
|
99
|
+
<Heading align="center" size="md" testID={childTestID("error-title")}>
|
|
100
|
+
{errorTitle}
|
|
101
|
+
</Heading>
|
|
102
|
+
<Text align="center">{errorText}</Text>
|
|
103
|
+
{Boolean(onRetry) && (
|
|
104
|
+
// Button pins itself to flex-start, so center it on the row's main axis instead.
|
|
105
|
+
<Box direction="row" justifyContent="center" width="100%">
|
|
106
|
+
<Button
|
|
107
|
+
onClick={onRetry!}
|
|
108
|
+
testID={childTestID("retry")}
|
|
109
|
+
text={retryText}
|
|
110
|
+
variant="primary"
|
|
111
|
+
/>
|
|
112
|
+
</Box>
|
|
113
|
+
)}
|
|
114
|
+
</Box>
|
|
115
|
+
</>
|
|
116
|
+
);
|
|
117
|
+
}
|
|
118
|
+
|
|
119
|
+
const body =
|
|
120
|
+
status === "loading" ? (
|
|
121
|
+
<Box alignItems="center" flex="grow" justifyContent="center" width="100%">
|
|
122
|
+
<Spinner color="secondary" testID={childTestID("spinner")} />
|
|
123
|
+
</Box>
|
|
124
|
+
) : (
|
|
125
|
+
<ScrollView
|
|
126
|
+
keyboardShouldPersistTaps="handled"
|
|
127
|
+
nestedScrollEnabled
|
|
128
|
+
style={{flexBasis: 0, flexGrow: 1, flexShrink: 1, minHeight: 0, width: "100%"}}
|
|
129
|
+
testID={childTestID("content")}
|
|
130
|
+
>
|
|
131
|
+
<Box paddingX={4} paddingY={3} width="100%">
|
|
132
|
+
{children ?? (Boolean(text) && <Text>{text}</Text>)}
|
|
133
|
+
</Box>
|
|
134
|
+
</ScrollView>
|
|
135
|
+
);
|
|
136
|
+
|
|
137
|
+
const showFooter = status === "loaded" && (Boolean(onOpen) || Boolean(onFeedbackChange));
|
|
138
|
+
|
|
139
|
+
return card(
|
|
140
|
+
<>
|
|
141
|
+
<Box
|
|
142
|
+
alignItems="center"
|
|
143
|
+
borderBottom="default"
|
|
144
|
+
direction="row"
|
|
145
|
+
gap={2}
|
|
146
|
+
paddingX={4}
|
|
147
|
+
paddingY={4}
|
|
148
|
+
>
|
|
149
|
+
<Box flex="grow" minWidth={0}>
|
|
150
|
+
{status === "loaded" ? (
|
|
151
|
+
<>
|
|
152
|
+
{Boolean(title) && (
|
|
153
|
+
<Heading size="sm" testID={childTestID("title")}>
|
|
154
|
+
{title}
|
|
155
|
+
</Heading>
|
|
156
|
+
)}
|
|
157
|
+
{Boolean(subtitle) && (
|
|
158
|
+
<Text size="sm" testID={childTestID("subtitle")}>
|
|
159
|
+
{subtitle}
|
|
160
|
+
</Text>
|
|
161
|
+
)}
|
|
162
|
+
</>
|
|
163
|
+
) : (
|
|
164
|
+
<Text color="secondaryLight" testID={childTestID("loading-text")}>
|
|
165
|
+
{loadingText}
|
|
166
|
+
</Text>
|
|
167
|
+
)}
|
|
168
|
+
</Box>
|
|
169
|
+
{closeButton}
|
|
170
|
+
</Box>
|
|
171
|
+
|
|
172
|
+
{body}
|
|
173
|
+
|
|
174
|
+
{showFooter && (
|
|
175
|
+
<Box
|
|
176
|
+
alignItems="center"
|
|
177
|
+
borderTop="default"
|
|
178
|
+
direction="row"
|
|
179
|
+
justifyContent="between"
|
|
180
|
+
paddingX={4}
|
|
181
|
+
paddingY={3}
|
|
182
|
+
>
|
|
183
|
+
{onOpen ? (
|
|
184
|
+
<Pressable
|
|
185
|
+
accessibilityRole="button"
|
|
186
|
+
aria-label={openText}
|
|
187
|
+
onPress={onOpen}
|
|
188
|
+
testID={childTestID("open")}
|
|
189
|
+
>
|
|
190
|
+
<Box alignItems="center" direction="row" gap={2}>
|
|
191
|
+
<Text bold color="link">
|
|
192
|
+
{openText}
|
|
193
|
+
</Text>
|
|
194
|
+
<Icon color="link" iconName="arrow-up-right-from-square" size="md" type="regular" />
|
|
195
|
+
</Box>
|
|
196
|
+
</Pressable>
|
|
197
|
+
) : (
|
|
198
|
+
<Box />
|
|
199
|
+
)}
|
|
200
|
+
{Boolean(onFeedbackChange) && (
|
|
201
|
+
<ThumbsUpDownFeedback
|
|
202
|
+
onChange={onFeedbackChange!}
|
|
203
|
+
testID={childTestID("feedback")}
|
|
204
|
+
value={feedback}
|
|
205
|
+
/>
|
|
206
|
+
)}
|
|
207
|
+
</Box>
|
|
208
|
+
)}
|
|
209
|
+
</>
|
|
210
|
+
);
|
|
211
|
+
};
|
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
|
+
});
|