@atlaskit/smart-card 21.0.2 → 21.0.3

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (46) hide show
  1. package/CHANGELOG.md +6 -0
  2. package/dist/cjs/version.json +1 -1
  3. package/dist/cjs/view/FlexibleCard/components/actions/action/action-button/index.js +87 -0
  4. package/dist/cjs/view/FlexibleCard/components/actions/action/action-button/types.js +5 -0
  5. package/dist/cjs/view/FlexibleCard/components/actions/action/action-dropdown-item/index.js +31 -0
  6. package/dist/cjs/view/FlexibleCard/components/actions/action/action-dropdown-item/types.js +5 -0
  7. package/dist/cjs/view/FlexibleCard/components/actions/action/action-icon/index.js +52 -0
  8. package/dist/cjs/view/FlexibleCard/components/actions/action/action-icon/types.js +5 -0
  9. package/dist/cjs/view/FlexibleCard/components/actions/action/index.js +42 -104
  10. package/dist/cjs/view/FlexibleCard/components/blocks/action-group/index.js +44 -15
  11. package/dist/cjs/view/FlexibleCard/components/blocks/utils.js +12 -1
  12. package/dist/cjs/view/FlexibleCard/components/utils.js +7 -2
  13. package/dist/es2019/version.json +1 -1
  14. package/dist/es2019/view/FlexibleCard/components/actions/action/action-button/index.js +88 -0
  15. package/dist/es2019/view/FlexibleCard/components/actions/action/action-button/types.js +1 -0
  16. package/dist/es2019/view/FlexibleCard/components/actions/action/action-dropdown-item/index.js +18 -0
  17. package/dist/es2019/view/FlexibleCard/components/actions/action/action-dropdown-item/types.js +1 -0
  18. package/dist/es2019/view/FlexibleCard/components/actions/action/action-icon/index.js +35 -0
  19. package/dist/es2019/view/FlexibleCard/components/actions/action/action-icon/types.js +1 -0
  20. package/dist/es2019/view/FlexibleCard/components/actions/action/index.js +26 -110
  21. package/dist/es2019/view/FlexibleCard/components/blocks/action-group/index.js +31 -12
  22. package/dist/es2019/view/FlexibleCard/components/blocks/utils.js +12 -2
  23. package/dist/es2019/view/FlexibleCard/components/utils.js +6 -0
  24. package/dist/esm/version.json +1 -1
  25. package/dist/esm/view/FlexibleCard/components/actions/action/action-button/index.js +67 -0
  26. package/dist/esm/view/FlexibleCard/components/actions/action/action-button/types.js +1 -0
  27. package/dist/esm/view/FlexibleCard/components/actions/action/action-dropdown-item/index.js +19 -0
  28. package/dist/esm/view/FlexibleCard/components/actions/action/action-dropdown-item/types.js +1 -0
  29. package/dist/esm/view/FlexibleCard/components/actions/action/action-icon/index.js +39 -0
  30. package/dist/esm/view/FlexibleCard/components/actions/action/action-icon/types.js +1 -0
  31. package/dist/esm/view/FlexibleCard/components/actions/action/index.js +41 -99
  32. package/dist/esm/view/FlexibleCard/components/blocks/action-group/index.js +44 -16
  33. package/dist/esm/view/FlexibleCard/components/blocks/utils.js +12 -1
  34. package/dist/esm/view/FlexibleCard/components/utils.js +3 -1
  35. package/dist/types/view/FlexibleCard/components/actions/action/action-button/index.d.ts +5 -0
  36. package/dist/types/view/FlexibleCard/components/actions/action/action-button/types.d.ts +8 -0
  37. package/dist/types/view/FlexibleCard/components/actions/action/action-dropdown-item/index.d.ts +4 -0
  38. package/dist/types/view/FlexibleCard/components/actions/action/action-dropdown-item/types.d.ts +8 -0
  39. package/dist/types/view/FlexibleCard/components/actions/action/action-icon/index.d.ts +5 -0
  40. package/dist/types/view/FlexibleCard/components/actions/action/action-icon/types.d.ts +7 -0
  41. package/dist/types/view/FlexibleCard/components/actions/action/index.d.ts +0 -3
  42. package/dist/types/view/FlexibleCard/components/actions/action/types.d.ts +0 -16
  43. package/dist/types/view/FlexibleCard/components/blocks/utils.d.ts +1 -1
  44. package/dist/types/view/FlexibleCard/components/utils.d.ts +2 -0
  45. package/package.json +8 -5
  46. package/report.api.md +32 -2
