@atlaskit/button 16.10.1 → 16.11.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 (81) hide show
  1. package/CHANGELOG.md +72 -60
  2. package/dist/cjs/containers/button-group.js +1 -0
  3. package/dist/cjs/entry-points/new.js +8 -1
  4. package/dist/cjs/entry-points/unsafe.js +40 -1
  5. package/dist/cjs/new-button/containers/split-button/index.js +50 -0
  6. package/dist/cjs/new-button/containers/split-button/split-button-context.js +37 -0
  7. package/dist/cjs/new-button/containers/split-button/split-button.js +137 -0
  8. package/dist/cjs/new-button/containers/split-button/types.js +5 -0
  9. package/dist/cjs/new-button/containers/split-button/utils.js +23 -0
  10. package/dist/cjs/new-button/variants/default/button.js +1 -2
  11. package/dist/cjs/new-button/variants/default/link.js +1 -2
  12. package/dist/cjs/new-button/variants/default/use-default-button.js +11 -16
  13. package/dist/cjs/new-button/variants/icon/button.js +1 -2
  14. package/dist/cjs/new-button/variants/icon/link.js +1 -2
  15. package/dist/cjs/new-button/variants/icon/use-icon-button.js +6 -10
  16. package/dist/cjs/new-button/variants/shared/colors.js +1 -2
  17. package/dist/cjs/new-button/variants/shared/content.js +51 -0
  18. package/dist/cjs/new-button/variants/shared/use-button-base.js +32 -9
  19. package/dist/cjs/new-button/variants/shared/xcss.js +53 -53
  20. package/dist/cjs/old-button/button.js +1 -2
  21. package/dist/cjs/old-button/custom-theme-button/custom-theme-button.js +1 -2
  22. package/dist/cjs/old-button/custom-theme-button/theme.js +1 -2
  23. package/dist/cjs/old-button/loading-button.js +1 -2
  24. package/dist/cjs/old-button/shared/button-base.js +9 -9
  25. package/dist/cjs/old-button/shared/colors.js +1 -2
  26. package/dist/cjs/old-button/shared/css.js +2 -3
  27. package/dist/cjs/old-button/shared/get-if-visually-hidden-children.js +2 -3
  28. package/dist/cjs/utils/appearances.js +1 -2
  29. package/dist/cjs/utils/spacing.js +1 -2
  30. package/dist/cjs/utils/variants.js +2 -4
  31. package/dist/es2019/containers/button-group.js +1 -0
  32. package/dist/es2019/entry-points/new.js +2 -1
  33. package/dist/es2019/entry-points/unsafe.js +4 -1
  34. package/dist/es2019/new-button/containers/split-button/index.js +3 -0
  35. package/dist/es2019/new-button/containers/split-button/split-button-context.js +31 -0
  36. package/dist/es2019/new-button/containers/split-button/split-button.js +129 -0
  37. package/dist/es2019/new-button/containers/split-button/types.js +1 -0
  38. package/dist/es2019/new-button/containers/split-button/utils.js +12 -0
  39. package/dist/es2019/new-button/variants/default/use-default-button.js +10 -14
  40. package/dist/es2019/new-button/variants/icon/use-icon-button.js +5 -8
  41. package/dist/es2019/new-button/variants/shared/content.js +43 -0
  42. package/dist/es2019/new-button/variants/shared/use-button-base.js +32 -8
  43. package/dist/es2019/new-button/variants/shared/xcss.js +55 -48
  44. package/dist/es2019/old-button/shared/button-base.js +7 -6
  45. package/dist/esm/containers/button-group.js +1 -0
  46. package/dist/esm/entry-points/new.js +2 -1
  47. package/dist/esm/entry-points/unsafe.js +4 -1
  48. package/dist/esm/new-button/containers/split-button/index.js +3 -0
  49. package/dist/esm/new-button/containers/split-button/split-button-context.js +31 -0
  50. package/dist/esm/new-button/containers/split-button/split-button.js +131 -0
  51. package/dist/esm/new-button/containers/split-button/types.js +1 -0
  52. package/dist/esm/new-button/containers/split-button/utils.js +16 -0
  53. package/dist/esm/new-button/variants/default/use-default-button.js +10 -14
  54. package/dist/esm/new-button/variants/icon/use-icon-button.js +5 -8
  55. package/dist/esm/new-button/variants/shared/content.js +44 -0
  56. package/dist/esm/new-button/variants/shared/use-button-base.js +32 -8
  57. package/dist/esm/new-button/variants/shared/xcss.js +52 -47
  58. package/dist/esm/old-button/shared/button-base.js +7 -6
  59. package/dist/types/entry-points/new.d.ts +1 -0
  60. package/dist/types/entry-points/unsafe.d.ts +3 -0
  61. package/dist/types/new-button/containers/split-button/index.d.ts +3 -0
  62. package/dist/types/new-button/containers/split-button/split-button-context.d.ts +47 -0
  63. package/dist/types/new-button/containers/split-button/split-button.d.ts +47 -0
  64. package/dist/types/new-button/containers/split-button/types.d.ts +4 -0
  65. package/dist/types/new-button/containers/split-button/utils.d.ts +5 -0
  66. package/dist/types/new-button/variants/shared/content.d.ts +13 -0
  67. package/dist/types/new-button/variants/shared/use-button-base.d.ts +1 -1
  68. package/dist/types/new-button/variants/shared/xcss.d.ts +14 -7
  69. package/dist/types/old-button/types.d.ts +2 -2
  70. package/dist/types-ts4.5/entry-points/new.d.ts +1 -0
  71. package/dist/types-ts4.5/entry-points/unsafe.d.ts +3 -0
  72. package/dist/types-ts4.5/new-button/containers/split-button/index.d.ts +3 -0
  73. package/dist/types-ts4.5/new-button/containers/split-button/split-button-context.d.ts +47 -0
  74. package/dist/types-ts4.5/new-button/containers/split-button/split-button.d.ts +47 -0
  75. package/dist/types-ts4.5/new-button/containers/split-button/types.d.ts +4 -0
  76. package/dist/types-ts4.5/new-button/containers/split-button/utils.d.ts +5 -0
  77. package/dist/types-ts4.5/new-button/variants/shared/content.d.ts +13 -0
  78. package/dist/types-ts4.5/new-button/variants/shared/use-button-base.d.ts +1 -1
  79. package/dist/types-ts4.5/new-button/variants/shared/xcss.d.ts +14 -7
  80. package/dist/types-ts4.5/old-button/types.d.ts +2 -2
  81. package/package.json +6 -6
