sapo-components-ui-rn 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 (215) hide show
  1. package/README.md +69 -0
  2. package/dist/assets/error.png +0 -0
  3. package/dist/assets/icon-checkbox-active.svg +4 -0
  4. package/dist/assets/icon-checkbox.svg +3 -0
  5. package/dist/assets/image_default.png +0 -0
  6. package/dist/assets/images/error.png +0 -0
  7. package/dist/assets/images/image_default.png +0 -0
  8. package/dist/assets/images/info.png +0 -0
  9. package/dist/assets/images/success.png +0 -0
  10. package/dist/assets/images/warning.png +0 -0
  11. package/dist/assets/info.png +0 -0
  12. package/dist/assets/success.png +0 -0
  13. package/dist/assets/svg/icon-checkbox-active.svg +4 -0
  14. package/dist/assets/svg/icon-checkbox.svg +3 -0
  15. package/dist/assets/warning.png +0 -0
  16. package/dist/components/ActivityIndicator.d.ts +28 -0
  17. package/dist/components/Avatar/index.d.ts +17 -0
  18. package/dist/components/Badge/index.d.ts +13 -0
  19. package/dist/components/Button/index.d.ts +23 -0
  20. package/dist/components/ButtonIcon/index.d.ts +18 -0
  21. package/dist/components/Checkbox/index.d.ts +14 -0
  22. package/dist/components/ChipBar/index.d.ts +16 -0
  23. package/dist/components/CountingDot/index.d.ts +13 -0
  24. package/dist/components/FloatingButton/index.d.ts +17 -0
  25. package/dist/components/Icon/index.d.ts +17 -0
  26. package/dist/components/IconSvg/index.d.ts +12 -0
  27. package/dist/components/Image/index.d.ts +14 -0
  28. package/dist/components/ProgressBar.d.ts +42 -0
  29. package/dist/components/RadioButton/index.d.ts +13 -0
  30. package/dist/components/ScaleButton/index.d.ts +4 -0
  31. package/dist/components/SelectionField/index.d.ts +24 -0
  32. package/dist/components/Spacer/index.d.ts +9 -0
  33. package/dist/components/Switch/Switch.d.ts +47 -0
  34. package/dist/components/Switch/utils.d.ts +14 -0
  35. package/dist/components/Text/index.d.ts +14 -0
  36. package/dist/components/TextInput/Addons/Outline.d.ts +15 -0
  37. package/dist/components/TextInput/Addons/Underline.d.ts +19 -0
  38. package/dist/components/TextInput/Adornment/TextInputAdornment.d.ts +43 -0
  39. package/dist/components/TextInput/Adornment/TextInputAffix.d.ts +72 -0
  40. package/dist/components/TextInput/Adornment/enums.d.ts +12 -0
  41. package/dist/components/TextInput/Adornment/types.d.ts +11 -0
  42. package/dist/components/TextInput/Adornment/utils.d.ts +11 -0
  43. package/dist/components/TextInput/Label/InputLabel.d.ts +4 -0
  44. package/dist/components/TextInput/Label/LabelBackground.d.ts +4 -0
  45. package/dist/components/TextInput/TextInput.d.ts +171 -0
  46. package/dist/components/TextInput/TextInputDefault.d.ts +4 -0
  47. package/dist/components/TextInput/TextInputFlat.d.ts +4 -0
  48. package/dist/components/TextInput/constants.d.ts +31 -0
  49. package/dist/components/TextInput/helpers.d.ts +95 -0
  50. package/dist/components/TextInput/types.d.ts +154 -0
  51. package/dist/components/Toast/ToastProvider.d.ts +21 -0
  52. package/dist/components/Toast/index.d.ts +3 -0
  53. package/dist/components/Typography/AnimatedText.d.ts +34 -0
  54. package/dist/components/Typography/StyledText.d.ts +12 -0
  55. package/dist/components/Typography/Text.d.ts +35 -0
  56. package/dist/components/Typography/types.d.ts +2 -0
  57. package/dist/components/View/index.d.ts +38 -0
  58. package/dist/components/ViewVisibleAnimated/index.d.ts +25 -0
  59. package/dist/constants.d.ts +1 -0
  60. package/dist/core/theming.d.ts +43 -0
  61. package/dist/icons/IconArrowDown.d.ts +4 -0
  62. package/dist/icons/IconCheckbox.d.ts +4 -0
  63. package/dist/icons/IconCheckboxActive.d.ts +4 -0
  64. package/dist/icons/IconClearText.d.ts +4 -0
  65. package/dist/icons/IconRadio.d.ts +4 -0
  66. package/dist/icons/IconRadioActive.d.ts +4 -0
  67. package/dist/icons/IconRadioDisable.d.ts +4 -0
  68. package/dist/index.d.ts +33 -0
  69. package/dist/index.esm.js +6758 -0
  70. package/dist/index.esm.js.map +1 -0
  71. package/dist/index.js +6823 -0
  72. package/dist/index.js.map +1 -0
  73. package/dist/styles/fonts.d.ts +78 -0
  74. package/dist/styles/overlay.d.ts +3 -0
  75. package/dist/styles/shadow.d.ts +18 -0
  76. package/dist/styles/themes/DarkTheme.d.ts +2 -0
  77. package/dist/styles/themes/LightTheme.d.ts +2 -0
  78. package/dist/styles/themes/index.d.ts +2 -0
  79. package/dist/styles/themes/tokens.d.ts +830 -0
  80. package/dist/theme/blue.d.ts +14 -0
  81. package/dist/theme/colors.d.ts +99 -0
  82. package/dist/theme/container-styles.d.ts +124 -0
  83. package/dist/theme/dimensions.d.ts +36 -0
  84. package/dist/theme/green.d.ts +15 -0
  85. package/dist/theme/icon.d.ts +5 -0
  86. package/dist/theme/ink.d.ts +11 -0
  87. package/dist/theme/orange.d.ts +14 -0
  88. package/dist/theme/purple.d.ts +6 -0
  89. package/dist/theme/red.d.ts +15 -0
  90. package/dist/theme/themes.d.ts +277 -0
  91. package/dist/theme/white.d.ts +10 -0
  92. package/dist/theme/yellow.d.ts +15 -0
  93. package/dist/types/index.d.ts +65 -0
  94. package/dist/types.d.ts +220 -0
  95. package/dist/utils/BackHandler/BackHandler.d.ts +9 -0
  96. package/dist/utils/BackHandler/BackHandler.native.d.ts +2 -0
  97. package/dist/utils/addEventListener.d.ts +12 -0
  98. package/dist/utils/forwardRef.d.ts +11 -0
  99. package/dist/utils/function-utils.d.ts +12 -0
  100. package/dist/utils/getContrastingColor.d.ts +2 -0
  101. package/dist/utils/hasTouchHandler.d.ts +5 -0
  102. package/dist/utils/roundLayoutSize.d.ts +1 -0
  103. package/dist/utils/splitStyles.d.ts +19 -0
  104. package/dist/utils/toast-manager.d.ts +21 -0
  105. package/dist/utils/useAnimatedValue.d.ts +2 -0
  106. package/dist/utils/useAnimatedValueArray.d.ts +2 -0
  107. package/dist/utils/useIsKeyboardShown.d.ts +6 -0
  108. package/dist/utils/useLayout.d.ts +6 -0
  109. package/dist/utils/useLazyRef.d.ts +2 -0
  110. package/package.json +104 -0
  111. package/src/.DS_Store +0 -0
  112. package/src/assets/images/error.png +0 -0
  113. package/src/assets/images/image_default.png +0 -0
  114. package/src/assets/images/info.png +0 -0
  115. package/src/assets/images/success.png +0 -0
  116. package/src/assets/images/warning.png +0 -0
  117. package/src/assets/svg/icon-checkbox-active.svg +4 -0
  118. package/src/assets/svg/icon-checkbox.svg +3 -0
  119. package/src/babel/.eslintrc +7 -0
  120. package/src/babel/index.js +63 -0
  121. package/src/components/.DS_Store +0 -0
  122. package/src/components/ActivityIndicator.tsx +238 -0
  123. package/src/components/Avatar/index.tsx +102 -0
  124. package/src/components/Badge/index.tsx +55 -0
  125. package/src/components/Button/index.tsx +162 -0
  126. package/src/components/ButtonIcon/index.tsx +98 -0
  127. package/src/components/Checkbox/index.tsx +107 -0
  128. package/src/components/ChipBar/index.tsx +112 -0
  129. package/src/components/CountingDot/index.tsx +63 -0
  130. package/src/components/FloatingButton/index.tsx +99 -0
  131. package/src/components/Icon/index.tsx +135 -0
  132. package/src/components/IconSvg/index.tsx +42 -0
  133. package/src/components/Image/index.tsx +127 -0
  134. package/src/components/ProgressBar.tsx +272 -0
  135. package/src/components/RadioButton/index.tsx +105 -0
  136. package/src/components/ScaleButton/index.tsx +17 -0
  137. package/src/components/SelectionField/index.tsx +166 -0
  138. package/src/components/Spacer/index.tsx +19 -0
  139. package/src/components/Switch/Switch.tsx +110 -0
  140. package/src/components/Switch/utils.ts +96 -0
  141. package/src/components/Text/index.tsx +69 -0
  142. package/src/components/TextInput/.DS_Store +0 -0
  143. package/src/components/TextInput/Addons/Outline.tsx +62 -0
  144. package/src/components/TextInput/Addons/Underline.tsx +71 -0
  145. package/src/components/TextInput/Adornment/TextInputAdornment.tsx +191 -0
  146. package/src/components/TextInput/Adornment/TextInputAffix.tsx +212 -0
  147. package/src/components/TextInput/Adornment/enums.tsx +12 -0
  148. package/src/components/TextInput/Adornment/types.tsx +11 -0
  149. package/src/components/TextInput/Adornment/utils.ts +39 -0
  150. package/src/components/TextInput/Label/InputLabel.tsx +216 -0
  151. package/src/components/TextInput/Label/LabelBackground.tsx +100 -0
  152. package/src/components/TextInput/TextInput.tsx +564 -0
  153. package/src/components/TextInput/TextInputDefault.tsx +187 -0
  154. package/src/components/TextInput/TextInputFlat.tsx +452 -0
  155. package/src/components/TextInput/constants.tsx +48 -0
  156. package/src/components/TextInput/helpers.tsx +546 -0
  157. package/src/components/TextInput/types.tsx +155 -0
  158. package/src/components/Toast/ToastProvider.tsx +69 -0
  159. package/src/components/Toast/index.tsx +239 -0
  160. package/src/components/Typography/AnimatedText.tsx +84 -0
  161. package/src/components/Typography/StyledText.tsx +53 -0
  162. package/src/components/Typography/Text.tsx +189 -0
  163. package/src/components/Typography/types.tsx +5 -0
  164. package/src/components/View/index.tsx +175 -0
  165. package/src/components/ViewVisibleAnimated/index.tsx +199 -0
  166. package/src/constants.tsx +16 -0
  167. package/src/core/theming.tsx +144 -0
  168. package/src/icons/IconArrowDown.tsx +14 -0
  169. package/src/icons/IconCheckbox.tsx +20 -0
  170. package/src/icons/IconCheckboxActive.tsx +18 -0
  171. package/src/icons/IconClearText.tsx +14 -0
  172. package/src/icons/IconRadio.tsx +11 -0
  173. package/src/icons/IconRadioActive.tsx +12 -0
  174. package/src/icons/IconRadioDisable.tsx +12 -0
  175. package/src/index.ts +51 -0
  176. package/src/index.tsx +50 -0
  177. package/src/styles/fonts.tsx +89 -0
  178. package/src/styles/overlay.tsx +69 -0
  179. package/src/styles/shadow.tsx +47 -0
  180. package/src/styles/themes/DarkTheme.tsx +157 -0
  181. package/src/styles/themes/LightTheme.tsx +160 -0
  182. package/src/styles/themes/index.ts +3 -0
  183. package/src/styles/themes/tokens.tsx +481 -0
  184. package/src/theme/blue.ts +25 -0
  185. package/src/theme/colors.ts +21 -0
  186. package/src/theme/container-styles.tsx +126 -0
  187. package/src/theme/dimensions.ts +44 -0
  188. package/src/theme/green.ts +27 -0
  189. package/src/theme/icon.ts +7 -0
  190. package/src/theme/ink.ts +18 -0
  191. package/src/theme/orange.ts +24 -0
  192. package/src/theme/purple.ts +8 -0
  193. package/src/theme/red.ts +26 -0
  194. package/src/theme/themes.tsx +287 -0
  195. package/src/theme/white.ts +16 -0
  196. package/src/theme/yellow.ts +26 -0
  197. package/src/types/index.ts +71 -0
  198. package/src/types/svg.d.ts +5 -0
  199. package/src/types.ts +259 -0
  200. package/src/types.tsx +284 -0
  201. package/src/utils/BackHandler/BackHandler.native.tsx +3 -0
  202. package/src/utils/BackHandler/BackHandler.tsx +11 -0
  203. package/src/utils/addEventListener.tsx +56 -0
  204. package/src/utils/forwardRef.tsx +23 -0
  205. package/src/utils/function-utils.tsx +108 -0
  206. package/src/utils/getContrastingColor.tsx +15 -0
  207. package/src/utils/hasTouchHandler.tsx +23 -0
  208. package/src/utils/roundLayoutSize.ts +2 -0
  209. package/src/utils/splitStyles.ts +60 -0
  210. package/src/utils/toast-manager.tsx +46 -0
  211. package/src/utils/useAnimatedValue.tsx +9 -0
  212. package/src/utils/useAnimatedValueArray.tsx +13 -0
  213. package/src/utils/useIsKeyboardShown.tsx +55 -0
  214. package/src/utils/useLayout.tsx +29 -0
  215. package/src/utils/useLazyRef.tsx +11 -0
