@terreno/ui 57.0.0-beta.1 → 57.1.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/DateTimeField.js +6 -2
- package/dist/DateTimeField.js.map +1 -1
- package/dist/DraggableList.js +7 -4
- package/dist/DraggableList.js.map +1 -1
- package/dist/Filter.js +14 -9
- package/dist/Filter.js.map +1 -1
- package/dist/GPTChat.d.ts +7 -1
- package/dist/GPTChat.js +26 -16
- package/dist/GPTChat.js.map +1 -1
- package/dist/ModalSheet.js +1 -1
- package/dist/ModalSheet.js.map +1 -1
- package/dist/PortalHost.d.ts +24 -0
- package/dist/PortalHost.js +52 -0
- package/dist/PortalHost.js.map +1 -0
- package/dist/SidebarNavigation.native.js +2 -1
- package/dist/SidebarNavigation.native.js.map +1 -1
- package/dist/TapToEdit.js +2 -5
- package/dist/TapToEdit.js.map +1 -1
- package/dist/TerrenoProvider.js +1 -1
- package/dist/TerrenoProvider.js.map +1 -1
- package/dist/ToastNotifications.js +8 -5
- package/dist/ToastNotifications.js.map +1 -1
- package/dist/Tooltip.js +1 -1
- package/dist/Tooltip.js.map +1 -1
- package/dist/Utilities.d.ts +24 -0
- package/dist/Utilities.js +51 -0
- package/dist/Utilities.js.map +1 -1
- package/dist/WebDropdownMenu.js +11 -15
- package/dist/WebDropdownMenu.js.map +1 -1
- package/dist/index.d.ts +1 -0
- package/dist/index.js +1 -0
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/DateTimeField.tsx +6 -3
- package/src/DraggableList.tsx +7 -4
- package/src/Filter.test.tsx +154 -1
- package/src/Filter.tsx +16 -7
- package/src/GPTChat.tsx +89 -16
- package/src/ModalSheet.tsx +2 -1
- package/src/PortalHost.tsx +105 -0
- package/src/SidebarNavigation.native.tsx +1 -1
- package/src/TapToEdit.tsx +6 -5
- package/src/TerrenoProvider.tsx +1 -1
- package/src/ToastNotifications.tsx +4 -5
- package/src/Tooltip.tsx +1 -1
- package/src/Utilities.test.tsx +47 -0
- package/src/Utilities.tsx +78 -0
- package/src/WebDropdownMenu.test.tsx +54 -0
- package/src/WebDropdownMenu.tsx +11 -10
- package/src/__snapshots__/AddressField.test.tsx.snap +1 -7
- package/src/__snapshots__/CustomSelectField.test.tsx.snap +7 -49
- package/src/__snapshots__/Field.test.tsx.snap +9 -51
- package/src/__snapshots__/SelectField.test.tsx.snap +6 -42
- package/src/__snapshots__/TerrenoProvider.test.tsx.snap +4 -4
- package/src/__snapshots__/TimezonePicker.test.tsx.snap +6 -42
- package/src/bunSetup.ts +2 -2
- package/src/index.tsx +1 -0
- package/src/shadowStyleProps.test.ts +30 -0
- package/src/table/__snapshots__/TableBadge.test.tsx.snap +1 -7
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
import type {FC, ReactNode} from "react";
|
|
2
|
+
import {
|
|
3
|
+
createContext,
|
|
4
|
+
useCallback,
|
|
5
|
+
useContext,
|
|
6
|
+
useEffect,
|
|
7
|
+
useId,
|
|
8
|
+
useMemo,
|
|
9
|
+
useRef,
|
|
10
|
+
useState,
|
|
11
|
+
} from "react";
|
|
12
|
+
import {type StyleProp, StyleSheet, View, type ViewStyle} from "react-native";
|
|
13
|
+
|
|
14
|
+
interface PortalManager {
|
|
15
|
+
mount: (key: string, children: ReactNode) => void;
|
|
16
|
+
update: (key: string, children: ReactNode) => void;
|
|
17
|
+
unmount: (key: string) => void;
|
|
18
|
+
}
|
|
19
|
+
|
|
20
|
+
interface PortalEntry {
|
|
21
|
+
children: ReactNode;
|
|
22
|
+
key: string;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
export const PortalContext = createContext<PortalManager | null>(null);
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* Renders its children plus any content sent from a {@link Portal} on top of
|
|
29
|
+
* them. Mount once near the root of the app (TerrenoProvider does this).
|
|
30
|
+
*/
|
|
31
|
+
export const Host: FC<{children?: ReactNode; style?: StyleProp<ViewStyle>}> = ({
|
|
32
|
+
children,
|
|
33
|
+
style,
|
|
34
|
+
}) => {
|
|
35
|
+
const [portals, setPortals] = useState<PortalEntry[]>([]);
|
|
36
|
+
|
|
37
|
+
const mount = useCallback((key: string, portalChildren: ReactNode): void => {
|
|
38
|
+
setPortals((prev) => [
|
|
39
|
+
...prev.filter((entry) => entry.key !== key),
|
|
40
|
+
{children: portalChildren, key},
|
|
41
|
+
]);
|
|
42
|
+
}, []);
|
|
43
|
+
|
|
44
|
+
const update = useCallback((key: string, portalChildren: ReactNode): void => {
|
|
45
|
+
setPortals((prev) =>
|
|
46
|
+
prev.map((entry) => (entry.key === key ? {...entry, children: portalChildren} : entry))
|
|
47
|
+
);
|
|
48
|
+
}, []);
|
|
49
|
+
|
|
50
|
+
const unmount = useCallback((key: string): void => {
|
|
51
|
+
setPortals((prev) => prev.filter((entry) => entry.key !== key));
|
|
52
|
+
}, []);
|
|
53
|
+
|
|
54
|
+
const manager = useMemo<PortalManager>(
|
|
55
|
+
() => ({mount, unmount, update}),
|
|
56
|
+
[mount, unmount, update]
|
|
57
|
+
);
|
|
58
|
+
|
|
59
|
+
return (
|
|
60
|
+
<PortalContext.Provider value={manager}>
|
|
61
|
+
<View collapsable={false} style={[{flex: 1, pointerEvents: "box-none"}, style]}>
|
|
62
|
+
{children}
|
|
63
|
+
</View>
|
|
64
|
+
{portals.map(({children: portalChildren, key}) => (
|
|
65
|
+
<View
|
|
66
|
+
collapsable={false}
|
|
67
|
+
key={key}
|
|
68
|
+
style={[StyleSheet.absoluteFill, {pointerEvents: "box-none"}]}
|
|
69
|
+
>
|
|
70
|
+
{portalChildren}
|
|
71
|
+
</View>
|
|
72
|
+
))}
|
|
73
|
+
</PortalContext.Provider>
|
|
74
|
+
);
|
|
75
|
+
};
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Teleports its children to the nearest {@link Host}, so overlays escape the
|
|
79
|
+
* clipping and stacking context of the component that renders them.
|
|
80
|
+
*/
|
|
81
|
+
export const Portal: FC<{children?: ReactNode}> = ({children}) => {
|
|
82
|
+
const manager = useContext(PortalContext);
|
|
83
|
+
const key = useId();
|
|
84
|
+
const childrenRef = useRef(children);
|
|
85
|
+
childrenRef.current = children;
|
|
86
|
+
|
|
87
|
+
// Register with the host on mount and clean up the portal when unmounting.
|
|
88
|
+
useEffect(() => {
|
|
89
|
+
if (!manager) {
|
|
90
|
+
return;
|
|
91
|
+
}
|
|
92
|
+
manager.mount(key, childrenRef.current);
|
|
93
|
+
return () => manager.unmount(key);
|
|
94
|
+
}, [key, manager]);
|
|
95
|
+
|
|
96
|
+
// Push the latest children into the host whenever the portal content changes.
|
|
97
|
+
useEffect(() => {
|
|
98
|
+
if (!manager) {
|
|
99
|
+
return;
|
|
100
|
+
}
|
|
101
|
+
manager.update(key, children);
|
|
102
|
+
}, [children, key, manager]);
|
|
103
|
+
|
|
104
|
+
return null;
|
|
105
|
+
};
|
|
@@ -391,12 +391,12 @@ const SidebarHeader: FC<{onOpen: () => void}> = ({onOpen}) => {
|
|
|
391
391
|
</View>
|
|
392
392
|
{Boolean(title) && (
|
|
393
393
|
<View
|
|
394
|
-
pointerEvents="none"
|
|
395
394
|
style={{
|
|
396
395
|
alignItems: "center",
|
|
397
396
|
bottom: 0,
|
|
398
397
|
justifyContent: "center",
|
|
399
398
|
left: 0,
|
|
399
|
+
pointerEvents: "none",
|
|
400
400
|
position: "absolute",
|
|
401
401
|
right: 0,
|
|
402
402
|
top: 0,
|
package/src/TapToEdit.tsx
CHANGED
|
@@ -84,15 +84,16 @@ export const TapToEdit: FC<TapToEditProps> = ({
|
|
|
84
84
|
const helperText: string | undefined = propsHelperText;
|
|
85
85
|
|
|
86
86
|
// TODO: Auto focus on input when editing for field types other than text for accessibility
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
87
|
+
interface FocusableInput {
|
|
88
|
+
focus?: () => void;
|
|
89
|
+
}
|
|
90
|
+
const inputRef = useRef<FocusableInput | null>(null);
|
|
90
91
|
|
|
91
92
|
// bring the bring the input into focus when editing from within the component,
|
|
92
93
|
// but not when editing from outside
|
|
93
94
|
useEffect(() => {
|
|
94
95
|
if (editable && editing && !isEditing) {
|
|
95
|
-
inputRef.current?.focus();
|
|
96
|
+
inputRef.current?.focus?.();
|
|
96
97
|
}
|
|
97
98
|
}, [editable, editing, isEditing]);
|
|
98
99
|
|
|
@@ -113,7 +114,7 @@ export const TapToEdit: FC<TapToEditProps> = ({
|
|
|
113
114
|
inputRef={
|
|
114
115
|
["text", "textarea", "url", "email", "number"].includes(fieldProps?.type)
|
|
115
116
|
? (ref: unknown) => {
|
|
116
|
-
inputRef.current = ref;
|
|
117
|
+
inputRef.current = ref as FocusableInput | null;
|
|
117
118
|
}
|
|
118
119
|
: undefined
|
|
119
120
|
}
|
package/src/TerrenoProvider.tsx
CHANGED
|
@@ -1,10 +1,10 @@
|
|
|
1
1
|
import type React from "react";
|
|
2
2
|
import type {FC} from "react";
|
|
3
|
-
import {Host} from "react-native-portalize";
|
|
4
3
|
|
|
5
4
|
import type {IconRegistryMap} from "./Common";
|
|
6
5
|
import {IconRegistryProvider} from "./IconRegistry";
|
|
7
6
|
import {OpenAPIProvider} from "./OpenAPIContext";
|
|
7
|
+
import {Host} from "./PortalHost";
|
|
8
8
|
import {ThemeProvider} from "./Theme";
|
|
9
9
|
import {Toast} from "./Toast";
|
|
10
10
|
import {ToastProvider} from "./ToastNotifications";
|
|
@@ -397,7 +397,6 @@ const ToastItem: FC<ToastProps> = (props) => {
|
|
|
397
397
|
|
|
398
398
|
return (
|
|
399
399
|
<Animated.View
|
|
400
|
-
pointerEvents={"box-none"}
|
|
401
400
|
ref={containerRef}
|
|
402
401
|
{...(swipeEnabled ? getPanResponder().panHandlers : null)}
|
|
403
402
|
style={[toastStyles.container, animationStyle]}
|
|
@@ -429,7 +428,7 @@ const ToastItem: FC<ToastProps> = (props) => {
|
|
|
429
428
|
};
|
|
430
429
|
|
|
431
430
|
const toastStyles = StyleSheet.create({
|
|
432
|
-
container: {alignItems: "center", width: "100%"},
|
|
431
|
+
container: {alignItems: "center", pointerEvents: "box-none", width: "100%"},
|
|
433
432
|
iconContainer: {
|
|
434
433
|
marginRight: 5,
|
|
435
434
|
},
|
|
@@ -640,7 +639,6 @@ const ToastContainer = forwardRef<ToastContainerRef, ToastContainerProps>((props
|
|
|
640
639
|
return (
|
|
641
640
|
<KeyboardAvoidingView
|
|
642
641
|
behavior={Platform.OS === "ios" ? "position" : undefined}
|
|
643
|
-
pointerEvents="box-none"
|
|
644
642
|
style={[containerStyles.container, style]}
|
|
645
643
|
>
|
|
646
644
|
<SafeAreaView>
|
|
@@ -664,7 +662,6 @@ const ToastContainer = forwardRef<ToastContainerRef, ToastContainerProps>((props
|
|
|
664
662
|
return (
|
|
665
663
|
<KeyboardAvoidingView
|
|
666
664
|
behavior={Platform.OS === "ios" ? "position" : undefined}
|
|
667
|
-
pointerEvents="box-none"
|
|
668
665
|
style={[containerStyles.container, style]}
|
|
669
666
|
>
|
|
670
667
|
<SafeAreaView>
|
|
@@ -695,7 +692,6 @@ const ToastContainer = forwardRef<ToastContainerRef, ToastContainerProps>((props
|
|
|
695
692
|
return (
|
|
696
693
|
<KeyboardAvoidingView
|
|
697
694
|
behavior={Platform.OS === "ios" ? "position" : undefined}
|
|
698
|
-
pointerEvents="box-none"
|
|
699
695
|
style={[containerStyles.container, style]}
|
|
700
696
|
>
|
|
701
697
|
{toasts
|
|
@@ -724,6 +720,9 @@ const containerStyles = StyleSheet.create({
|
|
|
724
720
|
elevation: 999999,
|
|
725
721
|
flex: 0,
|
|
726
722
|
maxWidth: "100%",
|
|
723
|
+
// box-none lets clicks pass through the full-width container to the page below,
|
|
724
|
+
// while individual toasts stay interactive.
|
|
725
|
+
pointerEvents: "box-none",
|
|
727
726
|
// @ts-expect-error: fixed is available on web.
|
|
728
727
|
position: Platform.OS === "web" ? "fixed" : "absolute",
|
|
729
728
|
zIndex: 999999,
|
package/src/Tooltip.tsx
CHANGED
|
@@ -8,9 +8,9 @@ import {
|
|
|
8
8
|
View,
|
|
9
9
|
type ViewStyle,
|
|
10
10
|
} from "react-native";
|
|
11
|
-
import {Portal} from "react-native-portalize";
|
|
12
11
|
|
|
13
12
|
import type {TooltipPosition, TooltipProps} from "./Common";
|
|
13
|
+
import {Portal} from "./PortalHost";
|
|
14
14
|
import {Text} from "./Text";
|
|
15
15
|
import {useTheme} from "./Theme";
|
|
16
16
|
|
package/src/Utilities.test.tsx
CHANGED
|
@@ -2,8 +2,10 @@ import {describe, expect, it} from "bun:test";
|
|
|
2
2
|
|
|
3
3
|
import type {APIError, BaseProfile} from "./Common";
|
|
4
4
|
import {
|
|
5
|
+
applyColorOpacity,
|
|
5
6
|
bind,
|
|
6
7
|
concat,
|
|
8
|
+
createBoxShadow,
|
|
7
9
|
findAddressComponent,
|
|
8
10
|
formattedCountyCode,
|
|
9
11
|
fromClassName,
|
|
@@ -425,4 +427,49 @@ describe("Utilities", () => {
|
|
|
425
427
|
expect(printAPIError(error as unknown as APIError, true)).toBe("Not Found");
|
|
426
428
|
});
|
|
427
429
|
});
|
|
430
|
+
|
|
431
|
+
describe("applyColorOpacity", () => {
|
|
432
|
+
it("converts six digit hex colors", () => {
|
|
433
|
+
expect(applyColorOpacity({color: "#1C1C1C", opacity: 0.15})).toBe("rgba(28, 28, 28, 0.15)");
|
|
434
|
+
});
|
|
435
|
+
|
|
436
|
+
it("expands shorthand hex colors", () => {
|
|
437
|
+
expect(applyColorOpacity({color: "#abc", opacity: 1})).toBe("rgba(170, 187, 204, 1)");
|
|
438
|
+
});
|
|
439
|
+
|
|
440
|
+
it("multiplies an existing alpha channel by the opacity", () => {
|
|
441
|
+
expect(applyColorOpacity({color: "#00000080", opacity: 0.5})).toBe("rgba(0, 0, 0, 0.251)");
|
|
442
|
+
});
|
|
443
|
+
|
|
444
|
+
it("converts rgb and rgba colors", () => {
|
|
445
|
+
expect(applyColorOpacity({color: "rgb(10, 20, 30)", opacity: 0.4})).toBe(
|
|
446
|
+
"rgba(10, 20, 30, 0.4)"
|
|
447
|
+
);
|
|
448
|
+
expect(applyColorOpacity({color: "rgba(10, 20, 30, 0.5)", opacity: 0.5})).toBe(
|
|
449
|
+
"rgba(10, 20, 30, 0.25)"
|
|
450
|
+
);
|
|
451
|
+
});
|
|
452
|
+
|
|
453
|
+
it("clamps opacity to the 0-1 range", () => {
|
|
454
|
+
expect(applyColorOpacity({color: "#000000", opacity: 5})).toBe("rgba(0, 0, 0, 1)");
|
|
455
|
+
expect(applyColorOpacity({color: "#000000", opacity: -1})).toBe("rgba(0, 0, 0, 0)");
|
|
456
|
+
});
|
|
457
|
+
|
|
458
|
+
it("returns unparseable colors unchanged", () => {
|
|
459
|
+
expect(applyColorOpacity({color: "papayawhip", opacity: 0.5})).toBe("papayawhip");
|
|
460
|
+
expect(applyColorOpacity({color: "#12345", opacity: 0.5})).toBe("#12345");
|
|
461
|
+
});
|
|
462
|
+
});
|
|
463
|
+
|
|
464
|
+
describe("createBoxShadow", () => {
|
|
465
|
+
it("builds a box shadow value with defaults", () => {
|
|
466
|
+
expect(createBoxShadow({blurRadius: 8})).toBe("0px 0px 8px rgba(0, 0, 0, 1)");
|
|
467
|
+
});
|
|
468
|
+
|
|
469
|
+
it("applies offsets, color, and opacity", () => {
|
|
470
|
+
expect(
|
|
471
|
+
createBoxShadow({blurRadius: 12, color: "#1C1C1C", offsetX: 1, offsetY: 4, opacity: 0.15})
|
|
472
|
+
).toBe("1px 4px 12px rgba(28, 28, 28, 0.15)");
|
|
473
|
+
});
|
|
474
|
+
});
|
|
428
475
|
});
|
package/src/Utilities.tsx
CHANGED
|
@@ -193,6 +193,84 @@ export const isNative = (): boolean => {
|
|
|
193
193
|
return ["android", "ios"].includes(Platform.OS);
|
|
194
194
|
};
|
|
195
195
|
|
|
196
|
+
interface ColorWithOpacityOptions {
|
|
197
|
+
color: string;
|
|
198
|
+
opacity: number;
|
|
199
|
+
}
|
|
200
|
+
|
|
201
|
+
/**
|
|
202
|
+
* Applies an opacity to a color, returning an `rgba()` string. Supports `#rgb`,
|
|
203
|
+
* `#rgba`, `#rrggbb`, `#rrggbbaa`, `rgb()`, and `rgba()` inputs. Colors that
|
|
204
|
+
* can't be parsed (e.g. named CSS colors) are returned unchanged.
|
|
205
|
+
*/
|
|
206
|
+
export const applyColorOpacity = ({color, opacity}: ColorWithOpacityOptions): string => {
|
|
207
|
+
const clampedOpacity = Math.max(0, Math.min(1, opacity));
|
|
208
|
+
|
|
209
|
+
if (color.startsWith("#")) {
|
|
210
|
+
const hex = color.slice(1);
|
|
211
|
+
const isShorthand = hex.length === 3 || hex.length === 4;
|
|
212
|
+
if (!isShorthand && hex.length !== 6 && hex.length !== 8) {
|
|
213
|
+
return color;
|
|
214
|
+
}
|
|
215
|
+
const expanded = isShorthand
|
|
216
|
+
? hex
|
|
217
|
+
.split("")
|
|
218
|
+
.map((char) => `${char}${char}`)
|
|
219
|
+
.join("")
|
|
220
|
+
: hex;
|
|
221
|
+
const red = Number.parseInt(expanded.slice(0, 2), 16);
|
|
222
|
+
const green = Number.parseInt(expanded.slice(2, 4), 16);
|
|
223
|
+
const blue = Number.parseInt(expanded.slice(4, 6), 16);
|
|
224
|
+
if (Number.isNaN(red) || Number.isNaN(green) || Number.isNaN(blue)) {
|
|
225
|
+
return color;
|
|
226
|
+
}
|
|
227
|
+
// An alpha channel on the input color multiplies with the requested opacity,
|
|
228
|
+
// matching how react-native-web combined a shadow's color and opacity.
|
|
229
|
+
const alphaChannel =
|
|
230
|
+
expanded.length === 8 ? Number.parseInt(expanded.slice(6, 8), 16) / 255 : 1;
|
|
231
|
+
const alpha = Number.isNaN(alphaChannel) ? clampedOpacity : alphaChannel * clampedOpacity;
|
|
232
|
+
return `rgba(${red}, ${green}, ${blue}, ${roundOpacity(alpha)})`;
|
|
233
|
+
}
|
|
234
|
+
|
|
235
|
+
const rgbMatch = /^rgba?\(([^)]+)\)$/i.exec(color);
|
|
236
|
+
if (!rgbMatch) {
|
|
237
|
+
return color;
|
|
238
|
+
}
|
|
239
|
+
const parts = rgbMatch[1].split(",").map((part) => part.trim());
|
|
240
|
+
if (parts.length !== 3 && parts.length !== 4) {
|
|
241
|
+
return color;
|
|
242
|
+
}
|
|
243
|
+
const existingAlpha = parts.length === 4 ? Number.parseFloat(parts[3]) : 1;
|
|
244
|
+
const alpha = Number.isNaN(existingAlpha) ? clampedOpacity : existingAlpha * clampedOpacity;
|
|
245
|
+
return `rgba(${parts[0]}, ${parts[1]}, ${parts[2]}, ${roundOpacity(alpha)})`;
|
|
246
|
+
};
|
|
247
|
+
|
|
248
|
+
const roundOpacity = (alpha: number): number => Math.round(alpha * 1000) / 1000;
|
|
249
|
+
|
|
250
|
+
interface BoxShadowOptions {
|
|
251
|
+
blurRadius: number;
|
|
252
|
+
/** Shadow color. Defaults to black, matching the platform shadow default. */
|
|
253
|
+
color?: string;
|
|
254
|
+
offsetX?: number;
|
|
255
|
+
offsetY?: number;
|
|
256
|
+
/** Shadow alpha, folded into the color since `boxShadow` has no opacity field. */
|
|
257
|
+
opacity?: number;
|
|
258
|
+
}
|
|
259
|
+
|
|
260
|
+
/**
|
|
261
|
+
* Builds a CSS `box-shadow` value for the `boxShadow` style prop, which replaces
|
|
262
|
+
* the deprecated `shadow*` style props (color, offset, opacity, and radius).
|
|
263
|
+
*/
|
|
264
|
+
export const createBoxShadow = ({
|
|
265
|
+
blurRadius,
|
|
266
|
+
color = "#000000",
|
|
267
|
+
offsetX = 0,
|
|
268
|
+
offsetY = 0,
|
|
269
|
+
opacity = 1,
|
|
270
|
+
}: BoxShadowOptions): string => {
|
|
271
|
+
return `${offsetX}px ${offsetY}px ${blurRadius}px ${applyColorOpacity({color, opacity})}`;
|
|
272
|
+
};
|
|
273
|
+
|
|
196
274
|
// Find more information about the address component types here: https://developers.google.com/maps/documentation/javascript/place-autocomplete
|
|
197
275
|
export type AddressComponentType = {
|
|
198
276
|
long_name: string;
|
|
@@ -647,6 +647,60 @@ describe("WebDropdownMenu centered presentation", () => {
|
|
|
647
647
|
expect(style.top).toBeUndefined();
|
|
648
648
|
expect(style.maxHeight).toBe(Math.round(812 * 0.55));
|
|
649
649
|
});
|
|
650
|
+
|
|
651
|
+
it("uses elevation without boxShadow on Android", () => {
|
|
652
|
+
const PlatformModule = require("react-native").Platform;
|
|
653
|
+
const savedOS = PlatformModule.OS;
|
|
654
|
+
try {
|
|
655
|
+
PlatformModule.OS = "android";
|
|
656
|
+
const {getByTestId} = renderWithTheme(
|
|
657
|
+
<WebDropdownMenu
|
|
658
|
+
anchor={anchor}
|
|
659
|
+
disableSearch
|
|
660
|
+
onClose={() => {}}
|
|
661
|
+
onSelect={() => {}}
|
|
662
|
+
options={options}
|
|
663
|
+
presentation="centered"
|
|
664
|
+
visible
|
|
665
|
+
/>
|
|
666
|
+
);
|
|
667
|
+
const menu = getByTestId("web_dropdown_menu");
|
|
668
|
+
const style = Array.isArray(menu.props.style)
|
|
669
|
+
? Object.assign({}, ...menu.props.style)
|
|
670
|
+
: menu.props.style;
|
|
671
|
+
expect(style.elevation).toBe(8);
|
|
672
|
+
expect(style.boxShadow).toBeUndefined();
|
|
673
|
+
} finally {
|
|
674
|
+
PlatformModule.OS = savedOS;
|
|
675
|
+
}
|
|
676
|
+
});
|
|
677
|
+
|
|
678
|
+
it("uses boxShadow without elevation on iOS", () => {
|
|
679
|
+
const PlatformModule = require("react-native").Platform;
|
|
680
|
+
const savedOS = PlatformModule.OS;
|
|
681
|
+
try {
|
|
682
|
+
PlatformModule.OS = "ios";
|
|
683
|
+
const {getByTestId} = renderWithTheme(
|
|
684
|
+
<WebDropdownMenu
|
|
685
|
+
anchor={anchor}
|
|
686
|
+
disableSearch
|
|
687
|
+
onClose={() => {}}
|
|
688
|
+
onSelect={() => {}}
|
|
689
|
+
options={options}
|
|
690
|
+
presentation="centered"
|
|
691
|
+
visible
|
|
692
|
+
/>
|
|
693
|
+
);
|
|
694
|
+
const menu = getByTestId("web_dropdown_menu");
|
|
695
|
+
const style = Array.isArray(menu.props.style)
|
|
696
|
+
? Object.assign({}, ...menu.props.style)
|
|
697
|
+
: menu.props.style;
|
|
698
|
+
expect(style.elevation).toBeUndefined();
|
|
699
|
+
expect(style.boxShadow).toBe("0px 4px 12px rgba(0, 0, 0, 0.25)");
|
|
700
|
+
} finally {
|
|
701
|
+
PlatformModule.OS = savedOS;
|
|
702
|
+
}
|
|
703
|
+
});
|
|
650
704
|
});
|
|
651
705
|
|
|
652
706
|
describe("useWebDropdownAnchor", () => {
|
package/src/WebDropdownMenu.tsx
CHANGED
|
@@ -15,6 +15,7 @@ import {
|
|
|
15
15
|
|
|
16
16
|
import {createWebPortal} from "./createWebPortal";
|
|
17
17
|
import {useTheme} from "./Theme";
|
|
18
|
+
import {createBoxShadow} from "./Utilities";
|
|
18
19
|
|
|
19
20
|
export const scheduleAfterPaint = (callback: () => void): void => {
|
|
20
21
|
if (typeof requestAnimationFrame === "function") {
|
|
@@ -244,31 +245,29 @@ export const WebDropdownMenu = ({
|
|
|
244
245
|
borderColor: theme.border.dark,
|
|
245
246
|
borderRadius: 4,
|
|
246
247
|
borderWidth: 1,
|
|
248
|
+
boxShadow: createBoxShadow({blurRadius: 8, offsetY: 2, opacity: 0.15}),
|
|
247
249
|
left: anchor.x,
|
|
248
250
|
maxHeight: clampedMaxHeight,
|
|
249
251
|
minWidth,
|
|
250
252
|
overflow: "hidden" as const,
|
|
251
|
-
shadowColor: "#000",
|
|
252
|
-
shadowOffset: {height: 2, width: 0},
|
|
253
|
-
shadowOpacity: 0.15,
|
|
254
|
-
shadowRadius: 8,
|
|
255
253
|
...(isOpenAbove ? {bottom: menuBottom} : {top: menuTop}),
|
|
256
254
|
width: width ?? anchor.width,
|
|
257
255
|
zIndex: 2,
|
|
258
256
|
};
|
|
259
257
|
|
|
258
|
+
// Centered presentation is the Android native-picker path. `boxShadow` and
|
|
259
|
+
// `elevation` both paint on Android, so keep elevation-only there — matching
|
|
260
|
+
// Box's `shadow` prop. iOS/web get `boxShadow`.
|
|
260
261
|
const centeredMenuLayoutStyle = {
|
|
261
262
|
backgroundColor: theme.surface.base,
|
|
262
263
|
borderRadius: 8,
|
|
263
|
-
elevation: 8,
|
|
264
264
|
maxHeight: clampedMaxHeight,
|
|
265
265
|
maxWidth: Math.min(400, windowWidth - 48),
|
|
266
266
|
overflow: "hidden" as const,
|
|
267
|
-
shadowColor: "#000",
|
|
268
|
-
shadowOffset: {height: 4, width: 0},
|
|
269
|
-
shadowOpacity: 0.25,
|
|
270
|
-
shadowRadius: 12,
|
|
271
267
|
width: Math.min(400, windowWidth - 48),
|
|
268
|
+
...(Platform.OS === "android"
|
|
269
|
+
? {elevation: 8}
|
|
270
|
+
: {boxShadow: createBoxShadow({blurRadius: 12, offsetY: 4, opacity: 0.25})}),
|
|
272
271
|
};
|
|
273
272
|
|
|
274
273
|
const menuLayoutStyle = isCenteredPresentation
|
|
@@ -410,6 +409,8 @@ export const WebDropdownMenu = ({
|
|
|
410
409
|
|
|
411
410
|
const webFixedOverlayStyle = {
|
|
412
411
|
inset: 0,
|
|
412
|
+
// box-none lets clicks pass to the backdrop / menu but not the empty overlay.
|
|
413
|
+
pointerEvents: "box-none",
|
|
413
414
|
position: "fixed",
|
|
414
415
|
zIndex: 9999,
|
|
415
416
|
} as unknown as ViewStyle;
|
|
@@ -426,7 +427,7 @@ export const WebDropdownMenu = ({
|
|
|
426
427
|
} as unknown as ViewStyle;
|
|
427
428
|
|
|
428
429
|
const overlay = (
|
|
429
|
-
<View
|
|
430
|
+
<View style={webFixedOverlayStyle}>
|
|
430
431
|
<Pressable
|
|
431
432
|
aria-role="button"
|
|
432
433
|
onPress={onClose}
|
|
@@ -2477,18 +2477,12 @@ exports[`AddressField renders correctly with default props 1`] = `
|
|
|
2477
2477
|
"borderColor": "#9A9A9A",
|
|
2478
2478
|
"borderRadius": 4,
|
|
2479
2479
|
"borderWidth": 1,
|
|
2480
|
+
"boxShadow": "0px 2px 8px rgba(0, 0, 0, 0.15)",
|
|
2480
2481
|
"left": 0,
|
|
2481
2482
|
"maxHeight": 300,
|
|
2482
2483
|
"minWidth": undefined,
|
|
2483
2484
|
"overflow": "hidden",
|
|
2484
2485
|
"position": "absolute",
|
|
2485
|
-
"shadowColor": "#000",
|
|
2486
|
-
"shadowOffset": {
|
|
2487
|
-
"height": 2,
|
|
2488
|
-
"width": 0,
|
|
2489
|
-
},
|
|
2490
|
-
"shadowOpacity": 0.15,
|
|
2491
|
-
"shadowRadius": 8,
|
|
2492
2486
|
"top": 4,
|
|
2493
2487
|
"width": 0,
|
|
2494
2488
|
"zIndex": 1,
|
|
@@ -324,18 +324,12 @@ exports[`CustomSelectField renders correctly with default props 1`] = `
|
|
|
324
324
|
"borderColor": "#9A9A9A",
|
|
325
325
|
"borderRadius": 4,
|
|
326
326
|
"borderWidth": 1,
|
|
327
|
+
"boxShadow": "0px 2px 8px rgba(0, 0, 0, 0.15)",
|
|
327
328
|
"left": 0,
|
|
328
329
|
"maxHeight": 300,
|
|
329
330
|
"minWidth": undefined,
|
|
330
331
|
"overflow": "hidden",
|
|
331
332
|
"position": "absolute",
|
|
332
|
-
"shadowColor": "#000",
|
|
333
|
-
"shadowOffset": {
|
|
334
|
-
"height": 2,
|
|
335
|
-
"width": 0,
|
|
336
|
-
},
|
|
337
|
-
"shadowOpacity": 0.15,
|
|
338
|
-
"shadowRadius": 8,
|
|
339
333
|
"top": 4,
|
|
340
334
|
"width": 0,
|
|
341
335
|
"zIndex": 1,
|
|
@@ -764,18 +758,12 @@ exports[`CustomSelectField renders with title 1`] = `
|
|
|
764
758
|
"borderColor": "#9A9A9A",
|
|
765
759
|
"borderRadius": 4,
|
|
766
760
|
"borderWidth": 1,
|
|
761
|
+
"boxShadow": "0px 2px 8px rgba(0, 0, 0, 0.15)",
|
|
767
762
|
"left": 0,
|
|
768
763
|
"maxHeight": 300,
|
|
769
764
|
"minWidth": undefined,
|
|
770
765
|
"overflow": "hidden",
|
|
771
766
|
"position": "absolute",
|
|
772
|
-
"shadowColor": "#000",
|
|
773
|
-
"shadowOffset": {
|
|
774
|
-
"height": 2,
|
|
775
|
-
"width": 0,
|
|
776
|
-
},
|
|
777
|
-
"shadowOpacity": 0.15,
|
|
778
|
-
"shadowRadius": 8,
|
|
779
767
|
"top": 4,
|
|
780
768
|
"width": 0,
|
|
781
769
|
"zIndex": 1,
|
|
@@ -1189,18 +1177,12 @@ exports[`CustomSelectField renders with placeholder 1`] = `
|
|
|
1189
1177
|
"borderColor": "#9A9A9A",
|
|
1190
1178
|
"borderRadius": 4,
|
|
1191
1179
|
"borderWidth": 1,
|
|
1180
|
+
"boxShadow": "0px 2px 8px rgba(0, 0, 0, 0.15)",
|
|
1192
1181
|
"left": 0,
|
|
1193
1182
|
"maxHeight": 300,
|
|
1194
1183
|
"minWidth": undefined,
|
|
1195
1184
|
"overflow": "hidden",
|
|
1196
1185
|
"position": "absolute",
|
|
1197
|
-
"shadowColor": "#000",
|
|
1198
|
-
"shadowOffset": {
|
|
1199
|
-
"height": 2,
|
|
1200
|
-
"width": 0,
|
|
1201
|
-
},
|
|
1202
|
-
"shadowOpacity": 0.15,
|
|
1203
|
-
"shadowRadius": 8,
|
|
1204
1186
|
"top": 4,
|
|
1205
1187
|
"width": 0,
|
|
1206
1188
|
"zIndex": 1,
|
|
@@ -1614,18 +1596,12 @@ exports[`CustomSelectField renders with selected value 1`] = `
|
|
|
1614
1596
|
"borderColor": "#9A9A9A",
|
|
1615
1597
|
"borderRadius": 4,
|
|
1616
1598
|
"borderWidth": 1,
|
|
1599
|
+
"boxShadow": "0px 2px 8px rgba(0, 0, 0, 0.15)",
|
|
1617
1600
|
"left": 0,
|
|
1618
1601
|
"maxHeight": 300,
|
|
1619
1602
|
"minWidth": undefined,
|
|
1620
1603
|
"overflow": "hidden",
|
|
1621
1604
|
"position": "absolute",
|
|
1622
|
-
"shadowColor": "#000",
|
|
1623
|
-
"shadowOffset": {
|
|
1624
|
-
"height": 2,
|
|
1625
|
-
"width": 0,
|
|
1626
|
-
},
|
|
1627
|
-
"shadowOpacity": 0.15,
|
|
1628
|
-
"shadowRadius": 8,
|
|
1629
1605
|
"top": 4,
|
|
1630
1606
|
"width": 0,
|
|
1631
1607
|
"zIndex": 1,
|
|
@@ -2039,18 +2015,12 @@ exports[`CustomSelectField renders with custom value (not in options) 1`] = `
|
|
|
2039
2015
|
"borderColor": "#9A9A9A",
|
|
2040
2016
|
"borderRadius": 4,
|
|
2041
2017
|
"borderWidth": 1,
|
|
2018
|
+
"boxShadow": "0px 2px 8px rgba(0, 0, 0, 0.15)",
|
|
2042
2019
|
"left": 0,
|
|
2043
2020
|
"maxHeight": 300,
|
|
2044
2021
|
"minWidth": undefined,
|
|
2045
2022
|
"overflow": "hidden",
|
|
2046
2023
|
"position": "absolute",
|
|
2047
|
-
"shadowColor": "#000",
|
|
2048
|
-
"shadowOffset": {
|
|
2049
|
-
"height": 2,
|
|
2050
|
-
"width": 0,
|
|
2051
|
-
},
|
|
2052
|
-
"shadowOpacity": 0.15,
|
|
2053
|
-
"shadowRadius": 8,
|
|
2054
2024
|
"top": 4,
|
|
2055
2025
|
"width": 0,
|
|
2056
2026
|
"zIndex": 1,
|
|
@@ -2568,18 +2538,12 @@ exports[`CustomSelectField renders disabled state 1`] = `
|
|
|
2568
2538
|
"borderColor": "#9A9A9A",
|
|
2569
2539
|
"borderRadius": 4,
|
|
2570
2540
|
"borderWidth": 1,
|
|
2541
|
+
"boxShadow": "0px 2px 8px rgba(0, 0, 0, 0.15)",
|
|
2571
2542
|
"left": 0,
|
|
2572
2543
|
"maxHeight": 300,
|
|
2573
2544
|
"minWidth": undefined,
|
|
2574
2545
|
"overflow": "hidden",
|
|
2575
2546
|
"position": "absolute",
|
|
2576
|
-
"shadowColor": "#000",
|
|
2577
|
-
"shadowOffset": {
|
|
2578
|
-
"height": 2,
|
|
2579
|
-
"width": 0,
|
|
2580
|
-
},
|
|
2581
|
-
"shadowOpacity": 0.15,
|
|
2582
|
-
"shadowRadius": 8,
|
|
2583
2547
|
"top": 4,
|
|
2584
2548
|
"width": 0,
|
|
2585
2549
|
"zIndex": 1,
|
|
@@ -2995,18 +2959,12 @@ exports[`CustomSelectField includes custom option in dropdown 1`] = `
|
|
|
2995
2959
|
"borderColor": "#9A9A9A",
|
|
2996
2960
|
"borderRadius": 4,
|
|
2997
2961
|
"borderWidth": 1,
|
|
2962
|
+
"boxShadow": "0px 2px 8px rgba(0, 0, 0, 0.15)",
|
|
2998
2963
|
"left": 0,
|
|
2999
2964
|
"maxHeight": 300,
|
|
3000
2965
|
"minWidth": undefined,
|
|
3001
2966
|
"overflow": "hidden",
|
|
3002
2967
|
"position": "absolute",
|
|
3003
|
-
"shadowColor": "#000",
|
|
3004
|
-
"shadowOffset": {
|
|
3005
|
-
"height": 2,
|
|
3006
|
-
"width": 0,
|
|
3007
|
-
},
|
|
3008
|
-
"shadowOpacity": 0.15,
|
|
3009
|
-
"shadowRadius": 8,
|
|
3010
2968
|
"top": 4,
|
|
3011
2969
|
"width": 0,
|
|
3012
2970
|
"zIndex": 1,
|