@jobber/components-native 0.114.13 → 0.114.14-JOB-183884-72cd42b.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/package.json +2 -2
- package/dist/src/primitives/Select/SelectPrimitive.js +8 -0
- package/dist/src/primitives/Select/SelectPrimitive.style.js +6 -0
- package/dist/src/primitives/Select/SelectPrimitive.test.js +29 -5
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/src/primitives/Select/SelectPrimitive.style.d.ts +6 -0
- package/package.json +2 -2
- package/src/primitives/Select/SelectPrimitive.style.ts +8 -0
- package/src/primitives/Select/SelectPrimitive.test.tsx +43 -2
- package/src/primitives/Select/SelectPrimitive.tsx +9 -0
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-JOB-183884-72cd42b.0+72cd42b9",
|
|
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": "72cd42b9f0c6b6650ba1e3915876164919ba0155"
|
|
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 { 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));
|
|
@@ -77,12 +81,14 @@ function SelectPrimitiveContent(_a) {
|
|
|
77
81
|
var _b;
|
|
78
82
|
var { children, style, sideOffset = staticTokens["space-smaller"], insets, ref } = _a, props = __rest(_a, ["children", "style", "sideOffset", "insets", "ref"]);
|
|
79
83
|
const styles = useStyles();
|
|
84
|
+
const isDarkTheme = useIsDarkTheme();
|
|
80
85
|
// Read the context directly, not `useSafeAreaInsets` (which throws without a
|
|
81
86
|
// provider): `Content` renders at the portal host, which may sit outside one.
|
|
82
87
|
const safeAreaInsets = (_b = React.useContext(SafeAreaInsetsContext)) !== null && _b !== void 0 ? _b : undefined;
|
|
83
88
|
const { triggerPosition } = Primitive.useRootContext();
|
|
84
89
|
return (React.createElement(Primitive.Content, Object.assign({ ref: ref, sideOffset: sideOffset, insets: insets !== null && insets !== void 0 ? insets : safeAreaInsets, style: StyleSheet.flatten([
|
|
85
90
|
styles.content,
|
|
91
|
+
isDarkTheme && styles.contentDarkElevated,
|
|
86
92
|
triggerPosition ? { width: triggerPosition.width } : undefined,
|
|
87
93
|
style,
|
|
88
94
|
]) }, props), children));
|
|
@@ -99,9 +105,11 @@ function SelectPrimitiveViewport(_a) {
|
|
|
99
105
|
function SelectPrimitiveItem(_a) {
|
|
100
106
|
var { style, disabled, ref } = _a, props = __rest(_a, ["style", "disabled", "ref"]);
|
|
101
107
|
const styles = useStyles();
|
|
108
|
+
const isDarkTheme = useIsDarkTheme();
|
|
102
109
|
return (React.createElement(Primitive.Item, Object.assign({ ref: ref, disabled: disabled, style: ({ pressed }) => [
|
|
103
110
|
styles.item,
|
|
104
111
|
pressed && styles.itemPressed,
|
|
112
|
+
pressed && isDarkTheme && styles.itemPressedDarkElevated,
|
|
105
113
|
style,
|
|
106
114
|
] }, props)));
|
|
107
115
|
}
|
|
@@ -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"],
|
|
@@ -8,11 +8,14 @@ var __awaiter = (this && this.__awaiter) || function (thisArg, _arguments, P, ge
|
|
|
8
8
|
});
|
|
9
9
|
};
|
|
10
10
|
import React from "react";
|
|
11
|
-
import { render, screen, userEvent, within, } from "@testing-library/react-native";
|
|
11
|
+
import { render, renderHook, screen, userEvent, within, } from "@testing-library/react-native";
|
|
12
|
+
import { darkTokens } from "@jobber/design";
|
|
12
13
|
import { SelectPrimitive } from "./SelectPrimitive";
|
|
14
|
+
import { useStyles } from "./SelectPrimitive.style";
|
|
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, 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, 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,6 +143,23 @@ 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
|
+
}));
|
|
153
|
+
});
|
|
154
|
+
describe("SelectPrimitive styles", () => {
|
|
155
|
+
it("uses the elevated dark surface active token for pressed items", () => {
|
|
156
|
+
const { result } = renderHook(useStyles, {
|
|
157
|
+
wrapper: ({ children }) => (React.createElement(AtlantisThemeContextProvider, { dangerouslyOverrideTheme: "dark" }, children)),
|
|
158
|
+
});
|
|
159
|
+
expect(result.current.itemPressedDarkElevated).toMatchObject({
|
|
160
|
+
backgroundColor: darkTokens["color-surface--active"],
|
|
161
|
+
});
|
|
162
|
+
});
|
|
139
163
|
});
|
|
140
164
|
describe("SelectPrimitive.Item", () => {
|
|
141
165
|
it("selects the option, emits { value, label }, and closes", () => __awaiter(void 0, void 0, void 0, function* () {
|