@hero-design/rn 8.132.1 → 8.133.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.
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @hero-design/rn
2
2
 
3
+ ## 8.133.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [#5297](https://github.com/Thinkei/hero-design/pull/5297) [`bc5f4bb`](https://github.com/Thinkei/hero-design/commit/bc5f4bbaa7cba327b2d529a1960f5b6a3d0817dd) Thanks [@vinhphan-eh](https://github.com/vinhphan-eh)! - [AppCue] Add spotlight cut-out backdrop and controlled visibility (visible/onDismiss)
8
+
3
9
  ## 8.132.1
4
10
 
5
11
  ### Patch Changes
package/es/index.js CHANGED
@@ -5,9 +5,9 @@ import React__default, { useState, useEffect, useMemo, useCallback, useRef, useL
5
5
  import MaskedView from '@react-native-masked-view/masked-view';
6
6
  import { LinearGradient } from 'expo-linear-gradient';
7
7
  import { createIconSet } from 'react-native-vector-icons';
8
+ import Svg, { Defs, Mask, Rect, G, ForeignObject, Line as Line$1, Path as Path$1, Circle as Circle$1, ClipPath } from 'react-native-svg';
8
9
  import { useSafeAreaInsets, SafeAreaView } from 'react-native-safe-area-context';
9
10
  import { MonthYearPickerViewIOS, MonthYearPickerDialogueAndroid } from '@hero-design/react-native-month-year-picker';
10
- import Svg, { G, ForeignObject, Line as Line$1, Path as Path$1, Rect, Mask, Circle as Circle$1, Defs, ClipPath } from 'react-native-svg';
11
11
  import DateTimePicker from '@react-native-community/datetimepicker';
12
12
  import RnSlider from '@react-native-community/slider';
13
13
  import MultiSlider from '@ptomasroos/react-native-multi-slider';
@@ -7768,7 +7768,8 @@ var getAppCueTheme = function getAppCueTheme(theme) {
7768
7768
  arrowOffset: theme.space.smallMedium
7769
7769
  };
7770
7770
  var radii = {
7771
- container: theme.radii.large
7771
+ container: theme.radii.large,
7772
+ spotlight: theme.radii['5xlarge']
7772
7773
  };
7773
7774
  return {
7774
7775
  colors: colors,
@@ -9465,17 +9466,16 @@ var StyledContent$1 = index$c(View)(function (_ref) {
9465
9466
  alignSelf: 'center'
9466
9467
  };
9467
9468
  });
9468
- var StyledContainer$a = index$c(View)(function (_ref2) {
9469
- var theme = _ref2.theme;
9470
- return {
9471
- width: '100%',
9472
- height: '100%',
9473
- backgroundColor: theme.__hd__.appCue.colors.backdropColor
9474
- };
9469
+ var StyledModalContainer = index$c(View)({
9470
+ width: '100%',
9471
+ height: '100%'
9475
9472
  });
9476
- var StyledIconContainer$2 = index$c(Animated.View)(function (_ref3) {
9477
- var theme = _ref3.theme,
9478
- themePlacement = _ref3.themePlacement;
9473
+ var StyledContentPositioner = index$c(View)({
9474
+ position: 'absolute'
9475
+ });
9476
+ var StyledIconContainer$2 = index$c(Animated.View)(function (_ref2) {
9477
+ var theme = _ref2.theme,
9478
+ themePlacement = _ref2.themePlacement;
9479
9479
  return _objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2(_objectSpread2({
9480
9480
  position: 'absolute',
9481
9481
  color: theme.__hd__.appCue.colors.background,
@@ -9524,25 +9524,47 @@ var StyledIconContainer$2 = index$c(Animated.View)(function (_ref3) {
9524
9524
  });
9525
9525
  });
9526
9526
 
9527
- /**
9528
- * Calculates the position of an element based on its placement relative to a reference position.
9529
- *
9530
- * @param {Object} params - The parameters for calculating the position.
9531
- * @param {Object} params.position - The position and size of target element.
9532
- * @param {number} params.position.pageX - The X coordinate of the target position.
9533
- * @param {number} params.position.pageY - The Y coordinate of the target position.
9534
- * @param {number} params.position.width - The width of the reference element.
9535
- * @param {number} params.position.height - The height of the reference element.
9536
- * @param {Object} params.contentSize - The size of the App Cue content.
9537
- * @param {number} params.contentSize.width - The width of the content.
9538
- * @param {number} params.contentSize.height - The height of the content.
9539
- * @param {Placement} params.placement - The placement of the content relative to the reference position ('top', 'bottom', 'right', 'left').
9540
- * @param {number} params.offset - The offset distance to display an arrow.
9541
- *
9542
- * @returns {Object} The calculated position of the App Cue.
9543
- * @returns {number} return.x - The X coordinate of the App Cue.
9544
- * @returns {number} return.y - The Y coordinate of the App Cue.
9545
- */
9527
+ var SpotlightBackdrop = function SpotlightBackdrop(_ref) {
9528
+ var bounds = _ref.bounds,
9529
+ testID = _ref.testID;
9530
+ var theme = useTheme();
9531
+ var _useWindowDimensions = useWindowDimensions(),
9532
+ windowWidth = _useWindowDimensions.width,
9533
+ windowHeight = _useWindowDimensions.height;
9534
+ var maxSpotlightRadius = theme.__hd__.appCue.radii.spotlight;
9535
+ var backdropColor = theme.__hd__.appCue.colors.backdropColor;
9536
+ var resolvedRadius = Math.min(bounds.height / 2, bounds.width / 2, maxSpotlightRadius);
9537
+ return /*#__PURE__*/React__default.createElement(Svg, {
9538
+ width: windowWidth,
9539
+ height: windowHeight,
9540
+ style: {
9541
+ position: 'absolute',
9542
+ top: 0,
9543
+ left: 0
9544
+ }
9545
+ }, /*#__PURE__*/React__default.createElement(Defs, null, /*#__PURE__*/React__default.createElement(Mask, {
9546
+ id: "spotlight-mask"
9547
+ }, /*#__PURE__*/React__default.createElement(Rect, {
9548
+ width: windowWidth,
9549
+ height: windowHeight,
9550
+ fill: "white"
9551
+ }), /*#__PURE__*/React__default.createElement(Rect, {
9552
+ x: bounds.x,
9553
+ y: bounds.y,
9554
+ width: bounds.width,
9555
+ height: bounds.height,
9556
+ rx: resolvedRadius,
9557
+ ry: resolvedRadius,
9558
+ fill: "black",
9559
+ testID: testID && "".concat(testID, "-spotlight")
9560
+ }))), /*#__PURE__*/React__default.createElement(Rect, {
9561
+ width: windowWidth,
9562
+ height: windowHeight,
9563
+ fill: backdropColor,
9564
+ mask: "url(#spotlight-mask)"
9565
+ }));
9566
+ };
9567
+
9546
9568
  var calculatePosition = function calculatePosition(_ref) {
9547
9569
  var placement = _ref.placement,
9548
9570
  position = _ref.position,
@@ -9553,92 +9575,61 @@ var calculatePosition = function calculatePosition(_ref) {
9553
9575
  case 'top':
9554
9576
  {
9555
9577
  return {
9556
- // The X coordinate is calculated by adding the half of the width of the target element to the X coordinate of the target element.
9557
- left: position.pageX + (position.width - contentSize.width) / 2,
9558
- // The Y coordinate is calculated by subtracting the height of the content and the offset from the Y coordinate of the target element
9559
- top: position.pageY - contentSize.height - offset
9578
+ left: position.x + (position.width - contentSize.width) / 2,
9579
+ top: position.y - contentSize.height - offset
9560
9580
  };
9561
9581
  }
9562
9582
  case 'bottom':
9563
9583
  {
9564
9584
  return {
9565
- // The X coordinate is calculated by adding the half of the width of the target element to the X coordinate of the target element.
9566
- left: position.pageX + (position.width - contentSize.width) / 2,
9567
- // The Y coordinate is calculated by adding the height of the target element and the offset to the Y coordinate of the target element.
9568
- top: position.pageY + position.height + offset
9585
+ left: position.x + (position.width - contentSize.width) / 2,
9586
+ top: position.y + position.height + offset
9569
9587
  };
9570
9588
  }
9571
9589
  case 'right':
9572
9590
  {
9573
9591
  return {
9574
- // The X coordinate is calculated by adding the width of the target element and the offset to the X coordinate of the target element.
9575
- left: position.pageX + position.width + offset,
9576
- // The Y coordinate is calculated by adding half of the height of the target element to the Y coordinate of the target element.
9577
- top: position.pageY + (position.height - contentSize.height) / 2
9592
+ left: position.x + position.width + offset,
9593
+ top: position.y + (position.height - contentSize.height) / 2
9578
9594
  };
9579
9595
  }
9580
9596
  case 'left':
9581
9597
  {
9582
9598
  return {
9583
- // The X coordinate is calculated by subtracting the width of the content and the offset from the X coordinate of the target element.
9584
- left: position.pageX - contentSize.width - offset,
9585
- // The Y coordinate is calculated by adding half of the height of the target element to the Y coordinate of the target element.
9586
- top: position.pageY + (position.height - contentSize.height) / 2
9599
+ left: position.x - contentSize.width - offset,
9600
+ top: position.y + (position.height - contentSize.height) / 2
9587
9601
  };
9588
9602
  }
9589
9603
  case 'top-left':
9590
9604
  {
9591
9605
  return {
9592
- // The X coordinate is calculated by subtracting the width of the content from the X coordinate of the target element.
9593
- right: windowWidth - position.pageX - position.width,
9594
- // The Y coordinate is calculated by subtracting the height of the content and the offset from the Y coordinate of the target element
9595
- top: position.pageY - contentSize.height - offset
9606
+ right: windowWidth - position.x - position.width,
9607
+ top: position.y - contentSize.height - offset
9596
9608
  };
9597
9609
  }
9598
9610
  case 'top-right':
9599
9611
  {
9600
9612
  return {
9601
- // The X coordinate is calculated by adding the width of the target element to the X coordinate of the target element.
9602
- left: position.pageX,
9603
- // The Y coordinate is calculated by subtracting the height of the content and the offset from the Y coordinate of the target element.
9604
- top: position.pageY - contentSize.height - offset
9613
+ left: position.x,
9614
+ top: position.y - contentSize.height - offset
9605
9615
  };
9606
9616
  }
9607
9617
  case 'bottom-left':
9608
9618
  {
9609
9619
  return {
9610
- // The X coordinate is calculated by subtracting the width of the content from the X coordinate of the target element.
9611
- right: windowWidth - position.pageX - position.width,
9612
- // The Y coordinate is calculated by adding the height of the target element and the offset to the Y coordinate of the target element.
9613
- top: position.pageY + position.height + offset
9620
+ right: windowWidth - position.x - position.width,
9621
+ top: position.y + position.height + offset
9614
9622
  };
9615
9623
  }
9616
9624
  case 'bottom-right':
9617
9625
  {
9618
9626
  return {
9619
- // The X coordinate is calculated by adding the width of the target element to the X coordinate of the target element.
9620
- left: position.pageX,
9621
- // The Y coordinate is calculated by adding the height of the target element and the offset to the Y coordinate of the target element.
9622
- top: position.pageY + position.height + offset
9627
+ left: position.x,
9628
+ top: position.y + position.height + offset
9623
9629
  };
9624
9630
  }
9625
9631
  }
9626
9632
  };
9627
- /**
9628
- * Calculates the maximum width of the content based on its position, offset, placement, and window width.
9629
- *
9630
- * @param {Object} params - The parameters for the calculation.
9631
- * @param {Object} params.position - The position and dimensions of the target element.
9632
- * @param {number} params.position.pageX - The X coordinate of the target element.
9633
- * @param {number} params.position.pageY - The Y coordinate of the target element.
9634
- * @param {number} params.position.width - The width of the target element.
9635
- * @param {number} params.position.height - The height of the target element.
9636
- * @param {number} params.offset - The offset value to display an arrow.
9637
- * @param {Placement} params.placement - The placement of the content relative to the element.
9638
- * @param {number} params.windowWidth - The width of the window.
9639
- *
9640
- * @returns {number | undefined} The maximum width of the content.
9641
- */
9642
9633
  var calulateContentMaxWidth = function calulateContentMaxWidth(_ref2) {
9643
9634
  var position = _ref2.position,
9644
9635
  offset = _ref2.offset,
@@ -9655,27 +9646,27 @@ var calulateContentMaxWidth = function calulateContentMaxWidth(_ref2) {
9655
9646
  }
9656
9647
  case 'right':
9657
9648
  {
9658
- return windowWidth - position.pageX - position.width - offset;
9649
+ return windowWidth - position.x - position.width - offset;
9659
9650
  }
9660
9651
  case 'left':
9661
9652
  {
9662
- return position.pageX - offset;
9653
+ return position.x - offset;
9663
9654
  }
9664
9655
  case 'top-left':
9665
9656
  {
9666
- return position.pageX + position.width;
9657
+ return position.x + position.width;
9667
9658
  }
9668
9659
  case 'top-right':
9669
9660
  {
9670
- return windowWidth - position.pageX;
9661
+ return windowWidth - position.x;
9671
9662
  }
9672
9663
  case 'bottom-left':
9673
9664
  {
9674
- return position.pageX + position.width;
9665
+ return position.x + position.width;
9675
9666
  }
9676
9667
  case 'bottom-right':
9677
9668
  {
9678
- return windowWidth - position.pageX;
9669
+ return windowWidth - position.x;
9679
9670
  }
9680
9671
  }
9681
9672
  };
@@ -9686,23 +9677,27 @@ var AppCue = function AppCue(_ref) {
9686
9677
  _ref$placement = _ref.placement,
9687
9678
  placement = _ref$placement === void 0 ? 'top' : _ref$placement,
9688
9679
  style = _ref.style,
9689
- testID = _ref.testID;
9680
+ testID = _ref.testID,
9681
+ controlledVisible = _ref.visible,
9682
+ onDismiss = _ref.onDismiss;
9690
9683
  var targetContainerRef = useRef(null);
9684
+ var isControlled = controlledVisible !== undefined;
9691
9685
  var _React$useState = React__default.useState(false),
9692
9686
  _React$useState2 = _slicedToArray(_React$useState, 2),
9693
- visible = _React$useState2[0],
9694
- setVisible = _React$useState2[1];
9687
+ internalVisible = _React$useState2[0],
9688
+ setInternalVisible = _React$useState2[1];
9689
+ var open = isControlled ? controlledVisible : internalVisible;
9695
9690
  var theme = useTheme();
9696
9691
  var offset = theme.__hd__.appCue.space.offset;
9697
9692
  var _React$useState3 = React__default.useState({
9698
- pageX: 0,
9699
- pageY: 0,
9693
+ x: 0,
9694
+ y: 0,
9700
9695
  width: 0,
9701
9696
  height: 0
9702
9697
  }),
9703
9698
  _React$useState4 = _slicedToArray(_React$useState3, 2),
9704
- position = _React$useState4[0],
9705
- setPosition = _React$useState4[1];
9699
+ bounds = _React$useState4[0],
9700
+ setBounds = _React$useState4[1];
9706
9701
  var _React$useState5 = React__default.useState({
9707
9702
  width: 0,
9708
9703
  height: 0
@@ -9713,23 +9708,36 @@ var AppCue = function AppCue(_ref) {
9713
9708
  var doMeasure = useCallback(function (cb) {
9714
9709
  var _targetContainerRef$c;
9715
9710
  (_targetContainerRef$c = targetContainerRef.current) === null || _targetContainerRef$c === void 0 || _targetContainerRef$c.measure(function (_, __, width, height, pageX, pageY) {
9716
- setPosition({
9717
- pageX: pageX,
9718
- pageY: pageY,
9711
+ setBounds({
9712
+ x: pageX,
9713
+ y: pageY,
9719
9714
  width: width,
9720
9715
  height: height
9721
9716
  });
9722
9717
  cb === null || cb === void 0 || cb();
9723
9718
  });
9724
9719
  }, []);
9725
- var handleOpen = function handleOpen() {
9726
- doMeasure(function () {
9727
- return setVisible(true);
9728
- });
9729
- };
9720
+ var handleOpen = useCallback(function () {
9721
+ if (!isControlled) {
9722
+ doMeasure(function () {
9723
+ return setInternalVisible(true);
9724
+ });
9725
+ }
9726
+ }, [isControlled, doMeasure]);
9727
+ var handleDismiss = useCallback(function () {
9728
+ if (!isControlled) {
9729
+ setInternalVisible(false);
9730
+ }
9731
+ onDismiss === null || onDismiss === void 0 || onDismiss();
9732
+ }, [isControlled, onDismiss]);
9730
9733
  useLayoutEffect(function () {
9731
9734
  doMeasure();
9732
9735
  }, [doMeasure]);
9736
+ useEffect(function () {
9737
+ if (open) {
9738
+ doMeasure();
9739
+ }
9740
+ }, [open, doMeasure]);
9733
9741
  var enhancedTarget = /*#__PURE__*/React__default.cloneElement(target, {
9734
9742
  onPress: function onPress() {
9735
9743
  var _target$props, _target$props$onPress;
@@ -9746,14 +9754,14 @@ var AppCue = function AppCue(_ref) {
9746
9754
  var _useWindowDimensions = useWindowDimensions(),
9747
9755
  windowWidth = _useWindowDimensions.width;
9748
9756
  var pos = calculatePosition({
9749
- position: position,
9757
+ position: bounds,
9750
9758
  contentSize: contentSize,
9751
9759
  placement: placement,
9752
9760
  offset: offset,
9753
9761
  windowWidth: windowWidth
9754
9762
  });
9755
9763
  var maxWidth = calulateContentMaxWidth({
9756
- position: position,
9764
+ position: bounds,
9757
9765
  offset: offset,
9758
9766
  placement: placement,
9759
9767
  windowWidth: windowWidth
@@ -9776,26 +9784,24 @@ var AppCue = function AppCue(_ref) {
9776
9784
  }
9777
9785
  }, enhancedTarget)), /*#__PURE__*/React__default.createElement(Modal$1, {
9778
9786
  animationType: "fade",
9779
- visible: visible,
9780
- onDismiss: function onDismiss() {
9781
- return setVisible(false);
9782
- },
9787
+ visible: open,
9788
+ onDismiss: handleDismiss,
9783
9789
  transparent: true,
9784
9790
  presentationStyle: "overFullScreen",
9785
9791
  statusBarTranslucent: true
9786
9792
  }, /*#__PURE__*/React__default.createElement(TouchableWithoutFeedback, {
9787
9793
  testID: testID && "".concat(testID, "-backdrop"),
9788
- onPress: function onPress() {
9789
- return setVisible(false);
9790
- }
9791
- }, /*#__PURE__*/React__default.createElement(StyledContainer$a, null, /*#__PURE__*/React__default.createElement(View, {
9792
- style: StyleSheet$1.flatten([{
9793
- position: 'absolute',
9794
+ onPress: handleDismiss
9795
+ }, /*#__PURE__*/React__default.createElement(StyledModalContainer, null, /*#__PURE__*/React__default.createElement(SpotlightBackdrop, {
9796
+ bounds: bounds,
9797
+ testID: testID
9798
+ }), /*#__PURE__*/React__default.createElement(StyledContentPositioner, {
9799
+ style: [{
9794
9800
  top: pos.top,
9795
9801
  left: pos.left,
9796
9802
  bottom: pos.bottom,
9797
9803
  right: pos.right
9798
- }, style]),
9804
+ }, style],
9799
9805
  onLayout: measureContent,
9800
9806
  testID: testID
9801
9807
  }, /*#__PURE__*/React__default.createElement(StyledContent$1, {