@terreno/ui 57.6.1 → 57.8.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/Avatar.js +2 -2
- package/dist/Avatar.js.map +1 -1
- package/dist/Button.js +2 -2
- package/dist/Button.js.map +1 -1
- package/dist/Common.d.ts +93 -5
- package/dist/Common.d.ts.map +1 -1
- package/dist/Common.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/DropdownPanel.d.ts +24 -0
- package/dist/DropdownPanel.d.ts.map +1 -0
- package/dist/DropdownPanel.js +186 -0
- package/dist/DropdownPanel.js.map +1 -0
- 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/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/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/UnifiedAddressAutoComplete.js +2 -2
- package/dist/UnifiedAddressAutoComplete.js.map +1 -1
- package/dist/dataTableFilters.js +3 -3
- package/dist/dataTableFilters.js.map +1 -1
- package/dist/dropdownPanelLayout.d.ts +59 -0
- package/dist/dropdownPanelLayout.d.ts.map +1 -0
- package/dist/dropdownPanelLayout.js +57 -0
- package/dist/dropdownPanelLayout.js.map +1 -0
- package/dist/fieldElements/FieldTitle.js +2 -2
- package/dist/fieldElements/FieldTitle.js.map +1 -1
- package/dist/index.d.ts +2 -1
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +2 -1
- package/dist/index.js.map +1 -1
- package/package.json +1 -1
- package/src/Avatar.tsx +2 -2
- package/src/Button.test.tsx +7 -7
- package/src/Button.tsx +2 -2
- package/src/Common.ts +93 -5
- package/src/DateTimeActionSheet.tsx +4 -4
- package/src/DateTimeField.test.tsx +5 -4
- package/src/DateTimeField.tsx +3 -3
- package/src/{Filter.test.tsx → DropdownPanel.test.tsx} +141 -43
- package/src/{Filter.tsx → DropdownPanel.tsx} +145 -74
- package/src/HeightField.tsx +2 -2
- package/src/IconButton.test.tsx +63 -0
- package/src/IconButton.tsx +10 -5
- package/src/MediaQuery.ts +14 -1
- package/src/MultiselectField.tsx +2 -2
- package/src/RadioField.tsx +2 -2
- package/src/SplitPage.test.tsx +449 -11
- package/src/SplitPage.tsx +255 -21
- package/src/UnifiedAddressAutoComplete.test.tsx +4 -4
- package/src/UnifiedAddressAutoComplete.tsx +2 -2
- package/src/__snapshots__/{Filter.test.tsx.snap → DropdownPanel.test.tsx.snap} +6 -2
- package/src/bunSetup.ts +8 -1
- package/src/dataTableFilters.tsx +5 -5
- package/src/dropdownPanelLayout.test.ts +140 -0
- package/src/dropdownPanelLayout.ts +131 -0
- package/src/fieldElements/FieldTitle.tsx +2 -2
- package/src/index.tsx +2 -1
- package/dist/Filter.d.ts +0 -14
- package/dist/Filter.d.ts.map +0 -1
- package/dist/Filter.js +0 -145
- package/dist/Filter.js.map +0 -1
|
@@ -1,38 +1,40 @@
|
|
|
1
1
|
import {afterEach, beforeEach, describe, expect, it, mock} from "bun:test";
|
|
2
|
-
import {act, fireEvent, waitFor} from "@testing-library/react-native";
|
|
2
|
+
import {act, fireEvent, render, waitFor} from "@testing-library/react-native";
|
|
3
3
|
import {assert} from "chai";
|
|
4
|
-
//
|
|
4
|
+
// DropdownPanel.tsx reads `Platform.OS` through this ESM binding, so the web branch tests must mutate
|
|
5
5
|
// the same object the component observes.
|
|
6
|
-
import {Platform as ImportedPlatform} from "react-native";
|
|
6
|
+
import {Dimensions, Platform as ImportedPlatform, Pressable} from "react-native";
|
|
7
7
|
|
|
8
|
-
import {
|
|
8
|
+
import {DropdownPanel} from "./DropdownPanel";
|
|
9
|
+
import {PortalContext} from "./PortalHost";
|
|
9
10
|
import {Text} from "./Text";
|
|
11
|
+
import {ThemeProvider} from "./Theme";
|
|
10
12
|
import {renderWithTheme} from "./test-utils";
|
|
11
13
|
|
|
12
|
-
describe("
|
|
14
|
+
describe("DropdownPanel", () => {
|
|
13
15
|
it("renders correctly with default props", () => {
|
|
14
16
|
const {toJSON} = renderWithTheme(
|
|
15
|
-
<
|
|
17
|
+
<DropdownPanel>
|
|
16
18
|
<Text>Body</Text>
|
|
17
|
-
</
|
|
19
|
+
</DropdownPanel>
|
|
18
20
|
);
|
|
19
21
|
expect(toJSON()).toMatchSnapshot();
|
|
20
22
|
});
|
|
21
23
|
|
|
22
24
|
it("renders the trigger label", () => {
|
|
23
25
|
const {getByText} = renderWithTheme(
|
|
24
|
-
<
|
|
26
|
+
<DropdownPanel label="Filters">
|
|
25
27
|
<Text>Body</Text>
|
|
26
|
-
</
|
|
28
|
+
</DropdownPanel>
|
|
27
29
|
);
|
|
28
30
|
expect(getByText("Filters")).toBeTruthy();
|
|
29
31
|
});
|
|
30
32
|
|
|
31
33
|
it("renders a compact icon-only trigger without the label", () => {
|
|
32
34
|
const {getByTestId, queryByText} = renderWithTheme(
|
|
33
|
-
<
|
|
35
|
+
<DropdownPanel iconOnly label="Filters" testID="f" triggerAccessibilityLabel="Filter Name">
|
|
34
36
|
<Text>Body</Text>
|
|
35
|
-
</
|
|
37
|
+
</DropdownPanel>
|
|
36
38
|
);
|
|
37
39
|
const trigger = getByTestId("f.trigger");
|
|
38
40
|
expect(queryByText("Filters")).toBeNull();
|
|
@@ -44,9 +46,9 @@ describe("Filter", () => {
|
|
|
44
46
|
|
|
45
47
|
it("opens the panel from the icon-only trigger", () => {
|
|
46
48
|
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
47
|
-
<
|
|
49
|
+
<DropdownPanel iconOnly testID="f">
|
|
48
50
|
<Text>Body</Text>
|
|
49
|
-
</
|
|
51
|
+
</DropdownPanel>
|
|
50
52
|
);
|
|
51
53
|
expect(queryByTestId("f.panel")).toBeNull();
|
|
52
54
|
fireEvent.press(getByTestId("f.trigger"));
|
|
@@ -55,16 +57,16 @@ describe("Filter", () => {
|
|
|
55
57
|
|
|
56
58
|
it("keeps the panel closed by default and open with defaultOpen", () => {
|
|
57
59
|
const closed = renderWithTheme(
|
|
58
|
-
<
|
|
60
|
+
<DropdownPanel testID="f">
|
|
59
61
|
<Text>Body</Text>
|
|
60
|
-
</
|
|
62
|
+
</DropdownPanel>
|
|
61
63
|
);
|
|
62
64
|
expect(closed.queryByTestId("f.panel")).toBeNull();
|
|
63
65
|
|
|
64
66
|
const open = renderWithTheme(
|
|
65
|
-
<
|
|
67
|
+
<DropdownPanel defaultOpen testID="f">
|
|
66
68
|
<Text>Body</Text>
|
|
67
|
-
</
|
|
69
|
+
</DropdownPanel>
|
|
68
70
|
);
|
|
69
71
|
expect(open.queryByTestId("f.panel")).toBeTruthy();
|
|
70
72
|
expect(open.getByText("Body")).toBeTruthy();
|
|
@@ -72,9 +74,9 @@ describe("Filter", () => {
|
|
|
72
74
|
|
|
73
75
|
it("hides the footer when action buttons are disabled", () => {
|
|
74
76
|
const {queryByTestId} = renderWithTheme(
|
|
75
|
-
<
|
|
77
|
+
<DropdownPanel defaultOpen showActionButtons={false} testID="f">
|
|
76
78
|
<Text>Body</Text>
|
|
77
|
-
</
|
|
79
|
+
</DropdownPanel>
|
|
78
80
|
);
|
|
79
81
|
expect(queryByTestId("f.apply")).toBeNull();
|
|
80
82
|
expect(queryByTestId("f.clear")).toBeNull();
|
|
@@ -84,9 +86,9 @@ describe("Filter", () => {
|
|
|
84
86
|
it("closes on outside click and calls onCancel", () => {
|
|
85
87
|
const onCancel = mock();
|
|
86
88
|
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
87
|
-
<
|
|
89
|
+
<DropdownPanel defaultOpen onCancel={onCancel} testID="f">
|
|
88
90
|
<Text>Body</Text>
|
|
89
|
-
</
|
|
91
|
+
</DropdownPanel>
|
|
90
92
|
);
|
|
91
93
|
fireEvent.press(getByTestId("f.backdrop"));
|
|
92
94
|
expect(onCancel).toHaveBeenCalled();
|
|
@@ -96,9 +98,9 @@ describe("Filter", () => {
|
|
|
96
98
|
it("calls onClear and keeps the panel open when Clear is pressed", () => {
|
|
97
99
|
const onClear = mock();
|
|
98
100
|
const {getByTestId} = renderWithTheme(
|
|
99
|
-
<
|
|
101
|
+
<DropdownPanel defaultOpen onClear={onClear} testID="f">
|
|
100
102
|
<Text>Body</Text>
|
|
101
|
-
</
|
|
103
|
+
</DropdownPanel>
|
|
102
104
|
);
|
|
103
105
|
fireEvent.press(getByTestId("f.clear"));
|
|
104
106
|
expect(onClear).toHaveBeenCalled();
|
|
@@ -108,9 +110,9 @@ describe("Filter", () => {
|
|
|
108
110
|
it("calls onApply and closes when Apply is pressed", async () => {
|
|
109
111
|
const onApply = mock();
|
|
110
112
|
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
111
|
-
<
|
|
113
|
+
<DropdownPanel defaultOpen onApply={onApply} testID="f">
|
|
112
114
|
<Text>Body</Text>
|
|
113
|
-
</
|
|
115
|
+
</DropdownPanel>
|
|
114
116
|
);
|
|
115
117
|
await act(async () => {
|
|
116
118
|
fireEvent.press(getByTestId("f.apply"));
|
|
@@ -124,9 +126,9 @@ describe("Filter", () => {
|
|
|
124
126
|
it("toggles the panel from the trigger when uncontrolled", async () => {
|
|
125
127
|
const onOpenChange = mock();
|
|
126
128
|
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
127
|
-
<
|
|
129
|
+
<DropdownPanel onOpenChange={onOpenChange} testID="f">
|
|
128
130
|
<Text>Body</Text>
|
|
129
|
-
</
|
|
131
|
+
</DropdownPanel>
|
|
130
132
|
);
|
|
131
133
|
|
|
132
134
|
await act(async () => {
|
|
@@ -145,12 +147,12 @@ describe("Filter", () => {
|
|
|
145
147
|
it("defers open state to the parent when controlled", async () => {
|
|
146
148
|
const onOpenChange = mock();
|
|
147
149
|
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
148
|
-
<
|
|
150
|
+
<DropdownPanel isOpen onOpenChange={onOpenChange} testID="f">
|
|
149
151
|
<Text>Body</Text>
|
|
150
|
-
</
|
|
152
|
+
</DropdownPanel>
|
|
151
153
|
);
|
|
152
154
|
|
|
153
|
-
// A controlled
|
|
155
|
+
// A controlled DropdownPanel must stay open until the parent flips `isOpen`, even after a
|
|
154
156
|
// dismissal that would close an uncontrolled panel.
|
|
155
157
|
await act(async () => {
|
|
156
158
|
fireEvent.press(getByTestId("f.cancel"));
|
|
@@ -161,9 +163,9 @@ describe("Filter", () => {
|
|
|
161
163
|
|
|
162
164
|
it("renders only the requested footer buttons", () => {
|
|
163
165
|
const {queryByTestId, getByTestId} = renderWithTheme(
|
|
164
|
-
<
|
|
166
|
+
<DropdownPanel defaultOpen showApplyButton={false} showClearButton={false} testID="f">
|
|
165
167
|
<Text>Body</Text>
|
|
166
|
-
</
|
|
168
|
+
</DropdownPanel>
|
|
167
169
|
);
|
|
168
170
|
expect(queryByTestId("f.clear")).toBeNull();
|
|
169
171
|
expect(queryByTestId("f.apply")).toBeNull();
|
|
@@ -172,7 +174,7 @@ describe("Filter", () => {
|
|
|
172
174
|
|
|
173
175
|
it("hides the footer when every button is disabled", () => {
|
|
174
176
|
const {queryByTestId} = renderWithTheme(
|
|
175
|
-
<
|
|
177
|
+
<DropdownPanel
|
|
176
178
|
defaultOpen
|
|
177
179
|
showApplyButton={false}
|
|
178
180
|
showCancelButton={false}
|
|
@@ -180,7 +182,7 @@ describe("Filter", () => {
|
|
|
180
182
|
testID="f"
|
|
181
183
|
>
|
|
182
184
|
<Text>Body</Text>
|
|
183
|
-
</
|
|
185
|
+
</DropdownPanel>
|
|
184
186
|
);
|
|
185
187
|
expect(queryByTestId("f.clear")).toBeNull();
|
|
186
188
|
expect(queryByTestId("f.apply")).toBeNull();
|
|
@@ -189,7 +191,7 @@ describe("Filter", () => {
|
|
|
189
191
|
|
|
190
192
|
it("uses custom footer button labels", () => {
|
|
191
193
|
const {getByText} = renderWithTheme(
|
|
192
|
-
<
|
|
194
|
+
<DropdownPanel
|
|
193
195
|
applyButtonText="Save"
|
|
194
196
|
cancelButtonText="Dismiss"
|
|
195
197
|
clearButtonText="Reset"
|
|
@@ -197,7 +199,7 @@ describe("Filter", () => {
|
|
|
197
199
|
testID="f"
|
|
198
200
|
>
|
|
199
201
|
<Text>Body</Text>
|
|
200
|
-
</
|
|
202
|
+
</DropdownPanel>
|
|
201
203
|
);
|
|
202
204
|
expect(getByText("Save")).toBeTruthy();
|
|
203
205
|
expect(getByText("Dismiss")).toBeTruthy();
|
|
@@ -206,16 +208,16 @@ describe("Filter", () => {
|
|
|
206
208
|
|
|
207
209
|
it("omits testIDs on the panel internals when no testID is provided", () => {
|
|
208
210
|
const {queryByTestId, getByText} = renderWithTheme(
|
|
209
|
-
<
|
|
211
|
+
<DropdownPanel defaultOpen>
|
|
210
212
|
<Text>Body</Text>
|
|
211
|
-
</
|
|
213
|
+
</DropdownPanel>
|
|
212
214
|
);
|
|
213
215
|
expect(getByText("Apply")).toBeTruthy();
|
|
214
216
|
expect(queryByTestId("f.panel")).toBeNull();
|
|
215
217
|
});
|
|
216
218
|
});
|
|
217
219
|
|
|
218
|
-
describe("
|
|
220
|
+
describe("DropdownPanel web platform", () => {
|
|
219
221
|
const globalScope = globalThis as {document?: unknown; HTMLElement?: unknown};
|
|
220
222
|
const originalDocument = globalScope.document;
|
|
221
223
|
const originalHTMLElement = globalScope.HTMLElement;
|
|
@@ -239,9 +241,9 @@ describe("Filter web platform", () => {
|
|
|
239
241
|
|
|
240
242
|
it("renders the fixed-position overlay once the trigger is measured", async () => {
|
|
241
243
|
const {getByTestId, getByText} = renderWithTheme(
|
|
242
|
-
<
|
|
244
|
+
<DropdownPanel defaultOpen testID="f">
|
|
243
245
|
<Text>Body</Text>
|
|
244
|
-
</
|
|
246
|
+
</DropdownPanel>
|
|
245
247
|
);
|
|
246
248
|
|
|
247
249
|
await waitFor(() => {
|
|
@@ -255,9 +257,9 @@ describe("Filter web platform", () => {
|
|
|
255
257
|
it("closes from the web backdrop", async () => {
|
|
256
258
|
const onCancel = mock();
|
|
257
259
|
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
258
|
-
<
|
|
260
|
+
<DropdownPanel defaultOpen onCancel={onCancel} testID="f">
|
|
259
261
|
<Text>Body</Text>
|
|
260
|
-
</
|
|
262
|
+
</DropdownPanel>
|
|
261
263
|
);
|
|
262
264
|
|
|
263
265
|
await waitFor(() => {
|
|
@@ -270,3 +272,99 @@ describe("Filter web platform", () => {
|
|
|
270
272
|
expect(queryByTestId("f.panel")).toBeNull();
|
|
271
273
|
});
|
|
272
274
|
});
|
|
275
|
+
|
|
276
|
+
describe("DropdownPanel trigger", () => {
|
|
277
|
+
it("renders a custom trigger and toggles the panel from it", async () => {
|
|
278
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
279
|
+
<DropdownPanel
|
|
280
|
+
renderTrigger={({isOpen, toggle}) => (
|
|
281
|
+
<Pressable onPress={toggle} testID="custom-trigger">
|
|
282
|
+
<Text>{isOpen ? "Close" : "Open"}</Text>
|
|
283
|
+
</Pressable>
|
|
284
|
+
)}
|
|
285
|
+
testID="f"
|
|
286
|
+
>
|
|
287
|
+
<Text>Body</Text>
|
|
288
|
+
</DropdownPanel>
|
|
289
|
+
);
|
|
290
|
+
|
|
291
|
+
expect(queryByTestId("f.trigger")).toBeNull();
|
|
292
|
+
await act(async () => {
|
|
293
|
+
fireEvent.press(getByTestId("custom-trigger"));
|
|
294
|
+
});
|
|
295
|
+
expect(getByTestId("f.panel")).toBeTruthy();
|
|
296
|
+
});
|
|
297
|
+
|
|
298
|
+
it("hugs the trigger so the panel anchors to it, not to the surrounding row", () => {
|
|
299
|
+
// The wrapper is what gets measured. A stretched wrapper starts at the edge of the
|
|
300
|
+
// whole row, which anchors the panel far from a trigger aligned anywhere else.
|
|
301
|
+
const {getByTestId} = renderWithTheme(
|
|
302
|
+
<DropdownPanel testID="f">
|
|
303
|
+
<Text>Body</Text>
|
|
304
|
+
</DropdownPanel>
|
|
305
|
+
);
|
|
306
|
+
const wrapper = getByTestId("f").props.children[0];
|
|
307
|
+
expect(wrapper.props.style.alignSelf).toBe("flex-start");
|
|
308
|
+
});
|
|
309
|
+
|
|
310
|
+
it("stretches the trigger wrapper when fullWidth is set", () => {
|
|
311
|
+
const {getByTestId} = renderWithTheme(
|
|
312
|
+
<DropdownPanel fullWidth testID="f">
|
|
313
|
+
<Text>Body</Text>
|
|
314
|
+
</DropdownPanel>
|
|
315
|
+
);
|
|
316
|
+
expect((getByTestId("f").props.style as {width?: string}).width).toBe("100%");
|
|
317
|
+
});
|
|
318
|
+
});
|
|
319
|
+
|
|
320
|
+
describe("DropdownPanel portal host", () => {
|
|
321
|
+
const manager = {mount: () => {}, unmount: () => {}, update: () => {}};
|
|
322
|
+
|
|
323
|
+
it("teleports the panel to the portal host when one is mounted", async () => {
|
|
324
|
+
const {getByTestId} = render(
|
|
325
|
+
<ThemeProvider>
|
|
326
|
+
<PortalContext.Provider value={manager as never}>
|
|
327
|
+
<DropdownPanel defaultOpen testID="f">
|
|
328
|
+
<Text>Body</Text>
|
|
329
|
+
</DropdownPanel>
|
|
330
|
+
</PortalContext.Provider>
|
|
331
|
+
</ThemeProvider>
|
|
332
|
+
);
|
|
333
|
+
|
|
334
|
+
await waitFor(() => {
|
|
335
|
+
expect(getByTestId("f.panel")).toBeTruthy();
|
|
336
|
+
});
|
|
337
|
+
expect(getByTestId("portal")).toBeTruthy();
|
|
338
|
+
});
|
|
339
|
+
|
|
340
|
+
it("renders inline when no portal host is mounted", async () => {
|
|
341
|
+
const {getByTestId, queryByTestId} = renderWithTheme(
|
|
342
|
+
<DropdownPanel defaultOpen testID="f">
|
|
343
|
+
<Text>Body</Text>
|
|
344
|
+
</DropdownPanel>
|
|
345
|
+
);
|
|
346
|
+
expect(getByTestId("f.panel")).toBeTruthy();
|
|
347
|
+
expect(queryByTestId("portal")).toBeNull();
|
|
348
|
+
});
|
|
349
|
+
});
|
|
350
|
+
|
|
351
|
+
describe("DropdownPanel viewport clamping", () => {
|
|
352
|
+
const originalGet = Dimensions.get;
|
|
353
|
+
|
|
354
|
+
afterEach(() => {
|
|
355
|
+
(Dimensions as {get: typeof originalGet}).get = originalGet;
|
|
356
|
+
});
|
|
357
|
+
|
|
358
|
+
it("keeps a panel wider than the viewport inside the screen margin", () => {
|
|
359
|
+
(Dimensions as {get: unknown}).get = () => ({fontScale: 1, height: 600, scale: 1, width: 240});
|
|
360
|
+
const {getByTestId} = renderWithTheme(
|
|
361
|
+
<DropdownPanel defaultOpen testID="f" width={320}>
|
|
362
|
+
<Text>Body</Text>
|
|
363
|
+
</DropdownPanel>
|
|
364
|
+
);
|
|
365
|
+
const style = getByTestId("f.panel").props.style as {maxHeight?: number; width?: number};
|
|
366
|
+
// A 320px panel cannot fit a 240px screen, so it renders at the margin-to-margin width.
|
|
367
|
+
expect(style.width).toBe(224);
|
|
368
|
+
expect(style.maxHeight).toBeGreaterThan(0);
|
|
369
|
+
});
|
|
370
|
+
});
|
|
@@ -1,10 +1,16 @@
|
|
|
1
|
-
import {type FC, type ReactNode, useEffect, useState} from "react";
|
|
2
|
-
import {Platform, Pressable, View, type ViewStyle} from "react-native";
|
|
1
|
+
import {type FC, type ReactNode, useContext, useEffect, useState} from "react";
|
|
2
|
+
import {Dimensions, Platform, Pressable, ScrollView, View, type ViewStyle} from "react-native";
|
|
3
3
|
|
|
4
4
|
import {Button} from "./Button";
|
|
5
|
-
import type {
|
|
5
|
+
import type {DropdownPanelProps} from "./Common";
|
|
6
6
|
import {createWebPortal} from "./createWebPortal";
|
|
7
|
+
import {
|
|
8
|
+
computeDropdownPanelLayout,
|
|
9
|
+
DROPDOWN_PANEL_GAP,
|
|
10
|
+
type DropdownPanelLayout,
|
|
11
|
+
} from "./dropdownPanelLayout";
|
|
7
12
|
import {Icon} from "./Icon";
|
|
13
|
+
import {Portal, PortalContext} from "./PortalHost";
|
|
8
14
|
import {Text} from "./Text";
|
|
9
15
|
import {useTheme} from "./Theme";
|
|
10
16
|
import {resolveTestID} from "./testing/resolveTestId";
|
|
@@ -12,27 +18,37 @@ import {createBoxShadow} from "./Utilities";
|
|
|
12
18
|
import {useWebDropdownAnchor} from "./WebDropdownMenu";
|
|
13
19
|
|
|
14
20
|
const DEFAULT_WIDTH = 320;
|
|
15
|
-
const TRIGGER_OFFSET = 44;
|
|
16
|
-
const PANEL_GAP = 4;
|
|
17
21
|
const ICON_TRIGGER_SIZE = {default: 32, sm: 24} as const;
|
|
22
|
+
/** Fallback trigger height for the inline overlay before the trigger has been measured. */
|
|
23
|
+
const TRIGGER_OFFSET = 44;
|
|
18
24
|
|
|
19
25
|
/**
|
|
20
|
-
* Compositional
|
|
21
|
-
* containing composed filter controls (`FilterSelectMenu`,
|
|
22
|
-
* `
|
|
23
|
-
*
|
|
26
|
+
* Compositional dropdown panel. Renders a trigger that opens a floating panel
|
|
27
|
+
* containing any composed content — the filter controls (`FilterSelectMenu`,
|
|
28
|
+
* `FilterBoolean`, `FilterAccordion`) it was designed for, or anything else that
|
|
29
|
+
* needs a panel with an optional Apply / Clear / Cancel footer. Clicking outside
|
|
30
|
+
* the panel closes it.
|
|
24
31
|
*
|
|
25
|
-
*
|
|
26
|
-
*
|
|
27
|
-
*
|
|
32
|
+
* The panel always escapes its ancestors' clipping and stacking contexts: on web
|
|
33
|
+
* it renders in a portal on `document.body` with fixed positioning, and on native
|
|
34
|
+
* it renders through the `TerrenoProvider` portal host (falling back to an inline
|
|
35
|
+
* absolute overlay when no host is mounted). It is anchored to the trigger and
|
|
36
|
+
* kept inside the viewport — right-aligning rather than running off the right
|
|
37
|
+
* edge, flipping above the trigger when there is no room below, and scrolling its
|
|
38
|
+
* body when the content is taller than the space available.
|
|
28
39
|
*/
|
|
29
|
-
export const
|
|
40
|
+
export const DropdownPanel: FC<DropdownPanelProps> = ({
|
|
41
|
+
align = "auto",
|
|
42
|
+
applyButtonVariant,
|
|
30
43
|
children,
|
|
31
44
|
label = "Filter",
|
|
32
45
|
triggerAccessibilityLabel,
|
|
33
46
|
iconName = "bars-filter",
|
|
34
47
|
iconOnly = false,
|
|
35
|
-
triggerSize
|
|
48
|
+
triggerSize,
|
|
49
|
+
triggerVariant,
|
|
50
|
+
renderTrigger,
|
|
51
|
+
fullWidth = false,
|
|
36
52
|
isOpen,
|
|
37
53
|
defaultOpen = false,
|
|
38
54
|
onOpenChange,
|
|
@@ -48,12 +64,16 @@ export const Filter: FC<FilterProps> = ({
|
|
|
48
64
|
onCancel,
|
|
49
65
|
variant = "primary",
|
|
50
66
|
width = DEFAULT_WIDTH,
|
|
67
|
+
maxPanelHeight,
|
|
51
68
|
testID,
|
|
52
69
|
}) => {
|
|
53
70
|
const {theme} = useTheme();
|
|
54
71
|
const [internalOpen, setInternalOpen] = useState(defaultOpen);
|
|
55
72
|
const [anchorReady, setAnchorReady] = useState(false);
|
|
56
73
|
const {anchor, cancelPendingMeasurement, measure, triggerRef} = useWebDropdownAnchor();
|
|
74
|
+
// Native portals need a host; without one the panel falls back to an inline overlay so
|
|
75
|
+
// apps (and tests) that render outside TerrenoProvider still get a usable dropdown.
|
|
76
|
+
const hasPortalHost = useContext(PortalContext) !== null;
|
|
57
77
|
|
|
58
78
|
const isControlled = isOpen !== undefined;
|
|
59
79
|
const open = isControlled ? isOpen : internalOpen;
|
|
@@ -99,8 +119,8 @@ export const Filter: FC<FilterProps> = ({
|
|
|
99
119
|
};
|
|
100
120
|
|
|
101
121
|
const handleClear = (): void => {
|
|
102
|
-
// Clearing resets the
|
|
103
|
-
// immediately pick new
|
|
122
|
+
// Clearing resets the values but keeps the panel open so the user can
|
|
123
|
+
// immediately pick new ones without reopening it.
|
|
104
124
|
onClear?.();
|
|
105
125
|
};
|
|
106
126
|
|
|
@@ -110,8 +130,19 @@ export const Filter: FC<FilterProps> = ({
|
|
|
110
130
|
restoreTriggerFocus();
|
|
111
131
|
};
|
|
112
132
|
|
|
133
|
+
const toggle = (): void => setOpen(!open);
|
|
134
|
+
|
|
113
135
|
const showFooter = showActionButtons && (showApplyButton || showClearButton || showCancelButton);
|
|
114
136
|
|
|
137
|
+
const layout: DropdownPanelLayout = computeDropdownPanelLayout({
|
|
138
|
+
align,
|
|
139
|
+
anchor,
|
|
140
|
+
maxPanelHeight,
|
|
141
|
+
panelWidth: width,
|
|
142
|
+
viewportHeight: Dimensions.get("window").height,
|
|
143
|
+
viewportWidth: Dimensions.get("window").width,
|
|
144
|
+
});
|
|
145
|
+
|
|
115
146
|
const panelSurfaceStyle: ViewStyle = {
|
|
116
147
|
backgroundColor: theme.surface.base,
|
|
117
148
|
borderColor: theme.border.default,
|
|
@@ -123,12 +154,19 @@ export const Filter: FC<FilterProps> = ({
|
|
|
123
154
|
offsetY: 4,
|
|
124
155
|
opacity: 0.15,
|
|
125
156
|
}),
|
|
126
|
-
|
|
157
|
+
maxHeight: layout.maxHeight,
|
|
158
|
+
width: layout.width,
|
|
127
159
|
};
|
|
128
160
|
|
|
129
161
|
const panelBody: ReactNode = (
|
|
130
162
|
<>
|
|
131
|
-
<
|
|
163
|
+
<ScrollView
|
|
164
|
+
contentContainerStyle={{padding: theme.spacing.sm}}
|
|
165
|
+
keyboardShouldPersistTaps="handled"
|
|
166
|
+
style={{flexShrink: 1}}
|
|
167
|
+
>
|
|
168
|
+
{children}
|
|
169
|
+
</ScrollView>
|
|
132
170
|
{showFooter && (
|
|
133
171
|
<View
|
|
134
172
|
style={{
|
|
@@ -173,7 +211,7 @@ export const Filter: FC<FilterProps> = ({
|
|
|
173
211
|
onClick={handleApply}
|
|
174
212
|
testID={testID ? resolveTestID(testID, "apply") : undefined}
|
|
175
213
|
text={applyButtonText}
|
|
176
|
-
variant={variant}
|
|
214
|
+
variant={applyButtonVariant ?? variant}
|
|
177
215
|
/>
|
|
178
216
|
)}
|
|
179
217
|
</View>
|
|
@@ -182,6 +220,15 @@ export const Filter: FC<FilterProps> = ({
|
|
|
182
220
|
</>
|
|
183
221
|
);
|
|
184
222
|
|
|
223
|
+
const positionedPanelStyle = (position: "absolute" | "fixed"): ViewStyle =>
|
|
224
|
+
({
|
|
225
|
+
...panelSurfaceStyle,
|
|
226
|
+
bottom: layout.bottom,
|
|
227
|
+
left: layout.left,
|
|
228
|
+
position,
|
|
229
|
+
top: layout.top,
|
|
230
|
+
}) as unknown as ViewStyle;
|
|
231
|
+
|
|
185
232
|
const renderOverlay = (): ReactNode => {
|
|
186
233
|
// Web: portal to document.body with fixed positioning so the panel escapes
|
|
187
234
|
// every ancestor stacking context and floats above all page content.
|
|
@@ -209,15 +256,7 @@ export const Filter: FC<FilterProps> = ({
|
|
|
209
256
|
testID={testID ? resolveTestID(testID, "backdrop") : undefined}
|
|
210
257
|
/>
|
|
211
258
|
<View
|
|
212
|
-
style={
|
|
213
|
-
{
|
|
214
|
-
...panelSurfaceStyle,
|
|
215
|
-
left: anchor.x,
|
|
216
|
-
position: "fixed",
|
|
217
|
-
top: anchor.y + anchor.height + PANEL_GAP,
|
|
218
|
-
zIndex: 2,
|
|
219
|
-
} as unknown as ViewStyle
|
|
220
|
-
}
|
|
259
|
+
style={{...positionedPanelStyle("fixed"), zIndex: 2}}
|
|
221
260
|
testID={testID ? resolveTestID(testID, "panel") : undefined}
|
|
222
261
|
>
|
|
223
262
|
{panelBody}
|
|
@@ -229,8 +268,24 @@ export const Filter: FC<FilterProps> = ({
|
|
|
229
268
|
return target ? createWebPortal({children: overlay, container: target}) : overlay;
|
|
230
269
|
}
|
|
231
270
|
|
|
232
|
-
// Native
|
|
233
|
-
|
|
271
|
+
// Native: teleport to the portal host so the panel is not clipped by a scroll view or
|
|
272
|
+
// card, positioned from the window coordinates the host shares. Without a host the
|
|
273
|
+
// panel stays inline and is anchored directly beneath the trigger.
|
|
274
|
+
const panelStyle: ViewStyle = hasPortalHost
|
|
275
|
+
? {...positionedPanelStyle("absolute"), zIndex: 11}
|
|
276
|
+
: {
|
|
277
|
+
...panelSurfaceStyle,
|
|
278
|
+
left: 0,
|
|
279
|
+
position: "absolute",
|
|
280
|
+
top: (anchor.height || TRIGGER_OFFSET) + DROPDOWN_PANEL_GAP,
|
|
281
|
+
zIndex: 11,
|
|
282
|
+
};
|
|
283
|
+
|
|
284
|
+
if (hasPortalHost && !anchorReady) {
|
|
285
|
+
return null;
|
|
286
|
+
}
|
|
287
|
+
|
|
288
|
+
const nativeOverlay = (
|
|
234
289
|
<>
|
|
235
290
|
<Pressable
|
|
236
291
|
aria-role="button"
|
|
@@ -238,60 +293,76 @@ export const Filter: FC<FilterProps> = ({
|
|
|
238
293
|
style={{bottom: 0, left: 0, position: "absolute", right: 0, top: 0, zIndex: 10}}
|
|
239
294
|
testID={testID ? resolveTestID(testID, "backdrop") : undefined}
|
|
240
295
|
/>
|
|
241
|
-
<View
|
|
242
|
-
style={{
|
|
243
|
-
...panelSurfaceStyle,
|
|
244
|
-
left: 0,
|
|
245
|
-
position: "absolute",
|
|
246
|
-
top: TRIGGER_OFFSET,
|
|
247
|
-
zIndex: 11,
|
|
248
|
-
}}
|
|
249
|
-
testID={testID ? resolveTestID(testID, "panel") : undefined}
|
|
250
|
-
>
|
|
296
|
+
<View style={panelStyle} testID={testID ? resolveTestID(testID, "panel") : undefined}>
|
|
251
297
|
{panelBody}
|
|
252
298
|
</View>
|
|
253
299
|
</>
|
|
254
300
|
);
|
|
301
|
+
|
|
302
|
+
return hasPortalHost ? <Portal>{nativeOverlay}</Portal> : nativeOverlay;
|
|
255
303
|
};
|
|
256
304
|
|
|
257
|
-
|
|
258
|
-
|
|
259
|
-
|
|
260
|
-
|
|
261
|
-
|
|
262
|
-
|
|
263
|
-
|
|
264
|
-
|
|
265
|
-
|
|
266
|
-
|
|
267
|
-
|
|
268
|
-
|
|
269
|
-
|
|
270
|
-
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
color="secondaryLight"
|
|
279
|
-
iconName={iconName}
|
|
280
|
-
size={triggerSize === "sm" ? "sm" : "md"}
|
|
281
|
-
/>
|
|
282
|
-
</Pressable>
|
|
283
|
-
) : (
|
|
284
|
-
<Button
|
|
285
|
-
accessibilityLabel={triggerAccessibilityLabel}
|
|
305
|
+
const renderDefaultTrigger = (): ReactNode => {
|
|
306
|
+
if (iconOnly) {
|
|
307
|
+
return (
|
|
308
|
+
<Pressable
|
|
309
|
+
accessibilityLabel={triggerAccessibilityLabel ?? label ?? "Filter"}
|
|
310
|
+
accessibilityRole="button"
|
|
311
|
+
aria-label={triggerAccessibilityLabel ?? label ?? "Filter"}
|
|
312
|
+
hitSlop={8}
|
|
313
|
+
onPress={toggle}
|
|
314
|
+
style={{
|
|
315
|
+
alignItems: "center",
|
|
316
|
+
backgroundColor: open ? theme.surface.neutralLight : theme.surface.base,
|
|
317
|
+
borderRadius: theme.radius.rounded,
|
|
318
|
+
height: ICON_TRIGGER_SIZE[triggerSize ?? "sm"],
|
|
319
|
+
justifyContent: "center",
|
|
320
|
+
width: ICON_TRIGGER_SIZE[triggerSize ?? "sm"],
|
|
321
|
+
}}
|
|
322
|
+
testID={testID ? resolveTestID(testID, "trigger") : undefined}
|
|
323
|
+
>
|
|
324
|
+
<Icon
|
|
325
|
+
color="secondaryLight"
|
|
286
326
|
iconName={iconName}
|
|
287
|
-
|
|
288
|
-
testID={testID ? resolveTestID(testID, "trigger") : undefined}
|
|
289
|
-
text={label}
|
|
290
|
-
variant={variant}
|
|
327
|
+
size={(triggerSize ?? "sm") === "sm" ? "sm" : "md"}
|
|
291
328
|
/>
|
|
292
|
-
|
|
329
|
+
</Pressable>
|
|
330
|
+
);
|
|
331
|
+
}
|
|
332
|
+
|
|
333
|
+
return (
|
|
334
|
+
<Button
|
|
335
|
+
accessibilityLabel={triggerAccessibilityLabel}
|
|
336
|
+
fullWidth={fullWidth}
|
|
337
|
+
iconName={iconName}
|
|
338
|
+
onClick={toggle}
|
|
339
|
+
size={triggerSize ?? "default"}
|
|
340
|
+
testID={testID ? resolveTestID(testID, "trigger") : undefined}
|
|
341
|
+
text={label}
|
|
342
|
+
variant={triggerVariant ?? variant}
|
|
343
|
+
/>
|
|
344
|
+
);
|
|
345
|
+
};
|
|
346
|
+
|
|
347
|
+
return (
|
|
348
|
+
<View style={{position: "relative", width: fullWidth ? "100%" : undefined}} testID={testID}>
|
|
349
|
+
{/* The wrapper is what gets measured, so it must hug the trigger. A stretched
|
|
350
|
+
wrapper anchors the panel to the start of the whole row instead — which looks
|
|
351
|
+
right only while the trigger happens to sit at that edge. */}
|
|
352
|
+
<View
|
|
353
|
+
collapsable={false}
|
|
354
|
+
ref={triggerRef}
|
|
355
|
+
style={{alignSelf: fullWidth ? "stretch" : "flex-start"}}
|
|
356
|
+
>
|
|
357
|
+
{renderTrigger ? renderTrigger({isOpen: Boolean(open), toggle}) : renderDefaultTrigger()}
|
|
293
358
|
</View>
|
|
294
359
|
{Boolean(open) && renderOverlay()}
|
|
295
360
|
</View>
|
|
296
361
|
);
|
|
297
362
|
};
|
|
363
|
+
|
|
364
|
+
/**
|
|
365
|
+
* @deprecated Renamed to {@link DropdownPanel} — the component is a general
|
|
366
|
+
* compositional dropdown, not filter-specific. Removed in Terreno 58.
|
|
367
|
+
*/
|
|
368
|
+
export const Filter = DropdownPanel;
|