@pagopa/io-app-design-system 4.5.6 → 4.6.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/commonjs/components/accordion/AccordionItem.js +20 -56
- package/lib/commonjs/components/accordion/AccordionItem.js.map +1 -1
- package/lib/commonjs/components/claimsSelector/ClaimsSelector.js +119 -0
- package/lib/commonjs/components/claimsSelector/ClaimsSelector.js.map +1 -0
- package/lib/commonjs/components/claimsSelector/__test__/ClaimsSelector.test.js +46 -0
- package/lib/commonjs/components/claimsSelector/__test__/ClaimsSelector.test.js.map +1 -0
- package/lib/commonjs/components/claimsSelector/__test__/__snapshots__/ClaimsSelector.test.tsx.snap +1270 -0
- package/lib/commonjs/components/claimsSelector/index.js +17 -0
- package/lib/commonjs/components/claimsSelector/index.js.map +1 -0
- package/lib/commonjs/components/index.js +11 -0
- package/lib/commonjs/components/index.js.map +1 -1
- package/lib/commonjs/components/listitems/ListItemInfo.js +6 -2
- package/lib/commonjs/components/listitems/ListItemInfo.js.map +1 -1
- package/lib/commonjs/components/listitems/__test__/__snapshots__/listitem.test.tsx.snap +10 -0
- package/lib/commonjs/components/textInput/TextInputValidation.js +19 -7
- package/lib/commonjs/components/textInput/TextInputValidation.js.map +1 -1
- package/lib/commonjs/components/typography/markdown/MdH1.js +1 -2
- package/lib/commonjs/components/typography/markdown/MdH1.js.map +1 -1
- package/lib/commonjs/components/typography/markdown/MdH2.js +2 -2
- package/lib/commonjs/components/typography/markdown/MdH2.js.map +1 -1
- package/lib/commonjs/components/typography/markdown/MdH3.js +2 -2
- package/lib/commonjs/components/typography/markdown/MdH3.js.map +1 -1
- package/lib/commonjs/core/IOColors.js +1 -1
- package/lib/commonjs/hooks/useAccordionAnimation.js +83 -0
- package/lib/commonjs/hooks/useAccordionAnimation.js.map +1 -0
- package/lib/commonjs/index.js +11 -0
- package/lib/commonjs/index.js.map +1 -1
- package/lib/module/components/accordion/AccordionItem.js +19 -52
- package/lib/module/components/accordion/AccordionItem.js.map +1 -1
- package/lib/module/components/claimsSelector/ClaimsSelector.js +109 -0
- package/lib/module/components/claimsSelector/ClaimsSelector.js.map +1 -0
- package/lib/module/components/claimsSelector/__test__/ClaimsSelector.test.js +41 -0
- package/lib/module/components/claimsSelector/__test__/ClaimsSelector.test.js.map +1 -0
- package/lib/module/components/claimsSelector/__test__/__snapshots__/ClaimsSelector.test.tsx.snap +1270 -0
- package/lib/module/components/claimsSelector/index.js +2 -0
- package/lib/module/components/claimsSelector/index.js.map +1 -0
- package/lib/module/components/index.js +1 -0
- package/lib/module/components/index.js.map +1 -1
- package/lib/module/components/listitems/ListItemInfo.js +6 -2
- package/lib/module/components/listitems/ListItemInfo.js.map +1 -1
- package/lib/module/components/listitems/__test__/__snapshots__/listitem.test.tsx.snap +10 -0
- package/lib/module/components/textInput/TextInputValidation.js +20 -8
- package/lib/module/components/textInput/TextInputValidation.js.map +1 -1
- package/lib/module/components/typography/markdown/MdH1.js +1 -2
- package/lib/module/components/typography/markdown/MdH1.js.map +1 -1
- package/lib/module/components/typography/markdown/MdH2.js +2 -2
- package/lib/module/components/typography/markdown/MdH2.js.map +1 -1
- package/lib/module/components/typography/markdown/MdH3.js +2 -2
- package/lib/module/components/typography/markdown/MdH3.js.map +1 -1
- package/lib/module/core/IOColors.js +1 -1
- package/lib/module/hooks/useAccordionAnimation.js +76 -0
- package/lib/module/hooks/useAccordionAnimation.js.map +1 -0
- package/lib/module/index.js +1 -0
- package/lib/module/index.js.map +1 -1
- package/lib/typescript/components/accordion/AccordionItem.d.ts +0 -6
- package/lib/typescript/components/accordion/AccordionItem.d.ts.map +1 -1
- package/lib/typescript/components/claimsSelector/ClaimsSelector.d.ts +42 -0
- package/lib/typescript/components/claimsSelector/ClaimsSelector.d.ts.map +1 -0
- package/lib/typescript/components/claimsSelector/__test__/ClaimsSelector.test.d.ts +2 -0
- package/lib/typescript/components/claimsSelector/__test__/ClaimsSelector.test.d.ts.map +1 -0
- package/lib/typescript/components/claimsSelector/index.d.ts +2 -0
- package/lib/typescript/components/claimsSelector/index.d.ts.map +1 -0
- package/lib/typescript/components/index.d.ts +1 -0
- package/lib/typescript/components/index.d.ts.map +1 -1
- package/lib/typescript/components/listitems/ListItemInfo.d.ts +2 -1
- package/lib/typescript/components/listitems/ListItemInfo.d.ts.map +1 -1
- package/lib/typescript/components/textInput/TextInputValidation.d.ts +31 -4
- package/lib/typescript/components/textInput/TextInputValidation.d.ts.map +1 -1
- package/lib/typescript/components/typography/markdown/MdH1.d.ts.map +1 -1
- package/lib/typescript/hooks/useAccordionAnimation.d.ts +41 -0
- package/lib/typescript/hooks/useAccordionAnimation.d.ts.map +1 -0
- package/lib/typescript/index.d.ts +1 -0
- package/lib/typescript/index.d.ts.map +1 -1
- package/package.json +1 -1
- package/src/components/accordion/AccordionItem.tsx +21 -82
- package/src/components/claimsSelector/ClaimsSelector.tsx +185 -0
- package/src/components/claimsSelector/__test__/ClaimsSelector.test.tsx +55 -0
- package/src/components/claimsSelector/__test__/__snapshots__/ClaimsSelector.test.tsx.snap +1270 -0
- package/src/components/claimsSelector/index.tsx +1 -0
- package/src/components/index.tsx +1 -0
- package/src/components/listitems/ListItemInfo.tsx +7 -2
- package/src/components/listitems/__test__/__snapshots__/listitem.test.tsx.snap +10 -0
- package/src/components/textInput/TextInputValidation.tsx +140 -97
- package/src/components/typography/markdown/MdH1.tsx +1 -2
- package/src/components/typography/markdown/MdH2.tsx +2 -2
- package/src/components/typography/markdown/MdH3.tsx +2 -2
- package/src/core/IOColors.ts +1 -1
- package/src/hooks/useAccordionAnimation.tsx +106 -0
- package/src/index.tsx +1 -0
|
@@ -0,0 +1,41 @@
|
|
|
1
|
+
import { type LayoutChangeEvent } from "react-native";
|
|
2
|
+
type Params = {
|
|
3
|
+
defaultExpanded?: boolean;
|
|
4
|
+
};
|
|
5
|
+
export declare const useAccordionAnimation: ({ defaultExpanded }?: Params) => {
|
|
6
|
+
expanded: boolean;
|
|
7
|
+
/**
|
|
8
|
+
* Toggle the accordion expanded/collapsed state.
|
|
9
|
+
*/
|
|
10
|
+
toggleAccordion: () => void;
|
|
11
|
+
/**
|
|
12
|
+
* The style to apply to the accordion icon.
|
|
13
|
+
*/
|
|
14
|
+
iconAnimatedStyle: {
|
|
15
|
+
transform: {
|
|
16
|
+
rotate: "0deg" | "180deg";
|
|
17
|
+
}[];
|
|
18
|
+
};
|
|
19
|
+
/**
|
|
20
|
+
* Callback to execute on the body's inner container layout.
|
|
21
|
+
*/
|
|
22
|
+
onBodyLayout: (event: LayoutChangeEvent) => void;
|
|
23
|
+
/**
|
|
24
|
+
* The animated style to apply to the collapsible body container – it must be an `Animated.View`.
|
|
25
|
+
*/
|
|
26
|
+
bodyAnimatedStyle: ({
|
|
27
|
+
overflow: "hidden";
|
|
28
|
+
} | {
|
|
29
|
+
height: number;
|
|
30
|
+
})[];
|
|
31
|
+
/**
|
|
32
|
+
* The style to apply to the inner body container.
|
|
33
|
+
*/
|
|
34
|
+
bodyInnerStyle: {
|
|
35
|
+
position: "absolute";
|
|
36
|
+
padding: 16;
|
|
37
|
+
paddingTop: number;
|
|
38
|
+
};
|
|
39
|
+
};
|
|
40
|
+
export {};
|
|
41
|
+
//# sourceMappingURL=useAccordionAnimation.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"useAccordionAnimation.d.ts","sourceRoot":"","sources":["../../../src/hooks/useAccordionAnimation.tsx"],"names":[],"mappings":"AACA,OAAO,EAAc,KAAK,iBAAiB,EAAE,MAAM,cAAc,CAAC;AAUlE,KAAK,MAAM,GAAG;IACZ,eAAe,CAAC,EAAE,OAAO,CAAC;CAC3B,CAAC;AAEF,eAAO,MAAM,qBAAqB,yBAE/B,MAAM;;IAwDL;;OAEG;;IAEH;;OAEG;;;;;;IAEH;;OAEG;;IAEH;;OAEG;;;;;;IAEH;;OAEG;;;;;;CAGN,CAAC"}
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,eAAe,CAAC"}
|
|
1
|
+
{"version":3,"file":"index.d.ts","sourceRoot":"","sources":["../../src/index.tsx"],"names":[],"mappings":"AAAA,cAAc,cAAc,CAAC;AAC7B,cAAc,QAAQ,CAAC;AACvB,cAAc,aAAa,CAAC;AAC5B,cAAc,SAAS,CAAC;AACxB,cAAc,eAAe,CAAC;AAC9B,cAAc,uBAAuB,CAAC;AACtC,cAAc,eAAe,CAAC"}
|
package/package.json
CHANGED
|
@@ -1,23 +1,15 @@
|
|
|
1
|
-
import React
|
|
2
|
-
import {
|
|
3
|
-
LayoutChangeEvent,
|
|
4
|
-
StyleSheet,
|
|
5
|
-
TouchableWithoutFeedback,
|
|
6
|
-
View
|
|
7
|
-
} from "react-native";
|
|
1
|
+
import React from "react";
|
|
2
|
+
import { StyleSheet, TouchableWithoutFeedback, View } from "react-native";
|
|
8
3
|
import LinearGradient from "react-native-linear-gradient";
|
|
9
|
-
import Animated
|
|
10
|
-
useAnimatedStyle,
|
|
11
|
-
withSpring
|
|
12
|
-
} from "react-native-reanimated";
|
|
4
|
+
import Animated from "react-native-reanimated";
|
|
13
5
|
import {
|
|
14
6
|
IOAccordionRadius,
|
|
15
7
|
IOStyles,
|
|
16
8
|
useIOTheme,
|
|
17
9
|
type IOSpacingScale
|
|
18
10
|
} from "../../core";
|
|
19
|
-
import { IOSpringValues } from "../../core/IOAnimations";
|
|
20
11
|
import { IOColors, hexToRgba } from "../../core/IOColors";
|
|
12
|
+
import { useAccordionAnimation } from "../../hooks/useAccordionAnimation";
|
|
21
13
|
import { IOIconSizeScale, IOIcons, Icon } from "../icons/Icon";
|
|
22
14
|
import { Body, H6 } from "../typography";
|
|
23
15
|
|
|
@@ -28,11 +20,6 @@ export type AccordionItem = {
|
|
|
28
20
|
icon?: IOIcons;
|
|
29
21
|
};
|
|
30
22
|
|
|
31
|
-
type AccordionBody = {
|
|
32
|
-
children: React.ReactNode;
|
|
33
|
-
expanded: boolean;
|
|
34
|
-
};
|
|
35
|
-
|
|
36
23
|
const accordionBodySpacing: IOSpacingScale = 16;
|
|
37
24
|
const accordionIconMargin: IOSpacingScale = 12;
|
|
38
25
|
const accordionChevronMargin: IOSpacingScale = 8;
|
|
@@ -40,40 +27,6 @@ const accordionChevronMargin: IOSpacingScale = 8;
|
|
|
40
27
|
// Icon size
|
|
41
28
|
const iconSize: IOIconSizeScale = 24;
|
|
42
29
|
|
|
43
|
-
/* The code below is a re-adaptation of Dima Portenko's code:
|
|
44
|
-
https://github.com/dimaportenko/reanimated-collapsable-card-tutorial
|
|
45
|
-
*/
|
|
46
|
-
export const AccordionBody = ({ children, expanded }: AccordionBody) => {
|
|
47
|
-
const [height, setHeight] = useState(0);
|
|
48
|
-
|
|
49
|
-
const onLayout = (event: LayoutChangeEvent) => {
|
|
50
|
-
const { height: onLayoutHeight } = event.nativeEvent.layout;
|
|
51
|
-
|
|
52
|
-
if (onLayoutHeight > 0 && height !== onLayoutHeight) {
|
|
53
|
-
setHeight(onLayoutHeight);
|
|
54
|
-
}
|
|
55
|
-
};
|
|
56
|
-
|
|
57
|
-
const animatedHeightStyle = useAnimatedStyle(
|
|
58
|
-
() => ({
|
|
59
|
-
height: expanded
|
|
60
|
-
? withSpring(height, IOSpringValues.accordion)
|
|
61
|
-
: withSpring(0, IOSpringValues.accordion)
|
|
62
|
-
}),
|
|
63
|
-
[expanded]
|
|
64
|
-
);
|
|
65
|
-
|
|
66
|
-
return (
|
|
67
|
-
<Animated.View
|
|
68
|
-
style={[animatedHeightStyle, styles.accordionCollapsableContainer]}
|
|
69
|
-
>
|
|
70
|
-
<View style={styles.accordionBodyContainer} onLayout={onLayout}>
|
|
71
|
-
{children}
|
|
72
|
-
</View>
|
|
73
|
-
</Animated.View>
|
|
74
|
-
);
|
|
75
|
-
};
|
|
76
|
-
|
|
77
30
|
export const AccordionItem = ({
|
|
78
31
|
title,
|
|
79
32
|
accessibilityLabel,
|
|
@@ -81,30 +34,21 @@ export const AccordionItem = ({
|
|
|
81
34
|
icon
|
|
82
35
|
}: AccordionItem) => {
|
|
83
36
|
const theme = useIOTheme();
|
|
84
|
-
|
|
37
|
+
|
|
38
|
+
const {
|
|
39
|
+
expanded,
|
|
40
|
+
toggleAccordion,
|
|
41
|
+
onBodyLayout,
|
|
42
|
+
iconAnimatedStyle,
|
|
43
|
+
bodyAnimatedStyle,
|
|
44
|
+
bodyInnerStyle
|
|
45
|
+
} = useAccordionAnimation();
|
|
85
46
|
|
|
86
47
|
// Visual attributes
|
|
87
48
|
const accordionBackground: IOColors = theme["appBackground-primary"];
|
|
88
49
|
const accordionBorder: IOColors = theme["cardBorder-default"];
|
|
89
50
|
const accordionIconColor: IOColors = theme["icon-decorative"];
|
|
90
51
|
|
|
91
|
-
const onItemPress = () => {
|
|
92
|
-
setExpanded(!expanded);
|
|
93
|
-
};
|
|
94
|
-
|
|
95
|
-
const animatedChevron = useAnimatedStyle(
|
|
96
|
-
() => ({
|
|
97
|
-
transform: [
|
|
98
|
-
{
|
|
99
|
-
rotate: expanded
|
|
100
|
-
? withSpring(`180deg`, IOSpringValues.accordion)
|
|
101
|
-
: withSpring(`0deg`, IOSpringValues.accordion)
|
|
102
|
-
}
|
|
103
|
-
]
|
|
104
|
-
}),
|
|
105
|
-
[expanded]
|
|
106
|
-
);
|
|
107
|
-
|
|
108
52
|
return (
|
|
109
53
|
<View
|
|
110
54
|
style={[
|
|
@@ -120,7 +64,7 @@ export const AccordionItem = ({
|
|
|
120
64
|
accessibilityRole="button"
|
|
121
65
|
accessibilityState={{ expanded }}
|
|
122
66
|
accessibilityLabel={accessibilityLabel ?? title}
|
|
123
|
-
onPress={
|
|
67
|
+
onPress={toggleAccordion}
|
|
124
68
|
>
|
|
125
69
|
<View style={styles.textContainer}>
|
|
126
70
|
<View
|
|
@@ -146,7 +90,7 @@ export const AccordionItem = ({
|
|
|
146
90
|
<H6 color={theme["textBody-default"]}>{title}</H6>
|
|
147
91
|
</View>
|
|
148
92
|
</View>
|
|
149
|
-
<Animated.View style={
|
|
93
|
+
<Animated.View style={iconAnimatedStyle}>
|
|
150
94
|
<Icon
|
|
151
95
|
name="chevronBottom"
|
|
152
96
|
color={theme["interactiveElem-default"]}
|
|
@@ -155,9 +99,12 @@ export const AccordionItem = ({
|
|
|
155
99
|
</View>
|
|
156
100
|
</TouchableWithoutFeedback>
|
|
157
101
|
|
|
158
|
-
<
|
|
159
|
-
{
|
|
160
|
-
|
|
102
|
+
<Animated.View style={bodyAnimatedStyle}>
|
|
103
|
+
<View style={bodyInnerStyle} onLayout={onBodyLayout}>
|
|
104
|
+
{typeof body === "string" ? <Body>{body}</Body> : body}
|
|
105
|
+
</View>
|
|
106
|
+
</Animated.View>
|
|
107
|
+
|
|
161
108
|
{/* This gradient adds a smooth end to the content. If it is missing,
|
|
162
109
|
the content will be cut sharply during the height transition. */}
|
|
163
110
|
<LinearGradient
|
|
@@ -185,14 +132,6 @@ const styles = StyleSheet.create({
|
|
|
185
132
|
borderRadius: IOAccordionRadius,
|
|
186
133
|
borderCurve: "continuous"
|
|
187
134
|
},
|
|
188
|
-
accordionCollapsableContainer: {
|
|
189
|
-
overflow: "hidden"
|
|
190
|
-
},
|
|
191
|
-
accordionBodyContainer: {
|
|
192
|
-
position: "absolute",
|
|
193
|
-
padding: accordionBodySpacing,
|
|
194
|
-
paddingTop: 0
|
|
195
|
-
},
|
|
196
135
|
textContainer: {
|
|
197
136
|
padding: accordionBodySpacing,
|
|
198
137
|
flexDirection: "row",
|
|
@@ -0,0 +1,185 @@
|
|
|
1
|
+
import React, { Fragment } from "react";
|
|
2
|
+
import { StyleSheet, View } from "react-native";
|
|
3
|
+
import Animated from "react-native-reanimated";
|
|
4
|
+
import { TouchableWithoutFeedback } from "react-native-gesture-handler";
|
|
5
|
+
import LinearGradient from "react-native-linear-gradient";
|
|
6
|
+
import {
|
|
7
|
+
hexToRgba,
|
|
8
|
+
IOAccordionRadius,
|
|
9
|
+
IOColors,
|
|
10
|
+
IOSpacingScale,
|
|
11
|
+
useIOTheme
|
|
12
|
+
} from "../../core";
|
|
13
|
+
import { useAccordionAnimation } from "../../hooks/useAccordionAnimation";
|
|
14
|
+
import { Divider } from "../divider";
|
|
15
|
+
import { H6 } from "../typography";
|
|
16
|
+
import { Icon } from "../icons";
|
|
17
|
+
import { ListItemCheckbox, ListItemInfo } from "../listitems";
|
|
18
|
+
|
|
19
|
+
const accordionBodySpacing: IOSpacingScale = 16;
|
|
20
|
+
|
|
21
|
+
type Props = {
|
|
22
|
+
/**
|
|
23
|
+
* The accordion title.
|
|
24
|
+
*/
|
|
25
|
+
title: string;
|
|
26
|
+
/**
|
|
27
|
+
* The list of items to display within the accordion.
|
|
28
|
+
*/
|
|
29
|
+
items: Array<Item>;
|
|
30
|
+
/**
|
|
31
|
+
* Enable the selection of items with a checkbox.
|
|
32
|
+
* @default true
|
|
33
|
+
*/
|
|
34
|
+
selectionEnabled?: boolean;
|
|
35
|
+
/**
|
|
36
|
+
* The IDs of the selected items, when the component is controlled.
|
|
37
|
+
*/
|
|
38
|
+
selectedItemIds?: Array<string>;
|
|
39
|
+
/**
|
|
40
|
+
* Whether the accordion starts expanded.
|
|
41
|
+
* @default false
|
|
42
|
+
*/
|
|
43
|
+
defaultExpanded?: boolean;
|
|
44
|
+
/**
|
|
45
|
+
* Function called when a item is selected.
|
|
46
|
+
*/
|
|
47
|
+
onItemSelected?: (item: Item, selected: boolean) => void;
|
|
48
|
+
/**
|
|
49
|
+
* Function called when the accordion is toggled to collapsed or expanded state.
|
|
50
|
+
*/
|
|
51
|
+
onToggle?: (expanded: boolean) => void;
|
|
52
|
+
accessibilityLabel?: string;
|
|
53
|
+
};
|
|
54
|
+
|
|
55
|
+
type Item = {
|
|
56
|
+
id: string;
|
|
57
|
+
title: string;
|
|
58
|
+
description: string;
|
|
59
|
+
};
|
|
60
|
+
|
|
61
|
+
export const ClaimsSelector = ({
|
|
62
|
+
title,
|
|
63
|
+
items,
|
|
64
|
+
defaultExpanded,
|
|
65
|
+
onItemSelected,
|
|
66
|
+
onToggle,
|
|
67
|
+
accessibilityLabel,
|
|
68
|
+
selectedItemIds,
|
|
69
|
+
selectionEnabled = true
|
|
70
|
+
}: Props) => {
|
|
71
|
+
const theme = useIOTheme();
|
|
72
|
+
const {
|
|
73
|
+
expanded,
|
|
74
|
+
toggleAccordion,
|
|
75
|
+
onBodyLayout,
|
|
76
|
+
iconAnimatedStyle,
|
|
77
|
+
bodyAnimatedStyle,
|
|
78
|
+
bodyInnerStyle
|
|
79
|
+
} = useAccordionAnimation({
|
|
80
|
+
defaultExpanded
|
|
81
|
+
});
|
|
82
|
+
|
|
83
|
+
const accordionBackground: IOColors = theme["appBackground-secondary"];
|
|
84
|
+
const accordionBorder: IOColors = theme["cardBorder-default"];
|
|
85
|
+
|
|
86
|
+
const onItemPress = () => {
|
|
87
|
+
toggleAccordion();
|
|
88
|
+
onToggle?.(!expanded);
|
|
89
|
+
};
|
|
90
|
+
|
|
91
|
+
const body = items.map((item, index) => (
|
|
92
|
+
<Fragment key={item.id}>
|
|
93
|
+
{index !== 0 && <Divider />}
|
|
94
|
+
{selectionEnabled ? (
|
|
95
|
+
<ListItemCheckbox
|
|
96
|
+
value={item.title}
|
|
97
|
+
description={item.description}
|
|
98
|
+
selected={selectedItemIds?.includes(item.id)}
|
|
99
|
+
onValueChange={
|
|
100
|
+
onItemSelected
|
|
101
|
+
? selected => onItemSelected(item, selected)
|
|
102
|
+
: undefined
|
|
103
|
+
}
|
|
104
|
+
/>
|
|
105
|
+
) : (
|
|
106
|
+
<ListItemInfo reversed value={item.title} label={item.description} />
|
|
107
|
+
)}
|
|
108
|
+
</Fragment>
|
|
109
|
+
));
|
|
110
|
+
|
|
111
|
+
return (
|
|
112
|
+
<View
|
|
113
|
+
style={[
|
|
114
|
+
styles.accordionWrapper,
|
|
115
|
+
{
|
|
116
|
+
backgroundColor: IOColors[accordionBackground],
|
|
117
|
+
borderColor: IOColors[accordionBorder]
|
|
118
|
+
}
|
|
119
|
+
]}
|
|
120
|
+
>
|
|
121
|
+
<TouchableWithoutFeedback
|
|
122
|
+
accessible={true}
|
|
123
|
+
accessibilityRole="button"
|
|
124
|
+
accessibilityState={{ expanded }}
|
|
125
|
+
accessibilityLabel={accessibilityLabel ?? title}
|
|
126
|
+
onPress={onItemPress}
|
|
127
|
+
>
|
|
128
|
+
<View style={styles.textContainer}>
|
|
129
|
+
<H6 color={theme["textBody-default"]}>{title}</H6>
|
|
130
|
+
<Animated.View style={iconAnimatedStyle}>
|
|
131
|
+
<Icon
|
|
132
|
+
name="chevronBottom"
|
|
133
|
+
color={theme["interactiveElem-default"]}
|
|
134
|
+
/>
|
|
135
|
+
</Animated.View>
|
|
136
|
+
</View>
|
|
137
|
+
</TouchableWithoutFeedback>
|
|
138
|
+
|
|
139
|
+
<Animated.View style={bodyAnimatedStyle}>
|
|
140
|
+
<View
|
|
141
|
+
style={[bodyInnerStyle, styles.bodyInnerContainer]}
|
|
142
|
+
onLayout={onBodyLayout}
|
|
143
|
+
>
|
|
144
|
+
{body}
|
|
145
|
+
</View>
|
|
146
|
+
</Animated.View>
|
|
147
|
+
|
|
148
|
+
{/* This gradient adds a smooth end to the content. If it is missing,
|
|
149
|
+
the content will be cut sharply during the height transition. */}
|
|
150
|
+
<LinearGradient
|
|
151
|
+
style={styles.linearGradient}
|
|
152
|
+
colors={[
|
|
153
|
+
hexToRgba(IOColors[accordionBackground], 0),
|
|
154
|
+
IOColors[accordionBackground]
|
|
155
|
+
]}
|
|
156
|
+
/>
|
|
157
|
+
</View>
|
|
158
|
+
);
|
|
159
|
+
};
|
|
160
|
+
|
|
161
|
+
const styles = StyleSheet.create({
|
|
162
|
+
accordionWrapper: {
|
|
163
|
+
borderWidth: 1,
|
|
164
|
+
borderRadius: IOAccordionRadius,
|
|
165
|
+
borderCurve: "continuous"
|
|
166
|
+
},
|
|
167
|
+
textContainer: {
|
|
168
|
+
padding: accordionBodySpacing,
|
|
169
|
+
flexDirection: "row",
|
|
170
|
+
alignItems: "center",
|
|
171
|
+
justifyContent: "space-between"
|
|
172
|
+
},
|
|
173
|
+
bodyInnerContainer: {
|
|
174
|
+
width: "100%"
|
|
175
|
+
},
|
|
176
|
+
linearGradient: {
|
|
177
|
+
height: accordionBodySpacing,
|
|
178
|
+
position: "absolute",
|
|
179
|
+
// Place at the bottom
|
|
180
|
+
bottom: 0,
|
|
181
|
+
// Avoid gradient overlaps with border radius
|
|
182
|
+
left: accordionBodySpacing,
|
|
183
|
+
right: accordionBodySpacing
|
|
184
|
+
}
|
|
185
|
+
});
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
import React from "react";
|
|
2
|
+
import * as TestRenderer from "react-test-renderer";
|
|
3
|
+
import { ClaimsSelector } from "../ClaimsSelector";
|
|
4
|
+
|
|
5
|
+
describe("ClaimsSelector", () => {
|
|
6
|
+
it("ClaimsSelector Snapshot (controlled)", () => {
|
|
7
|
+
const claimsSelector = TestRenderer.create(
|
|
8
|
+
<ClaimsSelector
|
|
9
|
+
title="Patente di guida"
|
|
10
|
+
selectedItemIds={["name"]}
|
|
11
|
+
items={[
|
|
12
|
+
{
|
|
13
|
+
id: "name",
|
|
14
|
+
title: "Mario Rossi",
|
|
15
|
+
description: "Nome e cognome"
|
|
16
|
+
}
|
|
17
|
+
]}
|
|
18
|
+
/>
|
|
19
|
+
);
|
|
20
|
+
expect(claimsSelector).toMatchSnapshot();
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it("ClaimsSelector Snapshot (uncontrolled)", () => {
|
|
24
|
+
const claimsSelector = TestRenderer.create(
|
|
25
|
+
<ClaimsSelector
|
|
26
|
+
title="Patente di guida"
|
|
27
|
+
items={[
|
|
28
|
+
{
|
|
29
|
+
id: "name",
|
|
30
|
+
title: "Mario Rossi",
|
|
31
|
+
description: "Nome e cognome"
|
|
32
|
+
}
|
|
33
|
+
]}
|
|
34
|
+
/>
|
|
35
|
+
);
|
|
36
|
+
expect(claimsSelector).toMatchSnapshot();
|
|
37
|
+
});
|
|
38
|
+
|
|
39
|
+
it("ClaimsSelector Snapshot (unselectable items)", () => {
|
|
40
|
+
const claimsSelector = TestRenderer.create(
|
|
41
|
+
<ClaimsSelector
|
|
42
|
+
title="Patente di guida"
|
|
43
|
+
selectionEnabled={false}
|
|
44
|
+
items={[
|
|
45
|
+
{
|
|
46
|
+
id: "name",
|
|
47
|
+
title: "Mario Rossi",
|
|
48
|
+
description: "Nome e cognome"
|
|
49
|
+
}
|
|
50
|
+
]}
|
|
51
|
+
/>
|
|
52
|
+
);
|
|
53
|
+
expect(claimsSelector).toMatchSnapshot();
|
|
54
|
+
});
|
|
55
|
+
});
|