@pagopa/io-app-design-system 5.0.0-7 → 5.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 (181) hide show
  1. package/lib/commonjs/components/accordion/AccordionItem.js +20 -56
  2. package/lib/commonjs/components/accordion/AccordionItem.js.map +1 -1
  3. package/lib/commonjs/components/buttons/ButtonLink.js +1 -1
  4. package/lib/commonjs/components/buttons/ButtonSolid.js +1 -1
  5. package/lib/commonjs/components/buttons/ButtonSolid.js.map +1 -1
  6. package/lib/commonjs/components/checkbox/AnimatedCheckbox.js +6 -4
  7. package/lib/commonjs/components/checkbox/AnimatedCheckbox.js.map +1 -1
  8. package/lib/commonjs/components/checkbox/AnimatedMessageCheckbox.js +4 -2
  9. package/lib/commonjs/components/checkbox/AnimatedMessageCheckbox.js.map +1 -1
  10. package/lib/commonjs/components/claimsSelector/ClaimsSelector.js +119 -0
  11. package/lib/commonjs/components/claimsSelector/ClaimsSelector.js.map +1 -0
  12. package/lib/commonjs/components/claimsSelector/__test__/ClaimsSelector.test.js +46 -0
  13. package/lib/commonjs/components/claimsSelector/__test__/ClaimsSelector.test.js.map +1 -0
  14. package/lib/commonjs/components/claimsSelector/__test__/__snapshots__/ClaimsSelector.test.tsx.snap +1270 -0
  15. package/lib/commonjs/components/claimsSelector/index.js +17 -0
  16. package/lib/commonjs/components/claimsSelector/index.js.map +1 -0
  17. package/lib/commonjs/components/index.js +11 -0
  18. package/lib/commonjs/components/index.js.map +1 -1
  19. package/lib/commonjs/components/listitems/ListItemCheckbox.js +1 -1
  20. package/lib/commonjs/components/listitems/ListItemCheckbox.js.map +1 -1
  21. package/lib/commonjs/components/listitems/ListItemInfo.js +6 -2
  22. package/lib/commonjs/components/listitems/ListItemInfo.js.map +1 -1
  23. package/lib/commonjs/components/listitems/ListItemRadio.js +1 -1
  24. package/lib/commonjs/components/listitems/ListItemRadio.js.map +1 -1
  25. package/lib/commonjs/components/listitems/ListItemSwitch.js +1 -1
  26. package/lib/commonjs/components/listitems/ListItemSwitch.js.map +1 -1
  27. package/lib/commonjs/components/listitems/__test__/__snapshots__/listitem.test.tsx.snap +10 -0
  28. package/lib/commonjs/components/radio/AnimatedRadio.js +5 -3
  29. package/lib/commonjs/components/radio/AnimatedRadio.js.map +1 -1
  30. package/lib/commonjs/components/switch/NativeSwitch.js +6 -5
  31. package/lib/commonjs/components/switch/NativeSwitch.js.map +1 -1
  32. package/lib/commonjs/components/switch/index.js +0 -22
  33. package/lib/commonjs/components/switch/index.js.map +1 -1
  34. package/lib/commonjs/components/textInput/TextInputValidation.js +19 -7
  35. package/lib/commonjs/components/textInput/TextInputValidation.js.map +1 -1
  36. package/lib/commonjs/components/typography/markdown/MdH1.js +1 -2
  37. package/lib/commonjs/components/typography/markdown/MdH1.js.map +1 -1
  38. package/lib/commonjs/components/typography/markdown/MdH2.js +2 -2
  39. package/lib/commonjs/components/typography/markdown/MdH2.js.map +1 -1
  40. package/lib/commonjs/components/typography/markdown/MdH3.js +2 -2
  41. package/lib/commonjs/components/typography/markdown/MdH3.js.map +1 -1
  42. package/lib/commonjs/core/IOColors.js +26 -5
  43. package/lib/commonjs/core/IOColors.js.map +1 -1
  44. package/lib/commonjs/core/IOStyles.js +2 -16
  45. package/lib/commonjs/core/IOStyles.js.map +1 -1
  46. package/lib/commonjs/hooks/useAccordionAnimation.js +83 -0
  47. package/lib/commonjs/hooks/useAccordionAnimation.js.map +1 -0
  48. package/lib/commonjs/index.js +11 -0
  49. package/lib/commonjs/index.js.map +1 -1
  50. package/lib/module/components/accordion/AccordionItem.js +19 -52
  51. package/lib/module/components/accordion/AccordionItem.js.map +1 -1
  52. package/lib/module/components/buttons/ButtonLink.js +1 -1
  53. package/lib/module/components/buttons/ButtonSolid.js +1 -1
  54. package/lib/module/components/buttons/ButtonSolid.js.map +1 -1
  55. package/lib/module/components/checkbox/AnimatedCheckbox.js +6 -4
  56. package/lib/module/components/checkbox/AnimatedCheckbox.js.map +1 -1
  57. package/lib/module/components/checkbox/AnimatedMessageCheckbox.js +5 -3
  58. package/lib/module/components/checkbox/AnimatedMessageCheckbox.js.map +1 -1
  59. package/lib/module/components/claimsSelector/ClaimsSelector.js +109 -0
  60. package/lib/module/components/claimsSelector/ClaimsSelector.js.map +1 -0
  61. package/lib/module/components/claimsSelector/__test__/ClaimsSelector.test.js +41 -0
  62. package/lib/module/components/claimsSelector/__test__/ClaimsSelector.test.js.map +1 -0
  63. package/lib/module/components/claimsSelector/__test__/__snapshots__/ClaimsSelector.test.tsx.snap +1270 -0
  64. package/lib/module/components/claimsSelector/index.js +2 -0
  65. package/lib/module/components/claimsSelector/index.js.map +1 -0
  66. package/lib/module/components/index.js +1 -0
  67. package/lib/module/components/index.js.map +1 -1
  68. package/lib/module/components/listitems/ListItemCheckbox.js +1 -1
  69. package/lib/module/components/listitems/ListItemCheckbox.js.map +1 -1
  70. package/lib/module/components/listitems/ListItemInfo.js +6 -2
  71. package/lib/module/components/listitems/ListItemInfo.js.map +1 -1
  72. package/lib/module/components/listitems/ListItemRadio.js +1 -1
  73. package/lib/module/components/listitems/ListItemRadio.js.map +1 -1
  74. package/lib/module/components/listitems/ListItemSwitch.js +1 -1
  75. package/lib/module/components/listitems/ListItemSwitch.js.map +1 -1
  76. package/lib/module/components/listitems/__test__/__snapshots__/listitem.test.tsx.snap +10 -0
  77. package/lib/module/components/radio/AnimatedRadio.js +5 -3
  78. package/lib/module/components/radio/AnimatedRadio.js.map +1 -1
  79. package/lib/module/components/switch/NativeSwitch.js +6 -5
  80. package/lib/module/components/switch/NativeSwitch.js.map +1 -1
  81. package/lib/module/components/switch/index.js +0 -2
  82. package/lib/module/components/switch/index.js.map +1 -1
  83. package/lib/module/components/textInput/TextInputValidation.js +20 -8
  84. package/lib/module/components/textInput/TextInputValidation.js.map +1 -1
  85. package/lib/module/components/typography/markdown/MdH1.js +1 -2
  86. package/lib/module/components/typography/markdown/MdH1.js.map +1 -1
  87. package/lib/module/components/typography/markdown/MdH2.js +2 -2
  88. package/lib/module/components/typography/markdown/MdH2.js.map +1 -1
  89. package/lib/module/components/typography/markdown/MdH3.js +2 -2
  90. package/lib/module/components/typography/markdown/MdH3.js.map +1 -1
  91. package/lib/module/core/IOColors.js +26 -5
  92. package/lib/module/core/IOColors.js.map +1 -1
  93. package/lib/module/core/IOStyles.js +1 -14
  94. package/lib/module/core/IOStyles.js.map +1 -1
  95. package/lib/module/hooks/useAccordionAnimation.js +76 -0
  96. package/lib/module/hooks/useAccordionAnimation.js.map +1 -0
  97. package/lib/module/index.js +1 -0
  98. package/lib/module/index.js.map +1 -1
  99. package/lib/typescript/components/accordion/AccordionItem.d.ts +0 -6
  100. package/lib/typescript/components/accordion/AccordionItem.d.ts.map +1 -1
  101. package/lib/typescript/components/checkbox/AnimatedCheckbox.d.ts.map +1 -1
  102. package/lib/typescript/components/checkbox/AnimatedMessageCheckbox.d.ts.map +1 -1
  103. package/lib/typescript/components/claimsSelector/ClaimsSelector.d.ts +42 -0
  104. package/lib/typescript/components/claimsSelector/ClaimsSelector.d.ts.map +1 -0
  105. package/lib/typescript/components/claimsSelector/__test__/ClaimsSelector.test.d.ts +2 -0
  106. package/lib/typescript/components/claimsSelector/__test__/ClaimsSelector.test.d.ts.map +1 -0
  107. package/lib/typescript/components/claimsSelector/index.d.ts +2 -0
  108. package/lib/typescript/components/claimsSelector/index.d.ts.map +1 -0
  109. package/lib/typescript/components/index.d.ts +1 -0
  110. package/lib/typescript/components/index.d.ts.map +1 -1
  111. package/lib/typescript/components/listitems/ListItemInfo.d.ts +2 -1
  112. package/lib/typescript/components/listitems/ListItemInfo.d.ts.map +1 -1
  113. package/lib/typescript/components/radio/AnimatedRadio.d.ts.map +1 -1
  114. package/lib/typescript/components/switch/NativeSwitch.d.ts.map +1 -1
  115. package/lib/typescript/components/switch/index.d.ts +0 -2
  116. package/lib/typescript/components/switch/index.d.ts.map +1 -1
  117. package/lib/typescript/components/textInput/TextInputValidation.d.ts +31 -4
  118. package/lib/typescript/components/textInput/TextInputValidation.d.ts.map +1 -1
  119. package/lib/typescript/components/typography/BodyMonospace.d.ts +1 -1
  120. package/lib/typescript/components/typography/ButtonText.d.ts +1 -1
  121. package/lib/typescript/components/typography/Caption.d.ts +1 -1
  122. package/lib/typescript/components/typography/H1.d.ts +1 -1
  123. package/lib/typescript/components/typography/H2.d.ts +1 -1
  124. package/lib/typescript/components/typography/H3.d.ts +1 -1
  125. package/lib/typescript/components/typography/H4.d.ts +1 -1
  126. package/lib/typescript/components/typography/H5.d.ts +1 -1
  127. package/lib/typescript/components/typography/H6.d.ts +1 -1
  128. package/lib/typescript/components/typography/Hero.d.ts +1 -1
  129. package/lib/typescript/components/typography/markdown/MdH1.d.ts +1 -1
  130. package/lib/typescript/components/typography/markdown/MdH1.d.ts.map +1 -1
  131. package/lib/typescript/components/typography/markdown/MdH2.d.ts +1 -1
  132. package/lib/typescript/components/typography/markdown/MdH3.d.ts +1 -1
  133. package/lib/typescript/core/IOColors.d.ts +4 -1
  134. package/lib/typescript/core/IOColors.d.ts.map +1 -1
  135. package/lib/typescript/core/IOStyles.d.ts +0 -14
  136. package/lib/typescript/core/IOStyles.d.ts.map +1 -1
  137. package/lib/typescript/hooks/useAccordionAnimation.d.ts +41 -0
  138. package/lib/typescript/hooks/useAccordionAnimation.d.ts.map +1 -0
  139. package/lib/typescript/index.d.ts +1 -0
  140. package/lib/typescript/index.d.ts.map +1 -1
  141. package/package.json +1 -1
  142. package/src/components/accordion/AccordionItem.tsx +21 -82
  143. package/src/components/buttons/ButtonLink.tsx +1 -1
  144. package/src/components/buttons/ButtonSolid.tsx +1 -1
  145. package/src/components/checkbox/AnimatedCheckbox.tsx +6 -4
  146. package/src/components/checkbox/AnimatedMessageCheckbox.tsx +5 -6
  147. package/src/components/claimsSelector/ClaimsSelector.tsx +185 -0
  148. package/src/components/claimsSelector/__test__/ClaimsSelector.test.tsx +55 -0
  149. package/src/components/claimsSelector/__test__/__snapshots__/ClaimsSelector.test.tsx.snap +1270 -0
  150. package/src/components/claimsSelector/index.tsx +1 -0
  151. package/src/components/index.tsx +1 -0
  152. package/src/components/listitems/ListItemCheckbox.tsx +1 -1
  153. package/src/components/listitems/ListItemInfo.tsx +7 -2
  154. package/src/components/listitems/ListItemRadio.tsx +1 -1
  155. package/src/components/listitems/ListItemSwitch.tsx +1 -1
  156. package/src/components/listitems/__test__/__snapshots__/listitem.test.tsx.snap +10 -0
  157. package/src/components/radio/AnimatedRadio.tsx +5 -3
  158. package/src/components/switch/NativeSwitch.tsx +7 -5
  159. package/src/components/switch/index.tsx +0 -2
  160. package/src/components/textInput/TextInputValidation.tsx +140 -97
  161. package/src/components/typography/markdown/MdH1.tsx +1 -2
  162. package/src/components/typography/markdown/MdH2.tsx +2 -2
  163. package/src/components/typography/markdown/MdH3.tsx +2 -2
  164. package/src/core/IOColors.ts +31 -4
  165. package/src/core/IOStyles.ts +1 -28
  166. package/src/hooks/useAccordionAnimation.tsx +106 -0
  167. package/src/index.tsx +1 -0
  168. package/lib/commonjs/components/switch/AnimatedSwitch.js +0 -94
  169. package/lib/commonjs/components/switch/AnimatedSwitch.js.map +0 -1
  170. package/lib/commonjs/components/switch/SwitchLabel.js +0 -76
  171. package/lib/commonjs/components/switch/SwitchLabel.js.map +0 -1
  172. package/lib/module/components/switch/AnimatedSwitch.js +0 -85
  173. package/lib/module/components/switch/AnimatedSwitch.js.map +0 -1
  174. package/lib/module/components/switch/SwitchLabel.js +0 -68
  175. package/lib/module/components/switch/SwitchLabel.js.map +0 -1
  176. package/lib/typescript/components/switch/AnimatedSwitch.d.ts +0 -13
  177. package/lib/typescript/components/switch/AnimatedSwitch.d.ts.map +0 -1
  178. package/lib/typescript/components/switch/SwitchLabel.d.ts +0 -18
  179. package/lib/typescript/components/switch/SwitchLabel.d.ts.map +0 -1
  180. package/src/components/switch/AnimatedSwitch.tsx +0 -126
  181. package/src/components/switch/SwitchLabel.tsx +0 -80
@@ -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
+ });