@pagopa/io-app-design-system 1.13.1 → 1.15.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 (154) hide show
  1. package/lib/commonjs/components/avatar/Avatar.js +22 -6
  2. package/lib/commonjs/components/avatar/Avatar.js.map +1 -1
  3. package/lib/commonjs/components/avatar/__test__/__snapshots__/avatar.test.tsx.snap +17 -4
  4. package/lib/commonjs/components/avatar/__test__/avatar.test.js +3 -8
  5. package/lib/commonjs/components/avatar/__test__/avatar.test.js.map +1 -1
  6. package/lib/commonjs/components/avatar/index.js +0 -11
  7. package/lib/commonjs/components/avatar/index.js.map +1 -1
  8. package/lib/commonjs/components/badge/Badge.js +46 -5
  9. package/lib/commonjs/components/badge/Badge.js.map +1 -1
  10. package/lib/commonjs/components/banner/Banner.js +9 -8
  11. package/lib/commonjs/components/banner/Banner.js.map +1 -1
  12. package/lib/commonjs/components/banner/__test__/__snapshots__/banner.test.tsx.snap +3 -2
  13. package/lib/commonjs/components/icons/svg/IconInstitution.js +3 -3
  14. package/lib/commonjs/components/icons/svg/IconInstitution.js.map +1 -1
  15. package/lib/commonjs/components/icons/svg/originals/IconInstitution.svg +2 -7
  16. package/lib/commonjs/components/listitems/ListItemNav.js +9 -0
  17. package/lib/commonjs/components/listitems/ListItemNav.js.map +1 -1
  18. package/lib/commonjs/components/listitems/ListItemSwitch.js +28 -10
  19. package/lib/commonjs/components/listitems/ListItemSwitch.js.map +1 -1
  20. package/lib/commonjs/components/listitems/ListItemTransaction.js +1 -1
  21. package/lib/commonjs/components/listitems/ListItemTransaction.js.map +1 -1
  22. package/lib/commonjs/components/listitems/__test__/__snapshots__/listitem.test.tsx.snap +1 -1
  23. package/lib/commonjs/components/loadingSpinner/LoadingSpinner.js +3 -3
  24. package/lib/commonjs/components/modules/ModuleIDP.js +6 -49
  25. package/lib/commonjs/components/modules/ModuleIDP.js.map +1 -1
  26. package/lib/commonjs/components/modules/ModulePaymentNotice.js +15 -51
  27. package/lib/commonjs/components/modules/ModulePaymentNotice.js.map +1 -1
  28. package/lib/commonjs/components/modules/PressableModuleBase.js +44 -0
  29. package/lib/commonjs/components/modules/PressableModuleBase.js.map +1 -0
  30. package/lib/commonjs/components/modules/hooks/useModuleSpringAnimation.js +41 -0
  31. package/lib/commonjs/components/modules/hooks/useModuleSpringAnimation.js.map +1 -0
  32. package/lib/commonjs/components/modules/index.js +11 -0
  33. package/lib/commonjs/components/modules/index.js.map +1 -1
  34. package/lib/commonjs/components/switch/NativeSwitch.js +5 -3
  35. package/lib/commonjs/components/switch/NativeSwitch.js.map +1 -1
  36. package/lib/commonjs/components/textInput/TextInputBase.js +6 -5
  37. package/lib/commonjs/components/textInput/TextInputBase.js.map +1 -1
  38. package/lib/commonjs/core/IOColors.js +1 -0
  39. package/lib/commonjs/core/IOColors.js.map +1 -1
  40. package/lib/commonjs/core/IOStyles.js +18 -2
  41. package/lib/commonjs/core/IOStyles.js.map +1 -1
  42. package/lib/commonjs/stories/ModuleIDP.stories.js +45 -0
  43. package/lib/commonjs/stories/ModuleIDP.stories.js.map +1 -0
  44. package/lib/commonjs/utils/textInput/index.js +2 -1
  45. package/lib/commonjs/utils/textInput/index.js.map +1 -1
  46. package/lib/module/components/avatar/Avatar.js +24 -8
  47. package/lib/module/components/avatar/Avatar.js.map +1 -1
  48. package/lib/module/components/avatar/__test__/__snapshots__/avatar.test.tsx.snap +17 -4
  49. package/lib/module/components/avatar/__test__/avatar.test.js +3 -8
  50. package/lib/module/components/avatar/__test__/avatar.test.js.map +1 -1
  51. package/lib/module/components/avatar/index.js +0 -1
  52. package/lib/module/components/avatar/index.js.map +1 -1
  53. package/lib/module/components/badge/Badge.js +44 -4
  54. package/lib/module/components/badge/Badge.js.map +1 -1
  55. package/lib/module/components/banner/Banner.js +9 -8
  56. package/lib/module/components/banner/Banner.js.map +1 -1
  57. package/lib/module/components/banner/__test__/__snapshots__/banner.test.tsx.snap +3 -2
  58. package/lib/module/components/icons/svg/IconInstitution.js +3 -3
  59. package/lib/module/components/icons/svg/IconInstitution.js.map +1 -1
  60. package/lib/module/components/icons/svg/originals/IconInstitution.svg +2 -7
  61. package/lib/module/components/listitems/ListItemNav.js +9 -0
  62. package/lib/module/components/listitems/ListItemNav.js.map +1 -1
  63. package/lib/module/components/listitems/ListItemSwitch.js +28 -11
  64. package/lib/module/components/listitems/ListItemSwitch.js.map +1 -1
  65. package/lib/module/components/listitems/ListItemTransaction.js +1 -1
  66. package/lib/module/components/listitems/ListItemTransaction.js.map +1 -1
  67. package/lib/module/components/listitems/__test__/__snapshots__/listitem.test.tsx.snap +1 -1
  68. package/lib/module/components/loadingSpinner/LoadingSpinner.js +3 -3
  69. package/lib/module/components/modules/ModuleIDP.js +8 -52
  70. package/lib/module/components/modules/ModuleIDP.js.map +1 -1
  71. package/lib/module/components/modules/ModulePaymentNotice.js +17 -54
  72. package/lib/module/components/modules/ModulePaymentNotice.js.map +1 -1
  73. package/lib/module/components/modules/PressableModuleBase.js +34 -0
  74. package/lib/module/components/modules/PressableModuleBase.js.map +1 -0
  75. package/lib/module/components/modules/hooks/useModuleSpringAnimation.js +34 -0
  76. package/lib/module/components/modules/hooks/useModuleSpringAnimation.js.map +1 -0
  77. package/lib/module/components/modules/index.js +1 -0
  78. package/lib/module/components/modules/index.js.map +1 -1
  79. package/lib/module/components/switch/NativeSwitch.js +5 -3
  80. package/lib/module/components/switch/NativeSwitch.js.map +1 -1
  81. package/lib/module/components/textInput/TextInputBase.js +6 -5
  82. package/lib/module/components/textInput/TextInputBase.js.map +1 -1
  83. package/lib/module/core/IOColors.js +1 -0
  84. package/lib/module/core/IOColors.js.map +1 -1
  85. package/lib/module/core/IOStyles.js +15 -0
  86. package/lib/module/core/IOStyles.js.map +1 -1
  87. package/lib/module/stories/ModuleIDP.stories.js +37 -0
  88. package/lib/module/stories/ModuleIDP.stories.js.map +1 -0
  89. package/lib/module/utils/textInput/index.js +2 -1
  90. package/lib/module/utils/textInput/index.js.map +1 -1
  91. package/lib/typescript/components/avatar/Avatar.d.ts +2 -2
  92. package/lib/typescript/components/avatar/Avatar.d.ts.map +1 -1
  93. package/lib/typescript/components/avatar/index.d.ts +0 -1
  94. package/lib/typescript/components/avatar/index.d.ts.map +1 -1
  95. package/lib/typescript/components/badge/Badge.d.ts +2 -1
  96. package/lib/typescript/components/badge/Badge.d.ts.map +1 -1
  97. package/lib/typescript/components/banner/Banner.d.ts.map +1 -1
  98. package/lib/typescript/components/listitems/ListItemNav.d.ts +14 -3
  99. package/lib/typescript/components/listitems/ListItemNav.d.ts.map +1 -1
  100. package/lib/typescript/components/listitems/ListItemSwitch.d.ts.map +1 -1
  101. package/lib/typescript/components/modules/ModuleIDP.d.ts +5 -7
  102. package/lib/typescript/components/modules/ModuleIDP.d.ts.map +1 -1
  103. package/lib/typescript/components/modules/ModulePaymentNotice.d.ts +1 -1
  104. package/lib/typescript/components/modules/ModulePaymentNotice.d.ts.map +1 -1
  105. package/lib/typescript/components/modules/PressableModuleBase.d.ts +10 -0
  106. package/lib/typescript/components/modules/PressableModuleBase.d.ts.map +1 -0
  107. package/lib/typescript/components/modules/hooks/useModuleSpringAnimation.d.ts +10 -0
  108. package/lib/typescript/components/modules/hooks/useModuleSpringAnimation.d.ts.map +1 -0
  109. package/lib/typescript/components/modules/index.d.ts +1 -0
  110. package/lib/typescript/components/modules/index.d.ts.map +1 -1
  111. package/lib/typescript/components/switch/NativeSwitch.d.ts +2 -2
  112. package/lib/typescript/components/switch/NativeSwitch.d.ts.map +1 -1
  113. package/lib/typescript/components/textInput/TextInputBase.d.ts +5 -5
  114. package/lib/typescript/components/textInput/TextInputBase.d.ts.map +1 -1
  115. package/lib/typescript/core/IOColors.d.ts +1 -0
  116. package/lib/typescript/core/IOColors.d.ts.map +1 -1
  117. package/lib/typescript/core/IOStyles.d.ts +13 -0
  118. package/lib/typescript/core/IOStyles.d.ts.map +1 -1
  119. package/lib/typescript/stories/ModuleIDP.stories.d.ts +24 -0
  120. package/lib/typescript/stories/ModuleIDP.stories.d.ts.map +1 -0
  121. package/lib/typescript/utils/textInput/index.d.ts.map +1 -1
  122. package/package.json +2 -2
  123. package/src/components/avatar/Avatar.tsx +63 -24
  124. package/src/components/avatar/__test__/__snapshots__/avatar.test.tsx.snap +17 -4
  125. package/src/components/avatar/__test__/avatar.test.tsx +1 -8
  126. package/src/components/avatar/index.tsx +0 -1
  127. package/src/components/badge/Badge.tsx +63 -7
  128. package/src/components/banner/Banner.tsx +9 -6
  129. package/src/components/banner/__test__/__snapshots__/banner.test.tsx.snap +3 -2
  130. package/src/components/icons/svg/IconInstitution.tsx +2 -2
  131. package/src/components/icons/svg/originals/IconInstitution.svg +2 -7
  132. package/src/components/listitems/ListItemNav.tsx +19 -5
  133. package/src/components/listitems/ListItemSwitch.tsx +37 -12
  134. package/src/components/listitems/ListItemTransaction.tsx +1 -1
  135. package/src/components/listitems/__test__/__snapshots__/listitem.test.tsx.snap +1 -1
  136. package/src/components/loadingSpinner/LoadingSpinner.tsx +3 -3
  137. package/src/components/modules/ModuleIDP.tsx +16 -86
  138. package/src/components/modules/ModulePaymentNotice.tsx +14 -77
  139. package/src/components/modules/PressableModuleBase.tsx +45 -0
  140. package/src/components/modules/hooks/useModuleSpringAnimation.ts +49 -0
  141. package/src/components/modules/index.tsx +1 -0
  142. package/src/components/switch/NativeSwitch.tsx +10 -2
  143. package/src/components/textInput/TextInputBase.tsx +16 -9
  144. package/src/core/IOColors.ts +2 -0
  145. package/src/core/IOStyles.ts +22 -1
  146. package/src/stories/ModuleIDP.stories.tsx +44 -0
  147. package/src/utils/textInput/index.ts +2 -1
  148. package/lib/commonjs/components/avatar/MultiImage.js +0 -47
  149. package/lib/commonjs/components/avatar/MultiImage.js.map +0 -1
  150. package/lib/module/components/avatar/MultiImage.js +0 -39
  151. package/lib/module/components/avatar/MultiImage.js.map +0 -1
  152. package/lib/typescript/components/avatar/MultiImage.d.ts +0 -22
  153. package/lib/typescript/components/avatar/MultiImage.d.ts.map +0 -1
  154. package/src/components/avatar/MultiImage.tsx +0 -57
