@telefonica/mistica 11.7.0 → 11.10.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 (57) hide show
  1. package/dist/avatar.d.ts +14 -0
  2. package/dist/avatar.js +239 -0
  3. package/dist/avatar.js.flow +16 -0
  4. package/dist/badge.d.ts +2 -0
  5. package/dist/badge.js +24 -7
  6. package/dist/badge.js.flow +2 -0
  7. package/dist/button.js +35 -10
  8. package/dist/image.d.ts +2 -0
  9. package/dist/image.js +68 -5
  10. package/dist/image.js.flow +2 -0
  11. package/dist/index.d.ts +5 -2
  12. package/dist/index.js +29 -2
  13. package/dist/index.js.flow +5 -2
  14. package/dist/package-version.js +1 -1
  15. package/dist/password-field.js +9 -8
  16. package/dist/placeholder.d.ts +0 -4
  17. package/dist/placeholder.js +1 -13
  18. package/dist/placeholder.js.flow +0 -4
  19. package/dist/section-title.d.ts +3 -0
  20. package/dist/section-title.js +3 -1
  21. package/dist/section-title.js.flow +3 -0
  22. package/dist/text-link.js +17 -5
  23. package/dist/text.js +8 -2
  24. package/dist/theme-context-provider.js +13 -8
  25. package/dist/theme.d.ts +3 -0
  26. package/dist/theme.js.flow +3 -0
  27. package/dist/title.d.ts +13 -0
  28. package/dist/title.js +87 -0
  29. package/dist/title.js.flow +18 -0
  30. package/dist/utils/__tests__/analytics-test.js +74 -0
  31. package/dist/utils/analytics.d.ts +14 -0
  32. package/dist/utils/analytics.js +50 -1
  33. package/dist/utils/analytics.js.flow +14 -0
  34. package/dist-es/avatar.js +208 -0
  35. package/dist-es/badge.js +24 -7
  36. package/dist-es/button.js +36 -11
  37. package/dist-es/image.js +69 -5
  38. package/dist-es/index.js +4 -1
  39. package/dist-es/package-version.js +1 -1
  40. package/dist-es/password-field.js +9 -8
  41. package/dist-es/placeholder.js +0 -11
  42. package/dist-es/section-title.js +3 -1
  43. package/dist-es/text-link.js +18 -6
  44. package/dist-es/text.js +8 -2
  45. package/dist-es/theme-context-provider.js +13 -8
  46. package/dist-es/title.js +54 -0
  47. package/dist-es/utils/__tests__/analytics-test.js +47 -0
  48. package/dist-es/utils/analytics.js +27 -0
  49. package/package.json +3 -3
  50. package/dist/icons/icon-visibility-off.d.ts +0 -7
  51. package/dist/icons/icon-visibility-off.js +0 -49
  52. package/dist/icons/icon-visibility-off.js.flow +0 -9
  53. package/dist/icons/icon-visibility.d.ts +0 -7
  54. package/dist/icons/icon-visibility.js +0 -49
  55. package/dist/icons/icon-visibility.js.flow +0 -9
  56. package/dist-es/icons/icon-visibility-off.js +0 -22
  57. package/dist-es/icons/icon-visibility.js +0 -22