@@ -0,0 +1,546 @@
1
+ import { Platform } from "react-native";
2
+
3
+ import color from "color";
4
+
5
+ import { AdornmentSide, AdornmentType } from "./Adornment/enums";
6
+ import type { AdornmentConfig } from "./Adornment/types";
7
+ import {
8
+ MIN_WIDTH,
9
+ ADORNMENT_SIZE,
10
+ MD2_ADORNMENT_OFFSET,
11
+ MD2_AFFIX_OFFSET,
12
+ MD2_FLAT_INPUT_OFFSET,
13
+ MD2_ICON_OFFSET,
14
+ MD2_INPUT_PADDING_HORIZONTAL,
15
+ MD2_LABEL_PADDING_HORIZONTAL,
16
+ MD2_LABEL_PADDING_TOP,
17
+ MD2_MIN_HEIGHT,
18
+ MD2_OUTLINED_INPUT_OFFSET,
19
+ MD3_ADORNMENT_OFFSET,
20
+ MD3_AFFIX_OFFSET,
21
+ MD3_FLAT_INPUT_OFFSET,
22
+ MD3_ICON_OFFSET,
23
+ MD3_INPUT_PADDING_HORIZONTAL,
24
+ MD3_LABEL_PADDING_HORIZONTAL,
25
+ MD3_LABEL_PADDING_TOP,
26
+ MD3_MIN_HEIGHT,
27
+ MD3_OUTLINED_INPUT_OFFSET,
28
+ } from "./constants";
29
+ import type { TextInputLabelProp } from "./types";
30
+ import type { InternalTheme } from "../../types";
31
+ type PaddingProps = {
32
+ height: number | null;
33
+ labelHalfHeight: number;
34
+ multiline: boolean | null;
35
+ dense: boolean | null;
36
+ topPosition: number;
37
+ fontSize: number;
38
+ lineHeight?: number;
39
+ label?: TextInputLabelProp | null;
40
+ scale: number;
41
+ offset: number;
42
+ isAndroid: boolean;
43
+ styles: { paddingTop: number; paddingBottom: number };
44
+ };
45
+
46
+ type AdjProps = PaddingProps & {
47
+ pad: number;
48
+ };
49
+
50
+ export type Padding = { paddingTop: number; paddingBottom: number };
51
+
52
+ export const calculateLabelTopPosition = (
53
+ labelHeight: number,
54
+ height: number = 0,
55
+ optionalPadding: number = 0
56
+ ): number => {
57
+ const customHeight = height > 0 ? height : 0;
58
+
59
+ return Math.floor((customHeight - labelHeight) / 2 + optionalPadding);
60
+ };
61
+
62
+ export const calculateInputHeight = (
63
+ labelHeight: number,
64
+ height: any = 0,
65
+ minHeight: number
66
+ ): number => {
67
+ const finalHeight = height > 0 ? height : labelHeight;
68
+
69
+ if (height > 0) return height;
70
+ return finalHeight < minHeight ? minHeight : finalHeight;
71
+ };
72
+
73
+ export const calculatePadding = (props: PaddingProps): number => {
74
+ const { height, multiline = false } = props;
75
+
76
+ let result = 0;
77
+
78
+ if (multiline) {
79
+ if (height && multiline) {
80
+ result = calculateTextAreaPadding(props);
81
+ } else {
82
+ result = calculateInputPadding(props);
83
+ }
84
+ }
85
+
86
+ return Math.max(0, result);
87
+ };
88
+
89
+ const calculateTextAreaPadding = (props: PaddingProps) => {
90
+ const { dense } = props;
91
+
92
+ return dense ? 10 : 20;
93
+ };
94
+
95
+ const calculateInputPadding = ({
96
+ topPosition,
97
+ fontSize,
98
+ multiline,
99
+ scale,
100
+ dense,
101
+ offset,
102
+ isAndroid,
103
+ }: PaddingProps): number => {
104
+ const refFontSize = scale * fontSize;
105
+ let result = Math.floor(topPosition / 2);
106
+
107
+ result =
108
+ result +
109
+ Math.floor((refFontSize - fontSize) / 2) -
110
+ (scale < 1 ? offset / 2 : 0);
111
+
112
+ if (multiline && isAndroid)
113
+ result = Math.min(dense ? offset / 2 : offset, result);
114
+
115
+ return result;
116
+ };
117
+
118
+ export const adjustPaddingOut = ({
119
+ pad,
120
+ multiline,
121
+ label,
122
+ scale,
123
+ height,
124
+ fontSize,
125
+ lineHeight,
126
+ dense,
127
+ offset,
128
+ isAndroid,
129
+ }: AdjProps): Padding => {
130
+ const fontHeight = lineHeight ?? fontSize;
131
+ const refFontHeight = scale * fontSize;
132
+ let result = pad;
133
+
134
+ if (!isAndroid && height && !multiline) {
135
+ return {
136
+ paddingTop: Math.max(0, (height - fontHeight) / 2),
137
+ paddingBottom: Math.max(0, (height - fontHeight) / 2),
138
+ };
139
+ }
140
+ if (!isAndroid && multiline) {
141
+ if (dense) {
142
+ if (label) {
143
+ result += scale < 1 ? Math.min(offset, (refFontHeight / 2) * scale) : 0;
144
+ } else {
145
+ result += 0;
146
+ }
147
+ }
148
+ if (!dense) {
149
+ if (label) {
150
+ result +=
151
+ scale < 1
152
+ ? Math.min(offset, refFontHeight * scale)
153
+ : Math.min(offset / 2, refFontHeight * scale);
154
+ } else {
155
+ result += scale < 1 ? Math.min(offset / 2, refFontHeight * scale) : 0;
156
+ }
157
+ }
158
+ result = Math.floor(result);
159
+ }
160
+ return { paddingTop: result, paddingBottom: result };
161
+ };
162
+
163
+ export const adjustPaddingFlat = ({
164
+ pad,
165
+ scale,
166
+ multiline,
167
+ label,
168
+ height,
169
+ offset,
170
+ dense,
171
+ fontSize,
172
+ isAndroid,
173
+ styles,
174
+ }: AdjProps): Padding => {
175
+ let result = pad;
176
+ let topResult = result;
177
+ let bottomResult = result;
178
+ const { paddingTop, paddingBottom } = styles;
179
+ const refFontSize = scale * fontSize;
180
+
181
+ if (!multiline) {
182
+ // do not modify padding if input is not multiline
183
+ if (label) {
184
+ // return const style for flat input with label
185
+ return { paddingTop, paddingBottom };
186
+ }
187
+ // return pad for flat input without label
188
+ return { paddingTop: result, paddingBottom: result };
189
+ }
190
+
191
+ if (label) {
192
+ // add paddings passed from styles
193
+ topResult = paddingTop;
194
+ bottomResult = paddingBottom;
195
+
196
+ // adjust top padding for iOS
197
+ if (!isAndroid) {
198
+ if (dense) {
199
+ topResult +=
200
+ scale < 1
201
+ ? Math.min(result, refFontSize * scale) - result / 2
202
+ : Math.min(result, refFontSize * scale) - result / 2;
203
+ }
204
+ if (!dense) {
205
+ topResult +=
206
+ scale < 1
207
+ ? Math.min(offset / 2, refFontSize * scale)
208
+ : Math.min(result, refFontSize * scale) - offset / 2;
209
+ }
210
+ }
211
+ topResult = Math.floor(topResult);
212
+ } else {
213
+ if (height) {
214
+ // center text when height is passed
215
+ return {
216
+ paddingTop: Math.max(0, (height - fontSize) / 2),
217
+ paddingBottom: Math.max(0, (height - fontSize) / 2),
218
+ };
219
+ }
220
+ // adjust paddings for iOS if no label
221
+ if (!isAndroid) {
222
+ if (dense) {
223
+ result +=
224
+ scale < 1
225
+ ? Math.min(offset / 2, (fontSize / 2) * scale)
226
+ : Math.min(offset / 2, scale);
227
+ }
228
+ if (!dense) {
229
+ result +=
230
+ scale < 1
231
+ ? Math.min(offset, fontSize * scale)
232
+ : Math.min(fontSize, (offset / 2) * scale);
233
+ }
234
+
235
+ result = Math.floor(result);
236
+ topResult = result;
237
+ bottomResult = result;
238
+ }
239
+ }
240
+
241
+ return {
242
+ paddingTop: Math.max(0, topResult),
243
+ paddingBottom: Math.max(0, bottomResult),
244
+ };
245
+ };
246
+
247
+ export function calculateFlatAffixTopPosition({
248
+ height,
249
+ paddingTop,
250
+ paddingBottom,
251
+ affixHeight,
252
+ }: {
253
+ height: number;
254
+ paddingTop: number;
255
+ paddingBottom: number;
256
+ affixHeight: number;
257
+ }): number {
258
+ const inputHeightWithoutPadding = height - paddingTop - paddingBottom;
259
+
260
+ const halfOfTheInputHeightDecreasedByAffixHeight =
261
+ (inputHeightWithoutPadding - affixHeight) / 2;
262
+
263
+ return paddingTop + halfOfTheInputHeightDecreasedByAffixHeight;
264
+ }
265
+
266
+ export function calculateOutlinedIconAndAffixTopPosition({
267
+ height,
268
+ affixHeight,
269
+ labelYOffset,
270
+ }: {
271
+ height: number;
272
+ affixHeight: number;
273
+ labelYOffset: number;
274
+ }): number {
275
+ return (height - affixHeight + labelYOffset) / 2;
276
+ }
277
+
278
+ export const calculateFlatInputHorizontalPadding = ({
279
+ adornmentConfig,
280
+ }: {
281
+ adornmentConfig: AdornmentConfig[];
282
+ }) => {
283
+ const { ADORNMENT_OFFSET, FLAT_INPUT_OFFSET } = getConstants();
284
+
285
+ let paddingLeft = 0;
286
+ let paddingRight = 0;
287
+
288
+ adornmentConfig.forEach(({ type, side }) => {
289
+ if (type === AdornmentType.Icon && side === AdornmentSide.Left) {
290
+ paddingLeft = ADORNMENT_SIZE + ADORNMENT_OFFSET + FLAT_INPUT_OFFSET;
291
+ } else if (side === AdornmentSide.Right) {
292
+ if (type === AdornmentType.Affix) {
293
+ paddingRight = ADORNMENT_SIZE + ADORNMENT_OFFSET + FLAT_INPUT_OFFSET;
294
+ } else if (type === AdornmentType.Icon) {
295
+ paddingRight = ADORNMENT_SIZE + ADORNMENT_OFFSET + FLAT_INPUT_OFFSET;
296
+ }
297
+ }
298
+ });
299
+
300
+ return { paddingLeft, paddingRight };
301
+ };
302
+
303
+ type BaseProps = {
304
+ theme: InternalTheme;
305
+ disabled?: boolean;
306
+ };
307
+
308
+ type Mode = "flat" | "outlined";
309
+
310
+ const getInputTextColor = ({
311
+ theme,
312
+ textColor,
313
+ disabled,
314
+ }: BaseProps & { textColor?: string }) => {
315
+ if (textColor) {
316
+ return textColor;
317
+ }
318
+
319
+ if (disabled) {
320
+ return theme.colors.textSecondary;
321
+ }
322
+
323
+ return theme.colors.textDefault;
324
+ };
325
+
326
+ const getActiveColor = ({
327
+ theme,
328
+ disabled,
329
+ error,
330
+ activeUnderlineColor,
331
+ activeOutlineColor,
332
+ mode,
333
+ }: BaseProps & {
334
+ error?: boolean;
335
+ activeUnderlineColor?: string;
336
+ activeOutlineColor?: string;
337
+ mode?: Mode;
338
+ }) => {
339
+ const isFlat = mode === "flat";
340
+ const modeColor = isFlat ? activeUnderlineColor : activeOutlineColor;
341
+
342
+ if (error) {
343
+ return theme.colors.surfaceErrorDefault;
344
+ }
345
+
346
+ if (modeColor) {
347
+ return modeColor;
348
+ }
349
+
350
+ if (disabled) {
351
+ return theme.colors.surfaceCriticalDisabled;
352
+ }
353
+
354
+ return theme.colors.surfaceBrandDefault;
355
+ };
356
+
357
+ const getPlaceholderColor = ({ theme, disabled }: BaseProps) => {
358
+ if (disabled) {
359
+ return theme.colors.textPlaceholder;
360
+ }
361
+
362
+ return theme.colors.textSecondary;
363
+ };
364
+
365
+ const getSelectionColor = ({
366
+ activeColor,
367
+ customSelectionColor,
368
+ }: {
369
+ activeColor: string;
370
+ customSelectionColor?: string;
371
+ }) => {
372
+ if (typeof customSelectionColor !== "undefined") {
373
+ return customSelectionColor;
374
+ }
375
+
376
+ if (Platform.OS === "android") {
377
+ return color(activeColor).alpha(0.54).rgb().string();
378
+ }
379
+
380
+ return activeColor;
381
+ };
382
+
383
+ const getFlatBackgroundColor = ({ theme, disabled }: BaseProps) => {
384
+ if (disabled) {
385
+ return theme.colors.surfacePrimaryDisabled;
386
+ } else {
387
+ return theme.colors.surfacePrimaryDefault;
388
+ }
389
+ };
390
+
391
+ const getFlatUnderlineColor = ({
392
+ theme,
393
+ disabled,
394
+ underlineColor,
395
+ }: BaseProps & { underlineColor?: string }) => {
396
+ if (!disabled && underlineColor) {
397
+ return underlineColor;
398
+ }
399
+
400
+ if (disabled) {
401
+ return theme.colors.surfacePrimaryDisabled;
402
+ }
403
+
404
+ return theme.colors.surfacePrimaryDefault;
405
+ };
406
+
407
+ const getOutlinedOutlineInputColor = ({
408
+ theme,
409
+ disabled,
410
+ customOutlineColor,
411
+ }: BaseProps & { customOutlineColor?: string }) => {
412
+ if (!disabled && customOutlineColor) {
413
+ return customOutlineColor;
414
+ }
415
+
416
+ if (disabled) {
417
+ if (theme.dark) {
418
+ return "transparent";
419
+ }
420
+ return theme.colors.surfacePrimaryDisabled;
421
+ }
422
+
423
+ return theme.colors.borderPrimaryDefault;
424
+ };
425
+
426
+ export const getFlatInputColors = ({
427
+ underlineColor,
428
+ activeUnderlineColor,
429
+ customSelectionColor,
430
+ textColor,
431
+ disabled,
432
+ error,
433
+ theme,
434
+ }: {
435
+ underlineColor?: string;
436
+ activeUnderlineColor?: string;
437
+ customSelectionColor?: string;
438
+ textColor?: string;
439
+ disabled?: boolean;
440
+ error?: boolean;
441
+ theme: InternalTheme;
442
+ }) => {
443
+ const baseFlatColorProps = { theme, disabled };
444
+ const activeColor = getActiveColor({
445
+ ...baseFlatColorProps,
446
+ error,
447
+ activeUnderlineColor,
448
+ mode: "flat",
449
+ });
450
+
451
+ return {
452
+ inputTextColor: getInputTextColor({
453
+ ...baseFlatColorProps,
454
+ textColor,
455
+ }),
456
+ activeColor,
457
+ underlineColorCustom: getFlatUnderlineColor({
458
+ ...baseFlatColorProps,
459
+ underlineColor,
460
+ }),
461
+ placeholderColor: getPlaceholderColor(baseFlatColorProps),
462
+ selectionColor: getSelectionColor({ activeColor, customSelectionColor }),
463
+ errorColor: theme.colors.surfaceErrorDefault,
464
+ backgroundColor: getFlatBackgroundColor(baseFlatColorProps),
465
+ };
466
+ };
467
+
468
+ export const getOutlinedInputColors = ({
469
+ activeOutlineColor,
470
+ customOutlineColor,
471
+ customSelectionColor,
472
+ textColor,
473
+ disabled,
474
+ error,
475
+ theme,
476
+ }: {
477
+ activeOutlineColor?: string;
478
+ customOutlineColor?: string;
479
+ customSelectionColor?: string;
480
+ textColor?: string;
481
+ disabled?: boolean;
482
+ error?: boolean;
483
+ theme: InternalTheme;
484
+ }) => {
485
+ const baseOutlinedColorProps = { theme, disabled };
486
+ const activeColor = getActiveColor({
487
+ ...baseOutlinedColorProps,
488
+ error,
489
+ activeOutlineColor,
490
+ mode: "outlined",
491
+ });
492
+
493
+ return {
494
+ inputTextColor: getInputTextColor({
495
+ ...baseOutlinedColorProps,
496
+ textColor,
497
+ }),
498
+ activeColor,
499
+ outlineColor: getOutlinedOutlineInputColor({
500
+ ...baseOutlinedColorProps,
501
+ customOutlineColor,
502
+ }),
503
+ placeholderColor: getPlaceholderColor(baseOutlinedColorProps),
504
+ selectionColor: getSelectionColor({ activeColor, customSelectionColor }),
505
+ errorColor: theme.colors.surfaceErrorDefault,
506
+ };
507
+ };
508
+
509
+ export const getConstants = () => {
510
+ // Text input affix
511
+ let AFFIX_OFFSET;
512
+ // Text input icon
513
+ let ICON_OFFSET;
514
+ //Text input flat
515
+ let LABEL_PADDING_TOP;
516
+ let LABEL_PADDING_HORIZONTAL;
517
+ let FLAT_INPUT_OFFSET;
518
+ let MIN_HEIGHT;
519
+ // Text input outlined;
520
+ let INPUT_PADDING_HORIZONTAL;
521
+ let ADORNMENT_OFFSET;
522
+ let OUTLINED_INPUT_OFFSET;
523
+
524
+ AFFIX_OFFSET = MD3_AFFIX_OFFSET;
525
+ ICON_OFFSET = MD3_ICON_OFFSET;
526
+ LABEL_PADDING_TOP = MD3_LABEL_PADDING_TOP;
527
+ LABEL_PADDING_HORIZONTAL = MD3_LABEL_PADDING_HORIZONTAL;
528
+ FLAT_INPUT_OFFSET = MD3_FLAT_INPUT_OFFSET;
529
+ MIN_HEIGHT = MD3_MIN_HEIGHT;
530
+ INPUT_PADDING_HORIZONTAL = MD3_INPUT_PADDING_HORIZONTAL;
531
+ ADORNMENT_OFFSET = MD3_ADORNMENT_OFFSET;
532
+ OUTLINED_INPUT_OFFSET = MD3_OUTLINED_INPUT_OFFSET;
533
+
534
+ return {
535
+ AFFIX_OFFSET,
536
+ ICON_OFFSET,
537
+ LABEL_PADDING_TOP,
538
+ LABEL_PADDING_HORIZONTAL,
539
+ FLAT_INPUT_OFFSET,
540
+ MIN_HEIGHT,
541
+ INPUT_PADDING_HORIZONTAL,
542
+ ADORNMENT_OFFSET,
543
+ OUTLINED_INPUT_OFFSET,
544
+ MIN_WIDTH,
545
+ };
546
+ };
@@ -0,0 +1,155 @@
1
+ import * as React from "react";
2
+ import type {
3
+ TextInput as NativeTextInput,
4
+ Animated,
5
+ TextStyle,
6
+ LayoutChangeEvent,
7
+ ColorValue,
8
+ StyleProp,
9
+ ViewProps,
10
+ ViewStyle,
11
+ NativeSyntheticEvent,
12
+ TextLayoutEventData,
13
+ } from "react-native";
14
+
15
+ import type { $Omit, InternalTheme, ThemeProp } from "./../../types";
16
+
17
+ export type TextInputLabelProp = string | React.ReactElement;
18
+
19
+ type TextInputProps = React.ComponentPropsWithRef<typeof NativeTextInput> & {
20
+ mode?: "flat" | "outlined";
21
+ left?: React.ReactNode;
22
+ right?: React.ReactNode;
23
+ disabled?: boolean;
24
+ label?: TextInputLabelProp;
25
+ placeholder?: string;
26
+ error?: boolean;
27
+ onChangeText?: Function;
28
+ selectionColor?: string;
29
+ cursorColor?: string;
30
+ underlineColor?: string;
31
+ activeUnderlineColor?: string;
32
+ outlineColor?: string;
33
+ activeOutlineColor?: string;
34
+ textColor?: string;
35
+ dense?: boolean;
36
+ multiline?: boolean;
37
+ numberOfLines?: number;
38
+ onFocus?: (args: any) => void;
39
+ onBlur?: (args: any) => void;
40
+ render?: (props: RenderProps) => React.ReactNode;
41
+ value?: string;
42
+ style?: StyleProp<TextStyle>;
43
+ theme?: ThemeProp;
44
+ testID?: string;
45
+ contentStyle?: StyleProp<TextStyle>;
46
+ outlineStyle?: StyleProp<ViewStyle>;
47
+ underlineStyle?: StyleProp<ViewStyle>;
48
+ scaledLabel?: boolean;
49
+ };
50
+
51
+ export type RenderProps = {
52
+ ref: (a?: NativeTextInput | null) => void;
53
+ onChangeText?: (a: string) => void;
54
+ placeholder?: string;
55
+ placeholderTextColor?: ColorValue;
56
+ editable?: boolean;
57
+ selectionColor?: string;
58
+ cursorColor?: string;
59
+ onFocus?: (args: any) => void;
60
+ onBlur?: (args: any) => void;
61
+ underlineColorAndroid?: string;
62
+ onLayout?: (args: any) => void;
63
+ style: any;
64
+ multiline?: boolean;
65
+ numberOfLines?: number;
66
+ value?: string;
67
+ adjustsFontSizeToFit?: boolean;
68
+ testID?: string;
69
+ };
70
+ type TextInputTypesWithoutMode = $Omit<TextInputProps, "mode">;
71
+ export type State = {
72
+ labeled: Animated.Value;
73
+ error: Animated.Value;
74
+ focused: boolean;
75
+ displayPlaceholder: boolean;
76
+ value?: string;
77
+ labelTextLayout: { width: number };
78
+ labelLayout: { measured: boolean; width: number; height: number };
79
+ leftLayout: { height: number | null; width: number | null };
80
+ rightLayout: { height: number | null; width: number | null };
81
+ inputContainerLayout: { width: number };
82
+ contentStyle?: StyleProp<ViewProps>;
83
+ };
84
+ export type ChildTextInputProps = {
85
+ parentState: State;
86
+ innerRef: (ref?: NativeTextInput | null) => void;
87
+ onFocus?: (args: any) => void;
88
+ onBlur?: (args: any) => void;
89
+ forceFocus: () => void;
90
+ onChangeText?: (value: string) => void;
91
+ onInputLayout: (event: LayoutChangeEvent) => void;
92
+ onLayoutAnimatedText: (args: any) => void;
93
+ onLabelTextLayout: (event: NativeSyntheticEvent<TextLayoutEventData>) => void;
94
+ onLeftAffixLayoutChange: (event: LayoutChangeEvent) => void;
95
+ onRightAffixLayoutChange: (event: LayoutChangeEvent) => void;
96
+ clearButton?: boolean;
97
+ } & $Omit<TextInputTypesWithoutMode, "theme"> & { theme: InternalTheme };
98
+
99
+ export type LabelProps = {
100
+ mode?: "flat" | "outlined";
101
+ placeholderStyle: any;
102
+ placeholderOpacity:
103
+ | number
104
+ | Animated.Value
105
+ | Animated.AnimatedInterpolation<number>;
106
+ baseLabelTranslateX: number;
107
+ baseLabelTranslateY: number;
108
+ wiggleOffsetX: number;
109
+ labelScale: number;
110
+ fontSize: number;
111
+ lineHeight?: number | undefined;
112
+ fontWeight: TextStyle["fontWeight"];
113
+ font: any;
114
+ topPosition: number;
115
+ paddingLeft?: number;
116
+ paddingRight?: number;
117
+ labelTranslationXOffset?: number;
118
+ placeholderColor: string | null;
119
+ backgroundColor?: ColorValue;
120
+ label?: TextInputLabelProp | null;
121
+ hasActiveOutline?: boolean | null;
122
+ activeColor: string;
123
+ errorColor?: string;
124
+ labelError?: boolean | null;
125
+ onLayoutAnimatedText: (args: any) => void;
126
+ onLabelTextLayout: (event: NativeSyntheticEvent<TextLayoutEventData>) => void;
127
+ roundness: number;
128
+ maxFontSizeMultiplier?: number | undefined | null;
129
+ testID?: string;
130
+ contentStyle?: StyleProp<ViewProps>;
131
+ theme?: ThemeProp;
132
+ };
133
+ export type InputLabelProps = {
134
+ labeled: Animated.Value;
135
+ error: Animated.Value;
136
+ focused: boolean;
137
+ wiggle: boolean;
138
+ opacity: number;
139
+ labelLayoutMeasured: boolean;
140
+ labelLayoutWidth: number;
141
+ labelLayoutHeight: number;
142
+ inputContainerLayout: { width: number };
143
+ labelBackground?: any;
144
+ maxFontSizeMultiplier?: number | undefined | null;
145
+ scaledLabel?: boolean;
146
+ } & LabelProps;
147
+
148
+ export type LabelBackgroundProps = {
149
+ labelStyle: any;
150
+ labeled: Animated.Value;
151
+ labelLayoutWidth: number;
152
+ labelLayoutHeight: number;
153
+ maxFontSizeMultiplier?: number | undefined | null;
154
+ theme?: ThemeProp;
155
+ } & LabelProps;