@atlaskit/smart-card 21.0.2 → 21.1.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 (55) hide show
  1. package/CHANGELOG.md +18 -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/block/index.js +1 -1
  12. package/dist/cjs/view/FlexibleCard/components/blocks/title-block/index.js +13 -4
  13. package/dist/cjs/view/FlexibleCard/components/blocks/utils.js +16 -3
  14. package/dist/cjs/view/FlexibleCard/components/utils.js +7 -2
  15. package/dist/es2019/version.json +1 -1
  16. package/dist/es2019/view/FlexibleCard/components/actions/action/action-button/index.js +88 -0
  17. package/dist/es2019/view/FlexibleCard/components/actions/action/action-button/types.js +1 -0
  18. package/dist/es2019/view/FlexibleCard/components/actions/action/action-dropdown-item/index.js +18 -0
  19. package/dist/es2019/view/FlexibleCard/components/actions/action/action-dropdown-item/types.js +1 -0
  20. package/dist/es2019/view/FlexibleCard/components/actions/action/action-icon/index.js +35 -0
  21. package/dist/es2019/view/FlexibleCard/components/actions/action/action-icon/types.js +1 -0
  22. package/dist/es2019/view/FlexibleCard/components/actions/action/index.js +26 -110
  23. package/dist/es2019/view/FlexibleCard/components/blocks/action-group/index.js +31 -12
  24. package/dist/es2019/view/FlexibleCard/components/blocks/block/index.js +2 -1
  25. package/dist/es2019/view/FlexibleCard/components/blocks/title-block/index.js +12 -2
  26. package/dist/es2019/view/FlexibleCard/components/blocks/utils.js +23 -2
  27. package/dist/es2019/view/FlexibleCard/components/utils.js +6 -0
  28. package/dist/esm/version.json +1 -1
  29. package/dist/esm/view/FlexibleCard/components/actions/action/action-button/index.js +67 -0
  30. package/dist/esm/view/FlexibleCard/components/actions/action/action-button/types.js +1 -0
  31. package/dist/esm/view/FlexibleCard/components/actions/action/action-dropdown-item/index.js +19 -0
  32. package/dist/esm/view/FlexibleCard/components/actions/action/action-dropdown-item/types.js +1 -0
  33. package/dist/esm/view/FlexibleCard/components/actions/action/action-icon/index.js +39 -0
  34. package/dist/esm/view/FlexibleCard/components/actions/action/action-icon/types.js +1 -0
  35. package/dist/esm/view/FlexibleCard/components/actions/action/index.js +41 -99
  36. package/dist/esm/view/FlexibleCard/components/blocks/action-group/index.js +44 -16
  37. package/dist/esm/view/FlexibleCard/components/blocks/block/index.js +2 -2
  38. package/dist/esm/view/FlexibleCard/components/blocks/title-block/index.js +13 -5
  39. package/dist/esm/view/FlexibleCard/components/blocks/utils.js +14 -2
  40. package/dist/esm/view/FlexibleCard/components/utils.js +3 -1
  41. package/dist/types/index.d.ts +1 -1
  42. package/dist/types/view/FlexibleCard/components/actions/action/action-button/index.d.ts +5 -0
  43. package/dist/types/view/FlexibleCard/components/actions/action/action-button/types.d.ts +8 -0
  44. package/dist/types/view/FlexibleCard/components/actions/action/action-dropdown-item/index.d.ts +4 -0
  45. package/dist/types/view/FlexibleCard/components/actions/action/action-dropdown-item/types.d.ts +8 -0
  46. package/dist/types/view/FlexibleCard/components/actions/action/action-icon/index.d.ts +5 -0
  47. package/dist/types/view/FlexibleCard/components/actions/action/action-icon/types.d.ts +7 -0
  48. package/dist/types/view/FlexibleCard/components/actions/action/index.d.ts +0 -3
  49. package/dist/types/view/FlexibleCard/components/actions/action/types.d.ts +0 -16
  50. package/dist/types/view/FlexibleCard/components/blocks/title-block/types.d.ts +6 -1
  51. package/dist/types/view/FlexibleCard/components/blocks/types.d.ts +3 -0
  52. package/dist/types/view/FlexibleCard/components/blocks/utils.d.ts +2 -1
  53. package/dist/types/view/FlexibleCard/components/utils.d.ts +2 -0
  54. package/package.json +8 -5
  55. package/report.api.md +41 -2
