@atlaskit/smart-card 17.1.0 → 17.2.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.
Files changed (38) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/index.js +6 -0
  3. package/dist/cjs/version.json +1 -1
  4. package/dist/cjs/view/FlexibleCard/components/blocks/element-group/index.js +7 -6
  5. package/dist/cjs/view/FlexibleCard/components/blocks/index.js +9 -1
  6. package/dist/cjs/view/FlexibleCard/components/blocks/metadata-block/index.js +102 -0
  7. package/dist/cjs/view/FlexibleCard/components/blocks/metadata-block/types.js +5 -0
  8. package/dist/cjs/view/FlexibleCard/components/blocks/title-block/errored/index.js +1 -1
  9. package/dist/cjs/view/FlexibleCard/components/blocks/utils.js +8 -6
  10. package/dist/cjs/view/FlexibleCard/components/elements/link/index.js +1 -1
  11. package/dist/cjs/view/FlexibleCard/components/utils.js +1 -1
  12. package/dist/es2019/index.js +1 -1
  13. package/dist/es2019/version.json +1 -1
  14. package/dist/es2019/view/FlexibleCard/components/blocks/element-group/index.js +12 -5
  15. package/dist/es2019/view/FlexibleCard/components/blocks/index.js +2 -1
  16. package/dist/es2019/view/FlexibleCard/components/blocks/metadata-block/index.js +83 -0
  17. package/dist/es2019/view/FlexibleCard/components/blocks/metadata-block/types.js +1 -0
  18. package/dist/es2019/view/FlexibleCard/components/blocks/title-block/errored/index.js +1 -0
  19. package/dist/es2019/view/FlexibleCard/components/blocks/utils.js +6 -7
  20. package/dist/es2019/view/FlexibleCard/components/elements/link/index.js +1 -0
  21. package/dist/es2019/view/FlexibleCard/components/utils.js +0 -1
  22. package/dist/esm/index.js +1 -1
  23. package/dist/esm/version.json +1 -1
  24. package/dist/esm/view/FlexibleCard/components/blocks/element-group/index.js +7 -6
  25. package/dist/esm/view/FlexibleCard/components/blocks/index.js +2 -1
  26. package/dist/esm/view/FlexibleCard/components/blocks/metadata-block/index.js +83 -0
  27. package/dist/esm/view/FlexibleCard/components/blocks/metadata-block/types.js +1 -0
  28. package/dist/esm/view/FlexibleCard/components/blocks/title-block/errored/index.js +1 -1
  29. package/dist/esm/view/FlexibleCard/components/blocks/utils.js +6 -7
  30. package/dist/esm/view/FlexibleCard/components/elements/link/index.js +1 -1
  31. package/dist/esm/view/FlexibleCard/components/utils.js +1 -1
  32. package/dist/types/index.d.ts +1 -1
  33. package/dist/types/view/FlexibleCard/components/blocks/element-group/types.d.ts +2 -0
  34. package/dist/types/view/FlexibleCard/components/blocks/index.d.ts +1 -0
  35. package/dist/types/view/FlexibleCard/components/blocks/metadata-block/index.d.ts +4 -0
  36. package/dist/types/view/FlexibleCard/components/blocks/metadata-block/types.d.ts +6 -0
  37. package/dist/types/view/FlexibleCard/components/blocks/utils.d.ts +1 -0
  38. package/package.json +1 -1
package/CHANGELOG.md CHANGED
@@ -1,5 +1,11 @@
1
1
  # @atlaskit/smart-card
2
2
 
3
+ ## 17.2.0
4
+
5
+ ### Minor Changes
6
+
7
+ - [`3200ce3abc5`](https://bitbucket.org/atlassian/atlassian-frontend/commits/3200ce3abc5) - Flexible UI: Add MetadataBlock
8
+
3
9
  ## 17.1.0
4
10
 
5
11
  ### Minor Changes
package/dist/cjs/index.js CHANGED
@@ -53,6 +53,12 @@ Object.defineProperty(exports, "EmbedResizeMessageListener", {
53
53
  return _EmbedResizeMessageListener.EmbedResizeMessageListener;
54
54
  }
55
55
  });
