@jobber/components-native 0.114.13 → 0.114.14
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/package.json +2 -2
- package/dist/src/primitives/Select/SelectPrimitive.js +12 -2
- package/dist/src/primitives/Select/SelectPrimitive.style.js +6 -0
- package/dist/src/primitives/Select/SelectPrimitive.test.js +47 -4
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/src/primitives/Select/SelectPrimitive.d.ts +1 -1
- package/dist/types/src/primitives/Select/SelectPrimitive.style.d.ts +6 -0
- package/package.json +2 -2
- package/src/Select/Select.guide.md +6 -0
- package/src/primitives/Select/SelectPrimitive.style.ts +8 -0
- package/src/primitives/Select/SelectPrimitive.test.tsx +82 -2
- package/src/primitives/Select/SelectPrimitive.tsx +25 -2
package/dist/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jobber/components-native",
|
|
3
|
-
"version": "0.114.
|
|
3
|
+
"version": "0.114.14",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "React Native implementation of Atlantis",
|
|
6
6
|
"repository": {
|
|
@@ -123,5 +123,5 @@
|
|
|
123
123
|
"react-native-screens": ">=4.18.0",
|
|
124
124
|
"react-native-svg": ">=12.0.0"
|
|
125
125
|
},
|
|
126
|
-
"gitHead": "
|
|
126
|
+
"gitHead": "3fba9dd8675ceed40979c17792faf2d091ac2ce7"
|
|
127
127
|
}
|
|
@@ -15,8 +15,12 @@ import * as Primitive from "@rn-primitives/select";
|
|
|
15
15
|
import { SafeAreaInsetsContext } from "react-native-safe-area-context";
|
|
16
16
|
import { useStyles } from "./SelectPrimitive.style";
|
|
17
17
|
import { tokens as staticTokens } from "../../utils/design";
|
|
18
|
+
import { AtlantisThemeContextProvider, useAtlantisTheme, } from "../../AtlantisThemeContext";
|
|
18
19
|
/** Default trigger testID. Consumer-supplied `testID`s are used verbatim. */
|
|
19
20
|
export const SELECT_TRIGGER_DEFAULT_TEST_ID = "ATL-Select-Trigger";
|
|
21
|
+
function useIsDarkTheme() {
|
|
22
|
+
return useAtlantisTheme().effectiveTheme === "dark";
|
|
23
|
+
}
|
|
20
24
|
function SelectPrimitiveRoot(_a) {
|
|
21
25
|
var props = __rest(_a, []);
|
|
22
26
|
return React.createElement(Primitive.Root, Object.assign({}, props));
|
|
@@ -59,8 +63,10 @@ function SelectPrimitiveValue(_a) {
|
|
|
59
63
|
}
|
|
60
64
|
/** Portals the dropdown into the mounted `AtlantisPortalHost`. */
|
|
61
65
|
function SelectPrimitivePortal(_a) {
|
|
62
|
-
var props = __rest(_a, []);
|
|
63
|
-
|
|
66
|
+
var { children } = _a, props = __rest(_a, ["children"]);
|
|
67
|
+
const { effectiveTheme } = useAtlantisTheme();
|
|
68
|
+
return (React.createElement(Primitive.Portal, Object.assign({}, props),
|
|
69
|
+
React.createElement(AtlantisThemeContextProvider, { dangerouslyOverrideTheme: effectiveTheme }, children)));
|
|
64
70
|
}
|
|
65
71
|
/** Tap-outside dismiss surface behind the dropdown (no scrim). */
|
|
66
72
|
function SelectPrimitiveOverlay(_a) {
|
|
@@ -77,12 +83,14 @@ function SelectPrimitiveContent(_a) {
|
|
|
77
83
|
var _b;
|
|
78
84
|
var { children, style, sideOffset = staticTokens["space-smaller"], insets, ref } = _a, props = __rest(_a, ["children", "style", "sideOffset", "insets", "ref"]);
|
|
79
85
|
const styles = useStyles();
|
|
86
|
+
const isDarkTheme = useIsDarkTheme();
|
|
80
87
|
// Read the context directly, not `useSafeAreaInsets` (which throws without a
|
|
81
88
|
// provider): `Content` renders at the portal host, which may sit outside one.
|
|
82
89
|
const safeAreaInsets = (_b = React.useContext(SafeAreaInsetsContext)) !== null && _b !== void 0 ? _b : undefined;
|
|
83
90
|
const { triggerPosition } = Primitive.useRootContext();
|
|
84
91
|
return (React.createElement(Primitive.Content, Object.assign({ ref: ref, sideOffset: sideOffset, insets: insets !== null && insets !== void 0 ? insets : safeAreaInsets, style: StyleSheet.flatten([
|
|
85
92
|
styles.content,
|
|
93
|
+
isDarkTheme && styles.contentDarkElevated,
|
|
86
94
|
triggerPosition ? { width: triggerPosition.width } : undefined,
|
|
87
95
|
style,
|
|
88
96
|
]) }, props), children));
|
|
@@ -99,9 +107,11 @@ function SelectPrimitiveViewport(_a) {
|
|
|
99
107
|
function SelectPrimitiveItem(_a) {
|
|
100
108
|
var { style, disabled, ref } = _a, props = __rest(_a, ["style", "disabled", "ref"]);
|
|
101
109
|
const styles = useStyles();
|
|
110
|
+
const isDarkTheme = useIsDarkTheme();
|
|
102
111
|
return (React.createElement(Primitive.Item, Object.assign({ ref: ref, disabled: disabled, style: ({ pressed }) => [
|
|
103
112
|
styles.item,
|
|
104
113
|
pressed && styles.itemPressed,
|
|
114
|
+
pressed && isDarkTheme && styles.itemPressedDarkElevated,
|
|
105
115
|
style,
|
|
106
116
|
] }, props)));
|
|
107
117
|
}
|
|
@@ -73,6 +73,9 @@ export const useStyles = buildThemedStyles(tokens => {
|
|
|
73
73
|
left: 0,
|
|
74
74
|
},
|
|
75
75
|
content: Object.assign({ backgroundColor: tokens["color-surface"], borderWidth: tokens["border-base"], borderColor: tokens["color-border"], borderRadius: tokens["radius-base"], padding: tokens["space-small"] }, contentShadow),
|
|
76
|
+
contentDarkElevated: {
|
|
77
|
+
backgroundColor: tokens["color-surface--background--subtle"],
|
|
78
|
+
},
|
|
76
79
|
item: {
|
|
77
80
|
flexDirection: "row",
|
|
78
81
|
alignItems: "center",
|
|
@@ -84,6 +87,9 @@ export const useStyles = buildThemedStyles(tokens => {
|
|
|
84
87
|
itemPressed: {
|
|
85
88
|
backgroundColor: tokens["color-surface--hover"],
|
|
86
89
|
},
|
|
90
|
+
itemPressedDarkElevated: {
|
|
91
|
+
backgroundColor: tokens["color-surface--active"],
|
|
92
|
+
},
|
|
87
93
|
itemText: {
|
|
88
94
|
flex: 1,
|
|
89
95
|
color: tokens["color-text"],
|
|
@@ -9,10 +9,13 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
9
9
|
};
|
|
10
10
|
import React from "react";
|
|
11
11
|
import { render, screen, userEvent, within, } from "@testing-library/react-native";
|
|
12
|
+
import { darkTokens } from "@jobber/design";
|
|
13
|
+
import { PortalHost } from "@rn-primitives/portal";
|
|
12
14
|
import { SelectPrimitive } from "./SelectPrimitive";
|
|
13
15
|
import { tokens } from "../../utils/design";
|
|
14
16
|
import { PortalHostWrapper } from "../../utils/test";
|
|
15
17
|
import { Icon } from "../../Icon";
|
|
18
|
+
import { AtlantisThemeContextProvider } from "../../AtlantisThemeContext";
|
|
16
19
|
const user = userEvent.setup();
|
|
17
20
|
beforeAll(() => {
|
|
18
21
|
var _a;
|
|
@@ -98,21 +101,25 @@ const CITIES = [
|
|
|
98
101
|
{ value: "van", label: "Vancouver" },
|
|
99
102
|
{ value: "edm", label: "Edmonton" },
|
|
100
103
|
];
|
|
101
|
-
function renderSelectWithContent({ defaultValue, onValueChange, closeOnPress, disabledItem, } = {}) {
|
|
104
|
+
function renderSelectWithContent({ defaultValue, onValueChange, closeOnPress, disabledItem, pressedItem, theme, } = {}) {
|
|
105
|
+
const wrapper = theme === "dark"
|
|
106
|
+
? ({ children }) => (React.createElement(AtlantisThemeContextProvider, { dangerouslyOverrideTheme: "dark" },
|
|
107
|
+
React.createElement(PortalHostWrapper, null, children)))
|
|
108
|
+
: PortalHostWrapper;
|
|
102
109
|
return render(React.createElement(SelectPrimitive.Root, { defaultValue: defaultValue, onValueChange: onValueChange },
|
|
103
110
|
React.createElement(SelectPrimitive.Trigger, null,
|
|
104
111
|
React.createElement(SelectPrimitive.Value, { placeholder: "Select an option" })),
|
|
105
112
|
React.createElement(SelectPrimitive.Portal, null,
|
|
106
113
|
React.createElement(SelectPrimitive.Overlay, null),
|
|
107
|
-
React.createElement(SelectPrimitive.Content,
|
|
114
|
+
React.createElement(SelectPrimitive.Content, { testID: "ATL-Select-Content" },
|
|
108
115
|
React.createElement(SelectPrimitive.Viewport, null,
|
|
109
116
|
React.createElement(SelectPrimitive.Group, null,
|
|
110
117
|
React.createElement(SelectPrimitive.Label, null, "Cities"),
|
|
111
|
-
CITIES.map(city => (React.createElement(SelectPrimitive.Item, { key: city.value, value: city.value, label: city.label, closeOnPress: closeOnPress, disabled: disabledItem === city.value },
|
|
118
|
+
CITIES.map(city => (React.createElement(SelectPrimitive.Item, { key: city.value, value: city.value, label: city.label, closeOnPress: closeOnPress, disabled: disabledItem === city.value, testOnly_pressed: pressedItem === city.value, testID: `ATL-Select-Item-${city.value}` },
|
|
112
119
|
React.createElement(SelectPrimitive.ItemText, { disabled: disabledItem === city.value }),
|
|
113
120
|
React.createElement(SelectPrimitive.ItemIndicator, null,
|
|
114
121
|
React.createElement(Icon, { name: "checkmark" })))))),
|
|
115
|
-
React.createElement(SelectPrimitive.Separator, null))))), { wrapper
|
|
122
|
+
React.createElement(SelectPrimitive.Separator, null))))), { wrapper });
|
|
116
123
|
}
|
|
117
124
|
function openSelect() {
|
|
118
125
|
return __awaiter(this, void 0, void 0, function* () {
|
|
@@ -136,8 +143,22 @@ describe("SelectPrimitive.Content", () => {
|
|
|
136
143
|
expect(screen.queryByText("Toronto")).toBeNull();
|
|
137
144
|
expect(onValueChange).not.toHaveBeenCalled();
|
|
138
145
|
}));
|
|
146
|
+
it("uses the elevated dark surface style for content", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
147
|
+
renderSelectWithContent({ theme: "dark" });
|
|
148
|
+
yield openSelect();
|
|
149
|
+
expect(screen.getByTestId("ATL-Select-Content")).toHaveStyle({
|
|
150
|
+
backgroundColor: darkTokens["color-surface--background--subtle"],
|
|
151
|
+
});
|
|
152
|
+
}));
|
|
139
153
|
});
|
|
140
154
|
describe("SelectPrimitive.Item", () => {
|
|
155
|
+
it("uses the elevated dark surface active token when pressed", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
156
|
+
renderSelectWithContent({ theme: "dark", pressedItem: "tor" });
|
|
157
|
+
yield openSelect();
|
|
158
|
+
expect(screen.getByTestId("ATL-Select-Item-tor")).toHaveStyle({
|
|
159
|
+
backgroundColor: darkTokens["color-surface--active"],
|
|
160
|
+
});
|
|
161
|
+
}));
|
|
141
162
|
it("selects the option, emits { value, label }, and closes", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
142
163
|
const onValueChange = jest.fn();
|
|
143
164
|
renderSelectWithContent({ onValueChange });
|
|
@@ -217,6 +238,28 @@ describe("SelectPrimitive.Item", () => {
|
|
|
217
238
|
});
|
|
218
239
|
}));
|
|
219
240
|
});
|
|
241
|
+
describe("SelectPrimitive.Portal", () => {
|
|
242
|
+
it("preserves the selected theme when the portal host is outside the provider", () => __awaiter(void 0, void 0, void 0, function* () {
|
|
243
|
+
render(React.createElement(SelectPrimitive.Root, null,
|
|
244
|
+
React.createElement(SelectPrimitive.Trigger, null,
|
|
245
|
+
React.createElement(SelectPrimitive.Value, { placeholder: "Select an option" })),
|
|
246
|
+
React.createElement(SelectPrimitive.Portal, null,
|
|
247
|
+
React.createElement(SelectPrimitive.Content, { testID: "ATL-Select-Content" },
|
|
248
|
+
React.createElement(SelectPrimitive.Viewport, null,
|
|
249
|
+
React.createElement(SelectPrimitive.Item, { value: "tor", label: "Toronto", testID: "ATL-Select-Item-tor" },
|
|
250
|
+
React.createElement(SelectPrimitive.ItemText, null),
|
|
251
|
+
React.createElement(SelectPrimitive.ItemIndicator, null,
|
|
252
|
+
React.createElement(Icon, { name: "checkmark" }))))))), {
|
|
253
|
+
wrapper: ({ children }) => (React.createElement(React.Fragment, null,
|
|
254
|
+
React.createElement(AtlantisThemeContextProvider, { dangerouslyOverrideTheme: "dark" }, children),
|
|
255
|
+
React.createElement(PortalHost, null))),
|
|
256
|
+
});
|
|
257
|
+
yield openSelect();
|
|
258
|
+
expect(screen.getByTestId("ATL-Select-Content")).toHaveStyle({
|
|
259
|
+
backgroundColor: darkTokens["color-surface--background--subtle"],
|
|
260
|
+
});
|
|
261
|
+
}));
|
|
262
|
+
});
|
|
220
263
|
describe("SelectPrimitive.Value", () => {
|
|
221
264
|
it("shows the placeholder with subdued styling when nothing is selected", () => {
|
|
222
265
|
renderSelect();
|