@pagopa/io-app-design-system 4.5.5 → 4.6.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 (182) 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/banner/Banner.js +3 -2
  4. package/lib/commonjs/components/banner/Banner.js.map +1 -1
  5. package/lib/commonjs/components/banner/__test__/__snapshots__/banner.test.tsx.snap +56 -0
  6. package/lib/commonjs/components/buttons/ButtonLink.js +1 -1
  7. package/lib/commonjs/components/buttons/ButtonSolid.js +1 -1
  8. package/lib/commonjs/components/buttons/ButtonSolid.js.map +1 -1
  9. package/lib/commonjs/components/checkbox/AnimatedCheckbox.js +8 -5
  10. package/lib/commonjs/components/checkbox/AnimatedCheckbox.js.map +1 -1
  11. package/lib/commonjs/components/checkbox/AnimatedMessageCheckbox.js +4 -2
  12. package/lib/commonjs/components/checkbox/AnimatedMessageCheckbox.js.map +1 -1
  13. package/lib/commonjs/components/claimsSelector/ClaimsSelector.js +119 -0
  14. package/lib/commonjs/components/claimsSelector/ClaimsSelector.js.map +1 -0
  15. package/lib/commonjs/components/claimsSelector/__test__/ClaimsSelector.test.js +46 -0
  16. package/lib/commonjs/components/claimsSelector/__test__/ClaimsSelector.test.js.map +1 -0
  17. package/lib/commonjs/components/claimsSelector/__test__/__snapshots__/ClaimsSelector.test.tsx.snap +1270 -0
  18. package/lib/commonjs/components/claimsSelector/index.js +17 -0
  19. package/lib/commonjs/components/claimsSelector/index.js.map +1 -0
  20. package/lib/commonjs/components/index.js +11 -0
  21. package/lib/commonjs/components/index.js.map +1 -1
  22. package/lib/commonjs/components/listitems/ListItemCheckbox.js +1 -1
  23. package/lib/commonjs/components/listitems/ListItemCheckbox.js.map +1 -1
  24. package/lib/commonjs/components/listitems/ListItemInfo.js +6 -2
  25. package/lib/commonjs/components/listitems/ListItemInfo.js.map +1 -1
  26. package/lib/commonjs/components/listitems/ListItemRadio.js +1 -1
  27. package/lib/commonjs/components/listitems/ListItemRadio.js.map +1 -1
  28. package/lib/commonjs/components/listitems/ListItemSwitch.js +1 -1
  29. package/lib/commonjs/components/listitems/ListItemSwitch.js.map +1 -1
  30. package/lib/commonjs/components/listitems/__test__/__snapshots__/listitem.test.tsx.snap +10 -0
  31. package/lib/commonjs/components/radio/AnimatedRadio.js +8 -5
  32. package/lib/commonjs/components/radio/AnimatedRadio.js.map +1 -1
  33. package/lib/commonjs/components/switch/NativeSwitch.js +5 -5
  34. package/lib/commonjs/components/switch/NativeSwitch.js.map +1 -1
  35. package/lib/commonjs/components/switch/index.js +0 -22
  36. package/lib/commonjs/components/switch/index.js.map +1 -1
  37. package/lib/commonjs/components/textInput/TextInputValidation.js +19 -7
  38. package/lib/commonjs/components/textInput/TextInputValidation.js.map +1 -1
  39. package/lib/commonjs/components/typography/markdown/MdH1.js +1 -2
  40. package/lib/commonjs/components/typography/markdown/MdH1.js.map +1 -1
  41. package/lib/commonjs/components/typography/markdown/MdH2.js +2 -2
  42. package/lib/commonjs/components/typography/markdown/MdH2.js.map +1 -1
  43. package/lib/commonjs/components/typography/markdown/MdH3.js +2 -2
  44. package/lib/commonjs/components/typography/markdown/MdH3.js.map +1 -1
  45. package/lib/commonjs/core/IOColors.js +28 -6
  46. package/lib/commonjs/core/IOColors.js.map +1 -1
  47. package/lib/commonjs/core/IOStyles.js +2 -16
  48. package/lib/commonjs/core/IOStyles.js.map +1 -1
  49. package/lib/commonjs/hooks/useAccordionAnimation.js +83 -0
  50. package/lib/commonjs/hooks/useAccordionAnimation.js.map +1 -0
  51. package/lib/module/components/accordion/AccordionItem.js +19 -52
  52. package/lib/module/components/accordion/AccordionItem.js.map +1 -1
  53. package/lib/module/components/banner/Banner.js +3 -2
  54. package/lib/module/components/banner/Banner.js.map +1 -1
  55. package/lib/module/components/banner/__test__/__snapshots__/banner.test.tsx.snap +56 -0
  56. package/lib/module/components/buttons/ButtonLink.js +1 -1
  57. package/lib/module/components/buttons/ButtonSolid.js +1 -1
  58. package/lib/module/components/buttons/ButtonSolid.js.map +1 -1
  59. package/lib/module/components/checkbox/AnimatedCheckbox.js +9 -6
  60. package/lib/module/components/checkbox/AnimatedCheckbox.js.map +1 -1
  61. package/lib/module/components/checkbox/AnimatedMessageCheckbox.js +6 -4
  62. package/lib/module/components/checkbox/AnimatedMessageCheckbox.js.map +1 -1
  63. package/lib/module/components/claimsSelector/ClaimsSelector.js +109 -0
  64. package/lib/module/components/claimsSelector/ClaimsSelector.js.map +1 -0
  65. package/lib/module/components/claimsSelector/__test__/ClaimsSelector.test.js +41 -0
  66. package/lib/module/components/claimsSelector/__test__/ClaimsSelector.test.js.map +1 -0
  67. package/lib/module/components/claimsSelector/__test__/__snapshots__/ClaimsSelector.test.tsx.snap +1270 -0
  68. package/lib/module/components/claimsSelector/index.js +2 -0
  69. package/lib/module/components/claimsSelector/index.js.map +1 -0
  70. package/lib/module/components/index.js +1 -0
  71. package/lib/module/components/index.js.map +1 -1
  72. package/lib/module/components/listitems/ListItemCheckbox.js +1 -1
  73. package/lib/module/components/listitems/ListItemCheckbox.js.map +1 -1
  74. package/lib/module/components/listitems/ListItemInfo.js +6 -2
  75. package/lib/module/components/listitems/ListItemInfo.js.map +1 -1
  76. package/lib/module/components/listitems/ListItemRadio.js +1 -1
  77. package/lib/module/components/listitems/ListItemRadio.js.map +1 -1
  78. package/lib/module/components/listitems/ListItemSwitch.js +1 -1
  79. package/lib/module/components/listitems/ListItemSwitch.js.map +1 -1
  80. package/lib/module/components/listitems/__test__/__snapshots__/listitem.test.tsx.snap +10 -0
  81. package/lib/module/components/radio/AnimatedRadio.js +9 -6
  82. package/lib/module/components/radio/AnimatedRadio.js.map +1 -1
  83. package/lib/module/components/switch/NativeSwitch.js +6 -6
  84. package/lib/module/components/switch/NativeSwitch.js.map +1 -1
  85. package/lib/module/components/switch/index.js +0 -2
  86. package/lib/module/components/switch/index.js.map +1 -1
  87. package/lib/module/components/textInput/TextInputValidation.js +20 -8
  88. package/lib/module/components/textInput/TextInputValidation.js.map +1 -1
  89. package/lib/module/components/typography/markdown/MdH1.js +1 -2
  90. package/lib/module/components/typography/markdown/MdH1.js.map +1 -1
  91. package/lib/module/components/typography/markdown/MdH2.js +2 -2
  92. package/lib/module/components/typography/markdown/MdH2.js.map +1 -1
  93. package/lib/module/components/typography/markdown/MdH3.js +2 -2
  94. package/lib/module/components/typography/markdown/MdH3.js.map +1 -1
  95. package/lib/module/core/IOColors.js +28 -6
  96. package/lib/module/core/IOColors.js.map +1 -1
  97. package/lib/module/core/IOStyles.js +1 -14
  98. package/lib/module/core/IOStyles.js.map +1 -1
  99. package/lib/module/hooks/useAccordionAnimation.js +76 -0
  100. package/lib/module/hooks/useAccordionAnimation.js.map +1 -0
  101. package/lib/typescript/components/accordion/AccordionItem.d.ts +0 -6
  102. package/lib/typescript/components/accordion/AccordionItem.d.ts.map +1 -1
  103. package/lib/typescript/components/banner/Banner.d.ts.map +1 -1
  104. package/lib/typescript/components/checkbox/AnimatedCheckbox.d.ts.map +1 -1
  105. package/lib/typescript/components/checkbox/AnimatedMessageCheckbox.d.ts.map +1 -1
  106. package/lib/typescript/components/claimsSelector/ClaimsSelector.d.ts +42 -0
  107. package/lib/typescript/components/claimsSelector/ClaimsSelector.d.ts.map +1 -0
  108. package/lib/typescript/components/claimsSelector/__test__/ClaimsSelector.test.d.ts +2 -0
  109. package/lib/typescript/components/claimsSelector/__test__/ClaimsSelector.test.d.ts.map +1 -0
  110. package/lib/typescript/components/claimsSelector/index.d.ts +2 -0
  111. package/lib/typescript/components/claimsSelector/index.d.ts.map +1 -0
  112. package/lib/typescript/components/index.d.ts +1 -0
  113. package/lib/typescript/components/index.d.ts.map +1 -1
  114. package/lib/typescript/components/listitems/ListItemInfo.d.ts +2 -1
  115. package/lib/typescript/components/listitems/ListItemInfo.d.ts.map +1 -1
  116. package/lib/typescript/components/switch/NativeSwitch.d.ts.map +1 -1
  117. package/lib/typescript/components/switch/index.d.ts +0 -2
  118. package/lib/typescript/components/switch/index.d.ts.map +1 -1
  119. package/lib/typescript/components/textInput/TextInputValidation.d.ts +31 -4
  120. package/lib/typescript/components/textInput/TextInputValidation.d.ts.map +1 -1
  121. package/lib/typescript/components/typography/BodyMonospace.d.ts +1 -1
  122. package/lib/typescript/components/typography/ButtonText.d.ts +1 -1
  123. package/lib/typescript/components/typography/Caption.d.ts +1 -1
  124. package/lib/typescript/components/typography/H1.d.ts +1 -1
  125. package/lib/typescript/components/typography/H2.d.ts +1 -1
  126. package/lib/typescript/components/typography/H3.d.ts +1 -1
  127. package/lib/typescript/components/typography/H4.d.ts +1 -1
  128. package/lib/typescript/components/typography/H5.d.ts +1 -1
  129. package/lib/typescript/components/typography/H6.d.ts +1 -1
  130. package/lib/typescript/components/typography/Hero.d.ts +1 -1
  131. package/lib/typescript/components/typography/markdown/MdH1.d.ts +1 -1
  132. package/lib/typescript/components/typography/markdown/MdH1.d.ts.map +1 -1
  133. package/lib/typescript/components/typography/markdown/MdH2.d.ts +1 -1
  134. package/lib/typescript/components/typography/markdown/MdH3.d.ts +1 -1
  135. package/lib/typescript/core/IOColors.d.ts +4 -1
  136. package/lib/typescript/core/IOColors.d.ts.map +1 -1
  137. package/lib/typescript/core/IOStyles.d.ts +0 -13
  138. package/lib/typescript/core/IOStyles.d.ts.map +1 -1
  139. package/lib/typescript/hooks/useAccordionAnimation.d.ts +41 -0
  140. package/lib/typescript/hooks/useAccordionAnimation.d.ts.map +1 -0
  141. package/package.json +1 -1
  142. package/src/components/accordion/AccordionItem.tsx +21 -82
  143. package/src/components/banner/Banner.tsx +3 -2
  144. package/src/components/banner/__test__/__snapshots__/banner.test.tsx.snap +56 -0
  145. package/src/components/buttons/ButtonLink.tsx +1 -1
  146. package/src/components/buttons/ButtonSolid.tsx +1 -1
  147. package/src/components/checkbox/AnimatedCheckbox.tsx +9 -10
  148. package/src/components/checkbox/AnimatedMessageCheckbox.tsx +5 -5
  149. package/src/components/claimsSelector/ClaimsSelector.tsx +185 -0
  150. package/src/components/claimsSelector/__test__/ClaimsSelector.test.tsx +55 -0
  151. package/src/components/claimsSelector/__test__/__snapshots__/ClaimsSelector.test.tsx.snap +1270 -0
  152. package/src/components/claimsSelector/index.tsx +1 -0
  153. package/src/components/index.tsx +1 -0
  154. package/src/components/listitems/ListItemCheckbox.tsx +1 -1
  155. package/src/components/listitems/ListItemInfo.tsx +7 -2
  156. package/src/components/listitems/ListItemRadio.tsx +1 -1
  157. package/src/components/listitems/ListItemSwitch.tsx +1 -1
  158. package/src/components/listitems/__test__/__snapshots__/listitem.test.tsx.snap +10 -0
  159. package/src/components/radio/AnimatedRadio.tsx +10 -10
  160. package/src/components/switch/NativeSwitch.tsx +6 -6
  161. package/src/components/switch/index.tsx +0 -2
  162. package/src/components/textInput/TextInputValidation.tsx +140 -97
  163. package/src/components/typography/markdown/MdH1.tsx +1 -2
  164. package/src/components/typography/markdown/MdH2.tsx +2 -2
  165. package/src/components/typography/markdown/MdH3.tsx +2 -2
  166. package/src/core/IOColors.ts +33 -5
  167. package/src/core/IOStyles.ts +1 -28
  168. package/src/hooks/useAccordionAnimation.tsx +106 -0
  169. package/lib/commonjs/components/switch/AnimatedSwitch.js +0 -94
  170. package/lib/commonjs/components/switch/AnimatedSwitch.js.map +0 -1
  171. package/lib/commonjs/components/switch/SwitchLabel.js +0 -76
  172. package/lib/commonjs/components/switch/SwitchLabel.js.map +0 -1
  173. package/lib/module/components/switch/AnimatedSwitch.js +0 -85
  174. package/lib/module/components/switch/AnimatedSwitch.js.map +0 -1
  175. package/lib/module/components/switch/SwitchLabel.js +0 -68
  176. package/lib/module/components/switch/SwitchLabel.js.map +0 -1
  177. package/lib/typescript/components/switch/AnimatedSwitch.d.ts +0 -13
  178. package/lib/typescript/components/switch/AnimatedSwitch.d.ts.map +0 -1
  179. package/lib/typescript/components/switch/SwitchLabel.d.ts +0 -18
  180. package/lib/typescript/components/switch/SwitchLabel.d.ts.map +0 -1
  181. package/src/components/switch/AnimatedSwitch.tsx +0 -126
  182. package/src/components/switch/SwitchLabel.tsx +0 -80