@@ -0,0 +1,18 @@
1
+ import React from 'react';
2
+ import { DropdownItem } from '@atlaskit/dropdown-menu';
3
+ import { handleOnClick } from '../../../../../../utils';
4
+
5
+ const ActionDropdownItem = ({
6
+ content,
7
+ iconAfter,
8
+ iconBefore,
9
+ onClick,
10
+ testId
11
+ }) => /*#__PURE__*/React.createElement(DropdownItem, {
12
+ elemAfter: iconAfter,
13
+ elemBefore: iconBefore,
14
+ onClick: handleOnClick(onClick),
15
+ testId: testId
16
+ }, content);
17
+
18
+ export default ActionDropdownItem;
@@ -0,0 +1,35 @@
1
+ /** @jsx jsx */
2
+ import React from 'react';
3
+ import { css, jsx } from '@emotion/core';
4
+ import { SmartLinkSize } from '../../../../../../constants';
5
+ import { tokens } from '../../../../../../utils/token';
6
+ import { getIconSizeStyles } from '../../../utils';
7
+
8
+ const getIconWidth = size => {
9
+ switch (size) {
10
+ case SmartLinkSize.XLarge:
11
+ case SmartLinkSize.Large:
12
+ return '1.5rem';
13
+
14
+ case SmartLinkSize.Medium:
15
+ case SmartLinkSize.Small:
16
+ default:
17
+ return '1rem';
18
+ }
19
+ };
20
+
21
+ const getIconStyles = size => css`
22
+ color: ${tokens.actionIcon};
23
+ ${getIconSizeStyles(getIconWidth(size))};
24
+ `;
25
+
26
+ const ActionIcon = ({
27
+ size,
28
+ testId,
29
+ icon
30
+ }) => jsx("span", {
31
+ css: getIconStyles(size),
32
+ "data-testid": `${testId}-icon`
33
+ }, icon);
34
+
35
+ export default ActionIcon;
@@ -1,88 +1,10 @@
1
1
  /** @jsx jsx */
2
2
  import React from 'react';
3
- import { css, jsx } from '@emotion/core';
4
- import Button from '@atlaskit/button/custom-theme-button';
3
+ import { jsx } from '@emotion/core';
5
4
  import { SmartLinkSize } from '../../../../../constants';
