@pagopa/io-app-design-system 1.3.1 → 1.4.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 +1 -0
- package/lib/commonjs/components/accordion/AccordionItem.js +137 -0
- package/lib/commonjs/components/accordion/AccordionItem.js.map +1 -0
- package/lib/commonjs/components/accordion/index.js +4 -4
- package/lib/commonjs/components/accordion/index.js.map +1 -1
- package/lib/commonjs/components/common/LogoPaymentWithFallback.js +49 -0
- package/lib/commonjs/components/common/LogoPaymentWithFallback.js.map +1 -0
- package/lib/commonjs/components/index.js +11 -0
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/components/listitems/ListItemTransaction.js +47 -29
- package/lib/commonjs/components/listitems/ListItemTransaction.js.map +1 -1
- package/lib/commonjs/components/pictograms/svg/PictogramFocusOn.js +6 -6
- package/lib/commonjs/components/pictograms/svg/PictogramFocusOn.js.map +1 -1
- package/lib/commonjs/components/{accordion/IOAccordion.js → textInput/TextInput.js} +5 -27
- package/lib/commonjs/components/textInput/TextInput.js.map +1 -0
- package/lib/commonjs/components/textInput/TextInputBase.js +233 -0
- package/lib/commonjs/components/textInput/TextInputBase.js.map +1 -0
- package/lib/commonjs/components/textInput/TextInputPassword.js +36 -0
- package/lib/commonjs/components/textInput/TextInputPassword.js.map +1 -0
- package/lib/commonjs/components/textInput/TextInputValidation.js +57 -0
- package/lib/commonjs/components/textInput/TextInputValidation.js.map +1 -0
- package/lib/commonjs/components/textInput/index.js +39 -0
- package/lib/commonjs/components/textInput/index.js.map +1 -0
- package/lib/commonjs/core/IOAnimations.js +5 -0
- package/lib/commonjs/core/IOAnimations.js.map +1 -1
- package/lib/commonjs/core/IOShapes.js +3 -1
- package/lib/commonjs/core/IOShapes.js.map +1 -1
- package/lib/commonjs/utils/accessibility.js +19 -0
- package/lib/commonjs/utils/accessibility.js.map +1 -0
- package/lib/commonjs/utils/object.js +16 -0
- package/lib/commonjs/utils/object.js.map +1 -0
- package/lib/commonjs/utils/textInput/index.js +24 -0
- package/lib/commonjs/utils/textInput/index.js.map +1 -0
- package/lib/commonjs/utils/url.js +14 -0
- package/lib/commonjs/utils/url.js.map +1 -0
- package/lib/module/components/accordion/AccordionItem.js +126 -0
- package/lib/module/components/accordion/AccordionItem.js.map +1 -0
- package/lib/module/components/accordion/index.js +1 -1
- package/lib/module/components/accordion/index.js.map +1 -1
- package/lib/module/components/common/LogoPaymentWithFallback.js +40 -0
- package/lib/module/components/common/LogoPaymentWithFallback.js.map +1 -0
- package/lib/module/components/index.js +1 -0
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/components/listitems/ListItemTransaction.js +48 -30
- package/lib/module/components/listitems/ListItemTransaction.js.map +1 -1
- package/lib/module/components/pictograms/svg/PictogramFocusOn.js +7 -7
- package/lib/module/components/pictograms/svg/PictogramFocusOn.js.map +1 -1
- package/lib/module/components/textInput/TextInput.js +4 -0
- package/lib/module/components/textInput/TextInput.js.map +1 -0
- package/lib/module/components/textInput/TextInputBase.js +225 -0
- package/lib/module/components/textInput/TextInputBase.js.map +1 -0
- package/lib/module/components/textInput/TextInputPassword.js +27 -0
- package/lib/module/components/textInput/TextInputPassword.js.map +1 -0
- package/lib/module/components/textInput/TextInputValidation.js +47 -0
- package/lib/module/components/textInput/TextInputValidation.js.map +1 -0
- package/lib/module/components/textInput/index.js +4 -0
- package/lib/module/components/textInput/index.js.map +1 -0
- package/lib/module/core/IOAnimations.js +5 -0
- package/lib/module/core/IOAnimations.js.map +1 -1
- package/lib/module/core/IOShapes.js +1 -0
- package/lib/module/core/IOShapes.js.map +1 -1
- package/lib/module/utils/accessibility.js +10 -0
- package/lib/module/utils/accessibility.js.map +1 -0
- package/lib/module/utils/object.js +7 -0
- package/lib/module/utils/object.js.map +1 -0
- package/lib/module/utils/textInput/index.js +17 -0
- package/lib/module/utils/textInput/index.js.map +1 -0
- package/lib/module/utils/url.js +7 -0
- package/lib/module/utils/url.js.map +1 -0
- package/lib/typescript/components/accordion/AccordionItem.d.ts +14 -0
- package/lib/typescript/components/accordion/AccordionItem.d.ts.map +1 -0
- package/lib/typescript/components/accordion/index.d.ts +1 -1
- package/lib/typescript/components/accordion/index.d.ts.map +1 -1
- package/lib/typescript/components/common/LogoPaymentWithFallback.d.ts +27 -0
- package/lib/typescript/components/common/LogoPaymentWithFallback.d.ts.map +1 -0
- package/lib/typescript/components/index.d.ts +1 -0
- package/lib/typescript/components/index.d.ts.map +1 -1
- package/lib/typescript/components/listitems/ListItemTransaction.d.ts +13 -5
- package/lib/typescript/components/listitems/ListItemTransaction.d.ts.map +1 -1
- package/lib/typescript/components/textInput/TextInput.d.ts +6 -0
- package/lib/typescript/components/textInput/TextInput.d.ts.map +1 -0
- package/lib/typescript/components/textInput/TextInputBase.d.ts +28 -0
- package/lib/typescript/components/textInput/TextInputBase.d.ts.map +1 -0
- package/lib/typescript/components/textInput/TextInputPassword.d.ts +6 -0
- package/lib/typescript/components/textInput/TextInputPassword.d.ts.map +1 -0
- package/lib/typescript/components/textInput/TextInputValidation.d.ts +9 -0
- package/lib/typescript/components/textInput/TextInputValidation.d.ts.map +1 -0
- package/lib/typescript/components/textInput/index.d.ts +4 -0
- package/lib/typescript/components/textInput/index.d.ts.map +1 -0
- package/lib/typescript/core/IOAnimations.d.ts +5 -0
- package/lib/typescript/core/IOAnimations.d.ts.map +1 -1
- package/lib/typescript/core/IOShapes.d.ts +1 -0
- package/lib/typescript/core/IOShapes.d.ts.map +1 -1
- package/lib/typescript/utils/accessibility.d.ts +6 -0
- package/lib/typescript/utils/accessibility.d.ts.map +1 -0
- package/lib/typescript/utils/object.d.ts +5 -0
- package/lib/typescript/utils/object.d.ts.map +1 -0
- package/lib/typescript/utils/textInput/index.d.ts +9 -0
- package/lib/typescript/utils/textInput/index.d.ts.map +1 -0
- package/lib/typescript/utils/types.d.ts +1 -0
- package/lib/typescript/utils/types.d.ts.map +1 -1
- package/lib/typescript/utils/url.d.ts +8 -0
- package/lib/typescript/utils/url.d.ts.map +1 -0
- package/package.json +1 -1
- package/src/components/accordion/AccordionItem.tsx +165 -0
- package/src/components/accordion/index.tsx +1 -1
- package/src/components/common/LogoPaymentWithFallback.tsx +60 -0
- package/src/components/index.tsx +1 -0
- package/src/components/listitems/ListItemTransaction.tsx +86 -39
- package/src/components/pictograms/svg/PictogramFocusOn.tsx +9 -9
- package/src/components/textInput/TextInput.tsx +15 -0
- package/src/components/textInput/TextInputBase.tsx +327 -0
- package/src/components/textInput/TextInputPassword.tsx +36 -0
- package/src/components/textInput/TextInputValidation.tsx +71 -0
- package/src/components/textInput/index.tsx +3 -0
- package/src/core/IOAnimations.ts +5 -0
- package/src/core/IOShapes.ts +1 -0
- package/src/utils/accessibility.ts +17 -0
- package/src/utils/object.ts +12 -0
- package/src/utils/textInput/index.ts +29 -0
- package/src/utils/types.ts +2 -0
- package/src/utils/url.ts +9 -0
- package/lib/commonjs/components/accordion/IOAccordion.js.map +0 -1
- package/lib/module/components/accordion/IOAccordion.js +0 -26
- package/lib/module/components/accordion/IOAccordion.js.map +0 -1
- package/lib/typescript/components/accordion/IOAccordion.d.ts +0 -13
- package/lib/typescript/components/accordion/IOAccordion.d.ts.map +0 -1
- package/src/components/accordion/IOAccordion.tsx +0 -35
|
@@ -0,0 +1,327 @@
|
|
|
1
|
+
/* eslint-disable functional/immutable-data */
|
|
2
|
+
import {
|
|
3
|
+
Pressable,
|
|
4
|
+
StyleSheet,
|
|
5
|
+
TextInput,
|
|
6
|
+
View,
|
|
7
|
+
ViewStyle
|
|
8
|
+
} from "react-native";
|
|
9
|
+
import React, { useCallback, useEffect, useMemo, useRef } from "react";
|
|
10
|
+
import Animated, {
|
|
11
|
+
Easing,
|
|
12
|
+
useAnimatedStyle,
|
|
13
|
+
useSharedValue,
|
|
14
|
+
withTiming
|
|
15
|
+
} from "react-native-reanimated";
|
|
16
|
+
import { IOColors, IOSpacingScale, IOStyles } from "../../core";
|
|
17
|
+
import { IOIcons, Icon } from "../icons";
|
|
18
|
+
import { HSpacer } from "../spacer";
|
|
19
|
+
import { LabelSmall } from "../typography";
|
|
20
|
+
import { InputType } from "../../utils/types";
|
|
21
|
+
import { getInputPropsByType } from "../../utils/textInput";
|
|
22
|
+
|
|
23
|
+
type InputStatus = "initial" | "focused" | "disabled" | "error";
|
|
24
|
+
|
|
25
|
+
type RNTextInputProps = Pick<
|
|
26
|
+
React.ComponentProps<typeof TextInput>,
|
|
27
|
+
"keyboardType" | "inputMode" | "textContentType" | "autoComplete"
|
|
28
|
+
>;
|
|
29
|
+
|
|
30
|
+
type InputTextProps = {
|
|
31
|
+
placeholder: string;
|
|
32
|
+
value: string;
|
|
33
|
+
onChangeText: (value: string) => void;
|
|
34
|
+
accessibilityLabel?: string;
|
|
35
|
+
textInputProps?: RNTextInputProps;
|
|
36
|
+
inputTyoe?: InputType;
|
|
37
|
+
status?: InputStatus;
|
|
38
|
+
icon?: IOIcons;
|
|
39
|
+
rightElement?: React.ReactNode;
|
|
40
|
+
counterLimit?: number;
|
|
41
|
+
bottomMessage?: string;
|
|
42
|
+
bottomMessageColor?: IOColors;
|
|
43
|
+
disabled?: boolean;
|
|
44
|
+
isPassword?: boolean;
|
|
45
|
+
onBlur?: () => void;
|
|
46
|
+
onFocus?: () => void;
|
|
47
|
+
};
|
|
48
|
+
|
|
49
|
+
const styles = StyleSheet.create({
|
|
50
|
+
textInput: {
|
|
51
|
+
...IOStyles.row,
|
|
52
|
+
alignItems: "center",
|
|
53
|
+
paddingVertical: 8,
|
|
54
|
+
height: 60,
|
|
55
|
+
borderRadius: 8,
|
|
56
|
+
paddingHorizontal: 12
|
|
57
|
+
},
|
|
58
|
+
textInputStyle: {
|
|
59
|
+
...IOStyles.flex,
|
|
60
|
+
fontSize: 16,
|
|
61
|
+
marginTop: IOSpacingScale[2],
|
|
62
|
+
fontWeight: "400",
|
|
63
|
+
lineHeight: 24,
|
|
64
|
+
fontFamily: "Readex Pro",
|
|
65
|
+
height: "100%"
|
|
66
|
+
},
|
|
67
|
+
textInputLabelWrapper: {
|
|
68
|
+
position: "absolute",
|
|
69
|
+
paddingHorizontal: 12,
|
|
70
|
+
zIndex: 10,
|
|
71
|
+
bottom: 0,
|
|
72
|
+
top: 0,
|
|
73
|
+
justifyContent: "center"
|
|
74
|
+
}
|
|
75
|
+
});
|
|
76
|
+
|
|
77
|
+
type InputTextHelperRow = Pick<
|
|
78
|
+
InputTextProps,
|
|
79
|
+
"value" | "counterLimit" | "bottomMessage" | "bottomMessageColor"
|
|
80
|
+
>;
|
|
81
|
+
|
|
82
|
+
const HelperRow = ({
|
|
83
|
+
value,
|
|
84
|
+
counterLimit,
|
|
85
|
+
bottomMessage,
|
|
86
|
+
bottomMessageColor = "grey-700"
|
|
87
|
+
}: InputTextHelperRow) => {
|
|
88
|
+
const valueCount = useMemo(() => value.length, [value]);
|
|
89
|
+
|
|
90
|
+
const helperRowStyle: ViewStyle = useMemo(() => {
|
|
91
|
+
if (counterLimit && bottomMessage) {
|
|
92
|
+
return {
|
|
93
|
+
justifyContent: "space-between"
|
|
94
|
+
};
|
|
95
|
+
}
|
|
96
|
+
if (counterLimit) {
|
|
97
|
+
return {
|
|
98
|
+
justifyContent: "flex-end"
|
|
99
|
+
};
|
|
100
|
+
}
|
|
101
|
+
if (bottomMessage) {
|
|
102
|
+
return {
|
|
103
|
+
justifyContent: "flex-start"
|
|
104
|
+
};
|
|
105
|
+
}
|
|
106
|
+
return {};
|
|
107
|
+
}, [counterLimit, bottomMessage]);
|
|
108
|
+
|
|
109
|
+
return (
|
|
110
|
+
<View
|
|
111
|
+
style={[
|
|
112
|
+
IOStyles.row,
|
|
113
|
+
{
|
|
114
|
+
alignItems: "center",
|
|
115
|
+
paddingHorizontal: 10
|
|
116
|
+
},
|
|
117
|
+
helperRowStyle
|
|
118
|
+
]}
|
|
119
|
+
>
|
|
120
|
+
{bottomMessage && (
|
|
121
|
+
<LabelSmall weight="Regular" color={bottomMessageColor}>
|
|
122
|
+
{bottomMessage}
|
|
123
|
+
</LabelSmall>
|
|
124
|
+
)}
|
|
125
|
+
{counterLimit && (
|
|
126
|
+
<LabelSmall
|
|
127
|
+
weight="Regular"
|
|
128
|
+
color="grey-700"
|
|
129
|
+
>{`${valueCount} / ${counterLimit}`}</LabelSmall>
|
|
130
|
+
)}
|
|
131
|
+
</View>
|
|
132
|
+
);
|
|
133
|
+
};
|
|
134
|
+
|
|
135
|
+
export const TextInputBase = ({
|
|
136
|
+
disabled = false,
|
|
137
|
+
placeholder,
|
|
138
|
+
value = "",
|
|
139
|
+
onChangeText,
|
|
140
|
+
accessibilityLabel,
|
|
141
|
+
textInputProps,
|
|
142
|
+
inputTyoe = "default",
|
|
143
|
+
status,
|
|
144
|
+
icon,
|
|
145
|
+
rightElement,
|
|
146
|
+
counterLimit,
|
|
147
|
+
bottomMessage,
|
|
148
|
+
bottomMessageColor,
|
|
149
|
+
onBlur,
|
|
150
|
+
onFocus,
|
|
151
|
+
isPassword
|
|
152
|
+
}: InputTextProps) => {
|
|
153
|
+
const labelSharedValue = useSharedValue<boolean>(false);
|
|
154
|
+
const [inputStatus, setInputStatus] = React.useState<InputStatus>(
|
|
155
|
+
disabled ? "disabled" : "initial"
|
|
156
|
+
);
|
|
157
|
+
const isSecretInput = useMemo(() => isPassword, [isPassword]);
|
|
158
|
+
const inputRef = useRef<TextInput>(null);
|
|
159
|
+
|
|
160
|
+
useEffect(() => {
|
|
161
|
+
if (status) {
|
|
162
|
+
setInputStatus(status);
|
|
163
|
+
}
|
|
164
|
+
}, [status]);
|
|
165
|
+
|
|
166
|
+
const boxStyle: ViewStyle = useMemo(() => {
|
|
167
|
+
if (inputStatus === "focused") {
|
|
168
|
+
return {
|
|
169
|
+
borderColor: IOColors["blueIO-500"],
|
|
170
|
+
borderWidth: 2
|
|
171
|
+
};
|
|
172
|
+
}
|
|
173
|
+
if (inputStatus === "error") {
|
|
174
|
+
return {
|
|
175
|
+
borderColor: IOColors["error-600"],
|
|
176
|
+
borderWidth: 1
|
|
177
|
+
};
|
|
178
|
+
}
|
|
179
|
+
return {
|
|
180
|
+
borderColor: IOColors["grey-200"],
|
|
181
|
+
borderWidth: 1
|
|
182
|
+
};
|
|
183
|
+
}, [inputStatus]);
|
|
184
|
+
|
|
185
|
+
const animatedLabelProps = useAnimatedStyle(() => ({
|
|
186
|
+
fontSize: withTiming(labelSharedValue.value ? 12 : 16, {
|
|
187
|
+
duration: 300,
|
|
188
|
+
easing: Easing.elastic(0.85)
|
|
189
|
+
}),
|
|
190
|
+
transform: [
|
|
191
|
+
{
|
|
192
|
+
translateY: withTiming(labelSharedValue.value ? -14 : 0, {
|
|
193
|
+
duration: 300,
|
|
194
|
+
easing: Easing.elastic(0.85)
|
|
195
|
+
})
|
|
196
|
+
}
|
|
197
|
+
]
|
|
198
|
+
}));
|
|
199
|
+
|
|
200
|
+
useEffect(() => {
|
|
201
|
+
if (value.length > 0) {
|
|
202
|
+
labelSharedValue.value = true;
|
|
203
|
+
} else {
|
|
204
|
+
if (inputStatus !== "focused") {
|
|
205
|
+
labelSharedValue.value = false;
|
|
206
|
+
}
|
|
207
|
+
}
|
|
208
|
+
}, [labelSharedValue, value, inputStatus]);
|
|
209
|
+
|
|
210
|
+
const onTextInputPress = () => {
|
|
211
|
+
if (disabled) {
|
|
212
|
+
return;
|
|
213
|
+
}
|
|
214
|
+
labelSharedValue.value = true;
|
|
215
|
+
setInputStatus("focused");
|
|
216
|
+
inputRef?.current?.focus();
|
|
217
|
+
};
|
|
218
|
+
|
|
219
|
+
const onChangeTextHandler = useCallback(
|
|
220
|
+
(text: string) => {
|
|
221
|
+
if (counterLimit && text.length > counterLimit) {
|
|
222
|
+
return;
|
|
223
|
+
}
|
|
224
|
+
onChangeText(text);
|
|
225
|
+
},
|
|
226
|
+
[counterLimit, onChangeText]
|
|
227
|
+
);
|
|
228
|
+
|
|
229
|
+
const onBlurHandler = useCallback(() => {
|
|
230
|
+
if (!value) {
|
|
231
|
+
labelSharedValue.value = false;
|
|
232
|
+
}
|
|
233
|
+
onBlur?.();
|
|
234
|
+
setInputStatus("initial");
|
|
235
|
+
}, [value, labelSharedValue, onBlur]);
|
|
236
|
+
|
|
237
|
+
const derivedInputProps = useMemo(
|
|
238
|
+
() => getInputPropsByType(inputTyoe),
|
|
239
|
+
[inputTyoe]
|
|
240
|
+
);
|
|
241
|
+
|
|
242
|
+
const inputValue = useMemo(
|
|
243
|
+
() =>
|
|
244
|
+
derivedInputProps && derivedInputProps.valueFormat
|
|
245
|
+
? derivedInputProps.valueFormat(value)
|
|
246
|
+
: value,
|
|
247
|
+
[value, derivedInputProps]
|
|
248
|
+
);
|
|
249
|
+
|
|
250
|
+
return (
|
|
251
|
+
<>
|
|
252
|
+
<Pressable
|
|
253
|
+
onPress={onTextInputPress}
|
|
254
|
+
style={[
|
|
255
|
+
inputStatus === "disabled" ? { opacity: 0.5 } : {},
|
|
256
|
+
boxStyle,
|
|
257
|
+
styles.textInput
|
|
258
|
+
]}
|
|
259
|
+
accessible={false}
|
|
260
|
+
accessibilityRole={"none"}
|
|
261
|
+
>
|
|
262
|
+
{icon && (
|
|
263
|
+
<>
|
|
264
|
+
<Icon name={icon} color="grey-300" size={24} />
|
|
265
|
+
<HSpacer size={8} />
|
|
266
|
+
</>
|
|
267
|
+
)}
|
|
268
|
+
<TextInput
|
|
269
|
+
{...(derivedInputProps
|
|
270
|
+
? derivedInputProps.textInputProps
|
|
271
|
+
: textInputProps)}
|
|
272
|
+
accessible
|
|
273
|
+
editable={!disabled}
|
|
274
|
+
secureTextEntry={isSecretInput}
|
|
275
|
+
disableFullscreenUI={true}
|
|
276
|
+
blurOnSubmit={true}
|
|
277
|
+
ref={inputRef}
|
|
278
|
+
accessibilityState={{ disabled }}
|
|
279
|
+
accessibilityLabel={accessibilityLabel ?? placeholder}
|
|
280
|
+
onFocus={() => {
|
|
281
|
+
setInputStatus("focused");
|
|
282
|
+
labelSharedValue.value = true;
|
|
283
|
+
onFocus?.();
|
|
284
|
+
}}
|
|
285
|
+
maxLength={counterLimit}
|
|
286
|
+
onBlur={onBlurHandler}
|
|
287
|
+
value={inputValue}
|
|
288
|
+
onChangeText={onChangeTextHandler}
|
|
289
|
+
style={styles.textInputStyle}
|
|
290
|
+
/>
|
|
291
|
+
{/** Left value is due to the absolute position of the label in order to let it
|
|
292
|
+
* translate to top on focus
|
|
293
|
+
*/}
|
|
294
|
+
<Animated.View
|
|
295
|
+
style={[styles.textInputLabelWrapper, icon ? { left: 32 } : {}]}
|
|
296
|
+
>
|
|
297
|
+
<Animated.Text
|
|
298
|
+
numberOfLines={1}
|
|
299
|
+
accessible={false}
|
|
300
|
+
style={[
|
|
301
|
+
animatedLabelProps,
|
|
302
|
+
{
|
|
303
|
+
color: IOColors["grey-700"]
|
|
304
|
+
}
|
|
305
|
+
]}
|
|
306
|
+
>
|
|
307
|
+
{placeholder}
|
|
308
|
+
</Animated.Text>
|
|
309
|
+
</Animated.View>
|
|
310
|
+
{rightElement && (
|
|
311
|
+
<View style={{ marginLeft: "auto" }}>
|
|
312
|
+
<HSpacer size={8} />
|
|
313
|
+
{rightElement}
|
|
314
|
+
</View>
|
|
315
|
+
)}
|
|
316
|
+
</Pressable>
|
|
317
|
+
{(bottomMessage || counterLimit) && (
|
|
318
|
+
<HelperRow
|
|
319
|
+
value={value}
|
|
320
|
+
bottomMessage={bottomMessage}
|
|
321
|
+
bottomMessageColor={bottomMessageColor}
|
|
322
|
+
counterLimit={counterLimit}
|
|
323
|
+
/>
|
|
324
|
+
)}
|
|
325
|
+
</>
|
|
326
|
+
);
|
|
327
|
+
};
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { IconButton } from "../buttons";
|
|
3
|
+
import { TextInputBase } from "./TextInputBase";
|
|
4
|
+
|
|
5
|
+
type TextInputPasswordProps = Omit<
|
|
6
|
+
React.ComponentProps<typeof TextInputBase>,
|
|
7
|
+
"isPassword"
|
|
8
|
+
>;
|
|
9
|
+
|
|
10
|
+
export const TextInputPassword = (props: TextInputPasswordProps) => {
|
|
11
|
+
const { onBlur, disabled } = props;
|
|
12
|
+
const [showPassword, setShowPassword] = React.useState<boolean>(false);
|
|
13
|
+
|
|
14
|
+
const rightElement = (
|
|
15
|
+
<IconButton
|
|
16
|
+
icon={showPassword ? "eyeShow" : "eyeHide"}
|
|
17
|
+
disabled={disabled}
|
|
18
|
+
onPress={() => setShowPassword(v => !v)}
|
|
19
|
+
accessibilityLabel="Toggle secret input"
|
|
20
|
+
/>
|
|
21
|
+
);
|
|
22
|
+
|
|
23
|
+
const onBlurHandler = React.useCallback(() => {
|
|
24
|
+
setShowPassword(false);
|
|
25
|
+
onBlur?.();
|
|
26
|
+
}, [onBlur]);
|
|
27
|
+
|
|
28
|
+
return (
|
|
29
|
+
<TextInputBase
|
|
30
|
+
{...props}
|
|
31
|
+
onBlur={onBlurHandler}
|
|
32
|
+
rightElement={rightElement}
|
|
33
|
+
isPassword={!showPassword}
|
|
34
|
+
/>
|
|
35
|
+
);
|
|
36
|
+
};
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { IOIcons, Icon } from "../icons";
|
|
3
|
+
import { IOColors } from "../../core/IOColors";
|
|
4
|
+
import { triggerHaptic } from "../../functions";
|
|
5
|
+
import { TextInputBase } from "./TextInputBase";
|
|
6
|
+
|
|
7
|
+
type TextInputValidationProps = Omit<
|
|
8
|
+
React.ComponentProps<typeof TextInputBase>,
|
|
9
|
+
"rightElement" | "status" | "bottomMessageColor" | "isPassword"
|
|
10
|
+
> & {
|
|
11
|
+
onValidate: (value: string) => boolean;
|
|
12
|
+
errorMessage?: string;
|
|
13
|
+
};
|
|
14
|
+
|
|
15
|
+
export const TextInputValidation = (props: TextInputValidationProps) => {
|
|
16
|
+
const { onValidate, errorMessage, value, bottomMessage, onBlur, onFocus } =
|
|
17
|
+
props;
|
|
18
|
+
const [isValid, setIsValid] = React.useState<boolean | undefined>(undefined);
|
|
19
|
+
|
|
20
|
+
const onBlurHandler = React.useCallback(() => {
|
|
21
|
+
const validation = onValidate(value);
|
|
22
|
+
setIsValid(validation);
|
|
23
|
+
if (!validation) {
|
|
24
|
+
triggerHaptic("notificationError");
|
|
25
|
+
} else {
|
|
26
|
+
triggerHaptic("notificationSuccess");
|
|
27
|
+
}
|
|
28
|
+
onBlur?.();
|
|
29
|
+
}, [onValidate, value, onBlur]);
|
|
30
|
+
|
|
31
|
+
const onFocusHandler = React.useCallback(() => {
|
|
32
|
+
setIsValid(undefined);
|
|
33
|
+
onFocus?.();
|
|
34
|
+
}, [onFocus]);
|
|
35
|
+
|
|
36
|
+
const labelError = React.useMemo(
|
|
37
|
+
() => (isValid === false && errorMessage ? errorMessage : bottomMessage),
|
|
38
|
+
[isValid, errorMessage, bottomMessage]
|
|
39
|
+
);
|
|
40
|
+
|
|
41
|
+
const labelErrorColor: IOColors | undefined = React.useMemo(
|
|
42
|
+
() => (isValid === false && errorMessage ? "error-600" : undefined),
|
|
43
|
+
[isValid, errorMessage]
|
|
44
|
+
);
|
|
45
|
+
|
|
46
|
+
const rightIcon = React.useMemo(
|
|
47
|
+
() =>
|
|
48
|
+
isValid !== undefined && (
|
|
49
|
+
<Icon
|
|
50
|
+
name={(isValid ? "success" : "errorFilled") as IOIcons}
|
|
51
|
+
color={(isValid ? "green" : "error-600") as IOColors}
|
|
52
|
+
size={24}
|
|
53
|
+
/>
|
|
54
|
+
),
|
|
55
|
+
[isValid]
|
|
56
|
+
);
|
|
57
|
+
|
|
58
|
+
return (
|
|
59
|
+
<TextInputBase
|
|
60
|
+
{...props}
|
|
61
|
+
status={isValid === false ? "error" : undefined}
|
|
62
|
+
bottomMessage={labelError}
|
|
63
|
+
bottomMessageColor={labelErrorColor}
|
|
64
|
+
rightElement={rightIcon}
|
|
65
|
+
onBlur={onBlurHandler}
|
|
66
|
+
onFocus={onFocusHandler}
|
|
67
|
+
/>
|
|
68
|
+
);
|
|
69
|
+
};
|
|
70
|
+
|
|
71
|
+
export default TextInputValidation;
|
package/src/core/IOAnimations.ts
CHANGED
package/src/core/IOShapes.ts
CHANGED
|
@@ -18,3 +18,4 @@ export const IOTagRadius: IORadiusScale = 6;
|
|
|
18
18
|
export const IOBottomSheetHeaderRadius: IORadiusScale = 24;
|
|
19
19
|
export const IOListItemIDPRadius: IORadiusScale = IODefaultRadius;
|
|
20
20
|
export const IOBadgeRadius: IORadiusScale = 24;
|
|
21
|
+
export const IOAccordionRadius: IORadiusScale = IODefaultRadius;
|
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
import { pipe } from "fp-ts/lib/function";
|
|
2
|
+
import * as O from "fp-ts/lib/Option";
|
|
3
|
+
import I18n from "i18n-js";
|
|
4
|
+
|
|
5
|
+
/**
|
|
6
|
+
* This function is used to get the text that will be read by the screen reader
|
|
7
|
+
* with the correct minus symbol pronunciation.
|
|
8
|
+
*/
|
|
9
|
+
export const getAccessibleAmountText = (amount?: string) =>
|
|
10
|
+
pipe(
|
|
11
|
+
amount,
|
|
12
|
+
O.fromNullable,
|
|
13
|
+
O.map(amount =>
|
|
14
|
+
amount.replace("-", I18n.t("global.accessibility.minusSymbol"))
|
|
15
|
+
),
|
|
16
|
+
O.getOrElseW(() => undefined)
|
|
17
|
+
);
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
import * as A from "fp-ts/Array";
|
|
2
|
+
import * as O from "fp-ts/Option";
|
|
3
|
+
import { pipe } from "fp-ts/lib/function";
|
|
4
|
+
|
|
5
|
+
export const findFirstCaseInsensitive =
|
|
6
|
+
<T>(obj: { [key: string]: T }) =>
|
|
7
|
+
(key: string): O.Option<[string, T]> =>
|
|
8
|
+
pipe(
|
|
9
|
+
obj,
|
|
10
|
+
Object.entries,
|
|
11
|
+
A.findFirst(([k, _]) => k.toLowerCase() === key.toLowerCase())
|
|
12
|
+
);
|
|
@@ -0,0 +1,29 @@
|
|
|
1
|
+
import * as React from "react";
|
|
2
|
+
import { TextInputBase } from "../../components/textInput/TextInputBase";
|
|
3
|
+
import { InputType } from "../types";
|
|
4
|
+
|
|
5
|
+
type InputProps = Pick<
|
|
6
|
+
React.ComponentProps<typeof TextInputBase>,
|
|
7
|
+
"textInputProps"
|
|
8
|
+
> & {
|
|
9
|
+
valueFormat?: (value: string) => string;
|
|
10
|
+
};
|
|
11
|
+
|
|
12
|
+
export const getInputPropsByType = (
|
|
13
|
+
type: InputType
|
|
14
|
+
): InputProps | undefined => {
|
|
15
|
+
switch (type) {
|
|
16
|
+
case "credit-card":
|
|
17
|
+
return {
|
|
18
|
+
valueFormat: v => v.replace(/\D/g, "").replace(/\d{4}?(?=.)/g, "$& "),
|
|
19
|
+
textInputProps: {
|
|
20
|
+
autoComplete: "cc-number",
|
|
21
|
+
keyboardType: "numeric",
|
|
22
|
+
textContentType: "creditCardNumber",
|
|
23
|
+
inputMode: "numeric"
|
|
24
|
+
}
|
|
25
|
+
};
|
|
26
|
+
default:
|
|
27
|
+
return undefined;
|
|
28
|
+
}
|
|
29
|
+
};
|
package/src/utils/types.ts
CHANGED
package/src/utils/url.ts
ADDED
|
@@ -0,0 +1,9 @@
|
|
|
1
|
+
import { ImageURISource } from "react-native";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* type guard to check if a value is an ImageURISource
|
|
5
|
+
* @argument value the value to check, can be anything
|
|
6
|
+
* @returns boolean
|
|
7
|
+
*/
|
|
8
|
+
export const isImageUri = (value: unknown): value is ImageURISource =>
|
|
9
|
+
typeof value === "object" && value !== null && "uri" in value;
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["React","_interopRequireWildcard","require","_reactNative","_H","_IOStyles","_RawAccordion","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","styles","StyleSheet","create","header","marginVertical","IOVisualCostants","appMarginDefault","IOAccordion","props","createElement","RawAccordion","animated","headerStyle","accessibilityLabel","title","H3","numberOfLines","style","IOStyles","flex","children","exports"],"sourceRoot":"../../../../src","sources":["components/accordion/IOAccordion.tsx"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,EAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,aAAA,GAAAJ,OAAA;AAA8C,SAAAK,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAP,wBAAAW,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAAA,IAAAA,GAAA,CAAAC,UAAA,WAAAD,GAAA,QAAAA,GAAA,oBAAAA,GAAA,wBAAAA,GAAA,4BAAAE,OAAA,EAAAF,GAAA,UAAAG,KAAA,GAAAR,wBAAA,CAAAC,WAAA,OAAAO,KAAA,IAAAA,KAAA,CAAAC,GAAA,CAAAJ,GAAA,YAAAG,KAAA,CAAAE,GAAA,CAAAL,GAAA,SAAAM,MAAA,WAAAC,qBAAA,GAAAC,MAAA,CAAAC,cAAA,IAAAD,MAAA,CAAAE,wBAAA,WAAAC,GAAA,IAAAX,GAAA,QAAAW,GAAA,kBAAAH,MAAA,CAAAI,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAd,GAAA,EAAAW,GAAA,SAAAI,IAAA,GAAAR,qBAAA,GAAAC,MAAA,CAAAE,wBAAA,CAAAV,GAAA,EAAAW,GAAA,cAAAI,IAAA,KAAAA,IAAA,CAAAV,GAAA,IAAAU,IAAA,CAAAC,GAAA,KAAAR,MAAA,CAAAC,cAAA,CAAAH,MAAA,EAAAK,GAAA,EAAAI,IAAA,YAAAT,MAAA,CAAAK,GAAA,IAAAX,GAAA,CAAAW,GAAA,SAAAL,MAAA,CAAAJ,OAAA,GAAAF,GAAA,MAAAG,KAAA,IAAAA,KAAA,CAAAa,GAAA,CAAAhB,GAAA,EAAAM,MAAA,YAAAA,MAAA;AAM9C,MAAMW,MAAM,GAAGC,uBAAU,CAACC,MAAM,CAAC;EAC/BC,MAAM,EAAE;IACNC,cAAc,EAAEC,0BAAgB,CAACC;EACnC;AACF,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACO,MAAMC,WAAW,GAAIC,KAAY,iBACtCrC,KAAA,CAAAsC,aAAA,CAAChC,aAAA,CAAAiC,YAAY;EACXC,QAAQ,EAAEH,KAAK,CAACG,QAAS;EACzBC,WAAW,EAAEZ,MAAM,CAACG,MAAO;EAC3BU,kBAAkB,EAAEL,KAAK,CAACM,KAAM;EAChCX,MAAM,eACJhC,KAAA,CAAAsC,aAAA,CAAClC,EAAA,CAAAwC,EAAE;IAACC,aAAa,EAAE,CAAE;IAACC,KAAK,EAAEC,kBAAQ,CAACC;EAAK,GACxCX,KAAK,CAACM,KACL;AACL,GAEAN,KAAK,CAACY,QACK,CACf;AAACC,OAAA,CAAAd,WAAA,GAAAA,WAAA"}
|
|
@@ -1,26 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { StyleSheet } from "react-native";
|
|
3
|
-
import { H3 } from "../typography/H3";
|
|
4
|
-
import { IOStyles, IOVisualCostants } from "../../core/IOStyles";
|
|
5
|
-
import { RawAccordion } from "./RawAccordion";
|
|
6
|
-
const styles = StyleSheet.create({
|
|
7
|
-
header: {
|
|
8
|
-
marginVertical: IOVisualCostants.appMarginDefault
|
|
9
|
-
}
|
|
10
|
-
});
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* A simplified accordion that accepts a title and one child and uses {@link RawAccordion}
|
|
14
|
-
* @param props
|
|
15
|
-
* @constructor
|
|
16
|
-
*/
|
|
17
|
-
export const IOAccordion = props => /*#__PURE__*/React.createElement(RawAccordion, {
|
|
18
|
-
animated: props.animated,
|
|
19
|
-
headerStyle: styles.header,
|
|
20
|
-
accessibilityLabel: props.title,
|
|
21
|
-
header: /*#__PURE__*/React.createElement(H3, {
|
|
22
|
-
numberOfLines: 1,
|
|
23
|
-
style: IOStyles.flex
|
|
24
|
-
}, props.title)
|
|
25
|
-
}, props.children);
|
|
26
|
-
//# sourceMappingURL=IOAccordion.js.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"names":["React","StyleSheet","H3","IOStyles","IOVisualCostants","RawAccordion","styles","create","header","marginVertical","appMarginDefault","IOAccordion","props","createElement","animated","headerStyle","accessibilityLabel","title","numberOfLines","style","flex","children"],"sourceRoot":"../../../../src","sources":["components/accordion/IOAccordion.tsx"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,UAAU,QAAQ,cAAc;AACzC,SAASC,EAAE,QAAQ,kBAAkB;AACrC,SAASC,QAAQ,EAAEC,gBAAgB,QAAQ,qBAAqB;AAChE,SAASC,YAAY,QAAQ,gBAAgB;AAM7C,MAAMC,MAAM,GAAGL,UAAU,CAACM,MAAM,CAAC;EAC/BC,MAAM,EAAE;IACNC,cAAc,EAAEL,gBAAgB,CAACM;EACnC;AACF,CAAC,CAAC;;AAEF;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,WAAW,GAAIC,KAAY,iBACtCZ,KAAA,CAAAa,aAAA,CAACR,YAAY;EACXS,QAAQ,EAAEF,KAAK,CAACE,QAAS;EACzBC,WAAW,EAAET,MAAM,CAACE,MAAO;EAC3BQ,kBAAkB,EAAEJ,KAAK,CAACK,KAAM;EAChCT,MAAM,eACJR,KAAA,CAAAa,aAAA,CAACX,EAAE;IAACgB,aAAa,EAAE,CAAE;IAACC,KAAK,EAAEhB,QAAQ,CAACiB;EAAK,GACxCR,KAAK,CAACK,KACL;AACL,GAEAL,KAAK,CAACS,QACK,CACf"}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { RawAccordion } from "./RawAccordion";
|
|
3
|
-
type Props = Omit<React.ComponentProps<typeof RawAccordion>, "header"> & {
|
|
4
|
-
title: string;
|
|
5
|
-
};
|
|
6
|
-
/**
|
|
7
|
-
* A simplified accordion that accepts a title and one child and uses {@link RawAccordion}
|
|
8
|
-
* @param props
|
|
9
|
-
* @constructor
|
|
10
|
-
*/
|
|
11
|
-
export declare const IOAccordion: (props: Props) => React.ReactElement;
|
|
12
|
-
export {};
|
|
13
|
-
//# sourceMappingURL=IOAccordion.d.ts.map
|
|
@@ -1 +0,0 @@
|
|
|
1
|
-
{"version":3,"file":"IOAccordion.d.ts","sourceRoot":"","sources":["../../../../src/components/accordion/IOAccordion.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAI/B,OAAO,EAAE,YAAY,EAAE,MAAM,gBAAgB,CAAC;AAE9C,KAAK,KAAK,GAAG,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,YAAY,CAAC,EAAE,QAAQ,CAAC,GAAG;IACvE,KAAK,EAAE,MAAM,CAAC;CACf,CAAC;AAQF;;;;GAIG;AACH,eAAO,MAAM,WAAW,UAAW,KAAK,KAAG,MAAM,YAahD,CAAC"}
|
|
@@ -1,35 +0,0 @@
|
|
|
1
|
-
import * as React from "react";
|
|
2
|
-
import { StyleSheet } from "react-native";
|
|
3
|
-
import { H3 } from "../typography/H3";
|
|
4
|
-
import { IOStyles, IOVisualCostants } from "../../core/IOStyles";
|
|
5
|
-
import { RawAccordion } from "./RawAccordion";
|
|
6
|
-
|
|
7
|
-
type Props = Omit<React.ComponentProps<typeof RawAccordion>, "header"> & {
|
|
8
|
-
title: string;
|
|
9
|
-
};
|
|
10
|
-
|
|
11
|
-
const styles = StyleSheet.create({
|
|
12
|
-
header: {
|
|
13
|
-
marginVertical: IOVisualCostants.appMarginDefault
|
|
14
|
-
}
|
|
15
|
-
});
|
|
16
|
-
|
|
17
|
-
/**
|
|
18
|
-
* A simplified accordion that accepts a title and one child and uses {@link RawAccordion}
|
|
19
|
-
* @param props
|
|
20
|
-
* @constructor
|
|
21
|
-
*/
|
|
22
|
-
export const IOAccordion = (props: Props): React.ReactElement => (
|
|
23
|
-
<RawAccordion
|
|
24
|
-
animated={props.animated}
|
|
25
|
-
headerStyle={styles.header}
|
|
26
|
-
accessibilityLabel={props.title}
|
|
27
|
-
header={
|
|
28
|
-
<H3 numberOfLines={1} style={IOStyles.flex}>
|
|
29
|
-
{props.title}
|
|
30
|
-
</H3>
|
|
31
|
-
}
|
|
32
|
-
>
|
|
33
|
-
{props.children}
|
|
34
|
-
</RawAccordion>
|
|
35
|
-
);
|