@jobber/components-native 0.90.1-JOB-140976-fc0b992.18 → 0.90.1-JOB-142149-547612b.8

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.
Files changed (41) hide show
  1. package/dist/package.json +2 -2
  2. package/dist/src/Form/Form.js +1 -1
  3. package/dist/src/Form/components/FormBody/FormBody.js +5 -5
  4. package/dist/src/InputDate/InputDate.js +2 -2
  5. package/dist/src/InputFieldWrapper/InputFieldWrapper.js +12 -14
  6. package/dist/src/InputFieldWrapper/components/Prefix/Prefix.js +2 -5
  7. package/dist/src/InputFieldWrapper/components/Suffix/Suffix.js +2 -5
  8. package/dist/src/InputPressable/InputPressable.js +8 -20
  9. package/dist/src/InputPressable/InputPressable.style.js +0 -3
  10. package/dist/src/InputText/InputText.js +11 -22
  11. package/dist/src/InputText/InputText.style.js +0 -4
  12. package/dist/src/InputTime/InputTime.js +2 -2
  13. package/dist/tsconfig.build.tsbuildinfo +1 -1
  14. package/dist/types/src/InputDate/InputDate.d.ts +1 -2
  15. package/dist/types/src/InputFieldWrapper/InputFieldWrapper.d.ts +2 -9
  16. package/dist/types/src/InputFieldWrapper/components/Prefix/Prefix.d.ts +3 -2
  17. package/dist/types/src/InputFieldWrapper/components/Suffix/Suffix.d.ts +3 -2
  18. package/dist/types/src/InputPressable/InputPressable.d.ts +1 -9
  19. package/dist/types/src/InputPressable/InputPressable.style.d.ts +0 -3
  20. package/dist/types/src/InputSearch/InputSearch.d.ts +1 -1
  21. package/dist/types/src/InputText/InputText.d.ts +0 -8
  22. package/dist/types/src/InputText/InputText.style.d.ts +0 -4
  23. package/dist/types/src/InputTime/InputTime.d.ts +1 -2
  24. package/package.json +2 -2
  25. package/src/Form/Form.tsx +0 -1
  26. package/src/Form/components/FormBody/FormBody.tsx +6 -6
  27. package/src/InputDate/InputDate.tsx +1 -5
  28. package/src/InputFieldWrapper/InputFieldWrapper.test.tsx +1 -48
  29. package/src/InputFieldWrapper/InputFieldWrapper.tsx +28 -38
  30. package/src/InputFieldWrapper/components/Prefix/Prefix.test.tsx +5 -3
  31. package/src/InputFieldWrapper/components/Prefix/Prefix.tsx +4 -6
  32. package/src/InputFieldWrapper/components/Suffix/Suffix.test.tsx +4 -2
  33. package/src/InputFieldWrapper/components/Suffix/Suffix.tsx +4 -6
  34. package/src/InputPressable/InputPressable.style.ts +0 -4
  35. package/src/InputPressable/InputPressable.test.tsx +1 -75
  36. package/src/InputPressable/InputPressable.tsx +7 -33
  37. package/src/InputSearch/InputSearch.tsx +0 -1
  38. package/src/InputText/InputText.style.ts +0 -5
  39. package/src/InputText/InputText.test.tsx +0 -75
  40. package/src/InputText/InputText.tsx +12 -32
  41. package/src/InputTime/InputTime.tsx +1 -5
@@ -1,5 +1,5 @@
1
1
  import React from "react";
2
- import { fireEvent, render, screen } from "@testing-library/react-native";
2
+ import { fireEvent, render } from "@testing-library/react-native";
3
3
  import { InputPressable } from ".";
4
4
  import type { InputFieldWrapperProps } from "../InputFieldWrapper";
5
5
 
@@ -120,80 +120,6 @@ 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
- });
197
123
  });
198
124
 
