@aws-amplify/ui-react-native 1.2.19 → 1.2.21

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 (101) hide show
  1. package/CHANGELOG.md +57 -0
  2. package/dist/Authenticator/Authenticator.d.ts +101 -148
  3. package/dist/Authenticator/Authenticator.js +7 -3
  4. package/dist/Authenticator/Defaults/ConfirmResetPassword/ConfirmResetPassword.d.ts +13 -2
  5. package/dist/Authenticator/Defaults/ConfirmResetPassword/ConfirmResetPassword.js +4 -3
  6. package/dist/Authenticator/Defaults/ConfirmSignIn/ConfirmSignIn.d.ts +13 -2
  7. package/dist/Authenticator/Defaults/ConfirmSignIn/ConfirmSignIn.js +4 -3
  8. package/dist/Authenticator/Defaults/ConfirmSignUp/ConfirmSignUp.d.ts +13 -2
  9. package/dist/Authenticator/Defaults/ConfirmSignUp/ConfirmSignUp.js +4 -3
  10. package/dist/Authenticator/Defaults/ConfirmVerifyUser/ConfirmVerifyUser.d.ts +13 -2
  11. package/dist/Authenticator/Defaults/ConfirmVerifyUser/ConfirmVerifyUser.js +4 -3
  12. package/dist/Authenticator/Defaults/ForceNewPassword/ForceNewPassword.d.ts +13 -2
  13. package/dist/Authenticator/Defaults/ForceNewPassword/ForceNewPassword.js +4 -3
  14. package/dist/Authenticator/Defaults/ResetPassword/ResetPassword.d.ts +13 -2
  15. package/dist/Authenticator/Defaults/ResetPassword/ResetPassword.js +4 -3
  16. package/dist/Authenticator/Defaults/SetupTOTP/SetupTOTP.d.ts +13 -2
  17. package/dist/Authenticator/Defaults/SetupTOTP/SetupTOTP.js +4 -3
  18. package/dist/Authenticator/Defaults/SignIn/SignIn.d.ts +13 -2
  19. package/dist/Authenticator/Defaults/SignIn/SignIn.js +4 -3
  20. package/dist/Authenticator/Defaults/SignUp/SignUp.d.ts +13 -2
  21. package/dist/Authenticator/Defaults/SignUp/SignUp.js +4 -3
  22. package/dist/Authenticator/Defaults/VerifyUser/VerifyUser.d.ts +13 -2
  23. package/dist/Authenticator/Defaults/VerifyUser/VerifyUser.js +4 -3
  24. package/dist/Authenticator/Defaults/types.d.ts +21 -20
  25. package/dist/Authenticator/common/DefaultContent/types.d.ts +1 -1
  26. package/dist/Authenticator/common/DefaultFormFields/DefaultRadioFormFields.d.ts +7 -3
  27. package/dist/Authenticator/common/DefaultFormFields/DefaultRadioFormFields.js +4 -3
  28. package/dist/Authenticator/common/DefaultFormFields/DefaultTextFormFields.d.ts +6 -2
  29. package/dist/Authenticator/common/DefaultFormFields/DefaultTextFormFields.js +3 -3
  30. package/dist/Authenticator/common/DefaultFormFields/types.d.ts +12 -3
  31. package/dist/Authenticator/hooks/types.d.ts +3 -2
  32. package/dist/Authenticator/hooks/useFieldValues/types.d.ts +4 -1
  33. package/dist/Authenticator/hooks/useFieldValues/useFieldValues.d.ts +1 -1
  34. package/dist/Authenticator/hooks/useFieldValues/useFieldValues.js +21 -3
  35. package/dist/Authenticator/hooks/useFieldValues/utils.d.ts +10 -1
  36. package/dist/Authenticator/hooks/useFieldValues/utils.js +32 -2
  37. package/dist/hooks/index.d.ts +1 -0
  38. package/dist/hooks/index.js +1 -0
  39. package/dist/hooks/useDeprecationWarning/index.d.ts +1 -0
  40. package/dist/hooks/useDeprecationWarning/index.js +1 -0
  41. package/dist/hooks/useDeprecationWarning/useDeprecationWarning.d.ts +6 -0
  42. package/dist/hooks/useDeprecationWarning/useDeprecationWarning.js +11 -0
  43. package/dist/primitives/TextField/TextField.js +2 -1
  44. package/dist/primitives/TextField/styles.js +3 -0
  45. package/dist/primitives/TextField/types.d.ts +1 -0
  46. package/dist/theme/createTheme.js +24 -18
  47. package/dist/theme/types.d.ts +1 -1
  48. package/dist/utils/platform.d.ts +5 -0
  49. package/dist/utils/platform.js +2 -0
  50. package/dist/version.d.ts +1 -1
  51. package/dist/version.js +1 -1
  52. package/jest.config.js +1 -0
  53. package/package.json +6 -5
  54. package/src/Authenticator/Authenticator.tsx +9 -6
  55. package/src/Authenticator/Defaults/ConfirmResetPassword/ConfirmResetPassword.tsx +7 -3
  56. package/src/Authenticator/Defaults/ConfirmSignIn/ConfirmSignIn.tsx +7 -3
  57. package/src/Authenticator/Defaults/ConfirmSignIn/__tests__/ConfirmSignIn.spec.tsx +1 -0
  58. package/src/Authenticator/Defaults/ConfirmSignUp/ConfirmSignUp.tsx +7 -3
  59. package/src/Authenticator/Defaults/ConfirmSignUp/__tests__/ConfirmSignUp.spec.tsx +1 -0
  60. package/src/Authenticator/Defaults/ConfirmVerifyUser/ConfirmVerifyUser.tsx +7 -3
  61. package/src/Authenticator/Defaults/ConfirmVerifyUser/__tests__/ConfirmVerifyUser.spec.tsx +1 -0
  62. package/src/Authenticator/Defaults/ForceNewPassword/ForceNewPassword.tsx +7 -3
  63. package/src/Authenticator/Defaults/ForceNewPassword/__tests__/__snapshots__/ForceNewPassword.spec.tsx.snap +1 -1
  64. package/src/Authenticator/Defaults/ResetPassword/ResetPassword.tsx +7 -3
  65. package/src/Authenticator/Defaults/ResetPassword/__tests__/ResetPassword.spec.tsx +1 -0
  66. package/src/Authenticator/Defaults/SetupTOTP/SetupTOTP.tsx +7 -3
  67. package/src/Authenticator/Defaults/SetupTOTP/__tests__/SetupTOTP.spec.tsx +1 -0
  68. package/src/Authenticator/Defaults/SignIn/SignIn.tsx +7 -3
  69. package/src/Authenticator/Defaults/SignIn/__tests__/SignIn.spec.tsx +1 -0
  70. package/src/Authenticator/Defaults/SignUp/SignUp.tsx +7 -3
  71. package/src/Authenticator/Defaults/SignUp/__tests__/__snapshots__/SignUp.spec.tsx.snap +1 -1
  72. package/src/Authenticator/Defaults/VerifyUser/VerifyUser.tsx +7 -3
  73. package/src/Authenticator/Defaults/VerifyUser/__tests__/VerifyUser.spec.tsx +1 -0
  74. package/src/Authenticator/Defaults/types.ts +63 -49
  75. package/src/Authenticator/__tests__/Authenticator.spec.tsx +16 -19
  76. package/src/Authenticator/__tests__/__snapshots__/Authenticator.spec.tsx.snap +1 -9
  77. package/src/Authenticator/__tests__/withAuthenticator.spec.tsx +1 -1
  78. package/src/Authenticator/common/DefaultContent/types.ts +1 -4
  79. package/src/Authenticator/common/DefaultFormFields/DefaultRadioFormFields.tsx +8 -6
  80. package/src/Authenticator/common/DefaultFormFields/DefaultTextFormFields.tsx +10 -7
  81. package/src/Authenticator/common/DefaultFormFields/types.ts +15 -5
  82. package/src/Authenticator/hooks/types.ts +3 -0
  83. package/src/Authenticator/hooks/useFieldValues/__tests__/useFieldValues.spec.ts +75 -2
  84. package/src/Authenticator/hooks/useFieldValues/__tests__/utils.spec.ts +67 -1
  85. package/src/Authenticator/hooks/useFieldValues/types.ts +5 -0
  86. package/src/Authenticator/hooks/useFieldValues/useFieldValues.ts +26 -1
  87. package/src/Authenticator/hooks/useFieldValues/utils.ts +44 -1
  88. package/src/hooks/index.ts +1 -0
  89. package/src/hooks/useDeprecationWarning/__tests__/useDeprecationWarning.spec.ts +42 -0
  90. package/src/hooks/useDeprecationWarning/index.ts +1 -0
  91. package/src/hooks/useDeprecationWarning/useDeprecationWarning.ts +21 -0
  92. package/src/primitives/TextField/TextField.tsx +2 -1
  93. package/src/primitives/TextField/__tests__/TextField.spec.tsx +57 -8
  94. package/src/primitives/TextField/__tests__/__snapshots__/TextField.spec.tsx.snap +31 -31
  95. package/src/primitives/TextField/styles.ts +3 -0
  96. package/src/primitives/TextField/types.ts +1 -0
  97. package/src/theme/__tests__/createTheme.spec.ts +48 -0
  98. package/src/theme/createTheme.ts +44 -21
  99. package/src/theme/types.ts +17 -16
  100. package/src/utils/platform.ts +2 -0
  101. package/src/version.ts +1 -1