@@ -0,0 +1,88 @@
1
+ /** @jsx jsx */
2
+ import React, { useCallback } from 'react';
3
+ import { css, jsx } from '@emotion/core';
4
+ import Button from '@atlaskit/button/custom-theme-button';
5
+ import Tooltip from '@atlaskit/tooltip';
6
+ import { SmartLinkSize } from '../../../../../../constants';
7
+ import { sizeToButtonSpacing } from '../../../utils';
8
+
9
+ const getButtonStyle = (size, iconOnly) => {
10
+ switch (size) {
11
+ case SmartLinkSize.Large:
12
+ return iconOnly ? css`
13
+ button,
14
+ button:hover,
15
+ button:focus,
16
+ button:active {
17
+ padding: 0;
18
+ > span {
19
+ margin: 0;
20
+ }
21
+ }
22
+ ` : '';
23
+
24
+ case SmartLinkSize.Small:
25
+ return css`
26
+ font-size: 0.75rem;
27
+ font-weight: 500;
28
+ line-height: 1rem;
29
+ button,
30
+ button:hover,
31
+ button:focus,
32
+ button:active {
33
+ line-height: 1rem;
34
+ ${iconOnly ? `
35
+ padding: 0.125rem;
36
+ ` : `
37
+ padding-left: 0.25rem;
38
+ padding-right: 0.25rem;
39
+ `}
40
+ }
41
+ `;
42
+
43
+ case SmartLinkSize.XLarge:
44
+ case SmartLinkSize.Medium:
45
+ default:
46
+ return '';
47
+ }
48
+ };
49
+
50
+ const ActionButton = ({
51
+ appearance,
52
+ content,
53
+ iconAfter,
54
+ iconBefore,
55
+ onClick,
56
+ overrideCss,
57
+ size,
58
+ testId,
59
+ tooltipMessage
60
+ }) => {
61
+ const iconOnly = !content;
62
+ const onButtonClick = useCallback(handler => e => {
63
+ e.preventDefault();
64
+ handler();
65
+ }, []);
66
+ const onContainerClick = useCallback(e => {
67
+ // Stop button on click event from propagate into parent container.
68
+ e.stopPropagation();
69
+ }, []);
70
+ return jsx("div", {
71
+ css: [getButtonStyle(size, iconOnly), overrideCss],
72
+ "data-testid": `${testId}-button-wrapper`,
73
+ onClick: onContainerClick
74
+ }, jsx(Tooltip, {
75
+ content: tooltipMessage,
76
+ hideTooltipOnClick: true,
77
+ testId: `${testId}-tooltip`
78
+ }, jsx(Button, {
79
+ appearance: appearance,
80
+ iconAfter: iconAfter,
81
+ iconBefore: iconBefore,
82
+ onClick: onButtonClick(onClick),
83
+ spacing: sizeToButtonSpacing[size],
84
+ testId: testId
85
+ }, content)));
86
+ };
87
+
88
+ export default ActionButton;
@@ -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;
@@ -2,10 +2,11 @@
2
2
  import React from 'react';
3
3
  import { css, jsx } from '@emotion/core';
4
4
  import { ElementName, SmartLinkDirection, SmartLinkSize } from '../../../../../constants';
5
- import { getBaseStyles, getGapSize, renderChildren } from '../utils';
5
+ import { getBaseStyles, getGapSize, highlightRemoveStyles, renderChildren } from '../utils';
6
6
 
