@pagopa/io-app-design-system 5.3.8 → 5.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.
Files changed (171) hide show
  1. package/README.md +3 -2
  2. package/lib/commonjs/components/buttons/ButtonLink.js +5 -2
  3. package/lib/commonjs/components/buttons/ButtonLink.js.map +1 -1
  4. package/lib/commonjs/components/buttons/ButtonOutline.js +20 -15
  5. package/lib/commonjs/components/buttons/ButtonOutline.js.map +1 -1
  6. package/lib/commonjs/components/buttons/ButtonSolid.js +4 -1
  7. package/lib/commonjs/components/buttons/ButtonSolid.js.map +1 -1
  8. package/lib/commonjs/components/buttons/IOButton/IOButton.js +230 -0
  9. package/lib/commonjs/components/buttons/IOButton/IOButton.js.map +1 -0
  10. package/lib/commonjs/components/buttons/IOButton/__test__/IOButton.test.js +43 -0
  11. package/lib/commonjs/components/buttons/IOButton/__test__/IOButton.test.js.map +1 -0
  12. package/lib/commonjs/components/buttons/IOButton/__test__/__snapshots__/IOButton.test.tsx.snap +391 -0
  13. package/lib/commonjs/components/buttons/IOButton/index.js +17 -0
  14. package/lib/commonjs/components/buttons/IOButton/index.js.map +1 -0
  15. package/lib/commonjs/components/buttons/IOButton/styles.js +166 -0
  16. package/lib/commonjs/components/buttons/IOButton/styles.js.map +1 -0
  17. package/lib/commonjs/components/buttons/IconButton.js +1 -2
  18. package/lib/commonjs/components/buttons/IconButton.js.map +1 -1
  19. package/lib/commonjs/components/buttons/IconButtonContained.js +1 -2
  20. package/lib/commonjs/components/buttons/IconButtonContained.js.map +1 -1
  21. package/lib/commonjs/components/buttons/__test__/__snapshots__/button.test.tsx.snap +3 -395
  22. package/lib/commonjs/components/buttons/__test__/button.test.js +0 -24
  23. package/lib/commonjs/components/buttons/__test__/button.test.js.map +1 -1
  24. package/lib/commonjs/components/buttons/index.js +11 -0
  25. package/lib/commonjs/components/buttons/index.js.map +1 -1
  26. package/lib/commonjs/components/claimsSelector/__test__/__snapshots__/ClaimsSelector.test.tsx.snap +3 -12
  27. package/lib/commonjs/components/contentWrapper/ContentWrapper.js +6 -2
  28. package/lib/commonjs/components/contentWrapper/ContentWrapper.js.map +1 -1
  29. package/lib/commonjs/components/icons/Icon.js +11 -9
  30. package/lib/commonjs/components/icons/Icon.js.map +1 -1
  31. package/lib/commonjs/components/layout/FooterActions.js +10 -9
  32. package/lib/commonjs/components/layout/FooterActions.js.map +1 -1
  33. package/lib/commonjs/components/layout/FooterActionsInline.js +8 -8
  34. package/lib/commonjs/components/layout/FooterActionsInline.js.map +1 -1
  35. package/lib/commonjs/components/layout/GradientBottomActions.js +8 -8
  36. package/lib/commonjs/components/layout/GradientBottomActions.js.map +1 -1
  37. package/lib/commonjs/components/layout/GradientScrollView.js.map +1 -1
  38. package/lib/commonjs/components/listitems/ListItemNav.js +1 -1
  39. package/lib/commonjs/components/listitems/ListItemNav.js.map +1 -1
  40. package/lib/commonjs/components/listitems/__test__/__snapshots__/listitem.test.tsx.snap +10 -40
  41. package/lib/commonjs/components/loadingSpinner/LoadingSpinner.js +6 -6
  42. package/lib/commonjs/components/loadingSpinner/LoadingSpinner.js.map +1 -1
  43. package/lib/commonjs/components/numberpad/NumberButton.js +15 -2
  44. package/lib/commonjs/components/numberpad/NumberButton.js.map +1 -1
  45. package/lib/commonjs/components/numberpad/NumberPad.js +9 -6
  46. package/lib/commonjs/components/numberpad/NumberPad.js.map +1 -1
  47. package/lib/commonjs/components/numberpad/__test__/__snapshots__/NumberPad.test.tsx.snap +36 -86
  48. package/lib/commonjs/components/typography/IOText.js +4 -1
  49. package/lib/commonjs/components/typography/IOText.js.map +1 -1
  50. package/lib/commonjs/core/IOStyles.js +2 -17
  51. package/lib/commonjs/core/IOStyles.js.map +1 -1
  52. package/lib/module/components/buttons/ButtonLink.js +6 -3
  53. package/lib/module/components/buttons/ButtonLink.js.map +1 -1
  54. package/lib/module/components/buttons/ButtonOutline.js +21 -16
  55. package/lib/module/components/buttons/ButtonOutline.js.map +1 -1
  56. package/lib/module/components/buttons/ButtonSolid.js +4 -1
  57. package/lib/module/components/buttons/ButtonSolid.js.map +1 -1
  58. package/lib/module/components/buttons/IOButton/IOButton.js +223 -0
  59. package/lib/module/components/buttons/IOButton/IOButton.js.map +1 -0
  60. package/lib/module/components/buttons/IOButton/__test__/IOButton.test.js +40 -0
  61. package/lib/module/components/buttons/IOButton/__test__/IOButton.test.js.map +1 -0
  62. package/lib/module/components/buttons/IOButton/__test__/__snapshots__/IOButton.test.tsx.snap +391 -0
  63. package/lib/module/components/buttons/IOButton/index.js +4 -0
  64. package/lib/module/components/buttons/IOButton/index.js.map +1 -0
  65. package/lib/module/components/buttons/IOButton/styles.js +160 -0
  66. package/lib/module/components/buttons/IOButton/styles.js.map +1 -0
  67. package/lib/module/components/buttons/IconButton.js +2 -3
  68. package/lib/module/components/buttons/IconButton.js.map +1 -1
  69. package/lib/module/components/buttons/IconButtonContained.js +2 -3
  70. package/lib/module/components/buttons/IconButtonContained.js.map +1 -1
  71. package/lib/module/components/buttons/__test__/__snapshots__/button.test.tsx.snap +3 -395
  72. package/lib/module/components/buttons/__test__/button.test.js +0 -24
  73. package/lib/module/components/buttons/__test__/button.test.js.map +1 -1
  74. package/lib/module/components/buttons/index.js +1 -0
  75. package/lib/module/components/buttons/index.js.map +1 -1
  76. package/lib/module/components/claimsSelector/__test__/__snapshots__/ClaimsSelector.test.tsx.snap +3 -12
  77. package/lib/module/components/contentWrapper/ContentWrapper.js +6 -2
  78. package/lib/module/components/contentWrapper/ContentWrapper.js.map +1 -1
  79. package/lib/module/components/icons/Icon.js +10 -7
  80. package/lib/module/components/icons/Icon.js.map +1 -1
  81. package/lib/module/components/layout/FooterActions.js +11 -10
  82. package/lib/module/components/layout/FooterActions.js.map +1 -1
  83. package/lib/module/components/layout/FooterActionsInline.js +9 -9
  84. package/lib/module/components/layout/FooterActionsInline.js.map +1 -1
  85. package/lib/module/components/layout/GradientBottomActions.js +9 -9
  86. package/lib/module/components/layout/GradientBottomActions.js.map +1 -1
  87. package/lib/module/components/layout/GradientScrollView.js.map +1 -1
  88. package/lib/module/components/listitems/ListItemNav.js +2 -2
  89. package/lib/module/components/listitems/ListItemNav.js.map +1 -1
  90. package/lib/module/components/listitems/__test__/__snapshots__/listitem.test.tsx.snap +10 -40
  91. package/lib/module/components/loadingSpinner/LoadingSpinner.js +6 -6
  92. package/lib/module/components/loadingSpinner/LoadingSpinner.js.map +1 -1
  93. package/lib/module/components/numberpad/NumberButton.js +16 -3
  94. package/lib/module/components/numberpad/NumberButton.js.map +1 -1
  95. package/lib/module/components/numberpad/NumberPad.js +10 -7
  96. package/lib/module/components/numberpad/NumberPad.js.map +1 -1
  97. package/lib/module/components/numberpad/__test__/__snapshots__/NumberPad.test.tsx.snap +36 -86
  98. package/lib/module/components/typography/IOText.js +2 -0
  99. package/lib/module/components/typography/IOText.js.map +1 -1
  100. package/lib/module/core/IOStyles.js +1 -16
  101. package/lib/module/core/IOStyles.js.map +1 -1
  102. package/lib/typescript/components/buttons/ButtonLink.d.ts +3 -0
  103. package/lib/typescript/components/buttons/ButtonLink.d.ts.map +1 -1
  104. package/lib/typescript/components/buttons/ButtonOutline.d.ts +3 -0
  105. package/lib/typescript/components/buttons/ButtonOutline.d.ts.map +1 -1
  106. package/lib/typescript/components/buttons/ButtonSolid.d.ts +3 -0
  107. package/lib/typescript/components/buttons/ButtonSolid.d.ts.map +1 -1
  108. package/lib/typescript/components/buttons/IOButton/IOButton.d.ts +57 -0
  109. package/lib/typescript/components/buttons/IOButton/IOButton.d.ts.map +1 -0
  110. package/lib/typescript/components/buttons/IOButton/__test__/IOButton.test.d.ts +2 -0
  111. package/lib/typescript/components/buttons/IOButton/__test__/IOButton.test.d.ts.map +1 -0
  112. package/lib/typescript/components/buttons/IOButton/index.d.ts +2 -0
  113. package/lib/typescript/components/buttons/IOButton/index.d.ts.map +1 -0
  114. package/lib/typescript/components/buttons/IOButton/styles.d.ts +35 -0
  115. package/lib/typescript/components/buttons/IOButton/styles.d.ts.map +1 -0
  116. package/lib/typescript/components/buttons/IconButton.d.ts.map +1 -1
  117. package/lib/typescript/components/buttons/IconButtonContained.d.ts.map +1 -1
  118. package/lib/typescript/components/buttons/index.d.ts +1 -0
  119. package/lib/typescript/components/buttons/index.d.ts.map +1 -1
  120. package/lib/typescript/components/contentWrapper/ContentWrapper.d.ts +6 -4
  121. package/lib/typescript/components/contentWrapper/ContentWrapper.d.ts.map +1 -1
  122. package/lib/typescript/components/icons/Icon.d.ts +1 -4
  123. package/lib/typescript/components/icons/Icon.d.ts.map +1 -1
  124. package/lib/typescript/components/icons/types.d.ts +3 -2
  125. package/lib/typescript/components/icons/types.d.ts.map +1 -1
  126. package/lib/typescript/components/layout/FooterActions.d.ts +10 -8
  127. package/lib/typescript/components/layout/FooterActions.d.ts.map +1 -1
  128. package/lib/typescript/components/layout/FooterActionsInline.d.ts +5 -4
  129. package/lib/typescript/components/layout/FooterActionsInline.d.ts.map +1 -1
  130. package/lib/typescript/components/layout/GradientBottomActions.d.ts +12 -6
  131. package/lib/typescript/components/layout/GradientBottomActions.d.ts.map +1 -1
  132. package/lib/typescript/components/layout/GradientScrollView.d.ts.map +1 -1
  133. package/lib/typescript/components/loadingSpinner/LoadingSpinner.d.ts +2 -2
  134. package/lib/typescript/components/loadingSpinner/LoadingSpinner.d.ts.map +1 -1
  135. package/lib/typescript/components/numberpad/NumberButton.d.ts +11 -0
  136. package/lib/typescript/components/numberpad/NumberButton.d.ts.map +1 -1
  137. package/lib/typescript/components/numberpad/NumberPad.d.ts.map +1 -1
  138. package/lib/typescript/components/typography/IOText.d.ts +1 -0
  139. package/lib/typescript/components/typography/IOText.d.ts.map +1 -1
  140. package/lib/typescript/core/IOStyles.d.ts +0 -14
  141. package/lib/typescript/core/IOStyles.d.ts.map +1 -1
  142. package/package.json +1 -1
  143. package/src/components/buttons/ButtonLink.tsx +6 -6
  144. package/src/components/buttons/ButtonOutline.tsx +21 -21
  145. package/src/components/buttons/ButtonSolid.tsx +4 -1
  146. package/src/components/buttons/IOButton/IOButton.tsx +363 -0
  147. package/src/components/buttons/IOButton/__test__/IOButton.test.tsx +46 -0
  148. package/src/components/buttons/IOButton/__test__/__snapshots__/IOButton.test.tsx.snap +391 -0
  149. package/src/components/buttons/IOButton/index.tsx +1 -0
  150. package/src/components/buttons/IOButton/styles.tsx +228 -0
  151. package/src/components/buttons/IconButton.tsx +3 -6
  152. package/src/components/buttons/IconButtonContained.tsx +3 -6
  153. package/src/components/buttons/__test__/__snapshots__/button.test.tsx.snap +3 -395
  154. package/src/components/buttons/__test__/button.test.tsx +1 -33
  155. package/src/components/buttons/index.tsx +1 -0
  156. package/src/components/claimsSelector/__test__/__snapshots__/ClaimsSelector.test.tsx.snap +3 -12
  157. package/src/components/contentWrapper/ContentWrapper.tsx +18 -8
  158. package/src/components/icons/Icon.tsx +12 -3
  159. package/src/components/icons/types.ts +3 -2
  160. package/src/components/layout/FooterActions.tsx +26 -14
  161. package/src/components/layout/FooterActionsInline.tsx +19 -12
  162. package/src/components/layout/GradientBottomActions.tsx +17 -18
  163. package/src/components/layout/GradientScrollView.tsx +2 -1
  164. package/src/components/listitems/ListItemNav.tsx +1 -1
  165. package/src/components/listitems/__test__/__snapshots__/listitem.test.tsx.snap +10 -40
  166. package/src/components/loadingSpinner/LoadingSpinner.tsx +8 -8
  167. package/src/components/numberpad/NumberButton.tsx +18 -11
  168. package/src/components/numberpad/NumberPad.tsx +8 -10
  169. package/src/components/numberpad/__test__/__snapshots__/NumberPad.test.tsx.snap +36 -86
  170. package/src/components/typography/IOText.tsx +3 -0
  171. package/src/core/IOStyles.ts +1 -18