56
+ Object.defineProperty(exports, "MetadataBlock", {
57
+ enumerable: true,
58
+ get: function get() {
59
+ return _blocks.MetadataBlock;
60
+ }
61
+ });
56
62
  Object.defineProperty(exports, "Provider", {
57
63
  enumerable: true,
58
64
  get: function get() {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "17.1.0",
3
+ "version": "17.2.0",
4
4
  "sideEffects": false
5
5
  }
@@ -17,21 +17,21 @@ var _constants = require("../../../../../constants");
17
17
 
18
18
  var _utils = require("../utils");
19
19
 
20
- var _templateObject;
20
+ var _templateObject, _templateObject2, _templateObject3;
21
21
 
22
- var getFlexJustifyContent = function getFlexJustifyContent(align) {
22
+ var getAlignmentStyles = function getAlignmentStyles(align) {
23
23
  switch (align) {
24
24
  case _constants.SmartLinkAlignment.Right:
25
- return 'flex-end';
25
+ return (0, _core.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n justify-content: flex-end;\n text-align: right;\n "])));
26
26
 
27
27
  case _constants.SmartLinkAlignment.Left:
28
28
  default:
29
- return 'flex-start';
29
+ return (0, _core.css)(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2.default)(["\n justify-content: flex-start;\n text-align: left;\n "])));
30
30
  }
31
31
  };
32
32
 
33
33
  var getElementGroupStyles = function getElementGroupStyles(direction, size, align, width) {
34
- return (0, _core.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n ", "\n justify-content: ", ";\n min-width: 10%;\n ", "\n"])), (0, _utils.getBaseStyles)(direction, size), getFlexJustifyContent(align), width === _constants.SmartLinkWidth.Flexible ? "flex: 1 3;" : '');
34
+ return (0, _core.css)(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2.default)(["\n ", "\n ", "\n min-width: 10%;\n ", "\n"])), (0, _utils.getBaseStyles)(direction, size), getAlignmentStyles(align), width === _constants.SmartLinkWidth.Flexible ? "flex: 1 3;" : '');
35
35
  };
36
36
 
37
37
  exports.getElementGroupStyles = getElementGroupStyles;
@@ -40,6 +40,7 @@ var ElementGroup = function ElementGroup(_ref) {
40
40
  var _ref$align = _ref.align,
41
41
  align = _ref$align === void 0 ? _constants.SmartLinkAlignment.Left : _ref$align,
42
42
  children = _ref.children,
43
+ css = _ref.css,
43
44
  _ref$direction = _ref.direction,
44
45
  direction = _ref$direction === void 0 ? _constants.SmartLinkDirection.Horizontal : _ref$direction,
45
46
  _ref$size = _ref.size,
@@ -49,7 +50,7 @@ var ElementGroup = function ElementGroup(_ref) {
49
50
  _ref$width = _ref.width,
50
51
  width = _ref$width === void 0 ? _constants.SmartLinkWidth.FitToContent : _ref$width;
51
52
  return (0, _core.jsx)("div", {
52
- css: getElementGroupStyles(direction, size, align, width),
53
+ css: [getElementGroupStyles(direction, size, align, width), css],
53
54
  "data-smart-element-group": true,
54
55
  "data-testid": testId
55
56
  }, (0, _utils.renderChildren)(children, size));
@@ -5,6 +5,12 @@ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefau
5
5
  Object.defineProperty(exports, "__esModule", {
6
6
  value: true
7
7
  });
8
+ Object.defineProperty(exports, "MetadataBlock", {
9
+ enumerable: true,
10
+ get: function get() {
11
+ return _metadataBlock.default;
12
+ }
13
+ });
8
14
  Object.defineProperty(exports, "TitleBlock", {
9
15
  enumerable: true,
10
16
  get: function get() {
@@ -12,4 +18,6 @@ Object.defineProperty(exports, "TitleBlock", {
12
18
  }
13
19
  });
14
20
 
15
- var _titleBlock = _interopRequireDefault(require("./title-block"));
21
+ var _titleBlock = _interopRequireDefault(require("./title-block"));
22
+
23
+ var _metadataBlock = _interopRequireDefault(require("./metadata-block"));
@@ -0,0 +1,102 @@
1
+ "use strict";
2
+
3
+ var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
4
+
5
+ Object.defineProperty(exports, "__esModule", {
6
+ value: true
7
+ });
8
+ exports.default = void 0;
9
+
10
+ var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
11
+
12
+ var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
13
+
14
+ var _taggedTemplateLiteral2 = _interopRequireDefault(require("@babel/runtime/helpers/taggedTemplateLiteral"));
15
+
16
+ var _react = _interopRequireDefault(require("react"));
17
+
18
+ var _core = require("@emotion/core");
19
+
20
+ var _constants = require("../../../../../constants");
21
+
22
+ var _utils = require("../utils");
23
+
24
+ var _block = _interopRequireDefault(require("../block"));
25
+
26
+ var _elementGroup = _interopRequireDefault(require("../element-group"));
27
+
28
+ var _excluded = ["maxLines", "status", "testId", "primary", "secondary"];
29
+
30
+ var _templateObject;
31
+
32
+ var DEFAULT_MAX_LINES = 2;
33
+ var MAXIMUM_MAX_LINES = 2;
34
+ var MINIMUM_MAX_LINES = 1;
35
+
36
+ var getElementGroupStyles = function getElementGroupStyles(size, maxLines) {
37
+ // MetadataBlock allows metadata elements to be displayed in
38
+ // multiple lines, with maximum of 2 lines.
39
+ // a) We need the height of the line to be equal on both left and right
40
+ // sides so they line up nicely. 1.75 is the The maximum height of
41
+ // all elements in specific size. This height belongs to AvatarGroup.
42
+ // b) There is no way to truncate non-text elements nicely. Here
43
+ // it's fix max height of the element group so that anything that is
44
+ // overflown will not be visible.
45
+ var lineHeight = 1.75;
46
+ var gap = (0, _utils.getGapSize)(size);
47
+ var gapHeight = gap * (maxLines - 1);
48
+ var height = lineHeight * maxLines + gapHeight;
49
+ return (0, _core.css)(_templateObject || (_templateObject = (0, _taggedTemplateLiteral2.default)(["\n flex-wrap: wrap;\n line-height: ", "rem;\n max-height: ", "rem;\n > span,\n > div {\n min-height: ", "rem;\n max-height: ", "rem;\n line-height: ", "rem;\n }\n "])), lineHeight, height, lineHeight, lineHeight, lineHeight);
50
+ };
51
+
52
+ var getMaxLines = function 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
+ var MetadataBlock = function MetadataBlock(_ref) {
65
+ var _ref$maxLines = _ref.maxLines,
66
+ maxLines = _ref$maxLines === void 0 ? DEFAULT_MAX_LINES : _ref$maxLines,
67
+ _ref$status = _ref.status,
68
+ status = _ref$status === void 0 ? _constants.SmartLinkStatus.Fallback : _ref$status,
69
+ _ref$testId = _ref.testId,
70
+ testId = _ref$testId === void 0 ? 'smart-block-metadata' : _ref$testId,
71
+ _ref$primary = _ref.primary,
72
+ primary = _ref$primary === void 0 ? [] : _ref$primary,
73
+ _ref$secondary = _ref.secondary,
74
+ secondary = _ref$secondary === void 0 ? [] : _ref$secondary,
75
+ blockProps = (0, _objectWithoutProperties2.default)(_ref, _excluded);
76
+
77
+ if (primary.length === 0 && secondary.length === 0 || status !== _constants.SmartLinkStatus.Resolved) {
78
+ return null;
79
+ }
80
+
81
+ var primaryElements = (0, _utils.renderElementItems)(primary);
82
+ var secondaryElements = (0, _utils.renderElementItems)(secondary);
83
+ var _blockProps$size = blockProps.size,
84
+ size = _blockProps$size === void 0 ? _constants.SmartLinkSize.Medium : _blockProps$size;
85
+ var elementGroupStyles = getElementGroupStyles(size, getMaxLines(maxLines));
86
+ return /*#__PURE__*/_react.default.createElement(_block.default, (0, _extends2.default)({}, blockProps, {
87
+ testId: "".concat(testId, "-resolved-view")
88
+ }), primaryElements && /*#__PURE__*/_react.default.createElement(_elementGroup.default, {
89
+ align: _constants.SmartLinkAlignment.Left,
90
+ css: elementGroupStyles,
91
+ direction: _constants.SmartLinkDirection.Horizontal,
92
+ width: _constants.SmartLinkWidth.Flexible
93
+ }, primaryElements), secondaryElements && /*#__PURE__*/_react.default.createElement(_elementGroup.default, {
94
+ align: _constants.SmartLinkAlignment.Right,
95
+ css: elementGroupStyles,
96
+ direction: _constants.SmartLinkDirection.Horizontal,
97
+ width: _constants.SmartLinkWidth.Flexible
98
+ }, secondaryElements));
99
+ };
100
+
101
+ var _default = MetadataBlock;
102
+ exports.default = _default;
@@ -0,0 +1,5 @@
1
+ "use strict";
2
+
3
+ Object.defineProperty(exports, "__esModule", {
4
+ value: true
5
+ });
@@ -39,7 +39,7 @@ var actionStyles = (0, _core.css)(_templateObject || (_templateObject = (0, _tag
39
39
 
40
40
  var getMessageStyles = function getMessageStyles(size, hasAction) {
41
41
  var sizeStyles = (0, _utils.getLinkSizeStyles)(size);
42
- return (0, _core.css)(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2.default)(["\n justify-content: flex-end;\n ", "\n ", "\n ", "\n color: ", ";\n "])), hasAction ? actionStyles : '', sizeStyles, (0, _utils.getTruncateStyles)(1, (0, _utils.getLinkLineHeight)(size)), _token.tokens.errorMessage);
42
+ return (0, _core.css)(_templateObject2 || (_templateObject2 = (0, _taggedTemplateLiteral2.default)(["\n flex: 1 1 auto;\n justify-content: flex-end;\n ", "\n ", "\n ", "\n color: ", ";\n "])), hasAction ? actionStyles : '', sizeStyles, (0, _utils.getTruncateStyles)(1, (0, _utils.getLinkLineHeight)(size)), _token.tokens.errorMessage);
43
43
  };
44
44
 
45
45
  var TitleBlockErroredView = function TitleBlockErroredView(_ref) {
@@ -7,7 +7,7 @@ var _typeof = require("@babel/runtime/helpers/typeof");
7
7
  Object.defineProperty(exports, "__esModule", {
8
8
  value: true
9
9
  });
10
- exports.renderElementItems = exports.renderChildren = exports.renderActionItems = exports.getBaseStyles = void 0;
10
+ exports.renderElementItems = exports.renderChildren = exports.renderActionItems = exports.getGapSize = exports.getBaseStyles = void 0;
11
11
 
12
12
  var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
13
13
 
@@ -56,22 +56,24 @@ var getDirectionStyles = function getDirectionStyles(direction) {
56
56
  var getGapSize = function getGapSize(size) {
57
57
  switch (size) {
58
58
  case _constants.SmartLinkSize.XLarge:
59
- return '1.25rem';
59
+ return 1.25;
60
60
 
61
61
  case _constants.SmartLinkSize.Large:
62
- return '1rem';
62
+ return 1;
63
63
 
64
64
  case _constants.SmartLinkSize.Medium:
65
- return '.5rem';
65
+ return 0.5;
66
66
 
67
67
  case _constants.SmartLinkSize.Small:
68
68
  default:
69
- return '.25rem';
69
+ return 0.25;
70
70
  }
71
71
  };
72
72
 
73
+ exports.getGapSize = getGapSize;
74
+
73
75
  var getBaseStyles = function getBaseStyles(direction, size) {
74
- return (0, _core.css)(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2.default)(["\n display: flex;\n gap: ", ";\n line-height: 1rem;\n min-width: 0;\n overflow: hidden;\n overflow-y: hidden;\n ", ";\n &:empty {\n display: none;\n }\n & > * {\n min-width: 0;\n }\n & > [data-fit-to-content] {\n min-width: fit-content;\n }\n"])), getGapSize(size), getDirectionStyles(direction));
76
+ return (0, _core.css)(_templateObject3 || (_templateObject3 = (0, _taggedTemplateLiteral2.default)(["\n display: flex;\n gap: ", "rem;\n line-height: 1rem;\n min-width: 0;\n overflow: hidden;\n overflow-y: hidden;\n ", ";\n &:empty {\n display: none;\n }\n & > * {\n min-width: 0;\n }\n & > [data-fit-to-content] {\n min-width: fit-content;\n }\n"])), getGapSize(size), getDirectionStyles(direction));
75
77
  };
76
78
 
77
79
  exports.getBaseStyles = getBaseStyles;
@@ -41,7 +41,7 @@ var getThemeStyles = function getThemeStyles(theme) {
41
41
 
42
42
  var getAnchorStyles = function getAnchorStyles(size, theme, maxLines) {
43
43
  var sizeStyles = (0, _utils.getLinkSizeStyles)(size);
44
- return (0, _core.css)(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2.default)(["\n ", "\n ", "\n // Theme should be last to be spread because it contains override values\n ", "\n "])), sizeStyles, (0, _utils.getTruncateStyles)(maxLines, (0, _utils.getLinkLineHeight)(size)), getThemeStyles(theme));
44
+ return (0, _core.css)(_templateObject4 || (_templateObject4 = (0, _taggedTemplateLiteral2.default)(["\n flex: 1 1 auto;\n ", "\n ", "\n // Theme should be last to be spread because it contains override values\n ", "\n "])), sizeStyles, (0, _utils.getTruncateStyles)(maxLines, (0, _utils.getLinkLineHeight)(size)), getThemeStyles(theme));
45
45
  };
46
46
 
47
47
  var getMaxLines = function getMaxLines(maxLines) {
@@ -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 flex: 1 1 auto;\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);
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;
@@ -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';
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "17.1.0",
3
+ "version": "17.2.0",
4
4
  "sideEffects": false
5
5
  }
@@ -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 getFlexJustifyContent = align => {
7
+ const getAlignmentStyles = align => {
8
8
  switch (align) {
9
9
  case SmartLinkAlignment.Right:
10
- return 'flex-end';
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 'flex-start';
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
- justify-content: ${getFlexJustifyContent(align)};
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,83 @@
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. 1.75 is the The maximum height of
17
+ // all elements in specific size. This height belongs to AvatarGroup.
18
+ // b) There is no way to truncate non-text elements nicely. Here
19
+ // it's fix max height of the element group so that anything that is
20
+ // overflown will not be visible.
21
+ const lineHeight = 1.75;
22
+ const gap = getGapSize(size);
23
+ const gapHeight = gap * (maxLines - 1);
24
+ const height = lineHeight * maxLines + gapHeight;
25
+ return css`
26
+ flex-wrap: wrap;
27
+ line-height: ${lineHeight}rem;
28
+ max-height: ${height}rem;
29
+ > span,
30
+ > div {
31
+ min-height: ${lineHeight}rem;
32
+ max-height: ${lineHeight}rem;
33
+ line-height: ${lineHeight}rem;
34
+ }
35
+ `;
36
+ };
37
+
38
+ const getMaxLines = maxLines => {
39
+ if (maxLines > MAXIMUM_MAX_LINES) {
40
+ return DEFAULT_MAX_LINES;
41
+ }
42
+
43
+ if (maxLines < MINIMUM_MAX_LINES) {
44
+ return MINIMUM_MAX_LINES;
45
+ }
46
+
47
+ return maxLines;
48
+ };
49
+
50
+ const MetadataBlock = ({
51
+ maxLines = DEFAULT_MAX_LINES,
52
+ status = SmartLinkStatus.Fallback,
53
+ testId = 'smart-block-metadata',
54
+ primary = [],
55
+ secondary = [],
56
+ ...blockProps
57
+ }) => {
58
+ if (primary.length === 0 && secondary.length === 0 || status !== SmartLinkStatus.Resolved) {
59
+ return null;
60
+ }
61
+
62
+ const primaryElements = renderElementItems(primary);
63
+ const secondaryElements = renderElementItems(secondary);
64
+ const {
65
+ size = SmartLinkSize.Medium
66
+ } = blockProps;
67
+ const elementGroupStyles = getElementGroupStyles(size, getMaxLines(maxLines));
68
+ return /*#__PURE__*/React.createElement(Block, _extends({}, blockProps, {
69
+ testId: `${testId}-resolved-view`
70
+ }), primaryElements && /*#__PURE__*/React.createElement(ElementGroup, {
71
+ align: SmartLinkAlignment.Left,
72
+ css: elementGroupStyles,
73
+ direction: SmartLinkDirection.Horizontal,
74
+ width: SmartLinkWidth.Flexible
75
+ }, primaryElements), secondaryElements && /*#__PURE__*/React.createElement(ElementGroup, {
76
+ align: SmartLinkAlignment.Right,
77
+ css: elementGroupStyles,
78
+ direction: SmartLinkDirection.Horizontal,
79
+ width: SmartLinkWidth.Flexible
80
+ }, secondaryElements));
81
+ };
82
+
83
+ export default MetadataBlock;
@@ -21,6 +21,7 @@ const actionStyles = css`
21
21
  const getMessageStyles = (size, hasAction) => {
22
22
  const sizeStyles = getLinkSizeStyles(size);
23
23
  return css`
24
+ flex: 1 1 auto;
24
25
  justify-content: flex-end;
25
26
  ${hasAction ? actionStyles : ''}
26
27
  ${sizeStyles}
@@ -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 '1.25rem';
31
+ return 1.25;
32
32
 
33
33
  case SmartLinkSize.Large:
34
- return '1rem';
34
+ return 1;
35
35
 
36
36
  case SmartLinkSize.Medium:
37
- return '.5rem';
37
+ return 0.5;
38
38
 
39
39
  case SmartLinkSize.Small:
40
40
  default:
41
- return '.25rem';
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;
@@ -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
@@ -82,7 +82,6 @@ export const getLinkSizeStyles = size => {
82
82
  };
83
83
  export const getTruncateStyles = (maxLines, lineHeight = '1rem') => css`
84
84
  display: -webkit-box;
85
- flex: 1 1 auto;
86
85
  overflow: hidden;
87
86
  text-overflow: ellipsis;
88
87
  word-break: break-word;
package/dist/esm/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';
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "17.1.0",
3
+ "version": "17.2.0",
4
4
  "sideEffects": false
5
5
  }
@@ -1,6 +1,6 @@
1
1
  import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
2
2
 
3
- var _templateObject;
3
+ var _templateObject, _templateObject2, _templateObject3;
4
4
 
5
5
  /** @jsx jsx */
6
6
  import React from 'react';
@@ -8,25 +8,26 @@ import { css, jsx } from '@emotion/core';
8
8
  import { SmartLinkAlignment, SmartLinkDirection, SmartLinkSize, SmartLinkWidth } from '../../../../../constants';
9
9
  import { getBaseStyles, renderChildren } from '../utils';
10
10
 
11
- var getFlexJustifyContent = function getFlexJustifyContent(align) {
11
+ var getAlignmentStyles = function getAlignmentStyles(align) {
12
12
  switch (align) {
13
13
  case SmartLinkAlignment.Right:
14
- return 'flex-end';
14
+ return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n justify-content: flex-end;\n text-align: right;\n "])));
15
15
 
16
16
  case SmartLinkAlignment.Left:
17
17
  default:
18
- return 'flex-start';
18
+ return css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n justify-content: flex-start;\n text-align: left;\n "])));
19
19
  }
20
20
  };
21
21
 
22
22
  export var getElementGroupStyles = function getElementGroupStyles(direction, size, align, width) {
23
- return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n ", "\n justify-content: ", ";\n min-width: 10%;\n ", "\n"])), getBaseStyles(direction, size), getFlexJustifyContent(align), width === SmartLinkWidth.Flexible ? "flex: 1 3;" : '');
23
+ return css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n ", "\n ", "\n min-width: 10%;\n ", "\n"])), getBaseStyles(direction, size), getAlignmentStyles(align), width === SmartLinkWidth.Flexible ? "flex: 1 3;" : '');
24
24
  };
25
25
 
26
26
  var ElementGroup = function ElementGroup(_ref) {
27
27
  var _ref$align = _ref.align,
28
28
  align = _ref$align === void 0 ? SmartLinkAlignment.Left : _ref$align,
29
29
  children = _ref.children,
30
+ css = _ref.css,
30
31
  _ref$direction = _ref.direction,
31
32
  direction = _ref$direction === void 0 ? SmartLinkDirection.Horizontal : _ref$direction,
32
33
  _ref$size = _ref.size,
@@ -36,7 +37,7 @@ var ElementGroup = function ElementGroup(_ref) {
36
37
  _ref$width = _ref.width,
37
38
  width = _ref$width === void 0 ? SmartLinkWidth.FitToContent : _ref$width;
38
39
  return jsx("div", {
39
- css: getElementGroupStyles(direction, size, align, width),
40
+ css: [getElementGroupStyles(direction, size, align, width), css],
40
41
  "data-smart-element-group": true,
41
42
  "data-testid": testId
42
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,83 @@
1
+ import _extends from "@babel/runtime/helpers/extends";
2
+ import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
3
+ import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
4
+ var _excluded = ["maxLines", "status", "testId", "primary", "secondary"];
5
+
6
+ var _templateObject;
7
+
8
+ import React from 'react';
9
+ import { css } from '@emotion/core';
10
+ import { SmartLinkAlignment, SmartLinkDirection, SmartLinkSize, SmartLinkStatus, SmartLinkWidth } from '../../../../../constants';
11
+ import { getGapSize, renderElementItems } from '../utils';
12
+ import Block from '../block';
13
+ import ElementGroup from '../element-group';
14
+ var DEFAULT_MAX_LINES = 2;
15
+ var MAXIMUM_MAX_LINES = 2;
16
+ var MINIMUM_MAX_LINES = 1;
17
+
18
+ var getElementGroupStyles = function getElementGroupStyles(size, maxLines) {
19
+ // MetadataBlock allows metadata elements to be displayed in
20
+ // multiple lines, with maximum of 2 lines.
21
+ // a) We need the height of the line to be equal on both left and right
22
+ // sides so they line up nicely. 1.75 is the The maximum height of
23
+ // all elements in specific size. This height belongs to AvatarGroup.
24
+ // b) There is no way to truncate non-text elements nicely. Here
25
+ // it's fix max height of the element group so that anything that is
26
+ // overflown will not be visible.
27
+ var lineHeight = 1.75;
28
+ var gap = getGapSize(size);
29
+ var gapHeight = gap * (maxLines - 1);
30
+ var height = lineHeight * maxLines + gapHeight;
31
+ return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n flex-wrap: wrap;\n line-height: ", "rem;\n max-height: ", "rem;\n > span,\n > div {\n min-height: ", "rem;\n max-height: ", "rem;\n line-height: ", "rem;\n }\n "])), lineHeight, height, lineHeight, lineHeight, lineHeight);
32
+ };
33
+
34
+ var getMaxLines = function getMaxLines(maxLines) {
35
+ if (maxLines > MAXIMUM_MAX_LINES) {
36
+ return DEFAULT_MAX_LINES;
37
+ }
38
+
39
+ if (maxLines < MINIMUM_MAX_LINES) {
40
+ return MINIMUM_MAX_LINES;
41
+ }
42
+
43
+ return maxLines;
44
+ };
45
+
46
+ var MetadataBlock = function MetadataBlock(_ref) {
47
+ var _ref$maxLines = _ref.maxLines,
48
+ maxLines = _ref$maxLines === void 0 ? DEFAULT_MAX_LINES : _ref$maxLines,
49
+ _ref$status = _ref.status,
50
+ status = _ref$status === void 0 ? SmartLinkStatus.Fallback : _ref$status,
51
+ _ref$testId = _ref.testId,
52
+ testId = _ref$testId === void 0 ? 'smart-block-metadata' : _ref$testId,
53
+ _ref$primary = _ref.primary,
54
+ primary = _ref$primary === void 0 ? [] : _ref$primary,
55
+ _ref$secondary = _ref.secondary,
56
+ secondary = _ref$secondary === void 0 ? [] : _ref$secondary,
57
+ blockProps = _objectWithoutProperties(_ref, _excluded);
58
+
59
+ if (primary.length === 0 && secondary.length === 0 || status !== SmartLinkStatus.Resolved) {
60
+ return null;
61
+ }
62
+
63
+ var primaryElements = renderElementItems(primary);
64
+ var secondaryElements = renderElementItems(secondary);
65
+ var _blockProps$size = blockProps.size,
66
+ size = _blockProps$size === void 0 ? SmartLinkSize.Medium : _blockProps$size;
67
+ var elementGroupStyles = getElementGroupStyles(size, getMaxLines(maxLines));
68
+ return /*#__PURE__*/React.createElement(Block, _extends({}, blockProps, {
69
+ testId: "".concat(testId, "-resolved-view")
70
+ }), primaryElements && /*#__PURE__*/React.createElement(ElementGroup, {
71
+ align: SmartLinkAlignment.Left,
72
+ css: elementGroupStyles,
73
+ direction: SmartLinkDirection.Horizontal,
74
+ width: SmartLinkWidth.Flexible
75
+ }, primaryElements), secondaryElements && /*#__PURE__*/React.createElement(ElementGroup, {
76
+ align: SmartLinkAlignment.Right,
77
+ css: elementGroupStyles,
78
+ direction: SmartLinkDirection.Horizontal,
79
+ width: SmartLinkWidth.Flexible
80
+ }, secondaryElements));
81
+ };
82
+
83
+ export default MetadataBlock;
@@ -19,7 +19,7 @@ var actionStyles = css(_templateObject || (_templateObject = _taggedTemplateLite
19
19
 
20
20
  var getMessageStyles = function getMessageStyles(size, hasAction) {
21
21
  var sizeStyles = getLinkSizeStyles(size);
22
- return css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n justify-content: flex-end;\n ", "\n ", "\n ", "\n color: ", ";\n "])), hasAction ? actionStyles : '', sizeStyles, getTruncateStyles(1, getLinkLineHeight(size)), tokens.errorMessage);
22
+ return css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n flex: 1 1 auto;\n justify-content: flex-end;\n ", "\n ", "\n ", "\n color: ", ";\n "])), hasAction ? actionStyles : '', sizeStyles, getTruncateStyles(1, getLinkLineHeight(size)), tokens.errorMessage);
23
23
  };
24
24
 
25
25
  var TitleBlockErroredView = function TitleBlockErroredView(_ref) {
@@ -27,25 +27,24 @@ var getDirectionStyles = function getDirectionStyles(direction) {
27
27
  }
28
28
  };
29
29
 
30
- var getGapSize = function getGapSize(size) {
30
+ export var getGapSize = function getGapSize(size) {
31
31
  switch (size) {
32
32
  case SmartLinkSize.XLarge:
33
- return '1.25rem';
33
+ return 1.25;
34
34
 
35
35
  case SmartLinkSize.Large:
36
- return '1rem';
36
+ return 1;
37
37
 
38
38
  case SmartLinkSize.Medium:
39
- return '.5rem';
39
+ return 0.5;
40
40
 
41
41
  case SmartLinkSize.Small:
42
42
  default:
43
- return '.25rem';
43
+ return 0.25;
44
44
  }
45
45
  };
46
-
47
46
  export var getBaseStyles = function getBaseStyles(direction, size) {
48
- return css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n display: flex;\n gap: ", ";\n line-height: 1rem;\n min-width: 0;\n overflow: hidden;\n overflow-y: hidden;\n ", ";\n &:empty {\n display: none;\n }\n & > * {\n min-width: 0;\n }\n & > [data-fit-to-content] {\n min-width: fit-content;\n }\n"])), getGapSize(size), getDirectionStyles(direction));
47
+ return css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n display: flex;\n gap: ", "rem;\n line-height: 1rem;\n min-width: 0;\n overflow: hidden;\n overflow-y: hidden;\n ", ";\n &:empty {\n display: none;\n }\n & > * {\n min-width: 0;\n }\n & > [data-fit-to-content] {\n min-width: fit-content;\n }\n"])), getGapSize(size), getDirectionStyles(direction));
49
48
  };
50
49
 
51
50
  var isActionGroup = function isActionGroup(node) {
@@ -27,7 +27,7 @@ var getThemeStyles = function getThemeStyles(theme) {
27
27
 
28
28
  var getAnchorStyles = function getAnchorStyles(size, theme, maxLines) {
29
29
  var sizeStyles = getLinkSizeStyles(size);
30
- return css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n ", "\n ", "\n // Theme should be last to be spread because it contains override values\n ", "\n "])), sizeStyles, getTruncateStyles(maxLines, getLinkLineHeight(size)), getThemeStyles(theme));
30
+ return css(_templateObject4 || (_templateObject4 = _taggedTemplateLiteral(["\n flex: 1 1 auto;\n ", "\n ", "\n // Theme should be last to be spread because it contains override values\n ", "\n "])), sizeStyles, getTruncateStyles(maxLines, getLinkLineHeight(size)), getThemeStyles(theme));
31
31
  };
32
32
 
33
33
  var getMaxLines = function getMaxLines(maxLines) {
@@ -53,5 +53,5 @@ export var getLinkSizeStyles = function getLinkSizeStyles(size) {
53
53
  };
54
54
  export var getTruncateStyles = function getTruncateStyles(maxLines) {
55
55
  var lineHeight = arguments.length > 1 && arguments[1] !== undefined ? arguments[1] : '1rem';
56
- return css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\n display: -webkit-box;\n flex: 1 1 auto;\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);
56
+ return css(_templateObject6 || (_templateObject6 = _taggedTemplateLiteral(["\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);
57
57
  };
@@ -17,5 +17,5 @@ export { useSmartLinkEvents } from './view/SmartLinkEvents/useSmartLinkEvents';
17
17
  export { contentFooterClassName, metadataListClassName, blockCardResolvingViewClassName, blockCardResolvedViewClassName, blockCardForbiddenViewClassName, blockCardIconImageClassName, blockCardResolvedViewByClassName, blockCardForbiddenViewLinkClassName, blockCardContentClassName, blockCardContentHeaderClassName, blockCardContentHeaderNameClassName, blockCardNotFoundViewClassName, blockCardErroredViewClassName, } from './classNames';
18
18
  export { loadingPlaceholderClassName } from './view/CardWithUrl/component-lazy/LazyFallback';
19
19
  export { ActionName, ElementName, SmartLinkDirection, SmartLinkPosition, SmartLinkSize, SmartLinkTheme, } from './constants';
20
- export { TitleBlock } from './view/FlexibleCard/components/blocks';
20
+ export { MetadataBlock, TitleBlock, } from './view/FlexibleCard/components/blocks';
21
21
  export type { ActionItem, ElementItem, } from './view/FlexibleCard/components/blocks/types';
@@ -1,6 +1,8 @@
1
+ import { Interpolation } from '@emotion/core';
1
2
  import { SmartLinkAlignment, SmartLinkDirection, SmartLinkSize, SmartLinkWidth } from '../../../../../constants';
2
3
  export declare type ElementGroupProps = {
3
4
  align?: SmartLinkAlignment;
5
+ css?: Interpolation;
4
6
  direction?: SmartLinkDirection;
5
7
  size?: SmartLinkSize;
6
8
  testId?: string;
@@ -1 +1,2 @@
1
1
  export { default as TitleBlock } from './title-block';
2
+ export { default as MetadataBlock } from './metadata-block';
@@ -0,0 +1,4 @@
1
+ import React from 'react';
2
+ import { MetadataBlockProps } from './types';
3
+ declare const MetadataBlock: React.FC<MetadataBlockProps>;
4
+ export default MetadataBlock;
@@ -0,0 +1,6 @@
1
+ import { BlockProps, ElementItem } from '../types';
2
+ export declare type MetadataBlockProps = BlockProps & {
3
+ maxLines?: number;
4
+ primary?: ElementItem[];
5
+ secondary?: ElementItem[];
6
+ };
@@ -2,6 +2,7 @@ import React from 'react';
2
2
  import { SerializedStyles } from '@emotion/core';
3
3
  import { ActionItem, ElementItem } from './types';
4
4
  import { SmartLinkDirection, SmartLinkSize } from '../../../../constants';
5
+ export declare const getGapSize: (size: SmartLinkSize) => number;
5
6
  export declare const getBaseStyles: (direction: SmartLinkDirection, size: SmartLinkSize) => SerializedStyles;
6
7
  export declare const renderChildren: (children: React.ReactNode, size: SmartLinkSize) => React.ReactNode;
7
8
  export declare const renderElementItems: (items?: ElementItem[]) => React.ReactNode | undefined;
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "17.1.0",
3
+ "version": "17.2.0",
4
4
  "description": "Smart card component",
5
5
  "publishConfig": {
6
6
  "registry": "https://registry.npmjs.org/"