@@ -0,0 +1,106 @@
1
+ import { useCallback, useState } from "react";
2
+ import { StyleSheet, type LayoutChangeEvent } from "react-native";
3
+ import {
4
+ useAnimatedStyle,
5
+ useSharedValue,
6
+ withSpring
7
+ } from "react-native-reanimated";
8
+ import { IOSpacingScale, IOSpringValues } from "../core";
9
+
10
+ const accordionBodySpacing: IOSpacingScale = 16;
11
+
12
+ type Params = {
13
+ defaultExpanded?: boolean;
14
+ };
15
+
16
+ export const useAccordionAnimation = ({
17
+ defaultExpanded = false
18
+ }: Params = {}) => {
19
+ const [expanded, setExpanded] = useState(defaultExpanded);
20
+ // Disable animation when starting expanded
21
+ const animationEnabled = useSharedValue(!defaultExpanded);
22
+ const bodyHeight = useSharedValue(0);
23
+
24
+ const toggleAccordion = useCallback(() => {
25
+ // Re-enable animation when the user interacts with the accordion
26
+ animationEnabled.value = true; // eslint-disable-line functional/immutable-data
27
+ setExpanded(expanded => !expanded);
28
+ }, [animationEnabled]);
29
+
30
+ const iconAnimatedStyle = useAnimatedStyle(
31
+ () => ({
32
+ transform: [
33
+ {
34
+ rotate: withSpring(
35
+ expanded ? "180deg" : "0deg",
36
+ IOSpringValues.accordion
37
+ )
38
+ }
39
+ ]
40
+ }),
41
+ [expanded]
42
+ );
43
+
44
+ // The code below is a re-adaptation of Dima Portenko's code:
45
+ // https://github.com/dimaportenko/reanimated-collapsable-card-tutorial
46
+ const onBodyLayout = useCallback(
47
+ (event: LayoutChangeEvent) => {
48
+ const { height: onLayoutHeight } = event.nativeEvent.layout;
49
+
50
+ if (onLayoutHeight > 0 && bodyHeight.value !== onLayoutHeight) {
51
+ bodyHeight.value = onLayoutHeight; // eslint-disable-line functional/immutable-data
52
+ }
53
+ },
54
+ [bodyHeight]
55
+ );
56
+
57
+ const bodyAnimatedHeight = useAnimatedStyle(() => {
58
+ const nextHeight = expanded ? bodyHeight.value : 0;
59
+ return {
60
+ height: animationEnabled.value
61
+ ? withSpring(nextHeight, IOSpringValues.accordion)
62
+ : nextHeight
63
+ };
64
+ });
65
+
66
+ const bodyAnimatedStyle = [
67
+ bodyAnimatedHeight,
68
+ styles.accordionCollapsableContainer
69
+ ];
70
+ const bodyInnerStyle = styles.accordionBodyContainer;
71
+
72
+ return {
73
+ expanded,
74
+ /**
75
+ * Toggle the accordion expanded/collapsed state.
76
+ */
77
+ toggleAccordion,
78
+ /**
79
+ * The style to apply to the accordion icon.
80
+ */
81
+ iconAnimatedStyle,
82
+ /**
83
+ * Callback to execute on the body's inner container layout.
84
+ */
85
+ onBodyLayout,
86
+ /**
87
+ * The animated style to apply to the collapsible body container – it must be an `Animated.View`.
88
+ */
89
+ bodyAnimatedStyle,
90
+ /**
91
+ * The style to apply to the inner body container.
92
+ */
93
+ bodyInnerStyle
94
+ };
95
+ };
96
+
97
+ const styles = StyleSheet.create({
98
+ accordionCollapsableContainer: {
99
+ overflow: "hidden"
100
+ },
101
+ accordionBodyContainer: {
102
+ position: "absolute",
103
+ padding: accordionBodySpacing,
104
+ paddingTop: 0
105
+ }
106
+ });
@@ -1,94 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.AnimatedSwitch = void 0;
7
- var _react = _interopRequireWildcard(require("react"));
8
- var _reactNative = require("react-native");
9
- var _reactNativeReanimated = _interopRequireWildcard(require("react-native-reanimated"));
10
- var _IOAnimations = require("../../core/IOAnimations");
11
- var _IOColors = require("../../core/IOColors");
12
- var _IOStyles = require("../../core/IOStyles");
13
- var _AnimatedTick = require("../common/AnimatedTick");
14
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
15
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
16
- const SWITCH_CIRCLE_SIZE = _IOStyles.IOSwitchVisualParams.height - _IOStyles.IOSwitchVisualParams.padding * 2;
17
- const styles = _reactNative.StyleSheet.create({
18
- switchWrapper: {
19
- width: _IOStyles.IOSwitchVisualParams.width,
20
- height: _IOStyles.IOSwitchVisualParams.height
21
- },
22
- switchBackground: {
23
- position: "absolute",
24
- left: 0,
25
- top: 0,
26
- width: "100%",
27
- height: "100%",
28
- borderRadius: _IOStyles.IOSwitchVisualParams.width,
29
- backgroundColor: _IOColors.IOColors[_IOStyles.IOSwitchVisualParams.bgColorOffState]
30
- },
31
- switchCircle: {
32
- position: "absolute",
33
- left: _IOStyles.IOSwitchVisualParams.padding,
34
- top: _IOStyles.IOSwitchVisualParams.padding,
35
- backgroundColor: _IOColors.IOColors[_IOStyles.IOSwitchVisualParams.bgCircle],
36
- width: SWITCH_CIRCLE_SIZE,
37
- height: SWITCH_CIRCLE_SIZE,
38
- borderRadius: _IOStyles.IOSwitchVisualParams.width
39
- }
40
- });
41
-
42
- /**
43
- * An animated checkbox. This can be used to implement a
44
- * standard {@link CheckBox} or other composite components.
45
- */
46
- const AnimatedSwitch = ({
47
- checked,
48
- onPress,
49
- disabled
50
- }) => {
51
- const squareAnimationProgress = (0, _reactNativeReanimated.useSharedValue)(checked ? 1 : 0);
52
- const tickAnimationProgress = (0, _reactNativeReanimated.useSharedValue)(checked ? 1 : 0);
53
- (0, _react.useEffect)(() => {
54
- // eslint-disable-next-line functional/immutable-data
55
- squareAnimationProgress.value = (0, _reactNativeReanimated.withSpring)(checked ? 1 : 0, _IOAnimations.IOSpringValues.selection);
56
- // eslint-disable-next-line functional/immutable-data
57
- tickAnimationProgress.value = (0, _reactNativeReanimated.withTiming)(checked ? 1 : 0, {
58
- duration: 400,
59
- easing: _reactNativeReanimated.Easing.elastic(1)
60
- });
61
- }, [checked, squareAnimationProgress, tickAnimationProgress]);
62
- const animatedSwitchBg = (0, _reactNativeReanimated.useAnimatedStyle)(() => ({
63
- backgroundColor: (0, _reactNativeReanimated.interpolateColor)(squareAnimationProgress.value, [0, 1], [_IOColors.IOColors[_IOStyles.IOSwitchVisualParams.bgColorOffState], _IOColors.IOColors[_IOStyles.IOSwitchVisualParams.bgColorOnState]])
64
- }), [squareAnimationProgress]);
65
- const animatedSwitchCircle = (0, _reactNativeReanimated.useAnimatedStyle)(() => {
66
- const translateX = (0, _reactNativeReanimated.interpolate)(squareAnimationProgress.value, [0, 1], [0, _IOStyles.IOSwitchVisualParams.width - SWITCH_CIRCLE_SIZE - 2 * _IOStyles.IOSwitchVisualParams.padding]);
67
- return {
68
- transform: [{
69
- translateX
70
- }]
71
- };
72
- });
73
- const animatedSwitchTick = (0, _reactNativeReanimated.useAnimatedStyle)(() => ({
74
- opacity: tickAnimationProgress.value
75
- }));
76
- return /*#__PURE__*/_react.default.createElement(_reactNative.Pressable, {
77
- accessibilityRole: "switch",
78
- disabled: disabled,
79
- testID: "AnimatedSwitch",
80
- onPress: onPress,
81
- style: styles.switchWrapper
82
- }, /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, {
83
- style: [styles.switchBackground, animatedSwitchBg]
84
- }), /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, {
85
- style: [styles.switchCircle, animatedSwitchCircle]
86
- }, /*#__PURE__*/_react.default.createElement(_reactNativeReanimated.default.View, {
87
- style: animatedSwitchTick
88
- }, /*#__PURE__*/_react.default.createElement(_AnimatedTick.AnimatedTick, {
89
- progress: tickAnimationProgress,
90
- stroke: _IOColors.IOColors[_IOStyles.IOSwitchVisualParams.tickColor]
91
- }))));
92
- };
93
- exports.AnimatedSwitch = AnimatedSwitch;
94
- //# sourceMappingURL=AnimatedSwitch.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_react","_interopRequireWildcard","require","_reactNative","_reactNativeReanimated","_IOAnimations","_IOColors","_IOStyles","_AnimatedTick","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","SWITCH_CIRCLE_SIZE","IOSwitchVisualParams","height","padding","styles","StyleSheet","create","switchWrapper","width","switchBackground","position","left","top","borderRadius","backgroundColor","IOColors","bgColorOffState","switchCircle","bgCircle","AnimatedSwitch","checked","onPress","disabled","squareAnimationProgress","useSharedValue","tickAnimationProgress","useEffect","value","withSpring","IOSpringValues","selection","withTiming","duration","easing","Easing","elastic","animatedSwitchBg","useAnimatedStyle","interpolateColor","bgColorOnState","animatedSwitchCircle","translateX","interpolate","transform","animatedSwitchTick","opacity","createElement","Pressable","accessibilityRole","testID","style","View","AnimatedTick","progress","stroke","tickColor","exports"],"sourceRoot":"../../../../src","sources":["components/switch/AnimatedSwitch.tsx"],"mappings":";;;;;;AAAA,IAAAA,MAAA,GAAAC,uBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,sBAAA,GAAAH,uBAAA,CAAAC,OAAA;AASA,IAAAG,aAAA,GAAAH,OAAA;AACA,IAAAI,SAAA,GAAAJ,OAAA;AACA,IAAAK,SAAA,GAAAL,OAAA;AACA,IAAAM,aAAA,GAAAN,OAAA;AAAsD,SAAAO,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBA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M,CAACK,gBAAgB,EAAE2B,gBAAgB;EAAE,CAAE,CAAC,eACrEnE,MAAA,CAAAgB,OAAA,CAAA6D,aAAA,CAACzE,sBAAA,CAAAY,OAAQ,CAACkE,IAAI;IAACD,KAAK,EAAE,CAAC9C,MAAM,CAACa,YAAY,EAAEuB,oBAAoB;EAAE,gBAChEvE,MAAA,CAAAgB,OAAA,CAAA6D,aAAA,CAACzE,sBAAA,CAAAY,OAAQ,CAACkE,IAAI;IAACD,KAAK,EAAEN;EAAmB,gBACvC3E,MAAA,CAAAgB,OAAA,CAAA6D,aAAA,CAACrE,aAAA,CAAA2E,YAAY;IACXC,QAAQ,EAAE5B,qBAAsB;IAChC6B,MAAM,EAAEvC,kBAAQ,CAACd,8BAAoB,CAACsD,SAAS;EAAE,CAClD,CACY,CACF,CACN,CAAC;AAEhB,CAAC;AAACC,OAAA,CAAArC,cAAA,GAAAA,cAAA"}
@@ -1,76 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.SwitchLabel = void 0;
7
- var React = _interopRequireWildcard(require("react"));
8
- var _reactNative = require("react-native");
9
- var _core = require("../../core");
10
- var _IOStyles = require("../../core/IOStyles");
11
- var _hapticFeedback = require("../../functions/haptic-feedback/hapticFeedback");
12
- var _Spacer = require("../spacer/Spacer");
13
- var _H = require("../typography/H6");
14
- var _AnimatedSwitch = require("./AnimatedSwitch");
15
- function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function (nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
16
- function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || typeof obj !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
17
- const DISABLED_OPACITY = 0.5;
18
-
19
- // disabled: the component is no longer touchable
20
- // onPress:
21
- /**
22
- * A checkbox with the automatic state management that uses a {@link AnimatedCheckBox}
23
- * The toggleValue change when a `onPress` event is received and dispatch the `onValueChange`.
24
- *
25
- * @param props
26
- * @constructor
27
- */
28
- const SwitchLabel = ({
29
- label,
30
- checked,
31
- disabled,
32
- onValueChange
33
- }) => {
34
- const theme = (0, _core.useIOTheme)();
35
- const [toggleValue, setToggleValue] = (0, React.useState)(checked ?? false);
36
- const toggleCheckbox = () => {
37
- (0, _hapticFeedback.triggerHaptic)("impactLight");
38
- setToggleValue(!toggleValue);
39
- if (onValueChange !== undefined) {
40
- onValueChange(!toggleValue);
41
- }
42
- };
43
- return /*#__PURE__*/React.createElement(_reactNative.Pressable, {
44
- disabled: disabled,
45
- onPress: toggleCheckbox,
46
- accessibilityRole: "switch",
47
- accessibilityState: {
48
- checked: checked ?? toggleValue,
49
- disabled: !!disabled
50
- },
51
- style: {
52
- alignSelf: "flex-start",
53
- opacity: disabled ? DISABLED_OPACITY : 1
54
- },
55
- testID: "SwitchLabel"
56
- }, /*#__PURE__*/React.createElement(_reactNative.View, {
57
- style: [_IOStyles.IOStyles.row, {
58
- alignItems: "flex-start",
59
- flexShrink: 1,
60
- width: "100%"
61
- }]
62
- }, /*#__PURE__*/React.createElement(_reactNative.View, {
63
- pointerEvents: "none"
64
- }, /*#__PURE__*/React.createElement(_AnimatedSwitch.AnimatedSwitch, {
65
- checked: checked ?? toggleValue
66
- })), /*#__PURE__*/React.createElement(_Spacer.HSpacer, {
67
- size: 8
68
- }), /*#__PURE__*/React.createElement(_H.H6, {
69
- style: {
70
- flexShrink: 1
71
- },
72
- color: theme["textBody-default"]
73
- }, label)));
74
- };
75
- exports.SwitchLabel = SwitchLabel;
76
- //# sourceMappingURL=SwitchLabel.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["React","_interopRequireWildcard","require","_reactNative","_core","_IOStyles","_hapticFeedback","_Spacer","_H","_AnimatedSwitch","_getRequireWildcardCache","nodeInterop","WeakMap","cacheBabelInterop","cacheNodeInterop","obj","__esModule","default","cache","has","get","newObj","hasPropertyDescriptor","Object","defineProperty","getOwnPropertyDescriptor","key","prototype","hasOwnProperty","call","desc","set","DISABLED_OPACITY","SwitchLabel","label","checked","disabled","onValueChange","theme","useIOTheme","toggleValue","setToggleValue","useState","toggleCheckbox","triggerHaptic","undefined","createElement","Pressable","onPress","accessibilityRole","accessibilityState","style","alignSelf","opacity","testID","View","IOStyles","row","alignItems","flexShrink","width","pointerEvents","AnimatedSwitch","HSpacer","size","H6","color","exports"],"sourceRoot":"../../../../src","sources":["components/switch/SwitchLabel.tsx"],"mappings":";;;;;;AAAA,IAAAA,KAAA,GAAAC,uBAAA,CAAAC,OAAA;AAEA,IAAAC,YAAA,GAAAD,OAAA;AACA,IAAAE,KAAA,GAAAF,OAAA;AACA,IAAAG,SAAA,GAAAH,OAAA;AACA,IAAAI,eAAA,GAAAJ,OAAA;AACA,IAAAK,OAAA,GAAAL,OAAA;AACA,IAAAM,EAAA,GAAAN,OAAA;AACA,IAAAO,eAAA,GAAAP,OAAA;AAAkD,SAAAQ,yBAAAC,WAAA,eAAAC,OAAA,kCAAAC,iBAAA,OAAAD,OAAA,QAAAE,gBAAA,OAAAF,OAAA,YAAAF,wBAAA,YAAAA,CAAAC,WAAA,WAAAA,WAAA,GAAAG,gBAAA,GAAAD,iBAAA,KAAAF,WAAA;AAAA,SAAAV,wBAAAc,GAAA,EAAAJ,WAAA,SAAAA,WAAA,IAAAI,GAA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CAAAlC,WAAA,GAAAA,WAAA"}
@@ -1,85 +0,0 @@
1
- import React, { useEffect } from "react";
2
- import { Pressable, StyleSheet } from "react-native";
3
- import Animated, { Easing, interpolate, interpolateColor, useAnimatedStyle, useSharedValue, withSpring, withTiming } from "react-native-reanimated";
4
- import { IOSpringValues } from "../../core/IOAnimations";
5
- import { IOColors } from "../../core/IOColors";
6
- import { IOSwitchVisualParams } from "../../core/IOStyles";
7
- import { AnimatedTick } from "../common/AnimatedTick";
8
- const SWITCH_CIRCLE_SIZE = IOSwitchVisualParams.height - IOSwitchVisualParams.padding * 2;
9
- const styles = StyleSheet.create({
10
- switchWrapper: {
11
- width: IOSwitchVisualParams.width,
12
- height: IOSwitchVisualParams.height
13
- },
14
- switchBackground: {
15
- position: "absolute",
16
- left: 0,
17
- top: 0,
18
- width: "100%",
19
- height: "100%",
20
- borderRadius: IOSwitchVisualParams.width,
21
- backgroundColor: IOColors[IOSwitchVisualParams.bgColorOffState]
22
- },
23
- switchCircle: {
24
- position: "absolute",
25
- left: IOSwitchVisualParams.padding,
26
- top: IOSwitchVisualParams.padding,
27
- backgroundColor: IOColors[IOSwitchVisualParams.bgCircle],
28
- width: SWITCH_CIRCLE_SIZE,
29
- height: SWITCH_CIRCLE_SIZE,
30
- borderRadius: IOSwitchVisualParams.width
31
- }
32
- });
33
-
34
- /**
35
- * An animated checkbox. This can be used to implement a
36
- * standard {@link CheckBox} or other composite components.
37
- */
38
- export const AnimatedSwitch = ({
39
- checked,
40
- onPress,
41
- disabled
42
- }) => {
43
- const squareAnimationProgress = useSharedValue(checked ? 1 : 0);
44
- const tickAnimationProgress = useSharedValue(checked ? 1 : 0);
45
- useEffect(() => {
46
- // eslint-disable-next-line functional/immutable-data
47
- squareAnimationProgress.value = withSpring(checked ? 1 : 0, IOSpringValues.selection);
48
- // eslint-disable-next-line functional/immutable-data
49
- tickAnimationProgress.value = withTiming(checked ? 1 : 0, {
50
- duration: 400,
51
- easing: Easing.elastic(1)
52
- });
53
- }, [checked, squareAnimationProgress, tickAnimationProgress]);
54
- const animatedSwitchBg = useAnimatedStyle(() => ({
55
- backgroundColor: interpolateColor(squareAnimationProgress.value, [0, 1], [IOColors[IOSwitchVisualParams.bgColorOffState], IOColors[IOSwitchVisualParams.bgColorOnState]])
56
- }), [squareAnimationProgress]);
57
- const animatedSwitchCircle = useAnimatedStyle(() => {
58
- const translateX = interpolate(squareAnimationProgress.value, [0, 1], [0, IOSwitchVisualParams.width - SWITCH_CIRCLE_SIZE - 2 * IOSwitchVisualParams.padding]);
59
- return {
60
- transform: [{
61
- translateX
62
- }]
63
- };
64
- });
65
- const animatedSwitchTick = useAnimatedStyle(() => ({
66
- opacity: tickAnimationProgress.value
67
- }));
68
- return /*#__PURE__*/React.createElement(Pressable, {
69
- accessibilityRole: "switch",
70
- disabled: disabled,
71
- testID: "AnimatedSwitch",
72
- onPress: onPress,
73
- style: styles.switchWrapper
74
- }, /*#__PURE__*/React.createElement(Animated.View, {
75
- style: [styles.switchBackground, animatedSwitchBg]
76
- }), /*#__PURE__*/React.createElement(Animated.View, {
77
- style: [styles.switchCircle, animatedSwitchCircle]
78
- }, /*#__PURE__*/React.createElement(Animated.View, {
79
- style: animatedSwitchTick
80
- }, /*#__PURE__*/React.createElement(AnimatedTick, {
81
- progress: tickAnimationProgress,
82
- stroke: IOColors[IOSwitchVisualParams.tickColor]
83
- }))));
84
- };
85
- //# sourceMappingURL=AnimatedSwitch.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["React","useEffect","Pressable","StyleSheet","Animated","Easing","interpolate","interpolateColor","useAnimatedStyle","useSharedValue","withSpring","withTiming","IOSpringValues","IOColors","IOSwitchVisualParams","AnimatedTick","SWITCH_CIRCLE_SIZE","height","padding","styles","create","switchWrapper","width","switchBackground","position","left","top","borderRadius","backgroundColor","bgColorOffState","switchCircle","bgCircle","AnimatedSwitch","checked","onPress","disabled","squareAnimationProgress","tickAnimationProgress","value","selection","duration","easing","elastic","animatedSwitchBg","bgColorOnState","animatedSwitchCircle","translateX","transform","animatedSwitchTick","opacity","createElement","accessibilityRole","testID","style","View","progress","stroke","tickColor"],"sourceRoot":"../../../../src","sources":["components/switch/AnimatedSwitch.tsx"],"mappings":"AAAA,OAAOA,KAAK,IAAIC,SAAS,QAAQ,OAAO;AACxC,SAASC,SAAS,EAAkBC,UAAU,QAAQ,cAAc;AACpE,OAAOC,QAAQ,IACbC,MAAM,EACNC,WAAW,EACXC,gBAAgB,EAChBC,gBAAgB,EAChBC,cAAc,EACdC,UAAU,EACVC,UAAU,QACL,yBAAyB;AAChC,SAASC,cAAc,QAAQ,yBAAyB;AACxD,SAASC,QAAQ,QAAQ,qBAAqB;AAC9C,SAASC,oBAAoB,QAAQ,qBAAqB;AAC1D,SAASC,YAAY,QAAQ,wBAAwB;AAQrD,MAAMC,kBAAkB,GACtBF,oBAAoB,CAACG,MAAM,GAAGH,oBAAoB,CAACI,OAAO,GAAG,CAAC;AAEhE,MAAMC,MAAM,GAAGhB,UAAU,CAACiB,MAAM,CAAC;EAC/BC,aAAa,EAAE;IACbC,KAAK,EAAER,oBAAoB,CAACQ,KAAK;IACjCL,MAAM,EAAEH,oBAAoB,CAACG;EAC/B,CAAC;EACDM,gBAAgB,EAAE;IAChBC,QAAQ,EAAE,UAAU;IACpBC,IAAI,EAAE,CAAC;IACPC,GAAG,EAAE,CAAC;IACNJ,KAAK,EAAE,MAAM;IACbL,MAAM,EAAE,MAAM;IACdU,YAAY,EAAEb,oBAAoB,CAACQ,KAAK;IACxCM,eAAe,EAAEf,QAAQ,CAACC,oBAAoB,CAACe,eAAe;EAChE,CAAC;EACDC,YAAY,EAAE;IACZN,QAAQ,EAAE,UAAU;IACpBC,IAAI,EAAEX,oBAAoB,CAACI,OAAO;IAClCQ,GAAG,EAAEZ,oBAAoB,CAACI,OAAO;IACjCU,eAAe,EAAEf,QAAQ,CAACC,oBAAoB,CAACiB,QAAQ,CAAC;IACxDT,KAAK,EAAEN,kBAAkB;IACzBC,MAAM,EA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B,oBAAoB,CAACQ,KAAK,GACxBN,kBAAkB,GAClB,CAAC,GAAGF,oBAAoB,CAACI,OAAO,CAEtC,CAAC;IAED,OAAO;MACL6B,SAAS,EAAE,CAAC;QAAED;MAAW,CAAC;IAC5B,CAAC;EACH,CAAC,CAAC;EAEF,MAAME,kBAAkB,GAAGxC,gBAAgB,CAAC,OAAO;IACjDyC,OAAO,EAAEZ,qBAAqB,CAACC;EACjC,CAAC,CAAC,CAAC;EAEH,oBACEtC,KAAA,CAAAkD,aAAA,CAAChD,SAAS;IACRiD,iBAAiB,EAAC,QAAQ;IAC1BhB,QAAQ,EAAEA,QAAS;IACnBiB,MAAM,EAAC,gBAAgB;IACvBlB,OAAO,EAAEA,OAAQ;IACjBmB,KAAK,EAAElC,MAAM,CAACE;EAAc,gBAE5BrB,KAAA,CAAAkD,aAAA,CAAC9C,QAAQ,CAACkD,IAAI;IAACD,KAAK,EAAE,CAAClC,MAAM,CAACI,gBAAgB,EAAEoB,gBAAgB;EAAE,CAAE,CAAC,eACrE3C,KAAA,CAAAkD,aAAA,CAAC9C,QAAQ,CAACkD,IAAI;IAACD,KAAK,EAAE,CAAClC,MAAM,CAACW,YAAY,EAAEe,oBAAoB;EAAE,gBAChE7C,KAAA,CAAAkD,aAAA,CAAC9C,QAAQ,CAACkD,IAAI;IAACD,KAAK,EAAEL;EAAmB,gBACvChD,KAAA,CAAAkD,aAAA,CAACnC,YAAY;IACXwC,QAAQ,EAAElB,qBAAsB;IAChCmB,MAAM,EAAE3C,QAAQ,CAACC,oBAAoB,CAAC2C,SAAS;EAAE,CAClD,CACY,CACF,CACN,CAAC;AAEhB,CAAC"}
@@ -1,68 +0,0 @@
1
- import * as React from "react";
2
- import { useState } from "react";
3
- import { Pressable, View } from "react-native";
4
- import { useIOTheme } from "../../core";
5
- import { IOStyles } from "../../core/IOStyles";
6
- import { triggerHaptic } from "../../functions/haptic-feedback/hapticFeedback";
7
- import { HSpacer } from "../spacer/Spacer";
8
- import { H6 } from "../typography/H6";
9
- import { AnimatedSwitch } from "./AnimatedSwitch";
10
- const DISABLED_OPACITY = 0.5;
11
-
12
- // disabled: the component is no longer touchable
13
- // onPress:
14
- /**
15
- * A checkbox with the automatic state management that uses a {@link AnimatedCheckBox}
16
- * The toggleValue change when a `onPress` event is received and dispatch the `onValueChange`.
17
- *
18
- * @param props
19
- * @constructor
20
- */
21
- export const SwitchLabel = ({
22
- label,
23
- checked,
24
- disabled,
25
- onValueChange
26
- }) => {
27
- const theme = useIOTheme();
28
- const [toggleValue, setToggleValue] = useState(checked ?? false);
29
- const toggleCheckbox = () => {
30
- triggerHaptic("impactLight");
31
- setToggleValue(!toggleValue);
32
- if (onValueChange !== undefined) {
33
- onValueChange(!toggleValue);
34
- }
35
- };
36
- return /*#__PURE__*/React.createElement(Pressable, {
37
- disabled: disabled,
38
- onPress: toggleCheckbox,
39
- accessibilityRole: "switch",
40
- accessibilityState: {
41
- checked: checked ?? toggleValue,
42
- disabled: !!disabled
43
- },
44
- style: {
45
- alignSelf: "flex-start",
46
- opacity: disabled ? DISABLED_OPACITY : 1
47
- },
48
- testID: "SwitchLabel"
49
- }, /*#__PURE__*/React.createElement(View, {
50
- style: [IOStyles.row, {
51
- alignItems: "flex-start",
52
- flexShrink: 1,
53
- width: "100%"
54
- }]
55
- }, /*#__PURE__*/React.createElement(View, {
56
- pointerEvents: "none"
57
- }, /*#__PURE__*/React.createElement(AnimatedSwitch, {
58
- checked: checked ?? toggleValue
59
- })), /*#__PURE__*/React.createElement(HSpacer, {
60
- size: 8
61
- }), /*#__PURE__*/React.createElement(H6, {
62
- style: {
63
- flexShrink: 1
64
- },
65
- color: theme["textBody-default"]
66
- }, label)));
67
- };
68
- //# sourceMappingURL=SwitchLabel.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["React","useState","Pressable","View","useIOTheme","IOStyles","triggerHaptic","HSpacer","H6","AnimatedSwitch","DISABLED_OPACITY","SwitchLabel","label","checked","disabled","onValueChange","theme","toggleValue","setToggleValue","toggleCheckbox","undefined","createElement","onPress","accessibilityRole","accessibilityState","style","alignSelf","opacity","testID","row","alignItems","flexShrink","width","pointerEvents","size","color"],"sourceRoot":"../../../../src","sources":["components/switch/SwitchLabel.tsx"],"mappings":"AAAA,OAAO,KAAKA,KAAK,MAAM,OAAO;AAC9B,SAASC,QAAQ,QAAQ,OAAO;AAChC,SAASC,SAAS,EAAEC,IAAI,QAAQ,cAAc;AAC9C,SAASC,UAAU,QAAQ,YAAY;AACvC,SAASC,QAAQ,QAAQ,qBAAqB;AAC9C,SAASC,aAAa,QAAQ,gDAAgD;AAC9E,SAASC,OAAO,QAAQ,kBAAkB;AAC1C,SAASC,EAAE,QAAQ,kBAAkB;AACrC,SAASC,cAAc,QAAQ,kBAAkB;AAQjD,MAAMC,gBAAgB,GAAG,GAAG;;AAE5B;AACA;AAKA;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,WAAW,GAAGA,CAAC;EAC1BC,KAAK;EACLC,OAAO;EACPC,QAAQ;EACRC;AACQ,CAAC,KAAK;EACd,MAAMC,KAAK,GAAGZ,UAAU,CAAC,CAAC;EAC1B,MAAM,CAACa,WAAW,EAAEC,cAAc,CAAC,GAAGjB,QAAQ,CAACY,OAAO,IAAI,KAAK,CAAC;EAEhE,MAAMM,cAAc,GAAGA,CAAA,KAAM;IAC3Bb,aAAa,CAAC,aAAa,CAAC;IAC5BY,cAAc,CAAC,CAACD,WAAW,CAAC;IAC5B,IAAIF,aAAa,KAAKK,SAAS,EAAE;MAC/BL,aAAa,CAAC,CAACE,WAAW,CAAC;IAC7B;EACF,CAAC;EAED,oBACEjB,KAAA,CAAAqB,aAAA,CAACnB,SAAS;IACRY,QAAQ,EAAEA,QAAS;IACnBQ,OAAO,EAAEH,cAAe;IACxBI,iBAAiB,EAAC,QAAQ;IAC1BC,kBAAkB,EAAE;MAClBX,OAAO,EAAEA,OAAO,IAAII,WAAW;MAC/BH,QAAQ,EAAE,CAAC,CAACA;IACd,CAAE;IACFW,KAAK,EAAE;MACLC,SAAS,EAAE,YAAY;MACvBC,OAAO,EAAEb,QAAQ,GAAGJ,gBAAgB,GAAG;IACzC,CAAE;IACFkB,MAAM,EAAC;EAAa,gBAEpB5B,KAAA,CAAAqB,aAAA,CAAClB,IAAI;IACHsB,KAAK,EAAE,CACLpB,QAAQ,CAACwB,GAAG,EACZ;MAAEC,UAAU,EAAE,YAAY;MAAEC,UAAU,EAAE,CAAC;MAAEC,KAAK,EAAE;IAAO,CAAC;EAC1D,gBAEFhC,KAAA,CAAAqB,aAAA,CAAClB,IAAI;IAAC8B,aAAa,EAAC;EAAM,gBACxBjC,KAAA,CAAAqB,aAAA,CAACZ,cAAc;IAACI,OAAO,EAAEA,OAAO,IAAII;EAAY,CAAE,CAC9C,CAAC,eACPjB,KAAA,CAAAqB,aAAA,CAACd,OAAO;IAAC2B,IAAI,EAAE;EAAE,CAAE,CAAC,eACpBlC,KAAA,CAAAqB,aAAA,CAACb,EAAE;IAACiB,KAAK,EAAE;MAAEM,UAAU,EAAE;IAAE,CAAE;IAACI,KAAK,EAAEnB,KAAK,CAAC,kBAAkB;EAAE,GAC5DJ,KACC,CACA,CACG,CAAC;AAEhB,CAAC"}
@@ -1,13 +0,0 @@
1
- import React from "react";
2
- import { PressableProps } from "react-native";
3
- type Props = {
4
- checked?: boolean;
5
- };
6
- type OwnProps = Props & Pick<PressableProps, "disabled" | "onPress">;
7
- /**
8
- * An animated checkbox. This can be used to implement a
9
- * standard {@link CheckBox} or other composite components.
10
- */
11
- export declare const AnimatedSwitch: ({ checked, onPress, disabled }: OwnProps) => React.JSX.Element;
12
- export {};
13
- //# sourceMappingURL=AnimatedSwitch.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"AnimatedSwitch.d.ts","sourceRoot":"","sources":["../../../../src/components/switch/AnimatedSwitch.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAoB,MAAM,OAAO,CAAC;AACzC,OAAO,EAAa,cAAc,EAAc,MAAM,cAAc,CAAC;AAerE,KAAK,KAAK,GAAG;IACX,OAAO,CAAC,EAAE,OAAO,CAAC;CACnB,CAAC;AAEF,KAAK,QAAQ,GAAG,KAAK,GAAG,IAAI,CAAC,cAAc,EAAE,UAAU,GAAG,SAAS,CAAC,CAAC;AA8BrE;;;GAGG;AACH,eAAO,MAAM,cAAc,mCAAoC,QAAQ,sBAuEtE,CAAC"}
@@ -1,18 +0,0 @@
1
- import * as React from "react";
2
- import { Pressable } from "react-native";
3
- import { AnimatedSwitch } from "./AnimatedSwitch";
4
- type Props = {
5
- label: string;
6
- onValueChange?: (newValue: boolean) => void;
7
- };
8
- type OwnProps = Props & Pick<React.ComponentProps<typeof AnimatedSwitch>, "disabled" | "checked"> & Pick<React.ComponentProps<typeof Pressable>, "onPress">;
9
- /**
10
- * A checkbox with the automatic state management that uses a {@link AnimatedCheckBox}
11
- * The toggleValue change when a `onPress` event is received and dispatch the `onValueChange`.
12
- *
13
- * @param props
14
- * @constructor
15
- */
16
- export declare const SwitchLabel: ({ label, checked, disabled, onValueChange }: OwnProps) => React.JSX.Element;
17
- export {};
18
- //# sourceMappingURL=SwitchLabel.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"SwitchLabel.d.ts","sourceRoot":"","sources":["../../../../src/components/switch/SwitchLabel.tsx"],"names":[],"mappings":"AAAA,OAAO,KAAK,KAAK,MAAM,OAAO,CAAC;AAE/B,OAAO,EAAE,SAAS,EAAQ,MAAM,cAAc,CAAC;AAM/C,OAAO,EAAE,cAAc,EAAE,MAAM,kBAAkB,CAAC;AAElD,KAAK,KAAK,GAAG;IACX,KAAK,EAAE,MAAM,CAAC;IAEd,aAAa,CAAC,EAAE,CAAC,QAAQ,EAAE,OAAO,KAAK,IAAI,CAAC;CAC7C,CAAC;AAMF,KAAK,QAAQ,GAAG,KAAK,GACnB,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,cAAc,CAAC,EAAE,UAAU,GAAG,SAAS,CAAC,GACzE,IAAI,CAAC,KAAK,CAAC,cAAc,CAAC,OAAO,SAAS,CAAC,EAAE,SAAS,CAAC,CAAC;AAE1D;;;;;;GAMG;AACH,eAAO,MAAM,WAAW,gDAKrB,QAAQ,sBA2CV,CAAC"}
@@ -1,126 +0,0 @@
1
- import React, { useEffect } from "react";
2
- import { Pressable, PressableProps, StyleSheet } from "react-native";
3
- import Animated, {
4
- Easing,
5
- interpolate,
6
- interpolateColor,
7
- useAnimatedStyle,
8
- useSharedValue,
9
- withSpring,
10
- withTiming
11
- } from "react-native-reanimated";
12
- import { IOSpringValues } from "../../core/IOAnimations";
13
- import { IOColors } from "../../core/IOColors";
14
- import { IOSwitchVisualParams } from "../../core/IOStyles";
15
- import { AnimatedTick } from "../common/AnimatedTick";
16
-
17
- type Props = {
18
- checked?: boolean;
19
- };
20
-
21
- type OwnProps = Props & Pick<PressableProps, "disabled" | "onPress">;
22
-
23
- const SWITCH_CIRCLE_SIZE =
24
- IOSwitchVisualParams.height - IOSwitchVisualParams.padding * 2;
25
-
26
- const styles = StyleSheet.create({
27
- switchWrapper: {
28
- width: IOSwitchVisualParams.width,
29
- height: IOSwitchVisualParams.height
30
- },
31
- switchBackground: {
32
- position: "absolute",
33
- left: 0,
34
- top: 0,
35
- width: "100%",
36
- height: "100%",
37
- borderRadius: IOSwitchVisualParams.width,
38
- backgroundColor: IOColors[IOSwitchVisualParams.bgColorOffState]
39
- },
40
- switchCircle: {
41
- position: "absolute",
42
- left: IOSwitchVisualParams.padding,
43
- top: IOSwitchVisualParams.padding,
44
- backgroundColor: IOColors[IOSwitchVisualParams.bgCircle],
45
- width: SWITCH_CIRCLE_SIZE,
46
- height: SWITCH_CIRCLE_SIZE,
47
- borderRadius: IOSwitchVisualParams.width
48
- }
49
- });
50
-
51
- /**
52
- * An animated checkbox. This can be used to implement a
53
- * standard {@link CheckBox} or other composite components.
54
- */
55
- export const AnimatedSwitch = ({ checked, onPress, disabled }: OwnProps) => {
56
- const squareAnimationProgress = useSharedValue(checked ? 1 : 0);
57
- const tickAnimationProgress = useSharedValue(checked ? 1 : 0);
58
-
59
- useEffect(() => {
60
- // eslint-disable-next-line functional/immutable-data
61
- squareAnimationProgress.value = withSpring(
62
- checked ? 1 : 0,
63
- IOSpringValues.selection
64
- );
65
- // eslint-disable-next-line functional/immutable-data
66
- tickAnimationProgress.value = withTiming(checked ? 1 : 0, {
67
- duration: 400,
68
- easing: Easing.elastic(1)
69
- });
70
- }, [checked, squareAnimationProgress, tickAnimationProgress]);
71
-
72
- const animatedSwitchBg = useAnimatedStyle(
73
- () => ({
74
- backgroundColor: interpolateColor(
75
- squareAnimationProgress.value,
76
- [0, 1],
77
- [
78
- IOColors[IOSwitchVisualParams.bgColorOffState],
79
- IOColors[IOSwitchVisualParams.bgColorOnState]
80
- ]
81
- )
82
- }),
83
- [squareAnimationProgress]
84
- );
85
-
86
- const animatedSwitchCircle = useAnimatedStyle(() => {
87
- const translateX = interpolate(
88
- squareAnimationProgress.value,
89
- [0, 1],
90
- [
91
- 0,
92
- IOSwitchVisualParams.width -
93
- SWITCH_CIRCLE_SIZE -
94
- 2 * IOSwitchVisualParams.padding
95
- ]
96
- );
97
-
98
- return {
99
- transform: [{ translateX }]
100
- };
101
- });
102
-
103
- const animatedSwitchTick = useAnimatedStyle(() => ({
104
- opacity: tickAnimationProgress.value
105
- }));
106
-
107
- return (
108
- <Pressable
109
- accessibilityRole="switch"
110
- disabled={disabled}
111
- testID="AnimatedSwitch"
112
- onPress={onPress}
113
- style={styles.switchWrapper}
114
- >
115
- <Animated.View style={[styles.switchBackground, animatedSwitchBg]} />
116
- <Animated.View style={[styles.switchCircle, animatedSwitchCircle]}>
117
- <Animated.View style={animatedSwitchTick}>
118
- <AnimatedTick
119
- progress={tickAnimationProgress}
120
- stroke={IOColors[IOSwitchVisualParams.tickColor]}
121
- />
122
- </Animated.View>
123
- </Animated.View>
124
- </Pressable>
125
- );
126
- };