@@ -2,21 +2,33 @@ import deepExtend from 'style-dictionary/lib/utils/deepExtend';
2
2
  import resolveObject from 'style-dictionary/lib/utils/resolveObject';
3
3
  import usesReference from 'style-dictionary/lib/utils/references/usesReference';
4
4
  import { isFunction, setupTokens } from '@aws-amplify/ui';
5
- import { Theme, StrictTheme, ColorMode, Components } from './types';
5
+ import {
6
+ Theme,
7
+ StrictTheme,
8
+ ColorMode,
9
+ Components,
10
+ StrictTokens,
11
+ } from './types';
6
12
  import { defaultTheme } from './defaultTheme';
7
13
 
8
14
  // This will resolve all references in component themes by either
9
15
  // calling the component theme function with the already resolved base tokens
10
16
  // OR
11
17
  // resolving the component theme object
12
- const setupComponents = ({ components, tokens }: StrictTheme) => {
18
+ const setupComponents = ({
19
+ components,
20
+ tokens,
21
+ }: {
22
+ components: Components;
23
+ tokens: StrictTokens;
24
+ }) => {
13
25
  const output = components
14
26
  ? Object.entries(components).reduce(
15
27
  (acc, [key, value]) => ({
16
28
  ...acc,
17
29
  [key]: isFunction(value) ? (value(tokens) as typeof value) : value,
18
30
  }),
19
- {} as Components<'components'>
31
+ {}
20
32
  )
21
33
  : {};
22
34
 
@@ -26,6 +38,16 @@ const setupComponents = ({ components, tokens }: StrictTheme) => {
26
38
  }).components;
27
39
  };
