@atlaskit/smart-card 17.1.0 → 17.3.1
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 +28 -0
- package/dist/cjs/index.js +6 -0
- package/dist/cjs/version.json +1 -1
- package/dist/cjs/view/FlexibleCard/components/actions/{delete-action → action}/index.js +40 -25
- package/dist/cjs/view/FlexibleCard/components/actions/{types.js → action/types.js} +0 -0
- package/dist/cjs/view/FlexibleCard/components/actions/index.js +3 -1
- package/dist/cjs/view/FlexibleCard/components/actions/utils.js +34 -6
- package/dist/cjs/view/FlexibleCard/components/blocks/action-group/index.js +1 -1
- package/dist/cjs/view/FlexibleCard/components/blocks/element-group/index.js +7 -6
- package/dist/cjs/view/FlexibleCard/components/blocks/index.js +9 -1
- package/dist/cjs/view/FlexibleCard/components/blocks/metadata-block/index.js +116 -0
- package/dist/cjs/view/FlexibleCard/components/blocks/metadata-block/types.js +5 -0
- package/dist/cjs/view/FlexibleCard/components/blocks/title-block/errored/index.js +1 -1
- package/dist/cjs/view/FlexibleCard/components/blocks/utils.js +20 -10
- package/dist/cjs/view/FlexibleCard/components/elements/avatar-group/index.js +24 -2
- package/dist/cjs/view/FlexibleCard/components/elements/link/index.js +1 -1
- package/dist/cjs/view/FlexibleCard/components/elements/utils.js +49 -40
- package/dist/cjs/view/FlexibleCard/components/utils.js +1 -1
- package/dist/es2019/index.js +1 -1
- package/dist/es2019/version.json +1 -1
- package/dist/es2019/view/FlexibleCard/components/actions/{delete-action → action}/index.js +31 -15
- package/dist/es2019/view/FlexibleCard/components/actions/{types.js → action/types.js} +0 -0
- package/dist/es2019/view/FlexibleCard/components/actions/index.js +5 -3
- package/dist/es2019/view/FlexibleCard/components/actions/utils.js +27 -4
- package/dist/es2019/view/FlexibleCard/components/blocks/action-group/index.js +1 -1
- package/dist/es2019/view/FlexibleCard/components/blocks/element-group/index.js +12 -5
- package/dist/es2019/view/FlexibleCard/components/blocks/index.js +2 -1
- package/dist/es2019/view/FlexibleCard/components/blocks/metadata-block/index.js +97 -0
- package/dist/{esm/view/FlexibleCard/components/actions → es2019/view/FlexibleCard/components/blocks/metadata-block}/types.js +0 -0
- package/dist/es2019/view/FlexibleCard/components/blocks/title-block/errored/index.js +1 -0
- package/dist/es2019/view/FlexibleCard/components/blocks/utils.js +16 -9
- package/dist/es2019/view/FlexibleCard/components/elements/avatar-group/index.js +28 -2
- package/dist/es2019/view/FlexibleCard/components/elements/link/index.js +1 -0
- package/dist/es2019/view/FlexibleCard/components/elements/utils.js +49 -38
- package/dist/es2019/view/FlexibleCard/components/utils.js +0 -1
- package/dist/esm/index.js +1 -1
- package/dist/esm/version.json +1 -1
- package/dist/esm/view/FlexibleCard/components/actions/action/index.js +82 -0
- package/dist/esm/view/FlexibleCard/components/actions/action/types.js +1 -0
- package/dist/esm/view/FlexibleCard/components/actions/index.js +5 -3
- package/dist/esm/view/FlexibleCard/components/actions/utils.js +26 -4
- package/dist/esm/view/FlexibleCard/components/blocks/action-group/index.js +1 -1
- package/dist/esm/view/FlexibleCard/components/blocks/element-group/index.js +7 -6
- package/dist/esm/view/FlexibleCard/components/blocks/index.js +2 -1
- package/dist/esm/view/FlexibleCard/components/blocks/metadata-block/index.js +97 -0
- package/dist/esm/view/FlexibleCard/components/blocks/metadata-block/types.js +1 -0
- package/dist/esm/view/FlexibleCard/components/blocks/title-block/errored/index.js +1 -1
- package/dist/esm/view/FlexibleCard/components/blocks/utils.js +17 -10
- package/dist/esm/view/FlexibleCard/components/elements/avatar-group/index.js +24 -2
- package/dist/esm/view/FlexibleCard/components/elements/link/index.js +1 -1
- package/dist/esm/view/FlexibleCard/components/elements/utils.js +49 -40
- package/dist/esm/view/FlexibleCard/components/utils.js +1 -1
- package/dist/types/index.d.ts +1 -1
- package/dist/types/view/FlexibleCard/components/actions/action/index.d.ts +5 -0
- package/dist/types/view/FlexibleCard/components/actions/action/types.d.ts +18 -0
- package/dist/types/view/FlexibleCard/components/actions/index.d.ts +1 -1
- package/dist/types/view/FlexibleCard/components/actions/utils.d.ts +2 -1
- package/dist/types/view/FlexibleCard/components/blocks/element-group/types.d.ts +2 -0
- package/dist/types/view/FlexibleCard/components/blocks/index.d.ts +1 -0
- package/dist/types/view/FlexibleCard/components/blocks/metadata-block/index.d.ts +4 -0
- package/dist/types/view/FlexibleCard/components/blocks/metadata-block/types.d.ts +6 -0
- package/dist/types/view/FlexibleCard/components/blocks/utils.d.ts +1 -0
- package/dist/types/view/FlexibleCard/components/elements/avatar-group/index.d.ts +1 -0
- package/dist/types/view/FlexibleCard/components/elements/avatar-group/types.d.ts +1 -2
- package/package.json +1 -1
- package/dist/esm/view/FlexibleCard/components/actions/delete-action/index.js +0 -64
- package/dist/types/view/FlexibleCard/components/actions/delete-action/index.d.ts +0 -5
- package/dist/types/view/FlexibleCard/components/actions/types.d.ts +0 -10
|
@@ -84,17 +84,6 @@ var getContextKey = function getContextKey(name) {
|
|
|
84
84
|
return name.length > 0 ? name.charAt(0).toLowerCase() + name.slice(1) : undefined;
|
|
85
85
|
};
|
|
86
86
|
|
|
87
|
-
var getFormattedMessage = function getFormattedMessage(descriptor, value) {
|
|
88
|
-
return value ? {
|
|
89
|
-
message: {
|
|
90
|
-
descriptor: descriptor,
|
|
91
|
-
values: {
|
|
92
|
-
context: value
|
|
93
|
-
}
|
|
94
|
-
}
|
|
95
|
-
} : undefined;
|
|
96
|
-
};
|
|
97
|
-
|
|
98
87
|
var getData = function getData(elementName, contextKey, context) {
|
|
99
88
|
if (!context) {
|
|
100
89
|
return undefined;
|
|
@@ -103,52 +92,72 @@ var getData = function getData(elementName, contextKey, context) {
|
|
|
103
92
|
var data = context[contextKey];
|
|
104
93
|
|
|
105
94
|
switch (elementName) {
|
|
95
|
+
case _constants.ElementName.AuthorGroup:
|
|
96
|
+
case _constants.ElementName.CollaboratorGroup:
|
|
97
|
+
return toAvatarGroupProps(data);
|
|
98
|
+
|
|
106
99
|
case _constants.ElementName.CommentCount:
|
|
107
100
|
case _constants.ElementName.ProgrammingLanguage:
|
|
108
101
|
case _constants.ElementName.SubscriberCount:
|
|
109
|
-
return
|
|
110
|
-
label: data
|
|
111
|
-
};
|
|
112
|
-
|
|
113
|
-
case _constants.ElementName.AuthorGroup:
|
|
114
|
-
return {
|
|
115
|
-
items: context.authorGroup
|
|
116
|
-
};
|
|
117
|
-
|
|
118
|
-
case _constants.ElementName.CollaboratorGroup:
|
|
119
|
-
return {
|
|
120
|
-
items: context.collaboratorGroup
|
|
121
|
-
};
|
|
102
|
+
return toBadgeProps(data);
|
|
122
103
|
|
|
123
104
|
case _constants.ElementName.CreatedBy:
|
|
124
|
-
return
|
|
105
|
+
return toFormattedTextProps(_messages.messages.created_by, context.createdBy);
|
|
106
|
+
|
|
107
|
+
case _constants.ElementName.CreatedOn:
|
|
108
|
+
return toDateTimeProps('created', context.createdOn);
|
|
125
109
|
|
|
126
110
|
case _constants.ElementName.ModifiedBy:
|
|
127
|
-
return
|
|
111
|
+
return toFormattedTextProps(_messages.messages.modified_by, context.modifiedBy);
|
|
128
112
|
|
|
129
113
|
case _constants.ElementName.ModifiedOn:
|
|
130
|
-
return context.modifiedOn
|
|
131
|
-
date: new Date(context.modifiedOn),
|
|
132
|
-
type: 'modified'
|
|
133
|
-
} : undefined;
|
|
134
|
-
|
|
135
|
-
case _constants.ElementName.CreatedOn:
|
|
136
|
-
return context.createdOn ? {
|
|
137
|
-
date: new Date(context.createdOn),
|
|
138
|
-
type: 'created'
|
|
139
|
-
} : undefined;
|
|
114
|
+
return toDateTimeProps('modified', context.modifiedOn);
|
|
140
115
|
|
|
141
116
|
case _constants.ElementName.Title:
|
|
142
|
-
return
|
|
143
|
-
text: context.title,
|
|
144
|
-
url: context.url
|
|
145
|
-
};
|
|
117
|
+
return toLinkProps(context.title, context.url);
|
|
146
118
|
|
|
147
119
|
default:
|
|
148
120
|
return data;
|
|
149
121
|
}
|
|
150
122
|
};
|
|
151
123
|
|
|
124
|
+
var toAvatarGroupProps = function toAvatarGroupProps(items) {
|
|
125
|
+
return items ? {
|
|
126
|
+
items: items
|
|
127
|
+
} : undefined;
|
|
128
|
+
};
|
|
129
|
+
|
|
130
|
+
var toBadgeProps = function toBadgeProps(label) {
|
|
131
|
+
return label ? {
|
|
132
|
+
label: label
|
|
133
|
+
} : undefined;
|
|
134
|
+
};
|
|
135
|
+
|
|
136
|
+
var toDateTimeProps = function toDateTimeProps(type, dateString) {
|
|
137
|
+
return dateString ? {
|
|
138
|
+
date: new Date(dateString),
|
|
139
|
+
type: type
|
|
140
|
+
} : undefined;
|
|
141
|
+
};
|
|
142
|
+
|
|
143
|
+
var toFormattedTextProps = function toFormattedTextProps(descriptor, context) {
|
|
144
|
+
return context ? {
|
|
145
|
+
message: {
|
|
146
|
+
descriptor: descriptor,
|
|
147
|
+
values: {
|
|
148
|
+
context: context
|
|
149
|
+
}
|
|
150
|
+
}
|
|
151
|
+
} : undefined;
|
|
152
|
+
};
|
|
153
|
+
|
|
154
|
+
var toLinkProps = function toLinkProps(text, url) {
|
|
155
|
+
return text ? {
|
|
156
|
+
text: text,
|
|
157
|
+
url: url
|
|
158
|
+
} : undefined;
|
|
159
|
+
};
|
|
160
|
+
|
|
152
161
|
var createElement = function createElement(name) {
|
|
153
162
|
var _ref = elementMappings[name] || {},
|
|
154
163
|
BaseElement = _ref.component,
|
|
@@ -78,7 +78,7 @@ exports.getLinkSizeStyles = getLinkSizeStyles;
|
|
|
78
78
|
|
|
79
79
|
var getTruncateStyles = function getTruncateStyles(maxLines) {
|
|
80
80
|
var lineHeight = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '1rem';
|
|
81
|
-
return (0, _core.css)(_templateObject6 || (_templateObject6 = (0, _taggedTemplateLiteral2.default)(["\n display: -webkit-box;\n
|
|
81
|
+
return (0, _core.css)(_templateObject6 || (_templateObject6 = (0, _taggedTemplateLiteral2.default)(["\n display: -webkit-box;\n overflow: hidden;\n text-overflow: ellipsis;\n word-break: break-word;\n -webkit-line-clamp: ", ";\n -webkit-box-orient: vertical;\n // Fallback options\n max-height: calc(", " * ", ");\n "])), maxLines, maxLines, lineHeight);
|
|
82
82
|
};
|
|
83
83
|
|
|
84
84
|
exports.getTruncateStyles = getTruncateStyles;
|
package/dist/es2019/index.js
CHANGED
|
@@ -13,4 +13,4 @@ export { contentFooterClassName, metadataListClassName, blockCardResolvingViewCl
|
|
|
13
13
|
export { loadingPlaceholderClassName } from './view/CardWithUrl/component-lazy/LazyFallback'; // Flexible UI
|
|
14
14
|
|
|
15
15
|
export { ActionName, ElementName, SmartLinkDirection, SmartLinkPosition, SmartLinkSize, SmartLinkTheme } from './constants';
|
|
16
|
-
export { TitleBlock } from './view/FlexibleCard/components/blocks';
|
|
16
|
+
export { MetadataBlock, TitleBlock } from './view/FlexibleCard/components/blocks';
|
package/dist/es2019/version.json
CHANGED
|
@@ -1,13 +1,10 @@
|
|
|
1
1
|
/** @jsx jsx */
|
|
2
2
|
import React from 'react';
|
|
3
|
-
import { FormattedMessage } from 'react-intl-next';
|
|
4
3
|
import { css, jsx } from '@emotion/core';
|
|
5
4
|
import Button from '@atlaskit/button/custom-theme-button';
|
|
6
|
-
import CrossIcon from '@atlaskit/icon/glyph/cross';
|
|
7
5
|
import { SmartLinkSize } from '../../../../../constants';
|
|
8
6
|
import Tooltip from '@atlaskit/tooltip';
|
|
9
7
|
import { getIconSizeStyles } from '../../utils';
|
|
10
|
-
import { messages } from '../../../../../messages';
|
|
11
8
|
import { tokens } from '../../../../../utils/token';
|
|
12
9
|
import { handleOnClick } from '../../../../../utils';
|
|
13
10
|
|
|
@@ -24,35 +21,54 @@ const getWidth = size => {
|
|
|
24
21
|
}
|
|
25
22
|
};
|
|
26
23
|
|
|
27
|
-
const
|
|
24
|
+
const getIconStyles = size => css`
|
|
28
25
|
color: ${tokens.actionIcon};
|
|
29
26
|
${getIconSizeStyles(getWidth(size))};
|
|
30
27
|
`;
|
|
31
28
|
|
|
32
|
-
const
|
|
29
|
+
const ActionIcon = ({
|
|
30
|
+
size,
|
|
31
|
+
testId,
|
|
32
|
+
icon
|
|
33
|
+
}) => jsx("span", {
|
|
34
|
+
css: getIconStyles(size),
|
|
35
|
+
"data-testid": `${testId}-icon`
|
|
36
|
+
}, icon);
|
|
37
|
+
|
|
38
|
+
const Action = ({
|
|
33
39
|
appearance = 'subtle',
|
|
34
40
|
content,
|
|
35
41
|
onClick,
|
|
36
42
|
size = SmartLinkSize.Medium,
|
|
37
|
-
testId = 'smart-action
|
|
43
|
+
testId = 'smart-action',
|
|
44
|
+
icon,
|
|
45
|
+
iconPosition = 'before',
|
|
46
|
+
tooltipMessage
|
|
38
47
|
}) => {
|
|
39
48
|
if (!onClick) {
|
|
40
49
|
return null;
|
|
41
50
|
}
|
|
42
51
|
|
|
52
|
+
const iconBefore = iconPosition === 'before' ? jsx(ActionIcon, {
|
|
53
|
+
size: size,
|
|
54
|
+
testId: testId,
|
|
55
|
+
icon: icon
|
|
56
|
+
}) : undefined;
|
|
57
|
+
const iconAfter = iconPosition === 'after' ? jsx(ActionIcon, {
|
|
58
|
+
size: size,
|
|
59
|
+
testId: testId,
|
|
60
|
+
icon: icon
|
|
61
|
+
}) : undefined;
|
|
43
62
|
return jsx(Tooltip, {
|
|
44
|
-
content:
|
|
63
|
+
content: tooltipMessage
|
|
45
64
|
}, jsx(Button, {
|
|
46
65
|
spacing: "none",
|
|
47
66
|
appearance: appearance,
|
|
48
67
|
testId: testId,
|
|
49
|
-
onClick: handleOnClick(onClick)
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
}, jsx(CrossIcon, {
|
|
54
|
-
label: "Delete"
|
|
55
|
-
}))));
|
|
68
|
+
onClick: handleOnClick(onClick),
|
|
69
|
+
iconBefore: iconBefore,
|
|
70
|
+
iconAfter: iconAfter
|
|
71
|
+
}, content));
|
|
56
72
|
};
|
|
57
73
|
|
|
58
|
-
export default
|
|
74
|
+
export default Action;
|
|
File without changes
|
|
@@ -1,6 +1,8 @@
|
|
|
1
1
|
import { ActionName } from '../../../../constants';
|
|
2
|
-
import {
|
|
3
|
-
// Attention: Keep the export name and action name the same.
|
|
2
|
+
import { createUIAction } from './utils'; // Attention: Keep the export name and action name the same.
|
|
4
3
|
// This will help reducing the code for mapping action inside
|
|
5
4
|
// createAction and renderActionItems
|
|
6
|
-
|
|
5
|
+
// UIActions infer that you do not need to get any data from the context.
|
|
6
|
+
// DataActions infer that the action depends on the data from the context.
|
|
7
|
+
|
|
8
|
+
export const DeleteAction = createUIAction(ActionName.DeleteAction);
|
|
@@ -2,10 +2,20 @@ import _extends from "@babel/runtime/helpers/extends";
|
|
|
2
2
|
import { ActionName } from '../../../../constants';
|
|
3
3
|
import { FlexibleUiContext } from '../../../../state/flexible-ui-context';
|
|
4
4
|
import React, { useContext } from 'react';
|
|
5
|
-
import
|
|
5
|
+
import Action from './action';
|
|
6
|
+
import { FormattedMessage } from 'react-intl-next';
|
|
7
|
+
import { messages } from '../../../../messages';
|
|
8
|
+
import CrossIcon from '@atlaskit/icon/glyph/cross';
|
|
6
9
|
const actionMappings = {
|
|
7
10
|
[ActionName.DeleteAction]: {
|
|
8
|
-
component:
|
|
11
|
+
component: Action,
|
|
12
|
+
props: {
|
|
13
|
+
testId: 'smart-action-delete-action',
|
|
14
|
+
icon: /*#__PURE__*/React.createElement(CrossIcon, {
|
|
15
|
+
label: "Delete"
|
|
16
|
+
}),
|
|
17
|
+
toolTipMessage: /*#__PURE__*/React.createElement(FormattedMessage, messages.delete)
|
|
18
|
+
}
|
|
9
19
|
}
|
|
10
20
|
};
|
|
11
21
|
|
|
@@ -23,13 +33,12 @@ const getActionData = (actionName, contextKey, context) => {
|
|
|
23
33
|
const data = context[contextKey];
|
|
24
34
|
|
|
25
35
|
switch (actionName) {
|
|
26
|
-
case ActionName.DeleteAction:
|
|
27
36
|
default:
|
|
28
37
|
return data;
|
|
29
38
|
}
|
|
30
39
|
};
|
|
31
40
|
|
|
32
|
-
export const
|
|
41
|
+
export const createDataAction = name => {
|
|
33
42
|
const {
|
|
34
43
|
component: BaseAction,
|
|
35
44
|
props
|
|
@@ -45,4 +54,18 @@ export const createAction = name => {
|
|
|
45
54
|
const data = getActionData(name, contextKey, context);
|
|
46
55
|
return /*#__PURE__*/React.createElement(BaseAction, _extends({}, props, data, overrides));
|
|
47
56
|
};
|
|
57
|
+
};
|
|
58
|
+
export const createUIAction = name => {
|
|
59
|
+
const {
|
|
60
|
+
component: BaseAction,
|
|
61
|
+
props
|
|
62
|
+
} = actionMappings[name] || {};
|
|
63
|
+
|
|
64
|
+
if (!BaseAction) {
|
|
65
|
+
throw Error(`Action ${name} does not exist.`);
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
return overrides => {
|
|
69
|
+
return /*#__PURE__*/React.createElement(BaseAction, _extends({}, props, overrides));
|
|
70
|
+
};
|
|
48
71
|
};
|
|
@@ -4,20 +4,26 @@ import { css, jsx } from '@emotion/core';
|
|
|
4
4
|
import { SmartLinkAlignment, SmartLinkDirection, SmartLinkSize, SmartLinkWidth } from '../../../../../constants';
|
|
5
5
|
import { getBaseStyles, renderChildren } from '../utils';
|
|
6
6
|
|
|
7
|
-
const
|
|
7
|
+
const getAlignmentStyles = align => {
|
|
8
8
|
switch (align) {
|
|
9
9
|
case SmartLinkAlignment.Right:
|
|
10
|
-
return
|
|
10
|
+
return css`
|
|
11
|
+
justify-content: flex-end;
|
|
12
|
+
text-align: right;
|
|
13
|
+
`;
|
|
11
14
|
|
|
12
15
|
case SmartLinkAlignment.Left:
|
|
13
16
|
default:
|
|
14
|
-
return
|
|
17
|
+
return css`
|
|
18
|
+
justify-content: flex-start;
|
|
19
|
+
text-align: left;
|
|
20
|
+
`;
|
|
15
21
|
}
|
|
16
22
|
};
|
|
17
23
|
|
|
18
24
|
export const getElementGroupStyles = (direction, size, align, width) => css`
|
|
19
25
|
${getBaseStyles(direction, size)}
|
|
20
|
-
|
|
26
|
+
${getAlignmentStyles(align)}
|
|
21
27
|
min-width: 10%;
|
|
22
28
|
${width === SmartLinkWidth.Flexible ? `flex: 1 3;` : ''}
|
|
23
29
|
`;
|
|
@@ -25,12 +31,13 @@ export const getElementGroupStyles = (direction, size, align, width) => css`
|
|
|
25
31
|
const ElementGroup = ({
|
|
26
32
|
align = SmartLinkAlignment.Left,
|
|
27
33
|
children,
|
|
34
|
+
css,
|
|
28
35
|
direction = SmartLinkDirection.Horizontal,
|
|
29
36
|
size = SmartLinkSize.Medium,
|
|
30
37
|
testId = 'smart-element-group',
|
|
31
38
|
width = SmartLinkWidth.FitToContent
|
|
32
39
|
}) => jsx("div", {
|
|
33
|
-
css: getElementGroupStyles(direction, size, align, width),
|
|
40
|
+
css: [getElementGroupStyles(direction, size, align, width), css],
|
|
34
41
|
"data-smart-element-group": true,
|
|
35
42
|
"data-testid": testId
|
|
36
43
|
}, renderChildren(children, size));
|
|
@@ -1 +1,2 @@
|
|
|
1
|
-
export { default as TitleBlock } from './title-block';
|
|
1
|
+
export { default as TitleBlock } from './title-block';
|
|
2
|
+
export { default as MetadataBlock } from './metadata-block';
|
|
@@ -0,0 +1,97 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { css } from '@emotion/core';
|
|
4
|
+
import { SmartLinkAlignment, SmartLinkDirection, SmartLinkSize, SmartLinkStatus, SmartLinkWidth } from '../../../../../constants';
|
|
5
|
+
import { getGapSize, renderElementItems } from '../utils';
|
|
6
|
+
import Block from '../block';
|
|
7
|
+
import ElementGroup from '../element-group';
|
|
8
|
+
const DEFAULT_MAX_LINES = 2;
|
|
9
|
+
const MAXIMUM_MAX_LINES = 2;
|
|
10
|
+
const MINIMUM_MAX_LINES = 1;
|
|
11
|
+
|
|
12
|
+
const getElementGroupStyles = (size, maxLines) => {
|
|
13
|
+
// MetadataBlock allows metadata elements to be displayed in
|
|
14
|
+
// multiple lines, with maximum of 2 lines.
|
|
15
|
+
// a) We need the height of the line to be equal on both left and right
|
|
16
|
+
// sides so they line up nicely.
|
|
17
|
+
// b) There is no way to truncate non-text elements nicely. Here
|
|
18
|
+
// it's fix max height of the element group so that anything that is
|
|
19
|
+
// overflown will not be visible.
|
|
20
|
+
const lineHeight = getLineHeight(size);
|
|
21
|
+
const gap = getGapSize(size);
|
|
22
|
+
const gapHeight = gap * (maxLines - 1);
|
|
23
|
+
const height = lineHeight * maxLines + gapHeight;
|
|
24
|
+
return css`
|
|
25
|
+
flex-wrap: wrap;
|
|
26
|
+
line-height: ${lineHeight}rem;
|
|
27
|
+
max-height: ${height}rem;
|
|
28
|
+
> span,
|
|
29
|
+
> div {
|
|
30
|
+
min-height: ${lineHeight}rem;
|
|
31
|
+
max-height: ${lineHeight}rem;
|
|
32
|
+
line-height: ${lineHeight}rem;
|
|
33
|
+
}
|
|
34
|
+
`;
|
|
35
|
+
};
|
|
36
|
+
|
|
37
|
+
const getLineHeight = size => {
|
|
38
|
+
// The maximum height of all elements in specific size.
|
|
39
|
+
// These heights belongs to AvatarGroup.
|
|
40
|
+
switch (size) {
|
|
41
|
+
case SmartLinkSize.XLarge:
|
|
42
|
+
case SmartLinkSize.Large:
|
|
43
|
+
return 1.75;
|
|
44
|
+
|
|
45
|
+
case SmartLinkSize.Medium:
|
|
46
|
+
case SmartLinkSize.Small:
|
|
47
|
+
default:
|
|
48
|
+
return 1.5;
|
|
49
|
+
}
|
|
50
|
+
};
|
|
51
|
+
|
|
52
|
+
const getMaxLines = maxLines => {
|
|
53
|
+
if (maxLines > MAXIMUM_MAX_LINES) {
|
|
54
|
+
return DEFAULT_MAX_LINES;
|
|
55
|
+
}
|
|
56
|
+
|
|
57
|
+
if (maxLines < MINIMUM_MAX_LINES) {
|
|
58
|
+
return MINIMUM_MAX_LINES;
|
|
59
|
+
}
|
|
60
|
+
|
|
61
|
+
return maxLines;
|
|
62
|
+
};
|
|
63
|
+
|
|
64
|
+
const MetadataBlock = ({
|
|
65
|
+
maxLines = DEFAULT_MAX_LINES,
|
|
66
|
+
status = SmartLinkStatus.Fallback,
|
|
67
|
+
testId = 'smart-block-metadata',
|
|
68
|
+
primary = [],
|
|
69
|
+
secondary = [],
|
|
70
|
+
...blockProps
|
|
71
|
+
}) => {
|
|
72
|
+
if (primary.length === 0 && secondary.length === 0 || status !== SmartLinkStatus.Resolved) {
|
|
73
|
+
return null;
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
const primaryElements = renderElementItems(primary);
|
|
77
|
+
const secondaryElements = renderElementItems(secondary);
|
|
78
|
+
const {
|
|
79
|
+
size = SmartLinkSize.Medium
|
|
80
|
+
} = blockProps;
|
|
81
|
+
const elementGroupStyles = getElementGroupStyles(size, getMaxLines(maxLines));
|
|
82
|
+
return /*#__PURE__*/React.createElement(Block, _extends({}, blockProps, {
|
|
83
|
+
testId: `${testId}-resolved-view`
|
|
84
|
+
}), primaryElements && /*#__PURE__*/React.createElement(ElementGroup, {
|
|
85
|
+
align: SmartLinkAlignment.Left,
|
|
86
|
+
css: elementGroupStyles,
|
|
87
|
+
direction: SmartLinkDirection.Horizontal,
|
|
88
|
+
width: SmartLinkWidth.Flexible
|
|
89
|
+
}, primaryElements), secondaryElements && /*#__PURE__*/React.createElement(ElementGroup, {
|
|
90
|
+
align: SmartLinkAlignment.Right,
|
|
91
|
+
css: elementGroupStyles,
|
|
92
|
+
direction: SmartLinkDirection.Horizontal,
|
|
93
|
+
width: SmartLinkWidth.Flexible
|
|
94
|
+
}, secondaryElements));
|
|
95
|
+
};
|
|
96
|
+
|
|
97
|
+
export default MetadataBlock;
|
|
File without changes
|
|
@@ -25,26 +25,25 @@ const getDirectionStyles = direction => {
|
|
|
25
25
|
}
|
|
26
26
|
};
|
|
27
27
|
|
|
28
|
-
const getGapSize = size => {
|
|
28
|
+
export const getGapSize = size => {
|
|
29
29
|
switch (size) {
|
|
30
30
|
case SmartLinkSize.XLarge:
|
|
31
|
-
return
|
|
31
|
+
return 1.25;
|
|
32
32
|
|
|
33
33
|
case SmartLinkSize.Large:
|
|
34
|
-
return
|
|
34
|
+
return 1;
|
|
35
35
|
|
|
36
36
|
case SmartLinkSize.Medium:
|
|
37
|
-
return
|
|
37
|
+
return 0.5;
|
|
38
38
|
|
|
39
39
|
case SmartLinkSize.Small:
|
|
40
40
|
default:
|
|
41
|
-
return
|
|
41
|
+
return 0.25;
|
|
42
42
|
}
|
|
43
43
|
};
|
|
44
|
-
|
|
45
44
|
export const getBaseStyles = (direction, size) => css`
|
|
46
45
|
display: flex;
|
|
47
|
-
gap: ${getGapSize(size)};
|
|
46
|
+
gap: ${getGapSize(size)}rem;
|
|
48
47
|
line-height: 1rem;
|
|
49
48
|
min-width: 0;
|
|
50
49
|
overflow: hidden;
|
|
@@ -63,6 +62,10 @@ export const getBaseStyles = (direction, size) => css`
|
|
|
63
62
|
|
|
64
63
|
const isActionGroup = node => /*#__PURE__*/React.isValidElement(node) && node.type === ActionGroup;
|
|
65
64
|
|
|
65
|
+
const isElementNull = children => {
|
|
66
|
+
return Boolean(children.type() === null);
|
|
67
|
+
};
|
|
68
|
+
|
|
66
69
|
const isElementOrElementGroup = node => /*#__PURE__*/React.isValidElement(node) && (isFlexibleUiElement(node) || node.type === ElementGroup);
|
|
67
70
|
|
|
68
71
|
export const renderChildren = (children, size) => React.Children.map(children, child => {
|
|
@@ -87,9 +90,13 @@ export const renderElementItems = (items = []) => {
|
|
|
87
90
|
const Element = Elements[name];
|
|
88
91
|
|
|
89
92
|
if (Element) {
|
|
90
|
-
|
|
93
|
+
const element = /*#__PURE__*/React.createElement(Element, _extends({
|
|
91
94
|
key: idx
|
|
92
|
-
}, props))
|
|
95
|
+
}, props));
|
|
96
|
+
|
|
97
|
+
if (!isElementNull(element)) {
|
|
98
|
+
return [...acc, element];
|
|
99
|
+
}
|
|
93
100
|
}
|
|
94
101
|
|
|
95
102
|
return acc;
|
|
@@ -1,8 +1,32 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
1
2
|
import React from 'react';
|
|
3
|
+
import { css, jsx } from '@emotion/core';
|
|
2
4
|
import AtlaskitAvatarGroup from '@atlaskit/avatar-group';
|
|
3
5
|
import { SmartLinkSize } from '../../../../../constants';
|
|
4
6
|
const MAX_COUNT = 4;
|
|
5
7
|
|
|
8
|
+
const getStyles = size => {
|
|
9
|
+
switch (size) {
|
|
10
|
+
case SmartLinkSize.XLarge:
|
|
11
|
+
case SmartLinkSize.Large:
|
|
12
|
+
// Default AK small size
|
|
13
|
+
return;
|
|
14
|
+
|
|
15
|
+
case SmartLinkSize.Medium:
|
|
16
|
+
case SmartLinkSize.Small:
|
|
17
|
+
default:
|
|
18
|
+
return css`
|
|
19
|
+
li {
|
|
20
|
+
span,
|
|
21
|
+
svg {
|
|
22
|
+
max-height: 1.25rem;
|
|
23
|
+
max-width: 1.25rem;
|
|
24
|
+
}
|
|
25
|
+
}
|
|
26
|
+
`;
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
|
|
6
30
|
const AvatarGroup = ({
|
|
7
31
|
items = [],
|
|
8
32
|
maxCount = MAX_COUNT,
|
|
@@ -13,13 +37,15 @@ const AvatarGroup = ({
|
|
|
13
37
|
return null;
|
|
14
38
|
}
|
|
15
39
|
|
|
16
|
-
return
|
|
40
|
+
return jsx("span", {
|
|
41
|
+
css: getStyles(size)
|
|
42
|
+
}, jsx(AtlaskitAvatarGroup, {
|
|
17
43
|
maxCount: maxCount,
|
|
18
44
|
appearance: "stack",
|
|
19
45
|
size: "small",
|
|
20
46
|
data: items,
|
|
21
47
|
testId: testId
|
|
22
|
-
});
|
|
48
|
+
}));
|
|
23
49
|
};
|
|
24
50
|
|
|
25
51
|
export default AvatarGroup;
|
|
@@ -44,6 +44,7 @@ const getThemeStyles = theme => {
|
|
|
44
44
|
const getAnchorStyles = (size, theme, maxLines) => {
|
|
45
45
|
const sizeStyles = getLinkSizeStyles(size);
|
|
46
46
|
return css`
|
|
47
|
+
flex: 1 1 auto;
|
|
47
48
|
${sizeStyles}
|
|
48
49
|
${getTruncateStyles(maxLines, getLinkLineHeight(size))}
|
|
49
50
|
// Theme should be last to be spread because it contains override values
|