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.
- package/README.md +69 -0
- package/dist/assets/error.png +0 -0
- package/dist/assets/icon-checkbox-active.svg +4 -0
- package/dist/assets/icon-checkbox.svg +3 -0
- package/dist/assets/image_default.png +0 -0
- package/dist/assets/images/error.png +0 -0
- package/dist/assets/images/image_default.png +0 -0
- package/dist/assets/images/info.png +0 -0
- package/dist/assets/images/success.png +0 -0
- package/dist/assets/images/warning.png +0 -0
- package/dist/assets/info.png +0 -0
- package/dist/assets/success.png +0 -0
- package/dist/assets/svg/icon-checkbox-active.svg +4 -0
- package/dist/assets/svg/icon-checkbox.svg +3 -0
- package/dist/assets/warning.png +0 -0
- package/dist/components/ActivityIndicator.d.ts +28 -0
- package/dist/components/Avatar/index.d.ts +17 -0
- package/dist/components/Badge/index.d.ts +13 -0
- package/dist/components/Button/index.d.ts +23 -0
- package/dist/components/ButtonIcon/index.d.ts +18 -0
- package/dist/components/Checkbox/index.d.ts +14 -0
- package/dist/components/ChipBar/index.d.ts +16 -0
- package/dist/components/CountingDot/index.d.ts +13 -0
- package/dist/components/FloatingButton/index.d.ts +17 -0
- package/dist/components/Icon/index.d.ts +17 -0
- package/dist/components/IconSvg/index.d.ts +12 -0
- package/dist/components/Image/index.d.ts +14 -0
- package/dist/components/ProgressBar.d.ts +42 -0
- package/dist/components/RadioButton/index.d.ts +13 -0
- package/dist/components/ScaleButton/index.d.ts +4 -0
- package/dist/components/SelectionField/index.d.ts +24 -0
- package/dist/components/Spacer/index.d.ts +9 -0
- package/dist/components/Switch/Switch.d.ts +47 -0
- package/dist/components/Switch/utils.d.ts +14 -0
- package/dist/components/Text/index.d.ts +14 -0
- package/dist/components/TextInput/Addons/Outline.d.ts +15 -0
- package/dist/components/TextInput/Addons/Underline.d.ts +19 -0
- package/dist/components/TextInput/Adornment/TextInputAdornment.d.ts +43 -0
- package/dist/components/TextInput/Adornment/TextInputAffix.d.ts +72 -0
- package/dist/components/TextInput/Adornment/enums.d.ts +12 -0
- package/dist/components/TextInput/Adornment/types.d.ts +11 -0
- package/dist/components/TextInput/Adornment/utils.d.ts +11 -0
- package/dist/components/TextInput/Label/InputLabel.d.ts +4 -0
- package/dist/components/TextInput/Label/LabelBackground.d.ts +4 -0
- package/dist/components/TextInput/TextInput.d.ts +171 -0
- package/dist/components/TextInput/TextInputDefault.d.ts +4 -0
- package/dist/components/TextInput/TextInputFlat.d.ts +4 -0
- package/dist/components/TextInput/constants.d.ts +31 -0
- package/dist/components/TextInput/helpers.d.ts +95 -0
- package/dist/components/TextInput/types.d.ts +154 -0
- package/dist/components/Toast/ToastProvider.d.ts +21 -0
- package/dist/components/Toast/index.d.ts +3 -0
- package/dist/components/Typography/AnimatedText.d.ts +34 -0
- package/dist/components/Typography/StyledText.d.ts +12 -0
- package/dist/components/Typography/Text.d.ts +35 -0
- package/dist/components/Typography/types.d.ts +2 -0
- package/dist/components/View/index.d.ts +38 -0
- package/dist/components/ViewVisibleAnimated/index.d.ts +25 -0
- package/dist/constants.d.ts +1 -0
- package/dist/core/theming.d.ts +43 -0
- package/dist/icons/IconArrowDown.d.ts +4 -0
- package/dist/icons/IconCheckbox.d.ts +4 -0
- package/dist/icons/IconCheckboxActive.d.ts +4 -0
- package/dist/icons/IconClearText.d.ts +4 -0
- package/dist/icons/IconRadio.d.ts +4 -0
- package/dist/icons/IconRadioActive.d.ts +4 -0
- package/dist/icons/IconRadioDisable.d.ts +4 -0
- package/dist/index.d.ts +33 -0
- package/dist/index.esm.js +6758 -0
- package/dist/index.esm.js.map +1 -0
- package/dist/index.js +6823 -0
- package/dist/index.js.map +1 -0
- package/dist/styles/fonts.d.ts +78 -0
- package/dist/styles/overlay.d.ts +3 -0
- package/dist/styles/shadow.d.ts +18 -0
- package/dist/styles/themes/DarkTheme.d.ts +2 -0
- package/dist/styles/themes/LightTheme.d.ts +2 -0
- package/dist/styles/themes/index.d.ts +2 -0
- package/dist/styles/themes/tokens.d.ts +830 -0
- package/dist/theme/blue.d.ts +14 -0
- package/dist/theme/colors.d.ts +99 -0
- package/dist/theme/container-styles.d.ts +124 -0
- package/dist/theme/dimensions.d.ts +36 -0
- package/dist/theme/green.d.ts +15 -0
- package/dist/theme/icon.d.ts +5 -0
- package/dist/theme/ink.d.ts +11 -0
- package/dist/theme/orange.d.ts +14 -0
- package/dist/theme/purple.d.ts +6 -0
- package/dist/theme/red.d.ts +15 -0
- package/dist/theme/themes.d.ts +277 -0
- package/dist/theme/white.d.ts +10 -0
- package/dist/theme/yellow.d.ts +15 -0
- package/dist/types/index.d.ts +65 -0
- package/dist/types.d.ts +220 -0
- package/dist/utils/BackHandler/BackHandler.d.ts +9 -0
- package/dist/utils/BackHandler/BackHandler.native.d.ts +2 -0
- package/dist/utils/addEventListener.d.ts +12 -0
- package/dist/utils/forwardRef.d.ts +11 -0
- package/dist/utils/function-utils.d.ts +12 -0
- package/dist/utils/getContrastingColor.d.ts +2 -0
- package/dist/utils/hasTouchHandler.d.ts +5 -0
- package/dist/utils/roundLayoutSize.d.ts +1 -0
- package/dist/utils/splitStyles.d.ts +19 -0
- package/dist/utils/toast-manager.d.ts +21 -0
- package/dist/utils/useAnimatedValue.d.ts +2 -0
- package/dist/utils/useAnimatedValueArray.d.ts +2 -0
- package/dist/utils/useIsKeyboardShown.d.ts +6 -0
- package/dist/utils/useLayout.d.ts +6 -0
- package/dist/utils/useLazyRef.d.ts +2 -0
- package/package.json +104 -0
- package/src/.DS_Store +0 -0
- package/src/assets/images/error.png +0 -0
- package/src/assets/images/image_default.png +0 -0
- package/src/assets/images/info.png +0 -0
- package/src/assets/images/success.png +0 -0
- package/src/assets/images/warning.png +0 -0
- package/src/assets/svg/icon-checkbox-active.svg +4 -0
- package/src/assets/svg/icon-checkbox.svg +3 -0
- package/src/babel/.eslintrc +7 -0
- package/src/babel/index.js +63 -0
- package/src/components/.DS_Store +0 -0
- package/src/components/ActivityIndicator.tsx +238 -0
- package/src/components/Avatar/index.tsx +102 -0
- package/src/components/Badge/index.tsx +55 -0
- package/src/components/Button/index.tsx +162 -0
- package/src/components/ButtonIcon/index.tsx +98 -0
- package/src/components/Checkbox/index.tsx +107 -0
- package/src/components/ChipBar/index.tsx +112 -0
- package/src/components/CountingDot/index.tsx +63 -0
- package/src/components/FloatingButton/index.tsx +99 -0
- package/src/components/Icon/index.tsx +135 -0
- package/src/components/IconSvg/index.tsx +42 -0
- package/src/components/Image/index.tsx +127 -0
- package/src/components/ProgressBar.tsx +272 -0
- package/src/components/RadioButton/index.tsx +105 -0
- package/src/components/ScaleButton/index.tsx +17 -0
- package/src/components/SelectionField/index.tsx +166 -0
- package/src/components/Spacer/index.tsx +19 -0
- package/src/components/Switch/Switch.tsx +110 -0
- package/src/components/Switch/utils.ts +96 -0
- package/src/components/Text/index.tsx +69 -0
- package/src/components/TextInput/.DS_Store +0 -0
- package/src/components/TextInput/Addons/Outline.tsx +62 -0
- package/src/components/TextInput/Addons/Underline.tsx +71 -0
- package/src/components/TextInput/Adornment/TextInputAdornment.tsx +191 -0
- package/src/components/TextInput/Adornment/TextInputAffix.tsx +212 -0
- package/src/components/TextInput/Adornment/enums.tsx +12 -0
- package/src/components/TextInput/Adornment/types.tsx +11 -0
- package/src/components/TextInput/Adornment/utils.ts +39 -0
- package/src/components/TextInput/Label/InputLabel.tsx +216 -0
- package/src/components/TextInput/Label/LabelBackground.tsx +100 -0
- package/src/components/TextInput/TextInput.tsx +564 -0
- package/src/components/TextInput/TextInputDefault.tsx +187 -0
- package/src/components/TextInput/TextInputFlat.tsx +452 -0
- package/src/components/TextInput/constants.tsx +48 -0
- package/src/components/TextInput/helpers.tsx +546 -0
- package/src/components/TextInput/types.tsx +155 -0
- package/src/components/Toast/ToastProvider.tsx +69 -0
- package/src/components/Toast/index.tsx +239 -0
- package/src/components/Typography/AnimatedText.tsx +84 -0
- package/src/components/Typography/StyledText.tsx +53 -0
- package/src/components/Typography/Text.tsx +189 -0
- package/src/components/Typography/types.tsx +5 -0
- package/src/components/View/index.tsx +175 -0
- package/src/components/ViewVisibleAnimated/index.tsx +199 -0
- package/src/constants.tsx +16 -0
- package/src/core/theming.tsx +144 -0
- package/src/icons/IconArrowDown.tsx +14 -0
- package/src/icons/IconCheckbox.tsx +20 -0
- package/src/icons/IconCheckboxActive.tsx +18 -0
- package/src/icons/IconClearText.tsx +14 -0
- package/src/icons/IconRadio.tsx +11 -0
- package/src/icons/IconRadioActive.tsx +12 -0
- package/src/icons/IconRadioDisable.tsx +12 -0
- package/src/index.ts +51 -0
- package/src/index.tsx +50 -0
- package/src/styles/fonts.tsx +89 -0
- package/src/styles/overlay.tsx +69 -0
- package/src/styles/shadow.tsx +47 -0
- package/src/styles/themes/DarkTheme.tsx +157 -0
- package/src/styles/themes/LightTheme.tsx +160 -0
- package/src/styles/themes/index.ts +3 -0
- package/src/styles/themes/tokens.tsx +481 -0
- package/src/theme/blue.ts +25 -0
- package/src/theme/colors.ts +21 -0
- package/src/theme/container-styles.tsx +126 -0
- package/src/theme/dimensions.ts +44 -0
- package/src/theme/green.ts +27 -0
- package/src/theme/icon.ts +7 -0
- package/src/theme/ink.ts +18 -0
- package/src/theme/orange.ts +24 -0
- package/src/theme/purple.ts +8 -0
- package/src/theme/red.ts +26 -0
- package/src/theme/themes.tsx +287 -0
- package/src/theme/white.ts +16 -0
- package/src/theme/yellow.ts +26 -0
- package/src/types/index.ts +71 -0
- package/src/types/svg.d.ts +5 -0
- package/src/types.ts +259 -0
- package/src/types.tsx +284 -0
- package/src/utils/BackHandler/BackHandler.native.tsx +3 -0
- package/src/utils/BackHandler/BackHandler.tsx +11 -0
- package/src/utils/addEventListener.tsx +56 -0
- package/src/utils/forwardRef.tsx +23 -0
- package/src/utils/function-utils.tsx +108 -0
- package/src/utils/getContrastingColor.tsx +15 -0
- package/src/utils/hasTouchHandler.tsx +23 -0
- package/src/utils/roundLayoutSize.ts +2 -0
- package/src/utils/splitStyles.ts +60 -0
- package/src/utils/toast-manager.tsx +46 -0
- package/src/utils/useAnimatedValue.tsx +9 -0
- package/src/utils/useAnimatedValueArray.tsx +13 -0
- package/src/utils/useIsKeyboardShown.tsx +55 -0
- package/src/utils/useLayout.tsx +29 -0
- 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;
|