@terreno/ui 56.0.0-beta.0 → 57.0.0-beta.1
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/LICENSE +21 -203
- package/dist/Badge.d.ts +1 -1
- package/dist/Badge.js +37 -1
- package/dist/Badge.js.map +1 -1
- package/dist/Common.d.ts +149 -3
- package/dist/Common.js.map +1 -1
- package/dist/DateTimeField.js +5 -21
- package/dist/DateTimeField.js.map +1 -1
- package/dist/EditableCard.d.ts +3 -0
- package/dist/EditableCard.js +23 -0
- package/dist/EditableCard.js.map +1 -0
- package/dist/Filter.d.ts +13 -0
- package/dist/Filter.js +120 -0
- package/dist/Filter.js.map +1 -0
- package/dist/FilterAccordion.d.ts +8 -0
- package/dist/FilterAccordion.js +59 -0
- package/dist/FilterAccordion.js.map +1 -0
- package/dist/FilterBoolean.d.ts +8 -0
- package/dist/FilterBoolean.js +74 -0
- package/dist/FilterBoolean.js.map +1 -0
- package/dist/FilterChangesBadge.d.ts +8 -0
- package/dist/FilterChangesBadge.js +11 -0
- package/dist/FilterChangesBadge.js.map +1 -0
- package/dist/FilterSelectMenu.d.ts +8 -0
- package/dist/FilterSelectMenu.js +37 -0
- package/dist/FilterSelectMenu.js.map +1 -0
- package/dist/IconRegistry.js +11 -6
- package/dist/IconRegistry.js.map +1 -1
- package/dist/Page.d.ts +2 -1
- package/dist/Page.js +0 -2
- package/dist/Page.js.map +1 -1
- package/dist/PickerSelect.d.ts +8 -1
- package/dist/PickerSelect.js +2 -2
- package/dist/PickerSelect.js.map +1 -1
- package/dist/SelectField.js +2 -2
- package/dist/SelectField.js.map +1 -1
- package/dist/Theme.js +3 -0
- package/dist/Theme.js.map +1 -1
- package/dist/WebDropdownMenu.d.ts +5 -1
- package/dist/WebDropdownMenu.js +24 -10
- package/dist/WebDropdownMenu.js.map +1 -1
- package/dist/icons/BarsFilterIcon.d.ts +9 -0
- package/dist/icons/BarsFilterIcon.js +12 -0
- package/dist/icons/BarsFilterIcon.js.map +1 -0
- package/dist/index.d.ts +7 -0
- package/dist/index.js +7 -0
- package/dist/index.js.map +1 -1
- package/package.json +26 -25
- package/src/ActionSheet.test.tsx +202 -172
- package/src/Badge.test.tsx +22 -1
- package/src/Badge.tsx +43 -0
- package/src/Box.test.tsx +31 -23
- package/src/Common.ts +167 -5
- package/src/ConsentFormScreen.test.tsx +22 -0
- package/src/ConsentNavigator.test.tsx +6 -8
- package/src/DateTimeField.test.tsx +66 -18
- package/src/DateTimeField.tsx +5 -19
- package/src/DraggableList.test.tsx +377 -0
- package/src/EditableCard.test.tsx +69 -0
- package/src/EditableCard.tsx +73 -0
- package/src/Filter.test.tsx +94 -0
- package/src/Filter.tsx +257 -0
- package/src/FilterAccordion.test.tsx +58 -0
- package/src/FilterAccordion.tsx +113 -0
- package/src/FilterBoolean.test.tsx +65 -0
- package/src/FilterBoolean.tsx +130 -0
- package/src/FilterChangesBadge.test.tsx +16 -0
- package/src/FilterChangesBadge.tsx +13 -0
- package/src/FilterSelectMenu.test.tsx +56 -0
- package/src/FilterSelectMenu.tsx +76 -0
- package/src/IconRegistry.test.tsx +6 -4
- package/src/IconRegistry.tsx +13 -8
- package/src/Page.tsx +2 -3
- package/src/PickerSelect.test.tsx +43 -12
- package/src/PickerSelect.tsx +10 -0
- package/src/SelectField.tsx +2 -0
- package/src/SidebarNavigation.test.tsx +339 -0
- package/src/Theme.tsx +3 -0
- package/src/WebDropdownMenu.test.tsx +214 -1
- package/src/WebDropdownMenu.tsx +43 -21
- package/src/__snapshots__/Card.test.tsx.snap +1 -0
- package/src/__snapshots__/EditableCard.test.tsx.snap +242 -0
- package/src/__snapshots__/Filter.test.tsx.snap +161 -0
- package/src/__snapshots__/FilterAccordion.test.tsx.snap +83 -0
- package/src/__snapshots__/FilterBoolean.test.tsx.snap +109 -0
- package/src/__snapshots__/FilterChangesBadge.test.tsx.snap +18 -0
- package/src/__snapshots__/FilterSelectMenu.test.tsx.snap +359 -0
- package/src/bunSetup.ts +6 -2
- package/src/conflictFieldDiff.test.ts +43 -0
- package/src/icons/BarsFilterIcon.tsx +18 -0
- package/src/index.tsx +7 -0
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
import {describe, expect, it, mock} from "bun:test";
|
|
2
|
+
import {fireEvent} from "@testing-library/react-native";
|
|
3
|
+
|
|
4
|
+
import {FilterBoolean} from "./FilterBoolean";
|
|
5
|
+
import {renderWithTheme} from "./test-utils";
|
|
6
|
+
|
|
7
|
+
describe("FilterBoolean", () => {
|
|
8
|
+
const defaultProps = {
|
|
9
|
+
onChange: () => {},
|
|
10
|
+
title: "Urgent only",
|
|
11
|
+
value: false,
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
it("renders correctly with default props", () => {
|
|
15
|
+
const {toJSON} = renderWithTheme(<FilterBoolean {...defaultProps} />);
|
|
16
|
+
expect(toJSON()).toMatchSnapshot();
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
it("renders the title", () => {
|
|
20
|
+
const {getByText} = renderWithTheme(<FilterBoolean {...defaultProps} />);
|
|
21
|
+
expect(getByText("Urgent only")).toBeTruthy();
|
|
22
|
+
});
|
|
23
|
+
|
|
24
|
+
it("toggles when the entire row is pressed", () => {
|
|
25
|
+
const onChange = mock();
|
|
26
|
+
const {getByTestId} = renderWithTheme(
|
|
27
|
+
<FilterBoolean {...defaultProps} onChange={onChange} testID="toggle" value={false} />
|
|
28
|
+
);
|
|
29
|
+
fireEvent.press(getByTestId("toggle"));
|
|
30
|
+
expect(onChange).toHaveBeenCalledWith(true);
|
|
31
|
+
});
|
|
32
|
+
|
|
33
|
+
it("does not toggle when disabled", () => {
|
|
34
|
+
const onChange = mock();
|
|
35
|
+
const {getByTestId} = renderWithTheme(
|
|
36
|
+
<FilterBoolean {...defaultProps} disabled onChange={onChange} testID="toggle" />
|
|
37
|
+
);
|
|
38
|
+
fireEvent.press(getByTestId("toggle"));
|
|
39
|
+
expect(onChange).not.toHaveBeenCalled();
|
|
40
|
+
});
|
|
41
|
+
|
|
42
|
+
it("exposes the checked state to assistive technology", () => {
|
|
43
|
+
const on = renderWithTheme(<FilterBoolean {...defaultProps} testID="toggle" value />);
|
|
44
|
+
expect(on.getByTestId("toggle")).toHaveProp("accessibilityState", {
|
|
45
|
+
checked: true,
|
|
46
|
+
disabled: false,
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
const off = renderWithTheme(<FilterBoolean {...defaultProps} testID="toggle" value={false} />);
|
|
50
|
+
expect(off.getByTestId("toggle")).toHaveProp("accessibilityState", {
|
|
51
|
+
checked: false,
|
|
52
|
+
disabled: false,
|
|
53
|
+
});
|
|
54
|
+
});
|
|
55
|
+
|
|
56
|
+
it("shows the changes badge only when enabled", () => {
|
|
57
|
+
const {queryByTestId, rerender} = renderWithTheme(
|
|
58
|
+
<FilterBoolean {...defaultProps} testID="toggle" />
|
|
59
|
+
);
|
|
60
|
+
expect(queryByTestId("toggle.badge")).toBeNull();
|
|
61
|
+
|
|
62
|
+
rerender(<FilterBoolean {...defaultProps} showChangesBadge testID="toggle" />);
|
|
63
|
+
expect(queryByTestId("toggle.badge")).toBeTruthy();
|
|
64
|
+
});
|
|
65
|
+
});
|
|
@@ -0,0 +1,130 @@
|
|
|
1
|
+
import {type FC, useState} from "react";
|
|
2
|
+
import {Pressable, View} from "react-native";
|
|
3
|
+
|
|
4
|
+
import type {FilterBooleanProps} from "./Common";
|
|
5
|
+
import {FilterChangesBadge} from "./FilterChangesBadge";
|
|
6
|
+
import {Text} from "./Text";
|
|
7
|
+
import {useTheme} from "./Theme";
|
|
8
|
+
import {resolveTestID} from "./testing/resolveTestId";
|
|
9
|
+
|
|
10
|
+
// react-native's Pressable does not type the web `onKeyDown` event, but React
|
|
11
|
+
// Native Web forwards it. A switch needs its own spacebar handler (per ARIA,
|
|
12
|
+
// Space toggles it) since role="switch" only activates on Enter on the web.
|
|
13
|
+
interface WebKeyDownEvent {
|
|
14
|
+
key: string;
|
|
15
|
+
preventDefault: () => void;
|
|
16
|
+
repeat?: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
interface WebKeyDownProps {
|
|
20
|
+
onKeyDown?: (event: WebKeyDownEvent) => void;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
const SWITCH_WIDTH = 36;
|
|
24
|
+
const SWITCH_HEIGHT = 20;
|
|
25
|
+
const KNOB_SIZE = 16;
|
|
26
|
+
|
|
27
|
+
/**
|
|
28
|
+
* A boolean filter row: a title on the left and a toggle switch on the right.
|
|
29
|
+
* The entire row is the click zone, matching the design spec. Hovering tints
|
|
30
|
+
* the row with the `surface-base-hover` token.
|
|
31
|
+
*/
|
|
32
|
+
export const FilterBoolean: FC<FilterBooleanProps> = ({
|
|
33
|
+
title,
|
|
34
|
+
value,
|
|
35
|
+
onChange,
|
|
36
|
+
showChangesBadge = false,
|
|
37
|
+
disabled = false,
|
|
38
|
+
focused = false,
|
|
39
|
+
testID,
|
|
40
|
+
}) => {
|
|
41
|
+
const {theme} = useTheme();
|
|
42
|
+
const [isHovered, setIsHovered] = useState(false);
|
|
43
|
+
|
|
44
|
+
const trackColor = disabled
|
|
45
|
+
? theme.surface.disabled
|
|
46
|
+
: value
|
|
47
|
+
? theme.surface.secondaryDark
|
|
48
|
+
: theme.surface.base;
|
|
49
|
+
const borderColor = focused
|
|
50
|
+
? theme.border.focus
|
|
51
|
+
: disabled
|
|
52
|
+
? theme.surface.disabled
|
|
53
|
+
: theme.surface.secondaryDark;
|
|
54
|
+
|
|
55
|
+
const handlePress = (): void => {
|
|
56
|
+
if (!disabled) {
|
|
57
|
+
onChange(!value);
|
|
58
|
+
}
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
const webKeyDownProps: WebKeyDownProps = {
|
|
62
|
+
onKeyDown: (event) => {
|
|
63
|
+
if (event.key !== " " && event.key !== "Spacebar") {
|
|
64
|
+
return;
|
|
65
|
+
}
|
|
66
|
+
event.preventDefault();
|
|
67
|
+
// A native switch activates once per press, so ignore held-key auto-repeat.
|
|
68
|
+
if (event.repeat) {
|
|
69
|
+
return;
|
|
70
|
+
}
|
|
71
|
+
handlePress();
|
|
72
|
+
},
|
|
73
|
+
};
|
|
74
|
+
|
|
75
|
+
return (
|
|
76
|
+
<Pressable
|
|
77
|
+
{...webKeyDownProps}
|
|
78
|
+
accessibilityRole="switch"
|
|
79
|
+
accessibilityState={{checked: value, disabled}}
|
|
80
|
+
aria-checked={value}
|
|
81
|
+
aria-disabled={disabled}
|
|
82
|
+
disabled={disabled}
|
|
83
|
+
onHoverIn={() => setIsHovered(true)}
|
|
84
|
+
onHoverOut={() => setIsHovered(false)}
|
|
85
|
+
onPress={handlePress}
|
|
86
|
+
style={{
|
|
87
|
+
alignItems: "center",
|
|
88
|
+
backgroundColor: isHovered && !disabled ? theme.surface.baseHover : theme.surface.base,
|
|
89
|
+
borderRadius: theme.radius.default,
|
|
90
|
+
flexDirection: "row",
|
|
91
|
+
justifyContent: "space-between",
|
|
92
|
+
paddingHorizontal: theme.spacing.sm,
|
|
93
|
+
paddingVertical: theme.primitives.spacing3,
|
|
94
|
+
}}
|
|
95
|
+
testID={testID}
|
|
96
|
+
>
|
|
97
|
+
<View style={{alignItems: "center", flexDirection: "row", gap: 6}}>
|
|
98
|
+
<Text size="md">{title}</Text>
|
|
99
|
+
{showChangesBadge && (
|
|
100
|
+
<FilterChangesBadge testID={testID ? resolveTestID(testID, "badge") : undefined} />
|
|
101
|
+
)}
|
|
102
|
+
</View>
|
|
103
|
+
<View
|
|
104
|
+
style={{
|
|
105
|
+
alignItems: value ? "flex-end" : "flex-start",
|
|
106
|
+
backgroundColor: trackColor,
|
|
107
|
+
borderColor,
|
|
108
|
+
borderRadius: SWITCH_HEIGHT,
|
|
109
|
+
borderWidth: focused ? 2 : 1,
|
|
110
|
+
height: SWITCH_HEIGHT,
|
|
111
|
+
justifyContent: "center",
|
|
112
|
+
paddingHorizontal: 1,
|
|
113
|
+
width: SWITCH_WIDTH,
|
|
114
|
+
}}
|
|
115
|
+
testID={testID ? resolveTestID(testID, "switch") : undefined}
|
|
116
|
+
>
|
|
117
|
+
<View
|
|
118
|
+
style={{
|
|
119
|
+
backgroundColor: theme.surface.base,
|
|
120
|
+
borderColor: disabled ? theme.surface.disabled : theme.surface.secondaryDark,
|
|
121
|
+
borderRadius: KNOB_SIZE / 2,
|
|
122
|
+
borderWidth: value ? 0 : 1,
|
|
123
|
+
height: KNOB_SIZE,
|
|
124
|
+
width: KNOB_SIZE,
|
|
125
|
+
}}
|
|
126
|
+
/>
|
|
127
|
+
</View>
|
|
128
|
+
</Pressable>
|
|
129
|
+
);
|
|
130
|
+
};
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import {describe, expect, it} from "bun:test";
|
|
2
|
+
|
|
3
|
+
import {FilterChangesBadge} from "./FilterChangesBadge";
|
|
4
|
+
import {renderWithTheme} from "./test-utils";
|
|
5
|
+
|
|
6
|
+
describe("FilterChangesBadge", () => {
|
|
7
|
+
it("renders correctly", () => {
|
|
8
|
+
const {toJSON} = renderWithTheme(<FilterChangesBadge />);
|
|
9
|
+
expect(toJSON()).toMatchSnapshot();
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it("renders with the primary surface color and dot dimensions", () => {
|
|
13
|
+
const {getByTestId} = renderWithTheme(<FilterChangesBadge testID="badge" />);
|
|
14
|
+
expect(getByTestId("badge")).toHaveStyle({height: 8, width: 8});
|
|
15
|
+
});
|
|
16
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
import type React from "react";
|
|
2
|
+
|
|
3
|
+
import {Badge} from "./Badge";
|
|
4
|
+
import type {FilterChangesBadgeProps} from "./Common";
|
|
5
|
+
|
|
6
|
+
/**
|
|
7
|
+
* Small blue dot rendered next to a filter control's title when its selection
|
|
8
|
+
* differs from the default. Implemented via the design system `Badge` using the
|
|
9
|
+
* `variant=status, status=active, color=bold` spec.
|
|
10
|
+
*/
|
|
11
|
+
export const FilterChangesBadge = ({testID}: FilterChangesBadgeProps): React.ReactElement => {
|
|
12
|
+
return <Badge color="bold" status="active" testID={testID} variant="status" />;
|
|
13
|
+
};
|
|
@@ -0,0 +1,56 @@
|
|
|
1
|
+
import {describe, expect, it, mock} from "bun:test";
|
|
2
|
+
import {assert} from "chai";
|
|
3
|
+
import {StyleSheet} from "react-native";
|
|
4
|
+
|
|
5
|
+
import {FilterSelectMenu} from "./FilterSelectMenu";
|
|
6
|
+
import {renderWithTheme} from "./test-utils";
|
|
7
|
+
|
|
8
|
+
const OPTIONS = [
|
|
9
|
+
{label: "All", value: "all"},
|
|
10
|
+
{label: "Today", value: "today"},
|
|
11
|
+
];
|
|
12
|
+
|
|
13
|
+
describe("FilterSelectMenu", () => {
|
|
14
|
+
const defaultProps = {
|
|
15
|
+
onChange: () => {},
|
|
16
|
+
options: OPTIONS,
|
|
17
|
+
title: "Due date",
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
it("renders correctly with default props", () => {
|
|
21
|
+
const {toJSON} = renderWithTheme(<FilterSelectMenu {...defaultProps} />);
|
|
22
|
+
expect(toJSON()).toMatchSnapshot();
|
|
23
|
+
});
|
|
24
|
+
|
|
25
|
+
it("renders the title", () => {
|
|
26
|
+
const {getByText} = renderWithTheme(<FilterSelectMenu {...defaultProps} />);
|
|
27
|
+
expect(getByText("Due date")).toBeTruthy();
|
|
28
|
+
});
|
|
29
|
+
|
|
30
|
+
it("shows the changes badge only when enabled", () => {
|
|
31
|
+
const {queryByTestId, rerender} = renderWithTheme(
|
|
32
|
+
<FilterSelectMenu {...defaultProps} testID="filter" />
|
|
33
|
+
);
|
|
34
|
+
expect(queryByTestId("filter.badge")).toBeNull();
|
|
35
|
+
|
|
36
|
+
rerender(<FilterSelectMenu {...defaultProps} showChangesBadge testID="filter" />);
|
|
37
|
+
expect(queryByTestId("filter.badge")).toBeTruthy();
|
|
38
|
+
});
|
|
39
|
+
|
|
40
|
+
it("renders the select control", () => {
|
|
41
|
+
const {getByTestId} = renderWithTheme(
|
|
42
|
+
<FilterSelectMenu {...defaultProps} onChange={mock()} testID="filter" value="all" />
|
|
43
|
+
);
|
|
44
|
+
expect(getByTestId("filter")).toBeTruthy();
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
it("clips the compact select control to its fixed width", () => {
|
|
48
|
+
const {getByTestId} = renderWithTheme(
|
|
49
|
+
<FilterSelectMenu {...defaultProps} testID="filter" value="all" />
|
|
50
|
+
);
|
|
51
|
+
const style = StyleSheet.flatten(getByTestId("filter.selectContainer").props.style);
|
|
52
|
+
|
|
53
|
+
assert.equal(style.width, 138);
|
|
54
|
+
assert.equal(style.overflow, "hidden");
|
|
55
|
+
});
|
|
56
|
+
});
|
|
@@ -0,0 +1,76 @@
|
|
|
1
|
+
import {type FC, useState} from "react";
|
|
2
|
+
import {Pressable, View} from "react-native";
|
|
3
|
+
|
|
4
|
+
import type {FilterSelectMenuProps} from "./Common";
|
|
5
|
+
import {FilterChangesBadge} from "./FilterChangesBadge";
|
|
6
|
+
import {SelectField} from "./SelectField";
|
|
7
|
+
import {Text} from "./Text";
|
|
8
|
+
import {useTheme} from "./Theme";
|
|
9
|
+
import {resolveTestID} from "./testing/resolveTestId";
|
|
10
|
+
|
|
11
|
+
const SELECT_WIDTH = 138;
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* A single-select filter row: a title on the left and a compact select control
|
|
15
|
+
* on the right. Only the select is the click zone. Hovering the select tints
|
|
16
|
+
* the row with the `surface-base-hover` token.
|
|
17
|
+
*/
|
|
18
|
+
export const FilterSelectMenu: FC<FilterSelectMenuProps> = ({
|
|
19
|
+
title,
|
|
20
|
+
options,
|
|
21
|
+
value,
|
|
22
|
+
onChange,
|
|
23
|
+
placeholder,
|
|
24
|
+
showChangesBadge = false,
|
|
25
|
+
disabled = false,
|
|
26
|
+
testID,
|
|
27
|
+
}) => {
|
|
28
|
+
const {theme} = useTheme();
|
|
29
|
+
const [isHovered, setIsHovered] = useState(false);
|
|
30
|
+
|
|
31
|
+
return (
|
|
32
|
+
<View
|
|
33
|
+
style={{
|
|
34
|
+
alignItems: "center",
|
|
35
|
+
backgroundColor: isHovered ? theme.surface.baseHover : theme.surface.base,
|
|
36
|
+
borderRadius: theme.radius.default,
|
|
37
|
+
flexDirection: "row",
|
|
38
|
+
gap: theme.spacing.sm,
|
|
39
|
+
paddingHorizontal: theme.spacing.sm,
|
|
40
|
+
paddingVertical: theme.primitives.spacing3,
|
|
41
|
+
}}
|
|
42
|
+
testID={testID}
|
|
43
|
+
>
|
|
44
|
+
<View style={{alignItems: "center", flex: 1, flexDirection: "row", gap: 6}}>
|
|
45
|
+
<Text size="md">{title}</Text>
|
|
46
|
+
{showChangesBadge && (
|
|
47
|
+
<FilterChangesBadge testID={testID ? resolveTestID(testID, "badge") : undefined} />
|
|
48
|
+
)}
|
|
49
|
+
</View>
|
|
50
|
+
<Pressable
|
|
51
|
+
onHoverIn={() => setIsHovered(true)}
|
|
52
|
+
onHoverOut={() => setIsHovered(false)}
|
|
53
|
+
style={{overflow: "hidden", width: SELECT_WIDTH}}
|
|
54
|
+
testID={testID ? resolveTestID(testID, "selectContainer") : undefined}
|
|
55
|
+
>
|
|
56
|
+
<SelectField
|
|
57
|
+
disabled={disabled}
|
|
58
|
+
// The compact filter select is fixed at SELECT_WIDTH. Search mode renders
|
|
59
|
+
// the trigger as an <input> whose intrinsic min-width exceeds that width,
|
|
60
|
+
// overflowing the row and pushing the chevron outside the control's border.
|
|
61
|
+
// Filter option lists are short, so a plain (non-search) dropdown is correct.
|
|
62
|
+
disableSearch
|
|
63
|
+
onChange={onChange}
|
|
64
|
+
options={options}
|
|
65
|
+
placeholder={placeholder}
|
|
66
|
+
// The Filter panel is a fixed portal on document.body (zIndex 9999).
|
|
67
|
+
// Render the menu in a matching body portal so it floats above the
|
|
68
|
+
// panel instead of a React Native Modal that would stack behind it.
|
|
69
|
+
renderMenuInBodyPortal
|
|
70
|
+
testID={testID ? resolveTestID(testID, "select") : undefined}
|
|
71
|
+
value={value}
|
|
72
|
+
/>
|
|
73
|
+
</Pressable>
|
|
74
|
+
</View>
|
|
75
|
+
);
|
|
76
|
+
};
|
|
@@ -86,25 +86,27 @@ describe("IconRegistry", () => {
|
|
|
86
86
|
).not.toThrow();
|
|
87
87
|
});
|
|
88
88
|
|
|
89
|
-
it("useIconRegistry
|
|
89
|
+
it("useIconRegistry merges consumer icons over the built-in icons", () => {
|
|
90
90
|
const wrapper = ({children}: {children: React.ReactNode}) => (
|
|
91
91
|
<ThemeProvider>
|
|
92
92
|
<IconRegistryProvider icons={ICONS}>{children}</IconRegistryProvider>
|
|
93
93
|
</ThemeProvider>
|
|
94
94
|
);
|
|
95
95
|
const {result} = renderHook(() => useIconRegistry(), {wrapper});
|
|
96
|
-
expect(result.current).toBe(ICONS);
|
|
97
96
|
expect(result.current.customStar).toBe(CustomStar);
|
|
97
|
+
// Built-in icons remain available alongside consumer icons.
|
|
98
|
+
expect(result.current["bars-filter"]).toBeDefined();
|
|
98
99
|
});
|
|
99
100
|
|
|
100
|
-
it("useIconRegistry
|
|
101
|
+
it("useIconRegistry exposes only the built-in icons when none are provided", () => {
|
|
101
102
|
const wrapper = ({children}: {children: React.ReactNode}) => (
|
|
102
103
|
<ThemeProvider>
|
|
103
104
|
<IconRegistryProvider>{children}</IconRegistryProvider>
|
|
104
105
|
</ThemeProvider>
|
|
105
106
|
);
|
|
106
107
|
const {result} = renderHook(() => useIconRegistry(), {wrapper});
|
|
107
|
-
expect(
|
|
108
|
+
expect(result.current["bars-filter"]).toBeDefined();
|
|
109
|
+
expect(result.current.customStar).toBeUndefined();
|
|
108
110
|
});
|
|
109
111
|
|
|
110
112
|
it("useCustomIcon resolves registered names and ignores everything else", () => {
|
package/src/IconRegistry.tsx
CHANGED
|
@@ -1,12 +1,17 @@
|
|
|
1
|
-
import {createContext, type FC, type ReactNode, useContext} from "react";
|
|
1
|
+
import {createContext, type FC, type ReactNode, useContext, useMemo} from "react";
|
|
2
2
|
|
|
3
3
|
import type {CustomIconComponent, IconName, IconRegistryMap} from "./Common";
|
|
4
|
+
import {BarsFilterIcon} from "./icons/BarsFilterIcon";
|
|
4
5
|
|
|
5
|
-
//
|
|
6
|
-
//
|
|
7
|
-
const
|
|
6
|
+
// Icons shipped with @terreno/ui and always available via `iconName`. Consumer
|
|
7
|
+
// icons passed to the provider override these on name collision.
|
|
8
|
+
const BUILT_IN_ICONS: IconRegistryMap = {
|
|
9
|
+
"bars-filter": ({color, size, testID}) => (
|
|
10
|
+
<BarsFilterIcon fill={color} height={size} testID={testID} width={size} />
|
|
11
|
+
),
|
|
12
|
+
};
|
|
8
13
|
|
|
9
|
-
const IconRegistryContext = createContext<IconRegistryMap>(
|
|
14
|
+
const IconRegistryContext = createContext<IconRegistryMap>(BUILT_IN_ICONS);
|
|
10
15
|
|
|
11
16
|
interface IconRegistryProviderProps {
|
|
12
17
|
/** Map of custom icon name to the component that renders it. */
|
|
@@ -15,10 +20,10 @@ interface IconRegistryProviderProps {
|
|
|
15
20
|
}
|
|
16
21
|
|
|
17
22
|
export const IconRegistryProvider: FC<IconRegistryProviderProps> = ({icons, children}) => {
|
|
23
|
+
// Built-in icons are always available; consumer icons override them by name.
|
|
24
|
+
const mergedIcons = useMemo(() => ({...BUILT_IN_ICONS, ...icons}), [icons]);
|
|
18
25
|
return (
|
|
19
|
-
<IconRegistryContext.Provider value={
|
|
20
|
-
{children}
|
|
21
|
-
</IconRegistryContext.Provider>
|
|
26
|
+
<IconRegistryContext.Provider value={mergedIcons}>{children}</IconRegistryContext.Provider>
|
|
22
27
|
);
|
|
23
28
|
};
|
|
24
29
|
|
package/src/Page.tsx
CHANGED
|
@@ -2,6 +2,7 @@ import {router} from "expo-router";
|
|
|
2
2
|
import React from "react";
|
|
3
3
|
import {SafeAreaView} from "react-native-safe-area-context";
|
|
4
4
|
|
|
5
|
+
import type {ActionSheet} from "./ActionSheet";
|
|
5
6
|
import {Box} from "./Box";
|
|
6
7
|
import {Button} from "./Button";
|
|
7
8
|
import type {PageProps} from "./Common";
|
|
@@ -12,9 +13,7 @@ import {Spinner} from "./Spinner";
|
|
|
12
13
|
import {Text} from "./Text";
|
|
13
14
|
|
|
14
15
|
export class Page extends React.Component<PageProps, {}> {
|
|
15
|
-
|
|
16
|
-
// biome-ignore lint/suspicious/noExplicitAny: ActionSheet class is defined in ActionSheet.tsx which imports from Common.ts indirectly; using its type here would create a circular dependency
|
|
17
|
-
actionSheetRef: React.RefObject<any> = React.createRef();
|
|
16
|
+
actionSheetRef: React.RefObject<ActionSheet | null> = React.createRef();
|
|
18
17
|
|
|
19
18
|
renderHeader() {
|
|
20
19
|
if (!this.props.title && !this.props.backButton) {
|
|
@@ -1,11 +1,22 @@
|
|
|
1
|
-
// noExplicitAny: test mock typing
|
|
2
|
-
// biome-ignore-all lint/suspicious/noExplicitAny: test mock typing
|
|
3
1
|
import {describe, expect, it, mock} from "bun:test";
|
|
4
2
|
import {act, fireEvent} from "@testing-library/react-native";
|
|
3
|
+
import {assert} from "chai";
|
|
5
4
|
import type {ReactTestInstance} from "react-test-renderer";
|
|
6
5
|
|
|
7
6
|
import {RNPickerSelect} from "./PickerSelect";
|
|
8
7
|
import {renderWithTheme} from "./test-utils";
|
|
8
|
+
import {WebDropdownMenu} from "./WebDropdownMenu";
|
|
9
|
+
|
|
10
|
+
/** Minimal element stub used to fake `document.activeElement` on web. */
|
|
11
|
+
interface MockElement {
|
|
12
|
+
blur: () => void;
|
|
13
|
+
}
|
|
14
|
+
|
|
15
|
+
/** Globals the web rendering tests stub out. */
|
|
16
|
+
const globalScope = globalThis as unknown as {
|
|
17
|
+
document?: unknown;
|
|
18
|
+
HTMLElement?: new () => MockElement;
|
|
19
|
+
};
|
|
9
20
|
|
|
10
21
|
// Note: @react-native-picker/picker is mocked globally in bunSetup.ts
|
|
11
22
|
|
|
@@ -166,22 +177,24 @@ describe("PickerSelect", () => {
|
|
|
166
177
|
|
|
167
178
|
describe("web rendering (Platform.OS === 'web')", () => {
|
|
168
179
|
const PlatformModule = require("react-native").Platform;
|
|
169
|
-
let savedOS:
|
|
180
|
+
let savedOS: unknown;
|
|
170
181
|
|
|
171
182
|
let hadDocument = false;
|
|
172
|
-
let savedDocument:
|
|
183
|
+
let savedDocument: unknown;
|
|
173
184
|
|
|
174
185
|
const searchEnabledWebProps = {...defaultProps, disableSearch: false};
|
|
175
186
|
|
|
176
187
|
const ensureDocument = () => {
|
|
177
188
|
hadDocument = "document" in globalThis;
|
|
178
|
-
savedDocument =
|
|
179
|
-
if (
|
|
180
|
-
|
|
189
|
+
savedDocument = globalScope.document;
|
|
190
|
+
if (globalScope.HTMLElement === undefined) {
|
|
191
|
+
globalScope.HTMLElement = class HTMLElement {
|
|
192
|
+
blur = (): void => {};
|
|
193
|
+
};
|
|
181
194
|
}
|
|
182
|
-
const el = new
|
|
195
|
+
const el = new globalScope.HTMLElement();
|
|
183
196
|
el.blur = () => {};
|
|
184
|
-
|
|
197
|
+
globalScope.document = {
|
|
185
198
|
activeElement: el,
|
|
186
199
|
addEventListener: () => {},
|
|
187
200
|
body: {
|
|
@@ -194,9 +207,9 @@ describe("PickerSelect", () => {
|
|
|
194
207
|
|
|
195
208
|
const restoreDocument = () => {
|
|
196
209
|
if (hadDocument) {
|
|
197
|
-
|
|
210
|
+
globalScope.document = savedDocument;
|
|
198
211
|
} else {
|
|
199
|
-
delete
|
|
212
|
+
delete globalScope.document;
|
|
200
213
|
}
|
|
201
214
|
};
|
|
202
215
|
|
|
@@ -221,6 +234,24 @@ describe("PickerSelect", () => {
|
|
|
221
234
|
}
|
|
222
235
|
});
|
|
223
236
|
|
|
237
|
+
it("requests body-portal rendering independently of trigger focus", () => {
|
|
238
|
+
ensureDocument();
|
|
239
|
+
savedOS = PlatformModule.OS;
|
|
240
|
+
try {
|
|
241
|
+
PlatformModule.OS = "web";
|
|
242
|
+
const {root} = renderWithTheme(
|
|
243
|
+
<RNPickerSelect {...defaultProps} renderMenuInBodyPortal value="2" />
|
|
244
|
+
);
|
|
245
|
+
const menu = root.findByType(WebDropdownMenu);
|
|
246
|
+
|
|
247
|
+
assert.isTrue(menu.props.renderInBodyPortal);
|
|
248
|
+
assert.isFalse(menu.props.keepTriggerFocus);
|
|
249
|
+
} finally {
|
|
250
|
+
PlatformModule.OS = savedOS;
|
|
251
|
+
restoreDocument();
|
|
252
|
+
}
|
|
253
|
+
});
|
|
254
|
+
|
|
224
255
|
it("renders web dropdown and opens on focus", async () => {
|
|
225
256
|
ensureDocument();
|
|
226
257
|
savedOS = PlatformModule.OS;
|
|
@@ -517,7 +548,7 @@ describe("PickerSelect", () => {
|
|
|
517
548
|
|
|
518
549
|
describe("android rendering", () => {
|
|
519
550
|
const PlatformModule = require("react-native").Platform;
|
|
520
|
-
let savedOS:
|
|
551
|
+
let savedOS: unknown;
|
|
521
552
|
|
|
522
553
|
it("renders android headless when useNativeAndroidPickerStyle is false", () => {
|
|
523
554
|
savedOS = PlatformModule.OS;
|
package/src/PickerSelect.tsx
CHANGED
|
@@ -133,6 +133,14 @@ export interface RNPickerSelectProps {
|
|
|
133
133
|
* @default false
|
|
134
134
|
*/
|
|
135
135
|
disableSearch?: boolean;
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Web only. When true, the dropdown menu renders in a fixed portal on
|
|
139
|
+
* `document.body` instead of a React Native `Modal`, so it floats above
|
|
140
|
+
* ancestor portals / high-zIndex overlays (e.g. the `Filter` panel).
|
|
141
|
+
* @default false
|
|
142
|
+
*/
|
|
143
|
+
renderMenuInBodyPortal?: boolean;
|
|
136
144
|
}
|
|
137
145
|
|
|
138
146
|
export const RNPickerSelect = ({
|
|
@@ -158,6 +166,7 @@ export const RNPickerSelect = ({
|
|
|
158
166
|
|
|
159
167
|
InputAccessoryView,
|
|
160
168
|
disableSearch = false,
|
|
169
|
+
renderMenuInBodyPortal = false,
|
|
161
170
|
}: RNPickerSelectProps) => {
|
|
162
171
|
const searchable = !disableSearch;
|
|
163
172
|
const [showPicker, setShowPicker] = useState<boolean>(false);
|
|
@@ -824,6 +833,7 @@ export const RNPickerSelect = ({
|
|
|
824
833
|
}}
|
|
825
834
|
options={menuOptions}
|
|
826
835
|
presentation={Platform.OS === "android" ? "centered" : "anchored"}
|
|
836
|
+
renderInBodyPortal={renderMenuInBodyPortal}
|
|
827
837
|
selectedIndex={menuSelectedIndex >= 0 ? menuSelectedIndex : undefined}
|
|
828
838
|
showEmptyStateWhenNoOptions={searchInTrigger && webSearchQuery.trim().length > 0}
|
|
829
839
|
testIDPrefix="web_dropdown"
|
package/src/SelectField.tsx
CHANGED
|
@@ -16,6 +16,7 @@ export const SelectField: FC<SelectFieldProps> = ({
|
|
|
16
16
|
requireValue = false,
|
|
17
17
|
placeholder = "Please select an option.",
|
|
18
18
|
disableSearch = false,
|
|
19
|
+
renderMenuInBodyPortal = false,
|
|
19
20
|
title,
|
|
20
21
|
value,
|
|
21
22
|
onChange,
|
|
@@ -42,6 +43,7 @@ export const SelectField: FC<SelectFieldProps> = ({
|
|
|
42
43
|
}
|
|
43
44
|
}}
|
|
44
45
|
placeholder={!requireValue ? clearOption : {}}
|
|
46
|
+
renderMenuInBodyPortal={renderMenuInBodyPortal}
|
|
45
47
|
textInputProps={{testID: fieldTestIDs.input}}
|
|
46
48
|
value={value ?? ""}
|
|
47
49
|
/>
|