@@ -0,0 +1,14 @@
1
+ import * as React from 'react';
2
+ import type { IconProps } from './utils/types';
3
+ declare type AvatarProps = {
4
+ size: number;
5
+ src?: string;
6
+ initials?: string;
7
+ textColor?: string;
8
+ backgroundColor?: string;
9
+ Icon?: React.FC<IconProps>;
10
+ badge?: boolean | number;
11
+ 'aria-label'?: string;
12
+ };
13
+ declare const Avatar: ({ size, src, Icon, badge, initials, "aria-label": ariaLabel, ...props }: AvatarProps) => JSX.Element;
14
+ export default Avatar;
package/dist/avatar.js ADDED
@@ -0,0 +1,239 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ exports.default = void 0;
6
+ var _jsxRuntime = require("react/jsx-runtime");
7
+ var React = _interopRequireWildcard(require("react"));
8
+ var _badge = _interopRequireDefault(require("./badge"));
9
+ var _iconUserAccountRegular = _interopRequireDefault(require("./generated/mistica-icons/icon-user-account-regular"));
10
+ var _hooks = require("./hooks");
11
+ var _jss = require("./jss");
12
+ var _themeVariantContext = require("./theme-variant-context");
13
+ function _interopRequireDefault(obj) {
14
+ return obj && obj.__esModule ? obj : {
15
+ default: obj
16
+ };
17
+ }
18
+ function _interopRequireWildcard(obj) {
19
+ if (obj && obj.__esModule) {
20
+ return obj;
21
+ } else {
22
+ var newObj = {};
23
+ if (obj != null) {
24
+ for(var key in obj){
25
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
26
+ var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {};
27
+ if (desc.get || desc.set) {
28
+ Object.defineProperty(newObj, key, desc);
29
+ } else {
30
+ newObj[key] = obj[key];
31
+ }
32
+ }
33
+ }
34
+ }
35
+ newObj.default = obj;
36
+ return newObj;
37
+ }
38
+ }
39
+ function _arrayLikeToArray(arr, len) {
40
+ if (len == null || len > arr.length) len = arr.length;
41
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
42
+ return arr2;
43
+ }
44
+ function _arrayWithHoles(arr) {
45
+ if (Array.isArray(arr)) return arr;
46
+ }
47
+ function _iterableToArrayLimit(arr, i) {
48
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
49
+ if (_i == null) return;
50
+ var _arr = [];
51
+ var _n = true;
52
+ var _d = false;
53
+ var _s, _e;
54
+ try {
55
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
56
+ _arr.push(_s.value);
57
+ if (i && _arr.length === i) break;
58
+ }
59
+ } catch (err) {
60
+ _d = true;
61
+ _e = err;
62
+ } finally{
63
+ try {
64
+ if (!_n && _i["return"] != null) _i["return"]();
65
+ } finally{
66
+ if (_d) throw _e;
67
+ }
68
+ }
69
+ return _arr;
70
+ }
71
+ function _nonIterableRest() {
72
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
73
+ }
74
+ function _objectWithoutProperties(source, excluded) {
75
+ if (source == null) return {};
76
+ var target = _objectWithoutPropertiesLoose(source, excluded);
77
+ var key, i;
78
+ if (Object.getOwnPropertySymbols) {
79
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
80
+ for(i = 0; i < sourceSymbolKeys.length; i++){
81
+ key = sourceSymbolKeys[i];
82
+ if (excluded.indexOf(key) >= 0) continue;
83
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
84
+ target[key] = source[key];
85
+ }
86
+ }
87
+ return target;
88
+ }
89
+ function _objectWithoutPropertiesLoose(source, excluded) {
90
+ if (source == null) return {};
91
+ var target = {};
92
+ var sourceKeys = Object.keys(source);
93
+ var key, i;
94
+ for(i = 0; i < sourceKeys.length; i++){
95
+ key = sourceKeys[i];
96
+ if (excluded.indexOf(key) >= 0) continue;
97
+ target[key] = source[key];
98
+ }
99
+ return target;
100
+ }
101
+ function _slicedToArray(arr, i) {
102
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
103
+ }
104
+ function _unsupportedIterableToArray(o, minLen) {
105
+ if (!o) return;
106
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
107
+ var n = Object.prototype.toString.call(o).slice(8, -1);
108
+ if (n === "Object" && o.constructor) n = o.constructor.name;
109
+ if (n === "Map" || n === "Set") return Array.from(n);
110
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
111
+ }
112
+ var useStyles = (0, _jss).createUseStyles(function() {
113
+ return {
114
+ avatar: {
115
+ borderRadius: "50%",
116
+ display: "flex",
117
+ alignItems: "center",
118
+ justifyContent: "center",
119
+ color: function color(param) {
120
+ var textColor = param.textColor;
121
+ return textColor;
122
+ },
123
+ background: function background(param) {
124
+ var backgroundColor = param.backgroundColor;
125
+ return backgroundColor;
126
+ },
127
+ width: function width(param) {
128
+ var size = param.size;
129
+ return size;
130
+ },
131
+ height: function height(param) {
132
+ var size = param.size;
133
+ return size;
134
+ },
135
+ overflow: "hidden"
136
+ },
137
+ image: {
138
+ width: function width(param) {
139
+ var size = param.size;
140
+ return size;
141
+ },
142
+ height: function height(param) {
143
+ var size = param.size;
144
+ return size;
145
+ },
146
+ objectFit: "cover"
147
+ }
148
+ };
149
+ });
150
+ /**
151
+ * Returns a right/top distance for the badge.
152
+ * The badge will be placed over the avatar's edge
153
+ * This is calculated using the `radius * (1 - sin(45deg))` distance minus a
154
+ * constant offset that depends on the badge size
155
+ */ var getBadgeDistance = function getBadgeDistance(size, badge) {
156
+ if (!badge) {
157
+ return 0;
158
+ }
159
+ var radius = size / 2;
160
+ var badgeOffset = badge === true ? 5 : 10; // badge=true renders a small circle
161
+ return radius * (1 - Math.sin(Math.PI / 4)) - badgeOffset;
162
+ };
163
+ /**
164
+ * Not using TextPresets here because we don't want to scale the avatar text with the device settings
165
+ */ var renderText = function renderText(size, text) {
166
+ if (!text) {
167
+ return null;
168
+ }
169
+ var fontSize;
170
+ if (size <= 40) {
171
+ fontSize = 14;
172
+ } else if (size <= 64) {
173
+ fontSize = 16;
174
+ } else {
175
+ fontSize = 18;
176
+ }
177
+ return /*#__PURE__*/ (0, _jsxRuntime).jsx("span", {
178
+ style: {
179
+ fontSize: fontSize,
180
+ textTransform: "uppercase"
181
+ },
182
+ children: text
183
+ });
184
+ };
185
+ var Avatar = function Avatar(_param) {
186
+ var size = _param.size, src = _param.src, _Icon = _param.Icon, Icon = _Icon === void 0 ? _iconUserAccountRegular.default : _Icon, badge = _param.badge, _initials = _param.initials, initials = _initials === void 0 ? "" : _initials, ariaLabel = _param["aria-label"], props = _objectWithoutProperties(_param, [
187
+ "size",
188
+ "src",
189
+ "Icon",
190
+ "badge",
191
+ "initials",
192
+ "aria-label"
193
+ ]);
194
+ var colors = (0, _hooks).useTheme().colors;
195
+ var isInverse = (0, _themeVariantContext).useIsInverseVariant();
196
+ var _backgroundColor;
197
+ var backgroundColor = (_backgroundColor = props.backgroundColor) !== null && _backgroundColor !== void 0 ? _backgroundColor : isInverse ? colors.brandDark : colors.tagBackgroundActive;
198
+ var _textColor;
199
+ var textColor = (_textColor = props.textColor) !== null && _textColor !== void 0 ? _textColor : isInverse ? colors.textPrimaryInverse : colors.textTagActive;
200
+ var ref = _slicedToArray(React.useState(false), 2), imgLoadError = ref[0], setImgLoadError = ref[1];
201
+ var classes = useStyles({
202
+ textColor: textColor,
203
+ backgroundColor: backgroundColor,
204
+ size: size
205
+ });
206
+ React.useEffect(function() {
207
+ setImgLoadError(false); // reset error state when url changes
208
+ }, [
209
+ src
210
+ ]);
211
+ var letters = initials.trim().slice(0, 2);
212
+ var badgePosition = getBadgeDistance(size, badge);
213
+ var badgeValue = badge === true ? undefined : badge || 0;
214
+ var shouldRenderImage = !!src && !imgLoadError;
215
+ var iconSize = size <= 40 ? 16 : 24;
216
+ return /*#__PURE__*/ (0, _jsxRuntime).jsx(_badge.default, {
217
+ value: badgeValue,
218
+ top: badgePosition,
219
+ right: badgePosition,
220
+ children: /*#__PURE__*/ (0, _jsxRuntime).jsx("div", {
221
+ className: classes.avatar,
222
+ role: "img",
223
+ "aria-label": ariaLabel !== null && ariaLabel !== void 0 ? ariaLabel : initials,
224
+ children: shouldRenderImage ? /*#__PURE__*/ (0, _jsxRuntime).jsx("img", {
225
+ src: src,
226
+ className: classes.image,
227
+ onError: function onError() {
228
+ return setImgLoadError(true);
229
+ },
230
+ role: "none"
231
+ }) : renderText(size, letters) || /*#__PURE__*/ (0, _jsxRuntime).jsx(Icon, {
232
+ size: iconSize,
233
+ color: "currentColor"
234
+ })
235
+ })
236
+ });
237
+ };
238
+ var _default = Avatar;
239
+ exports.default = _default;
@@ -0,0 +1,16 @@
1
+ // @flow
2
+
3
+ import * as React from "react";
4
+ import type { IconProps } from "./utils/types";
5
+ declare type AvatarProps = {
6
+ size: number,
7
+ src?: string,
8
+ initials?: string,
9
+ textColor?: string,
10
+ backgroundColor?: string,
11
+ Icon?: React.ComponentType<IconProps>,
12
+ badge?: boolean | number,
13
+ "aria-label"?: string,
14
+ };
15
+ declare var Avatar: (x: AvatarProps) => React.Node;
16
+ declare export default typeof Avatar;
package/dist/badge.d.ts CHANGED
@@ -2,6 +2,8 @@ import * as React from 'react';
2
2
  declare type Props = {
3
3
  children?: React.ReactNode;
4
4
  value?: number;
5
+ right?: number;
6
+ top?: number;
5
7
  };