28
40
 
41
+ const shouldParseFloatValue = (pathKey: string) =>
42
+ [
43
+ 'space',
44
+ 'borderWidths',
45
+ 'opacities',
46
+ 'fontSizes',
47
+ 'lineHeights',
48
+ 'radii',
49
+ ].includes(pathKey);
50
+
29
51
  const setupToken = ({
30
52
  token,
31
53
  path = [],
@@ -39,27 +61,28 @@ const setupToken = ({
39
61
  }): string | number => {
40
62
  const { value } = token;
41
63
  if (typeof value === 'string') {
42
- // Perform transforms
43
- if (path[0] === 'space') {
44
- if (value.includes('rem')) {
45
- return Math.floor(parseFloat(value) * 16 * spaceModifier);
46
- }
47
- }
48
- if (value.includes('rem')) {
49
- return Math.floor(parseFloat(value) * 16);
50
- }
51
- if (value.includes('px')) {
52
- return parseInt(value, 10);
53
- }
54
- if (path[0] === 'opacities') {
55
- return parseFloat(value);
56
- }
57
64
  // Remove .value from references if there is a reference
65
+ // this needs to come first so we don't get NaNs for references
58
66
  if (usesReference(value)) {
59
67
  return value.replace('.value', '');
60
68
  }
69
+
70
+ if (shouldParseFloatValue(path[0])) {
71
+ if (value.includes('rem')) {
72
+ if (path[0] === 'space') {
73
+ return Math.floor(parseFloat(value) * 16 * spaceModifier);
74
+ }
75
+ return Math.floor(parseFloat(value) * 16);
76
+ }
77
+ if (value.includes('px')) {
78
+ return parseInt(value, 10);
79
+ }
80
+ return parseFloat(value);
81
+ }
82
+
61
83
  return value;
62
84
  }
85
+
63
86
  // Font Weights in RN are strings
64
87
  if (path[0] === 'fontWeights') {
65
88
  return `${value}`;
@@ -118,14 +141,14 @@ export const createTheme = (
118
141
  }) as StrictTheme['tokens']
119
142
  );
120
143
 
121
- let { components } = mergedTheme;
144
+ let components;
122
145
 
123
146
  // Resolve component token references too
124
147
  if (mergedTheme.components) {
125
148
  components = setupComponents({
126
- ...mergedTheme,
149
+ components: mergedTheme.components,
127
150
  tokens,
128
- }) as Components<'output'>;
151
+ });
129
152
  }