@@ -0,0 +1,363 @@
1
+ import React, {
2
+ ComponentProps,
3
+ forwardRef,
4
+ useCallback,
5
+ useEffect,
6
+ useRef
7
+ } from "react";
8
+ import {
9
+ AccessibilityRole,
10
+ ColorValue,
11
+ GestureResponderEvent,
12
+ Pressable,
13
+ PressableProps,
14
+ StyleSheet,
15
+ TextProps,
16
+ TextStyle,
17
+ View,
18
+ ViewStyle
19
+ } from "react-native";
20
+ import ReactNativeHapticFeedback from "react-native-haptic-feedback";
21
+ import Animated, { useReducedMotion } from "react-native-reanimated";
22
+ import {
23
+ enterTransitionInnerContent,
24
+ enterTransitionInnerContentSmall,
25
+ exitTransitionInnerContent,
26
+ useIONewTypeface
27
+ } from "../../../core";
28
+ import { useScaleAnimation } from "../../../hooks";
29
+ import { WithTestID } from "../../../utils/types";
30
+ import {
31
+ AnimatedIcon,
32
+ AnimatedIconWithColorTransition,
33
+ IOIconSizeScale,
34
+ IOIcons
35
+ } from "../../icons";
36
+ import { LoadingSpinner } from "../../loadingSpinner";
37
+ import { AnimatedIOText } from "../../typography";
38
+ import {
39
+ buttonTextFontSize,
40
+ buttonTextLineHeight
41
+ } from "../../typography/ButtonText";
42
+ import { useButtonAnimatedStyles, useButtonColorMap } from "./styles";
43
+
44
+ export type IOButtonColor = "primary" | "danger" | "contrast";
45
+ export type IOButtonVariant = "solid" | "outline" | "link";
46
+
47
+ export type IOButtonBlockSpecificProps = Omit<
48
+ ComponentProps<typeof IOButton>,
49
+ "numberOfLines" | "textAlign"
50
+ >;
51
+
52
+ export type IOButtonLinkSpecificProps = Omit<
53
+ ComponentProps<typeof IOButton>,
54
+ "fullWidth" | "loading"
55
+ >;
56
+
57
+ type IOButtonSpecificProps =
58
+ | {
59
+ variant?: "link";
60
+ numberOfLines?: TextProps["numberOfLines"];
61
+ textAlign?: TextStyle["textAlign"];
62
+ fullWidth?: never;
63
+ loading?: never;
64
+ }
65
+ | {
66
+ variant?: "solid" | "outline";
67
+ fullWidth?: boolean;
68
+ loading?: boolean;
69
+ numberOfLines?: never;
70
+ textAlign?: never;
71
+ };
72
+
73
+ export type IOButtonProps = WithTestID<
74
+ IOButtonSpecificProps & {
75
+ /**
76
+ * @default primary
77
+ */
78
+ color?: IOButtonColor;
79
+ label: string;
80
+ icon?: IOIcons;
81
+ /**
82
+ * @default false
83
+ */
84
+ fullWidth?: boolean;
85
+ /**
86
+ * @default false
87
+ */
88
+ loading?: boolean;
89
+ /**
90
+ * @default start
91
+ */
92
+ iconPosition?: "start" | "end";
93
+ /**
94
+ * @default 1
95
+ */
96
+ numberOfLines?: number;
97
+ /**
98
+ * @default auto
99
+ */
100
+ textAlign?: TextStyle["textAlign"];
101
+ onPress: (event: GestureResponderEvent) => void;
102
+ /**
103
+ * @default button
104
+ */
105
+ accessibilityRole?: Extract<AccessibilityRole, "button" | "link">;
106
+ } & Pick<
107
+ ComponentProps<typeof Pressable>,
108
+ "disabled" | "accessibilityLabel" | "accessibilityHint"
109
+ >
110
+ >;
111
+
112
+ export const IOButton = forwardRef<View, IOButtonProps>(
113
+ (
114
+ {
115
+ variant = "solid",
116
+ color = "primary",
117
+ label,
118
+ fullWidth = false,
119
+ disabled = false,
120
+ loading = false,
121
+ numberOfLines = 1,
122
+ textAlign = "auto",
123
+ icon,
124
+ iconPosition = "start",
125
+ onPress,
126
+ accessibilityLabel,
127
+ accessibilityHint,
128
+ accessibilityRole = "button",
129
+ testID
130
+ },
131
+ ref
132
+ ) => {
133
+ const mapColorStates = useButtonColorMap(variant);
134
+ const { progress, onPressIn, onPressOut, scaleAnimatedStyle } =
135
+ useScaleAnimation();
136
+ const { buttonAnimatedStyle, labelAnimatedStyle, iconColorAnimatedStyle } =
137
+ useButtonAnimatedStyles(variant, color, progress);
138
+ const reducedMotion = useReducedMotion();
139
+ const { newTypefaceEnabled } = useIONewTypeface();
140
+
141
+ const isLinkButton = variant === "link";
142
+
143
+ // ---------------------------------------
144
+ // VISUAL ATTRIBUTES
145
+ // ---------------------------------------
146
+ const btnIconSizeMap: Record<IOButtonVariant, IOIconSizeScale> = {
147
+ solid: 20,
148
+ outline: 20,
149
+ link: 24
150
+ };
151
+
152
+ const btnBorderWidthMap: Record<IOButtonVariant, ViewStyle["borderWidth"]> =
153
+ {
154
+ solid: 0,
155
+ outline: 2,
156
+ link: 0
157
+ };
158
+
159
+ const btnPaddingHorizontalMap: Record<
160
+ string,
161
+ ViewStyle["paddingHorizontal"]
162
+ > = {
163
+ default: 24,
164
+ fullWidth: 16,
165
+ link: 0
166
+ };
167
+
168
+ const btnLinkHitSlop: PressableProps["hitSlop"] = {
169
+ top: 14,
170
+ right: 24,
171
+ bottom: 14,
172
+ left: 24
173
+ };
174
+
175
+ const btnIconSize = btnIconSizeMap[variant];
176
+ const btnBorderWidth = btnBorderWidthMap[variant];
177
+ const btnBorderRadius = 8;
178
+ const btnSizeDefault = 48;
179
+
180
+ const ICON_MARGIN = 8;
181
+ const DISABLED_OPACITY = 0.5;
182
+
183
+ // Background color
184
+ const backgroundColor: ColorValue = disabled
185
+ ? mapColorStates[color].background.disabled
186
+ : mapColorStates[color].background.default;
187
+
188
+ // Label & Icons colors
189
+ const foregroundColor: ColorValue = disabled
190
+ ? mapColorStates[color]?.foreground?.disabled
191
+ : mapColorStates[color]?.foreground?.default;
192
+
193
+ // ---------------------------------------
194
+ // BUTTON INNER LOGIC
195
+ // ---------------------------------------
196
+
197
+ /* Prevent the component from triggering the `isEntering' transition
198
+ on the on the first render. Solution from this discussion:
199
+ https://github.com/software-mansion/react-native-reanimated/discussions/2513
200
+ */
201
+ const isMounted = useRef<boolean>(false);
202
+
203
+ useEffect(() => {
204
+ // eslint-disable-next-line functional/immutable-data
205
+ isMounted.current = true;
206
+ }, []);
207
+
208
+ const handleOnPress = useCallback(
209
+ (event: GestureResponderEvent) => {
210
+ /* Don't call `onPress` if the button is
211
+ in loading state */
212
+ if (loading) {
213
+ return;
214
+ }
215
+ ReactNativeHapticFeedback.trigger("impactLight");
216
+ onPress(event);
217
+ },
218
+ [loading, onPress]
219
+ );
220
+
221
+ // ---------------------------------------
222
+ // BUTTON INNER CONTENT
223
+ // ---------------------------------------
224
+ const renderButtonContent = () => (
225
+ <>
226
+ {loading && (
227
+ <Animated.View
228
+ style={styles.buttonInner}
229
+ entering={
230
+ isMounted.current ? enterTransitionInnerContentSmall : undefined
231
+ }
232
+ exiting={exitTransitionInnerContent}
233
+ >
234
+ <LoadingSpinner color={foregroundColor} />
235
+ </Animated.View>
236
+ )}
237
+
238
+ {!loading && (
239
+ <Animated.View
240
+ style={[
241
+ styles.buttonInner,
242
+ { columnGap: ICON_MARGIN },
243
+ iconPosition === "end" && { flexDirection: "row-reverse" }
244
+ ]}
245
+ entering={
246
+ isMounted.current ? enterTransitionInnerContent : undefined
247
+ }
248
+ >
249
+ {icon &&
250
+ (!disabled ? (
251
+ <AnimatedIconWithColorTransition
252
+ allowFontScaling
253
+ name={icon}
254
+ animatedProps={iconColorAnimatedStyle}
255
+ size={btnIconSize}
256
+ />
257
+ ) : (
258
+ <AnimatedIcon
259
+ allowFontScaling
260
+ name={icon}
261
+ color={mapColorStates[color]?.foreground?.disabled}
262
+ size={btnIconSize}
263
+ />
264
+ ))}
265
+ <AnimatedIOText
266
+ font={newTypefaceEnabled ? "Titillio" : "TitilliumSansPro"}
267
+ weight={"Semibold"}
268
+ size={buttonTextFontSize}
269
+ lineHeight={isLinkButton ? buttonTextLineHeight : undefined}
270
+ accessible={false}
271
+ accessibilityElementsHidden
272
+ importantForAccessibility="no-hide-descendants"
273
+ numberOfLines={numberOfLines}
274
+ ellipsizeMode="tail"
275
+ style={[
276
+ { textAlign },
277
+ disabled
278
+ ? { color: mapColorStates[color]?.foreground?.disabled }
279
+ : { ...labelAnimatedStyle }
280
+ ]}
281
+ >
282
+ {label}
283
+ </AnimatedIOText>
284
+ </Animated.View>
285
+ )}
286
+ </>
287
+ );
288
+
289
+ return (
290
+ <Pressable
291
+ ref={ref}
292
+ accessible={true}
293
+ // Using || operator because empty string is not an accepted value
294
+ accessibilityLabel={accessibilityLabel || label}
295
+ accessibilityHint={accessibilityHint}
296
+ accessibilityRole={accessibilityRole}
297
+ accessibilityState={{
298
+ busy: loading,
299
+ disabled: disabled || false
300
+ }}
301
+ onPress={handleOnPress}
302
+ onPressIn={onPressIn}
303
+ onPressOut={onPressOut}
304
+ disabled={disabled}
305
+ hitSlop={isLinkButton ? btnLinkHitSlop : undefined}
306
+ style={
307
+ isLinkButton
308
+ ? { alignSelf: "flex-start" }
309
+ : fullWidth
310
+ ? { flexShrink: 0, alignSelf: "stretch" }
311
+ : { flexShrink: 1, alignSelf: "auto" }
312
+ }
313
+ testID={testID}
314
+ >
315
+ <Animated.View
316
+ style={[
317
+ styles.button,
318
+ {
319
+ paddingHorizontal: isLinkButton
320
+ ? btnPaddingHorizontalMap.link
321
+ : fullWidth
322
+ ? btnPaddingHorizontalMap.fullWidth
323
+ : btnPaddingHorizontalMap.default
324
+ },
325
+ {
326
+ height: isLinkButton ? undefined : btnSizeDefault,
327
+ backgroundColor,
328
+ borderWidth: btnBorderWidth,
329
+ borderRadius: btnBorderRadius,
330
+ borderColor: foregroundColor
331
+ },
332
+ disabled ? { opacity: DISABLED_OPACITY } : {},
333
+ /* Prevent Reanimated from overriding background colors
334
+ if button is disabled */
335
+ !disabled && !reducedMotion && scaleAnimatedStyle,
336
+ !disabled && buttonAnimatedStyle
337
+ ]}
338
+ >
339
+ {renderButtonContent()}
340
+ </Animated.View>
341
+ </Pressable>
342
+ );
343
+ }
344
+ );
345
+
346
+ const styles = StyleSheet.create({
347
+ button: {
348
+ flexDirection: "row",
349
+ alignItems: "center",
350
+ justifyContent: "center",
351
+ textAlignVertical: "center", // Prop supported on Android only
352
+ borderCurve: "continuous",
353
+ overflow: "hidden",
354
+ elevation: 0
355
+ },
356
+ buttonInner: {
357
+ flexDirection: "row",
358
+ alignItems: "center",
359
+ justifyContent: "center"
360
+ }
361
+ });
362
+
363
+ export default IOButton;
@@ -0,0 +1,46 @@
1
+ import React from "react";
2
+ import { Alert } from "react-native";
3
+ import * as TestRenderer from "react-test-renderer";
4
+ import IOButton from "../IOButton";
5
+
6
+ const onButtonPress = () => {
7
+ Alert.alert("Alert", "Action triggered");
8
+ };
9
+
10
+ describe("Test Buttons Components", () => {
11
+ it("IOButton Snapshot · Solid variant", () => {
12
+ const buttonSolid = TestRenderer.create(
13
+ <IOButton
14
+ variant="solid"
15
+ label={"label"}
16
+ accessibilityLabel={"accessibilityLabel"}
17
+ onPress={onButtonPress}
18
+ ></IOButton>
19
+ ).toJSON();
20
+ expect(buttonSolid).toMatchSnapshot();
21
+ });
22
+
23
+ it("IOButton Snapshot · Link variant", () => {
24
+ const buttonLink = TestRenderer.create(
25
+ <IOButton
26
+ variant="link"
27
+ label={"label"}
28
+ accessibilityLabel={"accessibilityLabel"}
29
+ onPress={onButtonPress}
30
+ ></IOButton>
31
+ ).toJSON();
32
+ expect(buttonLink).toMatchSnapshot();
33
+ });
34
+
35
+ it("IOButton Snapshot · Outline variant", () => {
36
+ const buttonOutline = TestRenderer.create(
37
+ <IOButton
38
+ variant="outline"
39
+ label={"label"}
40
+ accessibilityLabel={"accessibilityLabel"}
41
+ onPress={onButtonPress}
42
+ ></IOButton>
43
+ ).toJSON();
44
+ expect(buttonOutline).toMatchSnapshot();
45
+ });
46
+ });