6
8
  /**
7
9
  * This Component is decorative and won't be read by screenreaders, to make it accessible,
package/dist/badge.js CHANGED
@@ -57,8 +57,14 @@ var useStyles = (0, _jss).createUseStyles(function(theme) {
57
57
  var hasChildren = param.hasChildren;
58
58
  return hasChildren ? "absolute" : "static";
59
59
  },
60
- top: -2,
61
- right: -6,
60
+ top: function top(param) {
61
+ var top1 = param.top;
62
+ return top1 !== null && top1 !== void 0 ? top1 : -2;
63
+ },
64
+ right: function right(param) {
65
+ var right1 = param.right;
66
+ return right1 !== null && right1 !== void 0 ? right1 : -6;
67
+ },
62
68
  width: 8,
63
69
  height: 8,
64
70
  background: theme.colors.badge,
@@ -69,8 +75,14 @@ var useStyles = (0, _jss).createUseStyles(function(theme) {
69
75
  display: "flex",
70
76
  alignItems: "center",
71
77
  justifyContent: "center",
72
- top: -8,
73
- right: -9,
78
+ top: function top(param) {
79
+ var top2 = param.top;
80
+ return top2 !== null && top2 !== void 0 ? top2 : -8;
81
+ },
82
+ right: function right(param) {
83
+ var right2 = param.right;
84
+ return right2 !== null && right2 !== void 0 ? right2 : -9;
85
+ },
74
86
  width: 18,
75
87
  height: 18,
76
88
  fontSize: 12,
@@ -78,7 +90,10 @@ var useStyles = (0, _jss).createUseStyles(function(theme) {
78
90
  color: theme.colors.textPrimaryInverse
79
91
  },
80
92
  badgeBigNumber: {
81
- right: -14,
93
+ right: function right(param) {
94
+ var right3 = param.right;
95
+ return right3 !== null && right3 !== void 0 ? right3 : -14;
96
+ },
82
97
  width: 24,
83
98
  borderRadius: 24
84
99
  }
@@ -94,10 +109,12 @@ var useStyles = (0, _jss).createUseStyles(function(theme) {
94
109
  * </IconButton>
95
110
  * </Badge>
96
111
  */ var Badge = function Badge(param) {
97
- var children = param.children, value = param.value;
112
+ var children = param.children, value = param.value, right = param.right, top = param.top;
98
113
  var hasChildren = !!children;
99
114
  var classes = useStyles({
100
- hasChildren: hasChildren
115
+ hasChildren: hasChildren,
116
+ right: right,
117
+ top: top
101
118
  });
102
119
  if (children && value === 0) {
103
120
  return /*#__PURE__*/ (0, _jsxRuntime).jsx(_jsxRuntime.Fragment, {
@@ -4,6 +4,8 @@ import * as React from "react";
4
4
  declare type Props = {
5
5
  children?: React.Node,
6
6
  value?: number,
7
+ right?: number,
8
+ top?: number,
7
9
  };
8
10
  /**
9
11
  * This Component is decorative and won't be read by screenreaders, to make it accessible,
package/dist/button.js CHANGED
@@ -16,6 +16,7 @@ var _text = require("./text");
16
16
  var _box = _interopRequireDefault(require("./box"));
17
17
  var _common = require("./utils/common");
18
18
  var _analytics = require("./utils/analytics");
19
+ var _hooks = require("./hooks");
19
20
  function _interopRequireDefault(obj) {
20
21
  return obj && obj.__esModule ? obj : {
21
22
  default: obj
@@ -305,6 +306,7 @@ var useDangerButtonStyles = (0, _jss).createUseStyles(function(theme) {
305
306
  });
306
307
  });
307
308
  var Button = function Button(props) {
309
+ var eventFormat = (0, _analytics).useTrackingConfig().eventFormat;
308
310
  var ref = (0, _formContext).useForm(), formStatus = ref.formStatus, formId = ref.formId;
309
311
  var isInverse = (0, _themeVariantContext).useIsInverseVariant();
310
312
  var classes = props.classes, loadingText = props.loadingText;
@@ -343,6 +345,21 @@ var Button = function Button(props) {
343
345
  children: text
344
346
  });
345
347
  };
348
+ var createDefaultTrackingEvent = function createDefaultTrackingEvent() {
349
+ if (eventFormat === "google-analytics-4") {
350
+ return {
351
+ name: _analytics.eventNames.userInteraction,
352
+ component_type: "".concat(props.type, "_button"),
353
+ component_copy: (0, _common).getTextFromChildren(props.children)
354
+ };
355
+ } else {
356
+ return {
357
+ category: _analytics.eventCategories.userInteraction,
358
+ action: "".concat(props.type, "_button_tapped"),
359
+ label: (0, _common).getTextFromChildren(props.children)
360
+ };
361
+ }
362
+ };
346
363
  var _trackingEvent;
347
364
  var _obj;
348
365
  var commonProps = {
@@ -350,11 +367,7 @@ var Button = function Button(props) {
350
367
  style: _objectSpread({
351
368
  cursor: props.fake ? "pointer" : undefined
352
369
  }, props.style),
353
- trackingEvent: (_trackingEvent = props.trackingEvent) !== null && _trackingEvent !== void 0 ? _trackingEvent : props.trackEvent ? {
354
- category: _analytics.eventCategories.userInteraction,
355
- action: "".concat(props.type, "_button_tapped"),
356
- label: (0, _common).getTextFromChildren(props.children)
357
- } : undefined,
370
+ trackingEvent: (_trackingEvent = props.trackingEvent) !== null && _trackingEvent !== void 0 ? _trackingEvent : props.trackEvent ? createDefaultTrackingEvent() : undefined,
358
371
  dataAttributes: props.dataAttributes,
359
372
  "aria-controls": props["aria-controls"],
360
373
  "aria-expanded": props["aria-expanded"],
@@ -496,15 +509,27 @@ var ButtonLink = /*#__PURE__*/ React.forwardRef(function(props, ref) {
496
509
  var formStatus = (0, _formContext).useForm().formStatus;
497
510
  var classes = useButtonLinkStyles();
498
511
  var isInverse = (0, _themeVariantContext).useIsInverseVariant();
512
+ var analytics = (0, _hooks).useTheme().analytics;
513
+ var createDefaultTrackingEvent = function createDefaultTrackingEvent() {
514
+ if (analytics.eventFormat === "google-analytics-4") {
515
+ return {
516
+ name: _analytics.eventNames.userInteraction,
517
+ component_type: "link",
518
+ component_copy: (0, _common).getTextFromChildren(props.children)
519
+ };
520
+ } else {
521
+ return {
522
+ category: _analytics.eventCategories.userInteraction,
523
+ action: _analytics.eventActions.linkTapped,
524
+ label: (0, _common).getTextFromChildren(props.children)
525
+ };
526
+ }
527
+ };
499
528
  var _trackingEvent;
500
529
  var _obj;
501
530
  var commonProps = {
502
531
  className: (0, _classnames).default(classes.link, (_obj = {}, _defineProperty(_obj, classes.inverse, isInverse), _defineProperty(_obj, classes.aligned, props.aligned), _obj)),
503
- trackingEvent: (_trackingEvent = props.trackingEvent) !== null && _trackingEvent !== void 0 ? _trackingEvent : props.trackEvent ? {
504
- category: _analytics.eventCategories.userInteraction,
505
- action: _analytics.eventActions.linkTapped,
506
- label: (0, _common).getTextFromChildren(props.children)
507
- } : undefined,
532
+ trackingEvent: (_trackingEvent = props.trackingEvent) !== null && _trackingEvent !== void 0 ? _trackingEvent : props.trackEvent ? createDefaultTrackingEvent() : undefined,
508
533
  dataAttributes: props.dataAttributes,
509
534
  children: /*#__PURE__*/ (0, _jsxRuntime).jsx(_text.Text2, {
510
535
  medium: true,
package/dist/image.d.ts CHANGED
@@ -21,6 +21,8 @@ export declare type ImageProps = {
21
21
  children?: void;
22
22
  dataAttributes?: DataAttributes;
23
23
  noBorderRadius?: boolean;
24
+ onError?: (event: React.SyntheticEvent) => void;
25
+ onLoad?: (event: React.SyntheticEvent) => void;
24
26
  };
25
27
  declare const Image: React.ForwardRefExoticComponent<ImageProps & React.RefAttributes<HTMLImageElement>>;
26
28
  export default Image;
package/dist/image.js CHANGED
@@ -29,6 +29,14 @@ function _interopRequireWildcard(obj) {
29
29
  return newObj;
30
30
  }
31
31
  }
32
+ function _arrayLikeToArray(arr, len) {
33
+ if (len == null || len > arr.length) len = arr.length;
34
+ for(var i = 0, arr2 = new Array(len); i < len; i++)arr2[i] = arr[i];
35
+ return arr2;
36
+ }
37
+ function _arrayWithHoles(arr) {
38
+ if (Array.isArray(arr)) return arr;
39
+ }
32
40
  function _defineProperty(obj, key, value) {
33
41
  if (key in obj) {
34
42
  Object.defineProperty(obj, key, {
@@ -42,6 +50,33 @@ function _defineProperty(obj, key, value) {
42
50
  }
43
51
  return obj;
44
52
  }
53
+ function _iterableToArrayLimit(arr, i) {
54
+ var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
55
+ if (_i == null) return;
56
+ var _arr = [];
57
+ var _n = true;
58
+ var _d = false;
59
+ var _s, _e;
60
+ try {
61
+ for(_i = _i.call(arr); !(_n = (_s = _i.next()).done); _n = true){
62
+ _arr.push(_s.value);
63
+ if (i && _arr.length === i) break;
64
+ }
65
+ } catch (err) {
66
+ _d = true;
67
+ _e = err;
68
+ } finally{
69
+ try {
70
+ if (!_n && _i["return"] != null) _i["return"]();
71
+ } finally{
72
+ if (_d) throw _e;
73
+ }
74
+ }
75
+ return _arr;
76
+ }
77
+ function _nonIterableRest() {
78
+ throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
79
+ }
45
80
  function _objectSpread(target) {
46
81
  var _arguments = arguments, _loop = function(i) {
47
82
  var source = _arguments[i] != null ? _arguments[i] : {};
@@ -85,6 +120,17 @@ function _objectWithoutPropertiesLoose(source, excluded) {
85
120
  }
86
121
  return target;
87
122
  }
123
+ function _slicedToArray(arr, i) {
124
+ return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
125
+ }
126
+ function _unsupportedIterableToArray(o, minLen) {
127
+ if (!o) return;
128
+ if (typeof o === "string") return _arrayLikeToArray(o, minLen);
129
+ var n = Object.prototype.toString.call(o).slice(8, -1);
130
+ if (n === "Object" && o.constructor) n = o.constructor.name;
131
+ if (n === "Map" || n === "Set") return Array.from(n);
132
+ if (n === "Arguments" || /^(?:Ui|I)nt(?:8|16|32)(?:Clamped)?Array$/.test(n)) return _arrayLikeToArray(o, minLen);
133
+ }
88
134
  /**
89
135
  * This context is used internally to disable the border radius. This is useful for example
90
136
  * when using the Image component inside a Card
@@ -125,6 +171,10 @@ var useStyles = (0, _jss).createUseStyles(function() {
125
171
  height: "100%",
126
172
  top: 0,
127
173
  left: 0
174
+ },
175
+ opacity: function opacity(param) {
176
+ var isError = param.isError;
177
+ return isError ? 0 : 1;
128
178
  }
129
179
  },
130
180
  wrapper: {
@@ -157,16 +207,19 @@ var RATIO = {
157
207
  };
158
208
  exports.RATIO = RATIO;
159
209
  var Image = /*#__PURE__*/ React.forwardRef(function(_param, ref) {
160
- var _aspectRatio = _param.aspectRatio, aspectRatio = _aspectRatio === void 0 ? "1:1" : _aspectRatio, _alt = _param.alt, alt = _alt === void 0 ? "" : _alt, dataAttributes = _param.dataAttributes, noBorderRadius = _param.noBorderRadius, src = _param.src, props = _objectWithoutProperties(_param, [
210
+ var _aspectRatio = _param.aspectRatio, aspectRatio = _aspectRatio === void 0 ? "1:1" : _aspectRatio, _alt = _param.alt, alt = _alt === void 0 ? "" : _alt, dataAttributes = _param.dataAttributes, noBorderRadius = _param.noBorderRadius, src = _param.src, onError = _param.onError, onLoad = _param.onLoad, props = _objectWithoutProperties(_param, [
161
211
  "aspectRatio",
162
212
  "alt",
163
213
  "dataAttributes",
164
214
  "noBorderRadius",
165
- "src"
215
+ "src",
216
+ "onError",
217
+ "onLoad"
166
218
  ]);
167
219
  var supportsAspectRatio = (0, _aspectRatioSupport).useSupportsAspectRatio();
168
220
  var noBorderRadiusContext = useDisableBorderRadius();
169
221
  var noBorderSetting = noBorderRadius !== null && noBorderRadius !== void 0 ? noBorderRadius : noBorderRadiusContext;
222
+ var _$ref = _slicedToArray(React.useState(false), 2), isError = _$ref[0], setIsError = _$ref[1];
170
223
  var ratio = typeof aspectRatio === "number" ? aspectRatio : RATIO[aspectRatio];
171
224
  // if width or height are numeric, we can calculate the other with the ratio without css.
172
225
  // if aspect ratio is 0, we use the original image proportions
@@ -174,7 +227,8 @@ var Image = /*#__PURE__*/ React.forwardRef(function(_param, ref) {
174
227
  var classes = useStyles({
175
228
  noBorderRadius: noBorderSetting,
176
229
  aspectRatio: withCssAspectRatio ? ratio : undefined,
177
- width: props.width
230
+ width: props.width,
231
+ isError: isError
178
232
  });
179
233
  var width = props.width;
180
234
  var height = props.height;
@@ -189,11 +243,20 @@ var Image = /*#__PURE__*/ React.forwardRef(function(_param, ref) {
189
243
  width = props.width || "100%";
190
244
  }
191
245
  var needsWrapper = withCssAspectRatio && !supportsAspectRatio;
192
- var img = /*#__PURE__*/ (0, _jsxRuntime).jsx("img", _objectSpread({}, (0, _dom).getPrefixedDataAttributes(dataAttributes), {
246
+ var img = // eslint-disable-next-line jsx-a11y/no-noninteractive-element-interactions
247
+ /*#__PURE__*/ (0, _jsxRuntime).jsx("img", _objectSpread({}, (0, _dom).getPrefixedDataAttributes(dataAttributes), {
193
248
  ref: ref,
194
249
  src: src,
195
250
  className: classes.image,
196
- alt: alt
251
+ alt: alt,
252
+ onError: function onError1(event) {
253
+ setIsError(true);
254
+ onError === null || onError === void 0 ? void 0 : onError(event);
255
+ },
256
+ onLoad: function onLoad1(event) {
257
+ setIsError(false);
258
+ onLoad === null || onLoad === void 0 ? void 0 : onLoad(event);
259
+ }
197
260
  }, !needsWrapper ? {
198
261
  width: width,
199
262
  height: height
@@ -28,6 +28,8 @@ export type ImageProps = {
28
28
  alt?: string,
29
29
  dataAttributes?: DataAttributes,
30
30
  noBorderRadius?: boolean,
31
+ onError?: (event: SyntheticEvent<any>) => void,
32
+ onLoad?: (event: SyntheticEvent<any>) => void,
31
33
  };
32
34
  declare var Image: React.AbstractComponent<ImageProps, HTMLImageElement>;
33
35
  declare export default typeof Image;
package/dist/index.d.ts CHANGED
@@ -37,7 +37,8 @@ export { default as Text, Text1, Text2, Text3, Text4, Text5, Text6, Text7, Text8
37
37
  export { default as Tag } from './tag';
38
38
  export type { TagType } from './tag';
39
39
  export { default as SectionTitle } from './section-title';
40
- export { Placeholder, AvatarPlaceholder } from './placeholder';
40
+ export { Placeholder } from './placeholder';
41
+ export { Title1, Title2 } from './title';
41
42
  export { RowList, Row, BoxedRowList, BoxedRow } from './list';
42
43
  export { default as Switch } from './switch-component';
43
44
  export { default as Checkbox } from './checkbox';
@@ -54,6 +55,7 @@ export { default as Menu } from './menu';
54
55
  export { default as EmptyState } from './empty-state';
55
56
  export { default as EmptyStateCard } from './empty-state-card';
56
57
  export { default as Callout } from './callout';
58
+ export { default as Avatar } from './avatar';
57
59
  export { useModalState } from './modal-context-provider';
58
60
  export { NavigationBar, MainNavigationBar, FunnelNavigationBar, NavigationBarActionGroup, NavigationBarAction, NavigationBarLogo, } from './navigation-bar';
59
61
  export { default as Image } from './image';
@@ -87,7 +89,8 @@ export { default as IconSuccess } from './icons/icon-success';
87
89
  export { default as IconSuccessVivo } from './icons/icon-success-vivo';
88
90
  export { default as Circle } from './circle';
89
91
  export { useTheme, useScreenSize, useElementDimensions, useAriaId, useWindowSize, useWindowHeight, useWindowWidth, useIsInViewport, } from './hooks';
90
- export type { ThemeConfig, ColorScheme } from './theme';
92
+ export type { ThemeConfig, ColorScheme, EventFormat } from './theme';
93
+ export { TrackingConfig, useTrackingConfig } from './utils/analytics';
91
94
  export { useDocumentVisibility } from './utils/document-visibility';
92
95
  export { ThemeVariant, useIsInverseVariant } from './theme-variant-context';
93
96
  export type { Skin, KnownSkinName, SkinName } from './skins/types';