@telefonica/mistica 12.5.0 → 12.7.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 (79) hide show
  1. package/dist/carousel.js +5 -3
  2. package/dist/dialog.d.ts +20 -5
  3. package/dist/dialog.js +39 -14
  4. package/dist/dialog.js.flow +24 -7
  5. package/dist/fixed-footer-layout.js +31 -9
  6. package/dist/generated/mistica-icons/icon-buy-data-light.js +5 -11
  7. package/dist/generated/mistica-icons/icon-buy-data-regular.js +1 -1
  8. package/dist/generated/mistica-icons/icon-eco-light.js +1 -1
  9. package/dist/generated/mistica-icons/icon-justice-regular.js +1 -1
  10. package/dist/generated/mistica-icons/icon-tokens-filled.d.ts +4 -0
  11. package/dist/generated/mistica-icons/icon-tokens-filled.js +109 -0
  12. package/dist/generated/mistica-icons/icon-tokens-filled.js.flow +6 -0
  13. package/dist/generated/mistica-icons/icon-tokens-light.d.ts +4 -0
  14. package/dist/generated/mistica-icons/icon-tokens-light.js +109 -0
  15. package/dist/generated/mistica-icons/icon-tokens-light.js.flow +6 -0
  16. package/dist/generated/mistica-icons/icon-tokens-regular.d.ts +4 -0
  17. package/dist/generated/mistica-icons/icon-tokens-regular.js +109 -0
  18. package/dist/generated/mistica-icons/icon-tokens-regular.js.flow +6 -0
  19. package/dist/hooks.d.ts +3 -0
  20. package/dist/hooks.js +16 -3
  21. package/dist/hooks.js.flow +3 -0
  22. package/dist/image.d.ts +2 -0
  23. package/dist/image.js +118 -80
  24. package/dist/image.js.flow +2 -0
  25. package/dist/index.d.ts +4 -0
  26. package/dist/index.js +28 -0
  27. package/dist/index.js.flow +4 -0
  28. package/dist/navigation-bar.js +7 -9
  29. package/dist/package-version.js +1 -1
  30. package/dist/skeletons.d.ts +5 -2
  31. package/dist/skeletons.js +50 -87
  32. package/dist/skeletons.js.flow +4 -4
  33. package/dist/skins/o2.js +1 -1
  34. package/dist/text-field-base.d.ts +0 -1
  35. package/dist/text-field-base.js +23 -5
  36. package/dist/text-field-base.js.flow +0 -1
  37. package/dist/text-field-components.d.ts +1 -0
  38. package/dist/text-field-components.js +7 -3
  39. package/dist/text-field-components.js.flow +1 -0
  40. package/dist/text-link.js +2 -1
  41. package/dist/theme.d.ts +2 -0
  42. package/dist/theme.js +2 -1
  43. package/dist/theme.js.flow +2 -0
  44. package/dist/tooltip.d.ts +2 -0
  45. package/dist/tooltip.js +234 -78
  46. package/dist/tooltip.js.flow +2 -0
  47. package/dist/touchable.d.ts +1 -0
  48. package/dist/touchable.js +6 -1
  49. package/dist/touchable.js.flow +1 -0
  50. package/dist/utils/aspect-ratio-support.d.ts +10 -0
  51. package/dist/utils/aspect-ratio-support.js +115 -1
  52. package/dist/utils/aspect-ratio-support.js.flow +14 -0
  53. package/dist/video.js +20 -79
  54. package/dist-es/carousel.js +5 -3
  55. package/dist-es/dialog.js +40 -15
  56. package/dist-es/fixed-footer-layout.js +32 -10
  57. package/dist-es/generated/mistica-icons/icon-buy-data-light.js +6 -12
  58. package/dist-es/generated/mistica-icons/icon-buy-data-regular.js +1 -1
  59. package/dist-es/generated/mistica-icons/icon-eco-light.js +1 -1
  60. package/dist-es/generated/mistica-icons/icon-justice-regular.js +1 -1
  61. package/dist-es/generated/mistica-icons/icon-tokens-filled.js +85 -0
  62. package/dist-es/generated/mistica-icons/icon-tokens-light.js +85 -0
  63. package/dist-es/generated/mistica-icons/icon-tokens-regular.js +85 -0
  64. package/dist-es/hooks.js +14 -2
  65. package/dist-es/image.js +115 -83
  66. package/dist-es/index.js +4 -0
  67. package/dist-es/navigation-bar.js +7 -9
  68. package/dist-es/package-version.js +1 -1
  69. package/dist-es/skeletons.js +50 -87
  70. package/dist-es/skins/o2.js +1 -1
  71. package/dist-es/text-field-base.js +25 -7
  72. package/dist-es/text-field-components.js +7 -3
  73. package/dist-es/text-link.js +3 -1
  74. package/dist-es/theme.js +2 -1
  75. package/dist-es/tooltip.js +234 -78
  76. package/dist-es/touchable.js +6 -1
  77. package/dist-es/utils/aspect-ratio-support.js +112 -0
  78. package/dist-es/video.js +21 -81
  79. package/package.json +2 -1
