@khanacademy/wonder-blocks-tooltip 2.4.2 → 2.5.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,27 @@
1
1
  # @khanacademy/wonder-blocks-tooltip
2
2
 
3
+ ## 2.5.0
4
+
5
+ ### Minor Changes
6
+
7
+ - badad6ee: Adds a `viewportPadding` prop to provide spacing between the popper and the viewport edges. If this prop is not provided, default spacing is applied.
8
+
9
+ ### Patch Changes
10
+
11
+ - fcab789b: Only show the `TooltipPopper` contents once the popper has positioned itself. This fixes the issue where Tooltips are initially rendered in the top left corner for a brief moment before moving to the correct position (which was causing a flickering effect).
12
+
13
+ ## 2.4.3
14
+
15
+ ### Patch Changes
16
+
17
+ - 02a1b298: Make sure we don't package tsconfig and tsbuildinfo files
18
+ - Updated dependencies [02a1b298]
19
+ - @khanacademy/wonder-blocks-core@7.0.1
20
+ - @khanacademy/wonder-blocks-layout@2.2.1
21
+ - @khanacademy/wonder-blocks-modal@5.1.12
22
+ - @khanacademy/wonder-blocks-tokens@2.0.1
23
+ - @khanacademy/wonder-blocks-typography@2.1.16
24
+
3
25
  ## 2.4.2
4
26
 
5
27
  ### Patch Changes
@@ -34,16 +34,30 @@ type Props = {
34
34
  * on where there is available room within the document body.
35
35
  */
36
36
  rootBoundary?: RootBoundary;
37
+ /**
38
+ * If `rootBoundary` is `viewport`, this padding value is used to provide
39
+ * spacing between the popper and the viewport. If not provided, default
40
+ * spacing of 12px is applied.
41
+ */
42
+ viewportPadding?: number;
43
+ };
44
+ type State = {
45
+ /**
46
+ * If the popper is ready to show content.
47
+ */
48
+ isReady: boolean;
37
49
  };
38
50
  type DefaultProps = {
39
51
  rootBoundary: Props["rootBoundary"];
52
+ viewportPadding: Props["viewportPadding"];
40
53
  };
41
54
  /**
42
55
  * A component that wraps react-popper's Popper component to provide a
43
56
  * consistent interface for positioning floating elements.
44
57
  */
