@pagopa/io-app-design-system 6.0.6 → 6.0.7

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (39) hide show
  1. package/lib/commonjs/components/buttons/IOButton/__test__/__snapshots__/IOButton.test.tsx.snap +3 -3
  2. package/lib/commonjs/components/buttons/__test__/__snapshots__/button.test.tsx.snap +6 -6
  3. package/lib/commonjs/components/otpInput/OTPInput.js +41 -26
  4. package/lib/commonjs/components/otpInput/OTPInput.js.map +1 -1
  5. package/lib/commonjs/components/toast/ToastProvider.js +3 -3
  6. package/lib/commonjs/components/toast/ToastProvider.js.map +1 -1
  7. package/lib/commonjs/components/tooltip/Tooltip.js +3 -3
  8. package/lib/commonjs/components/tooltip/Tooltip.js.map +1 -1
  9. package/lib/commonjs/components/typography/IOText.js +2 -3
  10. package/lib/commonjs/components/typography/IOText.js.map +1 -1
  11. package/lib/commonjs/utils/throttle.js +19 -0
  12. package/lib/commonjs/utils/throttle.js.map +1 -0
  13. package/lib/module/components/buttons/IOButton/__test__/__snapshots__/IOButton.test.tsx.snap +3 -3
  14. package/lib/module/components/buttons/__test__/__snapshots__/button.test.tsx.snap +6 -6
  15. package/lib/module/components/otpInput/OTPInput.js +42 -27
  16. package/lib/module/components/otpInput/OTPInput.js.map +1 -1
  17. package/lib/module/components/toast/ToastProvider.js +1 -1
  18. package/lib/module/components/toast/ToastProvider.js.map +1 -1
  19. package/lib/module/components/tooltip/Tooltip.js +3 -3
  20. package/lib/module/components/tooltip/Tooltip.js.map +1 -1
  21. package/lib/module/components/typography/IOText.js +3 -4
  22. package/lib/module/components/typography/IOText.js.map +1 -1
  23. package/lib/module/utils/throttle.js +14 -0
  24. package/lib/module/utils/throttle.js.map +1 -0
  25. package/lib/typescript/components/otpInput/OTPInput.d.ts +4 -0
  26. package/lib/typescript/components/otpInput/OTPInput.d.ts.map +1 -1
  27. package/lib/typescript/components/toast/ToastProvider.d.ts.map +1 -1
  28. package/lib/typescript/components/tooltip/Tooltip.d.ts.map +1 -1
  29. package/lib/typescript/components/typography/IOText.d.ts.map +1 -1
  30. package/lib/typescript/utils/throttle.d.ts +2 -0
  31. package/lib/typescript/utils/throttle.d.ts.map +1 -0
  32. package/package.json +1 -3
  33. package/src/components/buttons/IOButton/__test__/__snapshots__/IOButton.test.tsx.snap +3 -3
  34. package/src/components/buttons/__test__/__snapshots__/button.test.tsx.snap +6 -6
  35. package/src/components/otpInput/OTPInput.tsx +57 -32
  36. package/src/components/toast/ToastProvider.tsx +1 -1
  37. package/src/components/tooltip/Tooltip.tsx +4 -3
  38. package/src/components/typography/IOText.tsx +5 -15
  39. package/src/utils/throttle.ts +15 -0
@@ -8,10 +8,11 @@ import {
8
8
  } from "react";
9
9
  import {
10
10
  AccessibilityInfo,
11
- NativeSyntheticEvent,
11
+ Platform,
12
12
  Pressable,
13
+ StyleSheet,
13
14
  TextInput,
14
- TextInputKeyPressEventData,
15
+ TextInputKeyPressEvent,
15
16
  View
16
17
  } from "react-native";
17
18
  import Animated from "react-native-reanimated";
@@ -35,6 +36,10 @@ type Props = {
35
36
  accessibilityLabel?: string;
36
37
  deleteButtonAccessibilityLabel?: string;
37
38
  accessibilityHint?: string;
39
+ accessibilityValueText?: (params: {
40
+ valueLength: number;
41
+ length: number;
42
+ }) => string;
38
43
  inputAccessoryViewID?: string;
39
44
  autoFocus?: boolean;
40
45
  };