199
125
  describe("accessibilityLabel", () => {
@@ -1,5 +1,5 @@
1
1
  import type { Ref } from "react";
2
- import React, { forwardRef } from "react";
2
+ import React, { forwardRef, useEffect, useState } 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,7 +7,6 @@ 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";
11
10
  import { InputFieldWrapper, useCommonInputStyles } from "../InputFieldWrapper";
12
11
 
13
12
  interface BasicSuffix {
@@ -52,15 +51,6 @@ export interface InputPressableProps {
52
51
  */
53
52
  readonly invalid?: boolean | string;
54
53
 
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
-
64
54
  /**
65
55
  * Callback that is called when the text input is focused
66
56
  * @param event
@@ -115,7 +105,6 @@ export function InputPressableInternal(
115
105
  disabled,
116
106
  invalid,
117
107
  error,
118
- showMiniLabel = true,
119
108
  onPress,
120
109
  accessibilityLabel,
121
110
  accessibilityHint,
@@ -128,8 +117,11 @@ export function InputPressableInternal(
128
117
  ref: Ref<InputPressableRef>,
129
118
  ): JSX.Element {
130
119
  const hasValue = !!value;
120
+ const [hasMiniLabel, setHasMiniLabel] = useState(Boolean(value));
131
121
 
132
- const placeholderMode = getPlaceholderMode(showMiniLabel, value);
122
+ useEffect(() => {
123
+ setHasMiniLabel(Boolean(value));
124
+ }, [value]);
133
125
 
134
126
  const showClear = useShowClear({
135
127
  clearable,
@@ -147,7 +139,7 @@ export function InputPressableInternal(
147
139
  prefix={prefix}
148
140
  suffix={suffix}
149
141
  hasValue={hasValue}
150
- placeholderMode={placeholderMode}
142
+ hasMiniLabel={hasMiniLabel}
151
143
  focused={focused}
152
144
  error={error}
153
145
  invalid={invalid}
@@ -168,8 +160,7 @@ export function InputPressableInternal(
168
160
  style={[
169
161
  commonInputStyles.input,
170
162
  styles.inputPressableStyles,
171
- placeholderMode === "normal" && commonInputStyles.inputEmpty,
172
- placeholderMode === "hidden" && styles.withoutMiniLabel,
163
+ !hasMiniLabel && commonInputStyles.inputEmpty,
173
164
  disabled && commonInputStyles.inputDisabled,
174
165
  (Boolean(invalid) || error) && styles.inputInvalid,
175
166
  ]}
@@ -185,20 +176,3 @@ export function InputPressableInternal(
185
176
  </InputFieldWrapper>
186
177
  );
187
178
  }
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
- }
@@ -16,7 +16,6 @@ export interface InputSearchProps
16
16
  | "autoFocus"
17
17
  | "placeholder"
18
18
  | "prefix"
19
- | "showMiniLabel"
20
19
  > {
21
20
  /**
22
21
  * A callback function that handles the update of the new value of the property value.
@@ -27,10 +27,5 @@ export const useStyles = buildThemedStyles(tokens => {
27
27
  paddingTop:
28
28
  (typographyStyles.defaultSize.fontSize || 0) + tokens["space-smallest"],
29
29
  },
30
-
31
- multilineWithoutMiniLabel: {
32
- paddingTop: tokens["space-base"] + tokens["space-smallest"],
33
- paddingBottom: tokens["space-base"] + tokens["space-smallest"],
34
- },
35
30
  };
36
31
  });
@@ -4,7 +4,6 @@ import {
4
4
  fireEvent,
5
5
  render,
6
6
  renderHook,
7
- screen,
8
7
  waitFor,
9
8
  } from "@testing-library/react-native";
10
9
  import type { TextStyle } from "react-native";
@@ -549,80 +548,6 @@ describe("InputText", () => {
549
548
  expect(styleOverride.inputText.color).toEqual(flattenedStyle.color);
550
549
  });
551
550
  });
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
- });
626
551
  });
627
552
 
628
553
  describe("Transform", () => {
@@ -65,15 +65,6 @@ 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
-
77
68
  /**
78
69
  * Determines what keyboard is shown
79
70
  */
@@ -254,7 +245,6 @@ function InputTextInternal(
254
245
  name,
255
246
  placeholder,
256
247
  assistiveText,
257
- showMiniLabel = true,
258
248
  keyboard,
259
249
  value: controlledValue,
260
250
  defaultValue,
@@ -302,8 +292,7 @@ function InputTextInternal(
302
292
 
303
293
  const hasValue = internalValue !== "" && internalValue !== undefined;
304
294
  const [focused, setFocused] = useState(false);
305
- const placeholderMode = getPlaceholderMode(showMiniLabel, internalValue);
306
- const miniLabelActive = placeholderMode === "mini";
295
+ const { hasMiniLabel } = useMiniLabel(internalValue);
307
296
 
308
297
  const textInputRef = useTextInputRef({ ref, onClear: handleClear });
309
298
 
@@ -378,7 +367,7 @@ function InputTextInternal(
378
367
  prefix={prefix}
379
368
  suffix={suffix}
380
369
  hasValue={hasValue}
381
- placeholderMode={placeholderMode}
370
+ hasMiniLabel={hasMiniLabel}
382
371
  assistiveText={assistiveText}
383
372
  focused={focused}
384
373
  error={error}
@@ -402,14 +391,11 @@ function InputTextInternal(
402
391
  style={[
403
392
  commonInputStyles.input,
404
393
  styles.inputPaddingTop,
405
- !miniLabelActive && commonInputStyles.inputEmpty,
394
+ !hasMiniLabel && commonInputStyles.inputEmpty,
406
395
  disabled && commonInputStyles.inputDisabled,
407
396
  multiline && styles.multiLineInput,
408
397
  multiline && Platform.OS === "ios" && styles.multilineInputiOS,
409
- multiline && miniLabelActive && styles.multiLineInputWithMini,
410
- multiline &&
411
- placeholderMode === "hidden" &&
412
- styles.multilineWithoutMiniLabel,
398
+ multiline && hasMiniLabel && styles.multiLineInputWithMini,
413
399
  styleOverride?.inputText,
414
400
  loading && loadingType === "glimmer" && { color: "transparent" },
415
401
  ]}
@@ -524,19 +510,13 @@ function useTextInputRef({ ref, onClear }: UseTextInputRefProps) {
524
510
  return textInputRef;
525
511
  }
526
512
 
527
- function getPlaceholderMode(
528
- isMiniLabelAllowed: boolean,
529
- internalValue: string,
530
- ): InputFieldWrapperProps["placeholderMode"] {
531
- const hasValue = Boolean(internalValue);
513
+ function useMiniLabel(internalValue: string): {
514
+ hasMiniLabel: boolean;
515
+ } {
516
+ const [hasMiniLabel, setHasMiniLabel] = useState(Boolean(internalValue));
517
+ useEffect(() => {
518
+ setHasMiniLabel(Boolean(internalValue));
519
+ }, [internalValue]);
532
520
 
533
- if (hasValue) {
534
- if (isMiniLabelAllowed) {
535
- return "mini";
536
- } else {
537
- return "hidden";
538
- }
539
- } else {
540
- return "normal";
541
- }
521
+ return { hasMiniLabel };
542
522
  }
@@ -11,11 +11,9 @@ import { InputPressable } from "../InputPressable";
11
11
  import { FormField } from "../FormField";
12
12
  import type { InputFieldWrapperProps } from "../InputFieldWrapper";
13
13
  import { useAtlantisI18n } from "../hooks/useAtlantisI18n";
14
- import type { InputPressableProps } from "../InputPressable/InputPressable";
15
14
 
16
15
  interface InputTimeBaseProps
17
- extends Pick<InputFieldWrapperProps, "invalid" | "disabled" | "placeholder">,
18
- Pick<InputPressableProps, "showMiniLabel"> {
16
+ extends Pick<InputFieldWrapperProps, "invalid" | "disabled" | "placeholder"> {
19
17
  /**
20
18
  * Defaulted to "always" so user can clear the time whenever there's a value.
21
19
  */
@@ -131,7 +129,6 @@ function InternalInputTime({
131
129
  value,
132
130
  name,
133
131
  type = "scheduling",
134
- showMiniLabel = true,
135
132
  onChange,
136
133
  showIcon = true,
137
134
  }: InputTimeProps): JSX.Element {
@@ -159,7 +156,6 @@ function InternalInputTime({
159
156
  return (
160
157
  <View style={styles.container}>
161
158
  <InputPressable
162
- showMiniLabel={showMiniLabel}
163
159
  clearable={canClearTime}
164
160
  disabled={disabled}
165
161
  invalid={invalid}