6
- import Tooltip from '@atlaskit/tooltip';
7
- import { DropdownItem } from '@atlaskit/dropdown-menu';
8
- import { getIconSizeStyles } from '../../utils';
9
- import { tokens } from '../../../../../utils/token';
10
- import { handleOnClick } from '../../../../../utils';
11
-
12
- const getIconWidth = size => {
13
- switch (size) {
14
- case SmartLinkSize.XLarge:
15
- case SmartLinkSize.Large:
16
- return '1.5rem';
17
-
18
- case SmartLinkSize.Medium:
19
- case SmartLinkSize.Small:
20
- default:
21
- return '1rem';
22
- }
23
- };
24
-
25
- const getIconStyles = size => css`
26
- color: ${tokens.actionIcon};
27
- ${getIconSizeStyles(getIconWidth(size))};
28
- `;
29
-
30
- const getButtonStyle = (size, iconOnly) => {
31
- switch (size) {
32
- case SmartLinkSize.Large:
33
- return iconOnly ? css`
34
- button,
35
- button:hover,
36
- button:focus,
37
- button:active {
38
- padding: 0;
39
- > span {
40
- margin: 0;
41
- }
42
- }
43
- ` : '';
44
-
45
- case SmartLinkSize.Small:
46
- return css`
47
- font-size: 0.75rem;
48
- font-weight: 500;
49
- line-height: 1rem;
50
- button,
51
- button:hover,
52
- button:focus,
53
- button:active {
54
- line-height: 1rem;
55
- ${iconOnly ? `
56
- padding: 0.125rem;
57
- ` : `
58
- padding-left: 0.25rem;
59
- padding-right: 0.25rem;
60
- `}
61
- }
62
- `;
63
-
64
- case SmartLinkSize.XLarge:
65
- case SmartLinkSize.Medium:
66
- default:
67
- return '';
68
- }
69
- };
70
-
71
- const ActionIcon = ({
72
- size,
73
- testId,
74
- icon
75
- }) => jsx("span", {
76
- css: getIconStyles(size),
77
- "data-testid": `${testId}-icon`
78
- }, icon);
79
-
80
- export const sizeToSpacing = {
81
- [SmartLinkSize.Small]: 'none',
82
- [SmartLinkSize.Medium]: 'compact',
83
- [SmartLinkSize.Large]: 'compact',
84
- [SmartLinkSize.XLarge]: 'default'
85
- };
5
+ import ActionButton from './action-button';
6
+ import ActionDropdownItem from './action-dropdown-item';
7
+ import ActionIcon from './action-icon';
86
8
  /**
87
9
  * A base action that can be triggered with an on click.
88
10
  * @internal
@@ -108,40 +30,34 @@ const Action = ({
108
30
  return null;
109
31
  }
110
32
 
111
- const iconBefore = icon && iconPosition === 'before' ? jsx(ActionIcon, {
112
- size: size,
113
- testId: testId,
114
- icon: icon
115
- }) : undefined;
116
- const iconAfter = icon && iconPosition === 'after' ? jsx(ActionIcon, {
33
+ const actionIcon = icon && jsx(ActionIcon, {
34
+ icon: icon,
117
35
  size: size,
118
- testId: testId,
119
- icon: icon
120
- }) : undefined;
121
- const iconOnly = !content;
36
+ testId: testId
37
+ });
38
+ const iconBefore = icon && iconPosition === 'before' ? actionIcon : undefined;
39
+ const iconAfter = icon && iconPosition === 'after' ? actionIcon : undefined;
122
40
 
123
41
  if (asDropDownItem) {
124
- return jsx(DropdownItem, {
125
- elemBefore: iconBefore,
126
- elemAfter: iconAfter,
127
- testId: testId,
128
- onClick: handleOnClick(onClick)
129
- }, content);
42
+ return jsx(ActionDropdownItem, {
43
+ content: content,
44
+ iconAfter: iconAfter,
45
+ iconBefore: iconBefore,
46
+ onClick: onClick,
47
+ testId: testId
48
+ });
130
49
  } else {
131
- return jsx(Tooltip, {
132
- content: tooltipMessage,
133
- testId: `${testId}-tooltip`
134
- }, jsx("div", {
135
- css: [getButtonStyle(size, iconOnly), overrideCss],
136
- "data-testid": `${testId}-button-wrapper`
137
- }, jsx(Button, {
138
- spacing: sizeToSpacing[size],
50
+ return jsx(ActionButton, {
139
51
  appearance: appearance,
140
- testId: testId,
141
- onClick: handleOnClick(onClick),
52
+ content: content,
53
+ iconAfter: iconAfter,
142
54
  iconBefore: iconBefore,
143
- iconAfter: iconAfter
144
- }, content)));
55
+ onClick: onClick,
56
+ overrideCss: overrideCss,
57
+ size: size,
58
+ testId: testId,
59
+ tooltipMessage: tooltipMessage
60
+ });
145
61
  }
146
62
  };
147
63
 
@@ -1,7 +1,7 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
2
 
3
3
  /** @jsx jsx */
4
- import { useCallback } from 'react';
4
+ import { useCallback, useMemo, useState } from 'react';
5
5
  import { FormattedMessage } from 'react-intl-next';