@@ -45,5 +45,4 @@ var LoadingButton = /*#__PURE__*/_react.default.forwardRef(function LoadingButto
45
45
 
46
46
  // Tools including enzyme rely on components having a display name
47
47
  LoadingButton.displayName = 'LoadingButton';
48
- var _default = LoadingButton;
49
- exports.default = _default;
48
+ var _default = exports.default = LoadingButton;
@@ -21,6 +21,7 @@ var _blockEvents = _interopRequireDefault(require("./block-events"));
21
21
  var _css = require("./css");
22
22
  var _getIfVisuallyHiddenChildren = require("./get-if-visually-hidden-children");
23
23
  var _excluded = ["analyticsContext", "appearance", "autoFocus", "buttonCss", "children", "className", "href", "component", "iconAfter", "iconBefore", "interactionName", "isDisabled", "isSelected", "onBlur", "onClick", "onFocus", "onMouseDown", "overlay", "shouldFitContainer", "spacing", "tabIndex", "type", "testId"];
24
+ /* eslint-disable @atlaskit/design-system/consistent-css-prop-usage */
24
25
  /** @jsx jsx */
25
26
  // eslint-disable-next-line no-duplicate-imports
26
27
  function _getRequireWildcardCache(nodeInterop) { if (typeof WeakMap !== "function") return null; var cacheBabelInterop = new WeakMap(); var cacheNodeInterop = new WeakMap(); return (_getRequireWildcardCache = function _getRequireWildcardCache(nodeInterop) { return nodeInterop ? cacheNodeInterop : cacheBabelInterop; })(nodeInterop); }
@@ -54,7 +55,7 @@ var getChildren = function getChildren(children, childrenStyles) {
54
55
  css: childrenStyles
55
56
  }, children) : null;
