@pagopa/io-app-design-system 1.0.0-9 → 1.0.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (265) hide show
  1. package/README.md +39 -4
  2. package/lib/commonjs/components/Advice/Advice.js +5 -7
  3. package/lib/commonjs/components/Advice/Advice.js.map +1 -1
  4. package/lib/commonjs/components/Advice/__test__/advice.test.js +2 -2
  5. package/lib/commonjs/components/Advice/__test__/advice.test.js.map +1 -1
  6. package/lib/commonjs/components/accordion/RawAccordion.js.map +1 -1
  7. package/lib/commonjs/components/badge/__test__/badge.test.js.map +1 -1
  8. package/lib/commonjs/components/buttons/ButtonLink.js +4 -5
  9. package/lib/commonjs/components/buttons/ButtonLink.js.map +1 -1
  10. package/lib/commonjs/components/buttons/IconButton.js +0 -2
  11. package/lib/commonjs/components/buttons/IconButton.js.map +1 -1
  12. package/lib/commonjs/components/buttons/IconButtonContained.js +131 -0
  13. package/lib/commonjs/components/buttons/IconButtonContained.js.map +1 -0
  14. package/lib/commonjs/components/buttons/IconButtonSolid.js +109 -0
  15. package/lib/commonjs/components/buttons/IconButtonSolid.js.map +1 -0
  16. package/lib/commonjs/components/buttons/__test__/__snapshots__/button.test.tsx.snap +370 -0
  17. package/lib/commonjs/components/buttons/__test__/button.test.js +27 -0
  18. package/lib/commonjs/components/buttons/__test__/button.test.js.map +1 -1
  19. package/lib/commonjs/components/buttons/index.js +30 -8
  20. package/lib/commonjs/components/buttons/index.js.map +1 -1
  21. package/lib/commonjs/components/checkbox/AnimatedCheckbox.js +1 -1
  22. package/lib/commonjs/components/checkbox/AnimatedCheckbox.js.map +1 -1
  23. package/lib/commonjs/components/icons/index.js +0 -18
  24. package/lib/commonjs/components/icons/index.js.map +1 -1
  25. package/lib/commonjs/components/index.js +72 -72
  26. package/lib/commonjs/components/index.js.map +1 -1
  27. package/lib/commonjs/components/layout/GradientBottomActions.js +90 -0
  28. package/lib/commonjs/components/layout/GradientBottomActions.js.map +1 -0
  29. package/lib/commonjs/components/layout/GradientScrollView.js +111 -0
  30. package/lib/commonjs/components/layout/GradientScrollView.js.map +1 -0
  31. package/lib/commonjs/components/layout/HeaderFirstLevel.js +62 -0
  32. package/lib/commonjs/components/layout/HeaderFirstLevel.js.map +1 -0
  33. package/lib/commonjs/components/layout/index.js +17 -0
  34. package/lib/commonjs/components/layout/index.js.map +1 -0
  35. package/lib/commonjs/components/listitems/ListItemCheckbox.js +135 -0
  36. package/lib/commonjs/components/listitems/ListItemCheckbox.js.map +1 -0
  37. package/lib/commonjs/components/listitems/ListItemInfo.js +3 -6
  38. package/lib/commonjs/components/listitems/ListItemInfo.js.map +1 -1
  39. package/lib/commonjs/components/listitems/ListItemInfoCopy.js +1 -4
  40. package/lib/commonjs/components/listitems/ListItemInfoCopy.js.map +1 -1
  41. package/lib/commonjs/components/listitems/ListItemRadio.js +136 -0
  42. package/lib/commonjs/components/listitems/ListItemRadio.js.map +1 -0
  43. package/lib/commonjs/components/listitems/ListItemSwitch.js +82 -0
  44. package/lib/commonjs/components/listitems/ListItemSwitch.js.map +1 -0
  45. package/lib/commonjs/components/listitems/ListItemTransaction.js.map +1 -1
  46. package/lib/commonjs/components/listitems/__test__/__snapshots__/listitem.test.tsx.snap +0 -14
  47. package/lib/commonjs/components/listitems/index.js +33 -0
  48. package/lib/commonjs/components/listitems/index.js.map +1 -1
  49. package/lib/commonjs/components/logos/svg/LogoPaymentExtMaestro.js +3 -19
  50. package/lib/commonjs/components/logos/svg/LogoPaymentExtMaestro.js.map +1 -1
  51. package/lib/commonjs/components/logos/svg/LogoPaymentExtMastercard.js +5 -21
  52. package/lib/commonjs/components/logos/svg/LogoPaymentExtMastercard.js.map +1 -1
  53. package/lib/commonjs/components/logos/svg/LogoPaymentExtPayPal.js +9 -28
  54. package/lib/commonjs/components/logos/svg/LogoPaymentExtPayPal.js.map +1 -1
  55. package/lib/commonjs/components/logos/svg/LogoPaymentMaestro.js +8 -18
  56. package/lib/commonjs/components/logos/svg/LogoPaymentMaestro.js.map +1 -1
  57. package/lib/commonjs/components/logos/svg/LogoPaymentMastercard.js +7 -17
  58. package/lib/commonjs/components/logos/svg/LogoPaymentMastercard.js.map +1 -1
  59. package/lib/commonjs/components/logos/svg/LogoPaymentPayPal.js +5 -5
  60. package/lib/commonjs/components/logos/svg/LogoPaymentPayPal.js.map +1 -1
  61. package/lib/commonjs/components/radio/AnimatedRadio.js +1 -1
  62. package/lib/commonjs/components/radio/AnimatedRadio.js.map +1 -1
  63. package/lib/commonjs/components/radio/RadioGroup.js +36 -0
  64. package/lib/commonjs/components/radio/RadioGroup.js.map +1 -0
  65. package/lib/commonjs/components/radio/index.js +11 -0
  66. package/lib/commonjs/components/radio/index.js.map +1 -1
  67. package/lib/commonjs/components/typography/H3.js +20 -49
  68. package/lib/commonjs/components/typography/H3.js.map +1 -1
  69. package/lib/commonjs/components/typography/Link.js +17 -23
  70. package/lib/commonjs/components/typography/Link.js.map +1 -1
  71. package/lib/commonjs/components/typography/__test__/__snapshots__/typography.test.tsx.snap +50 -45
  72. package/lib/commonjs/core/IOColors.js +1 -1
  73. package/lib/commonjs/core/IOColors.js.map +1 -1
  74. package/lib/commonjs/core/IOSpacing.js +1 -1
  75. package/lib/commonjs/core/IOSpacing.js.map +1 -1
  76. package/lib/commonjs/core/IOStyles.js +7 -1
  77. package/lib/commonjs/core/IOStyles.js.map +1 -1
  78. package/lib/commonjs/index.js +11 -0
  79. package/lib/commonjs/index.js.map +1 -1
  80. package/lib/commonjs/json-import.d.js +2 -0
  81. package/lib/commonjs/json-import.d.js.map +1 -0
  82. package/lib/module/components/Advice/Advice.js +4 -6
  83. package/lib/module/components/Advice/Advice.js.map +1 -1
  84. package/lib/module/components/Advice/__test__/advice.test.js +1 -1
  85. package/lib/module/components/Advice/__test__/advice.test.js.map +1 -1
  86. package/lib/module/components/accordion/RawAccordion.js +1 -1
  87. package/lib/module/components/accordion/RawAccordion.js.map +1 -1
  88. package/lib/module/components/badge/__test__/badge.test.js.map +1 -1
  89. package/lib/module/components/buttons/ButtonLink.js +4 -5
  90. package/lib/module/components/buttons/ButtonLink.js.map +1 -1
  91. package/lib/module/components/buttons/IconButton.js +0 -2
  92. package/lib/module/components/buttons/IconButton.js.map +1 -1
  93. package/lib/module/components/buttons/IconButtonContained.js +122 -0
  94. package/lib/module/components/buttons/IconButtonContained.js.map +1 -0
  95. package/lib/module/components/buttons/IconButtonSolid.js +100 -0
  96. package/lib/module/components/buttons/IconButtonSolid.js.map +1 -0
  97. package/lib/module/components/buttons/__test__/__snapshots__/button.test.tsx.snap +370 -0
  98. package/lib/module/components/buttons/__test__/button.test.js +27 -0
  99. package/lib/module/components/buttons/__test__/button.test.js.map +1 -1
  100. package/lib/module/components/buttons/index.js +4 -2
  101. package/lib/module/components/buttons/index.js.map +1 -1
  102. package/lib/module/components/checkbox/AnimatedCheckbox.js +3 -3
  103. package/lib/module/components/checkbox/AnimatedCheckbox.js.map +1 -1
  104. package/lib/module/components/icons/index.js +0 -1
  105. package/lib/module/components/icons/index.js.map +1 -1
  106. package/lib/module/components/index.js +13 -13
  107. package/lib/module/components/index.js.map +1 -1
  108. package/lib/module/components/layout/GradientBottomActions.js +79 -0
  109. package/lib/module/components/layout/GradientBottomActions.js.map +1 -0
  110. package/lib/module/components/layout/GradientScrollView.js +100 -0
  111. package/lib/module/components/layout/GradientScrollView.js.map +1 -0
  112. package/lib/module/components/layout/HeaderFirstLevel.js +52 -0
  113. package/lib/module/components/layout/HeaderFirstLevel.js.map +1 -0
  114. package/lib/module/components/layout/index.js +2 -0
  115. package/lib/module/components/layout/index.js.map +1 -0
  116. package/lib/module/components/listitems/ListItemCheckbox.js +126 -0
  117. package/lib/module/components/listitems/ListItemCheckbox.js.map +1 -0
  118. package/lib/module/components/listitems/ListItemInfo.js +3 -6
  119. package/lib/module/components/listitems/ListItemInfo.js.map +1 -1
  120. package/lib/module/components/listitems/ListItemInfoCopy.js +1 -4
  121. package/lib/module/components/listitems/ListItemInfoCopy.js.map +1 -1
  122. package/lib/module/components/listitems/ListItemRadio.js +127 -0
  123. package/lib/module/components/listitems/ListItemRadio.js.map +1 -0
  124. package/lib/module/components/listitems/ListItemSwitch.js +74 -0
  125. package/lib/module/components/listitems/ListItemSwitch.js.map +1 -0
  126. package/lib/module/components/listitems/ListItemTransaction.js.map +1 -1
  127. package/lib/module/components/listitems/__test__/__snapshots__/listitem.test.tsx.snap +0 -14
  128. package/lib/module/components/listitems/index.js +3 -0
  129. package/lib/module/components/listitems/index.js.map +1 -1
  130. package/lib/module/components/logos/svg/LogoPaymentExtMaestro.js +3 -19
  131. package/lib/module/components/logos/svg/LogoPaymentExtMaestro.js.map +1 -1
  132. package/lib/module/components/logos/svg/LogoPaymentExtMastercard.js +5 -21
  133. package/lib/module/components/logos/svg/LogoPaymentExtMastercard.js.map +1 -1
  134. package/lib/module/components/logos/svg/LogoPaymentExtPayPal.js +10 -29
  135. package/lib/module/components/logos/svg/LogoPaymentExtPayPal.js.map +1 -1
  136. package/lib/module/components/logos/svg/LogoPaymentMaestro.js +9 -19
  137. package/lib/module/components/logos/svg/LogoPaymentMaestro.js.map +1 -1
  138. package/lib/module/components/logos/svg/LogoPaymentMastercard.js +8 -18
  139. package/lib/module/components/logos/svg/LogoPaymentMastercard.js.map +1 -1
  140. package/lib/module/components/logos/svg/LogoPaymentPayPal.js +5 -5
  141. package/lib/module/components/logos/svg/LogoPaymentPayPal.js.map +1 -1
  142. package/lib/module/components/radio/AnimatedRadio.js +3 -3
  143. package/lib/module/components/radio/AnimatedRadio.js.map +1 -1
  144. package/lib/module/components/radio/RadioGroup.js +28 -0
  145. package/lib/module/components/radio/RadioGroup.js.map +1 -0
  146. package/lib/module/components/radio/index.js +1 -0
  147. package/lib/module/components/radio/index.js.map +1 -1
  148. package/lib/module/components/typography/H3.js +19 -47
  149. package/lib/module/components/typography/H3.js.map +1 -1
  150. package/lib/module/components/typography/Link.js +17 -23
  151. package/lib/module/components/typography/Link.js.map +1 -1
  152. package/lib/module/components/typography/__test__/__snapshots__/typography.test.tsx.snap +50 -45
  153. package/lib/module/core/IOColors.js +1 -1
  154. package/lib/module/core/IOColors.js.map +1 -1
  155. package/lib/module/core/IOSpacing.js +1 -1
  156. package/lib/module/core/IOSpacing.js.map +1 -1
  157. package/lib/module/core/IOStyles.js +5 -0
  158. package/lib/module/core/IOStyles.js.map +1 -1
  159. package/lib/module/index.js +1 -0
  160. package/lib/module/index.js.map +1 -1
  161. package/lib/module/json-import.d.js +2 -0
  162. package/lib/module/json-import.d.js.map +1 -0
  163. package/lib/typescript/components/Advice/Advice.d.ts +7 -3
  164. package/lib/typescript/components/Advice/Advice.d.ts.map +1 -1
  165. package/lib/typescript/components/accordion/RawAccordion.d.ts +2 -2
  166. package/lib/typescript/components/accordion/RawAccordion.d.ts.map +1 -1
  167. package/lib/typescript/components/buttons/ButtonLink.d.ts.map +1 -1
  168. package/lib/typescript/components/buttons/IconButton.d.ts.map +1 -1
  169. package/lib/typescript/components/buttons/IconButtonContained.d.ts +15 -0
  170. package/lib/typescript/components/buttons/IconButtonContained.d.ts.map +1 -0
  171. package/lib/typescript/components/buttons/IconButtonSolid.d.ts +15 -0
  172. package/lib/typescript/components/buttons/IconButtonSolid.d.ts.map +1 -0
  173. package/lib/typescript/components/buttons/index.d.ts +4 -2
  174. package/lib/typescript/components/buttons/index.d.ts.map +1 -1
  175. package/lib/typescript/components/checkbox/AnimatedCheckbox.d.ts.map +1 -1
  176. package/lib/typescript/components/icons/index.d.ts +0 -1
  177. package/lib/typescript/components/icons/index.d.ts.map +1 -1
  178. package/lib/typescript/components/index.d.ts +13 -13
  179. package/lib/typescript/components/index.d.ts.map +1 -1
  180. package/lib/typescript/components/layout/GradientBottomActions.d.ts +22 -0
  181. package/lib/typescript/components/layout/GradientBottomActions.d.ts.map +1 -0
  182. package/lib/typescript/components/layout/GradientScrollView.d.ts +14 -0
  183. package/lib/typescript/components/layout/GradientScrollView.d.ts.map +1 -0
  184. package/lib/typescript/components/layout/HeaderFirstLevel.d.ts +11 -0
  185. package/lib/typescript/components/layout/HeaderFirstLevel.d.ts.map +1 -0
  186. package/lib/typescript/components/layout/index.d.ts +2 -0
  187. package/lib/typescript/components/layout/index.d.ts.map +1 -0
  188. package/lib/typescript/components/listitems/ListItemCheckbox.d.ts +21 -0
  189. package/lib/typescript/components/listitems/ListItemCheckbox.d.ts.map +1 -0
  190. package/lib/typescript/components/listitems/ListItemInfo.d.ts.map +1 -1
  191. package/lib/typescript/components/listitems/ListItemInfoCopy.d.ts.map +1 -1
  192. package/lib/typescript/components/listitems/ListItemRadio.d.ts +22 -0
  193. package/lib/typescript/components/listitems/ListItemRadio.d.ts.map +1 -0
  194. package/lib/typescript/components/listitems/ListItemSwitch.d.ts +18 -0
  195. package/lib/typescript/components/listitems/ListItemSwitch.d.ts.map +1 -0
  196. package/lib/typescript/components/listitems/ListItemTransaction.d.ts.map +1 -1
  197. package/lib/typescript/components/listitems/index.d.ts +3 -0
  198. package/lib/typescript/components/listitems/index.d.ts.map +1 -1
  199. package/lib/typescript/components/logos/svg/LogoPaymentExtMaestro.d.ts.map +1 -1
  200. package/lib/typescript/components/logos/svg/LogoPaymentExtMastercard.d.ts +2 -2
  201. package/lib/typescript/components/logos/svg/LogoPaymentExtMastercard.d.ts.map +1 -1
  202. package/lib/typescript/components/logos/svg/LogoPaymentExtPayPal.d.ts.map +1 -1
  203. package/lib/typescript/components/logos/svg/LogoPaymentMaestro.d.ts.map +1 -1
  204. package/lib/typescript/components/logos/svg/LogoPaymentMastercard.d.ts.map +1 -1
  205. package/lib/typescript/components/radio/AnimatedRadio.d.ts.map +1 -1
  206. package/lib/typescript/components/radio/RadioGroup.d.ts +22 -0
  207. package/lib/typescript/components/radio/RadioGroup.d.ts.map +1 -0
  208. package/lib/typescript/components/radio/index.d.ts +1 -0
  209. package/lib/typescript/components/radio/index.d.ts.map +1 -1
  210. package/lib/typescript/components/typography/H3.d.ts +11 -30
  211. package/lib/typescript/components/typography/H3.d.ts.map +1 -1
  212. package/lib/typescript/components/typography/Link.d.ts +4 -4
  213. package/lib/typescript/components/typography/Link.d.ts.map +1 -1
  214. package/lib/typescript/core/IOColors.d.ts +2 -1
  215. package/lib/typescript/core/IOColors.d.ts.map +1 -1
  216. package/lib/typescript/core/IOSpacing.d.ts +1 -1
  217. package/lib/typescript/core/IOSpacing.d.ts.map +1 -1
  218. package/lib/typescript/core/IOStyles.d.ts +6 -2
  219. package/lib/typescript/core/IOStyles.d.ts.map +1 -1
  220. package/lib/typescript/index.d.ts +1 -0
  221. package/lib/typescript/index.d.ts.map +1 -1
  222. package/package.json +9 -5
  223. package/src/components/Advice/Advice.tsx +19 -23
  224. package/src/components/Advice/__test__/advice.test.tsx +4 -2
  225. package/src/components/accordion/RawAccordion.tsx +6 -6
  226. package/src/components/badge/__test__/badge.test.tsx +4 -2
  227. package/src/components/buttons/ButtonLink.tsx +177 -177
  228. package/src/components/buttons/IconButton.tsx +9 -6
  229. package/src/components/buttons/IconButtonContained.tsx +201 -0
  230. package/src/components/buttons/IconButtonSolid.tsx +168 -0
  231. package/src/components/buttons/__test__/__snapshots__/button.test.tsx.snap +370 -0
  232. package/src/components/buttons/__test__/button.test.tsx +59 -4
  233. package/src/components/buttons/index.tsx +5 -3
  234. package/src/components/checkbox/AnimatedCheckbox.tsx +6 -8
  235. package/src/components/icons/index.tsx +1 -2
  236. package/src/components/index.tsx +13 -13
  237. package/src/components/layout/GradientBottomActions.tsx +119 -0
  238. package/src/components/layout/GradientScrollView.tsx +167 -0
  239. package/src/components/layout/HeaderFirstLevel.tsx +76 -0
  240. package/src/components/layout/index.tsx +1 -0
  241. package/src/components/listitems/ListItemCheckbox.tsx +182 -0
  242. package/src/components/listitems/ListItemInfo.tsx +53 -58
  243. package/src/components/listitems/ListItemInfoCopy.tsx +122 -127
  244. package/src/components/listitems/ListItemRadio.tsx +185 -0
  245. package/src/components/listitems/ListItemSwitch.tsx +109 -0
  246. package/src/components/listitems/ListItemTransaction.tsx +154 -150
  247. package/src/components/listitems/__test__/__snapshots__/listitem.test.tsx.snap +0 -14
  248. package/src/components/listitems/index.tsx +3 -0
  249. package/src/components/logos/svg/LogoPaymentExtMaestro.tsx +3 -20
  250. package/src/components/logos/svg/LogoPaymentExtMastercard.tsx +5 -22
  251. package/src/components/logos/svg/LogoPaymentExtPayPal.tsx +9 -31
  252. package/src/components/logos/svg/LogoPaymentMaestro.tsx +8 -6
  253. package/src/components/logos/svg/LogoPaymentMastercard.tsx +8 -6
  254. package/src/components/logos/svg/LogoPaymentPayPal.tsx +5 -5
  255. package/src/components/radio/AnimatedRadio.tsx +6 -8
  256. package/src/components/radio/RadioGroup.tsx +43 -0
  257. package/src/components/radio/index.tsx +1 -0
  258. package/src/components/typography/H3.tsx +25 -91
  259. package/src/components/typography/Link.tsx +23 -30
  260. package/src/components/typography/__test__/__snapshots__/typography.test.tsx.snap +50 -45
  261. package/src/core/IOColors.ts +2 -2
  262. package/src/core/IOSpacing.ts +2 -2
  263. package/src/core/IOStyles.ts +9 -0
  264. package/src/index.tsx +1 -0
  265. package/src/json-import.d.ts +13 -0
