@atlaskit/button 16.5.3 → 16.5.5
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/CHANGELOG.md +12 -0
- package/dist/cjs/button-group.js +3 -11
- package/dist/cjs/button.js +14 -34
- package/dist/cjs/custom-theme-button/custom-theme-button.js +41 -76
- package/dist/cjs/custom-theme-button/index.js +0 -3
- package/dist/cjs/custom-theme-button/theme.js +31 -38
- package/dist/cjs/entry-points/button-group.js +0 -2
- package/dist/cjs/entry-points/custom-theme-button.js +0 -4
- package/dist/cjs/entry-points/loading-button.js +0 -2
- package/dist/cjs/entry-points/standard-button.js +0 -3
- package/dist/cjs/index.js +0 -8
- package/dist/cjs/loading-button.js +4 -12
- package/dist/cjs/shared/block-events.js +0 -6
- package/dist/cjs/shared/button-base.js +48 -66
- package/dist/cjs/shared/colors.js +0 -5
- package/dist/cjs/shared/css.js +17 -28
- package/dist/cjs/shared/get-is-only-single-icon.js +2 -7
- package/dist/cjs/shared/loading-spinner.js +4 -15
- package/dist/cjs/version.json +1 -1
- package/dist/es2019/button-group.js +1 -3
- package/dist/es2019/button.js +7 -7
- package/dist/es2019/custom-theme-button/custom-theme-button.js +19 -25
- package/dist/es2019/custom-theme-button/theme.js +21 -16
- package/dist/es2019/index.js +3 -1
- package/dist/es2019/loading-button.js +2 -2
- package/dist/es2019/shared/block-events.js +0 -4
- package/dist/es2019/shared/button-base.js +19 -18
- package/dist/es2019/shared/css.js +22 -14
- package/dist/es2019/shared/get-is-only-single-icon.js +0 -3
- package/dist/es2019/shared/loading-spinner.js +0 -5
- package/dist/es2019/version.json +1 -1
- package/dist/esm/button-group.js +2 -4
- package/dist/esm/button.js +14 -18
- package/dist/esm/custom-theme-button/custom-theme-button.js +41 -61
- package/dist/esm/custom-theme-button/theme.js +31 -31
- package/dist/esm/index.js +3 -1
- package/dist/esm/loading-button.js +4 -5
- package/dist/esm/shared/block-events.js +0 -4
- package/dist/esm/shared/button-base.js +51 -51
- package/dist/esm/shared/css.js +17 -19
- package/dist/esm/shared/get-is-only-single-icon.js +2 -6
- package/dist/esm/shared/loading-spinner.js +4 -11
- package/dist/esm/version.json +1 -1
- package/package.json +2 -2
- package/report.api.md +13 -0
|
@@ -3,65 +3,54 @@ import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
|
3
3
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
4
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
5
5
|
var _excluded = ["appearance", "autoFocus", "isDisabled", "isSelected", "shouldFitContainer", "spacing", "isLoading", "onMouseEnter", "onMouseLeave", "onMouseDown", "onMouseUp", "onFocus", "onBlur", "theme"];
|
|
6
|
-
|
|
7
6
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
8
|
-
|
|
9
7
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
10
|
-
|
|
11
8
|
import React, { useCallback, useState } from 'react';
|
|
12
9
|
import GlobalTheme from '@atlaskit/theme/components';
|
|
13
10
|
import ButtonBase from '../shared/button-base';
|
|
14
11
|
import getIsOnlySingleIcon from '../shared/get-is-only-single-icon';
|
|
15
12
|
import LoadingSpinner from '../shared/loading-spinner';
|
|
16
13
|
import Theme, { defaultThemeFn, getSpecifiers } from './theme';
|
|
17
|
-
|
|
18
14
|
function getInteractionState(_ref) {
|
|
19
15
|
var _ref$isDisabled = _ref.isDisabled,
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
16
|
+
isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled,
|
|
17
|
+
_ref$isActive = _ref.isActive,
|
|
18
|
+
isActive = _ref$isActive === void 0 ? false : _ref$isActive,
|
|
19
|
+
_ref$isFocus = _ref.isFocus,
|
|
20
|
+
isFocus = _ref$isFocus === void 0 ? false : _ref$isFocus,
|
|
21
|
+
_ref$isHover = _ref.isHover,
|
|
22
|
+
isHover = _ref$isHover === void 0 ? false : _ref$isHover,
|
|
23
|
+
_ref$isSelected = _ref.isSelected,
|
|
24
|
+
isSelected = _ref$isSelected === void 0 ? false : _ref$isSelected,
|
|
25
|
+
_ref$isLoading = _ref.isLoading,
|
|
26
|
+
isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading;
|
|
32
27
|
if (isDisabled) {
|
|
33
28
|
return 'disabled';
|
|
34
29
|
}
|
|
35
|
-
|
|
36
30
|
if (isSelected && isFocus) {
|
|
37
31
|
return 'focusSelected';
|
|
38
32
|
}
|
|
39
|
-
|
|
40
33
|
if (isSelected) {
|
|
41
34
|
return 'selected';
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
|
|
35
|
+
}
|
|
36
|
+
// not allowing active or focus style changes while loading
|
|
45
37
|
if (!isLoading && isActive) {
|
|
46
38
|
return 'active';
|
|
47
39
|
}
|
|
48
|
-
|
|
49
40
|
if (!isLoading && isHover) {
|
|
50
41
|
return 'hover';
|
|
51
42
|
}
|
|
52
|
-
|
|
53
43
|
if (isFocus) {
|
|
54
44
|
return 'focus';
|
|
55
45
|
}
|
|
56
|
-
|
|
57
46
|
return 'default';
|
|
58
47
|
}
|
|
59
|
-
|
|
60
48
|
var initial = {
|
|
61
49
|
isHover: false,
|
|
62
50
|
isActive: false,
|
|
63
51
|
isFocus: false
|
|
64
52
|
};
|
|
53
|
+
|
|
65
54
|
/**
|
|
66
55
|
* __Custom theme button__
|
|
67
56
|
*
|
|
@@ -69,32 +58,30 @@ var initial = {
|
|
|
69
58
|
*
|
|
70
59
|
* - [Examples](https://atlassian.design/components/button/examples#custom-theme-button)
|
|
71
60
|
*/
|
|
72
|
-
|
|
73
61
|
var CustomThemeButton = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef(function CustomThemeButton(_ref2, ref) {
|
|
74
62
|
var _ref2$appearance = _ref2.appearance,
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
63
|
+
appearance = _ref2$appearance === void 0 ? 'default' : _ref2$appearance,
|
|
64
|
+
_ref2$autoFocus = _ref2.autoFocus,
|
|
65
|
+
autoFocus = _ref2$autoFocus === void 0 ? false : _ref2$autoFocus,
|
|
66
|
+
_ref2$isDisabled = _ref2.isDisabled,
|
|
67
|
+
isDisabled = _ref2$isDisabled === void 0 ? false : _ref2$isDisabled,
|
|
68
|
+
_ref2$isSelected = _ref2.isSelected,
|
|
69
|
+
isSelected = _ref2$isSelected === void 0 ? false : _ref2$isSelected,
|
|
70
|
+
_ref2$shouldFitContai = _ref2.shouldFitContainer,
|
|
71
|
+
shouldFitContainer = _ref2$shouldFitContai === void 0 ? false : _ref2$shouldFitContai,
|
|
72
|
+
_ref2$spacing = _ref2.spacing,
|
|
73
|
+
spacing = _ref2$spacing === void 0 ? 'default' : _ref2$spacing,
|
|
74
|
+
_ref2$isLoading = _ref2.isLoading,
|
|
75
|
+
isLoading = _ref2$isLoading === void 0 ? false : _ref2$isLoading,
|
|
76
|
+
providedOnMouseEnter = _ref2.onMouseEnter,
|
|
77
|
+
providedOnMouseLeave = _ref2.onMouseLeave,
|
|
78
|
+
providedOnMouseDown = _ref2.onMouseDown,
|
|
79
|
+
providedOnMouseUp = _ref2.onMouseUp,
|
|
80
|
+
providedOnFocus = _ref2.onFocus,
|
|
81
|
+
providedOnBlur = _ref2.onBlur,
|
|
82
|
+
_ref2$theme = _ref2.theme,
|
|
83
|
+
theme = _ref2$theme === void 0 ? defaultThemeFn : _ref2$theme,
|
|
84
|
+
rest = _objectWithoutProperties(_ref2, _excluded);
|
|
98
85
|
// TODO is there a nicer way to do this?
|
|
99
86
|
// Add default props back into object for spreading
|
|
100
87
|
var restProps = _objectSpread({
|
|
@@ -105,19 +92,16 @@ var CustomThemeButton = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef(f
|
|
|
105
92
|
shouldFitContainer: shouldFitContainer,
|
|
106
93
|
spacing: spacing
|
|
107
94
|
}, rest);
|
|
108
|
-
|
|
109
95
|
var _useState = useState(initial),
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
96
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
97
|
+
state = _useState2[0],
|
|
98
|
+
setState = _useState2[1];
|
|
114
99
|
var onMouseEnter = useCallback(function (event) {
|
|
115
100
|
setState(function (current) {
|
|
116
101
|
return _objectSpread(_objectSpread({}, current), {}, {
|
|
117
102
|
isHover: true
|
|
118
103
|
});
|
|
119
104
|
});
|
|
120
|
-
|
|
121
105
|
if (providedOnMouseEnter) {
|
|
122
106
|
providedOnMouseEnter(event);
|
|
123
107
|
}
|
|
@@ -129,7 +113,6 @@ var CustomThemeButton = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef(f
|
|
|
129
113
|
isActive: false
|
|
130
114
|
});
|
|
131
115
|
});
|
|
132
|
-
|
|
133
116
|
if (providedOnMouseLeave) {
|
|
134
117
|
providedOnMouseLeave(event);
|
|
135
118
|
}
|
|
@@ -140,7 +123,6 @@ var CustomThemeButton = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef(f
|
|
|
140
123
|
isActive: true
|
|
141
124
|
});
|
|
142
125
|
});
|
|
143
|
-
|
|
144
126
|
if (providedOnMouseDown) {
|
|
145
127
|
providedOnMouseDown(event);
|
|
146
128
|
}
|
|
@@ -151,7 +133,6 @@ var CustomThemeButton = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef(f
|
|
|
151
133
|
isActive: false
|
|
152
134
|
});
|
|
153
135
|
});
|
|
154
|
-
|
|
155
136
|
if (providedOnMouseUp) {
|
|
156
137
|
providedOnMouseUp(event);
|
|
157
138
|
}
|
|
@@ -162,7 +143,6 @@ var CustomThemeButton = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef(f
|
|
|
162
143
|
isFocus: true
|
|
163
144
|
});
|
|
164
145
|
});
|
|
165
|
-
|
|
166
146
|
if (providedOnFocus) {
|
|
167
147
|
providedOnFocus(event);
|
|
168
148
|
}
|
|
@@ -173,7 +153,6 @@ var CustomThemeButton = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef(f
|
|
|
173
153
|
isFocus: false
|
|
174
154
|
});
|
|
175
155
|
});
|
|
176
|
-
|
|
177
156
|
if (providedOnBlur) {
|
|
178
157
|
providedOnBlur(event);
|
|
179
158
|
}
|
|
@@ -206,7 +185,8 @@ var CustomThemeButton = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef(f
|
|
|
206
185
|
}));
|
|
207
186
|
});
|
|
208
187
|
}));
|
|
209
|
-
}));
|
|
188
|
+
}));
|
|
210
189
|
|
|
190
|
+
// Tools including enzyme rely on components having a display name
|
|
211
191
|
CustomThemeButton.displayName = 'CustomThemeButton';
|
|
212
192
|
export default CustomThemeButton;
|
|
@@ -1,9 +1,6 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
|
|
3
2
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
-
|
|
5
3
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
|
-
|
|
7
4
|
import { createTheme } from '@atlaskit/theme/components';
|
|
8
5
|
import { getCss } from '../shared/css';
|
|
9
6
|
var stateToSelectorMap = {
|
|
@@ -12,26 +9,27 @@ var stateToSelectorMap = {
|
|
|
12
9
|
hover: '&:hover',
|
|
13
10
|
active: '&:active',
|
|
14
11
|
disabled: '&[disabled]'
|
|
15
|
-
};
|
|
12
|
+
};
|
|
13
|
+
|
|
14
|
+
// Mapping the new clean css back to the legacy theme format.
|
|
16
15
|
// The legacy theme format has all styles at the top level (no nested selectors)
|
|
17
16
|
// and uses `getSpecifiers()` to apply the style to all pseudo states
|
|
18
|
-
|
|
19
17
|
export function getCustomCss(_ref) {
|
|
20
18
|
var _ref$appearance = _ref.appearance,
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
19
|
+
appearance = _ref$appearance === void 0 ? 'default' : _ref$appearance,
|
|
20
|
+
_ref$spacing = _ref.spacing,
|
|
21
|
+
spacing = _ref$spacing === void 0 ? 'default' : _ref$spacing,
|
|
22
|
+
_ref$mode = _ref.mode,
|
|
23
|
+
mode = _ref$mode === void 0 ? 'light' : _ref$mode,
|
|
24
|
+
_ref$isSelected = _ref.isSelected,
|
|
25
|
+
isSelected = _ref$isSelected === void 0 ? false : _ref$isSelected,
|
|
26
|
+
_ref$shouldFitContain = _ref.shouldFitContainer,
|
|
27
|
+
shouldFitContainer = _ref$shouldFitContain === void 0 ? false : _ref$shouldFitContain,
|
|
28
|
+
_ref$iconIsOnlyChild = _ref.iconIsOnlyChild,
|
|
29
|
+
iconIsOnlyChild = _ref$iconIsOnlyChild === void 0 ? false : _ref$iconIsOnlyChild,
|
|
30
|
+
_ref$isLoading = _ref.isLoading,
|
|
31
|
+
isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading,
|
|
32
|
+
state = _ref.state;
|
|
35
33
|
var result = getCss({
|
|
36
34
|
appearance: appearance,
|
|
37
35
|
spacing: spacing,
|
|
@@ -39,37 +37,38 @@ export function getCustomCss(_ref) {
|
|
|
39
37
|
isSelected: isSelected,
|
|
40
38
|
shouldFitContainer: shouldFitContainer,
|
|
41
39
|
isOnlySingleIcon: iconIsOnlyChild
|
|
42
|
-
});
|
|
43
|
-
// this is because we are not expressing that we can have two pseudo states at a time
|
|
40
|
+
});
|
|
44
41
|
|
|
45
|
-
|
|
42
|
+
// we need to disable the default browser focus styles always
|
|
43
|
+
// this is because we are not expressing that we can have two pseudo states at a time
|
|
44
|
+
result.outline = 'none';
|
|
46
45
|
|
|
46
|
+
// Pulling relevant styles up to the top level
|
|
47
47
|
var selector = stateToSelectorMap[state];
|
|
48
|
-
|
|
49
48
|
if (selector) {
|
|
50
49
|
result = _objectSpread(_objectSpread({}, result), result[selector]);
|
|
51
50
|
}
|
|
52
|
-
|
|
53
51
|
if (isLoading) {
|
|
54
52
|
result = _objectSpread(_objectSpread({}, result), result['&[data-has-overlay="true"]']);
|
|
55
|
-
}
|
|
56
|
-
|
|
53
|
+
}
|
|
57
54
|
|
|
55
|
+
// Delete all selectors and just keep root styles
|
|
58
56
|
Object.keys(result).forEach(function (key) {
|
|
59
57
|
// want to keep this one
|
|
60
58
|
if (key === '&::-moz-focus-inner') {
|
|
61
59
|
return;
|
|
62
|
-
}
|
|
63
|
-
|
|
60
|
+
}
|
|
64
61
|
|
|
62
|
+
// Not using .startsWith for ie11
|
|
65
63
|
if (key.indexOf('&') === 0) {
|
|
66
64
|
delete result[key];
|
|
67
65
|
}
|
|
68
66
|
});
|
|
69
67
|
return result;
|
|
70
|
-
}
|
|
71
|
-
// To do this we are overwriting all pseudo selectors
|
|
68
|
+
}
|
|
72
69
|
|
|
70
|
+
// This styling approach works by generating a 'style' and applying with maximum specificity
|
|
71
|
+
// To do this we are overwriting all pseudo selectors
|
|
73
72
|
export function getSpecifiers(styles) {
|
|
74
73
|
return {
|
|
75
74
|
'&, &:hover, &:active, &:focus, &:visited, &:disabled, &[disabled]': styles
|
|
@@ -86,6 +85,7 @@ var Theme = createTheme(function (themeProps) {
|
|
|
86
85
|
// that we are changing theme soon there is no point
|
|
87
86
|
spinnerStyles: {}
|
|
88
87
|
};
|
|
89
|
-
});
|
|
88
|
+
});
|
|
90
89
|
|
|
90
|
+
// eslint-disable-next-line @repo/internal/react/require-jsdoc
|
|
91
91
|
export default Theme;
|
package/dist/esm/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
1
|
// Ideally this file is not used directly. But rather, you go through the entry points
|
|
2
|
-
|
|
2
|
+
|
|
3
|
+
export {
|
|
4
|
+
// default export is Button
|
|
3
5
|
default } from './entry-points/standard-button';
|
|
4
6
|
export { default as LoadingButton } from './entry-points/loading-button';
|
|
5
7
|
export { default as CustomThemeButton, Theme } from './entry-points/custom-theme-button';
|
|
@@ -4,7 +4,6 @@ var _excluded = ["isLoading"];
|
|
|
4
4
|
import React from 'react';
|
|
5
5
|
import Button from './button';
|
|
6
6
|
import LoadingSpinner from './shared/loading-spinner';
|
|
7
|
-
|
|
8
7
|
/**
|
|
9
8
|
* __Loading button__
|
|
10
9
|
*
|
|
@@ -14,15 +13,15 @@ import LoadingSpinner from './shared/loading-spinner';
|
|
|
14
13
|
*/
|
|
15
14
|
var LoadingButton = /*#__PURE__*/React.forwardRef(function LoadingButton(_ref, ref) {
|
|
16
15
|
var _ref$isLoading = _ref.isLoading,
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
16
|
+
isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading,
|
|
17
|
+
rest = _objectWithoutProperties(_ref, _excluded);
|
|
20
18
|
// Button already has React.memo, so just leaning on that
|
|
21
19
|
return /*#__PURE__*/React.createElement(Button, _extends({}, rest, {
|
|
22
20
|
ref: ref,
|
|
23
21
|
overlay: isLoading ? /*#__PURE__*/React.createElement(LoadingSpinner, rest) : null
|
|
24
22
|
}));
|
|
25
|
-
});
|
|
23
|
+
});
|
|
26
24
|
|
|
25
|
+
// Tools including enzyme rely on components having a display name
|
|
27
26
|
LoadingButton.displayName = 'LoadingButton';
|
|
28
27
|
export default LoadingButton;
|
|
@@ -2,18 +2,14 @@ function abort(event) {
|
|
|
2
2
|
event.preventDefault();
|
|
3
3
|
event.stopPropagation();
|
|
4
4
|
}
|
|
5
|
-
|
|
6
5
|
var tabKeyCode = 9;
|
|
7
|
-
|
|
8
6
|
function onKey(event) {
|
|
9
7
|
// Allowing tab so that a user can move focus away
|
|
10
8
|
if (event.keyCode === tabKeyCode) {
|
|
11
9
|
return;
|
|
12
10
|
}
|
|
13
|
-
|
|
14
11
|
abort(event);
|
|
15
12
|
}
|
|
16
|
-
|
|
17
13
|
var block = {
|
|
18
14
|
onMouseDownCapture: abort,
|
|
19
15
|
onMouseUpCapture: abort,
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import _extends from "@babel/runtime/helpers/extends";
|
|
2
2
|
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
3
3
|
var _excluded = ["appearance", "buttonCss", "spacing", "autoFocus", "isDisabled", "shouldFitContainer", "isSelected", "iconBefore", "iconAfter", "children", "className", "href", "overlay", "tabIndex", "type", "onMouseDown", "onClick", "component", "testId", "interactionName", "analyticsContext"];
|
|
4
|
-
|
|
5
4
|
/** @jsx jsx */
|
|
6
5
|
import React, { useCallback, useContext, useEffect, useRef } from 'react';
|
|
7
6
|
import { css, jsx } from '@emotion/react';
|
|
@@ -12,11 +11,12 @@ import useAutoFocus from '@atlaskit/ds-lib/use-auto-focus';
|
|
|
12
11
|
import InteractionContext from '@atlaskit/interaction-context';
|
|
13
12
|
import { N500 } from '@atlaskit/theme/colors';
|
|
14
13
|
import blockEvents from './block-events';
|
|
15
|
-
import { getContentStyle, getFadingCss, getIconStyle, overlayCss } from './css';
|
|
14
|
+
import { getContentStyle, getFadingCss, getIconStyle, overlayCss } from './css';
|
|
15
|
+
|
|
16
|
+
// Disabled buttons will still publish events for nested elements in webkit.
|
|
16
17
|
// We are disabling pointer events on child elements so that
|
|
17
18
|
// the button will always be the target of events
|
|
18
19
|
// Note: firefox does not have this behaviour for child elements
|
|
19
|
-
|
|
20
20
|
var noPointerEventsOnChildrenCss = {
|
|
21
21
|
'> *': {
|
|
22
22
|
pointerEvents: 'none'
|
|
@@ -24,56 +24,54 @@ var noPointerEventsOnChildrenCss = {
|
|
|
24
24
|
};
|
|
25
25
|
export default /*#__PURE__*/React.forwardRef(function ButtonBase(props, ref) {
|
|
26
26
|
var _props$appearance = props.appearance,
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
27
|
+
appearance = _props$appearance === void 0 ? 'default' : _props$appearance,
|
|
28
|
+
buttonCss = props.buttonCss,
|
|
29
|
+
_props$spacing = props.spacing,
|
|
30
|
+
spacing = _props$spacing === void 0 ? 'default' : _props$spacing,
|
|
31
|
+
_props$autoFocus = props.autoFocus,
|
|
32
|
+
autoFocus = _props$autoFocus === void 0 ? false : _props$autoFocus,
|
|
33
|
+
_props$isDisabled = props.isDisabled,
|
|
34
|
+
isDisabled = _props$isDisabled === void 0 ? false : _props$isDisabled,
|
|
35
|
+
_props$shouldFitConta = props.shouldFitContainer,
|
|
36
|
+
shouldFitContainer = _props$shouldFitConta === void 0 ? false : _props$shouldFitConta,
|
|
37
|
+
_props$isSelected = props.isSelected,
|
|
38
|
+
isSelected = _props$isSelected === void 0 ? false : _props$isSelected,
|
|
39
|
+
iconBefore = props.iconBefore,
|
|
40
|
+
iconAfter = props.iconAfter,
|
|
41
|
+
children = props.children,
|
|
42
|
+
className = props.className,
|
|
43
|
+
href = props.href,
|
|
44
|
+
overlay = props.overlay,
|
|
45
|
+
_props$tabIndex = props.tabIndex,
|
|
46
|
+
tabIndex = _props$tabIndex === void 0 ? 0 : _props$tabIndex,
|
|
47
|
+
_props$type = props.type,
|
|
48
|
+
type = _props$type === void 0 ? !href ? 'button' : undefined : _props$type,
|
|
49
|
+
_props$onMouseDown = props.onMouseDown,
|
|
50
|
+
providedOnMouseDown = _props$onMouseDown === void 0 ? noop : _props$onMouseDown,
|
|
51
|
+
_props$onClick = props.onClick,
|
|
52
|
+
providedOnClick = _props$onClick === void 0 ? noop : _props$onClick,
|
|
53
|
+
_props$component = props.component,
|
|
54
|
+
Component = _props$component === void 0 ? href ? 'a' : 'button' : _props$component,
|
|
55
|
+
testId = props.testId,
|
|
56
|
+
interactionName = props.interactionName,
|
|
57
|
+
analyticsContext = props.analyticsContext,
|
|
58
|
+
rest = _objectWithoutProperties(props, _excluded);
|
|
60
59
|
var ourRef = useRef();
|
|
61
60
|
var setRef = useCallback(function (node) {
|
|
62
61
|
ourRef.current = node;
|
|
63
|
-
|
|
64
62
|
if (ref == null) {
|
|
65
63
|
return;
|
|
66
64
|
}
|
|
67
|
-
|
|
68
65
|
if (typeof ref === 'function') {
|
|
69
66
|
ref(node);
|
|
70
67
|
return;
|
|
71
|
-
}
|
|
72
|
-
|
|
68
|
+
}
|
|
73
69
|
|
|
70
|
+
// @ts-ignore
|
|
74
71
|
ref.current = node;
|
|
75
|
-
}, [ourRef, ref]);
|
|
72
|
+
}, [ourRef, ref]);
|
|
76
73
|
|
|
74
|
+
// Cross browser auto focusing is pretty broken, so we are doing it ourselves
|
|
77
75
|
useAutoFocus(ourRef, autoFocus);
|
|
78
76
|
var interactionContext = useContext(InteractionContext);
|
|
79
77
|
var handleClick = useCallback(function (e, analyticsEvent) {
|
|
@@ -85,36 +83,37 @@ export default /*#__PURE__*/React.forwardRef(function ButtonBase(props, ref) {
|
|
|
85
83
|
action: 'clicked',
|
|
86
84
|
componentName: 'button',
|
|
87
85
|
packageName: "@atlaskit/button",
|
|
88
|
-
packageVersion: "16.5.
|
|
86
|
+
packageVersion: "16.5.5",
|
|
89
87
|
analyticsData: analyticsContext
|
|
90
|
-
});
|
|
88
|
+
});
|
|
91
89
|
|
|
90
|
+
// Button currently calls preventDefault, which is not standard button behaviour
|
|
92
91
|
var onMouseDown = useCallback(function (event) {
|
|
93
92
|
event.preventDefault();
|
|
94
93
|
providedOnMouseDown(event);
|
|
95
|
-
}, [providedOnMouseDown]);
|
|
94
|
+
}, [providedOnMouseDown]);
|
|
96
95
|
|
|
96
|
+
// Lose focus when becoming disabled (standard button behaviour)
|
|
97
97
|
useEffect(function () {
|
|
98
98
|
var el = ourRef.current;
|
|
99
|
-
|
|
100
99
|
if (isDisabled && el && el === document.activeElement) {
|
|
101
100
|
el.blur();
|
|
102
101
|
}
|
|
103
|
-
}, [isDisabled]);
|
|
102
|
+
}, [isDisabled]);
|
|
104
103
|
|
|
104
|
+
// we are 'disabling' input with a button when there is an overlay
|
|
105
105
|
var hasOverlay = Boolean(overlay);
|
|
106
106
|
var fadeCss = css(getFadingCss({
|
|
107
107
|
hasOverlay: hasOverlay
|
|
108
108
|
}));
|
|
109
109
|
var isInteractive = !isDisabled && !hasOverlay;
|
|
110
|
+
|
|
110
111
|
/**
|
|
111
112
|
* HACK: Spinner needs to have different colours in the "new" tokens design compared to the old design.
|
|
112
113
|
* For now, while we support both, these styles reach into Spinner when a theme is set, applies the right color.
|
|
113
114
|
* Ticket to remove: https://product-fabric.atlassian.net/browse/DSP-2067
|
|
114
115
|
*/
|
|
115
|
-
|
|
116
116
|
var spinnerHackCss = {};
|
|
117
|
-
|
|
118
117
|
if (isSelected || isDisabled || appearance === 'warning') {
|
|
119
118
|
spinnerHackCss = {
|
|
120
119
|
'[data-theme] & svg': {
|
|
@@ -122,7 +121,6 @@ export default /*#__PURE__*/React.forwardRef(function ButtonBase(props, ref) {
|
|
|
122
121
|
}
|
|
123
122
|
};
|
|
124
123
|
}
|
|
125
|
-
|
|
126
124
|
return jsx(Component, _extends({}, rest, {
|
|
127
125
|
css: [buttonCss, isInteractive ? null : noPointerEventsOnChildrenCss],
|
|
128
126
|
className: className,
|
|
@@ -130,11 +128,13 @@ export default /*#__PURE__*/React.forwardRef(function ButtonBase(props, ref) {
|
|
|
130
128
|
onClick: onClick,
|
|
131
129
|
onMouseDown: onMouseDown,
|
|
132
130
|
disabled: isDisabled,
|
|
133
|
-
href: isInteractive ? href : undefined
|
|
131
|
+
href: isInteractive ? href : undefined
|
|
132
|
+
// using undefined so that the property doesn't exist when false
|
|
134
133
|
,
|
|
135
134
|
"data-has-overlay": hasOverlay ? true : undefined,
|
|
136
135
|
"data-testid": testId,
|
|
137
|
-
type: type
|
|
136
|
+
type: type
|
|
137
|
+
// Adding a tab index so element is always focusable, even when not a <button> or <a>
|
|
138
138
|
// Disabling focus via keyboard navigation when disabled
|
|
139
139
|
// as this is standard button behaviour
|
|
140
140
|
,
|
package/dist/esm/shared/css.js
CHANGED
|
@@ -1,15 +1,14 @@
|
|
|
1
1
|
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
-
|
|
3
2
|
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); enumerableOnly && (symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; })), keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
-
|
|
5
3
|
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = null != arguments[i] ? arguments[i] : {}; i % 2 ? ownKeys(Object(source), !0).forEach(function (key) { _defineProperty(target, key, source[key]); }) : Object.getOwnPropertyDescriptors ? Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)) : ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } return target; }
|
|
6
|
-
|
|
7
4
|
import { css } from '@emotion/react';
|
|
8
5
|
import { borderRadius as getBorderRadius, fontSize as getFontSize, gridSize as getGridSize } from '@atlaskit/theme/constants';
|
|
9
6
|
import colors from './colors';
|
|
10
7
|
var borderRadius = getBorderRadius();
|
|
11
8
|
var gridSize = getGridSize();
|
|
12
|
-
var fontSize = getFontSize();
|
|
9
|
+
var fontSize = getFontSize();
|
|
10
|
+
|
|
11
|
+
// ## Button layout
|
|
13
12
|
//
|
|
14
13
|
// /------------------------------------------------------------------------------------------------------------------\
|
|
15
14
|
// | → | ← | | → | ← | | → | ← | | → | ← |
|
|
@@ -21,7 +20,6 @@ var fontSize = getFontSize(); // ## Button layout
|
|
|
21
20
|
// ↑ ↑
|
|
22
21
|
// Margins don't collapse with inline-flex
|
|
23
22
|
//
|
|
24
|
-
|
|
25
23
|
var heights = {
|
|
26
24
|
default: "".concat(gridSize * 4 / fontSize, "em"),
|
|
27
25
|
// 32px
|
|
@@ -54,19 +52,17 @@ var innerMargin = {
|
|
|
54
52
|
content: "0 ".concat(gridSize / 4, "px"),
|
|
55
53
|
icon: "0 ".concat(gridSize / 4, "px")
|
|
56
54
|
};
|
|
57
|
-
|
|
58
55
|
function getColor(_ref) {
|
|
59
56
|
var group = _ref.group,
|
|
60
|
-
|
|
61
|
-
|
|
57
|
+
key = _ref.key,
|
|
58
|
+
mode = _ref.mode;
|
|
62
59
|
var rule = group[key] || group.default;
|
|
63
60
|
return rule[mode];
|
|
64
61
|
}
|
|
65
|
-
|
|
66
62
|
function getColors(_ref2) {
|
|
67
63
|
var appearance = _ref2.appearance,
|
|
68
|
-
|
|
69
|
-
|
|
64
|
+
key = _ref2.key,
|
|
65
|
+
mode = _ref2.mode;
|
|
70
66
|
return {
|
|
71
67
|
background: getColor({
|
|
72
68
|
group: colors.background[appearance],
|
|
@@ -81,14 +77,13 @@ function getColors(_ref2) {
|
|
|
81
77
|
}), " !important")
|
|
82
78
|
};
|
|
83
79
|
}
|
|
84
|
-
|
|
85
80
|
export function getCss(_ref3) {
|
|
86
81
|
var appearance = _ref3.appearance,
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
82
|
+
spacing = _ref3.spacing,
|
|
83
|
+
mode = _ref3.mode,
|
|
84
|
+
isSelected = _ref3.isSelected,
|
|
85
|
+
shouldFitContainer = _ref3.shouldFitContainer,
|
|
86
|
+
isOnlySingleIcon = _ref3.isOnlySingleIcon;
|
|
92
87
|
var baseColors = getColors({
|
|
93
88
|
appearance: appearance,
|
|
94
89
|
key: isSelected ? 'selected' : 'default',
|
|
@@ -125,6 +120,7 @@ export function getCss(_ref3) {
|
|
|
125
120
|
justifyContent: 'center',
|
|
126
121
|
// Note: we cannot disable pointer events when there is an overlay.
|
|
127
122
|
// That would be easy for styling, but it would start letting events through on disabled buttons
|
|
123
|
+
|
|
128
124
|
// Disabling visited styles (just using the base colors)
|
|
129
125
|
'&:visited': _objectSpread({}, baseColors),
|
|
130
126
|
'&:hover': _objectSpread(_objectSpread({}, getColors({
|
|
@@ -193,8 +189,9 @@ export function getCss(_ref3) {
|
|
|
193
189
|
padding: 0
|
|
194
190
|
}
|
|
195
191
|
});
|
|
196
|
-
}
|
|
192
|
+
}
|
|
197
193
|
|
|
194
|
+
// inline-flex child
|
|
198
195
|
export function getIconStyle(_ref4) {
|
|
199
196
|
var spacing = _ref4.spacing;
|
|
200
197
|
return css({
|
|
@@ -208,8 +205,9 @@ export function getIconStyle(_ref4) {
|
|
|
208
205
|
lineHeight: 0,
|
|
209
206
|
userSelect: 'none'
|
|
210
207
|
});
|
|
211
|
-
}
|
|
208
|
+
}
|
|
212
209
|
|
|
210
|
+
// inline-flex child
|
|
213
211
|
export function getContentStyle(_ref5) {
|
|
214
212
|
var spacing = _ref5.spacing;
|
|
215
213
|
return css({
|