@@ -60,6 +65,7 @@ export const OTPInput = forwardRef<View, Props>(
60
65
  length,
61
66
  accessibilityLabel,
62
67
  accessibilityHint,
68
+ accessibilityValueText,
63
69
  onValidate,
64
70
  errorMessage = "",
65
71
  secret = false,
@@ -120,10 +126,8 @@ export const OTPInput = forwardRef<View, Props>(
120
126
  handleValidate(value);
121
127
  };
122
128
 
123
- const handleKeyPress = ({
124
- nativeEvent
125
- }: NativeSyntheticEvent<TextInputKeyPressEventData>) => {
126
- switch (nativeEvent.key) {
129
+ const handleKeyPress = (e: TextInputKeyPressEvent) => {
130
+ switch (e.nativeEvent.key) {
127
131
  case "Backspace":
128
132
  if (deleteButtonAccessibilityLabel && value.length > 0) {
129
133
  AccessibilityInfo.announceForAccessibility(
@@ -132,7 +136,7 @@ export const OTPInput = forwardRef<View, Props>(
132
136
  }
133
137
  break;
134
138
  default:
135
- AccessibilityInfo.announceForAccessibility(nativeEvent.key);
139
+ AccessibilityInfo.announceForAccessibility(e.nativeEvent.key);
136
140
  break;
137
141
  }
138
142
  };
@@ -147,21 +151,20 @@ export const OTPInput = forwardRef<View, Props>(
147
151
  setHasFocus(true);
148
152
  }}
149
153
  ref={ref}
150
- style={{
151
- flexDirection: "row",
152
- justifyContent: "space-between",
153
- columnGap: OTP_ITEMS_GAP
154
- }}
155
- accessible={true}
156
- accessibilityLabel={accessibilityLabel}
157
- accessibilityHint={accessibilityHint}
158
- accessibilityValue={{ text: value }}
154
+ accessible={false}
159
155
  >
160
156
  <TextInput
161
157
  value={value}
162
158
  onChangeText={handleChange}
163
159
  onKeyPress={handleKeyPress}
164
- style={{ position: "absolute", opacity: 0 }}
160
+ caretHidden={Platform.OS === "ios"}
161
+ style={[
162
+ StyleSheet.absoluteFillObject,
163
+ Platform.select({
164
+ ios: { opacity: 0.01 },
165
+ android: { opacity: 0 }
166
+ })
167
+ ]}
165
168
  maxLength={length}
166
169
  ref={inputRef}
167
170
  onBlur={() => setHasFocus(false)}
@@ -172,23 +175,45 @@ export const OTPInput = forwardRef<View, Props>(
172
175
  autoComplete={autocomplete ? "sms-otp" : undefined}
173
176
  inputAccessoryViewID={inputAccessoryViewID}
174
177
  accessible={true}
178
+ accessibilityLabel={accessibilityLabel}
179
+ accessibilityHint={accessibilityHint}
180
+ // Ensure the screen reader pronounces the code digit by digit
181
+ accessibilityValue={{
182
+ text:
183
+ accessibilityValueText?.({
184
+ valueLength: value.length,
185
+ length
186
+ }) ?? value.split("").join(" ")
187
+ }}
175
188
  autoFocus={autoFocus}
176
- secureTextEntry={true}
189
+ secureTextEntry={secret}
177
190
  />
178
- {cells.map((_, i) => (
179
- <BoxedInput
180
- key={i}
181
- status={
182
- hasError
183
- ? "error"
184
- : hasFocus && value.length === i
185
- ? "focus"
186
- : "default"
187
- }
188
- secret={secret}
189
- value={value[i]}
190
- />
191
- ))}
191
+ <View
192
+ style={{
193
+ flexDirection: "row",
194
+ justifyContent: "space-between",
195
+ columnGap: OTP_ITEMS_GAP,
196
+ flexGrow: 1,
197
+ zIndex: 10
198
+ }}
199
+ accessibilityElementsHidden={true}
200
+ importantForAccessibility="no-hide-descendants"
201
+ >
202
+ {cells.map((_, i) => (
203
+ <BoxedInput
204
+ key={i}
205
+ status={
206
+ hasError
207
+ ? "error"
208
+ : hasFocus && value.length === i
209
+ ? "focus"
210
+ : "default"
211
+ }
212
+ secret={secret}
213
+ value={value[i]}
214
+ />
215
+ ))}
216
+ </View>
192
217
  </Pressable>
193
218
  <VSpacer size={4} />
194
219
  {hasError && errorMessage && (
@@ -1,4 +1,3 @@
1
- import { throttle } from "lodash";
2
1
  import { ReactNode, useCallback, useMemo, useRef, useState } from "react";
3
2
  import { AccessibilityInfo, StyleSheet, View } from "react-native";
4
3
  import Animated, {
@@ -10,6 +9,7 @@ import Animated, {
10
9
  import { SafeAreaView } from "react-native-safe-area-context";
11
10
  import { IOVisualCostants } from "../../core";
12
11
  import { triggerHaptic } from "../../functions";
12
+ import { throttle } from "../../utils/throttle";
13
13
  import { Dismissable } from "../templates";
14
14
  import { ToastNotification } from "./ToastNotification";
15
15
  import { ToastContext } from "./context";
@@ -1,4 +1,3 @@
1
- import { every, some } from "lodash";
2
1
  import {
3
2
  JSXElementConstructor,
4
3
  PropsWithChildren,
@@ -194,8 +193,10 @@ export const Tooltip = ({
194
193
  () => ARROWS_BY_PLACEMENT[currentPlacement],
195
194
  [currentPlacement]
196
195
  );
196
+ const childrenCoordsValues = Object.values(childrenCoords);
197
197
  const isChildrenMeasurementFinished =
198
- every(childrenCoords, isDefined) && some(childrenCoords, isNotZero);
198
+ childrenCoordsValues.every(isDefined) &&
199
+ childrenCoordsValues.some(isNotZero);
199
200
  const isTooltipMeasurementCompleted = isDefined(tooltipLayout);
200
201
  const tooltipVisibility = { opacity: isTooltipMeasurementCompleted ? 1 : 0 };
201
202
 
@@ -211,7 +212,7 @@ export const Tooltip = ({
211
212
  width,
212
213
  height
213
214
  };
214
- if (every(coords, isDefined)) {
215
+ if (Object.values(coords).every(isDefined)) {
215
216
  setChildrenCoords(coords);
216
217
  }
217
218
  });
@@ -8,7 +8,7 @@ import {
8
8
  View
9
9
  } from "react-native";
10
10
  import Animated from "react-native-reanimated";
11
- import { useIONewTypeface, useIOTheme } from "../../context";
11
+ import { useIONewTypeface } from "../../context";
12
12
  import { IOColors } from "../../core";
13
13
  import { useBoldTextEnabled } from "../../utils/accessibility";
14
14
  import {
@@ -74,11 +74,11 @@ export type TypographicStyleAsLinkProps =
74
74
  * @param args the args of the function {@link makeFontStyleObject}
75
75
  */
76
76
  const calculateTextStyle = (
77
- color: IOColors,
77
+ color?: IOColors,
78
78
  ...args: Parameters<typeof makeFontStyleObject>
79
79
  ) => ({
80
80
  ...makeFontStyleObject(...args),
81
- color: IOColors[color]
81
+ color: color ? IOColors[color] : undefined
82
82
  });
83
83
 
84
84
  /**
@@ -106,7 +106,6 @@ export const IOText = forwardRef<View, IOTextProps>(
106
106
  },
107
107
  ref
108
108
  ) => {
109
- const theme = useIOTheme();
110
109
  const boldEnabled = useBoldTextEnabled();
111
110
  const { newTypefaceEnabled } = useIONewTypeface();
112
111
 
@@ -116,7 +115,7 @@ export const IOText = forwardRef<View, IOTextProps>(
116
115
  const computedStyleObj = useMemo(
117
116
  () =>
118
117
  calculateTextStyle(
119
- color ?? theme["textBody-default"],
118
+ color,
120
119
  size,
121
120
  computedFont,
122
121
  lineHeight,
@@ -124,16 +123,7 @@ export const IOText = forwardRef<View, IOTextProps>(
124
123
  fontStyle,
125
124
  boldEnabled
126
125
  ),
127
- [
128
- color,
129
- theme,
130
- size,
131
- computedFont,
132
- lineHeight,
133
- weight,
134
- fontStyle,
135
- boldEnabled
136
- ]
126
+ [color, size, computedFont, lineHeight, weight, fontStyle, boldEnabled]
137
127
  );
138
128
 
139
129
  /* In some cases, for example when we use color transitions with
@@ -0,0 +1,15 @@
1
+ export const throttle = <T extends Array<unknown>>(
2
+ fn: (...args: T) => void,
3
+ ms: number
4
+ ) => {
5
+ // eslint-disable-next-line functional/no-let
6
+ let lastCall = 0;
7
+ return (...args: T) => {
8
+ const now = Date.now();
9
+
10
+ if (now - lastCall >= ms) {
11
+ lastCall = now;
12
+ fn(...args);
13
+ }
14
+ };
15
+ };