@atlaskit/smart-card 45.25.1 → 45.26.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,21 @@
1
1
  # @atlaskit/smart-card
2
2
 
3
+ ## 45.26.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`223c7e6ba956b`](https://bitbucket.org/atlassian/atlassian-frontend-monorepo/commits/223c7e6ba956b) -
8
+ Add an optional `placement` prop to the hover card, for callers that need the card beside its
9
+ trigger rather than under the pointer — a row in a list, say, where the default position covers
10
+ the row being read. Left unset, positioning is unchanged.
11
+
12
+ The prop is gated on the `confluence_1p_and_3p_connection_byline_experiment` experiment that
13
+ introduced it, so it is inert for other callers until that gate is removed.
14
+
15
+ ### Patch Changes
16
+
17
+ - Updated dependencies
18
+
3
19
  ## 45.25.1
4
20
 
5
21
  ### Patch Changes
@@ -25,7 +25,7 @@ var ANALYTICS_CHANNEL = exports.ANALYTICS_CHANNEL = 'media';
25
25
  var context = exports.context = {
26
26
  componentName: 'smart-cards',
27
27
  packageName: "@atlaskit/smart-card" || '',
28
- packageVersion: "45.25.0" || ''
28
+ packageVersion: "45.25.1" || ''
29
29
  };
30
30
  var TrackQuickActionType = exports.TrackQuickActionType = /*#__PURE__*/function (TrackQuickActionType) {
31
31
  TrackQuickActionType["StatusUpdate"] = "StatusUpdate";
@@ -10,6 +10,7 @@ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends")
10
10
  var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
11
11
  var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
12
12
  var _react = _interopRequireWildcard(require("react"));
13
+ var _unsafeExpValNoExposure = require("@atlaskit/platform-feature-experiments/unsafe-exp-val-no-exposure");
13
14
  var _fg = require("@atlaskit/platform-feature-flags/fg");
14
15
  var _popup = require("@atlaskit/popup/popup");
15
16
  var _constants = require("../../../constants");
@@ -46,6 +47,7 @@ var HoverCardComponent = exports.HoverCardComponent = function HoverCardComponen
46
47
  _ref$noFadeDelay = _ref.noFadeDelay,
47
48
  noFadeDelay = _ref$noFadeDelay === void 0 ? false : _ref$noFadeDelay,
48
49
  hoverPreviewOptions = _ref.hoverPreviewOptions,
50
+ placement = _ref.placement,
49
51
  role = _ref.role,
50
52
  _ref$shouldRenderToPa = _ref.shouldRenderToParent,
51
53
  shouldRenderToParent = _ref$shouldRenderToPa === void 0 ? false : _ref$shouldRenderToPa,
@@ -53,6 +55,7 @@ var HoverCardComponent = exports.HoverCardComponent = function HoverCardComponen
53
55
  titleId = _ref.titleId,
54
56
  onVisibilityChange = _ref.onVisibilityChange;
55
57
  var fadeInDelay = (_hoverPreviewOptions$ = hoverPreviewOptions === null || hoverPreviewOptions === void 0 ? void 0 : hoverPreviewOptions.fadeInDelay) !== null && _hoverPreviewOptions$ !== void 0 ? _hoverPreviewOptions$ : FADE_IN_DELAY;
58
+ var gatedPlacement = placement && (0, _unsafeExpValNoExposure.UNSAFE_expValNoExposure)('confluence_1p_and_3p_connection_byline_experiment', 'isEnabled', false) ? placement : undefined;
56
59
  var _React$useState = _react.default.useState(false),
57
60
  _React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
58
61
  isOpen = _React$useState2[0],
@@ -81,6 +84,12 @@ var HoverCardComponent = exports.HoverCardComponent = function HoverCardComponen
81
84
  y: event.clientY
82
85
  };
83
86
 
87
+ // A caller-chosen placement anchors the card to the trigger, so a cursor-relative offset
88
+ // would drag it back over the element the placement was picked to keep clear of.
89
+ if (gatedPlacement) {
90
+ return;
91
+ }
92
+
84
93
  //If these are undefined then popupOffset is undefined and we fallback to default bottom-start placement
85
94
  if ((!isOpen || !canOpen) && parentSpan.current && mousePos.current) {
86
95
  var _parentSpan$current$g = parentSpan.current.getBoundingClientRect(),
@@ -88,7 +97,7 @@ var HoverCardComponent = exports.HoverCardComponent = function HoverCardComponen
88
97
  left = _parentSpan$current$g.left;
89
98
  popupOffset.current = [mousePos.current.x - left + _styled.CARD_GAP_PX, mousePos.current.y - bottom + _styled.CARD_GAP_PX];
90
99
  }