6
6
  import { css, jsx } from '@emotion/core';
7
7
  import ButtonGroup from '@atlaskit/button/button-group';
@@ -11,7 +11,7 @@ import DropdownMenu from '@atlaskit/dropdown-menu';
11
11
  import { SmartLinkSize } from '../../../../../constants';
12
12
  import Button from '@atlaskit/button/standard-button';
13
13
  import MoreIcon from '@atlaskit/icon/glyph/more';
14
- import { sizeToSpacing } from '../../actions/action';
14
+ import { sizeToButtonSpacing } from '../../utils';
15
15
  import { tokens } from '../../../../../utils/token';
16
16
  import { messages } from '../../../../../messages';
17
17
  const styles = css`
@@ -46,35 +46,54 @@ const ActionGroup = ({
46
46
  onDropdownOpenChange,
47
47
  testId
48
48
  }) => {
49
- const isMoreThenTwoItems = items.length > visibleButtonsNum;
50
- const firstActions = isMoreThenTwoItems ? items.slice(0, visibleButtonsNum - 1) : items;
51
- const restActions = isMoreThenTwoItems ? items.slice(visibleButtonsNum - 1) : []; // Stop AK dropdown menu to propagate event on click.
49
+ const [isOpen, setIsOpen] = useState(false);
50
+ const [buttonActions, dropdownItemActions] = useMemo(() => {
51
+ const isMoreThenTwoItems = items.length > visibleButtonsNum;
52
+ const buttons = isMoreThenTwoItems ? items.slice(0, visibleButtonsNum - 1) : items;
53
+ const dropdownItems = isMoreThenTwoItems ? items.slice(visibleButtonsNum - 1) : [];
54
+ return [buttons, dropdownItems];
55
+ }, [items, visibleButtonsNum]); // Stop AK dropdown menu to propagate event on click.
52
56
 
53
57
  const onClick = useCallback(e => e.stopPropagation(), []);
58
+ const onOpenChange = useCallback(attrs => {
59
+ setIsOpen(attrs.isOpen);
60
+
61
+ if (onDropdownOpenChange) {
62
+ onDropdownOpenChange(attrs.isOpen);
63
+ }
64
+ }, [onDropdownOpenChange]);
65
+ const onActionClick = useCallback(() => {
66
+ if (isOpen) {
67
+ onOpenChange({
68
+ isOpen: false
69
+ });
70
+ }
71
+ }, [isOpen, onOpenChange]);
54
72
  return jsx("div", {
55
73
  css: styles,
56
74
  className: "actions-button-group",
57
75
  onClick: onClick
58
- }, jsx(ButtonGroup, null, renderActionItems(firstActions, size, appearance), restActions.length > 0 ? jsx(DropdownMenu, {
59
- onOpenChange: ({
60
- isOpen
61
- }) => onDropdownOpenChange && onDropdownOpenChange(isOpen),
76
+ }, jsx(ButtonGroup, null, renderActionItems(buttonActions, size, appearance, false, onActionClick), dropdownItemActions.length > 0 ? jsx(DropdownMenu, {
77
+ isOpen: isOpen,
78
+ onOpenChange: onOpenChange,
62
79
  trigger: ({
63
80
  triggerRef,
64
81
  ...props
65
82
  }) => jsx(Tooltip, {
66
83
  content: jsx(FormattedMessage, messages.more_actions),
84
+ hideTooltipOnClick: true,
67
85
  testId: "action-group-more-button-tooltip",
68
86
  tag: "span"
69
87
  }, jsx(Button, _extends({}, props, {
70
- spacing: sizeToSpacing[size],
88
+ spacing: sizeToButtonSpacing[size],
71
89
  testId: "action-group-more-button",
72
90
  iconBefore: jsx(MoreIcon, {
73
91
  label: "more"
74
92
  }),
75
93
  ref: triggerRef
76
- })))
77
- }, renderActionItems(restActions, size, appearance, true)) : null));
94
+ }))),
95
+ testId: "action-group-dropdown"
96
+ }, renderActionItems(dropdownItemActions, size, appearance, true, onActionClick)) : null));
78
97
  };
79
98
 
80
99
  export default ActionGroup;
@@ -138,7 +138,7 @@ export const renderElementItems = (items = [], display = 'inline') => {
138
138
  return elements;
139
139
  }
140
140
  };
141
- export const renderActionItems = (items = [], size = SmartLinkSize.Medium, appearance, asDropDownItems) => {
141
+ export const renderActionItems = (items = [], size = SmartLinkSize.Medium, appearance, asDropDownItems, onActionItemClick) => {
142
142
  const actions = items.reduce((acc, curr, idx) => {
143
143
  const {
144
144
  name,
@@ -160,12 +160,22 @@ export const renderActionItems = (items = [], size = SmartLinkSize.Medium, appea
160
160
  }
161
161
 
162
162
  if (Action) {
163
+ const handleOnClick = () => {
164
+ if (onActionItemClick) {
165
+ onActionItemClick();
166
+ }
167
+
168
+ if (onClick) {
169
+ onClick();
170
+ }
171
+ };
172
+
163
173
  return [...acc, /*#__PURE__*/React.createElement(Action, _extends({
164
174
  asDropDownItem: asDropDownItems,
165
175
  size: size,
166
176
  key: idx,
167
177
  appearance: appearance,
168
- onClick: onClick
178
+ onClick: handleOnClick
169
179
  }, actionProps))];
170
180
  }
171
181
 
@@ -3,6 +3,12 @@ import React from 'react';
3
3
  import { css } from '@emotion/core';
4
4
  import { FormattedMessage } from 'react-intl-next';
5
5
  import { SmartLinkSize } from '../../../constants';
6
+ export const sizeToButtonSpacing = {
7
+ [SmartLinkSize.Small]: 'none',
8
+ [SmartLinkSize.Medium]: 'compact',
9
+ [SmartLinkSize.Large]: 'compact',
10
+ [SmartLinkSize.XLarge]: 'default'
11
+ };
6
12
  export const getFormattedMessage = message => {
7
13
  if (message) {
8
14
  const {
@@ -1,5 +1,5 @@
1
1
  {
2
2
  "name": "@atlaskit/smart-card",
3
- "version": "21.0.2",
3
+ "version": "21.0.3",
4
4
  "sideEffects": false
5
5
  }
@@ -0,0 +1,67 @@
1
+ import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
2
+
3
+ var _templateObject, _templateObject2;
4
+
5
+ /** @jsx jsx */
6
+ import React, { useCallback } from 'react';
7
+ import { css, jsx } from '@emotion/core';
8
+ import Button from '@atlaskit/button/custom-theme-button';
9
+ import Tooltip from '@atlaskit/tooltip';
10
+ import { SmartLinkSize } from '../../../../../../constants';
11
+ import { sizeToButtonSpacing } from '../../../utils';
12
+
13
+ var getButtonStyle = function getButtonStyle(size, iconOnly) {
14
+ switch (size) {
15
+ case SmartLinkSize.Large:
16
+ return iconOnly ? css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n button,\n button:hover,\n button:focus,\n button:active {\n padding: 0;\n > span {\n margin: 0;\n }\n }\n "]))) : '';
17
+
18
+ case SmartLinkSize.Small:
19
+ return css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n font-size: 0.75rem;\n font-weight: 500;\n line-height: 1rem;\n button,\n button:hover,\n button:focus,\n button:active {\n line-height: 1rem;\n ", "\n }\n "])), iconOnly ? "\n padding: 0.125rem;\n " : "\n padding-left: 0.25rem;\n padding-right: 0.25rem;\n ");
20
+
21
+ case SmartLinkSize.XLarge:
22
+ case SmartLinkSize.Medium:
23
+ default:
24
+ return '';
25
+ }
26
+ };
27
+
28
+ var ActionButton = function ActionButton(_ref) {
29
+ var appearance = _ref.appearance,
30
+ content = _ref.content,
31
+ iconAfter = _ref.iconAfter,
32
+ iconBefore = _ref.iconBefore,
33
+ onClick = _ref.onClick,
34
+ overrideCss = _ref.overrideCss,
35
+ size = _ref.size,
36
+ testId = _ref.testId,
37
+ tooltipMessage = _ref.tooltipMessage;
38
+ var iconOnly = !content;
39
+ var onButtonClick = useCallback(function (handler) {
40
+ return function (e) {
41
+ e.preventDefault();
42
+ handler();
43
+ };
44
+ }, []);
45
+ var onContainerClick = useCallback(function (e) {
46
+ // Stop button on click event from propagate into parent container.
47
+ e.stopPropagation();
48
+ }, []);
49
+ return jsx("div", {
50
+ css: [getButtonStyle(size, iconOnly), overrideCss],
51
+ "data-testid": "".concat(testId, "-button-wrapper"),
52
+ onClick: onContainerClick
53
+ }, jsx(Tooltip, {
54
+ content: tooltipMessage,
55
+ hideTooltipOnClick: true,
56
+ testId: "".concat(testId, "-tooltip")
57
+ }, jsx(Button, {
58
+ appearance: appearance,
59
+ iconAfter: iconAfter,
60
+ iconBefore: iconBefore,
61
+ onClick: onButtonClick(onClick),
62
+ spacing: sizeToButtonSpacing[size],
63
+ testId: testId
64
+ }, content)));
65
+ };
66
+
67
+ export default ActionButton;
@@ -0,0 +1,19 @@
1
+ import React from 'react';
2
+ import { DropdownItem } from '@atlaskit/dropdown-menu';
3
+ import { handleOnClick } from '../../../../../../utils';
4
+
5
+ var ActionDropdownItem = function ActionDropdownItem(_ref) {
6
+ var content = _ref.content,
7
+ iconAfter = _ref.iconAfter,
8
+ iconBefore = _ref.iconBefore,
9
+ onClick = _ref.onClick,
10
+ testId = _ref.testId;
11
+ return /*#__PURE__*/React.createElement(DropdownItem, {
12
+ elemAfter: iconAfter,
13
+ elemBefore: iconBefore,
14
+ onClick: handleOnClick(onClick),
15
+ testId: testId
16
+ }, content);
17
+ };
18
+
19
+ export default ActionDropdownItem;
@@ -0,0 +1,39 @@
1
+ import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
2
+
3
+ var _templateObject;
4
+
5
+ /** @jsx jsx */
6
+ import React from 'react';
7
+ import { css, jsx } from '@emotion/core';
8
+ import { SmartLinkSize } from '../../../../../../constants';
9
+ import { tokens } from '../../../../../../utils/token';
10
+ import { getIconSizeStyles } from '../../../utils';
11
+
12
+ var getIconWidth = function getIconWidth(size) {
13
+ switch (size) {
14
+ case SmartLinkSize.XLarge:
15
+ case SmartLinkSize.Large:
16
+ return '1.5rem';
17
+
18
+ case SmartLinkSize.Medium:
19
+ case SmartLinkSize.Small:
20
+ default:
21
+ return '1rem';
22
+ }
23
+ };
24
+
25
+ var getIconStyles = function getIconStyles(size) {
26
+ return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n color: ", ";\n ", ";\n"])), tokens.actionIcon, getIconSizeStyles(getIconWidth(size)));
27
+ };
28
+
29
+ var ActionIcon = function ActionIcon(_ref) {
30
+ var size = _ref.size,
31
+ testId = _ref.testId,
32
+ icon = _ref.icon;
33
+ return jsx("span", {
34
+ css: getIconStyles(size),
35
+ "data-testid": "".concat(testId, "-icon")
36
+ }, icon);
37
+ };
38
+
39
+ export default ActionIcon;
@@ -1,62 +1,10 @@
1
- import _defineProperty from "@babel/runtime/helpers/defineProperty";
2
- import _taggedTemplateLiteral from "@babel/runtime/helpers/taggedTemplateLiteral";
3
-
4
- var _templateObject, _templateObject2, _templateObject3, _sizeToSpacing;
5
-
6
1
  /** @jsx jsx */
7
2
  import React from 'react';
8
- import { css, jsx } from '@emotion/core';
9
- import Button from '@atlaskit/button/custom-theme-button';
3
+ import { jsx } from '@emotion/core';
10
4
  import { SmartLinkSize } from '../../../../../constants';
11
- import Tooltip from '@atlaskit/tooltip';
12
- import { DropdownItem } from '@atlaskit/dropdown-menu';
13
- import { getIconSizeStyles } from '../../utils';
14
- import { tokens } from '../../../../../utils/token';
15
- import { handleOnClick } from '../../../../../utils';
16
-
17
- var getIconWidth = function getIconWidth(size) {
18
- switch (size) {
19
- case SmartLinkSize.XLarge:
20
- case SmartLinkSize.Large:
21
- return '1.5rem';
22
-
23
- case SmartLinkSize.Medium:
24
- case SmartLinkSize.Small:
25
- default:
26
- return '1rem';
27
- }
28
- };
29
-
30
- var getIconStyles = function getIconStyles(size) {
31
- return css(_templateObject || (_templateObject = _taggedTemplateLiteral(["\n color: ", ";\n ", ";\n"])), tokens.actionIcon, getIconSizeStyles(getIconWidth(size)));
32
- };
33
-
34
- var getButtonStyle = function getButtonStyle(size, iconOnly) {
35
- switch (size) {
36
- case SmartLinkSize.Large:
37
- return iconOnly ? css(_templateObject2 || (_templateObject2 = _taggedTemplateLiteral(["\n button,\n button:hover,\n button:focus,\n button:active {\n padding: 0;\n > span {\n margin: 0;\n }\n }\n "]))) : '';
38
-
39
- case SmartLinkSize.Small:
40
- return css(_templateObject3 || (_templateObject3 = _taggedTemplateLiteral(["\n font-size: 0.75rem;\n font-weight: 500;\n line-height: 1rem;\n button,\n button:hover,\n button:focus,\n button:active {\n line-height: 1rem;\n ", "\n }\n "])), iconOnly ? "\n padding: 0.125rem;\n " : "\n padding-left: 0.25rem;\n padding-right: 0.25rem;\n ");
41
-
42
- case SmartLinkSize.XLarge:
43
- case SmartLinkSize.Medium:
44
- default:
45
- return '';
46
- }
47
- };
48
-
49
- var ActionIcon = function ActionIcon(_ref) {
50
- var size = _ref.size,
51
- testId = _ref.testId,
52
- icon = _ref.icon;
53
- return jsx("span", {
54
- css: getIconStyles(size),
55
- "data-testid": "".concat(testId, "-icon")
56
- }, icon);
57
- };
58
-
59
- export var sizeToSpacing = (_sizeToSpacing = {}, _defineProperty(_sizeToSpacing, SmartLinkSize.Small, 'none'), _defineProperty(_sizeToSpacing, SmartLinkSize.Medium, 'compact'), _defineProperty(_sizeToSpacing, SmartLinkSize.Large, 'compact'), _defineProperty(_sizeToSpacing, SmartLinkSize.XLarge, 'default'), _sizeToSpacing);
5
+ import ActionButton from './action-button';
6
+ import ActionDropdownItem from './action-dropdown-item';
7
+ import ActionIcon from './action-icon';
60
8
  /**
61
9
  * A base action that can be triggered with an on click.
62
10
  * @internal
@@ -66,60 +14,54 @@ export var sizeToSpacing = (_sizeToSpacing = {}, _defineProperty(_sizeToSpacing,
66
14
  * @see CustomAction
67
15
  */
68
16
 
69
- var Action = function Action(_ref2) {
70
- var _ref2$appearance = _ref2.appearance,
71
- appearance = _ref2$appearance === void 0 ? 'subtle' : _ref2$appearance,
72
- content = _ref2.content,
73
- onClick = _ref2.onClick,
74
- _ref2$size = _ref2.size,
75
- size = _ref2$size === void 0 ? SmartLinkSize.Medium : _ref2$size,
76
- _ref2$testId = _ref2.testId,
77
- testId = _ref2$testId === void 0 ? 'smart-action' : _ref2$testId,
78
- icon = _ref2.icon,
79
- _ref2$iconPosition = _ref2.iconPosition,
80
- iconPosition = _ref2$iconPosition === void 0 ? 'before' : _ref2$iconPosition,
81
- tooltipMessage = _ref2.tooltipMessage,
82
- asDropDownItem = _ref2.asDropDownItem,
83
- overrideCss = _ref2.overrideCss;
17
+ var Action = function Action(_ref) {
18
+ var _ref$appearance = _ref.appearance,
19
+ appearance = _ref$appearance === void 0 ? 'subtle' : _ref$appearance,
20
+ content = _ref.content,
21
+ onClick = _ref.onClick,
22
+ _ref$size = _ref.size,
23
+ size = _ref$size === void 0 ? SmartLinkSize.Medium : _ref$size,
24
+ _ref$testId = _ref.testId,
25
+ testId = _ref$testId === void 0 ? 'smart-action' : _ref$testId,
26
+ icon = _ref.icon,
27
+ _ref$iconPosition = _ref.iconPosition,
28
+ iconPosition = _ref$iconPosition === void 0 ? 'before' : _ref$iconPosition,
29
+ tooltipMessage = _ref.tooltipMessage,
30
+ asDropDownItem = _ref.asDropDownItem,
31
+ overrideCss = _ref.overrideCss;
84
32
 
85
33
  if (!onClick) {
86
34
  return null;
87
35
  }
88
36
 
89
- var iconBefore = icon && iconPosition === 'before' ? jsx(ActionIcon, {
37
+ var actionIcon = icon && jsx(ActionIcon, {
38
+ icon: icon,
90
39
  size: size,
91
- testId: testId,
92
- icon: icon
93
- }) : undefined;
94
- var iconAfter = icon && iconPosition === 'after' ? jsx(ActionIcon, {
95
- size: size,
96
- testId: testId,
97
- icon: icon
98
- }) : undefined;
99
- var iconOnly = !content;
40
+ testId: testId
41
+ });
42
+ var iconBefore = icon && iconPosition === 'before' ? actionIcon : undefined;
43
+ var iconAfter = icon && iconPosition === 'after' ? actionIcon : undefined;
100
44
 
101
45
  if (asDropDownItem) {
102
- return jsx(DropdownItem, {
103
- elemBefore: iconBefore,
104
- elemAfter: iconAfter,
105
- testId: testId,
106
- onClick: handleOnClick(onClick)
107
- }, content);
46
+ return jsx(ActionDropdownItem, {
47
+ content: content,
48
+ iconAfter: iconAfter,
49
+ iconBefore: iconBefore,
50
+ onClick: onClick,
51
+ testId: testId
52
+ });
108
53
  } else {
109
- return jsx(Tooltip, {
110
- content: tooltipMessage,
111
- testId: "".concat(testId, "-tooltip")
112
- }, jsx("div", {
113
- css: [getButtonStyle(size, iconOnly), overrideCss],
114
- "data-testid": "".concat(testId, "-button-wrapper")
115
- }, jsx(Button, {
116
- spacing: sizeToSpacing[size],
54
+ return jsx(ActionButton, {
117
55
  appearance: appearance,
118
- testId: testId,
119
- onClick: handleOnClick(onClick),
56
+ content: content,
57
+ iconAfter: iconAfter,
120
58
  iconBefore: iconBefore,
121
- iconAfter: iconAfter
122
- }, content)));
59
+ onClick: onClick,
60
+ overrideCss: overrideCss,
61
+ size: size,
62
+ testId: testId,
63
+ tooltipMessage: tooltipMessage
64
+ });
123
65
  }
124
66
  };
125
67