@pagopa/io-app-design-system 1.14.0 → 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 (114) 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/icons/svg/IconInstitution.js +3 -3
  11. package/lib/commonjs/components/icons/svg/IconInstitution.js.map +1 -1
  12. package/lib/commonjs/components/icons/svg/originals/IconInstitution.svg +2 -7
  13. package/lib/commonjs/components/listitems/ListItemTransaction.js +1 -1
  14. package/lib/commonjs/components/listitems/ListItemTransaction.js.map +1 -1
  15. package/lib/commonjs/components/listitems/__test__/__snapshots__/listitem.test.tsx.snap +1 -1
  16. package/lib/commonjs/components/modules/ModuleIDP.js +6 -49
  17. package/lib/commonjs/components/modules/ModuleIDP.js.map +1 -1
  18. package/lib/commonjs/components/modules/ModulePaymentNotice.js +15 -51
  19. package/lib/commonjs/components/modules/ModulePaymentNotice.js.map +1 -1
  20. package/lib/commonjs/components/modules/PressableModuleBase.js +44 -0
  21. package/lib/commonjs/components/modules/PressableModuleBase.js.map +1 -0
  22. package/lib/commonjs/components/modules/hooks/useModuleSpringAnimation.js +41 -0
  23. package/lib/commonjs/components/modules/hooks/useModuleSpringAnimation.js.map +1 -0
  24. package/lib/commonjs/components/modules/index.js +11 -0
  25. package/lib/commonjs/components/modules/index.js.map +1 -1
  26. package/lib/commonjs/components/textInput/TextInputBase.js.map +1 -1
  27. package/lib/commonjs/core/IOColors.js +1 -0
  28. package/lib/commonjs/core/IOColors.js.map +1 -1
  29. package/lib/commonjs/core/IOStyles.js +18 -2
  30. package/lib/commonjs/core/IOStyles.js.map +1 -1
  31. package/lib/commonjs/stories/ModuleIDP.stories.js +45 -0
  32. package/lib/commonjs/stories/ModuleIDP.stories.js.map +1 -0
  33. package/lib/module/components/avatar/Avatar.js +24 -8
  34. package/lib/module/components/avatar/Avatar.js.map +1 -1
  35. package/lib/module/components/avatar/__test__/__snapshots__/avatar.test.tsx.snap +17 -4
  36. package/lib/module/components/avatar/__test__/avatar.test.js +3 -8
  37. package/lib/module/components/avatar/__test__/avatar.test.js.map +1 -1
  38. package/lib/module/components/avatar/index.js +0 -1
  39. package/lib/module/components/avatar/index.js.map +1 -1
  40. package/lib/module/components/badge/Badge.js +44 -4
  41. package/lib/module/components/badge/Badge.js.map +1 -1
  42. package/lib/module/components/icons/svg/IconInstitution.js +3 -3
  43. package/lib/module/components/icons/svg/IconInstitution.js.map +1 -1
  44. package/lib/module/components/icons/svg/originals/IconInstitution.svg +2 -7
  45. package/lib/module/components/listitems/ListItemTransaction.js +1 -1
  46. package/lib/module/components/listitems/ListItemTransaction.js.map +1 -1
  47. package/lib/module/components/listitems/__test__/__snapshots__/listitem.test.tsx.snap +1 -1
  48. package/lib/module/components/modules/ModuleIDP.js +8 -52
  49. package/lib/module/components/modules/ModuleIDP.js.map +1 -1
  50. package/lib/module/components/modules/ModulePaymentNotice.js +17 -54
  51. package/lib/module/components/modules/ModulePaymentNotice.js.map +1 -1
  52. package/lib/module/components/modules/PressableModuleBase.js +34 -0
  53. package/lib/module/components/modules/PressableModuleBase.js.map +1 -0
  54. package/lib/module/components/modules/hooks/useModuleSpringAnimation.js +34 -0
  55. package/lib/module/components/modules/hooks/useModuleSpringAnimation.js.map +1 -0
  56. package/lib/module/components/modules/index.js +1 -0
  57. package/lib/module/components/modules/index.js.map +1 -1
  58. package/lib/module/components/textInput/TextInputBase.js.map +1 -1
  59. package/lib/module/core/IOColors.js +1 -0
  60. package/lib/module/core/IOColors.js.map +1 -1
  61. package/lib/module/core/IOStyles.js +15 -0
  62. package/lib/module/core/IOStyles.js.map +1 -1
  63. package/lib/module/stories/ModuleIDP.stories.js +37 -0
  64. package/lib/module/stories/ModuleIDP.stories.js.map +1 -0
  65. package/lib/typescript/components/avatar/Avatar.d.ts +2 -2
  66. package/lib/typescript/components/avatar/Avatar.d.ts.map +1 -1
  67. package/lib/typescript/components/avatar/index.d.ts +0 -1
  68. package/lib/typescript/components/avatar/index.d.ts.map +1 -1
  69. package/lib/typescript/components/badge/Badge.d.ts +2 -1
  70. package/lib/typescript/components/badge/Badge.d.ts.map +1 -1
  71. package/lib/typescript/components/modules/ModuleIDP.d.ts +5 -7
  72. package/lib/typescript/components/modules/ModuleIDP.d.ts.map +1 -1
  73. package/lib/typescript/components/modules/ModulePaymentNotice.d.ts +1 -1
  74. package/lib/typescript/components/modules/ModulePaymentNotice.d.ts.map +1 -1
  75. package/lib/typescript/components/modules/PressableModuleBase.d.ts +10 -0
  76. package/lib/typescript/components/modules/PressableModuleBase.d.ts.map +1 -0
  77. package/lib/typescript/components/modules/hooks/useModuleSpringAnimation.d.ts +10 -0
  78. package/lib/typescript/components/modules/hooks/useModuleSpringAnimation.d.ts.map +1 -0
  79. package/lib/typescript/components/modules/index.d.ts +1 -0
  80. package/lib/typescript/components/modules/index.d.ts.map +1 -1
  81. package/lib/typescript/components/textInput/TextInputBase.d.ts +1 -1
  82. package/lib/typescript/components/textInput/TextInputBase.d.ts.map +1 -1
  83. package/lib/typescript/core/IOColors.d.ts +1 -0
  84. package/lib/typescript/core/IOColors.d.ts.map +1 -1
  85. package/lib/typescript/core/IOStyles.d.ts +13 -0
  86. package/lib/typescript/core/IOStyles.d.ts.map +1 -1
  87. package/lib/typescript/stories/ModuleIDP.stories.d.ts +24 -0
  88. package/lib/typescript/stories/ModuleIDP.stories.d.ts.map +1 -0
  89. package/package.json +1 -1
  90. package/src/components/avatar/Avatar.tsx +63 -24
  91. package/src/components/avatar/__test__/__snapshots__/avatar.test.tsx.snap +17 -4
  92. package/src/components/avatar/__test__/avatar.test.tsx +1 -8
  93. package/src/components/avatar/index.tsx +0 -1
  94. package/src/components/badge/Badge.tsx +63 -7
  95. package/src/components/icons/svg/IconInstitution.tsx +2 -2
  96. package/src/components/icons/svg/originals/IconInstitution.svg +2 -7
  97. package/src/components/listitems/ListItemTransaction.tsx +1 -1
  98. package/src/components/listitems/__test__/__snapshots__/listitem.test.tsx.snap +1 -1
  99. package/src/components/modules/ModuleIDP.tsx +16 -86
  100. package/src/components/modules/ModulePaymentNotice.tsx +14 -77
  101. package/src/components/modules/PressableModuleBase.tsx +45 -0
  102. package/src/components/modules/hooks/useModuleSpringAnimation.ts +49 -0
  103. package/src/components/modules/index.tsx +1 -0
  104. package/src/components/textInput/TextInputBase.tsx +1 -0
  105. package/src/core/IOColors.ts +2 -0
  106. package/src/core/IOStyles.ts +22 -1
  107. package/src/stories/ModuleIDP.stories.tsx +44 -0
  108. package/lib/commonjs/components/avatar/MultiImage.js +0 -47
  109. package/lib/commonjs/components/avatar/MultiImage.js.map +0 -1
  110. package/lib/module/components/avatar/MultiImage.js +0 -39
  111. package/lib/module/components/avatar/MultiImage.js.map +0 -1
  112. package/lib/typescript/components/avatar/MultiImage.d.ts +0 -22
  113. package/lib/typescript/components/avatar/MultiImage.d.ts.map +0 -1
  114. package/src/components/avatar/MultiImage.tsx +0 -57
