@telefonica/mistica 10.17.0 → 10.21.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 (70) hide show
  1. package/CHANGELOG.md +36 -0
  2. package/dist/button-layout.js +28 -17
  3. package/dist/button.js +24 -8
  4. package/dist/card.d.ts +10 -1
  5. package/dist/card.js +29 -29
  6. package/dist/card.js.flow +16 -1
  7. package/dist/header.d.ts +2 -0
  8. package/dist/header.js.flow +5 -0
  9. package/dist/icons/icon-success.js +14 -6
  10. package/dist/image.d.ts +25 -4
  11. package/dist/image.js +67 -9
  12. package/dist/image.js.flow +33 -4
  13. package/dist/index.d.ts +2 -0
  14. package/dist/index.js +7 -0
  15. package/dist/index.js.flow +2 -0
  16. package/dist/package-version.js +1 -1
  17. package/dist/section-title.d.ts +1 -3
  18. package/dist/section-title.js.flow +1 -2
  19. package/dist/skins/blau.d.ts +6 -3
  20. package/dist/skins/blau.js +34 -5
  21. package/dist/skins/blau.js.flow +6 -3
  22. package/dist/skins/movistar.d.ts +21 -11
  23. package/dist/skins/movistar.js +76 -40
  24. package/dist/skins/movistar.js.flow +21 -11
  25. package/dist/skins/o2-classic.d.ts +21 -9
  26. package/dist/skins/o2-classic.js +64 -26
  27. package/dist/skins/o2-classic.js.flow +21 -9
  28. package/dist/skins/o2.d.ts +19 -17
  29. package/dist/skins/o2.js +68 -40
  30. package/dist/skins/o2.js.flow +19 -17
  31. package/dist/skins/telefonica.d.ts +18 -13
  32. package/dist/skins/telefonica.js +76 -45
  33. package/dist/skins/telefonica.js.flow +18 -13
  34. package/dist/skins/types.d.ts +12 -0
  35. package/dist/skins/types.js.flow +12 -0
  36. package/dist/skins/vivo.d.ts +9 -4
  37. package/dist/skins/vivo.js +37 -6
  38. package/dist/skins/vivo.js.flow +9 -4
  39. package/dist/tag.d.ts +6 -1
  40. package/dist/tag.js +133 -24
  41. package/dist/tag.js.flow +15 -1
  42. package/dist/text.d.ts +4 -0
  43. package/dist/text.js +13 -6
  44. package/dist/text.js.flow +10 -0
  45. package/dist/theme-context-provider.js +8 -2
  46. package/dist/theme.d.ts +2 -0
  47. package/dist/theme.js.flow +2 -0
  48. package/dist/touchable.js +3 -2
  49. package/dist/video.d.ts +32 -0
  50. package/dist/video.js +161 -0
  51. package/dist/video.js.flow +50 -0
  52. package/dist-es/button-layout.js +28 -17
  53. package/dist-es/button.js +24 -8
  54. package/dist-es/card.js +30 -30
  55. package/dist-es/icons/icon-success.js +14 -6
  56. package/dist-es/image.js +41 -8
  57. package/dist-es/index.js +1 -0
  58. package/dist-es/package-version.js +1 -1
  59. package/dist-es/skins/blau.js +36 -5
  60. package/dist-es/skins/movistar.js +78 -40
  61. package/dist-es/skins/o2-classic.js +66 -26
  62. package/dist-es/skins/o2.js +70 -40
  63. package/dist-es/skins/telefonica.js +78 -45
  64. package/dist-es/skins/vivo.js +39 -6
  65. package/dist-es/tag.js +130 -26
  66. package/dist-es/text.js +13 -6
  67. package/dist-es/theme-context-provider.js +8 -2
  68. package/dist-es/touchable.js +3 -2
  69. package/dist-es/video.js +123 -0
  70. package/package.json +1 -1
package/dist/text.d.ts CHANGED
@@ -2,9 +2,13 @@ import * as React from 'react';
2
2
  declare type FontWeight = 'light' | 'regular' | 'medium';