@@ -0,0 +1,201 @@
1
+ import * as React from "react";
2
+ import { useCallback } from "react";
3
+ import { GestureResponderEvent, Pressable } from "react-native";
4
+ import Animated, {
5
+ Extrapolate,
6
+ interpolate,
7
+ interpolateColor,
8
+ useAnimatedProps,
9
+ useAnimatedStyle,
10
+ useDerivedValue,
11
+ useSharedValue,
12
+ withSpring
13
+ } from "react-native-reanimated";
14
+ import { WithTestID } from "src/utils/types";
15
+ import {
16
+ AnimatedIcon,
17
+ IOIcons,
18
+ IconClassComponent
19
+ } from "../../components/icons";
20
+ import {
21
+ IOButtonStyles,
22
+ IOColors,
23
+ IOIconButtonStyles,
24
+ IOScaleValues,
25
+ IOSpringValues,
26
+ hexToRgba
27
+ } from "../../core";
28
+
29
+ export type IconButtonContained = WithTestID<{
30
+ icon: IOIcons;
31
+ color?: "primary" | "neutral" | "contrast";
32
+ disabled?: boolean;
33
+ accessibilityLabel: string;
34
+ accessibilityHint?: string;
35
+ onPress: (event: GestureResponderEvent) => void;
36
+ }>;
37
+
38
+ type ColorStates = {
39
+ background: {
40
+ default: string;
41
+ pressed: string;
42
+ disabled: string;
43
+ };
44
+ icon: {
45
+ default: string;
46
+ pressed: string;
47
+ disabled: string;
48
+ };
49
+ };
50
+
51
+ const mapColorStates: Record<
52
+ NonNullable<IconButtonContained["color"]>,
53
+ ColorStates
54
+ > = {
55
+ // Primary button
56
+ primary: {
57
+ background: {
58
+ default: hexToRgba(IOColors["blueIO-500"], 0),
59
+ pressed: hexToRgba(IOColors["blueIO-500"], 0.15),
60
+ disabled: "transparent"
61
+ },
62
+ icon: {
63
+ default: IOColors["blueIO-500"],
64
+ pressed: IOColors["blueIO-600"],
65
+ disabled: hexToRgba(IOColors["blueIO-500"], 0.25)
66
+ }
67
+ },
68
+ // Neutral button
69
+ neutral: {
70
+ background: {
71
+ default: IOColors.white,
72
+ pressed: IOColors.greyUltraLight,
73
+ disabled: "transparent"
74
+ },
75
+ icon: {
76
+ default: IOColors.bluegrey,
77
+ pressed: IOColors.black,
78
+ disabled: IOColors.grey
79
+ }
80
+ },
81
+ // Contrast button
82
+ contrast: {
83
+ background: {
84
+ default: hexToRgba(IOColors.white, 0),
85
+ pressed: hexToRgba(IOColors.white, 0.2),
86
+ disabled: "transparent"
87
+ },
88
+ icon: {
89
+ default: IOColors.white,
90
+ pressed: IOColors.white,
91
+ disabled: hexToRgba(IOColors.white, 0.25)
92
+ }
93
+ }
94
+ };
95
+
96
+ const AnimatedIconClassComponent =
97
+ Animated.createAnimatedComponent(IconClassComponent);
98
+
99
+ export const IconButtonContained = ({
100
+ icon,
101
+ color = "primary",
102
+ disabled = false,
103
+ onPress,
104
+ accessibilityLabel,
105
+ accessibilityHint,
106
+ testID
107
+ }: IconButtonContained) => {
108
+ const isPressed = useSharedValue(0);
109
+
110
+ // Scaling transformation applied when the button is pressed
111
+ const animationScaleValue = IOScaleValues?.exaggeratedButton?.pressedState;
112
+
113
+ // Using a spring-based animation for our interpolations
114
+ const progressPressed = useDerivedValue(() =>
115
+ withSpring(isPressed.value, IOSpringValues.button)
116
+ );
117
+
118
+ // Interpolate animation values from `isPressed` values
119
+
120
+ const pressedAnimationStyle = useAnimatedStyle(() => {
121
+ // Link color states to the pressed states
122
+ const backgroundColor = interpolateColor(
123
+ progressPressed.value,
124
+ [0, 1],
125
+ [
126
+ mapColorStates[color].background.default,
127
+ mapColorStates[color].background.pressed
128
+ ]
129
+ );
130
+
131
+ // Scale down button slightly when pressed
132
+ const scale = interpolate(
133
+ progressPressed.value,
134
+ [0, 1],
135
+ [1, animationScaleValue],
136
+ Extrapolate.CLAMP
137
+ );
138
+
139
+ return {
140
+ backgroundColor,
141
+ transform: [{ scale }]
142
+ };
143
+ });
144
+
145
+ // Animate the <Icon> color prop
146
+ const animatedColor = useAnimatedProps(() => {
147
+ const iconColor = interpolateColor(
148
+ progressPressed.value,
149
+ [0, 1],
150
+ [mapColorStates[color].icon.default, mapColorStates[color].icon.pressed]
151
+ );
152
+ return { color: iconColor };
153
+ });
154
+
155
+ const handlePressIn = useCallback(() => {
156
+ // eslint-disable-next-line functional/immutable-data
157
+ isPressed.value = 1;
158
+ }, [isPressed]);
159
+ const handlePressOut = useCallback(() => {
160
+ // eslint-disable-next-line functional/immutable-data
161
+ isPressed.value = 0;
162
+ }, [isPressed]);
163
+
164
+ return (
165
+ <Pressable
166
+ accessibilityLabel={accessibilityLabel}
167
+ accessibilityHint={accessibilityHint}
168
+ accessibilityRole={"button"}
169
+ testID={testID}
170
+ onPress={onPress}
171
+ onPressIn={handlePressIn}
172
+ onPressOut={handlePressOut}
173
+ accessible={true}
174
+ disabled={disabled}
175
+ style={IOButtonStyles.dimensionsDefault}
176
+ >
177
+ <Animated.View
178
+ style={[
179
+ IOIconButtonStyles.button,
180
+ IOIconButtonStyles.buttonSizeDefault,
181
+ !disabled && pressedAnimationStyle
182
+ ]}
183
+ >
184
+ {!disabled ? (
185
+ <AnimatedIconClassComponent
186
+ name={icon}
187
+ animatedProps={animatedColor}
188
+ color={mapColorStates[color]?.icon?.default}
189
+ />
190
+ ) : (
191
+ <AnimatedIcon
192
+ name={icon}
193
+ color={mapColorStates[color]?.icon?.disabled}
194
+ />
195
+ )}
196
+ </Animated.View>
197
+ </Pressable>
198
+ );
199
+ };
200
+
201
+ export default IconButtonContained;
@@ -0,0 +1,168 @@
1
+ import * as React from "react";
2
+ import { useCallback } from "react";
3
+ import { GestureResponderEvent, Pressable } from "react-native";
4
+ import Animated, {
5
+ Extrapolate,
6
+ interpolate,
7
+ interpolateColor,
8
+ useAnimatedStyle,
9
+ useDerivedValue,
10
+ useSharedValue,
11
+ withSpring
12
+ } from "react-native-reanimated";
13
+ import {
14
+ IOButtonStyles,
15
+ IOIconButtonStyles,
16
+ IOScaleValues,
17
+ IOSpringValues
18
+ } from "../../core";
19
+ import { IOColors, hexToRgba } from "../../core/IOColors";
20
+ import { WithTestID } from "../../utils/types";
21
+ import { AnimatedIcon, IOIcons } from "../icons";
22
+
23
+ export type IconButtonSolid = WithTestID<{
24
+ icon: IOIcons;
25
+ color?: "primary" | "contrast";
26
+ disabled?: boolean;
27
+ accessibilityLabel: string;
28
+ accessibilityHint?: string;
29
+ onPress: (event: GestureResponderEvent) => void;
30
+ }>;
31
+
32
+ type ColorStates = {
33
+ background: {
34
+ default: string;
35
+ pressed: string;
36
+ disabled: string;
37
+ };
38
+ icon: {
39
+ default: string;
40
+ disabled: string;
41
+ };
42
+ };
43
+
44
+ const mapColorStates: Record<
45
+ NonNullable<IconButtonSolid["color"]>,
46
+ ColorStates
47
+ > = {
48
+ // Primary button
49
+ primary: {
50
+ background: {
51
+ default: IOColors["blueIO-500"],
52
+ pressed: IOColors["blueIO-600"],
53
+ disabled: IOColors["grey-100"]
54
+ },
55
+ icon: {
56
+ default: IOColors.white,
57
+ disabled: IOColors["grey-450"]
58
+ }
59
+ },
60
+ contrast: {
61
+ background: {
62
+ default: IOColors.white,
63
+ pressed: IOColors["blueIO-50"],
64
+ disabled: hexToRgba(IOColors.white, 0.25)
65
+ },
66
+ icon: {
67
+ default: IOColors["blueIO-500"],
68
+ disabled: IOColors["blueIO-500"]
69
+ }
70
+ }
71
+ };
72
+
73
+ export const IconButtonSolid = ({
74
+ icon,
75
+ color = "primary",
76
+ disabled = false,
77
+ onPress,
78
+ accessibilityLabel,
79
+ accessibilityHint,
80
+ testID
81
+ }: IconButtonSolid) => {
82
+ const isPressed = useSharedValue(0);
83
+
84
+ // Scaling transformation applied when the button is pressed
85
+ const animationScaleValue = IOScaleValues?.exaggeratedButton?.pressedState;
86
+
87
+ // Using a spring-based animation for our interpolations
88
+ const progressPressed = useDerivedValue(() =>
89
+ withSpring(isPressed.value, IOSpringValues.button)
90
+ );
91
+
92
+ // Interpolate animation values from `isPressed` values
93
+ const pressedAnimationStyle = useAnimatedStyle(() => {
94
+ const backgroundColor = interpolateColor(
95
+ progressPressed.value,
96
+ [0, 1],
97
+ [
98
+ mapColorStates[color].background.default,
99
+ mapColorStates[color].background.pressed
100
+ ]
101
+ );
102
+
103
+ // Scale down button slightly when pressed
104
+ const scale = interpolate(
105
+ progressPressed.value,
106
+ [0, 1],
107
+ [1, animationScaleValue],
108
+ Extrapolate.CLAMP
109
+ );
110
+
111
+ return {
112
+ backgroundColor,
113
+ transform: [{ scale }]
114
+ };
115
+ });
116
+
117
+ const handlePressIn = useCallback(() => {
118
+ // eslint-disable-next-line functional/immutable-data
119
+ isPressed.value = 1;
120
+ }, [isPressed]);
121
+ const handlePressOut = useCallback(() => {
122
+ // eslint-disable-next-line functional/immutable-data
123
+ isPressed.value = 0;
124
+ }, [isPressed]);
125
+
126
+ const NewButton = () => (
127
+ <Pressable
128
+ accessibilityLabel={accessibilityLabel}
129
+ accessibilityHint={accessibilityHint}
130
+ accessibilityRole={"button"}
131
+ testID={testID}
132
+ onPress={onPress}
133
+ onPressIn={handlePressIn}
134
+ onPressOut={handlePressOut}
135
+ accessible={true}
136
+ disabled={disabled}
137
+ style={IOButtonStyles.dimensionsDefault}
138
+ >
139
+ <Animated.View
140
+ style={[
141
+ IOIconButtonStyles.button,
142
+ IOIconButtonStyles.buttonSizeLarge,
143
+ !disabled && pressedAnimationStyle,
144
+ disabled
145
+ ? {
146
+ backgroundColor: mapColorStates[color]?.background?.disabled
147
+ }
148
+ : {
149
+ backgroundColor: mapColorStates[color]?.background?.default
150
+ }
151
+ ]}
152
+ >
153
+ <AnimatedIcon
154
+ name={icon}
155
+ color={
156
+ !disabled
157
+ ? mapColorStates[color]?.icon?.default
158
+ : mapColorStates[color]?.icon?.disabled
159
+ }
160
+ />
161
+ </Animated.View>
162
+ </Pressable>
163
+ );
164
+
165
+ return <NewButton />;
166
+ };
167
+
168
+ export default IconButtonSolid;