@pagopa/io-app-design-system 7.0.2 → 7.1.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/lib/commonjs/components/alert/Alert.js +6 -5
- package/lib/commonjs/components/alert/Alert.js.map +1 -1
- package/lib/commonjs/components/banner/Banner.js +7 -6
- package/lib/commonjs/components/banner/Banner.js.map +1 -1
- package/lib/commonjs/components/buttons/IOButton/IOButton.js +10 -8
- package/lib/commonjs/components/buttons/IOButton/IOButton.js.map +1 -1
- package/lib/commonjs/components/layout/ContentWrapper.js +5 -4
- package/lib/commonjs/components/layout/ContentWrapper.js.map +1 -1
- package/lib/commonjs/components/otpInput/OTPInput.js +6 -4
- package/lib/commonjs/components/otpInput/OTPInput.js.map +1 -1
- package/lib/commonjs/components/searchInput/SearchInput.js +8 -6
- package/lib/commonjs/components/searchInput/SearchInput.js.map +1 -1
- package/lib/commonjs/components/tabs/TabItem.js +6 -4
- package/lib/commonjs/components/tabs/TabItem.js.map +1 -1
- package/lib/commonjs/components/textInput/TextInputValidation.js +5 -3
- package/lib/commonjs/components/textInput/TextInputValidation.js.map +1 -1
- package/lib/commonjs/components/typography/Body.js +8 -5
- package/lib/commonjs/components/typography/Body.js.map +1 -1
- package/lib/commonjs/components/typography/BodyMonospace.js +4 -5
- package/lib/commonjs/components/typography/BodyMonospace.js.map +1 -1
- package/lib/commonjs/components/typography/BodySmall.js +8 -5
- package/lib/commonjs/components/typography/BodySmall.js.map +1 -1
- package/lib/commonjs/components/typography/ButtonText.js +4 -5
- package/lib/commonjs/components/typography/ButtonText.js.map +1 -1
- package/lib/commonjs/components/typography/Caption.js +4 -5
- package/lib/commonjs/components/typography/Caption.js.map +1 -1
- package/lib/commonjs/components/typography/H1.js +4 -5
- package/lib/commonjs/components/typography/H1.js.map +1 -1
- package/lib/commonjs/components/typography/H2.js +4 -5
- package/lib/commonjs/components/typography/H2.js.map +1 -1
- package/lib/commonjs/components/typography/H3.js +4 -5
- package/lib/commonjs/components/typography/H3.js.map +1 -1
- package/lib/commonjs/components/typography/H4.js +4 -5
- package/lib/commonjs/components/typography/H4.js.map +1 -1
- package/lib/commonjs/components/typography/H5.js +4 -5
- package/lib/commonjs/components/typography/H5.js.map +1 -1
- package/lib/commonjs/components/typography/H6.js +4 -5
- package/lib/commonjs/components/typography/H6.js.map +1 -1
- package/lib/commonjs/components/typography/Hero.js +4 -5
- package/lib/commonjs/components/typography/Hero.js.map +1 -1
- package/lib/commonjs/components/typography/IOText.js +16 -14
- package/lib/commonjs/components/typography/IOText.js.map +1 -1
- package/lib/commonjs/components/typography/LabelMini.js +8 -5
- package/lib/commonjs/components/typography/LabelMini.js.map +1 -1
- package/lib/commonjs/components/typography/markdown/MdH1.js +4 -5
- package/lib/commonjs/components/typography/markdown/MdH1.js.map +1 -1
- package/lib/commonjs/components/typography/markdown/MdH2.js +4 -5
- package/lib/commonjs/components/typography/markdown/MdH2.js.map +1 -1
- package/lib/commonjs/components/typography/markdown/MdH3.js +4 -5
- package/lib/commonjs/components/typography/markdown/MdH3.js.map +1 -1
- package/lib/commonjs/context/IOThemeContextProvider.js +3 -4
- package/lib/commonjs/context/IOThemeContextProvider.js.map +1 -1
- package/lib/module/components/alert/Alert.js +5 -5
- package/lib/module/components/alert/Alert.js.map +1 -1
- package/lib/module/components/banner/Banner.js +6 -6
- package/lib/module/components/banner/Banner.js.map +1 -1
- package/lib/module/components/buttons/IOButton/IOButton.js +10 -9
- package/lib/module/components/buttons/IOButton/IOButton.js.map +1 -1
- package/lib/module/components/layout/ContentWrapper.js +4 -4
- package/lib/module/components/layout/ContentWrapper.js.map +1 -1
- package/lib/module/components/otpInput/OTPInput.js +6 -5
- package/lib/module/components/otpInput/OTPInput.js.map +1 -1
- package/lib/module/components/searchInput/SearchInput.js +8 -7
- package/lib/module/components/searchInput/SearchInput.js.map +1 -1
- package/lib/module/components/tabs/TabItem.js +6 -5
- package/lib/module/components/tabs/TabItem.js.map +1 -1
- package/lib/module/components/textInput/TextInputValidation.js +5 -4
- package/lib/module/components/textInput/TextInputValidation.js.map +1 -1
- package/lib/module/components/typography/Body.js +7 -5
- package/lib/module/components/typography/Body.js.map +1 -1
- package/lib/module/components/typography/BodyMonospace.js +3 -5
- package/lib/module/components/typography/BodyMonospace.js.map +1 -1
- package/lib/module/components/typography/BodySmall.js +7 -5
- package/lib/module/components/typography/BodySmall.js.map +1 -1
- package/lib/module/components/typography/ButtonText.js +3 -5
- package/lib/module/components/typography/ButtonText.js.map +1 -1
- package/lib/module/components/typography/Caption.js +3 -5
- package/lib/module/components/typography/Caption.js.map +1 -1
- package/lib/module/components/typography/H1.js +3 -5
- package/lib/module/components/typography/H1.js.map +1 -1
- package/lib/module/components/typography/H2.js +3 -5
- package/lib/module/components/typography/H2.js.map +1 -1
- package/lib/module/components/typography/H3.js +3 -5
- package/lib/module/components/typography/H3.js.map +1 -1
- package/lib/module/components/typography/H4.js +3 -5
- package/lib/module/components/typography/H4.js.map +1 -1
- package/lib/module/components/typography/H5.js +3 -5
- package/lib/module/components/typography/H5.js.map +1 -1
- package/lib/module/components/typography/H6.js +3 -5
- package/lib/module/components/typography/H6.js.map +1 -1
- package/lib/module/components/typography/Hero.js +3 -5
- package/lib/module/components/typography/Hero.js.map +1 -1
- package/lib/module/components/typography/IOText.js +16 -15
- package/lib/module/components/typography/IOText.js.map +1 -1
- package/lib/module/components/typography/LabelMini.js +7 -5
- package/lib/module/components/typography/LabelMini.js.map +1 -1
- package/lib/module/components/typography/markdown/MdH1.js +3 -5
- package/lib/module/components/typography/markdown/MdH1.js.map +1 -1
- package/lib/module/components/typography/markdown/MdH2.js +3 -5
- package/lib/module/components/typography/markdown/MdH2.js.map +1 -1
- package/lib/module/components/typography/markdown/MdH3.js +3 -5
- package/lib/module/components/typography/markdown/MdH3.js.map +1 -1
- package/lib/module/context/IOThemeContextProvider.js +3 -4
- package/lib/module/context/IOThemeContextProvider.js.map +1 -1
- package/lib/typescript/components/alert/Alert.d.ts +3 -1
- package/lib/typescript/components/alert/Alert.d.ts.map +1 -1
- package/lib/typescript/components/banner/Banner.d.ts +3 -1
- package/lib/typescript/components/banner/Banner.d.ts.map +1 -1
- package/lib/typescript/components/buttons/IOButton/IOButton.d.ts +3 -2
- package/lib/typescript/components/buttons/IOButton/IOButton.d.ts.map +1 -1
- package/lib/typescript/components/layout/ContentWrapper.d.ts +10 -6
- package/lib/typescript/components/layout/ContentWrapper.d.ts.map +1 -1
- package/lib/typescript/components/otpInput/OTPInput.d.ts +3 -1
- package/lib/typescript/components/otpInput/OTPInput.d.ts.map +1 -1
- package/lib/typescript/components/searchInput/SearchInput.d.ts +3 -1
- package/lib/typescript/components/searchInput/SearchInput.d.ts.map +1 -1
- package/lib/typescript/components/tabs/TabItem.d.ts +3 -11
- package/lib/typescript/components/tabs/TabItem.d.ts.map +1 -1
- package/lib/typescript/components/textInput/TextInputValidation.d.ts +7 -24
- package/lib/typescript/components/textInput/TextInputValidation.d.ts.map +1 -1
- package/lib/typescript/components/typography/Body.d.ts +4 -2
- package/lib/typescript/components/typography/Body.d.ts.map +1 -1
- package/lib/typescript/components/typography/BodyMonospace.d.ts +2 -8
- package/lib/typescript/components/typography/BodyMonospace.d.ts.map +1 -1
- package/lib/typescript/components/typography/BodySmall.d.ts +4 -2
- package/lib/typescript/components/typography/BodySmall.d.ts.map +1 -1
- package/lib/typescript/components/typography/ButtonText.d.ts +2 -8
- package/lib/typescript/components/typography/ButtonText.d.ts.map +1 -1
- package/lib/typescript/components/typography/Caption.d.ts +2 -8
- package/lib/typescript/components/typography/Caption.d.ts.map +1 -1
- package/lib/typescript/components/typography/H1.d.ts +2 -8
- package/lib/typescript/components/typography/H1.d.ts.map +1 -1
- package/lib/typescript/components/typography/H2.d.ts +6 -10
- package/lib/typescript/components/typography/H2.d.ts.map +1 -1
- package/lib/typescript/components/typography/H3.d.ts +2 -8
- package/lib/typescript/components/typography/H3.d.ts.map +1 -1
- package/lib/typescript/components/typography/H4.d.ts +2 -8
- package/lib/typescript/components/typography/H4.d.ts.map +1 -1
- package/lib/typescript/components/typography/H5.d.ts +2 -8
- package/lib/typescript/components/typography/H5.d.ts.map +1 -1
- package/lib/typescript/components/typography/H6.d.ts +2 -8
- package/lib/typescript/components/typography/H6.d.ts.map +1 -1
- package/lib/typescript/components/typography/Hero.d.ts +2 -8
- package/lib/typescript/components/typography/Hero.d.ts.map +1 -1
- package/lib/typescript/components/typography/IOText.d.ts +5 -5
- package/lib/typescript/components/typography/IOText.d.ts.map +1 -1
- package/lib/typescript/components/typography/LabelMini.d.ts +4 -2
- package/lib/typescript/components/typography/LabelMini.d.ts.map +1 -1
- package/lib/typescript/components/typography/markdown/MdH1.d.ts +2 -8
- package/lib/typescript/components/typography/markdown/MdH1.d.ts.map +1 -1
- package/lib/typescript/components/typography/markdown/MdH2.d.ts +2 -8
- package/lib/typescript/components/typography/markdown/MdH2.d.ts.map +1 -1
- package/lib/typescript/components/typography/markdown/MdH3.d.ts +2 -8
- package/lib/typescript/components/typography/markdown/MdH3.d.ts.map +1 -1
- package/lib/typescript/context/IOThemeContextProvider.d.ts.map +1 -1
- package/package.json +6 -7
- package/src/components/alert/Alert.tsx +108 -112
- package/src/components/banner/Banner.tsx +121 -125
- package/src/components/buttons/IOButton/IOButton.tsx +204 -216
- package/src/components/layout/ContentWrapper.tsx +21 -24
- package/src/components/otpInput/OTPInput.tsx +156 -167
- package/src/components/searchInput/SearchInput.tsx +208 -217
- package/src/components/tabs/TabItem.tsx +143 -146
- package/src/components/textInput/TextInputValidation.tsx +116 -122
- package/src/components/typography/Body.tsx +51 -52
- package/src/components/typography/BodyMonospace.tsx +19 -24
- package/src/components/typography/BodySmall.tsx +51 -52
- package/src/components/typography/ButtonText.tsx +14 -20
- package/src/components/typography/Caption.tsx +18 -23
- package/src/components/typography/H1.tsx +12 -20
- package/src/components/typography/H2.tsx +16 -23
- package/src/components/typography/H3.tsx +12 -20
- package/src/components/typography/H4.tsx +12 -20
- package/src/components/typography/H5.tsx +16 -24
- package/src/components/typography/H6.tsx +13 -21
- package/src/components/typography/Hero.tsx +14 -19
- package/src/components/typography/IOText.tsx +54 -59
- package/src/components/typography/LabelMini.tsx +45 -49
- package/src/components/typography/markdown/MdH1.tsx +14 -19
- package/src/components/typography/markdown/MdH2.tsx +14 -19
- package/src/components/typography/markdown/MdH3.tsx +14 -19
- package/src/context/IOThemeContextProvider.tsx +4 -12
|
@@ -1,4 +1,4 @@
|
|
|
1
|
-
import { Ref,
|
|
1
|
+
import { Ref, useCallback, useMemo } from "react";
|
|
2
2
|
import {
|
|
3
3
|
GestureResponderEvent,
|
|
4
4
|
Pressable,
|
|
@@ -25,6 +25,7 @@ type ColorMode = "light" | "dark";
|
|
|
25
25
|
type TabItemState = "default" | "selected" | "disabled";
|
|
26
26
|
|
|
27
27
|
export type TabItem = WithTestID<{
|
|
28
|
+
ref?: Ref<View>;
|
|
28
29
|
label: string;
|
|
29
30
|
color?: ColorMode;
|
|
30
31
|
selected?: boolean;
|
|
@@ -57,155 +58,151 @@ type ColorStates = {
|
|
|
57
58
|
|
|
58
59
|
const DISABLED_OPACITY = 0.5;
|
|
59
60
|
|
|
60
|
-
const TabItem =
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
IOColors[theme["tab-item-foreground-selected"]],
|
|
91
|
-
0.5
|
|
92
|
-
)
|
|
93
|
-
},
|
|
94
|
-
background: {
|
|
95
|
-
default: hexToRgba(
|
|
96
|
-
IOColors[theme["tab-item-background-selected"]],
|
|
97
|
-
0
|
|
98
|
-
),
|
|
99
|
-
selected: hexToRgba(
|
|
100
|
-
IOColors[theme["tab-item-background-selected"]],
|
|
101
|
-
0.25
|
|
102
|
-
),
|
|
103
|
-
pressed: IOColors[theme["appBackground-primary"]]
|
|
104
|
-
},
|
|
105
|
-
foreground: {
|
|
106
|
-
default: theme["tab-item-foreground-default"],
|
|
107
|
-
selected: theme["tab-item-foreground-selected"],
|
|
108
|
-
disabled: "grey-700"
|
|
109
|
-
}
|
|
61
|
+
const TabItem = ({
|
|
62
|
+
label,
|
|
63
|
+
color = "light",
|
|
64
|
+
selected = false,
|
|
65
|
+
accessibilityLabel,
|
|
66
|
+
accessibilityHint,
|
|
67
|
+
testID,
|
|
68
|
+
onPress,
|
|
69
|
+
disabled = false,
|
|
70
|
+
icon,
|
|
71
|
+
iconSelected,
|
|
72
|
+
ref
|
|
73
|
+
}: TabItem) => {
|
|
74
|
+
const { onPressIn, onPressOut, scaleAnimatedStyle } =
|
|
75
|
+
useScaleAnimation("medium");
|
|
76
|
+
const theme = useIOTheme();
|
|
77
|
+
const reducedMotion = useReducedMotion();
|
|
78
|
+
|
|
79
|
+
const mapColorStates: Record<
|
|
80
|
+
NonNullable<TabItem["color"]>,
|
|
81
|
+
ColorStates
|
|
82
|
+
> = useMemo(
|
|
83
|
+
() => ({
|
|
84
|
+
light: {
|
|
85
|
+
border: {
|
|
86
|
+
default: IOColors[theme["tab-item-border-default"]],
|
|
87
|
+
selected: hexToRgba(
|
|
88
|
+
IOColors[theme["tab-item-foreground-selected"]],
|
|
89
|
+
0.5
|
|
90
|
+
)
|
|
110
91
|
},
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
}
|
|
127
|
-
}),
|
|
128
|
-
[theme]
|
|
129
|
-
);
|
|
130
|
-
|
|
131
|
-
const itemState: TabItemState = selected
|
|
132
|
-
? "selected"
|
|
133
|
-
: disabled
|
|
134
|
-
? "disabled"
|
|
135
|
-
: "default";
|
|
136
|
-
|
|
137
|
-
const foregroundColor = mapColorStates[color].foreground[itemState];
|
|
138
|
-
|
|
139
|
-
const selectedStateTransition = useDerivedValue(() =>
|
|
140
|
-
withSpring(selected ? 1 : 0, IOSpringValues.selection)
|
|
141
|
-
);
|
|
142
|
-
|
|
143
|
-
// Interpolate animation values from `pressed` values
|
|
144
|
-
const animatedStyle = useAnimatedStyle(() => ({
|
|
145
|
-
backgroundColor: interpolateColor(
|
|
146
|
-
selectedStateTransition.value,
|
|
147
|
-
[0, 1],
|
|
148
|
-
[
|
|
149
|
-
mapColorStates[color].background.default,
|
|
150
|
-
mapColorStates[color].background.selected
|
|
151
|
-
]
|
|
152
|
-
),
|
|
153
|
-
borderColor: interpolateColor(
|
|
154
|
-
selectedStateTransition.value,
|
|
155
|
-
[0, 1],
|
|
156
|
-
[
|
|
157
|
-
mapColorStates[color].border.default,
|
|
158
|
-
mapColorStates[color].border.selected
|
|
159
|
-
]
|
|
160
|
-
)
|
|
161
|
-
}));
|
|
162
|
-
|
|
163
|
-
const activeIcon = selected ? iconSelected ?? icon : icon;
|
|
164
|
-
|
|
165
|
-
const handleOnPress = useCallback(
|
|
166
|
-
(event: GestureResponderEvent) => {
|
|
167
|
-
if (onPress) {
|
|
168
|
-
ReactNativeHapticFeedback.trigger("impactLight");
|
|
169
|
-
onPress(event);
|
|
92
|
+
background: {
|
|
93
|
+
default: hexToRgba(
|
|
94
|
+
IOColors[theme["tab-item-background-selected"]],
|
|
95
|
+
0
|
|
96
|
+
),
|
|
97
|
+
selected: hexToRgba(
|
|
98
|
+
IOColors[theme["tab-item-background-selected"]],
|
|
99
|
+
0.25
|
|
100
|
+
),
|
|
101
|
+
pressed: IOColors[theme["appBackground-primary"]]
|
|
102
|
+
},
|
|
103
|
+
foreground: {
|
|
104
|
+
default: theme["tab-item-foreground-default"],
|
|
105
|
+
selected: theme["tab-item-foreground-selected"],
|
|
106
|
+
disabled: "grey-700"
|
|
170
107
|
}
|
|
171
108
|
},
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
109
|
+
dark: {
|
|
110
|
+
border: {
|
|
111
|
+
default: hexToRgba(IOColors.white, 0),
|
|
112
|
+
selected: IOColors.white
|
|
113
|
+
},
|
|
114
|
+
background: {
|
|
115
|
+
default: hexToRgba(IOColors.white, 0.1),
|
|
116
|
+
selected: IOColors.white,
|
|
117
|
+
pressed: IOColors.white
|
|
118
|
+
},
|
|
119
|
+
foreground: {
|
|
120
|
+
default: "white",
|
|
121
|
+
selected: "black",
|
|
122
|
+
disabled: "white"
|
|
123
|
+
}
|
|
124
|
+
}
|
|
125
|
+
}),
|
|
126
|
+
[theme]
|
|
127
|
+
);
|
|
128
|
+
|
|
129
|
+
const itemState: TabItemState = selected
|
|
130
|
+
? "selected"
|
|
131
|
+
: disabled
|
|
132
|
+
? "disabled"
|
|
133
|
+
: "default";
|
|
134
|
+
|
|
135
|
+
const foregroundColor = mapColorStates[color].foreground[itemState];
|
|
136
|
+
|
|
137
|
+
const selectedStateTransition = useDerivedValue(() =>
|
|
138
|
+
withSpring(selected ? 1 : 0, IOSpringValues.selection)
|
|
139
|
+
);
|
|
140
|
+
|
|
141
|
+
// Interpolate animation values from `pressed` values
|
|
142
|
+
const animatedStyle = useAnimatedStyle(() => ({
|
|
143
|
+
backgroundColor: interpolateColor(
|
|
144
|
+
selectedStateTransition.value,
|
|
145
|
+
[0, 1],
|
|
146
|
+
[
|
|
147
|
+
mapColorStates[color].background.default,
|
|
148
|
+
mapColorStates[color].background.selected
|
|
149
|
+
]
|
|
150
|
+
),
|
|
151
|
+
borderColor: interpolateColor(
|
|
152
|
+
selectedStateTransition.value,
|
|
153
|
+
[0, 1],
|
|
154
|
+
[
|
|
155
|
+
mapColorStates[color].border.default,
|
|
156
|
+
mapColorStates[color].border.selected
|
|
157
|
+
]
|
|
158
|
+
)
|
|
159
|
+
}));
|
|
160
|
+
|
|
161
|
+
const activeIcon = selected ? iconSelected ?? icon : icon;
|
|
162
|
+
|
|
163
|
+
const handleOnPress = useCallback(
|
|
164
|
+
(event: GestureResponderEvent) => {
|
|
165
|
+
if (onPress) {
|
|
166
|
+
ReactNativeHapticFeedback.trigger("impactLight");
|
|
167
|
+
onPress(event);
|
|
168
|
+
}
|
|
169
|
+
},
|
|
170
|
+
[onPress]
|
|
171
|
+
);
|
|
172
|
+
|
|
173
|
+
return (
|
|
174
|
+
<Pressable
|
|
175
|
+
ref={ref}
|
|
176
|
+
accessibilityLabel={accessibilityLabel}
|
|
177
|
+
accessibilityHint={accessibilityHint}
|
|
178
|
+
accessibilityRole="tab"
|
|
179
|
+
accessibilityState={{ checked: !!selected }}
|
|
180
|
+
testID={testID}
|
|
181
|
+
onPress={handleOnPress}
|
|
182
|
+
onPressIn={onPressIn}
|
|
183
|
+
onPressOut={onPressOut}
|
|
184
|
+
accessible={true}
|
|
185
|
+
disabled={disabled}
|
|
186
|
+
>
|
|
187
|
+
<Animated.View
|
|
188
|
+
style={[
|
|
189
|
+
styles.container,
|
|
190
|
+
{ columnGap: 4 },
|
|
191
|
+
!disabled && !reducedMotion && scaleAnimatedStyle,
|
|
192
|
+
animatedStyle,
|
|
193
|
+
disabled && { opacity: DISABLED_OPACITY }
|
|
194
|
+
]}
|
|
188
195
|
>
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
<Icon name={activeIcon} color={foregroundColor} size={16} />
|
|
200
|
-
)}
|
|
201
|
-
<IOText size={14} weight="Semibold" color={foregroundColor}>
|
|
202
|
-
{label}
|
|
203
|
-
</IOText>
|
|
204
|
-
</Animated.View>
|
|
205
|
-
</Pressable>
|
|
206
|
-
);
|
|
207
|
-
}
|
|
208
|
-
);
|
|
196
|
+
{activeIcon && (
|
|
197
|
+
<Icon name={activeIcon} color={foregroundColor} size={16} />
|
|
198
|
+
)}
|
|
199
|
+
<IOText size={14} weight="Semibold" color={foregroundColor}>
|
|
200
|
+
{label}
|
|
201
|
+
</IOText>
|
|
202
|
+
</Animated.View>
|
|
203
|
+
</Pressable>
|
|
204
|
+
);
|
|
205
|
+
};
|
|
209
206
|
|
|
210
207
|
const styles = StyleSheet.create({
|
|
211
208
|
container: {
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
import {
|
|
2
2
|
ComponentProps,
|
|
3
|
-
|
|
3
|
+
Ref,
|
|
4
4
|
useCallback,
|
|
5
5
|
useImperativeHandle,
|
|
6
6
|
useMemo,
|
|
@@ -25,6 +25,7 @@ type TextInputValidationProps = Omit<
|
|
|
25
25
|
ComponentProps<typeof TextInputBase>,
|
|
26
26
|
"rightElement" | "status" | "bottomMessageColor" | "isPassword"
|
|
27
27
|
> & {
|
|
28
|
+
ref?: Ref<TextInputValidationRefProps>;
|
|
28
29
|
/**
|
|
29
30
|
* This function can return either a `boolean` or a `ValidationWithOptions` object.
|
|
30
31
|
* If a `boolean` is returned and the field is not valid, the value of the errorMessage prop will be displayed/announced.
|
|
@@ -57,132 +58,125 @@ function isValidationWithOptions(
|
|
|
57
58
|
|
|
58
59
|
const feedbackIconSize: IOIconSizeScale = 24;
|
|
59
60
|
|
|
60
|
-
export const TextInputValidation =
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
AccessibilityInfo.announceForAccessibilityWithOptions(
|
|
90
|
-
accessibilityErrorLabel ?? message,
|
|
91
|
-
{
|
|
92
|
-
queue: true
|
|
93
|
-
}
|
|
94
|
-
);
|
|
95
|
-
} else {
|
|
96
|
-
triggerHaptic("notificationSuccess");
|
|
97
|
-
}
|
|
98
|
-
},
|
|
99
|
-
[accessibilityErrorLabel]
|
|
100
|
-
);
|
|
101
|
-
|
|
102
|
-
const validateInput = useCallback(() => {
|
|
103
|
-
const validation = onValidate(value);
|
|
104
|
-
|
|
105
|
-
if (isValidationWithOptions(validation)) {
|
|
106
|
-
getErrorFeedback(validation.isValid, validation.errorMessage);
|
|
61
|
+
export const TextInputValidation = ({
|
|
62
|
+
onValidate,
|
|
63
|
+
errorMessage,
|
|
64
|
+
value,
|
|
65
|
+
bottomMessage,
|
|
66
|
+
onBlur,
|
|
67
|
+
onFocus,
|
|
68
|
+
validationMode = "onBlur",
|
|
69
|
+
accessibilityErrorLabel,
|
|
70
|
+
ref,
|
|
71
|
+
...props
|
|
72
|
+
}: TextInputValidationProps) => {
|
|
73
|
+
const theme = useIOTheme();
|
|
74
|
+
const [isValid, setIsValid] = useState<boolean | undefined>(undefined);
|
|
75
|
+
const [errMessage, setErrMessage] = useState(errorMessage);
|
|
76
|
+
|
|
77
|
+
const getErrorFeedback = useCallback(
|
|
78
|
+
(isValid: boolean, message: string) => {
|
|
79
|
+
setIsValid(isValid);
|
|
80
|
+
setErrMessage(message);
|
|
81
|
+
|
|
82
|
+
if (!isValid) {
|
|
83
|
+
triggerHaptic("notificationError");
|
|
84
|
+
AccessibilityInfo.announceForAccessibilityWithOptions(
|
|
85
|
+
accessibilityErrorLabel ?? message,
|
|
86
|
+
{
|
|
87
|
+
queue: true
|
|
88
|
+
}
|
|
89
|
+
);
|
|
107
90
|
} else {
|
|
108
|
-
|
|
91
|
+
triggerHaptic("notificationSuccess");
|
|
109
92
|
}
|
|
110
|
-
},
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
useImperativeHandle(ref, () => ({
|
|
114
|
-
validateInput
|
|
115
|
-
}));
|
|
116
|
-
|
|
117
|
-
const onBlurHandler = useCallback(() => {
|
|
118
|
-
if (validationMode === "onBlur") {
|
|
119
|
-
validateInput();
|
|
120
|
-
}
|
|
121
|
-
onBlur?.();
|
|
122
|
-
}, [validationMode, validateInput, onBlur]);
|
|
93
|
+
},
|
|
94
|
+
[accessibilityErrorLabel]
|
|
95
|
+
);
|
|
123
96
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
97
|
+
const validateInput = useCallback(() => {
|
|
98
|
+
const validation = onValidate(value);
|
|
99
|
+
|
|
100
|
+
if (isValidationWithOptions(validation)) {
|
|
101
|
+
getErrorFeedback(validation.isValid, validation.errorMessage);
|
|
102
|
+
} else {
|
|
103
|
+
getErrorFeedback(validation, errorMessage);
|
|
104
|
+
}
|
|
105
|
+
}, [value, errorMessage, onValidate, getErrorFeedback]);
|
|
106
|
+
|
|
107
|
+
// Expose the validateInput function to the parent component
|
|
108
|
+
useImperativeHandle(ref, () => ({
|
|
109
|
+
validateInput
|
|
110
|
+
}));
|
|
111
|
+
|
|
112
|
+
const onBlurHandler = useCallback(() => {
|
|
113
|
+
if (validationMode === "onBlur") {
|
|
114
|
+
validateInput();
|
|
115
|
+
}
|
|
116
|
+
onBlur?.();
|
|
117
|
+
}, [validationMode, validateInput, onBlur]);
|
|
118
|
+
|
|
119
|
+
const onFocusHandler = useCallback(() => {
|
|
120
|
+
setIsValid(undefined);
|
|
121
|
+
onFocus?.();
|
|
122
|
+
}, [onFocus]);
|
|
123
|
+
|
|
124
|
+
const labelError = useMemo(
|
|
125
|
+
() => (isValid === false && errMessage ? errMessage : bottomMessage),
|
|
126
|
+
[isValid, errMessage, bottomMessage]
|
|
127
|
+
);
|
|
128
128
|
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
129
|
+
const labelErrorColor: IOColors | undefined = useMemo(
|
|
130
|
+
() => (isValid === false && errMessage ? theme.errorText : undefined),
|
|
131
|
+
[isValid, errMessage, theme.errorText]
|
|
132
|
+
);
|
|
133
133
|
|
|
134
|
-
|
|
135
|
-
|
|
136
|
-
|
|
137
|
-
|
|
134
|
+
const feedbackIconAttrMap: Record<
|
|
135
|
+
string,
|
|
136
|
+
{ name: IOIcons; color: IOColors }
|
|
137
|
+
> = useMemo(
|
|
138
|
+
() => ({
|
|
139
|
+
valid: {
|
|
140
|
+
name: "success",
|
|
141
|
+
color: theme.successIcon
|
|
142
|
+
},
|
|
143
|
+
notValid: {
|
|
144
|
+
name: "errorFilled",
|
|
145
|
+
color: theme.errorIcon
|
|
146
|
+
}
|
|
147
|
+
}),
|
|
148
|
+
[theme]
|
|
149
|
+
);
|
|
138
150
|
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
152
|
-
|
|
153
|
-
|
|
151
|
+
const feedbackIcon = useMemo(() => {
|
|
152
|
+
const validationStatus = isValid ? "valid" : "notValid";
|
|
153
|
+
|
|
154
|
+
return isValid !== undefined ? (
|
|
155
|
+
<Animated.View
|
|
156
|
+
entering={enterTransitionInputIcon}
|
|
157
|
+
exiting={exitTransitionInputIcon}
|
|
158
|
+
>
|
|
159
|
+
<Icon
|
|
160
|
+
name={feedbackIconAttrMap[validationStatus].name}
|
|
161
|
+
color={feedbackIconAttrMap[validationStatus].color}
|
|
162
|
+
size={feedbackIconSize}
|
|
163
|
+
/>
|
|
164
|
+
</Animated.View>
|
|
165
|
+
) : (
|
|
166
|
+
<View style={{ width: feedbackIconSize, height: feedbackIconSize }} />
|
|
154
167
|
);
|
|
168
|
+
}, [feedbackIconAttrMap, isValid]);
|
|
155
169
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
</Animated.View>
|
|
170
|
-
) : (
|
|
171
|
-
<View style={{ width: feedbackIconSize, height: feedbackIconSize }} />
|
|
172
|
-
);
|
|
173
|
-
}, [feedbackIconAttrMap, isValid]);
|
|
174
|
-
|
|
175
|
-
return (
|
|
176
|
-
<TextInputBase
|
|
177
|
-
{...props}
|
|
178
|
-
value={value}
|
|
179
|
-
status={isValid === false ? "error" : undefined}
|
|
180
|
-
bottomMessage={labelError}
|
|
181
|
-
bottomMessageColor={labelErrorColor}
|
|
182
|
-
rightElement={feedbackIcon}
|
|
183
|
-
onBlur={onBlurHandler}
|
|
184
|
-
onFocus={onFocusHandler}
|
|
185
|
-
/>
|
|
186
|
-
);
|
|
187
|
-
}
|
|
188
|
-
);
|
|
170
|
+
return (
|
|
171
|
+
<TextInputBase
|
|
172
|
+
{...props}
|
|
173
|
+
value={value}
|
|
174
|
+
status={isValid === false ? "error" : undefined}
|
|
175
|
+
bottomMessage={labelError}
|
|
176
|
+
bottomMessageColor={labelErrorColor}
|
|
177
|
+
rightElement={feedbackIcon}
|
|
178
|
+
onBlur={onBlurHandler}
|
|
179
|
+
onFocus={onFocusHandler}
|
|
180
|
+
/>
|
|
181
|
+
);
|
|
182
|
+
};
|