@react-native-ama/forms 1.0.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.
Files changed (110) hide show
  1. package/dist/core/src/components/AMAProvider.d.ts +26 -0
  2. package/dist/core/src/components/AMAProvider.js +147 -0
  3. package/dist/core/src/components/AutofocusContainer.d.ts +9 -0
  4. package/dist/core/src/components/AutofocusContainer.js +58 -0
  5. package/dist/core/src/components/HideChildrenFromAccessibilityTree.d.ts +6 -0
  6. package/dist/core/src/components/HideChildrenFromAccessibilityTree.js +40 -0
  7. package/dist/core/src/hooks/useButtonChecks.d.ts +6 -0
  8. package/dist/core/src/hooks/useButtonChecks.js +51 -0
  9. package/dist/core/src/hooks/useChecks.d.ts +15 -0
  10. package/dist/core/src/hooks/useChecks.js +152 -0
  11. package/dist/core/src/hooks/useFocus.d.ts +4 -0
  12. package/dist/core/src/hooks/useFocus.js +55 -0
  13. package/dist/core/src/hooks/useTimedAction.d.ts +3 -0
  14. package/dist/core/src/hooks/useTimedAction.js +63 -0
  15. package/dist/core/src/index.d.ts +7 -0
  16. package/dist/core/src/index.js +20 -0
  17. package/dist/forms/src/components/Form.d.ts +24 -0
  18. package/dist/forms/src/components/Form.js +122 -0
  19. package/dist/forms/src/components/FormField.d.ts +7 -0
  20. package/dist/forms/src/components/FormField.js +52 -0
  21. package/dist/forms/src/components/FormSubmit.d.ts +10 -0
  22. package/dist/forms/src/components/FormSubmit.js +25 -0
  23. package/dist/forms/src/components/FormSwitch.d.ts +4 -0
  24. package/dist/forms/src/components/FormSwitch.js +15 -0
  25. package/dist/forms/src/components/TextInput.d.ts +26 -0
  26. package/dist/forms/src/components/TextInput.js +123 -0
  27. package/dist/forms/src/hooks/useFormField.d.ts +26 -0
  28. package/dist/forms/src/hooks/useFormField.js +92 -0
  29. package/dist/forms/src/hooks/useTextInput.d.ts +350 -0
  30. package/dist/forms/src/hooks/useTextInput.js +102 -0
  31. package/dist/forms/src/index.d.ts +16 -0
  32. package/dist/forms/src/index.js +24 -0
  33. package/dist/internal/src/checks/checkAccessibilityRole.d.ts +3 -0
  34. package/dist/internal/src/checks/checkAccessibilityRole.js +32 -0
  35. package/dist/internal/src/checks/checkFocusTrap.d.ts +8 -0
  36. package/dist/internal/src/checks/checkFocusTrap.js +34 -0
  37. package/dist/internal/src/checks/checkForAccessibilityState.d.ts +7 -0
  38. package/dist/internal/src/checks/checkForAccessibilityState.js +48 -0
  39. package/dist/internal/src/checks/checkMinimumSize.d.ts +3 -0
  40. package/dist/internal/src/checks/checkMinimumSize.js +29 -0
  41. package/dist/internal/src/checks/contrastChecker.d.ts +8 -0
  42. package/dist/internal/src/checks/contrastChecker.js +77 -0
  43. package/dist/internal/src/checks/noUndefinedProperty.d.ts +8 -0
  44. package/dist/internal/src/checks/noUndefinedProperty.js +14 -0
  45. package/dist/internal/src/checks/uppercaseChecker.d.ts +8 -0
  46. package/dist/internal/src/checks/uppercaseChecker.js +18 -0
  47. package/dist/internal/src/checks/uppercaseStringChecker.d.ts +8 -0
  48. package/dist/internal/src/checks/uppercaseStringChecker.js +29 -0
  49. package/dist/internal/src/index.d.ts +20 -0
  50. package/dist/internal/src/index.js +56 -0
  51. package/dist/internal/src/types.d.ts +17 -0
  52. package/dist/internal/src/types.js +2 -0
  53. package/dist/internal/src/utils/applyStyle.d.ts +9 -0
  54. package/dist/internal/src/utils/applyStyle.js +33 -0
  55. package/dist/internal/src/utils/constants.d.ts +3 -0
  56. package/dist/internal/src/utils/constants.js +32 -0
  57. package/dist/internal/src/utils/error.style.d.ts +6 -0
  58. package/dist/internal/src/utils/error.style.js +11 -0
  59. package/dist/internal/src/utils/generateAccessibilityStateFromProp.d.ts +9 -0
  60. package/dist/internal/src/utils/generateAccessibilityStateFromProp.js +35 -0
  61. package/dist/internal/src/utils/getPropertyFromStyle.d.ts +2 -0
  62. package/dist/internal/src/utils/getPropertyFromStyle.js +10 -0
  63. package/dist/internal/src/utils/interpolateAnimationStates.d.ts +2 -0
  64. package/dist/internal/src/utils/interpolateAnimationStates.js +43 -0
  65. package/dist/internal/src/utils/isFocused.d.ts +2 -0
  66. package/dist/internal/src/utils/isFocused.js +7 -0
  67. package/dist/internal/src/utils/logger.d.ts +16 -0
  68. package/dist/internal/src/utils/logger.js +53 -0
  69. package/dist/internal/src/utils/logger.rules.d.ts +15 -0
  70. package/dist/internal/src/utils/logger.rules.js +74 -0
  71. package/dist/internal/src/utils/maybeGenerateStringFromElement.d.ts +2 -0
  72. package/dist/internal/src/utils/maybeGenerateStringFromElement.js +51 -0
  73. package/dist/internal/src/utils/minimumTouchableSize.d.ts +3 -0
  74. package/dist/internal/src/utils/minimumTouchableSize.js +9 -0
  75. package/dist/react-native/src/components/ExpandablePressable.d.ts +6 -0
  76. package/dist/react-native/src/components/ExpandablePressable.js +26 -0
  77. package/dist/react-native/src/components/Pressable.d.ts +5 -0
  78. package/dist/react-native/src/components/Pressable.js +49 -0
  79. package/dist/react-native/src/components/SwitchListItem.d.ts +12 -0
  80. package/dist/react-native/src/components/SwitchListItem.js +44 -0
  81. package/dist/react-native/src/components/SwitchWrapper.d.ts +11 -0
  82. package/dist/react-native/src/components/SwitchWrapper.js +36 -0
  83. package/dist/react-native/src/components/Text.d.ts +6 -0
  84. package/dist/react-native/src/components/Text.js +77 -0
  85. package/dist/react-native/src/components/TouchableOpacity.d.ts +6 -0
  86. package/dist/react-native/src/components/TouchableOpacity.js +48 -0
  87. package/dist/react-native/src/components/TouchableWithoutFeedback.d.ts +5 -0
  88. package/dist/react-native/src/components/TouchableWithoutFeedback.js +48 -0
  89. package/dist/react-native/src/hooks/useExpandable.d.ts +13 -0
  90. package/dist/react-native/src/hooks/useExpandable.js +31 -0
  91. package/dist/react-native/src/hooks/usePressable.d.ts +16 -0
  92. package/dist/react-native/src/hooks/usePressable.js +44 -0
  93. package/dist/react-native/src/hooks/useSwitch.d.ts +10 -0
  94. package/dist/react-native/src/hooks/useSwitch.js +25 -0
  95. package/dist/react-native/src/index.d.ts +10 -0
  96. package/dist/react-native/src/index.js +25 -0
  97. package/package.json +82 -0
  98. package/src/components/Form.test.tsx +262 -0
  99. package/src/components/Form.tsx +138 -0
  100. package/src/components/FormField.test.tsx +54 -0
  101. package/src/components/FormField.tsx +45 -0
  102. package/src/components/FormSubmit.test.tsx +71 -0
  103. package/src/components/FormSubmit.tsx +43 -0
  104. package/src/components/FormSwitch.tsx +17 -0
  105. package/src/components/TextInput.test.tsx +540 -0
  106. package/src/components/TextInput.tsx +168 -0
  107. package/src/hooks/useFormField.test.tsx +183 -0
  108. package/src/hooks/useFormField.ts +133 -0
  109. package/src/hooks/useTextInput.ts +128 -0
  110. package/src/index.ts +39 -0