7
7
  const getBlockStyles = (direction, size) => css`
8
8
  ${getBaseStyles(direction, size)}
9
+ ${highlightRemoveStyles}
9
10
  justify-content: flex-start;
10
11
  [data-separator] + [data-separator]:before {
11
12
  content: '•';
@@ -1,5 +1,5 @@
1
1
  import _extends from "@babel/runtime/helpers/extends";
2
- import React, { useState } from 'react';
2
+ import React, { useCallback, useState } from 'react';
3
3
  import { css } from '@emotion/core';
4
4
  import { SmartLinkStatus } from '../../../../../constants';
5
5
  import TitleBlockResolvedView from './resolved';
@@ -60,6 +60,7 @@ const TitleBlock = ({
60
60
  anchorTarget,
61
61
  hideTitleTooltip,
62
62
  maxLines,
63
+ onActionMenuOpenChange,
63
64
  onClick,
64
65
  overrideCss,
65
66
  status = SmartLinkStatus.Fallback,
@@ -70,10 +71,19 @@ const TitleBlock = ({
70
71
  ...props
71
72
  }) => {
72
73
  const [actionDropdownOpen, setActionDropdownOpen] = useState(false);
74
+ const onDropdownOpenChange = useCallback(isOpen => {
75
+ setActionDropdownOpen(isOpen);
76
+
77
+ if (onActionMenuOpenChange) {
78
+ onActionMenuOpenChange({
79
+ isOpen
80
+ });
81
+ }
82
+ }, [onActionMenuOpenChange]);
73
83
  const actionGroup = actions.length > 0 && /*#__PURE__*/React.createElement(ActionGroup, {
74
84
  items: actions,
75
85
  visibleButtonsNum: showActionOnHover ? 1 : 2,
76
- onDropdownOpenChange: isOpen => setActionDropdownOpen(isOpen)
86
+ onDropdownOpenChange: onDropdownOpenChange
77
87
  });
78
88
  const actionStyles = getActionStyles(showActionOnHover, actionDropdownOpen);
79
89
  const combinedCss = css`
@@ -84,6 +84,17 @@ export const getBaseStyles = (direction, size) => css`
84
84
  min-width: fit-content;
85
85
  }
86
86
  `;
87
+ export const highlightRemoveStyles = css`
88
+ outline: none !important;
89
+ outline-color: inherit;
90
+ color: inherit;
91
+ -webkit-tap-highlight-color: transparent;
92
+ -webkit-touch-callout: none;
93
+ -webkit-user-select: none;
94
+ -moz-user-select: none;
95
+ -ms-user-select: none;
96
+ user-select: none;
97
+ `;
87
98
 
88
99
  const isActionGroup = node => /*#__PURE__*/React.isValidElement(node) && node.type === ActionGroup;
89
100
 
@@ -138,7 +149,7 @@ export const renderElementItems = (items = [], display = 'inline') => {
138
149
  return elements;
139
150
  }
140
151
  };
141
- export const renderActionItems = (items = [], size = SmartLinkSize.Medium, appearance, asDropDownItems) => {
152
+ export const renderActionItems = (items = [], size = SmartLinkSize.Medium, appearance, asDropDownItems, onActionItemClick) => {
142
153
  const actions = items.reduce((acc, curr, idx) => {
143
154
  const {
144
155
  name,
@@ -160,12 +171,22 @@ export const renderActionItems = (items = [], size = SmartLinkSize.Medium, appea
160
171
  }
161
172
 
162
173
  if (Action) {
174
+ const handleOnClick = () => {
175
+ if (onActionItemClick) {
176
+ onActionItemClick();
177
+ }
178
+
179
+ if (onClick) {
180
+ onClick();
181
+ }
182
+ };
183
+
163
184
  return [...acc, /*#__PURE__*/React.createElement(Action, _extends({
164
185
  asDropDownItem: asDropDownItems,
165
186
  size: size,
166
187
  key: idx,
167
188
  appearance: appearance,
168
- onClick: onClick
189
+ onClick: handleOnClick
169
190
  }, actionProps))];
170
191
  }
171
192
 
@@ -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.1.0",
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;