@atlaskit/smart-card 18.0.0 → 18.0.3
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 +18 -0
- package/dist/cjs/version.json +1 -1
- package/dist/cjs/view/CardWithUrl/component.js +12 -6
- package/dist/cjs/view/HoverCard/index.js +96 -11
- package/dist/cjs/view/HoverCard/styled.js +2 -4
- package/dist/es2019/version.json +1 -1
- package/dist/es2019/view/CardWithUrl/component.js +11 -6
- package/dist/es2019/view/HoverCard/index.js +69 -10
- package/dist/es2019/view/HoverCard/styled.js +2 -4
- package/dist/esm/version.json +1 -1
- package/dist/esm/view/CardWithUrl/component.js +11 -6
- package/dist/esm/view/HoverCard/index.js +88 -11
- package/dist/esm/view/HoverCard/styled.js +2 -3
- package/dist/types/state/hooks/useSmartLink.d.ts +1 -1
- package/dist/types/view/Card/index.d.ts +1 -1
- package/dist/types/view/HoverCard/styled.d.ts +1 -2
- package/package.json +2 -1
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @atlaskit/smart-card
|
|
2
2
|
|
|
3
|
+
## 18.0.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- [`7dc2fb8eb8b`](https://bitbucket.org/atlassian/atlassian-frontend/commits/7dc2fb8eb8b) - Handle exceptions coming from client
|
|
8
|
+
|
|
9
|
+
## 18.0.2
|
|
10
|
+
|
|
11
|
+
### Patch Changes
|
|
12
|
+
|
|
13
|
+
- [`cff21812950`](https://bitbucket.org/atlassian/atlassian-frontend/commits/cff21812950) - add smart link actions to footer of hover card, plus small styling changes
|
|
14
|
+
|
|
15
|
+
## 18.0.1
|
|
16
|
+
|
|
17
|
+
### Patch Changes
|
|
18
|
+
|
|
19
|
+
- [`75c16ae4964`](https://bitbucket.org/atlassian/atlassian-frontend/commits/75c16ae4964) - refactor code to use atlaskit/popup instead of atlaskit/tooltip as a base component
|
|
20
|
+
|
|
3
21
|
## 18.0.0
|
|
4
22
|
|
|
5
23
|
### Major Changes
|
package/dist/cjs/version.json
CHANGED
|
@@ -29,6 +29,8 @@ var _flexible = require("../../utils/flexible");
|
|
|
29
29
|
|
|
30
30
|
var _FlexibleCard = _interopRequireDefault(require("../FlexibleCard"));
|
|
31
31
|
|
|
32
|
+
var _ = require("../..");
|
|
33
|
+
|
|
32
34
|
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
33
35
|
|
|
34
36
|
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
@@ -107,15 +109,14 @@ function CardWithUrlContent(_ref) {
|
|
|
107
109
|
if ((0, _helpers.isFinalState)(state.status)) {
|
|
108
110
|
analytics.ui.renderSuccessEvent(appearance, id, definitionId, extensionKey);
|
|
109
111
|
}
|
|
110
|
-
}, [appearance, state.details, state.status, url, definitionId, extensionKey, analytics.ui, id]);
|
|
111
|
-
|
|
112
|
-
if (error) {
|
|
113
|
-
throw error;
|
|
114
|
-
}
|
|
112
|
+
}, [appearance, state.details, state.status, url, definitionId, extensionKey, analytics.ui, id]);
|
|
115
113
|
|
|
116
114
|
if (isFlexibleUi) {
|
|
115
|
+
var cardState = (error === null || error === void 0 ? void 0 : error.constructor) === _.APIError ? {
|
|
116
|
+
status: 'errored'
|
|
117
|
+
} : state;
|
|
117
118
|
return /*#__PURE__*/_react.default.createElement(_FlexibleCard.default, {
|
|
118
|
-
cardState:
|
|
119
|
+
cardState: cardState,
|
|
119
120
|
onAuthorize: services.length && handleAuthorize || undefined,
|
|
120
121
|
onClick: handleClickWrapper,
|
|
121
122
|
renderers: renderers,
|
|
@@ -123,6 +124,11 @@ function CardWithUrlContent(_ref) {
|
|
|
123
124
|
url: url,
|
|
124
125
|
testId: testId
|
|
125
126
|
}, children);
|
|
127
|
+
} // We have to keep this last to prevent hook order from being violated
|
|
128
|
+
|
|
129
|
+
|
|
130
|
+
if (error) {
|
|
131
|
+
throw error;
|
|
126
132
|
}
|
|
127
133
|
|
|
128
134
|
switch (appearance) {
|
|
@@ -2,36 +2,121 @@
|
|
|
2
2
|
|
|
3
3
|
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
4
|
|
|
5
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
+
|
|
5
7
|
Object.defineProperty(exports, "__esModule", {
|
|
6
8
|
value: true
|
|
7
9
|
});
|
|
8
10
|
exports.HoverCard = void 0;
|
|
9
11
|
|
|
10
|
-
var
|
|
12
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
|
+
|
|
14
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
11
15
|
|
|
12
|
-
var
|
|
16
|
+
var _core = require("@emotion/core");
|
|
17
|
+
|
|
18
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
13
19
|
|
|
14
20
|
var _blocks = require("../FlexibleCard/components/blocks");
|
|
15
21
|
|
|
16
22
|
var _Card = require("../Card");
|
|
17
23
|
|
|
24
|
+
var _popup = _interopRequireDefault(require("@atlaskit/popup"));
|
|
25
|
+
|
|
26
|
+
var _constants = require("../../constants");
|
|
27
|
+
|
|
28
|
+
var _useSmartLinkActions = require("../../state/hooks-external/useSmartLinkActions");
|
|
29
|
+
|
|
18
30
|
var _styled = require("./styled");
|
|
19
31
|
|
|
32
|
+
function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
|
|
33
|
+
|
|
34
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
35
|
+
|
|
36
|
+
/** @jsx jsx */
|
|
20
37
|
var HoverCard = function HoverCard(_ref) {
|
|
21
38
|
var children = _ref.children,
|
|
22
39
|
url = _ref.url;
|
|
40
|
+
var delay = 300;
|
|
23
41
|
|
|
24
|
-
var
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
42
|
+
var _React$useState = _react.default.useState(false),
|
|
43
|
+
_React$useState2 = (0, _slicedToArray2.default)(_React$useState, 2),
|
|
44
|
+
isOpen = _React$useState2[0],
|
|
45
|
+
setIsOpen = _React$useState2[1];
|
|
28
46
|
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
47
|
+
var fadeOutTimeoutId = (0, _react.useRef)();
|
|
48
|
+
var fadeInTimeoutId = (0, _react.useRef)();
|
|
49
|
+
var initHideCard = (0, _react.useCallback)(function () {
|
|
50
|
+
if (fadeInTimeoutId.current) {
|
|
51
|
+
clearTimeout(fadeInTimeoutId.current);
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
fadeOutTimeoutId.current = setTimeout(function () {
|
|
55
|
+
setIsOpen(false);
|
|
56
|
+
}, delay);
|
|
57
|
+
}, [delay]);
|
|
58
|
+
var initShowCard = (0, _react.useCallback)(function () {
|
|
59
|
+
if (fadeOutTimeoutId.current) {
|
|
60
|
+
clearTimeout(fadeOutTimeoutId.current);
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
fadeInTimeoutId.current = setTimeout(function () {
|
|
64
|
+
setIsOpen(true);
|
|
65
|
+
}, delay);
|
|
66
|
+
}, [delay]); //TODO: EDM-2905: Add analytics events
|
|
67
|
+
|
|
68
|
+
var analyticsHandler = (0, _react.useCallback)(function () {}, []);
|
|
69
|
+
var linkActions = (0, _useSmartLinkActions.useSmartLinkActions)({
|
|
70
|
+
url: url,
|
|
71
|
+
appearance: 'block',
|
|
72
|
+
analyticsHandler: analyticsHandler
|
|
73
|
+
});
|
|
74
|
+
var actions = (0, _react.useMemo)(function () {
|
|
75
|
+
return linkActions.map(function (action) {
|
|
76
|
+
return {
|
|
77
|
+
content: action.text,
|
|
78
|
+
name: _constants.ActionName.CustomAction,
|
|
79
|
+
onClick: function onClick() {
|
|
80
|
+
return action.invoke();
|
|
81
|
+
},
|
|
82
|
+
testId: action.id
|
|
83
|
+
};
|
|
84
|
+
});
|
|
85
|
+
}, [linkActions]);
|
|
86
|
+
|
|
87
|
+
var cardComponent = function cardComponent() {
|
|
88
|
+
return (0, _core.jsx)("div", {
|
|
89
|
+
onMouseEnter: initShowCard,
|
|
90
|
+
onMouseLeave: initHideCard,
|
|
91
|
+
css: _styled.HoverCardContainer
|
|
92
|
+
}, (0, _core.jsx)(_Card.Card, {
|
|
93
|
+
appearance: "block",
|
|
94
|
+
url: url,
|
|
95
|
+
ui: {
|
|
96
|
+
hideElevation: true,
|
|
97
|
+
size: _constants.SmartLinkSize.Large
|
|
98
|
+
}
|
|
99
|
+
}, (0, _core.jsx)(_blocks.TitleBlock, null), (0, _core.jsx)(_blocks.SnippetBlock, null), (0, _core.jsx)(_blocks.FooterBlock, {
|
|
100
|
+
actions: actions
|
|
101
|
+
})));
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
var onClose = (0, _react.useCallback)(function () {
|
|
105
|
+
return setIsOpen(false);
|
|
106
|
+
}, []);
|
|
107
|
+
return (0, _core.jsx)(_popup.default, {
|
|
32
108
|
testId: "hover-card",
|
|
33
|
-
|
|
34
|
-
|
|
109
|
+
isOpen: isOpen,
|
|
110
|
+
onClose: onClose,
|
|
111
|
+
placement: "bottom",
|
|
112
|
+
content: cardComponent,
|
|
113
|
+
trigger: function trigger(triggerProps) {
|
|
114
|
+
return (0, _core.jsx)("span", (0, _extends2.default)({}, triggerProps, {
|
|
115
|
+
onMouseEnter: initShowCard,
|
|
116
|
+
onMouseLeave: initHideCard
|
|
117
|
+
}), children);
|
|
118
|
+
}
|
|
119
|
+
});
|
|
35
120
|
};
|
|
36
121
|
|
|
37
122
|
exports.HoverCard = HoverCard;
|
|
@@ -9,11 +9,9 @@ exports.HoverCardContainer = void 0;
|
|
|
9
9
|
|
|
10
10
|
var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
|
|
11
11
|
|
|
12
|
-
var
|
|
13
|
-
|
|
14
|
-
var _tooltip = require("@atlaskit/tooltip");
|
|
12
|
+
var _core = require("@emotion/core");
|
|
15
13
|
|
|
16
14
|
var _templateObject;
|
|
17
15
|
|
|
18
|
-
var HoverCardContainer = (0,
|
|
16
|
+
var HoverCardContainer = (0, _core.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n background: none;\n border-width: 0;\n max-width: 500px;\n padding: 0;\n"])));
|
|
19
17
|
exports.HoverCardContainer = HoverCardContainer;
|
package/dist/es2019/version.json
CHANGED
|
@@ -8,6 +8,7 @@ import { InlineCard } from '../InlineCard';
|
|
|
8
8
|
import { EmbedCard } from '../EmbedCard';
|
|
9
9
|
import { isFlexibleUiCard } from '../../utils/flexible';
|
|
10
10
|
import FlexibleCard from '../FlexibleCard';
|
|
11
|
+
import { APIError } from '../..';
|
|
11
12
|
export function CardWithUrlContent({
|
|
12
13
|
id,
|
|
13
14
|
url,
|
|
@@ -76,15 +77,14 @@ export function CardWithUrlContent({
|
|
|
76
77
|
if (isFinalState(state.status)) {
|
|
77
78
|
analytics.ui.renderSuccessEvent(appearance, id, definitionId, extensionKey);
|
|
78
79
|
}
|
|
79
|
-
}, [appearance, state.details, state.status, url, definitionId, extensionKey, analytics.ui, id]);
|
|
80
|
-
|
|
81
|
-
if (error) {
|
|
82
|
-
throw error;
|
|
83
|
-
}
|
|
80
|
+
}, [appearance, state.details, state.status, url, definitionId, extensionKey, analytics.ui, id]);
|
|
84
81
|
|
|
85
82
|
if (isFlexibleUi) {
|
|
83
|
+
let cardState = (error === null || error === void 0 ? void 0 : error.constructor) === APIError ? {
|
|
84
|
+
status: 'errored'
|
|
85
|
+
} : state;
|
|
86
86
|
return /*#__PURE__*/React.createElement(FlexibleCard, {
|
|
87
|
-
cardState:
|
|
87
|
+
cardState: cardState,
|
|
88
88
|
onAuthorize: services.length && handleAuthorize || undefined,
|
|
89
89
|
onClick: handleClickWrapper,
|
|
90
90
|
renderers: renderers,
|
|
@@ -92,6 +92,11 @@ export function CardWithUrlContent({
|
|
|
92
92
|
url: url,
|
|
93
93
|
testId: testId
|
|
94
94
|
}, children);
|
|
95
|
+
} // We have to keep this last to prevent hook order from being violated
|
|
96
|
+
|
|
97
|
+
|
|
98
|
+
if (error) {
|
|
99
|
+
throw error;
|
|
95
100
|
}
|
|
96
101
|
|
|
97
102
|
switch (appearance) {
|
|
@@ -1,20 +1,79 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
|
|
3
|
+
/** @jsx jsx */
|
|
4
|
+
import { jsx } from '@emotion/core';
|
|
5
|
+
import React, { useCallback, useRef, useMemo } from 'react';
|
|
3
6
|
import { TitleBlock, SnippetBlock, FooterBlock } from '../FlexibleCard/components/blocks';
|
|
4
7
|
import { Card } from '../Card';
|
|
8
|
+
import Popup from '@atlaskit/popup';
|
|
9
|
+
import { SmartLinkSize, ActionName } from '../../constants';
|
|
10
|
+
import { useSmartLinkActions } from '../../state/hooks-external/useSmartLinkActions';
|
|
5
11
|
import { HoverCardContainer } from './styled';
|
|
6
12
|
export const HoverCard = ({
|
|
7
13
|
children,
|
|
8
14
|
url
|
|
9
15
|
}) => {
|
|
10
|
-
const
|
|
16
|
+
const delay = 300;
|
|
17
|
+
const [isOpen, setIsOpen] = React.useState(false);
|
|
18
|
+
const fadeOutTimeoutId = useRef();
|
|
19
|
+
const fadeInTimeoutId = useRef();
|
|
20
|
+
const initHideCard = useCallback(() => {
|
|
21
|
+
if (fadeInTimeoutId.current) {
|
|
22
|
+
clearTimeout(fadeInTimeoutId.current);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
fadeOutTimeoutId.current = setTimeout(() => {
|
|
26
|
+
setIsOpen(false);
|
|
27
|
+
}, delay);
|
|
28
|
+
}, [delay]);
|
|
29
|
+
const initShowCard = useCallback(() => {
|
|
30
|
+
if (fadeOutTimeoutId.current) {
|
|
31
|
+
clearTimeout(fadeOutTimeoutId.current);
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
fadeInTimeoutId.current = setTimeout(() => {
|
|
35
|
+
setIsOpen(true);
|
|
36
|
+
}, delay);
|
|
37
|
+
}, [delay]); //TODO: EDM-2905: Add analytics events
|
|
38
|
+
|
|
39
|
+
const analyticsHandler = useCallback(() => {}, []);
|
|
40
|
+
const linkActions = useSmartLinkActions({
|
|
41
|
+
url,
|
|
42
|
+
appearance: 'block',
|
|
43
|
+
analyticsHandler
|
|
44
|
+
});
|
|
45
|
+
const actions = useMemo(() => linkActions.map(action => ({
|
|
46
|
+
content: action.text,
|
|
47
|
+
name: ActionName.CustomAction,
|
|
48
|
+
onClick: () => action.invoke(),
|
|
49
|
+
testId: action.id
|
|
50
|
+
})), [linkActions]);
|
|
51
|
+
|
|
52
|
+
const cardComponent = () => jsx("div", {
|
|
53
|
+
onMouseEnter: initShowCard,
|
|
54
|
+
onMouseLeave: initHideCard,
|
|
55
|
+
css: HoverCardContainer
|
|
56
|
+
}, jsx(Card, {
|
|
11
57
|
appearance: "block",
|
|
12
|
-
url: url
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
58
|
+
url: url,
|
|
59
|
+
ui: {
|
|
60
|
+
hideElevation: true,
|
|
61
|
+
size: SmartLinkSize.Large
|
|
62
|
+
}
|
|
63
|
+
}, jsx(TitleBlock, null), jsx(SnippetBlock, null), jsx(FooterBlock, {
|
|
64
|
+
actions: actions
|
|
65
|
+
})));
|
|
66
|
+
|
|
67
|
+
const onClose = useCallback(() => setIsOpen(false), []);
|
|
68
|
+
return jsx(Popup, {
|
|
17
69
|
testId: "hover-card",
|
|
18
|
-
|
|
19
|
-
|
|
70
|
+
isOpen: isOpen,
|
|
71
|
+
onClose: onClose,
|
|
72
|
+
placement: "bottom",
|
|
73
|
+
content: cardComponent,
|
|
74
|
+
trigger: triggerProps => jsx("span", _extends({}, triggerProps, {
|
|
75
|
+
onMouseEnter: initShowCard,
|
|
76
|
+
onMouseLeave: initHideCard
|
|
77
|
+
}), children)
|
|
78
|
+
});
|
|
20
79
|
};
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
|
|
3
|
-
export const HoverCardContainer = styled(TooltipPrimitive)`
|
|
1
|
+
import { css } from '@emotion/core';
|
|
2
|
+
export const HoverCardContainer = css`
|
|
4
3
|
background: none;
|
|
5
4
|
border-width: 0;
|
|
6
|
-
box-sizing: content-box; /* do not set this to border-box or it will break the overflow handling */
|
|
7
5
|
max-width: 500px;
|
|
8
6
|
padding: 0;
|
|
9
7
|
`;
|
package/dist/esm/version.json
CHANGED
|
@@ -8,6 +8,7 @@ import { InlineCard } from '../InlineCard';
|
|
|
8
8
|
import { EmbedCard } from '../EmbedCard';
|
|
9
9
|
import { isFlexibleUiCard } from '../../utils/flexible';
|
|
10
10
|
import FlexibleCard from '../FlexibleCard';
|
|
11
|
+
import { APIError } from '../..';
|
|
11
12
|
export function CardWithUrlContent(_ref) {
|
|
12
13
|
var id = _ref.id,
|
|
13
14
|
url = _ref.url,
|
|
@@ -82,15 +83,14 @@ export function CardWithUrlContent(_ref) {
|
|
|
82
83
|
if (isFinalState(state.status)) {
|
|
83
84
|
analytics.ui.renderSuccessEvent(appearance, id, definitionId, extensionKey);
|
|
84
85
|
}
|
|
85
|
-
}, [appearance, state.details, state.status, url, definitionId, extensionKey, analytics.ui, id]);
|
|
86
|
-
|
|
87
|
-
if (error) {
|
|
88
|
-
throw error;
|
|
89
|
-
}
|
|
86
|
+
}, [appearance, state.details, state.status, url, definitionId, extensionKey, analytics.ui, id]);
|
|
90
87
|
|
|
91
88
|
if (isFlexibleUi) {
|
|
89
|
+
var cardState = (error === null || error === void 0 ? void 0 : error.constructor) === APIError ? {
|
|
90
|
+
status: 'errored'
|
|
91
|
+
} : state;
|
|
92
92
|
return /*#__PURE__*/React.createElement(FlexibleCard, {
|
|
93
|
-
cardState:
|
|
93
|
+
cardState: cardState,
|
|
94
94
|
onAuthorize: services.length && handleAuthorize || undefined,
|
|
95
95
|
onClick: handleClickWrapper,
|
|
96
96
|
renderers: renderers,
|
|
@@ -98,6 +98,11 @@ export function CardWithUrlContent(_ref) {
|
|
|
98
98
|
url: url,
|
|
99
99
|
testId: testId
|
|
100
100
|
}, children);
|
|
101
|
+
} // We have to keep this last to prevent hook order from being violated
|
|
102
|
+
|
|
103
|
+
|
|
104
|
+
if (error) {
|
|
105
|
+
throw error;
|
|
101
106
|
}
|
|
102
107
|
|
|
103
108
|
switch (appearance) {
|
|
@@ -1,19 +1,96 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
|
|
4
|
+
/** @jsx jsx */
|
|
5
|
+
import { jsx } from '@emotion/core';
|
|
6
|
+
import React, { useCallback, useRef, useMemo } from 'react';
|
|
3
7
|
import { TitleBlock, SnippetBlock, FooterBlock } from '../FlexibleCard/components/blocks';
|
|
4
8
|
import { Card } from '../Card';
|
|
9
|
+
import Popup from '@atlaskit/popup';
|
|
10
|
+
import { SmartLinkSize, ActionName } from '../../constants';
|
|
11
|
+
import { useSmartLinkActions } from '../../state/hooks-external/useSmartLinkActions';
|
|
5
12
|
import { HoverCardContainer } from './styled';
|
|
6
13
|
export var HoverCard = function HoverCard(_ref) {
|
|
7
14
|
var children = _ref.children,
|
|
8
15
|
url = _ref.url;
|
|
9
|
-
var
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
+
var delay = 300;
|
|
17
|
+
|
|
18
|
+
var _React$useState = React.useState(false),
|
|
19
|
+
_React$useState2 = _slicedToArray(_React$useState, 2),
|
|
20
|
+
isOpen = _React$useState2[0],
|
|
21
|
+
setIsOpen = _React$useState2[1];
|
|
22
|
+
|
|
23
|
+
var fadeOutTimeoutId = useRef();
|
|
24
|
+
var fadeInTimeoutId = useRef();
|
|
25
|
+
var initHideCard = useCallback(function () {
|
|
26
|
+
if (fadeInTimeoutId.current) {
|
|
27
|
+
clearTimeout(fadeInTimeoutId.current);
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
fadeOutTimeoutId.current = setTimeout(function () {
|
|
31
|
+
setIsOpen(false);
|
|
32
|
+
}, delay);
|
|
33
|
+
}, [delay]);
|
|
34
|
+
var initShowCard = useCallback(function () {
|
|
35
|
+
if (fadeOutTimeoutId.current) {
|
|
36
|
+
clearTimeout(fadeOutTimeoutId.current);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
fadeInTimeoutId.current = setTimeout(function () {
|
|
40
|
+
setIsOpen(true);
|
|
41
|
+
}, delay);
|
|
42
|
+
}, [delay]); //TODO: EDM-2905: Add analytics events
|
|
43
|
+
|
|
44
|
+
var analyticsHandler = useCallback(function () {}, []);
|
|
45
|
+
var linkActions = useSmartLinkActions({
|
|
46
|
+
url: url,
|
|
47
|
+
appearance: 'block',
|
|
48
|
+
analyticsHandler: analyticsHandler
|
|
49
|
+
});
|
|
50
|
+
var actions = useMemo(function () {
|
|
51
|
+
return linkActions.map(function (action) {
|
|
52
|
+
return {
|
|
53
|
+
content: action.text,
|
|
54
|
+
name: ActionName.CustomAction,
|
|
55
|
+
onClick: function onClick() {
|
|
56
|
+
return action.invoke();
|
|
57
|
+
},
|
|
58
|
+
testId: action.id
|
|
59
|
+
};
|
|
60
|
+
});
|
|
61
|
+
}, [linkActions]);
|
|
62
|
+
|
|
63
|
+
var cardComponent = function cardComponent() {
|
|
64
|
+
return jsx("div", {
|
|
65
|
+
onMouseEnter: initShowCard,
|
|
66
|
+
onMouseLeave: initHideCard,
|
|
67
|
+
css: HoverCardContainer
|
|
68
|
+
}, jsx(Card, {
|
|
69
|
+
appearance: "block",
|
|
70
|
+
url: url,
|
|
71
|
+
ui: {
|
|
72
|
+
hideElevation: true,
|
|
73
|
+
size: SmartLinkSize.Large
|
|
74
|
+
}
|
|
75
|
+
}, jsx(TitleBlock, null), jsx(SnippetBlock, null), jsx(FooterBlock, {
|
|
76
|
+
actions: actions
|
|
77
|
+
})));
|
|
78
|
+
};
|
|
79
|
+
|
|
80
|
+
var onClose = useCallback(function () {
|
|
81
|
+
return setIsOpen(false);
|
|
82
|
+
}, []);
|
|
83
|
+
return jsx(Popup, {
|
|
16
84
|
testId: "hover-card",
|
|
17
|
-
|
|
18
|
-
|
|
85
|
+
isOpen: isOpen,
|
|
86
|
+
onClose: onClose,
|
|
87
|
+
placement: "bottom",
|
|
88
|
+
content: cardComponent,
|
|
89
|
+
trigger: function trigger(triggerProps) {
|
|
90
|
+
return jsx("span", _extends({}, triggerProps, {
|
|
91
|
+
onMouseEnter: initShowCard,
|
|
92
|
+
onMouseLeave: initHideCard
|
|
93
|
+
}), children);
|
|
94
|
+
}
|
|
95
|
+
});
|
|
19
96
|
};
|
|
@@ -2,6 +2,5 @@ import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral
|
|
|
2
2
|
|
|
3
3
|
var _templateObject;
|
|
4
4
|
|
|
5
|
-
import
|
|
6
|
-
|
|
7
|
-
export var HoverCardContainer = styled(TooltipPrimitive)(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n background: none;\n border-width: 0;\n box-sizing: content-box; /* do not set this to border-box or it will break the overflow handling */\n max-width: 500px;\n padding: 0;\n"])));
|
|
5
|
+
import { css } from '@emotion/core';
|
|
6
|
+
export var HoverCardContainer = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n background: none;\n border-width: 0;\n max-width: 500px;\n padding: 0;\n"])));
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import React from 'react';
|
|
2
2
|
import { CardAppearance, CardPlatform, CardProps } from './types';
|
|
3
3
|
import { WrappedComponentProps } from 'react-intl-next';
|
|
4
|
-
export declare const Card: React.ForwardRefExoticComponent<Pick<Pick<React.PropsWithChildren<import("react-intl-next").WithIntlProps<CardProps & WrappedComponentProps<"intl">>>, "children" | "data" | "appearance" | "testId" | "isSelected" | "inheritDimensions" | "onClick" | "url" | "
|
|
4
|
+
export declare const Card: React.ForwardRefExoticComponent<Pick<Pick<React.PropsWithChildren<import("react-intl-next").WithIntlProps<CardProps & WrappedComponentProps<"intl">>>, "children" | "data" | "appearance" | "testId" | "isSelected" | "inheritDimensions" | "onClick" | "url" | "ui" | "showActions" | "onResolve" | "platform" | "forwardedRef" | "isFrameVisible" | "importer" | "container" | "embedIframeRef" | "inlinePreloaderStyle"> & React.RefAttributes<any> & import("@atlaskit/analytics-next").WithContextProps, "children" | "data" | "appearance" | "testId" | "isSelected" | "inheritDimensions" | "onClick" | "analyticsContext" | "key" | "url" | "ui" | "showActions" | "onResolve" | "platform" | "forwardedRef" | "isFrameVisible" | "importer" | "container" | "embedIframeRef" | "inlinePreloaderStyle"> & React.RefAttributes<any>>;
|
|
5
5
|
export type { CardAppearance, CardProps, CardPlatform };
|
|
@@ -1,2 +1 @@
|
|
|
1
|
-
|
|
2
|
-
export declare const HoverCardContainer: import("@emotion/styled-base").StyledComponent<Pick<import("@atlaskit/tooltip").TooltipPrimitiveProps, "children" | "style" | "testId" | "className" | "id" | "onMouseOut" | "onMouseOver" | "placement" | "truncate"> & import("react").RefAttributes<HTMLDivElement> & import("react").Attributes, Pick<Pick<import("@atlaskit/tooltip").TooltipPrimitiveProps, "children" | "style" | "testId" | "className" | "id" | "onMouseOut" | "onMouseOver" | "placement" | "truncate"> & import("react").RefAttributes<HTMLDivElement> & import("react").Attributes, "children" | "style" | "testId" | "className" | "id" | "onMouseOut" | "onMouseOver" | "placement" | "truncate">, any>;
|
|
1
|
+
export declare const HoverCardContainer: import("@emotion/utils").SerializedStyles;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@atlaskit/smart-card",
|
|
3
|
-
"version": "18.0.
|
|
3
|
+
"version": "18.0.3",
|
|
4
4
|
"description": "Smart card component",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"registry": "https://registry.npmjs.org/"
|
|
@@ -39,6 +39,7 @@
|
|
|
39
39
|
"@atlaskit/media-ui": "^21.0.0",
|
|
40
40
|
"@atlaskit/modal-dialog": "^12.2.0",
|
|
41
41
|
"@atlaskit/outbound-auth-flow-client": "^3.3.0",
|
|
42
|
+
"@atlaskit/popup": "^1.3.0",
|
|
42
43
|
"@atlaskit/spinner": "^15.1.0",
|
|
43
44
|
"@atlaskit/theme": "^12.1.0",
|
|
44
45
|
"@atlaskit/tokens": "^0.8.0",
|