@jobber/components-native 0.116.0 → 0.116.2-large-chec-aaeb9fd.2
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/AutoLink/hooks/useTokenGenerator.js +1 -1
- package/dist/src/AutoLink/hooks/useTokenGenerator.test.js +24 -0
- package/dist/src/Select/SelectRoot.test.js +35 -1
- package/dist/src/Select/components/SelectTrigger.js +6 -3
- package/dist/src/Select/components/SelectTrigger.style.js +5 -0
- package/dist/src/hooks/useFormController.js +1 -1
- package/dist/src/hooks/useFormController.test.js +29 -0
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/src/AutoLink/hooks/useTokenGenerator.test.d.ts +1 -0
- package/dist/types/src/Select/components/SelectTrigger.style.d.ts +4 -0
- package/dist/types/src/hooks/useFormController.test.d.ts +1 -0
- package/package.json +2 -2
- package/src/AutoLink/hooks/useTokenGenerator.test.ts +28 -0
- package/src/AutoLink/hooks/useTokenGenerator.ts +1 -1
- package/src/Select/Select.guide.md +6 -0
- package/src/Select/SelectRoot.test.tsx +44 -1
- package/src/Select/components/SelectTrigger.style.ts +6 -0
- package/src/Select/components/SelectTrigger.tsx +14 -4
- package/src/hooks/useFormController.test.tsx +38 -0
- package/src/hooks/useFormController.ts +1 -1
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@jobber/components-native",
|
|
3
|
-
"version": "0.116.
|
|
3
|
+
"version": "0.116.2-large-chec-aaeb9fd.2+aaeb9fde",
|
|
4
4
|
"license": "MIT",
|
|
5
5
|
"description": "React Native implementation of Atlantis",
|
|
6
6
|
"repository": {
|
|
@@ -125,5 +125,5 @@
|
|
|
125
125
|
"react-native-screens": ">=4.18.0",
|
|
126
126
|
"react-native-svg": ">=12.0.0"
|
|
127
127
|
},
|
|
128
|
-
"gitHead": "
|
|
128
|
+
"gitHead": "aaeb9fdef9e69599b84e28de7ed82ed5ac7f26f7"
|
|
129
129
|
}
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { renderHook } from "@testing-library/react-native";
|
|
2
|
+
import uuid from "react-native-uuid";
|
|
3
|
+
import { useTokenGenerator } from "./useTokenGenerator";
|
|
4
|
+
|
|
5
|
+
describe("useTokenGenerator", () => {
|
|
6
|
+
it("generates tokens that its pattern matches", () => {
|
|
7
|
+
const { result } = renderHook(() => useTokenGenerator());
|
|
8
|
+
const [generateToken, tokenRegexp] = result.current;
|
|
9
|
+
|
|
10
|
+
const text = `${generateToken()} and ${generateToken()}`;
|
|
11
|
+
|
|
12
|
+
expect(text.match(tokenRegexp)).toHaveLength(2);
|
|
13
|
+
});
|
|
14
|
+
|
|
15
|
+
it("still renders late in a long session", () => {
|
|
16
|
+
// Exhaust react-native-uuid's argument-less v1() budget, which throws on
|
|
17
|
+
// its 10,000th call in a JS session.
|
|
18
|
+
for (let i = 0; i < 10_000; i++) {
|
|
19
|
+
try {
|
|
20
|
+
uuid.v1();
|
|
21
|
+
} catch {
|
|
22
|
+
break;
|
|
23
|
+
}
|
|
24
|
+
}
|
|
25
|
+
|
|
26
|
+
expect(() => renderHook(() => useTokenGenerator())).not.toThrow();
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -3,7 +3,7 @@ import uuid from "react-native-uuid";
|
|
|
3
3
|
|
|
4
4
|
export function useTokenGenerator(): [() => string, RegExp] {
|
|
5
5
|
let counter = 0;
|
|
6
|
-
const [identifier] = useState(uuid.
|
|
6
|
+
const [identifier] = useState(() => uuid.v4());
|
|
7
7
|
|
|
8
8
|
return [
|
|
9
9
|
() => `@__ELEMENT-${identifier}-${counter++}__@`,
|
|
@@ -104,6 +104,12 @@ A few decisions shape how the composable parts fit together:
|
|
|
104
104
|
`Select.Trigger` renders it in the inside slot. So the part's JSX position is
|
|
105
105
|
irrelevant; only `labelPlacement` matters.
|
|
106
106
|
|
|
107
|
+
- **Only an actual inside label uses the stacked layout.** With no composed
|
|
108
|
+
label, or with `labelPlacement="above"`, the trigger centers its value or
|
|
109
|
+
placeholder vertically alongside the chevron. Its content uses a row so the
|
|
110
|
+
primitive Value's `flex: 1` fills width rather than stretching the text box
|
|
111
|
+
vertically. The inside-label inset only applies when label content exists.
|
|
112
|
+
|
|
107
113
|
- **Accessibility names the trigger directly.** The accessible name is applied
|
|
108
114
|
as the trigger's `accessibilityLabel` — not via the rn-primitives `Label` / a
|
|
109
115
|
`nativeID`+`accessibilityLabelledBy` association (unsupported on iOS). It is
|
|
@@ -1,11 +1,12 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
+
import { Pressable, StyleSheet } from "react-native";
|
|
3
|
+
import type { ReactTestInstance } from "react-test-renderer";
|
|
2
4
|
import {
|
|
3
5
|
fireEvent,
|
|
4
6
|
render,
|
|
5
7
|
screen,
|
|
6
8
|
within,
|
|
7
9
|
} from "@testing-library/react-native";
|
|
8
|
-
import { Pressable } from "react-native";
|
|
9
10
|
import type { TriggerRef } from "@rn-primitives/select";
|
|
10
11
|
import { SelectRoot } from "./SelectRoot";
|
|
11
12
|
import { SelectTrigger } from "./components/SelectTrigger";
|
|
@@ -190,11 +191,53 @@ describe("SelectRoot label placement", () => {
|
|
|
190
191
|
);
|
|
191
192
|
}
|
|
192
193
|
|
|
194
|
+
function getTriggerContent() {
|
|
195
|
+
const trigger = screen.getByTestId("ATL-Select-Trigger");
|
|
196
|
+
const content = trigger.children[0] as ReactTestInstance;
|
|
197
|
+
|
|
198
|
+
// Unwrap the mocked View to return its native host element.
|
|
199
|
+
return content.children[0] as ReactTestInstance;
|
|
200
|
+
}
|
|
201
|
+
|
|
202
|
+
it.each([
|
|
203
|
+
{ labelPlacement: "inside" as const },
|
|
204
|
+
{ labelPlacement: "above" as const },
|
|
205
|
+
{ readOnly: true },
|
|
206
|
+
{ disabled: true },
|
|
207
|
+
])("centers a value without an inside label (%j)", props => {
|
|
208
|
+
renderRoot({
|
|
209
|
+
...props,
|
|
210
|
+
defaultValue: { value: "tor", label: "Toronto" },
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
const content = getTriggerContent();
|
|
214
|
+
expect(content).toHaveStyle({
|
|
215
|
+
flexDirection: "row",
|
|
216
|
+
alignItems: "center",
|
|
217
|
+
});
|
|
218
|
+
expect(StyleSheet.flatten(content.props.style).paddingTop ?? 0).toBe(0);
|
|
219
|
+
});
|
|
220
|
+
|
|
221
|
+
it("centers the placeholder when the composed label is above the trigger", () => {
|
|
222
|
+
renderComposed({ labelPlacement: "above" });
|
|
223
|
+
|
|
224
|
+
expect(getTriggerContent()).toHaveStyle({
|
|
225
|
+
flexDirection: "row",
|
|
226
|
+
alignItems: "center",
|
|
227
|
+
});
|
|
228
|
+
});
|
|
229
|
+
|
|
193
230
|
it("places the label inside the trigger by default (labelPlacement inside)", () => {
|
|
194
231
|
renderComposed();
|
|
195
232
|
|
|
196
233
|
const trigger = screen.getByTestId("ATL-Select-Trigger");
|
|
197
234
|
expect(within(trigger).getByText("City", hidden)).toBeDefined();
|
|
235
|
+
expect(getTriggerContent()).toHaveStyle({
|
|
236
|
+
paddingTop: tokens["space-small"] - tokens["space-smallest"],
|
|
237
|
+
});
|
|
238
|
+
expect(getTriggerContent()).not.toHaveStyle({
|
|
239
|
+
flexDirection: "row",
|
|
240
|
+
});
|
|
198
241
|
});
|
|
199
242
|
|
|
200
243
|
it("places the label above the trigger with labelPlacement='above'", () => {
|
|
@@ -6,6 +6,12 @@ export const useStyles = buildThemedStyles(tokens => ({
|
|
|
6
6
|
justifyContent: "center",
|
|
7
7
|
},
|
|
8
8
|
|
|
9
|
+
// Keep the Value's flex horizontal when there is no label to stack above it.
|
|
10
|
+
contentWithoutLabel: {
|
|
11
|
+
flexDirection: "row",
|
|
12
|
+
alignItems: "center",
|
|
13
|
+
},
|
|
14
|
+
|
|
9
15
|
// Inside-label placement: the Value's flex fills the column vertically and
|
|
10
16
|
// would otherwise pin the label flush to the top. This top inset gives the
|
|
11
17
|
// label the same breathing room as the shared input chrome's mini-label.
|
|
@@ -35,18 +35,28 @@ export function SelectTrigger({
|
|
|
35
35
|
ref,
|
|
36
36
|
}: SelectTriggerProps): ReactElement {
|
|
37
37
|
const styles = useStyles();
|
|
38
|
-
const {
|
|
39
|
-
|
|
38
|
+
const {
|
|
39
|
+
invalid,
|
|
40
|
+
readOnly,
|
|
41
|
+
accessibilityLabel,
|
|
42
|
+
labelPlacement,
|
|
43
|
+
labelContent,
|
|
44
|
+
} = useSelectFieldState();
|
|
40
45
|
const { open, value, disabled } = useRootContext();
|
|
41
46
|
|
|
42
47
|
const isDisabled = disabled ?? false;
|
|
43
48
|
// `disabled` wins over `readOnly`.
|
|
44
49
|
const isReadOnly = !isDisabled && (readOnly ?? false);
|
|
45
50
|
|
|
46
|
-
const isInsideLabel = labelPlacement === "inside";
|
|
51
|
+
const isInsideLabel = labelPlacement === "inside" && labelContent != null;
|
|
47
52
|
|
|
48
53
|
const content = (
|
|
49
|
-
<View
|
|
54
|
+
<View
|
|
55
|
+
style={[
|
|
56
|
+
styles.content,
|
|
57
|
+
isInsideLabel ? styles.contentInside : styles.contentWithoutLabel,
|
|
58
|
+
]}
|
|
59
|
+
>
|
|
50
60
|
{isInsideLabel && <FieldLabel />}
|
|
51
61
|
{children}
|
|
52
62
|
</View>
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { renderHook } from "@testing-library/react-native";
|
|
2
|
+
import uuid from "react-native-uuid";
|
|
3
|
+
import { useFormController } from "./useFormController";
|
|
4
|
+
|
|
5
|
+
// react-native-uuid's v1() only resets its counter when given options, so its
|
|
6
|
+
// 10,000th argument-less call in a JS session throws. Exhaust it the way a long
|
|
7
|
+
// session with large forms does.
|
|
8
|
+
function exhaustUuidV1Budget() {
|
|
9
|
+
for (let i = 0; i < 10_000; i++) {
|
|
10
|
+
try {
|
|
11
|
+
uuid.v1();
|
|
12
|
+
} catch {
|
|
13
|
+
return;
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
describe("useFormController", () => {
|
|
19
|
+
it("keeps the generated field name stable across re-renders", () => {
|
|
20
|
+
const { result, rerender } = renderHook(() =>
|
|
21
|
+
useFormController({ value: "" }),
|
|
22
|
+
);
|
|
23
|
+
const initialName = result.current.field.name;
|
|
24
|
+
|
|
25
|
+
rerender({});
|
|
26
|
+
|
|
27
|
+
expect(initialName).toMatch(/^generatedName--/);
|
|
28
|
+
expect(result.current.field.name).toBe(initialName);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it("still renders unnamed fields late in a long session", () => {
|
|
32
|
+
exhaustUuidV1Budget();
|
|
33
|
+
|
|
34
|
+
expect(() =>
|
|
35
|
+
renderHook(() => useFormController({ value: "" })),
|
|
36
|
+
).not.toThrow();
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -54,7 +54,7 @@ export function useFormController<T>({
|
|
|
54
54
|
}
|
|
55
55
|
|
|
56
56
|
function useControlName(name?: string): UseControllerReturn["field"]["name"] {
|
|
57
|
-
const [identifier] = useState(uuid.
|
|
57
|
+
const [identifier] = useState(() => uuid.v4());
|
|
58
58
|
const prefix = `generatedName--${identifier}`;
|
|
59
59
|
|
|
60
60
|
return `${name || prefix}` as const;
|