@@ -0,0 +1,45 @@
1
+ import * as React from 'react';
2
+ import {
3
+ TouchableWithoutFeedback,
4
+ TouchableWithoutFeedbackProps,
5
+ View,
6
+ } from 'react-native';
7
+
8
+ import { UseFormField, useFormField } from '../hooks/useFormField';
9
+
10
+ export type FormFieldProps = React.PropsWithChildren<
11
+ TouchableWithoutFeedbackProps &
12
+ Omit<
13
+ UseFormField,
14
+ 'hasFocusCallback' | 'nextFormFieldRef' | 'nextFieldId' | 'editable'
15
+ > & {
16
+ wrapInsideAccessibleView?: boolean;
17
+ }
18
+ >;
19
+
20
+ export const FormField = ({
21
+ children,
22
+ wrapInsideAccessibleView = true,
23
+ ...props
24
+ }: FormFieldProps) => {
25
+ const viewRef = React.useRef<React.ElementRef<
26
+ typeof TouchableWithoutFeedback
27
+ > | null>(null);
28
+
29
+ // @ts-ignore
30
+ const formProps = useFormField({
31
+ hasFocusCallback: false,
32
+ ref: viewRef,
33
+ ...props,
34
+ });
35
+
36
+ return wrapInsideAccessibleView ? (
37
+ <TouchableWithoutFeedback {...props} ref={viewRef} {...formProps}>
38
+ <View accessible>{children}</View>
39
+ </TouchableWithoutFeedback>
40
+ ) : (
41
+ <TouchableWithoutFeedback {...props} ref={viewRef} {...formProps}>
42
+ <>{children}</>
43
+ </TouchableWithoutFeedback>
44
+ );
45
+ };
@@ -0,0 +1,71 @@
1
+ import { render } from '@testing-library/react-native';
2
+ import * as React from 'react';
3
+ import { Pressable, View } from 'react-native';
4
+
5
+ import { FormSubmit } from './FormSubmit';
6
+
7
+ beforeEach(() => {
8
+ jest.clearAllMocks();
9
+ });
10
+
11
+ describe('FormSubmit', () => {
12
+ it('wraps the children inside a Pressable component with the correct accessibility role and label', () => {
13
+ const { getByTestId, UNSAFE_getByType } = render(
14
+ <FormSubmit
15
+ accessibilityLabel="This is the label"
16
+ busy={false}
17
+ testID="test-me"
18
+ />,
19
+ );
20
+
21
+ expect(UNSAFE_getByType(Pressable)).toBeTruthy();
22
+ expect(getByTestId('test-me').props).toEqual(
23
+ expect.objectContaining({
24
+ accessibilityRole: 'button',
25
+ accessibilityLabel: 'This is the label',
26
+ accessibilityState: {
27
+ busy: false,
28
+ },
29
+ busy: false,
30
+ accessible: true,
31
+ }),
32
+ );
33
+ });
34
+
35
+ it('hides the children from the accessiblity tree', () => {
36
+ const { getByTestId } = render(
37
+ <FormSubmit
38
+ accessibilityLabel="This is the label"
39
+ busy={false}
40
+ testID="test-me">
41
+ <View testID="child" />
42
+ </FormSubmit>,
43
+ );
44
+
45
+ expect(getByTestId('child').props).toEqual({
46
+ accessibilityElementsHidden: true,
47
+ children: null,
48
+ importantForAccessibility: 'no',
49
+ testID: 'child',
50
+ });
51
+ });
52
+ });
53
+
54
+ jest.mock('../hooks/useFormField', () => {
55
+ return {
56
+ useFormField: jest.fn().mockReturnValue({}),
57
+ };
58
+ });
59
+
60
+ jest.mock('@react-native-ama/core', () => {
61
+ const originalModule = jest.requireActual('@react-native-ama/core');
62
+
63
+ return {
64
+ ...originalModule,
65
+ useAMAContext: () => {
66
+ return {
67
+ isScreenReaderEnabled: true,
68
+ };
69
+ },
70
+ };
71
+ });
@@ -0,0 +1,43 @@
1
+ import { useAMAContext } from '@react-native-ama/core';
2
+ import { HideChildrenFromAccessibilityTree } from '@react-native-ama/core';
3
+ import React from 'react';
4
+ import { Pressable, PressableProps } from 'react-native';
5
+
6
+ import { useForm } from '../components/Form';
7
+
8
+ export type FormSubmitProps = React.PropsWithChildren<{
9
+ accessibilityLabel: string;
10
+ accessibilityHint?: string;
11
+ busy: boolean;
12
+ style?: PressableProps['style'];
13
+ testID?: string;
14
+ }>;
15
+
16
+ export const FormSubmit = (props: FormSubmitProps) => {
17
+ const { submitForm } = useForm();
18
+ const { isScreenReaderEnabled } = useAMAContext();
19
+
20
+ return (
21
+ <Pressable
22
+ accessibilityRole="button"
23
+ pointerEvents="box-only" // prevent event propagation to children eg Pressable
24
+ {...props}
25
+ onPress={submitForm}>
26
+ {isScreenReaderEnabled ? (
27
+ <FormSubmitForScreenReader children={props.children} />
28
+ ) : (
29
+ props.children
30
+ )}
31
+ </Pressable>
32
+ );
33
+ };
34
+
35
+ const FormSubmitForScreenReader = ({
36
+ children,
37
+ }: React.PropsWithChildren<{}>) => {
38
+ return (
39
+ <HideChildrenFromAccessibilityTree>
40
+ {children}
41
+ </HideChildrenFromAccessibilityTree>
42
+ );
43
+ };
@@ -0,0 +1,17 @@
1
+ import {
2
+ SwitchListItem,
3
+ SwitchListItemProps,
4
+ } from '@react-native-ama/react-native';
5
+ import React from 'react';
6
+
7
+ import { FormField } from './FormField';
8
+
9
+ export type FormSwitchProps = SwitchListItemProps;
10
+
11
+ export const FormSwitch = (props: FormSwitchProps) => {
12
+ return (
13
+ <FormField hasValidation={false}>
14
+ <SwitchListItem {...props} />
15
+ </FormField>
16
+ );
17
+ };