56
57
  };
57
- var _default = /*#__PURE__*/_react.default.forwardRef(function ButtonBase(props, ref) {
58
+ var _default = exports.default = /*#__PURE__*/_react.default.forwardRef(function ButtonBase(props, ref) {
58
59
  var analyticsContext = props.analyticsContext,
59
60
  _props$appearance = props.appearance,
60
61
  appearance = _props$appearance === void 0 ? 'default' : _props$appearance,
@@ -117,7 +118,7 @@ var _default = /*#__PURE__*/_react.default.forwardRef(function ButtonBase(props,
117
118
  action: 'clicked',
118
119
  componentName: 'button',
119
120
  packageName: "@atlaskit/button",
120
- packageVersion: "16.10.1",
121
+ packageVersion: "16.11.0",
121
122
  analyticsData: analyticsContext
122
123
  });
123
124
 
@@ -137,7 +138,7 @@ var _default = /*#__PURE__*/_react.default.forwardRef(function ButtonBase(props,
137
138
 
138
139
  // we are 'disabling' input with a button when there is an overlay
139
140
  var hasOverlay = Boolean(overlay);
140
- var fadeCss = (0, _react2.css)((0, _css.getFadingCss)({
141
+ var fadeStyles = (0, _react2.css)((0, _css.getFadingCss)({
141
142
  hasOverlay: hasOverlay
142
143
  }));
143
144
  var isInteractive = !isDisabled && !hasOverlay;
@@ -178,21 +179,20 @@ var _default = /*#__PURE__*/_react.default.forwardRef(function ButtonBase(props,
178
179
  }, (0, _blockEvents.default)({
179
180
  isInteractive: isInteractive
180
181
  })), iconBefore ? (0, _react2.jsx)("span", {
181
- css: [fadeCss, (0, _css.getIconStyle)({
182
+ css: [fadeStyles, (0, _css.getIconStyle)({
182
183
  spacing: spacing
183
184
  }), getSpacingFix(children, iconBeforeSpacingFixStyle)]
184
185
  }, iconBefore) : null, !(0, _platformFeatureFlags.getBooleanFF)('platform.design-system-team.icon-button-spacing-fix_o1zc5') && children ? (0, _react2.jsx)("span", {
185
- css: [fadeCss, (0, _css.getContentStyle)({
186
+ css: [fadeStyles, (0, _css.getContentStyle)({
186
187
  spacing: spacing
187
188
  })]
188
- }, children) : null, (0, _platformFeatureFlags.getBooleanFF)('platform.design-system-team.icon-button-spacing-fix_o1zc5') && getChildren(children, [fadeCss, (0, _css.getContentStyle)({
189
+ }, children) : null, (0, _platformFeatureFlags.getBooleanFF)('platform.design-system-team.icon-button-spacing-fix_o1zc5') && getChildren(children, [fadeStyles, (0, _css.getContentStyle)({
189
190
  spacing: spacing
190
191
  })]), iconAfter ? (0, _react2.jsx)("span", {
191
- css: [fadeCss, (0, _css.getIconStyle)({
192
+ css: [fadeStyles, (0, _css.getIconStyle)({
192
193
  spacing: spacing
193
194
  }), getSpacingFix(children, iconAfterSpacingFixStyle)]
194
195
  }, iconAfter) : null, overlay ? (0, _react2.jsx)("span", {
195
196
  css: [_css.overlayCss, spinnerHackCss]
196
197
  }, overlay) : null));
197
- });
198
- exports.default = _default;
198
+ });
@@ -326,5 +326,4 @@ var values = {
326
326
  }
327
327
  }
328
328
  };
329
- var _default = values;
330
- exports.default = _default;
329
+ var _default = exports.default = values;
@@ -229,7 +229,7 @@ function getFadingCss(_ref6) {
229
229
  transition: 'opacity 0.3s'
230
230
  });
231
231
  }
232
- var overlayCss = {
232
+ var overlayCss = exports.overlayCss = {
233
233
  // stretching to full width / height of button
234
234
  // this is important as we need it to still block
235
235
  // event if clicking in the button's own padding
@@ -242,5 +242,4 @@ var overlayCss = {
242
242
  display: 'flex',
243
243
  justifyContent: 'center',
244
244
  alignItems: 'center'
245
- };
246
- exports.overlayCss = overlayCss;
245
+ };
@@ -7,7 +7,6 @@ Object.defineProperty(exports, "__esModule", {
7
7
  exports.getIfVisuallyHiddenChildren = void 0;
8
8
  var _react = require("react");
9
9
  var _visuallyHidden = _interopRequireDefault(require("@atlaskit/visually-hidden"));
10
- var getIfVisuallyHiddenChildren = function getIfVisuallyHiddenChildren(children) {
10
+ var getIfVisuallyHiddenChildren = exports.getIfVisuallyHiddenChildren = function getIfVisuallyHiddenChildren(children) {
11
11
  return children && /*#__PURE__*/(0, _react.isValidElement)(children) && children.type === _visuallyHidden.default;
12
- };
13
- exports.getIfVisuallyHiddenChildren = getIfVisuallyHiddenChildren;
12
+ };
@@ -5,5 +5,4 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var appearances = ['default', 'primary', 'link', 'subtle', 'subtle-link', 'warning', 'danger'];
8
- var _default = appearances;
9
- exports.default = _default;
8
+ var _default = exports.default = appearances;
@@ -5,5 +5,4 @@ Object.defineProperty(exports, "__esModule", {
5
5
  });
6
6
  exports.default = void 0;
7
7
  var spacing = ['default', 'compact', 'none'];
8
- var _default = spacing;
9
- exports.default = _default;
8
+ var _default = exports.default = spacing;
@@ -21,7 +21,7 @@ var LinkButtonRender = /*#__PURE__*/(0, _react.forwardRef)(function (props, ref)
21
21
  href: "#"
22
22
  }, props), props.children);
23
23
  });
24
- var variants = [{
24
+ var variants = exports.variants = [{
25
25
  name: 'Button',
26
26
  Component: _button.default,
27
27
  elementType: HTMLButtonElement
@@ -30,6 +30,4 @@ var variants = [{
30
30
  Component: LinkButtonRender,
31
31
  elementType: HTMLAnchorElement
32
32
  }];
33
- exports.variants = variants;
34
- var _default = variants;
35
- exports.default = _default;
33
+ var _default = exports.default = variants;
@@ -4,6 +4,7 @@ import { css, jsx } from '@emotion/react';
4
4
  const buttonGroupStyles = css({
5
5
  display: 'inline-flex',
6
6
  gap: "var(--ds-space-050, 4px)",
7
+ // eslint-disable-next-line @atlaskit/design-system/no-nested-styles
7
8
  '> *': {
8
9
  flex: '1 0 auto'
9
10
  }
@@ -1,4 +1,5 @@
1
1
  export { default } from '../new-button/variants/default/button';
2
2
  export { default as LinkButton } from '../new-button/variants/default/link';
3
3
  export { default as IconButton } from '../new-button/variants/icon/button';
4
- export { default as LinkIconButton } from '../new-button/variants/icon/link';
4
+ export { default as LinkIconButton } from '../new-button/variants/icon/link';
5
+ export { SplitButton } from '../new-button/containers/split-button';
@@ -1 +1,4 @@
1
- export { default as UNSAFE_BUTTON } from '../new-button/variants/default/button';
1
+ export { default as UNSAFE_BUTTON } from '../new-button/variants/default/button';
2
+ export { default as UNSAFE_ICON_BUTTON } from '../new-button/variants/icon/button';
3
+ export { SplitButton as UNSAFE_SPLIT_BUTTON, SplitButtonContainer as UNSAFE_SPLIT_BUTTON_CONTAINER, Divider as UNSAFE_DIVIDER, getActions as UNSAFE_GET_ACTIONS } from '../new-button/containers/split-button';
4
+ export { SplitButtonContext as UNSAFE_SPLIT_BUTTON_CONTEXT } from '../new-button/containers/split-button/split-button-context';
@@ -0,0 +1,3 @@
1
+ export { SplitButton, SplitButtonWithSlots, Divider, SplitButtonContainer } from './split-button';
2
+ export { getActions } from './utils';
3
+ export { SplitButtonContext, useSplitButtonContext } from './split-button-context';
@@ -0,0 +1,31 @@
1
+ import { createContext, useContext } from 'react';
2
+ /**
3
+ * TODO: Add jsdoc
4
+ */
5
+ export const SplitButtonContext = /*#__PURE__*/createContext(undefined);
6
+ export const useSplitButtonContext = () => {
7
+ const context = useContext(SplitButtonContext);
8
+ if (!context) {
9
+ return undefined;
10
+ }
11
+ if (context.appearance === 'navigation') {
12
+ const newContext = {
13
+ spacing: 'default',
14
+ appearance: 'subtle',
15
+ isDisabled: false,
16
+ isActiveOverSelected: false,
17
+ isNavigationSplitButton: true,
18
+ isHighlighted: context.isHighlighted
19
+ };
20
+ return newContext;
21
+ }
22
+ const splitButtonContext = {
23
+ spacing: context.spacing,
24
+ appearance: context.appearance,
25
+ isDisabled: context.isDisabled,
26
+ isActiveOverSelected: true,
27
+ isNavigationSplitButton: false,
28
+ isHighlighted: false
29
+ };
30
+ return splitButtonContext;
31
+ };
@@ -0,0 +1,129 @@
1
+ /** @jsx jsx */
2
+
3
+ import { css, jsx } from '@emotion/react';
4
+ import { fontSize as getFontSize } from '@atlaskit/theme/constants';
5
+ import { SplitButtonContext } from './split-button-context';
6
+ import { getActions } from './utils';
7
+ const fontSize = getFontSize();
8
+ const defaultDividerHeight = 20 / fontSize + 'em';
9
+ const defaultDividerStyles = css({
10
+ height: defaultDividerHeight,
11
+ margin: `${"var(--ds-space-075, 6px)"} -0.5px`
12
+ });
13
+ const compactDividerHeight = 16 / fontSize + 'em';
14
+ const compactDividerStyles = css({
15
+ height: compactDividerHeight,
16
+ margin: `${"var(--ds-space-050, 4px)"} -0.5px`
17
+ });
18
+ const baseDividerStyles = css({
19
+ display: 'inline-flex',
20
+ width: '1px',
21
+ position: 'relative',
22
+ zIndex: 2
23
+ });
24
+ const disabledStyles = css({
25
+ backgroundColor: "var(--ds-border, #091E4224)",
26
+ cursor: 'not-allowed'
27
+ });
28
+ const navigationDividerStyles = css({
29
+ height: compactDividerHeight,
30
+ margin: `${"var(--ds-space-100, 8px)"} -0.5px`,
31
+ backgroundColor: "var(--ds-border, #0052cc)"
32
+ });
33
+ const dividerAppearance = {
34
+ default: css({
35
+ backgroundColor: "var(--ds-text, #172B4D)"
36
+ }),
37
+ primary: css({
38
+ backgroundColor: "var(--ds-text-inverse, #FFF)"
39
+ }),
40
+ danger: css({
41
+ backgroundColor: "var(--ds-text-inverse, #FFF)"
42
+ }),
43
+ warning: css({
44
+ backgroundColor: "var(--ds-text-warning-inverse, #172B4D)"
45
+ }),
46
+ navigation: navigationDividerStyles
47
+ };
48
+ const dividerHeight = {
49
+ default: defaultDividerStyles,
50
+ compact: compactDividerStyles
51
+ };
52
+ /**
53
+ * TODO: Add JSDoc
54
+ */
55
+ export const Divider = ({
56
+ appearance,
57
+ spacing,
58
+ isDisabled = false
59
+ }) => {
60
+ return (
61
+ // I find it funny to provide a div for Divider
62
+ jsx("div", {
63
+ css: [baseDividerStyles, dividerAppearance[appearance], dividerHeight[spacing], isDisabled ? disabledStyles : undefined]
64
+ })
65
+ );
66
+ };
67
+ const splitButtonStyles = css({
68
+ display: 'inline-flex',
69
+ position: 'relative',
70
+ whiteSpace: 'nowrap'
71
+ });
72
+
73
+ /**
74
+ * TODO: Add JSdoc
75
+ */
76
+ export const SplitButtonContainer = ({
77
+ children
78
+ }) => {
79
+ return jsx("div", {
80
+ css: splitButtonStyles
81
+ }, children);
82
+ };
83
+ /**
84
+ * TODO: Add description when adding docs
85
+ */
86
+ export const SplitButton = ({
87
+ children,
88
+ appearance = 'default',
89
+ spacing = 'default',
90
+ isDisabled = false
91
+ }) => {
92
+ const {
93
+ PrimaryAction,
94
+ SecondaryAction
95
+ } = getActions(children);
96
+ return jsx(SplitButtonContainer, null, jsx(SplitButtonContext.Provider, {
97
+ value: {
98
+ appearance,
99
+ spacing,
100
+ isDisabled
101
+ }
102
+ }, PrimaryAction, jsx(Divider, {
103
+ appearance: appearance,
104
+ spacing: spacing,
105
+ isDisabled: isDisabled
106
+ }), SecondaryAction));
107
+ };
108
+ /**
109
+ * TODO: Decide on API
110
+ */
111
+ export const SplitButtonWithSlots = ({
112
+ primaryAction,
113
+ secondaryAction,
114
+ appearance = 'default',
115
+ spacing = 'default',
116
+ isDisabled = false
117
+ }) => {
118
+ return jsx(SplitButtonContainer, null, jsx(SplitButtonContext.Provider, {
119
+ value: {
120
+ appearance,
121
+ spacing,
122
+ isDisabled
123
+ }
124
+ }, primaryAction, jsx(Divider, {
125
+ appearance: appearance,
126
+ spacing: spacing,
127
+ isDisabled: isDisabled
128
+ }), secondaryAction));
129
+ };
@@ -0,0 +1,12 @@
1
+ import { Children } from 'react';
2
+ export const getActions = children => {
3
+ const [PrimaryAction, SecondaryAction] = Children.toArray(children);
4
+ if (typeof process !== 'undefined' && process.env.NODE_ENV === 'development' && (!PrimaryAction || !SecondaryAction)) {
5
+ // TODO: i18n?
6
+ throw new SyntaxError('SplitButton requires two children to be provided');
7
+ }
8
+ return {
9
+ PrimaryAction,
10
+ SecondaryAction
11
+ };
12
+ };
@@ -1,7 +1,6 @@
1
1
  import React, { Fragment } from 'react';
2
- import { Box } from '@atlaskit/primitives';
2
+ import Content from '../shared/content';
3
3
  import useButtonBase from '../shared/use-button-base';
4
- import { contentStyles, getFadingStyles, iconStyles } from '../shared/xcss';
5
4
  /**
6
5
  * __Use default button base__
7
6
  *
@@ -37,23 +36,20 @@ const useDefaultButton = ({
37
36
  shouldFitContainer,
38
37
  spacing
39
38
  }) => {
40
- const fadeStyles = getFadingStyles({
41
- hasOverlay: Boolean(overlay)
42
- });
39
+ const hasOverlay = Boolean(overlay);
43
40
  const baseProps = useButtonBase({
44
41
  analyticsContext,
45
42
  appearance,
46
43
  autoFocus,
47
44
  buttonType,
48
- children: /*#__PURE__*/React.createElement(Fragment, null, iconBefore && /*#__PURE__*/React.createElement(Box, {
49
- as: "span",
50
- xcss: [fadeStyles, iconStyles]
51
- }, iconBefore), children && /*#__PURE__*/React.createElement(Box, {
52
- as: "span",
53
- xcss: [fadeStyles, contentStyles]
54
- }, children), iconAfter && /*#__PURE__*/React.createElement(Box, {
55
- as: "span",
56
- xcss: [fadeStyles, iconStyles]
45
+ children: /*#__PURE__*/React.createElement(Fragment, null, iconBefore && /*#__PURE__*/React.createElement(Content, {
46
+ type: "icon",
47
+ hasOverlay: hasOverlay
48
+ }, iconBefore), children && /*#__PURE__*/React.createElement(Content, {
49
+ hasOverlay: hasOverlay
50
+ }, children), iconAfter && /*#__PURE__*/React.createElement(Content, {
51
+ type: "icon",
52
+ hasOverlay: hasOverlay
57
53
  }, iconAfter)),
58
54
  interactionName,
59
55
  isDisabled,
@@ -1,7 +1,6 @@
1
1
  import React from 'react';
2
- import { Box } from '@atlaskit/primitives';
2
+ import Content from '../shared/content';
3
3
  import useButtonBase from '../shared/use-button-base';
4
- import { getFadingStyles, iconStyles } from '../shared/xcss';
5
4
  /**
6
5
  * __Use icon button__
7
6
  *
@@ -37,9 +36,7 @@ const useIconButton = ({
37
36
  shouldFitContainer,
38
37
  spacing
39
38
  }) => {
40
- const fadeStyles = getFadingStyles({
41
- hasOverlay: Boolean(overlay)
42
- });
39
+ const hasOverlay = Boolean(overlay);
43
40
  const baseProps = useButtonBase({
44
41
  analyticsContext,
45
42
  appearance,
@@ -49,9 +46,9 @@ const useIconButton = ({
49
46
  * TODO: Have not finished IconButton yet. It also needs a required accessible
50
47
  * label - likely implemented using VisuallyHidden
51
48
  */
52
- children: /*#__PURE__*/React.createElement(Box, {
53
- as: "span",
54
- xcss: [fadeStyles, iconStyles]
49
+ children: /*#__PURE__*/React.createElement(Content, {
50
+ type: "icon",
51
+ hasOverlay: hasOverlay
55
52
  }, icon),
56
53
  interactionName,
57
54
  isDisabled,
@@ -0,0 +1,43 @@
1
+ import React from 'react';
2
+ import { Box, xcss } from '@atlaskit/primitives';
3
+ const textStyles = xcss({
4
+ // content can grow and shrink
5
+ flexGrow: 1,
6
+ flexShrink: 1,
7
+ // ellipsis for overflow text
8
+ overflow: 'hidden',
9
+ textOverflow: 'ellipsis',
10
+ whiteSpace: 'nowrap'
11
+ });
12
+ const iconStyles = xcss({
13
+ display: 'flex',
14
+ // icon size cannot grow and shrink
15
+ flexGrow: 0,
16
+ flexShrink: 0,
17
+ alignSelf: 'center',
18
+ fontSize: 0,
19
+ lineHeight: 0,
20
+ userSelect: 'none'
21
+ });
22
+ const commonStyles = xcss({
23
+ transition: 'opacity 0.3s'
24
+ });
25
+ const fadeStyles = xcss({
26
+ opacity: 0
27
+ });
28
+ /**
29
+ * __Content__
30
+ *
31
+ * Used for slots within a Button, including icons and text content.
32
+ */
33
+ const Content = ({
34
+ children,
35
+ type = 'text',
36
+ hasOverlay
37
+ }) => {
38
+ return /*#__PURE__*/React.createElement(Box, {
39
+ as: "span",
40
+ xcss: [commonStyles, ...(type === 'text' ? [textStyles] : [iconStyles]), ...(hasOverlay ? [fadeStyles] : [])]
41
+ }, children);
42
+ };
43
+ export default Content;
@@ -4,12 +4,24 @@ import noop from '@atlaskit/ds-lib/noop';
4
4
  import useAutoFocus from '@atlaskit/ds-lib/use-auto-focus';
5
5
  // eslint-disable-next-line no-duplicate-imports
6
6
  import InteractionContext from '@atlaskit/interaction-context';
7
- import { Box } from '@atlaskit/primitives';
7
+ import { Box, xcss } from '@atlaskit/primitives';
8
+ import { useSplitButtonContext } from '../../containers/split-button/split-button-context';
8
9
  import blockEvents from './block-events';
9
- import { getXCSS, overlayStyles } from './xcss';
10
+ import { getXCSS } from './xcss';
10
11
 
11
12
  // Include modified onClick with analytics
12
13
 
14
+ const overlayStyles = xcss({
15
+ position: 'absolute',
16
+ insetInlineStart: 'space.0',
17
+ insetBlockStart: 'space.0',
18
+ insetInlineEnd: 'space.0',
19
+ insetBlockEnd: 'space.0',
20
+ display: 'flex',
21
+ alignItems: 'center',
22
+ justifyContent: 'center'
23
+ });
24
+
13
25
  /**
14
26
  * __Use button base__
15
27
  *
@@ -25,11 +37,11 @@ import { getXCSS, overlayStyles } from './xcss';
25
37
  */
26
38
  const useButtonBase = ({
27
39
  analyticsContext,
28
- appearance = 'default',
40
+ appearance: propAppearance = 'default',
29
41
  autoFocus = false,
30
42
  buttonType,
31
43
  interactionName,
32
- isDisabled = false,
44
+ isDisabled: propIsDisabled = false,
33
45
  isSelected = false,
34
46
  // TODO: Separate Icon Button styling from button base
35
47
  isIconButton = false,
@@ -50,9 +62,17 @@ const useButtonBase = ({
50
62
  overlay,
51
63
  ref,
52
64
  shouldFitContainer = false,
53
- spacing = 'default'
65
+ spacing: propSpacing = 'default'
54
66
  }) => {
55
67
  const ourRef = useRef();
68
+ const splitButtonContext = useSplitButtonContext();
69
+ const isSplitButton = Boolean(splitButtonContext);
70
+ const isNavigationSplitButton = (splitButtonContext === null || splitButtonContext === void 0 ? void 0 : splitButtonContext.isNavigationSplitButton) || false;
71
+ const appearance = (splitButtonContext === null || splitButtonContext === void 0 ? void 0 : splitButtonContext.appearance) || propAppearance;
72
+ const spacing = (splitButtonContext === null || splitButtonContext === void 0 ? void 0 : splitButtonContext.spacing) || propSpacing;
73
+ const isDisabled = (splitButtonContext === null || splitButtonContext === void 0 ? void 0 : splitButtonContext.isDisabled) || propIsDisabled;
74
+ const isHighlighted = (splitButtonContext === null || splitButtonContext === void 0 ? void 0 : splitButtonContext.isHighlighted) || false;
75
+ const isActiveOverSelected = (splitButtonContext === null || splitButtonContext === void 0 ? void 0 : splitButtonContext.isActiveOverSelected) || false;
56
76
  const setRef = useCallback(node => {
57
77
  ourRef.current = node;
58
78
  if (ref === null) {
@@ -77,7 +97,7 @@ const useButtonBase = ({
77
97
  action: 'clicked',
78
98
  componentName: 'button',
79
99
  packageName: "@atlaskit/button",
80
- packageVersion: "16.10.1",
100
+ packageVersion: "16.11.0",
81
101
  analyticsData: analyticsContext,
82
102
  actionSubject: buttonType
83
103
  });
@@ -86,13 +106,17 @@ const useButtonBase = ({
86
106
  spacing,
87
107
  isDisabled,
88
108
  isSelected,
109
+ isHighlighted,
110
+ isActiveOverSelected,
89
111
  shouldFitContainer,
90
112
  isIconButton,
91
113
  hasOverlay: Boolean(overlay),
92
114
  isLink: buttonType === 'link',
93
115
  hasIconBefore,
94
- hasIconAfter
95
- }), [appearance, buttonType, spacing, isDisabled, isSelected, isIconButton, shouldFitContainer, overlay, hasIconBefore, hasIconAfter]);
116
+ hasIconAfter,
117
+ isSplit: isSplitButton,
118
+ isNavigationSplit: isNavigationSplitButton
119
+ }), [appearance, buttonType, spacing, isDisabled, isSelected, isHighlighted, isActiveOverSelected, isIconButton, shouldFitContainer, overlay, hasIconBefore, hasIconAfter, isSplitButton, isNavigationSplitButton]);
96
120
  const isEffectivelyDisabled = isDisabled || Boolean(overlay);
97
121
  return {
98
122
  ref: setRef,