45
- export default class TooltipPopper extends React.Component<Props> {
58
+ export default class TooltipPopper extends React.Component<Props, State> {
46
59
  static defaultProps: DefaultProps;
60
+ constructor(props: Props);
47
61
  /**
48
62
  * Automatically updates the position of the floating element when necessary
49
63
  * to ensure it stays anchored.
@@ -75,6 +89,7 @@ export default class TooltipPopper extends React.Component<Props> {
75
89
  */
76
90
  _popperUpdate: PopperUpdateFn | null;
77
91
  _renderPositionedContent(popperProps: PopperChildrenProps): React.ReactNode;
92
+ handleFirstUpdate: () => void;
78
93
  render(): React.ReactNode;
79
94
  }
80
95
  export {};
@@ -101,6 +101,12 @@ type Props = AriaProps & Readonly<{
101
101
  * Optional background color.
102
102
  */
103
103
  backgroundColor?: keyof typeof color;
104
+ /**
105
+ * If `rootBoundary` is `viewport`, this padding value is used to provide
106
+ * spacing between the popper and the viewport. If not provided, default
107
+ * spacing of 12px is applied.
108
+ */
109
+ viewportPadding?: number;
104
110
  }>;
105
111
  type State = Readonly<{
106
112
  /**
package/dist/es/index.js CHANGED
@@ -658,12 +658,20 @@ const smallViewportModifier = {
658
658
  fn: _modifyPosition
659
659
  };
660
660
  class TooltipPopper extends React.Component {
661
- constructor(...args) {
662
- super(...args);
661
+ constructor(props) {
662
+ super(props);
663
663
  this._bubbleRefTracker = new RefTracker();
664
664
  this._tailRefTracker = new RefTracker();
665
665
  this._observer = null;
666
666
  this._popperUpdate = null;
667
+ this.handleFirstUpdate = () => {
668
+ this.setState({
669
+ isReady: true
670
+ });
671
+ };
672
+ this.state = {
673
+ isReady: false
674
+ };
667
675
  }
668
676
  componentDidMount() {
669
677
  const {
@@ -691,6 +699,9 @@ class TooltipPopper extends React.Component {
691
699
  const {
692
700
  children
693
701
  } = this.props;
702
+ const {
703
+ isReady
704
+ } = this.state;
694
705
  const placement = filterPopperPlacement(popperProps.placement) || this.props.placement;
695
706
  this._bubbleRefTracker.setCallback(popperProps.ref);
696
707
  this._tailRefTracker.setCallback(popperProps.arrowProps.ref);
@@ -703,7 +714,8 @@ class TooltipPopper extends React.Component {
703
714
  bottom: popperProps.style.bottom,
704
715
  right: popperProps.style.right,
705
716
  position: popperProps.style.position,
706
- transform: popperProps.style.transform
717
+ transform: popperProps.style.transform,
718
+ visibility: !isReady ? "hidden" : undefined
707
719
  },
708
720
  updateBubbleRef: this._bubbleRefTracker.updateRef,
709
721
  tailOffset: {
@@ -722,14 +734,16 @@ class TooltipPopper extends React.Component {
722
734
  const {
723
735
  anchorElement,
724
736
  placement,
725
- rootBoundary
737
+ rootBoundary,
738
+ viewportPadding
726
739
  } = this.props;
727
740
  const modifiers = [smallViewportModifier];
728
741
  if (rootBoundary === "viewport") {
729
742
  modifiers.push({
730
743
  name: "preventOverflow",
731
744
  options: {
732
- rootBoundary: "viewport"
745
+ rootBoundary: "viewport",
746
+ padding: viewportPadding
733
747
  }
734
748
  });
735
749
  } else {
@@ -744,12 +758,14 @@ class TooltipPopper extends React.Component {
744
758
  referenceElement: anchorElement,
745
759
  strategy: "fixed",
746
760
  placement: placement,
747
- modifiers: modifiers
761
+ modifiers: modifiers,
762
+ onFirstUpdate: this.handleFirstUpdate
748
763
  }, props => this._renderPositionedContent(props));
749
764
  }
750
765
  }
751
766
  TooltipPopper.defaultProps = {
752
- rootBoundary: "viewport"
767
+ rootBoundary: "viewport",
768
+ viewportPadding: spacing.small_12
753
769
  };
754
770
 
755
771
  class Tooltip extends React.Component {
@@ -808,7 +824,8 @@ class Tooltip extends React.Component {
808
824
  return React.createElement(TooltipPopper, {
809
825
  anchorElement: this.state.anchorElement,
810
826
  placement: placement,
811
- autoUpdate: this.props.autoUpdate
827
+ autoUpdate: this.props.autoUpdate,
828
+ viewportPadding: this.props.viewportPadding
812
829
  }, props => React.createElement(TooltipBubble, {
813
830
  id: bubbleId,
814
831
  style: props.style,
package/dist/index.js CHANGED
@@ -686,12 +686,20 @@ const smallViewportModifier = {
686
686
  fn: _modifyPosition
687
687
  };
688
688
  class TooltipPopper extends React__namespace.Component {
689
- constructor(...args) {
690
- super(...args);
689
+ constructor(props) {
690
+ super(props);
691
691
  this._bubbleRefTracker = new RefTracker();
692
692
  this._tailRefTracker = new RefTracker();
693
693
  this._observer = null;
694
694
  this._popperUpdate = null;
695
+ this.handleFirstUpdate = () => {
696
+ this.setState({
697
+ isReady: true
698
+ });
699
+ };
700
+ this.state = {
701
+ isReady: false
702
+ };
695
703
  }
696
704
  componentDidMount() {
697
705
  const {
@@ -719,6 +727,9 @@ class TooltipPopper extends React__namespace.Component {
719
727
  const {
720
728
  children
721
729
  } = this.props;
730
+ const {
731
+ isReady
732
+ } = this.state;
722
733
  const placement = filterPopperPlacement(popperProps.placement) || this.props.placement;
723
734
  this._bubbleRefTracker.setCallback(popperProps.ref);
724
735
  this._tailRefTracker.setCallback(popperProps.arrowProps.ref);
@@ -731,7 +742,8 @@ class TooltipPopper extends React__namespace.Component {
731
742
  bottom: popperProps.style.bottom,
732
743
  right: popperProps.style.right,
733
744
  position: popperProps.style.position,
734
- transform: popperProps.style.transform
745
+ transform: popperProps.style.transform,
746
+ visibility: !isReady ? "hidden" : undefined
735
747
  },
736
748
  updateBubbleRef: this._bubbleRefTracker.updateRef,
737
749
  tailOffset: {
@@ -750,14 +762,16 @@ class TooltipPopper extends React__namespace.Component {
750
762
  const {
751
763
  anchorElement,
752
764
  placement,
753
- rootBoundary
765
+ rootBoundary,
766
+ viewportPadding
754
767
  } = this.props;
755
768
  const modifiers = [smallViewportModifier];
756
769
  if (rootBoundary === "viewport") {
757
770
  modifiers.push({
758
771
  name: "preventOverflow",
759
772
  options: {
760
- rootBoundary: "viewport"
773
+ rootBoundary: "viewport",
774
+ padding: viewportPadding
761
775
  }
762
776
  });
763
777
  } else {
@@ -772,12 +786,14 @@ class TooltipPopper extends React__namespace.Component {
772
786
  referenceElement: anchorElement,
773
787
  strategy: "fixed",
774
788
  placement: placement,
775
- modifiers: modifiers
789
+ modifiers: modifiers,
790
+ onFirstUpdate: this.handleFirstUpdate
776
791
  }, props => this._renderPositionedContent(props));
777
792
  }
778
793
  }
779
794
  TooltipPopper.defaultProps = {
780
- rootBoundary: "viewport"
795
+ rootBoundary: "viewport",
796
+ viewportPadding: wonderBlocksTokens.spacing.small_12
781
797
  };
782
798
 
783
799
  class Tooltip extends React__namespace.Component {
@@ -836,7 +852,8 @@ class Tooltip extends React__namespace.Component {
836
852
  return React__namespace.createElement(TooltipPopper, {
837
853
  anchorElement: this.state.anchorElement,
838
854
  placement: placement,
839
- autoUpdate: this.props.autoUpdate
855
+ autoUpdate: this.props.autoUpdate,
856
+ viewportPadding: this.props.viewportPadding
840
857
  }, props => React__namespace.createElement(TooltipBubble, {
841
858
  id: bubbleId,
842
859
  style: props.style,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-tooltip",
3
- "version": "2.4.2",
3
+ "version": "2.5.0",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -16,11 +16,11 @@
16
16
  "license": "MIT",
17
17
  "dependencies": {
18
18
  "@babel/runtime": "^7.18.6",
19
- "@khanacademy/wonder-blocks-core": "^7.0.0",
20
- "@khanacademy/wonder-blocks-layout": "^2.2.0",
21
- "@khanacademy/wonder-blocks-modal": "^5.1.11",
22
- "@khanacademy/wonder-blocks-tokens": "^2.0.0",
23
- "@khanacademy/wonder-blocks-typography": "^2.1.15"
19
+ "@khanacademy/wonder-blocks-core": "^7.0.1",
20
+ "@khanacademy/wonder-blocks-layout": "^2.2.1",
21
+ "@khanacademy/wonder-blocks-modal": "^5.1.12",
22
+ "@khanacademy/wonder-blocks-tokens": "^2.0.1",
23
+ "@khanacademy/wonder-blocks-typography": "^2.1.16"
24
24
  },
25
25
  "peerDependencies": {
26
26
  "@popperjs/core": "^2.10.1",