3
3
  export interface TextPresetProps {
4
4
  color?: string;
5
+ /** @deprecated use decoration prop */
5
6
  textDecoration?: 'underline' | 'line-through' | 'none';
7
+ decoration?: 'underline' | 'line-through' | 'inherit' | 'none';
8
+ transform?: 'uppercase' | 'capitalize' | 'lowercase' | 'inherit' | 'none';
6
9
  children?: React.ReactNode;
7
10
  truncate?: boolean | number;
11
+ /** @deprecated use transform */
8
12
  uppercase?: boolean;
9
13
  wordBreak?: boolean;
10
14
  id?: string;
package/dist/text.js CHANGED
@@ -86,7 +86,7 @@ var useStyles = (0, _jss).createUseStyles(function(theme) {
86
86
  }
87
87
  return 'initial';
88
88
  };
89
- var _color, _textDecoration;
89
+ var _color, _decoration;
90
90
  return {
91
91
  text: _defineProperty({
92
92
  lineHeight: function lineHeight(param) {
@@ -94,8 +94,14 @@ var useStyles = (0, _jss).createUseStyles(function(theme) {
94
94
  return (0, _css).pxToRem(desktopLineHeight);
95
95
  },
96
96
  textTransform: function textTransform(param) {
97
- var uppercase = param.uppercase;
98
- return uppercase ? 'uppercase' : 'inherit';
97
+ var uppercase = param.uppercase, transform = param.transform;
98
+ if (uppercase) {
99
+ return 'uppercase';
100
+ }
101
+ if (transform) {
102
+ return transform;
103
+ }
104
+ return 'inherit';
99
105
  },
100
106
  fontSize: function fontSize(param) {
101
107
  var desktopSize = param.desktopSize;
@@ -110,7 +116,7 @@ var useStyles = (0, _jss).createUseStyles(function(theme) {
110
116
  return isInverse ? (_color = inverseColorsMap[color1]) !== null && _color !== void 0 ? _color : color1 : color1;
111
117
  },
112
118
  textDecoration: function textDecoration(p) {
113
- return (_textDecoration = p.textDecoration) !== null && _textDecoration !== void 0 ? _textDecoration : 'inherit';
119
+ return (_decoration = p.decoration) !== null && _decoration !== void 0 ? _decoration : 'inherit';
114
120
  },
115
121
  letterSpacing: function letterSpacing(param) {
116
122
  var letterSpacing1 = param.letterSpacing;
@@ -146,7 +152,7 @@ var useStyles = (0, _jss).createUseStyles(function(theme) {
146
152
  };
147
153
  });
148
154
  var Text = function Text(param) {
149
- var weight = param.weight, color = param.color, textDecoration = param.textDecoration, truncate = param.truncate, uppercase = param.uppercase, wordBreak = param.wordBreak, _as = param.as, as = _as === void 0 ? 'span' : _as, children = param.children, size = param.size, _mobileSize = param.mobileSize, mobileSize = _mobileSize === void 0 ? size : _mobileSize, _desktopSize = param.desktopSize, desktopSize = _desktopSize === void 0 ? size : _desktopSize, lineHeight = param.lineHeight, _mobileLineHeight = param.mobileLineHeight, mobileLineHeight = _mobileLineHeight === void 0 ? lineHeight : _mobileLineHeight, _desktopLineHeight = param.desktopLineHeight, desktopLineHeight = _desktopLineHeight === void 0 ? lineHeight : _desktopLineHeight, letterSpacing = param.letterSpacing, id = param.id, role = param.role, ariaLevel = param['aria-level'];
155
+ var weight = param.weight, color = param.color, textDecoration = param.textDecoration, _decoration = param.decoration, decoration = _decoration === void 0 ? textDecoration : _decoration, truncate = param.truncate, uppercase = param.uppercase, transform = param.transform, wordBreak = param.wordBreak, _as = param.as, as = _as === void 0 ? 'span' : _as, children = param.children, size = param.size, _mobileSize = param.mobileSize, mobileSize = _mobileSize === void 0 ? size : _mobileSize, _desktopSize = param.desktopSize, desktopSize = _desktopSize === void 0 ? size : _desktopSize, lineHeight = param.lineHeight, _mobileLineHeight = param.mobileLineHeight, mobileLineHeight = _mobileLineHeight === void 0 ? lineHeight : _mobileLineHeight, _desktopLineHeight = param.desktopLineHeight, desktopLineHeight = _desktopLineHeight === void 0 ? lineHeight : _desktopLineHeight, letterSpacing = param.letterSpacing, id = param.id, role = param.role, ariaLevel = param['aria-level'];
150
156
  var isInverse = (0, _themeVariantContext).useIsInverseVariant();
151
157
  var classes = useStyles({
152
158
  isInverse: isInverse,
@@ -156,8 +162,9 @@ var Text = function Text(param) {
156
162
  desktopLineHeight: desktopLineHeight,
157
163
  weight: weight,
158
164
  color: color,
159
- textDecoration: textDecoration,
165
+ decoration: decoration,
160
166
  uppercase: uppercase,
167
+ transform: transform,
161
168
  wordBreak: wordBreak,
162
169
  letterSpacing: letterSpacing,
163
170
  truncate: truncate
package/dist/text.js.flow CHANGED
@@ -4,9 +4,19 @@ import * as React from "react";
4
4
  declare type FontWeight = "light" | "regular" | "medium";
5
5
  export type TextPresetProps = {
6
6
  color?: string,
7
+
8
+ /**
9
+ * @deprecated use decoration prop
10
+ */
7
11
  textDecoration?: "underline" | "line-through" | "none",
12
+ decoration?: "underline" | "line-through" | "inherit" | "none",
13
+ transform?: "uppercase" | "capitalize" | "lowercase" | "inherit" | "none",
8
14
  children?: React.Node,
9
15
  truncate?: boolean | number,
16
+
17
+ /**
18
+ * @deprecated use transform
19
+ */
10
20
  uppercase?: boolean,
11
21
  wordBreak?: boolean,
12
22
  id?: string,
@@ -148,6 +148,11 @@ var generateId = function() {
148
148
  // in frontend, use the same generator for all JssProvider renders, this way we avoid classname collisions
149
149
  return (0, _jss).createGenerateId();
150
150
  }();
151
+ var useDefaultHrefDecorator = function useDefaultHrefDecorator() {
152
+ return function(href) {
153
+ return href;
154
+ };
155
+ };
151
156
  var ThemeContextProvider = function ThemeContextProvider(param) {
152
157
  var theme = param.theme, children = param.children;
153
158
  var classNamePrefix = React.useMemo(// we'll have missmatches when rendering client side. The disadvantage of this is that we can only have one instance of
@@ -173,7 +178,7 @@ var ThemeContextProvider = function ThemeContextProvider(param) {
173
178
  platform: (0, _platform).getPlatform(),
174
179
  insideNovumNativeApp: (0, _platform).isInsideNovumNativeApp()
175
180
  }, theme.platformOverrides);
176
- var _mediaQueries1, _Link;
181
+ var _mediaQueries1, _Link, _useHrefDecorator;
177
182
  return {
178
183
  skinName: theme.skin.name,
179
184
  i18n: theme.i18n,
@@ -191,7 +196,8 @@ var ThemeContextProvider = function ThemeContextProvider(param) {
191
196
  colors: colors,
192
197
  Link: (_Link = theme.Link) !== null && _Link !== void 0 ? _Link : _theme.AnchorLink,
193
198
  isDarkMode: isDarkModeEnabled,
194
- isIos: (0, _platform).getPlatform(platformOverrides) === 'ios'
199
+ isIos: (0, _platform).getPlatform(platformOverrides) === 'ios',
200
+ useHrefDecorator: (_useHrefDecorator = theme.useHrefDecorator) !== null && _useHrefDecorator !== void 0 ? _useHrefDecorator : useDefaultHrefDecorator
195
201
  };
196
202
  }, [
197
203
  theme,
package/dist/theme.d.ts CHANGED
@@ -98,6 +98,7 @@ export declare type ThemeConfig = {
98
98
  desktopOrTabletMinHeight: number;
99
99
  };
100
100
  Link?: LinkComponent;
101
+ useHrefDecorator?: () => (href: string) => string;
101
102
  enableTabFocus?: boolean;
102
103
  };
103
104
  export declare type Theme = {
@@ -132,5 +133,6 @@ export declare type Theme = {
132
133
  Link: LinkComponent;
133
134
  isDarkMode: boolean;
134
135
  isIos: boolean;
136
+ useHrefDecorator: () => (href: string) => string;
135
137
  };
136
138
  export {};
@@ -102,6 +102,7 @@ export type ThemeConfig = {
102
102
  desktopOrTabletMinHeight: number,
103
103
  },
104
104
  Link?: LinkComponent,
105
+ useHrefDecorator?: () => (href: string) => string,
105
106
  enableTabFocus?: boolean,
106
107
  };
107
108
  export type Theme = {
@@ -136,6 +137,7 @@ export type Theme = {
136
137
  Link: LinkComponent,
137
138
  isDarkMode: boolean,
138
139
  isIos: boolean,
140
+ useHrefDecorator: () => (href: string) => string,
139
141
  };
140
142
  declare export {};
141
143
 
package/dist/touchable.js CHANGED
@@ -114,7 +114,8 @@ var useStyles = (0, _jss).createUseStyles(function() {
114
114
  };
115
115
  });
116
116
  var Touchable = /*#__PURE__*/ React.forwardRef(function(props, ref) {
117
- var ref1 = (0, _hooks).useTheme(), texts = ref1.texts, analytics = ref1.analytics, platformOverrides = ref1.platformOverrides, Link = ref1.Link;
117
+ var ref1 = (0, _hooks).useTheme(), texts = ref1.texts, analytics = ref1.analytics, platformOverrides = ref1.platformOverrides, Link = ref1.Link, useHrefDecorator = ref1.useHrefDecorator;
118
+ var hrefDecorator = useHrefDecorator();
118
119
  var classes = useStyles();
119
120
  var isClicked = React.useRef(false);
120
121
  var trackingEvents = [];
@@ -150,7 +151,7 @@ var Touchable = /*#__PURE__*/ React.forwardRef(function(props, ref) {
150
151
  };
151
152
  var getHref = function getHref() {
152
153
  if (props.href) {
153
- return props.href;
154
+ return hrefDecorator(props.href);
154
155
  }
155
156
  if (props.to && props.fullPageOnWebView) {
156
157
  if (typeof props.to === 'string') {
@@ -0,0 +1,32 @@
1
+ import * as React from 'react';
2
+ export declare type AspectRatio = '1:1' | '16:9' | '12:5';
3
+ export declare const RATIO: {
4
+ '1:1': number;
5
+ '16:9': number;
6
+ '12:5': number;
7
+ };
8
+ declare type VideoSource = {
9
+ src: string;
10
+ type?: string;
11
+ };
12
+ export declare type VideoProps = {
13
+ /** defaults to 100% when no width and no height are given */
14
+ width?: number;
15
+ height?: number;
16
+ /** defaults to 1:1, if both width and height are given, aspectRatio is ignored */
17
+ aspectRatio?: AspectRatio;
18
+ /** accepts multiple sources */
19
+ src: string | Array<string> | VideoSource | Array<VideoSource>;
20
+ /** defaults to true */
21
+ loop?: boolean;
22
+ /** defaults to true */
23
+ muted?: boolean;
24
+ /** defaults to true */
25
+ autoPlay?: boolean;
26
+ poster?: string;
27
+ children?: void;
28
+ /** defaults to none */
29
+ preload?: 'none' | 'metadata' | 'auto';
30
+ };
31
+ declare const Video: React.ForwardRefExoticComponent<VideoProps & React.RefAttributes<HTMLVideoElement>>;
32
+ export default Video;
package/dist/video.js ADDED
@@ -0,0 +1,161 @@
1
+ "use strict";
2
+ Object.defineProperty(exports, "__esModule", {
3
+ value: true
4
+ });
5
+ exports.default = exports.RATIO = void 0;
6
+ var _jsxRuntime = require("react/jsx-runtime");
7
+ var React = _interopRequireWildcard(require("react"));
8
+ var _image = require("./image");
9
+ var _jss = require("./jss");
10
+ var _common = require("./utils/common");
11
+ function _interopRequireWildcard(obj) {
12
+ if (obj && obj.__esModule) {
13
+ return obj;
14
+ } else {
15
+ var newObj = {
16
+ };
17
+ if (obj != null) {
18
+ for(var key in obj){
19
+ if (Object.prototype.hasOwnProperty.call(obj, key)) {
20
+ var desc = Object.defineProperty && Object.getOwnPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : {
21
+ };
22
+ if (desc.get || desc.set) {
23
+ Object.defineProperty(newObj, key, desc);
24
+ } else {
25
+ newObj[key] = obj[key];
26
+ }
27
+ }
28
+ }
29
+ }
30
+ newObj.default = obj;
31
+ return newObj;
32
+ }
33
+ }
34
+ function _objectWithoutProperties(source, excluded) {
35
+ if (source == null) return {
36
+ };
37
+ var target = _objectWithoutPropertiesLoose(source, excluded);
38
+ var key, i;
39
+ if (Object.getOwnPropertySymbols) {
40
+ var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
41
+ for(i = 0; i < sourceSymbolKeys.length; i++){
42
+ key = sourceSymbolKeys[i];
43
+ if (excluded.indexOf(key) >= 0) continue;
44
+ if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
45
+ target[key] = source[key];
46
+ }
47
+ }
48
+ return target;
49
+ }
50
+ function _objectWithoutPropertiesLoose(source, excluded) {
51
+ if (source == null) return {
52
+ };
53
+ var target = {
54
+ };
55
+ var sourceKeys = Object.keys(source);
56
+ var key, i;
57
+ for(i = 0; i < sourceKeys.length; i++){
58
+ key = sourceKeys[i];
59
+ if (excluded.indexOf(key) >= 0) continue;
60
+ target[key] = source[key];
61
+ }
62
+ return target;
63
+ }
64
+ var RATIO = {
65
+ '1:1': 1,
66
+ '16:9': 16 / 9,
67
+ '12:5': 12 / 5
68
+ };
69
+ exports.RATIO = RATIO;
70
+ var useStyles = (0, _jss).createUseStyles(function() {
71
+ return {
72
+ video: {
73
+ borderRadius: function borderRadius(param) {
74
+ var noBorderRadius = param.noBorderRadius;
75
+ return noBorderRadius ? 0 : 4;
76
+ },
77
+ display: 'block',
78
+ maxWidth: '100%',
79
+ maxHeight: '100%',
80
+ objectFit: 'cover',
81
+ aspectRatio: function aspectRatio(param) {
82
+ var aspectRatio1 = param.aspectRatio;
83
+ return aspectRatio1 !== null && aspectRatio1 !== void 0 ? aspectRatio1 : 'unset';
84
+ }
85
+ }
86
+ };
87
+ });
88
+ /** Transparent 1x1px PNG */ var TRANSPARENT_PIXEL = 'data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAYAAAAfFcSJAAAAAXNSR0IArs4c6QAAAAtJREFUGFdjYAACAAAFAAGq1chRAAAAAElFTkSuQmCC';
89
+ var Video = /*#__PURE__*/ React.forwardRef(function(_param, ref) {
90
+ var src = _param.src, poster = _param.poster, _autoPlay = _param.autoPlay, autoPlay = _autoPlay === void 0 ? true : _autoPlay, _muted = _param.muted, muted = _muted === void 0 ? true : _muted, _loop = _param.loop, loop = _loop === void 0 ? true : _loop, _preload = _param.preload, preload = _preload === void 0 ? 'none' : _preload, _aspectRatio = _param.aspectRatio, aspectRatio = _aspectRatio === void 0 ? '1:1' : _aspectRatio, props = _objectWithoutProperties(_param, [
91
+ "src",
92
+ "poster",
93
+ "autoPlay",
94
+ "muted",
95
+ "loop",
96
+ "preload",
97
+ "aspectRatio"
98
+ ]);
99
+ var noBorderRadius = (0, _image).useDisableBorderRadius();
100
+ var classes = useStyles({
101
+ noBorderRadius: noBorderRadius,
102
+ aspectRatio: !props.width && !props.height ? RATIO[aspectRatio] : undefined
103
+ });
104
+ var videoRef = React.useRef(null);
105
+ React.useEffect(function() {
106
+ var video = videoRef.current;
107
+ if (video && autoPlay && video.paused) {
108
+ video.play();
109
+ }
110
+ }, [
111
+ autoPlay
112
+ ]);
113
+ // normalize sources
114
+ var sources = (Array.isArray(src) ? src : [
115
+ src
116
+ ]).map(function(source) {
117
+ if (typeof source === 'string') {
118
+ return {
119
+ src: source
120
+ };
121
+ } else {
122
+ return source;
123
+ }
124
+ });
125
+ var width = props.width;
126
+ var height = props.height;
127
+ if (props.width !== undefined && props.height !== undefined) {
128
+ width = props.width;
129
+ height = props.height;
130
+ } else if (props.width !== undefined) {
131
+ height = props.width / RATIO[aspectRatio];
132
+ } else if (props.height !== undefined) {
133
+ width = props.height * RATIO[aspectRatio];
134
+ } else {
135
+ width = '100%';
136
+ }
137
+ return(/*#__PURE__*/ (0, _jsxRuntime).jsx("video", {
138
+ ref: (0, _common).combineRefs(ref, videoRef),
139
+ playsInline: true,
140
+ disablePictureInPicture: true,
141
+ disableRemotePlayback: true,
142
+ autoPlay: autoPlay,
143
+ muted: muted,
144
+ loop: loop,
145
+ width: width,
146
+ height: height,
147
+ className: classes.video,
148
+ preload: preload,
149
+ // This transparent pixel fallback avoids showing the ugly "play" image in android webviews
150
+ poster: poster || TRANSPARENT_PIXEL,
151
+ children: sources.map(function(param, index) {
152
+ var src = param.src, type = param.type;
153
+ /*#__PURE__*/ return (0, _jsxRuntime).jsx("source", {
154
+ src: src,
155
+ type: type
156
+ }, index);
157
+ })
158
+ }));
159
+ });
160
+ var _default = Video;
161
+ exports.default = _default;
@@ -0,0 +1,50 @@
1
+ // @flow
2
+
3
+ import * as React from "react";
4
+ export type AspectRatio = "1:1" | "16:9" | "12:5";
5
+ declare export var RATIO: {
6
+ "1:1": number,
7
+ "16:9": number,
8
+ "12:5": number,
9
+ };
10
+ declare type VideoSource = {
11
+ src: string,
12
+ type?: string,
13
+ };
14
+ export type VideoProps = {
15
+ /**
16
+ * defaults to 100% when no width and no height are given
17
+ */
18
+ width?: number,
19
+ height?: number,
20
+ /**
21
+ * defaults to 1:1, if both width and height are given, aspectRatio is ignored
22
+ */
23
+ aspectRatio?: AspectRatio,
24
+ /**
25
+ * accepts multiple sources
26
+ */
27
+ src: string | Array<string> | VideoSource | Array<VideoSource>,
28
+ /**
29
+ * defaults to true
30
+ */
31
+ loop?: boolean,
32
+ /**
33
+ * defaults to true
34
+ */
35
+ muted?: boolean,
36
+ /**
37
+ * defaults to true
38
+ */
39
+ autoPlay?: boolean,
40
+ poster?: string,
41
+ /**
42
+ * defaults to none
43
+ */
44
+ preload?: "none" | "metadata" | "auto",
45
+ };
46
+ declare var Video: React.ComponentType<{
47
+ ...VideoProps,
48
+ ref?: React.Ref<HTMLVideoElement>,
49
+ }>;
50
+ declare export default typeof Video;
@@ -4,6 +4,7 @@ import { createUseStyles } from './jss';
4
4
  import { useScreenSize, useIsomorphicLayoutEffect } from './hooks';
5
5
  import { BUTTON_MIN_WIDTH, ButtonPrimary, ButtonSecondary, ButtonDanger } from './button';
6
6
  import classNames from 'classnames';
7
+ import debounce from 'lodash/debounce';
7
8
  function _arrayWithHoles(arr) {
8
9
  if (Array.isArray(arr)) return arr;
9
10
  }
@@ -174,28 +175,29 @@ var buttonsRange = [
174
175
  var ButtonLayout = function(param) {
175
176
  var children = param.children, _align = param.align, align = _align === void 0 ? 'full-width' : _align, link = param.link, _withMargins = param.withMargins, withMargins = _withMargins === void 0 ? false : _withMargins;
176
177
  var ref = useScreenSize(), isTabletOrSmaller = ref.isTabletOrSmaller;
177
- var ref1 = _slicedToArray(React.useState(true), 2), isMeasuring = ref1[0], setIsMeasuring = ref1[1];
178
178
  var childrenCount = React.Children.count(children);
179
- var ref2 = _slicedToArray(React.useState(0), 2), buttonWidth = ref2[0], setButtonWidth = ref2[1];
180
- var updateButtonWidth = function(buttonWidth) {
179
+ var ref1 = _slicedToArray(React.useState({
180
+ isMeasuring: true,
181
+ buttonWidth: 0
182
+ }), 2), buttonStatus = ref1[0], setButtonStatus = ref1[1];
183
+ var updateButtonStatus = function(param) {
184
+ var isMeasuring = param.isMeasuring, buttonWidth = param.buttonWidth;
181
185
  if (process.env.NODE_ENV !== 'test') {
182
- setButtonWidth(buttonWidth);
183
- }
184
- };
185
- var updateIsMeasuring = function(isMeasuring) {
186
- if (process.env.NODE_ENV !== 'test') {
187
- setIsMeasuring(isMeasuring);
186
+ setButtonStatus({
187
+ isMeasuring: isMeasuring,
188
+ buttonWidth: buttonWidth
189
+ });
188
190
  }
189
191
  };
190
192
  var classes = useStyles({
191
- buttonWidth: buttonWidth,
193
+ buttonWidth: buttonStatus.buttonWidth,
192
194
  isTabletOrSmaller: isTabletOrSmaller,
193
195
  align: align,
194
196
  childrenCount: childrenCount
195
197
  });
196
198
  var wrapperElRef = React.useRef(null);
197
199
  useIsomorphicLayoutEffect(function() {
198
- if (isMeasuring) {
200
+ if (buttonStatus.isMeasuring) {
199
201
  var req = window.requestAnimationFrame(function() {
200
202
  if (wrapperElRef.current) {
201
203
  var childrenWidths = Array.from(wrapperElRef.current.children).map(function(el) {
@@ -210,8 +212,10 @@ var ButtonLayout = function(param) {
210
212
  var maxChildWidth = Math.ceil((_Math = Math).max.apply(_Math, _toConsumableArray(childrenWidths).concat([
211
213
  BUTTON_MIN_WIDTH
212
214
  ])));
213
- updateButtonWidth(maxChildWidth);
214
- updateIsMeasuring(false);
215
+ updateButtonStatus({
216
+ isMeasuring: false,
217
+ buttonWidth: maxChildWidth
218
+ });
215
219
  }
216
220
  });
217
221
  return function() {
@@ -222,11 +226,18 @@ var ButtonLayout = function(param) {
222
226
  };
223
227
  }, [
224
228
  classes.link,
225
- isMeasuring
229
+ buttonStatus
226
230
  ]);
227
- var calcLayout = React.useCallback(function() {
228
- updateButtonWidth(0);
229
- updateIsMeasuring(true);
231
+ /**
232
+ * Multiple calls to calcLayout are debounced to workaround an issue that can be reproduced in chrome when pressing
233
+ * the button during a focus/visibility change. For example, pressing the button having the focus on the devTools.
234
+ */ var calcLayout = React.useMemo(function() {
235
+ return debounce(function() {
236
+ updateButtonStatus({
237
+ isMeasuring: true,
238
+ buttonWidth: 0
239
+ });
240
+ }, 50);
230
241
  }, []);
231
242
  useOnChildrenChangeEffect(wrapperElRef.current, calcLayout);
232
243
  useOnFontsReadyEffect(calcLayout);
package/dist-es/button.js CHANGED
@@ -361,6 +361,11 @@ var Button = function(props) {
361
361
  disabled: props.disabled || showSpinner || isFormSending,
362
362
  role: 'button'
363
363
  };
364
+ if (process.env.NODE_ENV !== 'production') {
365
+ if (props.to === '' || props.href === '') {
366
+ throw Error('to or href props are empty strings');
367
+ }
368
+ }
364
369
  if (props.fake) {
365
370
  return(/*#__PURE__*/ _jsx(Touchable, _objectSpread({
366
371
  maybe: true
@@ -384,22 +389,25 @@ var Button = function(props) {
384
389
  onPress: props.onPress
385
390
  })));
386
391
  }
387
- if (props.to) {
392
+ if (props.to || props.to === '') {
388
393
  return(/*#__PURE__*/ _jsx(Touchable, _objectSpread({
389
394
  }, commonProps, {
390
395
  to: props.to,
391
396
  fullPageOnWebView: props.fullPageOnWebView
392
397
  })));
393
398
  }
394
- if (props.href) {
399
+ if (props.href || props.href === '') {
395
400
  return(/*#__PURE__*/ _jsx(Touchable, _objectSpread({
396
401
  }, commonProps, {
397
402
  href: props.href,
398
403
  newTab: props.newTab
399
404
  })));
400
405
  }
401
- // this cannot happen
402
- throw Error('Bad button props');
406
+ if (process.env.NODE_ENV !== 'production') {
407
+ // this cannot happen
408
+ throw Error('Bad button props');
409
+ }
410
+ return null;
403
411
  };
404
412
  var useButtonLinkStyles = createUseStyles(function(theme) {
405
413
  var padding = 6;
@@ -456,6 +464,11 @@ export var ButtonLink = /*#__PURE__*/ React.forwardRef(function(props, ref) {
456
464
  children: props.children
457
465
  })
458
466
  };
467
+ if (process.env.NODE_ENV !== 'production') {
468
+ if (props.to === '' || props.href === '') {
469
+ throw Error('to or href props are empty strings');
470
+ }
471
+ }
459
472
  if (props.onPress) {
460
473
  return(/*#__PURE__*/ _jsx(Touchable, _objectSpread({
461
474
  ref: ref
@@ -463,7 +476,7 @@ export var ButtonLink = /*#__PURE__*/ React.forwardRef(function(props, ref) {
463
476
  onPress: props.onPress
464
477
  })));
465
478
  }
466
- if (props.to) {
479
+ if (props.to || props.to === '') {
467
480
  return(/*#__PURE__*/ _jsx(Touchable, _objectSpread({
468
481
  ref: ref
469
482
  }, commonProps, {
@@ -471,7 +484,7 @@ export var ButtonLink = /*#__PURE__*/ React.forwardRef(function(props, ref) {
471
484
  fullPageOnWebView: props.fullPageOnWebView
472
485
  })));
473
486
  }
474
- if (props.href) {
487
+ if (props.href || props.href === '') {
475
488
  return(/*#__PURE__*/ _jsx(Touchable, _objectSpread({
476
489
  ref: ref
477
490
  }, commonProps, {
@@ -479,8 +492,11 @@ export var ButtonLink = /*#__PURE__*/ React.forwardRef(function(props, ref) {
479
492
  newTab: props.newTab
480
493
  })));
481
494
  }
482
- // this cannot happen
483
- throw Error('Bad button props');
495
+ if (process.env.NODE_ENV !== 'production') {
496
+ // this cannot happen
497
+ throw Error('Bad button props');
498
+ }
499
+ return null;
484
500
  });
485
501
  export var ButtonPrimary = function(props) {
486
502
  var classes = usePrimaryButtonStyles();