@atlaskit/smart-card 23.13.2 → 23.13.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 +6 -0
- package/dist/cjs/version.json +1 -1
- package/dist/cjs/view/FlexibleCard/components/blocks/action-group/action-group-item/index.js +88 -0
- package/dist/cjs/view/FlexibleCard/components/blocks/action-group/index.js +90 -42
- package/dist/cjs/view/FlexibleCard/components/blocks/utils.js +5 -69
- package/dist/cjs/view/FlexibleCard/index.js +3 -1
- package/dist/cjs/view/HoverCard/components/HoverCardComponent.js +27 -25
- package/dist/es2019/version.json +1 -1
- package/dist/es2019/view/FlexibleCard/components/blocks/action-group/action-group-item/index.js +64 -0
- package/dist/es2019/view/FlexibleCard/components/blocks/action-group/index.js +75 -34
- package/dist/es2019/view/FlexibleCard/components/blocks/utils.js +3 -56
- package/dist/es2019/view/FlexibleCard/index.js +2 -2
- package/dist/es2019/view/HoverCard/components/HoverCardComponent.js +24 -22
- package/dist/esm/version.json +1 -1
- package/dist/esm/view/FlexibleCard/components/blocks/action-group/action-group-item/index.js +69 -0
- package/dist/esm/view/FlexibleCard/components/blocks/action-group/index.js +89 -42
- package/dist/esm/view/FlexibleCard/components/blocks/utils.js +4 -66
- package/dist/esm/view/FlexibleCard/index.js +4 -2
- package/dist/esm/view/HoverCard/components/HoverCardComponent.js +27 -25
- package/dist/types/view/FlexibleCard/components/blocks/action-group/action-group-item/index.d.ts +12 -0
- package/dist/types/view/FlexibleCard/components/blocks/utils.d.ts +2 -3
- package/package.json +1 -1
|
@@ -6,14 +6,15 @@ import { FormattedMessage } from 'react-intl-next';
|
|
|
6
6
|
import { css, jsx } from '@emotion/react';
|
|
7
7
|
import ButtonGroup from '@atlaskit/button/button-group';
|
|
8
8
|
import Tooltip from '@atlaskit/tooltip';
|
|
9
|
-
import { renderActionItems } from '../utils';
|
|
10
9
|
import DropdownMenu from '@atlaskit/dropdown-menu';
|
|
11
|
-
import { SmartLinkSize } from '../../../../../constants';
|
|
10
|
+
import { ActionName, SmartLinkSize } from '../../../../../constants';
|
|
12
11
|
import Button from '@atlaskit/button/standard-button';
|
|
13
12
|
import MoreIcon from '@atlaskit/icon/glyph/more';
|
|
14
13
|
import { sizeToButtonSpacing } from '../../utils';
|
|
15
14
|
import { tokens } from '../../../../../utils/token';
|
|
16
15
|
import { messages } from '../../../../../messages';
|
|
16
|
+
import { useFlexibleUiContext } from '../../../../../state/flexible-ui-context';
|
|
17
|
+
import ActionGroupItem from './action-group-item';
|
|
17
18
|
const styles = css`
|
|
18
19
|
display: inline-flex;
|
|
19
20
|
line-height: 1rem;
|
|
@@ -30,6 +31,35 @@ const styles = css`
|
|
|
30
31
|
}
|
|
31
32
|
}
|
|
32
33
|
`;
|
|
34
|
+
|
|
35
|
+
const renderActionItems = (items = [], size = SmartLinkSize.Medium, appearance, asDropDownItems, onActionItemClick) => items.map((item, idx) => jsx(ActionGroupItem, {
|
|
36
|
+
item: item,
|
|
37
|
+
key: idx,
|
|
38
|
+
size: size,
|
|
39
|
+
appearance: appearance,
|
|
40
|
+
asDropDownItems: asDropDownItems,
|
|
41
|
+
onActionItemClick: onActionItemClick
|
|
42
|
+
}));
|
|
43
|
+
|
|
44
|
+
const filterActionItems = (items = [], context) => {
|
|
45
|
+
return items.filter(item => {
|
|
46
|
+
switch (item.name) {
|
|
47
|
+
// Action that require data from the data context to render.
|
|
48
|
+
case ActionName.DownloadAction:
|
|
49
|
+
return Boolean(context === null || context === void 0 ? void 0 : context.downloadAction);
|
|
50
|
+
|
|
51
|
+
case ActionName.PreviewAction:
|
|
52
|
+
return Boolean(context === null || context === void 0 ? void 0 : context.previewAction);
|
|
53
|
+
|
|
54
|
+
case ActionName.ViewAction:
|
|
55
|
+
return Boolean(context === null || context === void 0 ? void 0 : context.viewAction);
|
|
56
|
+
|
|
57
|
+
default:
|
|
58
|
+
// Named and custom actions that user defines.
|
|
59
|
+
return Boolean(ActionName[item.name]);
|
|
60
|
+
}
|
|
61
|
+
});
|
|
62
|
+
};
|
|
33
63
|
/**
|
|
34
64
|
* Creates a group of Action components. Accepts an array of Actions, in addition to some styling
|
|
35
65
|
* preferences.
|
|
@@ -38,6 +68,7 @@ const styles = css`
|
|
|
38
68
|
* @see Action
|
|
39
69
|
*/
|
|
40
70
|
|
|
71
|
+
|
|
41
72
|
const ActionGroup = ({
|
|
42
73
|
items = [],
|
|
43
74
|
size = SmartLinkSize.Medium,
|
|
@@ -46,7 +77,10 @@ const ActionGroup = ({
|
|
|
46
77
|
onDropdownOpenChange,
|
|
47
78
|
testId
|
|
48
79
|
}) => {
|
|
80
|
+
const context = useFlexibleUiContext();
|
|
49
81
|
const [isOpen, setIsOpen] = useState(false);
|
|
82
|
+
const renderableActionItems = useMemo(() => filterActionItems(items, context), [context, items]);
|
|
83
|
+
const isMoreThenTwoItems = renderableActionItems.length > visibleButtonsNum;
|
|
50
84
|
const onOpenChange = useCallback(attrs => {
|
|
51
85
|
setIsOpen(attrs.isOpen);
|
|
52
86
|
|
|
@@ -54,46 +88,53 @@ const ActionGroup = ({
|
|
|
54
88
|
onDropdownOpenChange(attrs.isOpen);
|
|
55
89
|
}
|
|
56
90
|
}, [onDropdownOpenChange]);
|
|
57
|
-
const
|
|
91
|
+
const onActionItemClick = useCallback(() => {
|
|
58
92
|
if (isOpen) {
|
|
59
93
|
onOpenChange({
|
|
60
94
|
isOpen: false
|
|
61
95
|
});
|
|
62
96
|
}
|
|
63
97
|
}, [isOpen, onOpenChange]);
|
|
64
|
-
const
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
72
|
-
|
|
73
|
-
|
|
98
|
+
const actionButtons = useMemo(() => {
|
|
99
|
+
const actionItems = isMoreThenTwoItems ? renderableActionItems.slice(0, visibleButtonsNum - 1) : renderableActionItems;
|
|
100
|
+
return renderActionItems(actionItems, size, appearance, false, onActionItemClick);
|
|
101
|
+
}, [appearance, isMoreThenTwoItems, onActionItemClick, renderableActionItems, size, visibleButtonsNum]);
|
|
102
|
+
const moreActionDropdown = useMemo(() => {
|
|
103
|
+
const actionItems = isMoreThenTwoItems ? renderableActionItems.slice(visibleButtonsNum - 1) : [];
|
|
104
|
+
|
|
105
|
+
if (actionItems.length > 0) {
|
|
106
|
+
const spacing = sizeToButtonSpacing[size];
|
|
107
|
+
const moreIcon = jsx(MoreIcon, {
|
|
108
|
+
label: "more"
|
|
109
|
+
});
|
|
110
|
+
const formatMessage = jsx(FormattedMessage, messages.more_actions);
|
|
111
|
+
return jsx(DropdownMenu, {
|
|
112
|
+
isOpen: isOpen,
|
|
113
|
+
onOpenChange: onOpenChange,
|
|
114
|
+
trigger: ({
|
|
115
|
+
triggerRef,
|
|
116
|
+
...props
|
|
117
|
+
}) => jsx(Tooltip, {
|
|
118
|
+
content: formatMessage,
|
|
119
|
+
hideTooltipOnClick: true,
|
|
120
|
+
testId: "action-group-more-button-tooltip",
|
|
121
|
+
tag: "span"
|
|
122
|
+
}, jsx(Button, _extends({}, props, {
|
|
123
|
+
spacing: spacing,
|
|
124
|
+
testId: "action-group-more-button",
|
|
125
|
+
iconBefore: moreIcon,
|
|
126
|
+
ref: triggerRef
|
|
127
|
+
}))),
|
|
128
|
+
testId: "action-group-dropdown"
|
|
129
|
+
}, renderActionItems(actionItems, size, appearance, true, onActionItemClick));
|
|
130
|
+
}
|
|
131
|
+
|
|
132
|
+
return null;
|
|
133
|
+
}, [appearance, isMoreThenTwoItems, isOpen, onActionItemClick, onOpenChange, renderableActionItems, size, visibleButtonsNum]);
|
|
134
|
+
return renderableActionItems.length > 0 ? jsx("div", {
|
|
74
135
|
css: styles,
|
|
75
136
|
className: "actions-button-group"
|
|
76
|
-
}, jsx(ButtonGroup, null,
|
|
77
|
-
isOpen: isOpen,
|
|
78
|
-
onOpenChange: onOpenChange,
|
|
79
|
-
trigger: ({
|
|
80
|
-
triggerRef,
|
|
81
|
-
...props
|
|
82
|
-
}) => jsx(Tooltip, {
|
|
83
|
-
content: jsx(FormattedMessage, messages.more_actions),
|
|
84
|
-
hideTooltipOnClick: true,
|
|
85
|
-
testId: "action-group-more-button-tooltip",
|
|
86
|
-
tag: "span"
|
|
87
|
-
}, jsx(Button, _extends({}, props, {
|
|
88
|
-
spacing: sizeToButtonSpacing[size],
|
|
89
|
-
testId: "action-group-more-button",
|
|
90
|
-
iconBefore: jsx(MoreIcon, {
|
|
91
|
-
label: "more"
|
|
92
|
-
}),
|
|
93
|
-
ref: triggerRef
|
|
94
|
-
}))),
|
|
95
|
-
testId: "action-group-dropdown"
|
|
96
|
-
}, dropdownMenuElement) : null));
|
|
137
|
+
}, jsx(ButtonGroup, null, actionButtons, moreActionDropdown)) : null;
|
|
97
138
|
};
|
|
98
139
|
|
|
99
140
|
export default ActionGroup;
|
|
@@ -3,10 +3,10 @@ import React from 'react';
|
|
|
3
3
|
import { css } from '@emotion/react';
|
|
4
4
|
import { ElementName, SmartLinkDirection, SmartLinkSize } from '../../../../constants';
|
|
5
5
|
import * as Elements from '../elements';
|
|
6
|
-
import * as Actions from '../actions';
|
|
7
6
|
import { isFlexibleUiElement } from '../../../../utils/flexible';
|
|
8
7
|
import ActionGroup from './action-group';
|
|
9
|
-
import ElementGroup from './element-group';
|
|
8
|
+
import ElementGroup from './element-group'; // Determine whether the element can be display as inline/block.
|
|
9
|
+
|
|
10
10
|
export const ElementDisplaySchema = {
|
|
11
11
|
[ElementName.AttachmentCount]: ['inline'],
|
|
12
12
|
[ElementName.AuthorGroup]: ['inline'],
|
|
@@ -106,7 +106,7 @@ const isElementDisplayValid = (name, display) => {
|
|
|
106
106
|
return (_ElementDisplaySchema = (_ElementDisplaySchema2 = ElementDisplaySchema[name]) === null || _ElementDisplaySchema2 === void 0 ? void 0 : _ElementDisplaySchema2.includes(display)) !== null && _ElementDisplaySchema !== void 0 ? _ElementDisplaySchema : false;
|
|
107
107
|
};
|
|
108
108
|
|
|
109
|
-
const isJSXElementNull = children => {
|
|
109
|
+
export const isJSXElementNull = children => {
|
|
110
110
|
return Boolean(children.type() === null);
|
|
111
111
|
};
|
|
112
112
|
|
|
@@ -150,57 +150,4 @@ export const renderElementItems = (items = [], display = 'inline') => {
|
|
|
150
150
|
if (elements.length) {
|
|
151
151
|
return elements;
|
|
152
152
|
}
|
|
153
|
-
};
|
|
154
|
-
export const renderActionItems = (items = [], size = SmartLinkSize.Medium, appearance, asDropDownItems, onActionItemClick) => {
|
|
155
|
-
const actions = items.reduce((acc, curr, idx) => {
|
|
156
|
-
const {
|
|
157
|
-
name,
|
|
158
|
-
hideContent,
|
|
159
|
-
hideIcon,
|
|
160
|
-
onClick,
|
|
161
|
-
...props
|
|
162
|
-
} = curr;
|
|
163
|
-
const Action = Actions[name];
|
|
164
|
-
const actionProps = { ...props
|
|
165
|
-
};
|
|
166
|
-
|
|
167
|
-
if (hideContent && !asDropDownItems) {
|
|
168
|
-
actionProps.content = '';
|
|
169
|
-
}
|
|
170
|
-
|
|
171
|
-
if (hideIcon) {
|
|
172
|
-
actionProps.icon = undefined;
|
|
173
|
-
}
|
|
174
|
-
|
|
175
|
-
if (Action) {
|
|
176
|
-
const handleOnClick = () => {
|
|
177
|
-
if (onActionItemClick) {
|
|
178
|
-
onActionItemClick();
|
|
179
|
-
}
|
|
180
|
-
|
|
181
|
-
if (onClick) {
|
|
182
|
-
onClick();
|
|
183
|
-
}
|
|
184
|
-
};
|
|
185
|
-
|
|
186
|
-
const action = /*#__PURE__*/React.createElement(Action, _extends({
|
|
187
|
-
url: '',
|
|
188
|
-
asDropDownItem: asDropDownItems,
|
|
189
|
-
size: size,
|
|
190
|
-
key: idx,
|
|
191
|
-
appearance: appearance,
|
|
192
|
-
onClick: handleOnClick
|
|
193
|
-
}, actionProps));
|
|
194
|
-
|
|
195
|
-
if (!isJSXElementNull(action)) {
|
|
196
|
-
return [...acc, action];
|
|
197
|
-
}
|
|
198
|
-
}
|
|
199
|
-
|
|
200
|
-
return acc;
|
|
201
|
-
}, []);
|
|
202
|
-
|
|
203
|
-
if (actions.length) {
|
|
204
|
-
return actions;
|
|
205
|
-
}
|
|
206
153
|
};
|
|
@@ -1,5 +1,5 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
-
import React, { useEffect } from 'react';
|
|
2
|
+
import React, { useEffect, useMemo } from 'react';
|
|
3
3
|
import { SmartLinkStatus } from '../../constants';
|
|
4
4
|
import Container from './components/container';
|
|
5
5
|
import { FlexibleUiAnalyticsContext, FlexibleUiContext } from '../../state/flexible-ui-context';
|
|
@@ -30,7 +30,7 @@ const FlexibleCard = ({
|
|
|
30
30
|
details
|
|
31
31
|
} = cardState;
|
|
32
32
|
const status = cardType;
|
|
33
|
-
const context = getContextByStatus(url, status, details, renderers);
|
|
33
|
+
const context = useMemo(() => getContextByStatus(url, status, details, renderers), [details, renderers, status, url]);
|
|
34
34
|
const retry = getRetryOptions(url, status, details, onAuthorize);
|
|
35
35
|
const {
|
|
36
36
|
title
|
|
@@ -111,6 +111,28 @@ export const HoverCardComponent = ({
|
|
|
111
111
|
hideCard();
|
|
112
112
|
}
|
|
113
113
|
}, [closeOnChildClick, hideCard]);
|
|
114
|
+
const content = useCallback(({
|
|
115
|
+
update
|
|
116
|
+
}) => jsx(HoverCardContent, {
|
|
117
|
+
onMouseEnter: initShowCard,
|
|
118
|
+
onMouseLeave: initHideCard,
|
|
119
|
+
analytics: analytics,
|
|
120
|
+
cardActions: linkActions,
|
|
121
|
+
cardState: linkState,
|
|
122
|
+
onActionClick: onActionClick,
|
|
123
|
+
onResolve: update,
|
|
124
|
+
renderers: renderers,
|
|
125
|
+
url: url
|
|
126
|
+
}), [analytics, initHideCard, initShowCard, linkActions, linkState, onActionClick, renderers, url]);
|
|
127
|
+
const trigger = useCallback(triggerProps => jsx("span", {
|
|
128
|
+
ref: parentSpan
|
|
129
|
+
}, jsx("span", _extends({}, triggerProps, {
|
|
130
|
+
onMouseEnter: initShowCard,
|
|
131
|
+
onMouseLeave: initHideCard,
|
|
132
|
+
onMouseMove: setMousePosition,
|
|
133
|
+
onClick: onChildClick,
|
|
134
|
+
"data-testid": "hover-card-trigger-wrapper"
|
|
135
|
+
}), children)), [children, initHideCard, initShowCard, onChildClick, setMousePosition]);
|
|
114
136
|
return jsx(Popup, {
|
|
115
137
|
testId: "hover-card",
|
|
116
138
|
isOpen: isOpen && canOpen,
|
|
@@ -118,28 +140,8 @@ export const HoverCardComponent = ({
|
|
|
118
140
|
placement: "bottom-start",
|
|
119
141
|
offset: popupOffset.current,
|
|
120
142
|
autoFocus: false,
|
|
121
|
-
content:
|
|
122
|
-
|
|
123
|
-
}) => jsx(HoverCardContent, {
|
|
124
|
-
onMouseEnter: initShowCard,
|
|
125
|
-
onMouseLeave: initHideCard,
|
|
126
|
-
analytics: analytics,
|
|
127
|
-
cardActions: linkActions,
|
|
128
|
-
cardState: linkState,
|
|
129
|
-
onActionClick: onActionClick,
|
|
130
|
-
onResolve: update,
|
|
131
|
-
renderers: renderers,
|
|
132
|
-
url: url
|
|
133
|
-
}),
|
|
134
|
-
trigger: triggerProps => jsx("span", {
|
|
135
|
-
ref: parentSpan
|
|
136
|
-
}, jsx("span", _extends({}, triggerProps, {
|
|
137
|
-
onMouseEnter: initShowCard,
|
|
138
|
-
onMouseLeave: initHideCard,
|
|
139
|
-
onMouseMove: setMousePosition,
|
|
140
|
-
onClick: onChildClick,
|
|
141
|
-
"data-testid": "hover-card-trigger-wrapper"
|
|
142
|
-
}), children)),
|
|
143
|
+
content: content,
|
|
144
|
+
trigger: trigger,
|
|
143
145
|
zIndex: 511 // Temporary fix for Confluence inline comment on editor mod has z-index of 500, Jira issue view has z-index of 510
|
|
144
146
|
|
|
145
147
|
});
|
package/dist/esm/version.json
CHANGED
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
+
var _excluded = ["name", "hideContent", "hideIcon", "onClick"];
|
|
5
|
+
|
|
6
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
7
|
+
|
|
8
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
9
|
+
|
|
10
|
+
/** @jsx jsx */
|
|
11
|
+
import { jsx } from '@emotion/react';
|
|
12
|
+
import React, { useCallback } from 'react';
|
|
13
|
+
import * as Actions from '../../../actions';
|
|
14
|
+
import { isJSXElementNull } from '../../utils';
|
|
15
|
+
|
|
16
|
+
var ActionGroupItem = function ActionGroupItem(_ref) {
|
|
17
|
+
var item = _ref.item,
|
|
18
|
+
size = _ref.size,
|
|
19
|
+
appearance = _ref.appearance,
|
|
20
|
+
asDropDownItems = _ref.asDropDownItems,
|
|
21
|
+
onActionItemClick = _ref.onActionItemClick;
|
|
22
|
+
|
|
23
|
+
var name = item.name,
|
|
24
|
+
hideContent = item.hideContent,
|
|
25
|
+
hideIcon = item.hideIcon,
|
|
26
|
+
onClick = item.onClick,
|
|
27
|
+
props = _objectWithoutProperties(item, _excluded);
|
|
28
|
+
|
|
29
|
+
var handleOnClick = useCallback(function () {
|
|
30
|
+
if (onActionItemClick) {
|
|
31
|
+
onActionItemClick();
|
|
32
|
+
}
|
|
33
|
+
|
|
34
|
+
if (onClick) {
|
|
35
|
+
onClick();
|
|
36
|
+
}
|
|
37
|
+
}, [onActionItemClick, onClick]);
|
|
38
|
+
var Action = Actions[name];
|
|
39
|
+
|
|
40
|
+
if (!Action) {
|
|
41
|
+
return null;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
var actionProps = _objectSpread({}, props);
|
|
45
|
+
|
|
46
|
+
if (hideContent && !asDropDownItems) {
|
|
47
|
+
actionProps.content = '';
|
|
48
|
+
}
|
|
49
|
+
|
|
50
|
+
if (hideIcon) {
|
|
51
|
+
actionProps.icon = undefined;
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
var action = jsx(Action, _extends({
|
|
55
|
+
url: "",
|
|
56
|
+
asDropDownItem: asDropDownItems,
|
|
57
|
+
size: size,
|
|
58
|
+
appearance: appearance,
|
|
59
|
+
onClick: handleOnClick
|
|
60
|
+
}, actionProps));
|
|
61
|
+
|
|
62
|
+
if (!isJSXElementNull(action)) {
|
|
63
|
+
return action;
|
|
64
|
+
}
|
|
65
|
+
|
|
66
|
+
return null;
|
|
67
|
+
};
|
|
68
|
+
|
|
69
|
+
export default ActionGroupItem;
|
|
@@ -12,15 +12,56 @@ import { FormattedMessage } from 'react-intl-next';
|
|
|
12
12
|
import { css, jsx } from '@emotion/react';
|
|
13
13
|
import ButtonGroup from '@atlaskit/button/button-group';
|
|
14
14
|
import Tooltip from '@atlaskit/tooltip';
|
|
15
|
-
import { renderActionItems } from '../utils';
|
|
16
15
|
import DropdownMenu from '@atlaskit/dropdown-menu';
|
|
17
|
-
import { SmartLinkSize } from '../../../../../constants';
|
|
16
|
+
import { ActionName, SmartLinkSize } from '../../../../../constants';
|
|
18
17
|
import Button from '@atlaskit/button/standard-button';
|
|
19
18
|
import MoreIcon from '@atlaskit/icon/glyph/more';
|
|
20
19
|
import { sizeToButtonSpacing } from '../../utils';
|
|
21
20
|
import { tokens } from '../../../../../utils/token';
|
|
22
21
|
import { messages } from '../../../../../messages';
|
|
22
|
+
import { useFlexibleUiContext } from '../../../../../state/flexible-ui-context';
|
|
23
|
+
import ActionGroupItem from './action-group-item';
|
|
23
24
|
var styles = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n display: inline-flex;\n line-height: 1rem;\n > div {\n align-items: center;\n button:focus {\n // AK button removes the default browser outline on focus and apply\n // box-shadow styling to create the outline appearance.\n // Due to our container elements (Container/Block/ElementGroup) has\n // overflow hidden to prevent the metadata element from leaking outside\n // of its container, the box-shadow doesn't show properly.\n // Invert the AK box-shadow styling.\n box-shadow: inset 0 0 0 2px ", ";\n }\n }\n"])), tokens.focus);
|
|
25
|
+
|
|
26
|
+
var renderActionItems = function renderActionItems() {
|
|
27
|
+
var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
28
|
+
var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SmartLinkSize.Medium;
|
|
29
|
+
var appearance = arguments.length > 2 ? arguments[2] : undefined;
|
|
30
|
+
var asDropDownItems = arguments.length > 3 ? arguments[3] : undefined;
|
|
31
|
+
var onActionItemClick = arguments.length > 4 ? arguments[4] : undefined;
|
|
32
|
+
return items.map(function (item, idx) {
|
|
33
|
+
return jsx(ActionGroupItem, {
|
|
34
|
+
item: item,
|
|
35
|
+
key: idx,
|
|
36
|
+
size: size,
|
|
37
|
+
appearance: appearance,
|
|
38
|
+
asDropDownItems: asDropDownItems,
|
|
39
|
+
onActionItemClick: onActionItemClick
|
|
40
|
+
});
|
|
41
|
+
});
|
|
42
|
+
};
|
|
43
|
+
|
|
44
|
+
var filterActionItems = function filterActionItems() {
|
|
45
|
+
var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
46
|
+
var context = arguments.length > 1 ? arguments[1] : undefined;
|
|
47
|
+
return items.filter(function (item) {
|
|
48
|
+
switch (item.name) {
|
|
49
|
+
// Action that require data from the data context to render.
|
|
50
|
+
case ActionName.DownloadAction:
|
|
51
|
+
return Boolean(context === null || context === void 0 ? void 0 : context.downloadAction);
|
|
52
|
+
|
|
53
|
+
case ActionName.PreviewAction:
|
|
54
|
+
return Boolean(context === null || context === void 0 ? void 0 : context.previewAction);
|
|
55
|
+
|
|
56
|
+
case ActionName.ViewAction:
|
|
57
|
+
return Boolean(context === null || context === void 0 ? void 0 : context.viewAction);
|
|
58
|
+
|
|
59
|
+
default:
|
|
60
|
+
// Named and custom actions that user defines.
|
|
61
|
+
return Boolean(ActionName[item.name]);
|
|
62
|
+
}
|
|
63
|
+
});
|
|
64
|
+
};
|
|
24
65
|
/**
|
|
25
66
|
* Creates a group of Action components. Accepts an array of Actions, in addition to some styling
|
|
26
67
|
* preferences.
|
|
@@ -29,6 +70,7 @@ var styles = css(_templateObject || (_templateObject = _taggedTemplateLiteral(["
|
|
|
29
70
|
* @see Action
|
|
30
71
|
*/
|
|
31
72
|
|
|
73
|
+
|
|
32
74
|
var ActionGroup = function ActionGroup(_ref) {
|
|
33
75
|
var _ref$items = _ref.items,
|
|
34
76
|
items = _ref$items === void 0 ? [] : _ref$items,
|
|
@@ -39,12 +81,17 @@ var ActionGroup = function ActionGroup(_ref) {
|
|
|
39
81
|
visibleButtonsNum = _ref$visibleButtonsNu === void 0 ? 2 : _ref$visibleButtonsNu,
|
|
40
82
|
onDropdownOpenChange = _ref.onDropdownOpenChange,
|
|
41
83
|
testId = _ref.testId;
|
|
84
|
+
var context = useFlexibleUiContext();
|
|
42
85
|
|
|
43
86
|
var _useState = useState(false),
|
|
44
87
|
_useState2 = _slicedToArray(_useState, 2),
|
|
45
88
|
isOpen = _useState2[0],
|
|
46
89
|
setIsOpen = _useState2[1];
|
|
47
90
|
|
|
91
|
+
var renderableActionItems = useMemo(function () {
|
|
92
|
+
return filterActionItems(items, context);
|
|
93
|
+
}, [context, items]);
|
|
94
|
+
var isMoreThenTwoItems = renderableActionItems.length > visibleButtonsNum;
|
|
48
95
|
var onOpenChange = useCallback(function (attrs) {
|
|
49
96
|
setIsOpen(attrs.isOpen);
|
|
50
97
|
|
|
@@ -52,55 +99,55 @@ var ActionGroup = function ActionGroup(_ref) {
|
|
|
52
99
|
onDropdownOpenChange(attrs.isOpen);
|
|
53
100
|
}
|
|
54
101
|
}, [onDropdownOpenChange]);
|
|
55
|
-
var
|
|
102
|
+
var onActionItemClick = useCallback(function () {
|
|
56
103
|
if (isOpen) {
|
|
57
104
|
onOpenChange({
|
|
58
105
|
isOpen: false
|
|
59
106
|
});
|
|
60
107
|
}
|
|
61
108
|
}, [isOpen, onOpenChange]);
|
|
62
|
-
var
|
|
63
|
-
|
|
64
|
-
|
|
109
|
+
var actionButtons = useMemo(function () {
|
|
110
|
+
var actionItems = isMoreThenTwoItems ? renderableActionItems.slice(0, visibleButtonsNum - 1) : renderableActionItems;
|
|
111
|
+
return renderActionItems(actionItems, size, appearance, false, onActionItemClick);
|
|
112
|
+
}, [appearance, isMoreThenTwoItems, onActionItemClick, renderableActionItems, size, visibleButtonsNum]);
|
|
113
|
+
var moreActionDropdown = useMemo(function () {
|
|
114
|
+
var actionItems = isMoreThenTwoItems ? renderableActionItems.slice(visibleButtonsNum - 1) : [];
|
|
115
|
+
|
|
116
|
+
if (actionItems.length > 0) {
|
|
117
|
+
var spacing = sizeToButtonSpacing[size];
|
|
118
|
+
var moreIcon = jsx(MoreIcon, {
|
|
119
|
+
label: "more"
|
|
120
|
+
});
|
|
121
|
+
var formatMessage = jsx(FormattedMessage, messages.more_actions);
|
|
122
|
+
return jsx(DropdownMenu, {
|
|
123
|
+
isOpen: isOpen,
|
|
124
|
+
onOpenChange: onOpenChange,
|
|
125
|
+
trigger: function trigger(_ref2) {
|
|
126
|
+
var triggerRef = _ref2.triggerRef,
|
|
127
|
+
props = _objectWithoutProperties(_ref2, _excluded);
|
|
128
|
+
|
|
129
|
+
return jsx(Tooltip, {
|
|
130
|
+
content: formatMessage,
|
|
131
|
+
hideTooltipOnClick: true,
|
|
132
|
+
testId: "action-group-more-button-tooltip",
|
|
133
|
+
tag: "span"
|
|
134
|
+
}, jsx(Button, _extends({}, props, {
|
|
135
|
+
spacing: spacing,
|
|
136
|
+
testId: "action-group-more-button",
|
|
137
|
+
iconBefore: moreIcon,
|
|
138
|
+
ref: triggerRef
|
|
139
|
+
})));
|
|
140
|
+
},
|
|
141
|
+
testId: "action-group-dropdown"
|
|
142
|
+
}, renderActionItems(actionItems, size, appearance, true, onActionItemClick));
|
|
143
|
+
}
|
|
65
144
|
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
var dropdownItems = isMoreThenTwoItems ? renderableActions.slice(visibleButtonsNum - 1) : [];
|
|
70
|
-
return [buttons, dropdownItems];
|
|
71
|
-
}, [renderableActions, visibleButtonsNum]),
|
|
72
|
-
_useMemo2 = _slicedToArray(_useMemo, 2),
|
|
73
|
-
buttonActions = _useMemo2[0],
|
|
74
|
-
dropdownItemActions = _useMemo2[1];
|
|
75
|
-
|
|
76
|
-
var dropdownMenuElement = renderActionItems(dropdownItemActions, size, appearance, true, onActionClick);
|
|
77
|
-
var buttonGroupElement = renderActionItems(buttonActions, size, appearance, false, onActionClick);
|
|
78
|
-
return jsx("div", {
|
|
145
|
+
return null;
|
|
146
|
+
}, [appearance, isMoreThenTwoItems, isOpen, onActionItemClick, onOpenChange, renderableActionItems, size, visibleButtonsNum]);
|
|
147
|
+
return renderableActionItems.length > 0 ? jsx("div", {
|
|
79
148
|
css: styles,
|
|
80
149
|
className: "actions-button-group"
|
|
81
|
-
}, jsx(ButtonGroup, null,
|
|
82
|
-
isOpen: isOpen,
|
|
83
|
-
onOpenChange: onOpenChange,
|
|
84
|
-
trigger: function trigger(_ref2) {
|
|
85
|
-
var triggerRef = _ref2.triggerRef,
|
|
86
|
-
props = _objectWithoutProperties(_ref2, _excluded);
|
|
87
|
-
|
|
88
|
-
return jsx(Tooltip, {
|
|
89
|
-
content: jsx(FormattedMessage, messages.more_actions),
|
|
90
|
-
hideTooltipOnClick: true,
|
|
91
|
-
testId: "action-group-more-button-tooltip",
|
|
92
|
-
tag: "span"
|
|
93
|
-
}, jsx(Button, _extends({}, props, {
|
|
94
|
-
spacing: sizeToButtonSpacing[size],
|
|
95
|
-
testId: "action-group-more-button",
|
|
96
|
-
iconBefore: jsx(MoreIcon, {
|
|
97
|
-
label: "more"
|
|
98
|
-
}),
|
|
99
|
-
ref: triggerRef
|
|
100
|
-
})));
|
|
101
|
-
},
|
|
102
|
-
testId: "action-group-dropdown"
|
|
103
|
-
}, dropdownMenuElement) : null));
|
|
150
|
+
}, jsx(ButtonGroup, null, actionButtons, moreActionDropdown)) : null;
|
|
104
151
|
};
|
|
105
152
|
|
|
106
153
|
export default ActionGroup;
|
|
@@ -3,23 +3,18 @@ import _extends from "@babel/runtime/helpers/extends";
|
|
|
3
3
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
4
|
import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
|
|
5
5
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
6
|
-
var _excluded = ["name"]
|
|
7
|
-
_excluded2 = ["name", "hideContent", "hideIcon", "onClick"];
|
|
6
|
+
var _excluded = ["name"];
|
|
8
7
|
|
|
9
8
|
var _ElementDisplaySchema, _templateObject, _templateObject2, _templateObject3, _templateObject4;
|
|
10
9
|
|
|
11
|
-
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
12
|
-
|
|
13
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
14
|
-
|
|
15
10
|
import React from 'react';
|
|
16
11
|
import { css } from '@emotion/react';
|
|
17
12
|
import { ElementName, SmartLinkDirection, SmartLinkSize } from '../../../../constants';
|
|
18
13
|
import * as Elements from '../elements';
|
|
19
|
-
import * as Actions from '../actions';
|
|
20
14
|
import { isFlexibleUiElement } from '../../../../utils/flexible';
|
|
21
15
|
import ActionGroup from './action-group';
|
|
22
|
-
import ElementGroup from './element-group';
|
|
16
|
+
import ElementGroup from './element-group'; // Determine whether the element can be display as inline/block.
|
|
17
|
+
|
|
23
18
|
export var ElementDisplaySchema = (_ElementDisplaySchema = {}, _defineProperty(_ElementDisplaySchema, ElementName.AttachmentCount, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.AuthorGroup, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.ChecklistProgress, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.CollaboratorGroup, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.CommentCount, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.ViewCount, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.ReactCount, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.VoteCount, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.CreatedBy, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.CreatedOn, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.DueOn, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.LatestCommit, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.LinkIcon, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.ModifiedBy, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.ModifiedOn, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.Preview, ['block']), _defineProperty(_ElementDisplaySchema, ElementName.Priority, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.ProgrammingLanguage, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.Provider, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.Snippet, ['block']), _defineProperty(_ElementDisplaySchema, ElementName.SourceBranch, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.State, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.SubscriberCount, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.TargetBranch, ['inline']), _defineProperty(_ElementDisplaySchema, ElementName.Title, ['inline']), _ElementDisplaySchema);
|
|
24
19
|
|
|
25
20
|
var getDirectionStyles = function getDirectionStyles(direction) {
|
|
@@ -64,7 +59,7 @@ var isElementDisplayValid = function isElementDisplayValid(name, display) {
|
|
|
64
59
|
return (_ElementDisplaySchema2 = (_ElementDisplaySchema3 = ElementDisplaySchema[name]) === null || _ElementDisplaySchema3 === void 0 ? void 0 : _ElementDisplaySchema3.includes(display)) !== null && _ElementDisplaySchema2 !== void 0 ? _ElementDisplaySchema2 : false;
|
|
65
60
|
};
|
|
66
61
|
|
|
67
|
-
var isJSXElementNull = function isJSXElementNull(children) {
|
|
62
|
+
export var isJSXElementNull = function isJSXElementNull(children) {
|
|
68
63
|
return Boolean(children.type() === null);
|
|
69
64
|
};
|
|
70
65
|
|
|
@@ -111,61 +106,4 @@ export var renderElementItems = function renderElementItems() {
|
|
|
111
106
|
if (elements.length) {
|
|
112
107
|
return elements;
|
|
113
108
|
}
|
|
114
|
-
};
|
|
115
|
-
export var renderActionItems = function renderActionItems() {
|
|
116
|
-
var items = arguments.length > 0 && arguments[0] !== undefined ? arguments[0] : [];
|
|
117
|
-
var size = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : SmartLinkSize.Medium;
|
|
118
|
-
var appearance = arguments.length > 2 ? arguments[2] : undefined;
|
|
119
|
-
var asDropDownItems = arguments.length > 3 ? arguments[3] : undefined;
|
|
120
|
-
var onActionItemClick = arguments.length > 4 ? arguments[4] : undefined;
|
|
121
|
-
var actions = items.reduce(function (acc, curr, idx) {
|
|
122
|
-
var name = curr.name,
|
|
123
|
-
hideContent = curr.hideContent,
|
|
124
|
-
hideIcon = curr.hideIcon,
|
|
125
|
-
onClick = curr.onClick,
|
|
126
|
-
props = _objectWithoutProperties(curr, _excluded2);
|
|
127
|
-
|
|
128
|
-
var Action = Actions[name];
|
|
129
|
-
|
|
130
|
-
var actionProps = _objectSpread({}, props);
|
|
131
|
-
|
|
132
|
-
if (hideContent && !asDropDownItems) {
|
|
133
|
-
actionProps.content = '';
|
|
134
|
-
}
|
|
135
|
-
|
|
136
|
-
if (hideIcon) {
|
|
137
|
-
actionProps.icon = undefined;
|
|
138
|
-
}
|
|
139
|
-
|
|
140
|
-
if (Action) {
|
|
141
|
-
var handleOnClick = function handleOnClick() {
|
|
142
|
-
if (onActionItemClick) {
|
|
143
|
-
onActionItemClick();
|
|
144
|
-
}
|
|
145
|
-
|
|
146
|
-
if (onClick) {
|
|
147
|
-
onClick();
|
|
148
|
-
}
|
|
149
|
-
};
|
|
150
|
-
|
|
151
|
-
var action = /*#__PURE__*/React.createElement(Action, _extends({
|
|
152
|
-
url: '',
|
|
153
|
-
asDropDownItem: asDropDownItems,
|
|
154
|
-
size: size,
|
|
155
|
-
key: idx,
|
|
156
|
-
appearance: appearance,
|
|
157
|
-
onClick: handleOnClick
|
|
158
|
-
}, actionProps));
|
|
159
|
-
|
|
160
|
-
if (!isJSXElementNull(action)) {
|
|
161
|
-
return [].concat(_toConsumableArray(acc), [action]);
|
|
162
|
-
}
|
|
163
|
-
}
|
|
164
|
-
|
|
165
|
-
return acc;
|
|
166
|
-
}, []);
|
|
167
|
-
|
|
168
|
-
if (actions.length) {
|
|
169
|
-
return actions;
|
|
170
|
-
}
|
|
171
109
|
};
|