package/dist/tooltip.js CHANGED
@@ -6,11 +6,14 @@ exports.default = void 0;
6
6
  var _jsxRuntime = require("react/jsx-runtime");
7
7
  var React = _interopRequireWildcard(require("react"));
8
8
  var _classnames = _interopRequireDefault(require("classnames"));
9
+ var _reactTransitionGroup = require("react-transition-group");
9
10
  var _hooks = require("./hooks");
10
11
  var _portal = require("./portal");
11
12
  var _overlay = _interopRequireDefault(require("./overlay"));
13
+ var _text = require("./text");
12
14
  var key = _interopRequireWildcard(require("./utils/key-codes"));
13
15
  var _jss = require("./jss");
16
+ var _stack = _interopRequireDefault(require("./stack"));
14
17
  function _interopRequireDefault(obj) {
15
18
  return obj && obj.__esModule ? obj : {
16
19
  default: obj
@@ -142,11 +145,16 @@ function _unsupportedIterableToArray(o, minLen) {
142
145
  var defaultPositionDesktop = "bottom";
143
146
  var defaultPositionMobile = "top";
144
147
  var arrowSize = 12;
145
- var distanceToTarget = 8 + arrowSize;
148
+ var distanceToTarget = 4 + arrowSize;
146
149
  var marginLeftRightMobile = 16;
147
150
  var defaultWidthDesktop = 340;
148
151
  var arrowWrapperWidth = arrowSize * 2;
149
152
  var arrowWrapperHeight = arrowSize;
153
+ var transitionDurationMs = 500;
154
+ var animationMovement = 12;
155
+ var animationTiming = "cubic-bezier(0.215, 0.61, 0.355, 1)";
156
+ var defaultShowTooltipDelayMs = 500;
157
+ var noOp = function noOp() {};
150
158
  var useStyles = (0, _jss).createUseStyles(function(theme) {
151
159
  var shadowAlpha = theme.isDarkMode ? 1 : 0.2;
152
160
  return {
@@ -158,7 +166,7 @@ var useStyles = (0, _jss).createUseStyles(function(theme) {
158
166
  top: 0,
159
167
  left: "50%",
160
168
  transform: "translate(-50%, -50%) rotate(45deg)",
161
- border: "1px solid ".concat(theme.colors.divider),
169
+ border: "1px solid ".concat(theme.colors.border),
162
170
  borderRadius: 2
163
171
  },
164
172
  arrowTop: {
@@ -207,42 +215,142 @@ var useStyles = (0, _jss).createUseStyles(function(theme) {
207
215
  left: 16,
208
216
  width: "auto",
209
217
  boxShadow: "0 2px 4px 0 rgba(0, 0, 0, ".concat(shadowAlpha, ")"),
210
- padding: 16,
218
+ padding: 8,
211
219
  backgroundColor: theme.colors.backgroundContainer,
212
- zIndex: 12,
213
- border: "1px solid ".concat(theme.colors.divider),
220
+ zIndex: 50,
221
+ border: "1px solid ".concat(theme.colors.border),
214
222
  borderRadius: 8
223
+ }
224
+ };
225
+ });
226
+ var useAnimationStyles = (0, _jss).createUseStyles(function() {
227
+ return {
228
+ enter: {
229
+ transform: function transform(param) {
230
+ var position = param.position;
231
+ if (position === "bottom") {
232
+ return "translateY(".concat(animationMovement, "px)");
233
+ }
234
+ if (position === "top") {
235
+ return "translateY(calc(-100% - ".concat(animationMovement, "px))");
236
+ }
237
+ if (position === "right") {
238
+ return "translateX(".concat(animationMovement, "px) translateY(-50%)");
239
+ }
240
+ if (position === "left") {
241
+ return "translateX(-".concat(animationMovement, "px) translateY(-50%)");
242
+ }
243
+ return "translateY(-".concat(animationMovement, "px)");
244
+ }
245
+ },
246
+ enterActive: {
247
+ animationName: function animationName(param) {
248
+ var position = param.position;
249
+ if (position === "top") return "$fadeInTop";
250
+ if (position === "bottom") return "$fadeInBottom";
251
+ return "$fadeInX";
252
+ },
253
+ animationFillMode: "both",
254
+ animationDuration: "".concat(transitionDurationMs, "ms"),
255
+ animationTimingFunction: animationTiming
256
+ },
257
+ enterDone: {
258
+ transform: function transform(param) {
259
+ var position = param.position;
260
+ if (position === "top") return "translateY(-100%)";
261
+ if (position === "bottom") return "translateY(0)";
262
+ return "translateY(-50%)";
263
+ }
215
264
  },
216
- title: {
217
- margin: 0,
218
- marginBottom: 12,
219
- color: theme.colors.textPrimary,
220
- lineHeight: 1.42857142,
221
- fontSize: 14
265
+ exit: {
266
+ transform: function transform(param) {
267
+ var position = param.position;
268
+ if (position === "bottom") {
269
+ return "translateY(0)";
270
+ }
271
+ if (position === "top") {
272
+ return "translateY(-100%)";
273
+ }
274
+ if (position === "right") {
275
+ return "translateX(0px) translateY(-50%)";
276
+ }
277
+ if (position === "left") {
278
+ return "translateX(0px) translateY(-50%)";
279
+ }
280
+ return "translateY(0px)";
281
+ },
282
+ opacity: 1,
283
+ transition: "opacity 0.3s ".concat(animationTiming)
284
+ },
285
+ exitActive: {
286
+ animation: "$fadeOut 0.3s ".concat(animationTiming, " both")
222
287
  },
223
- description: {
224
- margin: 0,
225
- color: theme.colors.textPrimary,
226
- lineHeight: 1.42857142,
227
- fontSize: 14
288
+ "@keyframes fadeInBottom": {
289
+ from: {
290
+ opacity: 0
291
+ },
292
+ "40%": {
293
+ opacity: 1
294
+ },
295
+ to: {
296
+ opacity: 1,
297
+ transform: "translateY(0)"
298
+ }
299
+ },
300
+ "@keyframes fadeInTop": {
301
+ from: {
302
+ opacity: 0
303
+ },
304
+ "40%": {
305
+ opacity: 1
306
+ },
307
+ to: {
308
+ opacity: 1,
309
+ transform: "translateY(-100%)"
310
+ }
311
+ },
312
+ "@keyframes fadeInX": {
313
+ from: {
314
+ opacity: 0
315
+ },
316
+ "40%": {
317
+ opacity: 1
318
+ },
319
+ to: {
320
+ opacity: 1,
321
+ transform: "translateX(0) translateY(-50%)"
322
+ }
323
+ },
324
+ "@keyframes fadeOut": {
325
+ from: {
326
+ opacity: 1
327
+ },
328
+ to: {
329
+ opacity: 0
330
+ }
228
331
  }
229
332
  };
230
333
  });
231
334
  var getWidthDesktop = function getWidthDesktop(customWidth) {
232
335
  return customWidth ? customWidth : defaultWidthDesktop;
233
336
  };
234
- var EVENT_THROTTLE_TIME = process.env.NODE_ENV === "test" ? 0 : 200;
235
337
  var Tooltip = function Tooltip(_param) {
236
- var children = _param.children, description = _param.description, target = _param.target, title = _param.title, targetLabel = _param.targetLabel, rest = _objectWithoutProperties(_param, [
338
+ var children = _param.children, extra = _param.extra, description = _param.description, target = _param.target, title = _param.title, targetLabel = _param.targetLabel, _delay = _param.delay, delay = _delay === void 0 ? true : _delay, rest = _objectWithoutProperties(_param, [
237
339
  "children",
340
+ "extra",
238
341
  "description",
239
342
  "target",
240
343
  "title",
241
- "targetLabel"
344
+ "targetLabel",
345
+ "delay"
242
346
  ]);
243
347
  var ref = _slicedToArray(React.useState(false), 2), isVisible = ref[0], setIsVisible = ref[1];
244
348
  var isTabletOrSmaller = (0, _hooks).useScreenSize().isTabletOrSmaller;
245
349
  var ariaId = (0, _hooks).useAriaId();
350
+ var isPointerOver = React.useRef(false);
351
+ var closeTooltipTimeoutId = React.useRef(null);
352
+ var showTooltipTimeoutId = React.useRef(null);
353
+ var targetRef = React.useRef(null);
246
354
  var targetBoundingClientRect = React.useRef({
247
355
  top: 0,
248
356
  right: 0,
@@ -251,10 +359,16 @@ var Tooltip = function Tooltip(_param) {
251
359
  width: 0,
252
360
  height: 0
253
361
  });
254
- // This property is needed because safari is making a mess with the events (it has problems
255
- // when the overlay layer appears and disappears). This way we ensure that events don't get handled twice
256
- var lastChangeTime = React.useRef(0);
362
+ var getPosition = function getPosition() {
363
+ var position = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : defaultPositionDesktop;
364
+ return isTabletOrSmaller && (position === "left" || position === "right") ? defaultPositionMobile : position;
365
+ };
366
+ var position1 = getPosition(rest.position);
257
367
  var classes = useStyles();
368
+ var animationClasses = useAnimationStyles({
369
+ position: position1
370
+ });
371
+ var isTouchableDevice = typeof window !== "undefined" ? window.matchMedia("(pointer: coarse)").matches : false;
258
372
  var closeTooltip = function closeTooltip() {
259
373
  if (isVisible) {
260
374
  setIsVisible(false);
@@ -267,23 +381,16 @@ var Tooltip = function Tooltip(_param) {
267
381
  };
268
382
  });
269
383
  var handleClickOutside = function handleClickOutside() {
270
- if (Date.now() - lastChangeTime.current < EVENT_THROTTLE_TIME) {
271
- return;
272
- }
273
- lastChangeTime.current = Date.now();
274
384
  setIsVisible(false);
275
385
  };
276
- var toggleVisibility = function toggleVisibility(e) {
277
- if (Date.now() - lastChangeTime.current < EVENT_THROTTLE_TIME) {
278
- return;
279
- }
280
- lastChangeTime.current = Date.now();
281
- targetBoundingClientRect.current = e.currentTarget.getBoundingClientRect();
386
+ var toggleVisibility = function toggleVisibility() {
387
+ if (!targetRef.current) return;
388
+ targetBoundingClientRect.current = targetRef.current.getBoundingClientRect();
282
389
  setIsVisible(!isVisible);
283
390
  };
284
- var handleFocus = function handleFocus(e) {
391
+ var handleFocus = function handleFocus() {
285
392
  if (!isVisible) {
286
- toggleVisibility(e);
393
+ toggleVisibility();
287
394
  }
288
395
  };
289
396
  var handleKeyDown = function handleKeyDown(event) {
@@ -292,22 +399,19 @@ var Tooltip = function Tooltip(_param) {
292
399
  }
293
400
  };
294
401
  var getContainerPosition = function getContainerPosition(position, width) {
402
+ if (typeof window === "undefined") {
403
+ return {};
404
+ }
295
405
  var containerPos = {
296
406
  right: {
297
407
  left: targetBoundingClientRect.current.right + distanceToTarget,
298
- top: window.pageYOffset + targetBoundingClientRect.current.top + targetBoundingClientRect.current.height / 2,
299
- transform: "translateY(-50%)",
300
- WebKitTransform: "translateY(-50%)"
408
+ top: window.pageYOffset + targetBoundingClientRect.current.top + targetBoundingClientRect.current.height / 2
301
409
  },
302
410
  left: {
303
411
  left: targetBoundingClientRect.current.left - width - distanceToTarget,
304
- top: window.pageYOffset + targetBoundingClientRect.current.top + targetBoundingClientRect.current.height / 2,
305
- transform: "translateY(-50%)",
306
- WebKitTransform: "translateY(-50%)"
412
+ top: window.pageYOffset + targetBoundingClientRect.current.top + targetBoundingClientRect.current.height / 2
307
413
  },
308
414
  top: {
309
- transform: "translateY(-100%)",
310
- WebKitTransform: "translateY(-100%)",
311
415
  top: window.pageYOffset + targetBoundingClientRect.current.top - distanceToTarget,
312
416
  left: isTabletOrSmaller ? marginLeftRightMobile : window.pageXOffset + targetBoundingClientRect.current.left + targetBoundingClientRect.current.width / 2 - width / 2
313
417
  },
@@ -318,10 +422,6 @@ var Tooltip = function Tooltip(_param) {
318
422
  };
319
423
  return containerPos[position];
320
424
  };
321
- var getPosition = function getPosition() {
322
- var position = arguments.length > 0 && arguments[0] !== void 0 ? arguments[0] : defaultPositionDesktop;
323
- return isTabletOrSmaller && (position === "left" || position === "right") ? defaultPositionMobile : position;
324
- };
325
425
  var getCustomStylesForMobile = function getCustomStylesForMobile() {
326
426
  return isTabletOrSmaller ? {
327
427
  left: targetBoundingClientRect.current.left + targetBoundingClientRect.current.width / 2 - marginLeftRightMobile
@@ -330,7 +430,6 @@ var Tooltip = function Tooltip(_param) {
330
430
  var getWidth = function getWidth() {
331
431
  return isTabletOrSmaller ? window.innerWidth - marginLeftRightMobile * 2 : getWidthDesktop(rest.width);
332
432
  };
333
- var position1 = getPosition(rest.position);
334
433
  var width1 = getWidth();
335
434
  var classNameByPosition = {
336
435
  top: classes.arrowTop,
@@ -341,8 +440,38 @@ var Tooltip = function Tooltip(_param) {
341
440
  return /*#__PURE__*/ (0, _jsxRuntime).jsxs(_jsxRuntime.Fragment, {
342
441
  children: [
343
442
  /*#__PURE__*/ (0, _jsxRuntime).jsx("div", {
443
+ ref: targetRef,
344
444
  className: classes.wrapper,
345
- onPointerDown: toggleVisibility,
445
+ onPointerOver: function onPointerOver() {
446
+ if (closeTooltipTimeoutId.current) {
447
+ clearTimeout(closeTooltipTimeoutId.current);
448
+ closeTooltipTimeoutId.current = null;
449
+ }
450
+ if (isPointerOver.current) return;
451
+ isPointerOver.current = true;
452
+ if (delay) {
453
+ showTooltipTimeoutId.current = setTimeout(function() {
454
+ showTooltipTimeoutId.current = null;
455
+ toggleVisibility();
456
+ }, defaultShowTooltipDelayMs);
457
+ } else {
458
+ toggleVisibility();
459
+ }
460
+ },
461
+ onPointerLeave: isTouchableDevice ? noOp : function() {
462
+ if (showTooltipTimeoutId.current) {
463
+ clearTimeout(showTooltipTimeoutId.current);
464
+ showTooltipTimeoutId.current = null;
465
+ isPointerOver.current = false;
466
+ return;
467
+ }
468
+ closeTooltipTimeoutId.current = setTimeout(function() {
469
+ if (!isPointerOver.current) return;
470
+ closeTooltipTimeoutId.current = null;
471
+ isPointerOver.current = false;
472
+ toggleVisibility();
473
+ }, 100);
474
+ },
346
475
  onFocus: handleFocus,
347
476
  onKeyDown: handleKeyDown,
348
477
  "touch-action": "auto" // Prop needed for Pointer Events Polyfill to work properly
@@ -354,40 +483,67 @@ var Tooltip = function Tooltip(_param) {
354
483
  "aria-label": targetLabel,
355
484
  children: target
356
485
  }),
357
- isVisible && /*#__PURE__*/ (0, _jsxRuntime).jsxs(_portal.Portal, {
486
+ /*#__PURE__*/ (0, _jsxRuntime).jsxs(_portal.Portal, {
358
487
  children: [
359
- /*#__PURE__*/ (0, _jsxRuntime).jsx(_overlay.default, {
488
+ isVisible && isTouchableDevice && /*#__PURE__*/ (0, _jsxRuntime).jsx(_overlay.default, {
360
489
  onPress: handleClickOutside
361
490
  }),
362
- /*#__PURE__*/ (0, _jsxRuntime).jsxs("div", {
363
- role: "tooltip",
364
- id: ariaId,
365
- className: classes.container,
366
- style: _objectSpread({
367
- width: width1
368
- }, getContainerPosition(position1, width1)),
369
- children: [
370
- /*#__PURE__*/ (0, _jsxRuntime).jsx("div", {
371
- className: (0, _classnames).default(classes.arrowWrapper, classNameByPosition[position1]),
372
- style: getCustomStylesForMobile(),
373
- children: /*#__PURE__*/ (0, _jsxRuntime).jsx("div", {
374
- className: classes.arrow
375
- })
376
- }),
377
- (title || description) && /*#__PURE__*/ (0, _jsxRuntime).jsxs(_jsxRuntime.Fragment, {
378
- children: [
379
- title && /*#__PURE__*/ (0, _jsxRuntime).jsx("p", {
380
- className: classes.title,
381
- children: title
382
- }),
383
- description && /*#__PURE__*/ (0, _jsxRuntime).jsx("p", {
384
- className: classes.description,
385
- children: description
491
+ /*#__PURE__*/ (0, _jsxRuntime).jsx(_reactTransitionGroup.CSSTransition, {
492
+ in: isVisible,
493
+ timeout: transitionDurationMs,
494
+ classNames: {
495
+ enter: animationClasses.enter,
496
+ enterActive: animationClasses.enterActive,
497
+ enterDone: animationClasses.enterDone,
498
+ exit: animationClasses.exit,
499
+ exitActive: animationClasses.exitActive
500
+ },
501
+ unmountOnExit: true,
502
+ children: /*#__PURE__*/ (0, _jsxRuntime).jsxs("div", {
503
+ role: "tooltip",
504
+ id: ariaId,
505
+ className: classes.container,
506
+ style: _objectSpread({
507
+ width: width1
508
+ }, getContainerPosition(position1, width1)),
509
+ onPointerOver: function onPointerOver() {
510
+ if (closeTooltipTimeoutId.current) {
511
+ clearTimeout(closeTooltipTimeoutId.current);
512
+ closeTooltipTimeoutId.current = null;
513
+ }
514
+ },
515
+ onPointerLeave: isTouchableDevice ? noOp : function() {
516
+ closeTooltipTimeoutId.current = setTimeout(function() {
517
+ if (!isPointerOver.current) return;
518
+ closeTooltipTimeoutId.current = null;
519
+ isPointerOver.current = false;
520
+ toggleVisibility();
521
+ }, 100);
522
+ },
523
+ children: [
524
+ /*#__PURE__*/ (0, _jsxRuntime).jsx("div", {
525
+ className: (0, _classnames).default(classes.arrowWrapper, classNameByPosition[position1]),
526
+ style: getCustomStylesForMobile(),
527
+ children: /*#__PURE__*/ (0, _jsxRuntime).jsx("div", {
528
+ className: classes.arrow
386
529
  })
387
- ]
388
- }),
389
- children
390
- ]
530
+ }),
531
+ (title || description) && /*#__PURE__*/ (0, _jsxRuntime).jsxs(_stack.default, {
532
+ space: 4,
533
+ children: [
534
+ title && /*#__PURE__*/ (0, _jsxRuntime).jsx(_text.Text2, {
535
+ medium: true,
536
+ children: title
537
+ }),
538
+ description && /*#__PURE__*/ (0, _jsxRuntime).jsx(_text.Text2, {
539
+ regular: true,
540
+ children: description
541
+ })
542
+ ]
543
+ }),
544
+ extra || children
545
+ ]
546
+ })
391
547
  })
392
548
  ]
393
549
  })
@@ -4,12 +4,14 @@ import * as React from "react";
4
4
  declare type Position = "top" | "bottom" | "left" | "right";
5
5
  declare type Props = {
6
6
  children?: React.Node,
7
+ extra?: React.Node,
7
8
  description?: string,
8
9
  target: React.Node,
9
10
  title?: string,
10
11
  position?: Position,
11
12
  width?: number,
12
13
  targetLabel: string,
14
+ delay?: boolean,
13
15
  };
14
16
  declare var Tooltip: React.ComponentType<Props>;
15
17
  declare export default typeof Tooltip;
@@ -21,6 +21,7 @@ interface CommonProps {
21
21
  role?: string;
22
22
  type?: 'button' | 'submit';
23
23
  tabIndex?: number;
24
+ as?: 'a';
24
25
  }
25
26
  export interface PropsHref extends CommonProps {
26
27
  href: string;
package/dist/touchable.js CHANGED
@@ -237,7 +237,12 @@ var Touchable = /*#__PURE__*/ React.forwardRef(function(props, ref) {
237
237
  }));
238
238
  }
239
239
  if (props.onPress) {
240
- return /*#__PURE__*/ (0, _jsxRuntime).jsx("button", _objectSpread({}, commonProps, {
240
+ var _as;
241
+ var elementType = (_as = props.as) !== null && _as !== void 0 ? _as : "button";
242
+ var _role;
243
+ var role = (_role = commonProps.role) !== null && _role !== void 0 ? _role : props.as === "a" ? "button" : undefined;
244
+ return /*#__PURE__*/ React.createElement(elementType, _objectSpread({}, commonProps, {
245
+ role: role,
241
246
  // this "form" attribute is useful when the form's submit button
242
247
  // is located outside the <form> element, for example if you use
243
248
  // a ButtonFixedFooter layout inside a form with the submit
@@ -26,6 +26,7 @@ declare type CommonProps = {
26
26
  role?: string,
27
27
  type?: "button" | "submit",
28
28
  tabIndex?: number,
29
+ as?: "a",
29
30
  };
30
31
  export type PropsHref = {
31
32
  ...$Exact<CommonProps>,
@@ -4,4 +4,14 @@ declare type Props = {
4
4
  };
5
5
  export declare const AspectRatioSupportProvider: React.FC<Props>;
6
6
  export declare const useSupportsAspectRatio: () => boolean;
7
+ declare type AspectRatioElementProps = {
8
+ width?: number | string;
9
+ height?: number | string;
10
+ aspectRatio: number;
11
+ children: React.ReactNode;
12
+ as?: React.ComponentType<any> | string;
13
+ style?: React.CSSProperties;
14
+ className?: string;
15
+ };
16
+ export declare const AspectRatioElement: (props: AspectRatioElementProps) => JSX.Element;
7
17
  export {};
@@ -2,10 +2,11 @@
2
2
  Object.defineProperty(exports, "__esModule", {
3
3
  value: true
4
4
  });
5
- exports.useSupportsAspectRatio = exports.AspectRatioSupportProvider = void 0;
5
+ exports.AspectRatioElement = exports.useSupportsAspectRatio = exports.AspectRatioSupportProvider = void 0;
6
6
  var _jsxRuntime = require("react/jsx-runtime");
7
7
  var React = _interopRequireWildcard(require("react"));
8
8
  var _hooks = require("../hooks");
9
+ var _jss = require("../jss");
9
10
  function _interopRequireWildcard(obj) {
10
11
  if (obj && obj.__esModule) {
11
12
  return obj;
@@ -35,6 +36,19 @@ function _arrayLikeToArray(arr, len) {
35
36
  function _arrayWithHoles(arr) {
36
37
  if (Array.isArray(arr)) return arr;
37
38
  }
39
+ function _defineProperty(obj, key, value) {
40
+ if (key in obj) {
41
+ Object.defineProperty(obj, key, {
42
+ value: value,
43
+ enumerable: true,
44
+ configurable: true,
45
+ writable: true
46
+ });
47
+ } else {
48
+ obj[key] = value;
49
+ }
50
+ return obj;
51
+ }
38
52
  function _iterableToArrayLimit(arr, i) {
39
53
  var _i = arr == null ? null : typeof Symbol !== "undefined" && arr[Symbol.iterator] || arr["@@iterator"];
40
54
  if (_i == null) return;
@@ -62,6 +76,22 @@ function _iterableToArrayLimit(arr, i) {
62
76
  function _nonIterableRest() {
63
77
  throw new TypeError("Invalid attempt to destructure non-iterable instance.\\nIn order to be iterable, non-array objects must have a [Symbol.iterator]() method.");
64
78
  }
79
+ function _objectSpread(target) {
80
+ var _arguments = arguments, _loop = function(i) {
81
+ var source = _arguments[i] != null ? _arguments[i] : {};
82
+ var ownKeys = Object.keys(source);
83
+ if (typeof Object.getOwnPropertySymbols === "function") {
84
+ ownKeys = ownKeys.concat(Object.getOwnPropertySymbols(source).filter(function(sym) {
85
+ return Object.getOwnPropertyDescriptor(source, sym).enumerable;
86
+ }));
87
+ }
88
+ ownKeys.forEach(function(key) {
89
+ _defineProperty(target, key, source[key]);
90
+ });
91
+ };
92
+ for(var i = 1; i < arguments.length; i++)_loop(i);
93
+ return target;
94
+ }
65
95
  function _slicedToArray(arr, i) {
66
96
  return _arrayWithHoles(arr) || _iterableToArrayLimit(arr, i) || _unsupportedIterableToArray(arr, i) || _nonIterableRest();
67
97
  }
@@ -98,3 +128,87 @@ var useSupportsAspectRatio = function useSupportsAspectRatio() {
98
128
  return React.useContext(AspectRatioSupport);
99
129
  };
100
130
  exports.useSupportsAspectRatio = useSupportsAspectRatio;
131
+ var useAspectRatioStyles = (0, _jss).createUseStyles(function() {
132
+ return {
133
+ container: {
134
+ "@supports (aspect-ratio: 1 / 1)": {
135
+ aspectRatio: function aspectRatio(param) {
136
+ var aspectRatio1 = param.aspectRatio;
137
+ return aspectRatio1 !== null && aspectRatio1 !== void 0 ? aspectRatio1 : "unset";
138
+ }
139
+ },
140
+ "$wrapper &": {
141
+ position: function position(param) {
142
+ var aspectRatio = param.aspectRatio;
143
+ return aspectRatio ? "absolute" : "static";
144
+ },
145
+ width: "100%",
146
+ height: "100%",
147
+ top: 0,
148
+ left: 0
149
+ }
150
+ },
151
+ wrapper: {
152
+ overflow: "hidden",
153
+ maxWidth: "100%",
154
+ maxHeight: "100%",
155
+ position: "relative",
156
+ paddingTop: function paddingTop(param) {
157
+ var aspectRatio = param.aspectRatio, width = param.width;
158
+ if (!aspectRatio) {
159
+ return 0;
160
+ }
161
+ if (width && typeof width === "string" && width.endsWith("%")) {
162
+ return "".concat(Number(width.replace("%", "")) / aspectRatio, "%");
163
+ }
164
+ return "".concat(100 / aspectRatio, "%");
165
+ }
166
+ }
167
+ };
168
+ });
169
+ var AspectRatioElement = function AspectRatioElement(props) {
170
+ var supportsAspectRatio = useSupportsAspectRatio();
171
+ // if width or height are numeric, we can calculate the other with the ratio without css.
172
+ // if aspect ratio is 0, we use the original image proportions
173
+ var withCssAspectRatio = typeof props.width !== "number" && typeof props.height !== "number" && props.aspectRatio !== 0;
174
+ var classes = useAspectRatioStyles({
175
+ aspectRatio: withCssAspectRatio ? props.aspectRatio : undefined,
176
+ width: props.width
177
+ });
178
+ var width = props.width;
179
+ var height = props.height;
180
+ if (props.width !== undefined && props.height !== undefined) {
181
+ width = props.width;
182
+ height = props.height;
183
+ } else if (typeof props.width === "number") {
184
+ height = props.aspectRatio !== 0 ? props.width / props.aspectRatio : undefined;
185
+ } else if (typeof props.height === "number") {
186
+ width = props.aspectRatio !== 0 ? props.height * props.aspectRatio : undefined;
187
+ } else {
188
+ width = props.width || "100%";
189
+ }
190
+ var needsWrapper = withCssAspectRatio && !supportsAspectRatio;
191
+ var _as;
192
+ var container = /*#__PURE__*/ React.createElement((_as = props.as) !== null && _as !== void 0 ? _as : "div", {
193
+ className: props.className ? "".concat(props.className, " ").concat(classes.container) : classes.container,
194
+ style: _objectSpread({}, needsWrapper ? _objectSpread({}, props.style, {
195
+ width: "100%"
196
+ }) : _objectSpread({}, props.style, {
197
+ width: width,
198
+ height: height
199
+ }))
200
+ }, props.children);
201
+ if (needsWrapper) {
202
+ return /*#__PURE__*/ (0, _jsxRuntime).jsx("div", {
203
+ style: {
204
+ width: width,
205
+ height: height
206
+ },
207
+ className: classes.wrapper,
208
+ children: container
209
+ });
210
+ } else {
211
+ return container;
212
+ }
213
+ };
214
+ exports.AspectRatioElement = AspectRatioElement;
@@ -6,4 +6,18 @@ declare type Props = {
6
6
  };
7
7
  declare export var AspectRatioSupportProvider: React.ComponentType<Props>;
8
8
  declare export var useSupportsAspectRatio: () => boolean;
9
+ declare type AspectRatioElementProps = {
10
+ width?: number | string,
11
+ height?: number | string,
12
+ aspectRatio: number,
13
+ children: React.Node,
14
+ as?: React.ComponentType<any> | string,
15
+ style?: CssStyle,
16
+ className?: string,
17
+ };
18
+ declare export var AspectRatioElement: (
19
+ props: AspectRatioElementProps
20
+ ) => React.Node;
9
21
  declare export {};
22
+
23
+ import { type CssStyle } from "../__css_types__.js.flow";