@@ -0,0 +1,49 @@
1
+ import {
2
+ Extrapolate,
3
+ interpolate,
4
+ useAnimatedStyle,
5
+ useDerivedValue,
6
+ useSharedValue,
7
+ withSpring
8
+ } from "react-native-reanimated";
9
+ import { useCallback } from "react";
10
+ import { IOScaleValues, IOSpringValues } from "../../../core";
11
+
12
+ export const useModuleSpringAnimation = () => {
13
+ const isPressed = useSharedValue(0);
14
+ // Scaling transformation applied when the button is pressed
15
+ const animationScaleValue = IOScaleValues?.magnifiedButton?.pressedState;
16
+
17
+ const scaleTraversed = useDerivedValue(() =>
18
+ withSpring(isPressed.value, IOSpringValues.button)
19
+ );
20
+
21
+ // Interpolate animation values from `isPressed` values
22
+ const animatedStyle = useAnimatedStyle(() => {
23
+ const scale = interpolate(
24
+ scaleTraversed.value,
25
+ [0, 1],
26
+ [1, animationScaleValue],
27
+ Extrapolate.CLAMP
28
+ );
29
+
30
+ return {
31
+ transform: [{ scale }]
32
+ };
33
+ });
34
+
35
+ const handlePressIn = useCallback(() => {
36
+ // eslint-disable-next-line functional/immutable-data
37
+ isPressed.value = 1;
38
+ }, [isPressed]);
39
+ const handlePressOut = useCallback(() => {
40
+ // eslint-disable-next-line functional/immutable-data
41
+ isPressed.value = 0;
42
+ }, [isPressed]);
43
+
44
+ return {
45
+ animatedStyle,
46
+ handlePressIn,
47
+ handlePressOut
48
+ };
49
+ };
@@ -1,2 +1,3 @@
1
1
  export * from "./ModuleIDP";
