@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.
- package/README.md +39 -4
- package/lib/commonjs/components/Advice/Advice.js +5 -7
- package/lib/commonjs/components/Advice/Advice.js.map +1 -1
- package/lib/commonjs/components/Advice/__test__/advice.test.js +2 -2
- package/lib/commonjs/components/Advice/__test__/advice.test.js.map +1 -1
- package/lib/commonjs/components/accordion/RawAccordion.js.map +1 -1
- package/lib/commonjs/components/badge/__test__/badge.test.js.map +1 -1
- package/lib/commonjs/components/buttons/ButtonLink.js +4 -5
- package/lib/commonjs/components/buttons/ButtonLink.js.map +1 -1
- package/lib/commonjs/components/buttons/IconButton.js +0 -2
- package/lib/commonjs/components/buttons/IconButton.js.map +1 -1
- package/lib/commonjs/components/buttons/IconButtonContained.js +131 -0
- package/lib/commonjs/components/buttons/IconButtonContained.js.map +1 -0
- package/lib/commonjs/components/buttons/IconButtonSolid.js +109 -0
- package/lib/commonjs/components/buttons/IconButtonSolid.js.map +1 -0
- package/lib/commonjs/components/buttons/__test__/__snapshots__/button.test.tsx.snap +370 -0
- package/lib/commonjs/components/buttons/__test__/button.test.js +27 -0
- package/lib/commonjs/components/buttons/__test__/button.test.js.map +1 -1
- package/lib/commonjs/components/buttons/index.js +30 -8
- package/lib/commonjs/components/buttons/index.js.map +1 -1
- package/lib/commonjs/components/checkbox/AnimatedCheckbox.js +1 -1
- package/lib/commonjs/components/checkbox/AnimatedCheckbox.js.map +1 -1
- package/lib/commonjs/components/icons/index.js +0 -18
- package/lib/commonjs/components/icons/index.js.map +1 -1
- package/lib/commonjs/components/index.js +72 -72
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/components/layout/GradientBottomActions.js +90 -0
- package/lib/commonjs/components/layout/GradientBottomActions.js.map +1 -0
- package/lib/commonjs/components/layout/GradientScrollView.js +111 -0
- package/lib/commonjs/components/layout/GradientScrollView.js.map +1 -0
- package/lib/commonjs/components/layout/HeaderFirstLevel.js +62 -0
- package/lib/commonjs/components/layout/HeaderFirstLevel.js.map +1 -0
- package/lib/commonjs/components/layout/index.js +17 -0
- package/lib/commonjs/components/layout/index.js.map +1 -0
- package/lib/commonjs/components/listitems/ListItemCheckbox.js +135 -0
- package/lib/commonjs/components/listitems/ListItemCheckbox.js.map +1 -0
- package/lib/commonjs/components/listitems/ListItemInfo.js +3 -6
- package/lib/commonjs/components/listitems/ListItemInfo.js.map +1 -1
- package/lib/commonjs/components/listitems/ListItemInfoCopy.js +1 -4
- package/lib/commonjs/components/listitems/ListItemInfoCopy.js.map +1 -1
- package/lib/commonjs/components/listitems/ListItemRadio.js +136 -0
- package/lib/commonjs/components/listitems/ListItemRadio.js.map +1 -0
- package/lib/commonjs/components/listitems/ListItemSwitch.js +82 -0
- package/lib/commonjs/components/listitems/ListItemSwitch.js.map +1 -0
- package/lib/commonjs/components/listitems/ListItemTransaction.js.map +1 -1
- package/lib/commonjs/components/listitems/__test__/__snapshots__/listitem.test.tsx.snap +0 -14
- package/lib/commonjs/components/listitems/index.js +33 -0
- package/lib/commonjs/components/listitems/index.js.map +1 -1
- package/lib/commonjs/components/logos/svg/LogoPaymentExtMaestro.js +3 -19
- package/lib/commonjs/components/logos/svg/LogoPaymentExtMaestro.js.map +1 -1
- package/lib/commonjs/components/logos/svg/LogoPaymentExtMastercard.js +5 -21
- package/lib/commonjs/components/logos/svg/LogoPaymentExtMastercard.js.map +1 -1
- package/lib/commonjs/components/logos/svg/LogoPaymentExtPayPal.js +9 -28
- package/lib/commonjs/components/logos/svg/LogoPaymentExtPayPal.js.map +1 -1
- package/lib/commonjs/components/logos/svg/LogoPaymentMaestro.js +8 -18
- package/lib/commonjs/components/logos/svg/LogoPaymentMaestro.js.map +1 -1
- package/lib/commonjs/components/logos/svg/LogoPaymentMastercard.js +7 -17
- package/lib/commonjs/components/logos/svg/LogoPaymentMastercard.js.map +1 -1
- package/lib/commonjs/components/logos/svg/LogoPaymentPayPal.js +5 -5
- package/lib/commonjs/components/logos/svg/LogoPaymentPayPal.js.map +1 -1
- package/lib/commonjs/components/radio/AnimatedRadio.js +1 -1
- package/lib/commonjs/components/radio/AnimatedRadio.js.map +1 -1
- package/lib/commonjs/components/radio/RadioGroup.js +36 -0
- package/lib/commonjs/components/radio/RadioGroup.js.map +1 -0
- package/lib/commonjs/components/radio/index.js +11 -0
- package/lib/commonjs/components/radio/index.js.map +1 -1
- package/lib/commonjs/components/typography/H3.js +20 -49
- package/lib/commonjs/components/typography/H3.js.map +1 -1
- package/lib/commonjs/components/typography/Link.js +17 -23
- package/lib/commonjs/components/typography/Link.js.map +1 -1
- package/lib/commonjs/components/typography/__test__/__snapshots__/typography.test.tsx.snap +50 -45
- package/lib/commonjs/core/IOColors.js +1 -1
- package/lib/commonjs/core/IOColors.js.map +1 -1
- package/lib/commonjs/core/IOSpacing.js +1 -1
- package/lib/commonjs/core/IOSpacing.js.map +1 -1
- package/lib/commonjs/core/IOStyles.js +7 -1
- package/lib/commonjs/core/IOStyles.js.map +1 -1
- package/lib/commonjs/index.js +11 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/commonjs/json-import.d.js +2 -0
- package/lib/commonjs/json-import.d.js.map +1 -0
- package/lib/module/components/Advice/Advice.js +4 -6
- package/lib/module/components/Advice/Advice.js.map +1 -1
- package/lib/module/components/Advice/__test__/advice.test.js +1 -1
- package/lib/module/components/Advice/__test__/advice.test.js.map +1 -1
- package/lib/module/components/accordion/RawAccordion.js +1 -1
- package/lib/module/components/accordion/RawAccordion.js.map +1 -1
- package/lib/module/components/badge/__test__/badge.test.js.map +1 -1
- package/lib/module/components/buttons/ButtonLink.js +4 -5
- package/lib/module/components/buttons/ButtonLink.js.map +1 -1
- package/lib/module/components/buttons/IconButton.js +0 -2
- package/lib/module/components/buttons/IconButton.js.map +1 -1
- package/lib/module/components/buttons/IconButtonContained.js +122 -0
- package/lib/module/components/buttons/IconButtonContained.js.map +1 -0
- package/lib/module/components/buttons/IconButtonSolid.js +100 -0
- package/lib/module/components/buttons/IconButtonSolid.js.map +1 -0
- package/lib/module/components/buttons/__test__/__snapshots__/button.test.tsx.snap +370 -0
- package/lib/module/components/buttons/__test__/button.test.js +27 -0
- package/lib/module/components/buttons/__test__/button.test.js.map +1 -1
- package/lib/module/components/buttons/index.js +4 -2
- package/lib/module/components/buttons/index.js.map +1 -1
- package/lib/module/components/checkbox/AnimatedCheckbox.js +3 -3
- package/lib/module/components/checkbox/AnimatedCheckbox.js.map +1 -1
- package/lib/module/components/icons/index.js +0 -1
- package/lib/module/components/icons/index.js.map +1 -1
- package/lib/module/components/index.js +13 -13
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/components/layout/GradientBottomActions.js +79 -0
- package/lib/module/components/layout/GradientBottomActions.js.map +1 -0
- package/lib/module/components/layout/GradientScrollView.js +100 -0
- package/lib/module/components/layout/GradientScrollView.js.map +1 -0
- package/lib/module/components/layout/HeaderFirstLevel.js +52 -0
- package/lib/module/components/layout/HeaderFirstLevel.js.map +1 -0
- package/lib/module/components/layout/index.js +2 -0
- package/lib/module/components/layout/index.js.map +1 -0
- package/lib/module/components/listitems/ListItemCheckbox.js +126 -0
- package/lib/module/components/listitems/ListItemCheckbox.js.map +1 -0
- package/lib/module/components/listitems/ListItemInfo.js +3 -6
- package/lib/module/components/listitems/ListItemInfo.js.map +1 -1
- package/lib/module/components/listitems/ListItemInfoCopy.js +1 -4
- package/lib/module/components/listitems/ListItemInfoCopy.js.map +1 -1
- package/lib/module/components/listitems/ListItemRadio.js +127 -0
- package/lib/module/components/listitems/ListItemRadio.js.map +1 -0
- package/lib/module/components/listitems/ListItemSwitch.js +74 -0
- package/lib/module/components/listitems/ListItemSwitch.js.map +1 -0
- package/lib/module/components/listitems/ListItemTransaction.js.map +1 -1
- package/lib/module/components/listitems/__test__/__snapshots__/listitem.test.tsx.snap +0 -14
- package/lib/module/components/listitems/index.js +3 -0
- package/lib/module/components/listitems/index.js.map +1 -1
- package/lib/module/components/logos/svg/LogoPaymentExtMaestro.js +3 -19
- package/lib/module/components/logos/svg/LogoPaymentExtMaestro.js.map +1 -1
- package/lib/module/components/logos/svg/LogoPaymentExtMastercard.js +5 -21
- package/lib/module/components/logos/svg/LogoPaymentExtMastercard.js.map +1 -1
- package/lib/module/components/logos/svg/LogoPaymentExtPayPal.js +10 -29
- package/lib/module/components/logos/svg/LogoPaymentExtPayPal.js.map +1 -1
- package/lib/module/components/logos/svg/LogoPaymentMaestro.js +9 -19
- package/lib/module/components/logos/svg/LogoPaymentMaestro.js.map +1 -1
- package/lib/module/components/logos/svg/LogoPaymentMastercard.js +8 -18
- package/lib/module/components/logos/svg/LogoPaymentMastercard.js.map +1 -1
- package/lib/module/components/logos/svg/LogoPaymentPayPal.js +5 -5
- package/lib/module/components/logos/svg/LogoPaymentPayPal.js.map +1 -1
- package/lib/module/components/radio/AnimatedRadio.js +3 -3
- package/lib/module/components/radio/AnimatedRadio.js.map +1 -1
- package/lib/module/components/radio/RadioGroup.js +28 -0
- package/lib/module/components/radio/RadioGroup.js.map +1 -0
- package/lib/module/components/radio/index.js +1 -0
- package/lib/module/components/radio/index.js.map +1 -1
- package/lib/module/components/typography/H3.js +19 -47
- package/lib/module/components/typography/H3.js.map +1 -1
- package/lib/module/components/typography/Link.js +17 -23
- package/lib/module/components/typography/Link.js.map +1 -1
- package/lib/module/components/typography/__test__/__snapshots__/typography.test.tsx.snap +50 -45
- package/lib/module/core/IOColors.js +1 -1
- package/lib/module/core/IOColors.js.map +1 -1
- package/lib/module/core/IOSpacing.js +1 -1
- package/lib/module/core/IOSpacing.js.map +1 -1
- package/lib/module/core/IOStyles.js +5 -0
- package/lib/module/core/IOStyles.js.map +1 -1
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/module/json-import.d.js +2 -0
- package/lib/module/json-import.d.js.map +1 -0
- package/lib/typescript/components/Advice/Advice.d.ts +7 -3
- package/lib/typescript/components/Advice/Advice.d.ts.map +1 -1
- package/lib/typescript/components/accordion/RawAccordion.d.ts +2 -2
- package/lib/typescript/components/accordion/RawAccordion.d.ts.map +1 -1
- package/lib/typescript/components/buttons/ButtonLink.d.ts.map +1 -1
- package/lib/typescript/components/buttons/IconButton.d.ts.map +1 -1
- package/lib/typescript/components/buttons/IconButtonContained.d.ts +15 -0
- package/lib/typescript/components/buttons/IconButtonContained.d.ts.map +1 -0
- package/lib/typescript/components/buttons/IconButtonSolid.d.ts +15 -0
- package/lib/typescript/components/buttons/IconButtonSolid.d.ts.map +1 -0
- package/lib/typescript/components/buttons/index.d.ts +4 -2
- package/lib/typescript/components/buttons/index.d.ts.map +1 -1
- package/lib/typescript/components/checkbox/AnimatedCheckbox.d.ts.map +1 -1
- package/lib/typescript/components/icons/index.d.ts +0 -1
- package/lib/typescript/components/icons/index.d.ts.map +1 -1
- package/lib/typescript/components/index.d.ts +13 -13
- package/lib/typescript/components/index.d.ts.map +1 -1
- package/lib/typescript/components/layout/GradientBottomActions.d.ts +22 -0
- package/lib/typescript/components/layout/GradientBottomActions.d.ts.map +1 -0
- package/lib/typescript/components/layout/GradientScrollView.d.ts +14 -0
- package/lib/typescript/components/layout/GradientScrollView.d.ts.map +1 -0
- package/lib/typescript/components/layout/HeaderFirstLevel.d.ts +11 -0
- package/lib/typescript/components/layout/HeaderFirstLevel.d.ts.map +1 -0
- package/lib/typescript/components/layout/index.d.ts +2 -0
- package/lib/typescript/components/layout/index.d.ts.map +1 -0
- package/lib/typescript/components/listitems/ListItemCheckbox.d.ts +21 -0
- package/lib/typescript/components/listitems/ListItemCheckbox.d.ts.map +1 -0
- package/lib/typescript/components/listitems/ListItemInfo.d.ts.map +1 -1
- package/lib/typescript/components/listitems/ListItemInfoCopy.d.ts.map +1 -1
- package/lib/typescript/components/listitems/ListItemRadio.d.ts +22 -0
- package/lib/typescript/components/listitems/ListItemRadio.d.ts.map +1 -0
- package/lib/typescript/components/listitems/ListItemSwitch.d.ts +18 -0
- package/lib/typescript/components/listitems/ListItemSwitch.d.ts.map +1 -0
- package/lib/typescript/components/listitems/ListItemTransaction.d.ts.map +1 -1
- package/lib/typescript/components/listitems/index.d.ts +3 -0
- package/lib/typescript/components/listitems/index.d.ts.map +1 -1
- package/lib/typescript/components/logos/svg/LogoPaymentExtMaestro.d.ts.map +1 -1
- package/lib/typescript/components/logos/svg/LogoPaymentExtMastercard.d.ts +2 -2
- package/lib/typescript/components/logos/svg/LogoPaymentExtMastercard.d.ts.map +1 -1
- package/lib/typescript/components/logos/svg/LogoPaymentExtPayPal.d.ts.map +1 -1
- package/lib/typescript/components/logos/svg/LogoPaymentMaestro.d.ts.map +1 -1
- package/lib/typescript/components/logos/svg/LogoPaymentMastercard.d.ts.map +1 -1
- package/lib/typescript/components/radio/AnimatedRadio.d.ts.map +1 -1
- package/lib/typescript/components/radio/RadioGroup.d.ts +22 -0
- package/lib/typescript/components/radio/RadioGroup.d.ts.map +1 -0
- package/lib/typescript/components/radio/index.d.ts +1 -0
- package/lib/typescript/components/radio/index.d.ts.map +1 -1
- package/lib/typescript/components/typography/H3.d.ts +11 -30
- package/lib/typescript/components/typography/H3.d.ts.map +1 -1
- package/lib/typescript/components/typography/Link.d.ts +4 -4
- package/lib/typescript/components/typography/Link.d.ts.map +1 -1
- package/lib/typescript/core/IOColors.d.ts +2 -1
- package/lib/typescript/core/IOColors.d.ts.map +1 -1
- package/lib/typescript/core/IOSpacing.d.ts +1 -1
- package/lib/typescript/core/IOSpacing.d.ts.map +1 -1
- package/lib/typescript/core/IOStyles.d.ts +6 -2
- package/lib/typescript/core/IOStyles.d.ts.map +1 -1
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +9 -5
- package/src/components/Advice/Advice.tsx +19 -23
- package/src/components/Advice/__test__/advice.test.tsx +4 -2
- package/src/components/accordion/RawAccordion.tsx +6 -6
- package/src/components/badge/__test__/badge.test.tsx +4 -2
- package/src/components/buttons/ButtonLink.tsx +177 -177
- package/src/components/buttons/IconButton.tsx +9 -6
- package/src/components/buttons/IconButtonContained.tsx +201 -0
- package/src/components/buttons/IconButtonSolid.tsx +168 -0
- package/src/components/buttons/__test__/__snapshots__/button.test.tsx.snap +370 -0
- package/src/components/buttons/__test__/button.test.tsx +59 -4
- package/src/components/buttons/index.tsx +5 -3
- package/src/components/checkbox/AnimatedCheckbox.tsx +6 -8
- package/src/components/icons/index.tsx +1 -2
- package/src/components/index.tsx +13 -13
- package/src/components/layout/GradientBottomActions.tsx +119 -0
- package/src/components/layout/GradientScrollView.tsx +167 -0
- package/src/components/layout/HeaderFirstLevel.tsx +76 -0
- package/src/components/layout/index.tsx +1 -0
- package/src/components/listitems/ListItemCheckbox.tsx +182 -0
- package/src/components/listitems/ListItemInfo.tsx +53 -58
- package/src/components/listitems/ListItemInfoCopy.tsx +122 -127
- package/src/components/listitems/ListItemRadio.tsx +185 -0
- package/src/components/listitems/ListItemSwitch.tsx +109 -0
- package/src/components/listitems/ListItemTransaction.tsx +154 -150
- package/src/components/listitems/__test__/__snapshots__/listitem.test.tsx.snap +0 -14
- package/src/components/listitems/index.tsx +3 -0
- package/src/components/logos/svg/LogoPaymentExtMaestro.tsx +3 -20
- package/src/components/logos/svg/LogoPaymentExtMastercard.tsx +5 -22
- package/src/components/logos/svg/LogoPaymentExtPayPal.tsx +9 -31
- package/src/components/logos/svg/LogoPaymentMaestro.tsx +8 -6
- package/src/components/logos/svg/LogoPaymentMastercard.tsx +8 -6
- package/src/components/logos/svg/LogoPaymentPayPal.tsx +5 -5
- package/src/components/radio/AnimatedRadio.tsx +6 -8
- package/src/components/radio/RadioGroup.tsx +43 -0
- package/src/components/radio/index.tsx +1 -0
- package/src/components/typography/H3.tsx +25 -91
- package/src/components/typography/Link.tsx +23 -30
- package/src/components/typography/__test__/__snapshots__/typography.test.tsx.snap +50 -45
- package/src/core/IOColors.ts +2 -2
- package/src/core/IOSpacing.ts +2 -2
- package/src/core/IOStyles.ts +9 -0
- package/src/index.tsx +1 -0
- 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;
|