@@ -0,0 +1,45 @@
1
+ import * as React from "react";
2
+ import { GestureResponderEvent, Pressable } from "react-native";
3
+ import Animated from "react-native-reanimated";
4
+ import { IOModuleIDPSavedVSpacing, IOModuleStyles } from "../../core";
5
+ import { WithTestID } from "../../utils/types";
6
+ import { useModuleSpringAnimation } from "./hooks/useModuleSpringAnimation";
7
+
8
+ export type PressableModuleBaseProps = WithTestID<{
9
+ accessibilityLabel?: string;
10
+ onPress?: (event: GestureResponderEvent) => void;
11
+ withLooseSpacing?: boolean;
12
+ }>;
13
+
14
+ export const PressableModuleBase = ({
15
+ onPress,
16
+ testID,
17
+ accessibilityLabel,
18
+ withLooseSpacing = false,
19
+ children
20
+ }: React.PropsWithChildren<PressableModuleBaseProps>) => {
21
+ const { handlePressIn, handlePressOut, animatedStyle } =
22
+ useModuleSpringAnimation();
23
+ return (
24
+ <Pressable
25
+ onPress={onPress}
26
+ testID={testID}
27
+ accessible={true}
28
+ accessibilityLabel={accessibilityLabel}
29
+ onPressIn={handlePressIn}
30
+ onPressOut={handlePressOut}
31
+ onTouchEnd={handlePressOut}
32
+ accessibilityRole="button"
33
+ >
34
+ <Animated.View
35
+ style={[
36
+ IOModuleStyles.button,
37
+ withLooseSpacing && { paddingVertical: IOModuleIDPSavedVSpacing },
38
+ animatedStyle
39
+ ]}
40
+ >
41
+ {children}
42
+ </Animated.View>
43
+ </Pressable>
44
+ );
45
+ };
@@ -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";
@@ -36,6 +36,7 @@ type RNTextInputProps = Pick<
36
36
  | "autoComplete"
37
37
  | "returnKeyType"
38
38
  | "autoCapitalize"
39
+ | "autoCorrect"
39
40
  >;
40
41
 
41
42
  type InputTextProps = {
@@ -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
+ };
@@ -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
- }