2
2
  export * from "./ModulePaymentNotice";
3
+ export * from "./PressableModuleBase";
@@ -4,13 +4,20 @@ import { useIOExperimentalDesign } from "../../core";
4
4
  import { IOColors } from "../../core/IOColors";
5
5
  import { IOSwitchVisualParams } from "../../core/IOStyles";
6
6
 
7
- type OwnProps = Pick<SwitchProps, "onValueChange" | "value">;
7
+ type OwnProps = Pick<
8
+ SwitchProps,
9
+ "onValueChange" | "value" | "accessible" | "accessibilityLabel"
10
+ >;
8
11
 
9
12
  // TODO: Remove this when legacy look is deprecated https://pagopa.atlassian.net/browse/IOPLT-153
10
13
  const bgLegacyTrackColorAndroid =
11
14
  Platform.OS === "android" ? IOColors["grey-300"] : IOColors.greyUltraLight;
12
15
 
13
- export const NativeSwitch = ({ onValueChange, value }: OwnProps) => {
16
+ export const NativeSwitch = ({
17
+ onValueChange,
18
+ value,
19
+ ...accessibility
20
+ }: OwnProps) => {
14
21
  const { isExperimental } = useIOExperimentalDesign();
15
22
  const trackColor = {
16
23
  false: IOColors[IOSwitchVisualParams.bgColorOffState],
@@ -27,6 +34,7 @@ export const NativeSwitch = ({ onValueChange, value }: OwnProps) => {
27
34
 
28
35
  return (
29
36
  <Switch
37
+ {...accessibility}
30
38
  trackColor={trackColorComponent}
31
39
  thumbColor={IOColors[IOSwitchVisualParams.bgCircle]}
32
40
  ios_backgroundColor={
@@ -1,4 +1,5 @@
1
1
  /* eslint-disable functional/immutable-data */
2
+ import React, { useCallback, useEffect, useMemo, useRef } from "react";
2
3
  import {
3
4
  Pressable,
4
5
  StyleSheet,
@@ -6,7 +7,6 @@ import {
6
7
  View,
7
8
  ViewStyle
8
9
  } from "react-native";
9
- import React, { useCallback, useEffect, useMemo, useRef } from "react";
10
10
  import Animated, {
11
11
  Easing,
12
12
  useAnimatedStyle,
@@ -19,18 +19,24 @@ import {
19
19
  IOStyles,
20
20
  useIOExperimentalDesign
21
21
  } from "../../core";
22
+ import { makeFontStyleObject } from "../../utils/fonts";
23
+ import { getInputPropsByType } from "../../utils/textInput";
24
+ import { InputType } from "../../utils/types";
22
25
  import { IOIcons, Icon } from "../icons";
23
26
  import { HSpacer } from "../spacer";
24
27
  import { LabelSmall } from "../typography";
25
- import { InputType } from "../../utils/types";
26
- import { getInputPropsByType } from "../../utils/textInput";
27
- import { makeFontStyleObject } from "../../utils/fonts";
28
28
 
29
29
  type InputStatus = "initial" | "focused" | "disabled" | "error";
30
30
 
31
31
  type RNTextInputProps = Pick<
32
32
  React.ComponentProps<typeof TextInput>,
33
- "keyboardType" | "inputMode" | "textContentType" | "autoComplete"
33
+ | "keyboardType"
34
+ | "inputMode"
35
+ | "textContentType"
36
+ | "autoComplete"
37
+ | "returnKeyType"
38
+ | "autoCapitalize"
39
+ | "autoCorrect"
34
40
  >;
35
41
 
36
42
  type InputTextProps = {
@@ -39,7 +45,7 @@ type InputTextProps = {
39
45
  onChangeText: (value: string) => void;
40
46
  accessibilityLabel?: string;
41
47
  textInputProps?: RNTextInputProps;
42
- inputTyoe?: InputType;
48
+ inputType?: InputType;
43
49
  status?: InputStatus;
44
50
  icon?: IOIcons;
45
51
  rightElement?: React.ReactNode;
@@ -152,7 +158,7 @@ export const TextInputBase = ({
152
158
  onChangeText,
153
159
  accessibilityLabel,
154
160
  textInputProps,
155
- inputTyoe = "default",
161
+ inputType = "default",
156
162
  status,
157
163
  icon,
158
164
  rightElement,
@@ -248,8 +254,8 @@ export const TextInputBase = ({
248
254
  }, [value, labelSharedValue, onBlur]);
249
255
 
250
256
  const derivedInputProps = useMemo(
251
- () => getInputPropsByType(inputTyoe),
252
- [inputTyoe]
257
+ () => getInputPropsByType(inputType),
258
+ [inputType]
253
259
  );
254
260
 
255
261
  const inputValue = useMemo(
@@ -319,6 +325,7 @@ export const TextInputBase = ({
319
325
  style={[
320
326
  animatedLabelProps,
321
327
  {
328
+ ...makeFontStyleObject("Regular", false, "TitilliumWeb"),
322
329
  color: IOColors["grey-700"]
323
330
  }
324
331
  ]}
@@ -285,6 +285,7 @@ export type IOTheme = {
285
285
  // Design System related
286
286
  "cardBorder-default": IOColors;
287
287
  "icon-default": IOColors;
288
+ "icon-decorative": IOColors;
288
289
  // Layout
289
290
  "divider-default": IOColors;
290
291
  // Status
@@ -312,6 +313,7 @@ export const IOThemeLight: IOTheme = {
312
313
  // Design System related
313
314
  "cardBorder-default": "grey-100",
314
315
  "icon-default": "grey-650",
316
+ "icon-decorative": "grey-300",
315
317
  // Layout
316
318
  "divider-default": "grey-200",
317
319
  // Status
@@ -1,7 +1,14 @@
1
1
  import { Platform, StyleSheet } from "react-native";
2
2
  import { IOIconSizeScale } from "../components/icons";
3
3
  import { IOColors } from "./IOColors";
4
- import { IOAppMargin, IOSpacer, IOSpacingScale } from "./IOSpacing";
4
+ import {
5
+ IOAppMargin,
6
+ IOModuleIDPHSpacing,
7
+ IOModuleIDPVSpacing,
8
+ IOSpacer,
9
+ IOSpacingScale
10
+ } from "./IOSpacing";
11
+ import { IOModuleIDPRadius } from "./IOShapes";
5
12
 
6
13
  /**
7
14
  * A collection of default styles used within IO App.
@@ -254,6 +261,20 @@ export const IOListItemStyles = StyleSheet.create({
254
261
  }
255
262
  });
256
263
 
264
+ export const IOModuleStyles = StyleSheet.create({
265
+ button: {
266
+ borderWidth: 1,
267
+ borderColor: IOColors["grey-100"],
268
+ borderRadius: IOModuleIDPRadius,
269
+ backgroundColor: IOColors.white,
270
+ flexDirection: "row",
271
+ justifyContent: "space-between",
272
+ alignItems: "center",
273
+ paddingVertical: IOModuleIDPVSpacing,
274
+ paddingHorizontal: IOModuleIDPHSpacing
275
+ }
276
+ });
277
+
257
278
  /**
258
279
  * SELECTION ITEM STYLES
259
280
  */
@@ -0,0 +1,44 @@
1
+ import type { Meta, StoryObj } from "@storybook/react";
2
+ import React from "react";
3
+ import { action } from "@storybook/addon-actions";
4
+
5
+ import { ImageSourcePropType } from "react-native";
6
+ import { ModuleIDP } from "../components";
7
+ import { IOThemeContext, IOThemes } from "..";
8
+
9
+ // More on how to set up stories at: https://storybook.js.org/docs/react/writing-stories/introduction#default-export
10
+ const meta = {
11
+ title: "Example/ModuleIDP",
12
+ component: ModuleIDP,
13
+ decorators: [
14
+ Story => (
15
+ <IOThemeContext.Provider value={IOThemes.dark}>
16
+ <div style={{ width: "300px" }}>
17
+ <Story />
18
+ </div>
19
+ </IOThemeContext.Provider>
20
+ )
21
+ ],
22
+ parameters: {
23
+ // Optional parameter to center the component in the Canvas. More info: https://storybook.js.org/docs/react/configure/story-layout
24
+ layout: "centered"
25
+ },
26
+ // This component will have an automatically generated Autodocs entry: https://storybook.js.org/docs/react/writing-docs/autodocs
27
+ tags: ["autodocs"]
28
+ } satisfies Meta<typeof ModuleIDP>;
29
+
30
+ export default meta;
31
+ type Story = StoryObj<typeof meta>;
32
+
33
+ // More on writing stories with args: https://storybook.js.org/docs/react/writing-stories/args
34
+ export const Primary: Story = {
35
+ args: {
36
+ logo: "https://assets.cdn.io.italia.it/spid/idps/spid-idp-posteid.png" as ImageSourcePropType,
37
+ name: "POSTE ID",
38
+ accessibilityLabel: "Tap to trigger test alert",
39
+ localLogo: 0,
40
+ onPress: e => {
41
+ action("clicked")(e);
42
+ }
43
+ }
44
+ };
@@ -20,7 +20,8 @@ export const getInputPropsByType = (
20
20
  autoComplete: "cc-number",
21
21
  keyboardType: "numeric",
22
22
  textContentType: "creditCardNumber",
23
- inputMode: "numeric"
23
+ inputMode: "numeric",
24
+ returnKeyType: "done"
24
25
  }
25
26
  };
26
27
  default:
@@ -1,47 +0,0 @@
1
- "use strict";
2
-
3
- Object.defineProperty(exports, "__esModule", {
4
- value: true
5
- });
6
- exports.MultiImage = void 0;
7
- var _react = _interopRequireDefault(require("react"));
8
- var _reactNative = require("react-native");
9
- var _image = require("../../utils/image");
10
- function _interopRequireDefault(obj) { return obj && obj.__esModule ? obj : { default: obj }; }
11
- function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
12
- /**
13
- * An image component that attempts to load the provided images
14
- * until one is available.
15
- *
16
- * Usually you want to provide a local image as last one to make sure
17
- * there is always an image that can be displayed.
18
- */
19
- class MultiImage extends _react.default.PureComponent {
20
- constructor(props) {
21
- super(props);
22
- this.state = {
23
- // start by rendering the first image
24
- sourceIndex: props.source.length > 0 ? 0 : undefined
25
- };
26
- }
27
- render() {
28
- const sourceIndex = this.state.sourceIndex;
29
- if (sourceIndex === undefined) {
30
- return null;
31
- }
32
- const atIndex = this.props.source[sourceIndex];
33
- const source = typeof atIndex === "number" ? atIndex : (0, _image.addCacheTimestampToUri)(atIndex);
34
- const onError = () => {
35
- // if current image fails loading, move to next
36
- this.setState((_, props) => ({
37
- sourceIndex: sourceIndex < props.source.length ? sourceIndex + 1 : undefined
38
- }));
39
- };
40
- return source && /*#__PURE__*/_react.default.createElement(_reactNative.Image, _extends({}, this.props, {
41
- source: source,
42
- onError: onError
43
- }));
44
- }
45
- }
46
- exports.MultiImage = MultiImage;
47
- //# sourceMappingURL=MultiImage.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["_react","_interopRequireDefault","require","_reactNative","_image","obj","__esModule","default","_extends","Object","assign","bind","target","i","arguments","length","source","key","prototype","hasOwnProperty","call","apply","MultiImage","React","PureComponent","constructor","props","state","sourceIndex","undefined","render","atIndex","addCacheTimestampToUri","onError","setState","_","createElement","Image","exports"],"sourceRoot":"../../../../src","sources":["components/avatar/MultiImage.tsx"],"mappings":";;;;;;AACA,IAAAA,MAAA,GAAAC,sBAAA,CAAAC,OAAA;AACA,IAAAC,YAAA,GAAAD,OAAA;AAMA,IAAAE,MAAA,GAAAF,OAAA;AAA2D,SAAAD,uBAAAI,GAAA,WAAAA,GAAA,IAAAA,GAAA,CAAAC,UAAA,GAAAD,GAAA,KAAAE,OAAA,EAAAF,GAAA;AAAA,SAAAG,SAAA,IAAAA,QAAA,GAAAC,MAAA,CAAAC,MAAA,GAAAD,MAAA,CAAAC,MAAA,CAAAC,IAAA,eAAAC,MAAA,aAAAC,CAAA,MAAAA,CAAA,GAAAC,SAAA,CAAAC,MAAA,EAAAF,CAAA,UAAAG,MAAA,GAAAF,SAAA,CAAAD,CAAA,YAAAI,GAAA,IAAAD,MAAA,QAAAP,MAAA,CAAAS,SAAA,CAAAC,cAAA,CAAAC,IAAA,CAAAJ,MAAA,EAAAC,GAAA,KAAAL,MAAA,CAAAK,GAAA,IAAAD,MAAA,CAAAC,GAAA,gBAAAL,MAAA,YAAAJ,QAAA,CAAAa,KAAA,OAAAP,SAAA;AAU3D;AACA;AACA;AACA;AACA;AACA;AACA;AACO,MAAMQ,UAAU,SAASC,cAAK,CAACC,aAAa,CAAe;EAChEC,WAAWA,CAACC,KAAY,EAAE;IACxB,KAAK,CAACA,KAAK,CAAC;IACZ,IAAI,CAACC,KAAK,GAAG;MACX;MACAC,WAAW,EAAEF,KAAK,CAACV,MAAM,CAACD,MAAM,GAAG,CAAC,GAAG,CAAC,GAAGc;IAC7C,CAAC;EACH;EAEOC,MAAMA,CAAA,EAAG;IACd,MAAMF,WAAW,GAAG,IAAI,CAACD,KAAK,CAACC,WAAW;IAC1C,IAAIA,WAAW,KAAKC,SAAS,EAAE;MAC7B,OAAO,IAAI;IACb;IAEA,MAAME,OAAO,GAAG,IAAI,CAACL,KAAK,CAACV,MAAM,CAACY,WAAW,CAAC;IAE9C,MAAMZ,MAAM,GACV,OAAOe,OAAO,KAAK,QAAQ,GAAGA,OAAO,GAAG,IAAAC,6BAAsB,EAACD,OAAO,CAAC;IAEzE,MAAME,OAAO,GAAGA,CAAA,KAAM;MACpB;MACA,IAAI,CAACC,QAAQ,CAAC,CAACC,CAAC,EAAET,KAAK,MAAM;QAC3BE,WAAW,EACTA,WAAW,GAAGF,KAAK,CAACV,MAAM,CAACD,MAAM,GAAGa,WAAW,GAAG,CAAC,GAAGC;MAC1D,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OACEb,MAAM,iBAAIhB,MAAA,CAAAO,OAAA,CAAA6B,aAAA,CAACjC,YAAA,CAAAkC,KAAK,EAAA7B,QAAA,KAAK,IAAI,CAACkB,KAAK;MAAEV,MAAM,EAAEA,MAAO;MAACiB,OAAO,EAAEA;IAAQ,EAAE,CAAC;EAEzE;AACF;AAACK,OAAA,CAAAhB,UAAA,GAAAA,UAAA"}
@@ -1,39 +0,0 @@
1
- function _extends() { _extends = Object.assign ? Object.assign.bind() : function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
2
- import React from "react";
3
- import { Image } from "react-native";
4
- import { addCacheTimestampToUri } from "../../utils/image";
5
- /**
6
- * An image component that attempts to load the provided images
7
- * until one is available.
8
- *
9
- * Usually you want to provide a local image as last one to make sure
10
- * there is always an image that can be displayed.
11
- */
12
- export class MultiImage extends React.PureComponent {
13
- constructor(props) {
14
- super(props);
15
- this.state = {
16
- // start by rendering the first image
17
- sourceIndex: props.source.length > 0 ? 0 : undefined
18
- };
19
- }
20
- render() {
21
- const sourceIndex = this.state.sourceIndex;
22
- if (sourceIndex === undefined) {
23
- return null;
24
- }
25
- const atIndex = this.props.source[sourceIndex];
26
- const source = typeof atIndex === "number" ? atIndex : addCacheTimestampToUri(atIndex);
27
- const onError = () => {
28
- // if current image fails loading, move to next
29
- this.setState((_, props) => ({
30
- sourceIndex: sourceIndex < props.source.length ? sourceIndex + 1 : undefined
31
- }));
32
- };
33
- return source && /*#__PURE__*/React.createElement(Image, _extends({}, this.props, {
34
- source: source,
35
- onError: onError
36
- }));
37
- }
38
- }
39
- //# sourceMappingURL=MultiImage.js.map
@@ -1 +0,0 @@
1
- {"version":3,"names":["React","Image","addCacheTimestampToUri","MultiImage","PureComponent","constructor","props","state","sourceIndex","source","length","undefined","render","atIndex","onError","setState","_","createElement","_extends"],"sourceRoot":"../../../../src","sources":["components/avatar/MultiImage.tsx"],"mappings":";AACA,OAAOA,KAAK,MAAM,OAAO;AACzB,SACEC,KAAK,QAIA,cAAc;AACrB,SAASC,sBAAsB,QAAQ,mBAAmB;AAU1D;AACA;AACA;AACA;AACA;AACA;AACA;AACA,OAAO,MAAMC,UAAU,SAASH,KAAK,CAACI,aAAa,CAAe;EAChEC,WAAWA,CAACC,KAAY,EAAE;IACxB,KAAK,CAACA,KAAK,CAAC;IACZ,IAAI,CAACC,KAAK,GAAG;MACX;MACAC,WAAW,EAAEF,KAAK,CAACG,MAAM,CAACC,MAAM,GAAG,CAAC,GAAG,CAAC,GAAGC;IAC7C,CAAC;EACH;EAEOC,MAAMA,CAAA,EAAG;IACd,MAAMJ,WAAW,GAAG,IAAI,CAACD,KAAK,CAACC,WAAW;IAC1C,IAAIA,WAAW,KAAKG,SAAS,EAAE;MAC7B,OAAO,IAAI;IACb;IAEA,MAAME,OAAO,GAAG,IAAI,CAACP,KAAK,CAACG,MAAM,CAACD,WAAW,CAAC;IAE9C,MAAMC,MAAM,GACV,OAAOI,OAAO,KAAK,QAAQ,GAAGA,OAAO,GAAGX,sBAAsB,CAACW,OAAO,CAAC;IAEzE,MAAMC,OAAO,GAAGA,CAAA,KAAM;MACpB;MACA,IAAI,CAACC,QAAQ,CAAC,CAACC,CAAC,EAAEV,KAAK,MAAM;QAC3BE,WAAW,EACTA,WAAW,GAAGF,KAAK,CAACG,MAAM,CAACC,MAAM,GAAGF,WAAW,GAAG,CAAC,GAAGG;MAC1D,CAAC,CAAC,CAAC;IACL,CAAC;IACD,OACEF,MAAM,iBAAIT,KAAA,CAAAiB,aAAA,CAAChB,KAAK,EAAAiB,QAAA,KAAK,IAAI,CAACZ,KAAK;MAAEG,MAAM,EAAEA,MAAO;MAACK,OAAO,EAAEA;IAAQ,EAAE,CAAC;EAEzE;AACF"}
@@ -1,22 +0,0 @@
1
- import { Omit } from "@pagopa/ts-commons/lib/types";
2
- import React from "react";
3
- import { ImageProps, ImageRequireSource, ImageURISource } from "react-native";
4
- interface Props extends Omit<ImageProps, "source"> {
5
- source: ReadonlyArray<ImageURISource | ImageRequireSource>;
6
- }
7
- type State = Readonly<{
8
- sourceIndex?: number;
9
- }>;
10
- /**
11
- * An image component that attempts to load the provided images
12
- * until one is available.
13
- *
14
- * Usually you want to provide a local image as last one to make sure
15
- * there is always an image that can be displayed.
16
- */
17
- export declare class MultiImage extends React.PureComponent<Props, State> {
18
- constructor(props: Props);
19
- render(): 0 | React.JSX.Element | null;
20
- }
21
- export {};
22
- //# sourceMappingURL=MultiImage.d.ts.map
@@ -1 +0,0 @@
1
- {"version":3,"file":"MultiImage.d.ts","sourceRoot":"","sources":["../../../../src/components/avatar/MultiImage.tsx"],"names":[],"mappings":"AAAA,OAAO,EAAE,IAAI,EAAE,MAAM,8BAA8B,CAAC;AACpD,OAAO,KAAK,MAAM,OAAO,CAAC;AAC1B,OAAO,EAEL,UAAU,EACV,kBAAkB,EAClB,cAAc,EACf,MAAM,cAAc,CAAC;AAGtB,UAAU,KAAM,SAAQ,IAAI,CAAC,UAAU,EAAE,QAAQ,CAAC;IAChD,MAAM,EAAE,aAAa,CAAC,cAAc,GAAG,kBAAkB,CAAC,CAAC;CAC5D;AAED,KAAK,KAAK,GAAG,QAAQ,CAAC;IACpB,WAAW,CAAC,EAAE,MAAM,CAAC;CACtB,CAAC,CAAC;AAEH;;;;;;GAMG;AACH,qBAAa,UAAW,SAAQ,KAAK,CAAC,aAAa,CAAC,KAAK,EAAE,KAAK,CAAC;gBACnD,KAAK,EAAE,KAAK;IAQjB,MAAM;CAsBd"}
@@ -1,57 +0,0 @@
1
- import { Omit } from "@pagopa/ts-commons/lib/types";
2
- import React from "react";
3
- import {
4
- Image,
5
- ImageProps,
6
- ImageRequireSource,
7
- ImageURISource
8
- } from "react-native";
9
- import { addCacheTimestampToUri } from "../../utils/image";
10
-
11
- interface Props extends Omit<ImageProps, "source"> {
12
- source: ReadonlyArray<ImageURISource | ImageRequireSource>;
13
- }
14
-
15
- type State = Readonly<{
16
- sourceIndex?: number;
17
- }>;
18
-
19
- /**
20
- * An image component that attempts to load the provided images
21
- * until one is available.
22
- *
23
- * Usually you want to provide a local image as last one to make sure
24
- * there is always an image that can be displayed.
25
- */
26
- export class MultiImage extends React.PureComponent<Props, State> {
27
- constructor(props: Props) {
28
- super(props);
29
- this.state = {
30
- // start by rendering the first image
31
- sourceIndex: props.source.length > 0 ? 0 : undefined
32
- };
33
- }
34
-
35
- public render() {
36
- const sourceIndex = this.state.sourceIndex;
37
- if (sourceIndex === undefined) {
38
- return null;
39
- }
40
-
41
- const atIndex = this.props.source[sourceIndex];
42
-
43
- const source =
44
- typeof atIndex === "number" ? atIndex : addCacheTimestampToUri(atIndex);
45
-
46
- const onError = () => {
47
- // if current image fails loading, move to next
48
- this.setState((_, props) => ({
49
- sourceIndex:
50
- sourceIndex < props.source.length ? sourceIndex + 1 : undefined
51
- }));
52
- };
53
- return (
54
- source && <Image {...this.props} source={source} onError={onError} />
55
- );
56
- }
57
- }