130
153
 
131
154
  return { ...mergedTheme, tokens, components };
@@ -26,22 +26,23 @@ type ComponentTheme<ComponentType, Output> = Output extends 'output'
26
26
  : ((tokens: StrictTheme['tokens']) => ComponentType) | ComponentType;
27
27
 
28
28
  // TODO: make optional all the way down
29
- export type Components<Output> = Record<string, object> & {
30
- button?: ComponentTheme<ButtonStyles, Output>;
31
- checkbox?: ComponentTheme<CheckboxStyles, Output>;
32
- divider?: ComponentTheme<DividerStyles, Output>;
33
- errorMessage?: ComponentTheme<ErrorMessageStyles, Output>;
34
- heading?: ComponentTheme<HeadingStyles, Output>;
35
- icon?: ComponentTheme<IconStyles, Output>;
36
- iconButton?: ComponentTheme<IconButtonStyles, Output>;
37
- label?: ComponentTheme<LabelStyles, Output>;
38
- passwordField?: ComponentTheme<PasswordFieldStyles, Output>;
39
- phoneNumberField?: ComponentTheme<PhoneNumberFieldStyles, Output>;
40
- radio?: ComponentTheme<RadioStyles, Output>;
41
- radioGroup?: ComponentTheme<RadioGroupStyles, Output>;
42
- tabs?: ComponentTheme<TabsStyles, Output>;
43
- textField?: ComponentTheme<TextFieldStyles, Output>;
44
- };
29
+ export type Components<Output extends 'input' | 'output' | unknown = unknown> =
30
+ {
31
+ button?: ComponentTheme<ButtonStyles, Output>;
32
+ checkbox?: ComponentTheme<CheckboxStyles, Output>;
33
+ divider?: ComponentTheme<DividerStyles, Output>;
34
+ errorMessage?: ComponentTheme<ErrorMessageStyles, Output>;
35
+ heading?: ComponentTheme<HeadingStyles, Output>;
36
+ icon?: ComponentTheme<IconStyles, Output>;
37
+ iconButton?: ComponentTheme<IconButtonStyles, Output>;
38
+ label?: ComponentTheme<LabelStyles, Output>;
39
+ passwordField?: ComponentTheme<PasswordFieldStyles, Output>;
40
+ phoneNumberField?: ComponentTheme<PhoneNumberFieldStyles, Output>;
41
+ radio?: ComponentTheme<RadioStyles, Output>;
42
+ radioGroup?: ComponentTheme<RadioGroupStyles, Output>;
43
+ tabs?: ComponentTheme<TabsStyles, Output>;
44
+ textField?: ComponentTheme<TextFieldStyles, Output>;
45
+ };
45
46
 
46
47
  export type ColorMode = 'light' | 'dark' | 'system' | null;
47
48
  export type Override = Omit<Theme, 'overrides'> & {
@@ -1,5 +1,6 @@
1
1
  import { Platform } from 'react-native';
2
2
 
3
+ const IS_DEV = __DEV__;
3
4
  const IS_ANDROID = Platform.OS === 'android';
4
5
  const IS_IOS = Platform.OS === 'ios';
5
6
 
@@ -16,6 +17,7 @@ const PLATFORM_TOUCH_TARGET = Platform.select({
16
17
  export default {
17
18
  ...Platform,
18
19
  IS_ANDROID,
20
+ IS_DEV,
19
21
  IS_IOS,
20
22
  PLATFORM_TOUCH_TARGET,
21
23
  };
package/src/version.ts CHANGED
@@ -1 +1 @@
1
- export const VERSION = '1.2.19';
1
+ export const VERSION = '1.2.21';