@jobber/components-native 0.89.5-JOB-139254-4e3c64d.7 → 0.90.1-JOB-140976-20bb6ae.11
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/Form/Form.js +2 -2
- package/dist/src/Form/hooks/useInternalForm.js +2 -2
- package/dist/src/InputFieldWrapper/InputFieldWrapper.js +14 -12
- package/dist/src/InputFieldWrapper/components/Prefix/Prefix.js +5 -2
- package/dist/src/InputFieldWrapper/components/Suffix/Suffix.js +5 -2
- package/dist/src/InputPressable/InputPressable.js +20 -8
- package/dist/src/InputText/InputText.js +19 -11
- package/dist/tsconfig.build.tsbuildinfo +1 -1
- package/dist/types/src/Form/hooks/useInternalForm.d.ts +2 -2
- package/dist/types/src/Form/types.d.ts +1 -1
- package/dist/types/src/InputFieldWrapper/InputFieldWrapper.d.ts +9 -2
- package/dist/types/src/InputFieldWrapper/components/Prefix/Prefix.d.ts +2 -3
- package/dist/types/src/InputFieldWrapper/components/Suffix/Suffix.d.ts +2 -3
- package/dist/types/src/InputPressable/InputPressable.d.ts +9 -1
- package/dist/types/src/InputText/InputText.d.ts +8 -0
- package/package.json +2 -2
- package/src/Form/Form.test.tsx +143 -0
- package/src/Form/Form.tsx +2 -2
- package/src/Form/hooks/useInternalForm.ts +3 -3
- package/src/Form/types.ts +1 -1
- package/src/InputFieldWrapper/InputFieldWrapper.test.tsx +48 -1
- package/src/InputFieldWrapper/InputFieldWrapper.tsx +38 -28
- package/src/InputFieldWrapper/components/Prefix/Prefix.test.tsx +3 -5
- package/src/InputFieldWrapper/components/Prefix/Prefix.tsx +6 -4
- package/src/InputFieldWrapper/components/Suffix/Suffix.test.tsx +2 -4
- package/src/InputFieldWrapper/components/Suffix/Suffix.tsx +6 -4
- package/src/InputPressable/InputPressable.test.tsx +75 -1
- package/src/InputPressable/InputPressable.tsx +33 -7
- package/src/InputText/InputText.test.tsx +75 -0
- package/src/InputText/InputText.tsx +29 -12
|
@@ -10,7 +10,7 @@ const mockLabel = "$";
|
|
|
10
10
|
function setupLabel({
|
|
11
11
|
disabled = false,
|
|
12
12
|
focused = false,
|
|
13
|
-
|
|
13
|
+
miniLabelActive = false,
|
|
14
14
|
inputInvalid = false,
|
|
15
15
|
label = mockLabel,
|
|
16
16
|
styleOverride,
|
|
@@ -19,7 +19,7 @@ function setupLabel({
|
|
|
19
19
|
<SuffixLabel
|
|
20
20
|
disabled={disabled}
|
|
21
21
|
focused={focused}
|
|
22
|
-
|
|
22
|
+
miniLabelActive={miniLabelActive}
|
|
23
23
|
inputInvalid={inputInvalid}
|
|
24
24
|
label={label}
|
|
25
25
|
styleOverride={styleOverride}
|
|
@@ -30,7 +30,6 @@ function setupLabel({
|
|
|
30
30
|
function setupIcon({
|
|
31
31
|
disabled = false,
|
|
32
32
|
focused = false,
|
|
33
|
-
hasMiniLabel = false,
|
|
34
33
|
inputInvalid = false,
|
|
35
34
|
icon = "invoice",
|
|
36
35
|
}: Partial<SuffixIconProps>) {
|
|
@@ -38,7 +37,6 @@ function setupIcon({
|
|
|
38
37
|
<SuffixIcon
|
|
39
38
|
disabled={disabled}
|
|
40
39
|
focused={focused}
|
|
41
|
-
hasMiniLabel={hasMiniLabel}
|
|
42
40
|
inputInvalid={inputInvalid}
|
|
43
41
|
icon={icon}
|
|
44
42
|
/>,
|
|
@@ -11,7 +11,7 @@ import { useStyles } from "../../InputFieldWrapper.style";
|
|
|
11
11
|
export interface SuffixLabelProps {
|
|
12
12
|
readonly focused: boolean;
|
|
13
13
|
readonly disabled?: boolean;
|
|
14
|
-
readonly
|
|
14
|
+
readonly miniLabelActive: boolean;
|
|
15
15
|
readonly inputInvalid?: boolean;
|
|
16
16
|
readonly label: string;
|
|
17
17
|
readonly hasLeftMargin?: boolean;
|
|
@@ -24,7 +24,7 @@ export const suffixIconTestId = "ATL-InputFieldWrapper-SuffixIcon";
|
|
|
24
24
|
export function SuffixLabel({
|
|
25
25
|
focused,
|
|
26
26
|
disabled,
|
|
27
|
-
|
|
27
|
+
miniLabelActive,
|
|
28
28
|
inputInvalid,
|
|
29
29
|
label,
|
|
30
30
|
hasLeftMargin = true,
|
|
@@ -44,7 +44,10 @@ export function SuffixLabel({
|
|
|
44
44
|
]}
|
|
45
45
|
>
|
|
46
46
|
<View
|
|
47
|
-
style={[
|
|
47
|
+
style={[
|
|
48
|
+
styles.suffixLabel,
|
|
49
|
+
miniLabelActive && styles.fieldAffixMiniLabel,
|
|
50
|
+
]}
|
|
48
51
|
>
|
|
49
52
|
{!styleOverride ? (
|
|
50
53
|
<Text variation={disabled ? "disabled" : "base"}>{label}</Text>
|
|
@@ -70,7 +73,6 @@ export function SuffixLabel({
|
|
|
70
73
|
export interface SuffixIconProps {
|
|
71
74
|
readonly focused: boolean;
|
|
72
75
|
readonly disabled?: boolean;
|
|
73
|
-
readonly hasMiniLabel: boolean;
|
|
74
76
|
readonly inputInvalid?: boolean;
|
|
75
77
|
readonly icon: IconNames;
|
|
76
78
|
readonly hasLeftMargin?: boolean;
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from "react";
|
|
2
|
-
import { fireEvent, render } from "@testing-library/react-native";
|
|
2
|
+
import { fireEvent, render, screen } from "@testing-library/react-native";
|
|
3
3
|
import { InputPressable } from ".";
|
|
4
4
|
import type { InputFieldWrapperProps } from "../InputFieldWrapper";
|
|
5
5
|
|
|
@@ -120,6 +120,80 @@ describe("InputPressable", () => {
|
|
|
120
120
|
expect(getByText(value, { includeHiddenElements: true })).toBeDefined();
|
|
121
121
|
});
|
|
122
122
|
});
|
|
123
|
+
|
|
124
|
+
describe("showMiniLabel", () => {
|
|
125
|
+
it("defaults to true", () => {
|
|
126
|
+
const props = { placeholder: "placeholder", value: "value" };
|
|
127
|
+
render(<InputPressable {...props} />);
|
|
128
|
+
expect(
|
|
129
|
+
screen.getByText("placeholder", { includeHiddenElements: true }),
|
|
130
|
+
).toBeDefined();
|
|
131
|
+
expect(MockInputFieldWrapper).toHaveBeenCalledWith(
|
|
132
|
+
expect.objectContaining({
|
|
133
|
+
placeholderMode: "mini",
|
|
134
|
+
}),
|
|
135
|
+
);
|
|
136
|
+
});
|
|
137
|
+
|
|
138
|
+
describe("when true", () => {
|
|
139
|
+
it("renders the placeholder in its normal position when the input has no value", () => {
|
|
140
|
+
const props = { showMiniLabel: true, placeholder: "placeholder" };
|
|
141
|
+
render(<InputPressable {...props} />);
|
|
142
|
+
expect(
|
|
143
|
+
screen.getByText("placeholder", { includeHiddenElements: true }),
|
|
144
|
+
).toBeDefined();
|
|
145
|
+
expect(MockInputFieldWrapper).toHaveBeenCalledWith(
|
|
146
|
+
expect.objectContaining({
|
|
147
|
+
placeholderMode: "normal",
|
|
148
|
+
}),
|
|
149
|
+
);
|
|
150
|
+
});
|
|
151
|
+
|
|
152
|
+
it("renders the placeholder as a mini label when the input has a value", () => {
|
|
153
|
+
const props = {
|
|
154
|
+
showMiniLabel: true,
|
|
155
|
+
placeholder: "placeholder",
|
|
156
|
+
value: "value",
|
|
157
|
+
};
|
|
158
|
+
render(<InputPressable {...props} />);
|
|
159
|
+
expect(
|
|
160
|
+
screen.getByText("placeholder", { includeHiddenElements: true }),
|
|
161
|
+
).toBeDefined();
|
|
162
|
+
expect(MockInputFieldWrapper).toHaveBeenCalledWith(
|
|
163
|
+
expect.objectContaining({
|
|
164
|
+
placeholderMode: "mini",
|
|
165
|
+
}),
|
|
166
|
+
);
|
|
167
|
+
});
|
|
168
|
+
});
|
|
169
|
+
|
|
170
|
+
describe("when false", () => {
|
|
171
|
+
it("renders the placeholder in its normal position when the input has no value", () => {
|
|
172
|
+
const props = { showMiniLabel: false, placeholder: "placeholder" };
|
|
173
|
+
render(<InputPressable {...props} />);
|
|
174
|
+
expect(
|
|
175
|
+
screen.getByText("placeholder", { includeHiddenElements: true }),
|
|
176
|
+
).toBeDefined();
|
|
177
|
+
expect(MockInputFieldWrapper).toHaveBeenCalledWith(
|
|
178
|
+
expect.objectContaining({
|
|
179
|
+
placeholderMode: "normal",
|
|
180
|
+
}),
|
|
181
|
+
);
|
|
182
|
+
});
|
|
183
|
+
|
|
184
|
+
it("does not render the placeholder when the input has a value", () => {
|
|
185
|
+
const props = {
|
|
186
|
+
showMiniLabel: false,
|
|
187
|
+
placeholder: "placeholder",
|
|
188
|
+
value: "value",
|
|
189
|
+
};
|
|
190
|
+
render(<InputPressable {...props} />);
|
|
191
|
+
expect(
|
|
192
|
+
screen.queryByText("placeholder", { includeHiddenElements: true }),
|
|
193
|
+
).toBeNull();
|
|
194
|
+
});
|
|
195
|
+
});
|
|
196
|
+
});
|
|
123
197
|
});
|
|
124
198
|
|
|
125
199
|
describe("accessibilityLabel", () => {
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import type { Ref } from "react";
|
|
2
|
-
import React, { forwardRef
|
|
2
|
+
import React, { forwardRef } from "react";
|
|
3
3
|
import type { IconNames } from "@jobber/design";
|
|
4
4
|
import type { FieldError } from "react-hook-form";
|
|
5
5
|
import { Text as NativeText, Pressable } from "react-native";
|
|
@@ -7,6 +7,7 @@ import type { Clearable } from "@jobber/hooks";
|
|
|
7
7
|
import { useShowClear } from "@jobber/hooks";
|
|
8
8
|
import type { XOR } from "ts-xor";
|
|
9
9
|
import { useStyles } from "./InputPressable.style";
|
|
10
|
+
import type { InputFieldWrapperProps } from "../InputFieldWrapper";
|
|
10
11
|
import { InputFieldWrapper, useCommonInputStyles } from "../InputFieldWrapper";
|
|
11
12
|
|
|
12
13
|
interface BasicSuffix {
|
|
@@ -51,6 +52,15 @@ export interface InputPressableProps {
|
|
|
51
52
|
*/
|
|
52
53
|
readonly invalid?: boolean | string;
|
|
53
54
|
|
|
55
|
+
/**
|
|
56
|
+
* Controls the visibility of the mini label that appears inside the input
|
|
57
|
+
* when a value is entered. By default, the placeholder text moves up to
|
|
58
|
+
* become a mini label. Set to false to disable this behavior.
|
|
59
|
+
*
|
|
60
|
+
* @default true
|
|
61
|
+
*/
|
|
62
|
+
readonly showMiniLabel?: boolean;
|
|
63
|
+
|
|
54
64
|
/**
|
|
55
65
|
* Callback that is called when the text input is focused
|
|
56
66
|
* @param event
|
|
@@ -105,6 +115,7 @@ export function InputPressableInternal(
|
|
|
105
115
|
disabled,
|
|
106
116
|
invalid,
|
|
107
117
|
error,
|
|
118
|
+
showMiniLabel = true,
|
|
108
119
|
onPress,
|
|
109
120
|
accessibilityLabel,
|
|
110
121
|
accessibilityHint,
|
|
@@ -117,11 +128,9 @@ export function InputPressableInternal(
|
|
|
117
128
|
ref: Ref<InputPressableRef>,
|
|
118
129
|
): JSX.Element {
|
|
119
130
|
const hasValue = !!value;
|
|
120
|
-
const [hasMiniLabel, setHasMiniLabel] = useState(Boolean(value));
|
|
121
131
|
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
}, [value]);
|
|
132
|
+
const placeholderMode = getPlaceholderMode(showMiniLabel, value);
|
|
133
|
+
const miniLabelActive = placeholderMode === "mini";
|
|
125
134
|
|
|
126
135
|
const showClear = useShowClear({
|
|
127
136
|
clearable,
|
|
@@ -139,7 +148,7 @@ export function InputPressableInternal(
|
|
|
139
148
|
prefix={prefix}
|
|
140
149
|
suffix={suffix}
|
|
141
150
|
hasValue={hasValue}
|
|
142
|
-
|
|
151
|
+
placeholderMode={placeholderMode}
|
|
143
152
|
focused={focused}
|
|
144
153
|
error={error}
|
|
145
154
|
invalid={invalid}
|
|
@@ -160,7 +169,7 @@ export function InputPressableInternal(
|
|
|
160
169
|
style={[
|
|
161
170
|
commonInputStyles.input,
|
|
162
171
|
styles.inputPressableStyles,
|
|
163
|
-
!
|
|
172
|
+
!miniLabelActive && commonInputStyles.inputEmpty,
|
|
164
173
|
disabled && commonInputStyles.inputDisabled,
|
|
165
174
|
(Boolean(invalid) || error) && styles.inputInvalid,
|
|
166
175
|
]}
|
|
@@ -176,3 +185,20 @@ export function InputPressableInternal(
|
|
|
176
185
|
</InputFieldWrapper>
|
|
177
186
|
);
|
|
178
187
|
}
|
|
188
|
+
|
|
189
|
+
function getPlaceholderMode(
|
|
190
|
+
isMiniLabelAllowed: boolean,
|
|
191
|
+
internalValue: string | undefined,
|
|
192
|
+
): InputFieldWrapperProps["placeholderMode"] {
|
|
193
|
+
const hasValue = Boolean(internalValue);
|
|
194
|
+
|
|
195
|
+
if (hasValue) {
|
|
196
|
+
if (isMiniLabelAllowed) {
|
|
197
|
+
return "mini";
|
|
198
|
+
} else {
|
|
199
|
+
return "hidden";
|
|
200
|
+
}
|
|
201
|
+
} else {
|
|
202
|
+
return "normal";
|
|
203
|
+
}
|
|
204
|
+
}
|
|
@@ -4,6 +4,7 @@ import {
|
|
|
4
4
|
fireEvent,
|
|
5
5
|
render,
|
|
6
6
|
renderHook,
|
|
7
|
+
screen,
|
|
7
8
|
waitFor,
|
|
8
9
|
} from "@testing-library/react-native";
|
|
9
10
|
import type { TextStyle } from "react-native";
|
|
@@ -548,6 +549,80 @@ describe("InputText", () => {
|
|
|
548
549
|
expect(styleOverride.inputText.color).toEqual(flattenedStyle.color);
|
|
549
550
|
});
|
|
550
551
|
});
|
|
552
|
+
|
|
553
|
+
describe("showMiniLabel", () => {
|
|
554
|
+
it("defaults to true", () => {
|
|
555
|
+
const props = { placeholder: "placeholder", value: "value" };
|
|
556
|
+
renderInputText(props);
|
|
557
|
+
expect(
|
|
558
|
+
screen.getByText("placeholder", { includeHiddenElements: true }),
|
|
559
|
+
).toBeDefined();
|
|
560
|
+
expect(MockInputFieldWrapper).toHaveBeenCalledWith(
|
|
561
|
+
expect.objectContaining({
|
|
562
|
+
placeholderMode: "mini",
|
|
563
|
+
}),
|
|
564
|
+
);
|
|
565
|
+
});
|
|
566
|
+
|
|
567
|
+
describe("when true", () => {
|
|
568
|
+
it("renders the placeholder in its normal position when the input has no value", () => {
|
|
569
|
+
const props = { showMiniLabel: true, placeholder: "placeholder" };
|
|
570
|
+
renderInputText(props);
|
|
571
|
+
expect(
|
|
572
|
+
screen.getByText("placeholder", { includeHiddenElements: true }),
|
|
573
|
+
).toBeDefined();
|
|
574
|
+
expect(MockInputFieldWrapper).toHaveBeenCalledWith(
|
|
575
|
+
expect.objectContaining({
|
|
576
|
+
placeholderMode: "normal",
|
|
577
|
+
}),
|
|
578
|
+
);
|
|
579
|
+
});
|
|
580
|
+
|
|
581
|
+
it("renders the placeholder as a mini label when the input has a value", () => {
|
|
582
|
+
const props = {
|
|
583
|
+
showMiniLabel: true,
|
|
584
|
+
placeholder: "placeholder",
|
|
585
|
+
value: "value",
|
|
586
|
+
};
|
|
587
|
+
renderInputText(props);
|
|
588
|
+
expect(
|
|
589
|
+
screen.getByText("placeholder", { includeHiddenElements: true }),
|
|
590
|
+
).toBeDefined();
|
|
591
|
+
expect(MockInputFieldWrapper).toHaveBeenCalledWith(
|
|
592
|
+
expect.objectContaining({
|
|
593
|
+
placeholderMode: "mini",
|
|
594
|
+
}),
|
|
595
|
+
);
|
|
596
|
+
});
|
|
597
|
+
});
|
|
598
|
+
|
|
599
|
+
describe("when false", () => {
|
|
600
|
+
it("renders the placeholder in its normal position when the input has no value", () => {
|
|
601
|
+
const props = { showMiniLabel: false, placeholder: "placeholder" };
|
|
602
|
+
renderInputText(props);
|
|
603
|
+
expect(
|
|
604
|
+
screen.getByText("placeholder", { includeHiddenElements: true }),
|
|
605
|
+
).toBeDefined();
|
|
606
|
+
expect(MockInputFieldWrapper).toHaveBeenCalledWith(
|
|
607
|
+
expect.objectContaining({
|
|
608
|
+
placeholderMode: "normal",
|
|
609
|
+
}),
|
|
610
|
+
);
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
it("does not render the placeholder when the input has a value", () => {
|
|
614
|
+
const props = {
|
|
615
|
+
showMiniLabel: false,
|
|
616
|
+
placeholder: "placeholder",
|
|
617
|
+
value: "value",
|
|
618
|
+
};
|
|
619
|
+
renderInputText(props);
|
|
620
|
+
expect(
|
|
621
|
+
screen.queryByText("placeholder", { includeHiddenElements: true }),
|
|
622
|
+
).toBeNull();
|
|
623
|
+
});
|
|
624
|
+
});
|
|
625
|
+
});
|
|
551
626
|
});
|
|
552
627
|
|
|
553
628
|
describe("Transform", () => {
|
|
@@ -65,6 +65,15 @@ export interface InputTextProps
|
|
|
65
65
|
*/
|
|
66
66
|
readonly assistiveText?: string;
|
|
67
67
|
|
|
68
|
+
/**
|
|
69
|
+
* Controls the visibility of the mini label that appears inside the input
|
|
70
|
+
* when a value is entered. By default, the placeholder text moves up to
|
|
71
|
+
* become a mini label. Set to false to disable this behavior.
|
|
72
|
+
*
|
|
73
|
+
* @default true
|
|
74
|
+
*/
|
|
75
|
+
readonly showMiniLabel?: boolean;
|
|
76
|
+
|
|
68
77
|
/**
|
|
69
78
|
* Determines what keyboard is shown
|
|
70
79
|
*/
|
|
@@ -245,6 +254,7 @@ function InputTextInternal(
|
|
|
245
254
|
name,
|
|
246
255
|
placeholder,
|
|
247
256
|
assistiveText,
|
|
257
|
+
showMiniLabel = true,
|
|
248
258
|
keyboard,
|
|
249
259
|
value: controlledValue,
|
|
250
260
|
defaultValue,
|
|
@@ -292,7 +302,8 @@ function InputTextInternal(
|
|
|
292
302
|
|
|
293
303
|
const hasValue = internalValue !== "" && internalValue !== undefined;
|
|
294
304
|
const [focused, setFocused] = useState(false);
|
|
295
|
-
const
|
|
305
|
+
const placeholderMode = getPlaceholderMode(showMiniLabel, internalValue);
|
|
306
|
+
const miniLabelActive = placeholderMode === "mini";
|
|
296
307
|
|
|
297
308
|
const textInputRef = useTextInputRef({ ref, onClear: handleClear });
|
|
298
309
|
|
|
@@ -367,7 +378,7 @@ function InputTextInternal(
|
|
|
367
378
|
prefix={prefix}
|
|
368
379
|
suffix={suffix}
|
|
369
380
|
hasValue={hasValue}
|
|
370
|
-
|
|
381
|
+
placeholderMode={placeholderMode}
|
|
371
382
|
assistiveText={assistiveText}
|
|
372
383
|
focused={focused}
|
|
373
384
|
error={error}
|
|
@@ -391,11 +402,11 @@ function InputTextInternal(
|
|
|
391
402
|
style={[
|
|
392
403
|
commonInputStyles.input,
|
|
393
404
|
styles.inputPaddingTop,
|
|
394
|
-
!
|
|
405
|
+
!miniLabelActive && commonInputStyles.inputEmpty,
|
|
395
406
|
disabled && commonInputStyles.inputDisabled,
|
|
396
407
|
multiline && styles.multiLineInput,
|
|
397
408
|
multiline && Platform.OS === "ios" && styles.multilineInputiOS,
|
|
398
|
-
multiline &&
|
|
409
|
+
multiline && miniLabelActive && styles.multiLineInputWithMini,
|
|
399
410
|
styleOverride?.inputText,
|
|
400
411
|
loading && loadingType === "glimmer" && { color: "transparent" },
|
|
401
412
|
]}
|
|
@@ -510,13 +521,19 @@ function useTextInputRef({ ref, onClear }: UseTextInputRefProps) {
|
|
|
510
521
|
return textInputRef;
|
|
511
522
|
}
|
|
512
523
|
|
|
513
|
-
function
|
|
514
|
-
|
|
515
|
-
|
|
516
|
-
|
|
517
|
-
|
|
518
|
-
setHasMiniLabel(Boolean(internalValue));
|
|
519
|
-
}, [internalValue]);
|
|
524
|
+
function getPlaceholderMode(
|
|
525
|
+
isMiniLabelAllowed: boolean,
|
|
526
|
+
internalValue: string,
|
|
527
|
+
): InputFieldWrapperProps["placeholderMode"] {
|
|
528
|
+
const hasValue = Boolean(internalValue);
|
|
520
529
|
|
|
521
|
-
|
|
530
|
+
if (hasValue) {
|
|
531
|
+
if (isMiniLabelAllowed) {
|
|
532
|
+
return "mini";
|
|
533
|
+
} else {
|
|
534
|
+
return "hidden";
|
|
535
|
+
}
|
|
536
|
+
} else {
|
|
537
|
+
return "normal";
|
|
538
|
+
}
|
|
522
539
|
}
|