91
- }, [canOpen, isOpen]);
100
+ }, [canOpen, isOpen, gatedPlacement]);
92
101
  var hideCard = (0, _react.useCallback)(function () {
93
102
  if (handleSetIsOpen) {
94
103
  handleSetIsOpen(false);
@@ -269,8 +278,10 @@ var HoverCardComponent = exports.HoverCardComponent = function HoverCardComponen
269
278
  testId: "hover-card",
270
279
  isOpen: isOpen && canOpen,
271
280
  onClose: initHideCard,
272
- placement: "bottom-start",
273
- offset: popupOffset.current,
281
+ placement: gatedPlacement !== null && gatedPlacement !== void 0 ? gatedPlacement : 'bottom-start'
282
+ // A trigger-anchored card keeps the same gap the cursor-anchored one leaves.
283
+ ,
284
+ offset: gatedPlacement ? [0, _styled.CARD_GAP_PX] : popupOffset.current,
274
285
  autoFocus: false,
275
286
  content: content,
276
287
  trigger: trigger,
@@ -19,7 +19,7 @@ var _excluded = ["href", "children", "checkSafety", "onClick", "testId", "isLink
19
19
  _excluded2 = ["isLinkSafe", "showSafetyWarningModal"];
20
20
  var PACKAGE_DATA = {
21
21
  packageName: "@atlaskit/smart-card",
22
- packageVersion: "45.25.0",
22
+ packageVersion: "45.25.1",
23
23
  componentName: 'linkUrl'
24
24
  };
25
25
  var LinkUrl = function LinkUrl(_ref) {
@@ -4,7 +4,7 @@ export const ANALYTICS_CHANNEL = 'media';
4
4
  export const context = {
5
5
  componentName: 'smart-cards',
6
6
  packageName: "@atlaskit/smart-card" || '',
7
- packageVersion: "45.25.0" || ''
7
+ packageVersion: "45.25.1" || ''
8
8
  };
9
9
  export let TrackQuickActionType = /*#__PURE__*/function (TrackQuickActionType) {
10
10
  TrackQuickActionType["StatusUpdate"] = "StatusUpdate";
@@ -1,5 +1,6 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
  import React, { useCallback, useEffect, useMemo, useRef } from 'react';
3
+ import { UNSAFE_expValNoExposure } from '@atlaskit/platform-feature-experiments/unsafe-exp-val-no-exposure';
3
4
  import { fg } from '@atlaskit/platform-feature-flags/fg';
4
5
  import { Popup } from '@atlaskit/popup/popup';
5
6
  import { ActionName, CardDisplay } from '../../../constants';
@@ -27,6 +28,7 @@ export const HoverCardComponent = ({
27
28
  zIndex = HOVER_CARD_Z_INDEX,
28
29
  noFadeDelay = false,
29
30
  hoverPreviewOptions,
31
+ placement,
30
32
  role,
31
33
  shouldRenderToParent = false,
32
34
  label,
@@ -35,6 +37,7 @@ export const HoverCardComponent = ({
35
37
  }) => {
36
38
  var _hoverPreviewOptions$;
37
39
  const fadeInDelay = (_hoverPreviewOptions$ = hoverPreviewOptions === null || hoverPreviewOptions === void 0 ? void 0 : hoverPreviewOptions.fadeInDelay) !== null && _hoverPreviewOptions$ !== void 0 ? _hoverPreviewOptions$ : FADE_IN_DELAY;
40
+ const gatedPlacement = placement && UNSAFE_expValNoExposure('confluence_1p_and_3p_connection_byline_experiment', 'isEnabled', false) ? placement : undefined;
38
41
  const [isOpen, setIsOpen] = React.useState(false);
39
42
  const fadeOutTimeoutId = useRef();
40
43
  const fadeInTimeoutId = useRef();
@@ -61,6 +64,12 @@ export const HoverCardComponent = ({
61
64
  y: event.clientY
62
65
  };
63
66
 
67
+ // A caller-chosen placement anchors the card to the trigger, so a cursor-relative offset
68
+ // would drag it back over the element the placement was picked to keep clear of.
69
+ if (gatedPlacement) {
70
+ return;
71
+ }
72
+
64
73
  //If these are undefined then popupOffset is undefined and we fallback to default bottom-start placement
65
74
  if ((!isOpen || !canOpen) && parentSpan.current && mousePos.current) {
66
75
  const {
@@ -69,7 +78,7 @@ export const HoverCardComponent = ({
69
78
  } = parentSpan.current.getBoundingClientRect();
70
79
  popupOffset.current = [mousePos.current.x - left + CARD_GAP_PX, mousePos.current.y - bottom + CARD_GAP_PX];
71
80
  }
72
- }, [canOpen, isOpen]);
81
+ }, [canOpen, isOpen, gatedPlacement]);
73
82
  const hideCard = useCallback(() => {
74
83
  if (handleSetIsOpen) {
75
84
  handleSetIsOpen(false);
@@ -245,8 +254,10 @@ export const HoverCardComponent = ({
245
254
  testId: "hover-card",
246
255
  isOpen: isOpen && canOpen,
247
256
  onClose: initHideCard,
248
- placement: "bottom-start",
249
- offset: popupOffset.current,
257
+ placement: gatedPlacement !== null && gatedPlacement !== void 0 ? gatedPlacement : 'bottom-start'
258
+ // A trigger-anchored card keeps the same gap the cursor-anchored one leaves.
259
+ ,
260
+ offset: gatedPlacement ? [0, CARD_GAP_PX] : popupOffset.current,
250
261
  autoFocus: false,
251
262
  content: content,
252
263
  trigger: trigger,
@@ -9,7 +9,7 @@ import LinkWarningModal from './LinkWarningModal';
9
9
  import { useLinkWarningModal } from './LinkWarningModal/hooks/use-link-warning-modal';
10
10
  const PACKAGE_DATA = {
11
11
  packageName: "@atlaskit/smart-card",
12
- packageVersion: "45.25.0",
12
+ packageVersion: "45.25.1",
13
13
  componentName: 'linkUrl'
14
14
  };
15
15
  const LinkUrl = ({
@@ -4,7 +4,7 @@ export var ANALYTICS_CHANNEL = 'media';
4
4
  export var context = {
5
5
  componentName: 'smart-cards',
6
6
  packageName: "@atlaskit/smart-card" || '',
7
- packageVersion: "45.25.0" || ''
7
+ packageVersion: "45.25.1" || ''
8
8
  };
9
9
  export var TrackQuickActionType = /*#__PURE__*/function (TrackQuickActionType) {
10
10
  TrackQuickActionType["StatusUpdate"] = "StatusUpdate";
@@ -3,6 +3,7 @@ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProper
3
3
  import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
4
4
  var _excluded = ["aria-haspopup", "aria-expanded", "aria-controls"];
5
5
  import React, { useCallback, useEffect, useMemo, useRef } from 'react';
6
+ import { UNSAFE_expValNoExposure } from '@atlaskit/platform-feature-experiments/unsafe-exp-val-no-exposure';
6
7
  import { fg } from '@atlaskit/platform-feature-flags/fg';
7
8
  import { Popup } from '@atlaskit/popup/popup';
8
9
  import { ActionName, CardDisplay } from '../../../constants';
@@ -37,6 +38,7 @@ export var HoverCardComponent = function HoverCardComponent(_ref) {
37
38
  _ref$noFadeDelay = _ref.noFadeDelay,
38
39
  noFadeDelay = _ref$noFadeDelay === void 0 ? false : _ref$noFadeDelay,
39
40
  hoverPreviewOptions = _ref.hoverPreviewOptions,
41
+ placement = _ref.placement,
40
42
  role = _ref.role,
41
43
  _ref$shouldRenderToPa = _ref.shouldRenderToParent,
42
44
  shouldRenderToParent = _ref$shouldRenderToPa === void 0 ? false : _ref$shouldRenderToPa,
@@ -44,6 +46,7 @@ export var HoverCardComponent = function HoverCardComponent(_ref) {
44
46
  titleId = _ref.titleId,
45
47
  onVisibilityChange = _ref.onVisibilityChange;
46
48
  var fadeInDelay = (_hoverPreviewOptions$ = hoverPreviewOptions === null || hoverPreviewOptions === void 0 ? void 0 : hoverPreviewOptions.fadeInDelay) !== null && _hoverPreviewOptions$ !== void 0 ? _hoverPreviewOptions$ : FADE_IN_DELAY;
49
+ var gatedPlacement = placement && UNSAFE_expValNoExposure('confluence_1p_and_3p_connection_byline_experiment', 'isEnabled', false) ? placement : undefined;
47
50
  var _React$useState = React.useState(false),
48
51
  _React$useState2 = _slicedToArray(_React$useState, 2),
49
52
  isOpen = _React$useState2[0],
@@ -72,6 +75,12 @@ export var HoverCardComponent = function HoverCardComponent(_ref) {
72
75
  y: event.clientY
73
76
  };
74
77
 
78
+ // A caller-chosen placement anchors the card to the trigger, so a cursor-relative offset
79
+ // would drag it back over the element the placement was picked to keep clear of.
80
+ if (gatedPlacement) {
81
+ return;
82
+ }
83
+
75
84
  //If these are undefined then popupOffset is undefined and we fallback to default bottom-start placement
76
85
  if ((!isOpen || !canOpen) && parentSpan.current && mousePos.current) {
77
86
  var _parentSpan$current$g = parentSpan.current.getBoundingClientRect(),
@@ -79,7 +88,7 @@ export var HoverCardComponent = function HoverCardComponent(_ref) {
79
88
  left = _parentSpan$current$g.left;
80
89
  popupOffset.current = [mousePos.current.x - left + CARD_GAP_PX, mousePos.current.y - bottom + CARD_GAP_PX];
81
90
  }
82
- }, [canOpen, isOpen]);
91
+ }, [canOpen, isOpen, gatedPlacement]);
83
92
  var hideCard = useCallback(function () {
84
93
  if (handleSetIsOpen) {
85
94
  handleSetIsOpen(false);
@@ -260,8 +269,10 @@ export var HoverCardComponent = function HoverCardComponent(_ref) {
260
269
  testId: "hover-card",
261
270
  isOpen: isOpen && canOpen,
262
271
  onClose: initHideCard,
263
- placement: "bottom-start",
264
- offset: popupOffset.current,
272
+ placement: gatedPlacement !== null && gatedPlacement !== void 0 ? gatedPlacement : 'bottom-start'
273
+ // A trigger-anchored card keeps the same gap the cursor-anchored one leaves.
274
+ ,
275
+ offset: gatedPlacement ? [0, CARD_GAP_PX] : popupOffset.current,
265
276
  autoFocus: false,
266
277
  content: content,
267
278
  trigger: trigger,
@@ -12,7 +12,7 @@ import LinkWarningModal from './LinkWarningModal';
12
12
  import { useLinkWarningModal } from './LinkWarningModal/hooks/use-link-warning-modal';
13
13
  var PACKAGE_DATA = {
14
14
  packageName: "@atlaskit/smart-card",
15
- packageVersion: "45.25.0",
15
+ packageVersion: "45.25.1",
16
16
  componentName: 'linkUrl'
17
17
  };
18
18
  var LinkUrl = function LinkUrl(_ref) {
@@ -7,5 +7,5 @@ interface HoverCardComponentProps extends HoverCardProps {
7
7
  canOpen?: boolean;
8
8
  closeOnChildClick?: boolean;
9
9
  }
10
- export declare const HoverCardComponent: ({ children, url, id, canOpen, closeOnChildClick, actionOptions, allowEventPropagation, zIndex, noFadeDelay, hoverPreviewOptions, role, shouldRenderToParent, label, titleId, onVisibilityChange, }: HoverCardComponentProps) => React.JSX.Element;
10
+ export declare const HoverCardComponent: ({ children, url, id, canOpen, closeOnChildClick, actionOptions, allowEventPropagation, zIndex, noFadeDelay, hoverPreviewOptions, placement, role, shouldRenderToParent, label, titleId, onVisibilityChange, }: HoverCardComponentProps) => React.JSX.Element;
11
11
  export {};
@@ -3,6 +3,7 @@ import type { WithAnalyticsEventsProps } from '@atlaskit/analytics-next/withAnal
3
3
  import type { CardProviderRenderers } from '@atlaskit/link-provider/types';
4
4
  import type { CardState } from '@atlaskit/linking-common/store';
5
5
  import type { SmartLinkResponse } from '@atlaskit/linking-types/smart-link';
6
+ import type { PopupProps } from '@atlaskit/popup/types';
6
7
  import type { ActionName } from '../../constants';
7
8
  import { type AnalyticsHandler } from '../../utils/types';
8
9
  import type { CardActionOptions, InternalCardActionOptions } from '../Card/types';
@@ -50,6 +51,13 @@ export interface HoverCardProps extends WithAnalyticsEventsProps {
50
51
  * Callback function that is called when the hover card is visible or hidden.
51
52
  */
52
53
  onVisibilityChange?: (isVisible: boolean) => void;
54
+ /**
55
+ * Where the card should sit relative to the trigger element. Omitted, the card opens below and
56
+ * to the right of the pointer, which is what an inline link in a body of text wants. Set it when
57
+ * the card would otherwise cover the content the user is pointing at — for example a row in a
58
+ * list, where `"left-start"` keeps the row itself visible.
59
+ */
60
+ placement?: PopupProps['placement'];
53
61
  /**
54
62
  * Use this to set the accessibility role for the hover card.
55
63
  * Should be used along with `label` or `titleId` for supported roles.
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "45.25.1",
3
+ "version": "45.26.0",
4
4
  "description": "Smart card component",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"