@atlaskit/button 16.1.2
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 +1485 -0
- package/LICENSE +13 -0
- package/README.md +13 -0
- package/__perf__/button.tsx +19 -0
- package/__perf__/custom.tsx +19 -0
- package/__perf__/customised.tsx +11 -0
- package/__perf__/default.tsx +5 -0
- package/__perf__/loading.tsx +5 -0
- package/__perf__/utils/example-runner.tsx +48 -0
- package/__perf__/utils/interaction-tasks.tsx +98 -0
- package/button-group/package.json +7 -0
- package/codemods/15.0.0-lite-mode.ts +49 -0
- package/codemods/15.1.1-data-testid.ts +173 -0
- package/codemods/__tests__/15.0.0-lite-mode/optimistic.ts +646 -0
- package/codemods/__tests__/15.0.0-lite-mode/safe.ts +223 -0
- package/codemods/__tests__/15.0.0-lite-mode/shared.ts +257 -0
- package/codemods/__tests__/15.1.1-data-testid/rename-data-testid.ts +186 -0
- package/codemods/__tests__/_framework.ts +47 -0
- package/codemods/helpers/15.0.0-runner.ts +169 -0
- package/codemods/helpers/helpers-generic.ts +662 -0
- package/codemods/optimistic-15.0.0-lite-mode.ts +279 -0
- package/codemods/readme.md +1 -0
- package/custom-theme-button/package.json +7 -0
- package/dist/cjs/button-group.js +50 -0
- package/dist/cjs/button.js +104 -0
- package/dist/cjs/custom-theme-button/custom-theme-button-types.js +5 -0
- package/dist/cjs/custom-theme-button/custom-theme-button.js +229 -0
- package/dist/cjs/custom-theme-button/index.js +23 -0
- package/dist/cjs/custom-theme-button/theme.js +108 -0
- package/dist/cjs/entry-points/button-group.js +15 -0
- package/dist/cjs/entry-points/custom-theme-button.js +25 -0
- package/dist/cjs/entry-points/loading-button.js +15 -0
- package/dist/cjs/entry-points/standard-button.js +15 -0
- package/dist/cjs/entry-points/types.js +5 -0
- package/dist/cjs/index.js +51 -0
- package/dist/cjs/loading-button.js +34 -0
- package/dist/cjs/shared/block-events.js +44 -0
- package/dist/cjs/shared/button-base.js +158 -0
- package/dist/cjs/shared/colors.js +409 -0
- package/dist/cjs/shared/css.js +265 -0
- package/dist/cjs/shared/get-is-only-single-icon.js +26 -0
- package/dist/cjs/shared/loading-spinner.js +45 -0
- package/dist/cjs/types.js +5 -0
- package/dist/cjs/version.json +5 -0
- package/dist/es2019/button-group.js +36 -0
- package/dist/es2019/button.js +69 -0
- package/dist/es2019/custom-theme-button/custom-theme-button-types.js +1 -0
- package/dist/es2019/custom-theme-button/custom-theme-button.js +164 -0
- package/dist/es2019/custom-theme-button/index.js +2 -0
- package/dist/es2019/custom-theme-button/theme.js +81 -0
- package/dist/es2019/entry-points/button-group.js +1 -0
- package/dist/es2019/entry-points/custom-theme-button.js +1 -0
- package/dist/es2019/entry-points/loading-button.js +1 -0
- package/dist/es2019/entry-points/standard-button.js +1 -0
- package/dist/es2019/entry-points/types.js +1 -0
- package/dist/es2019/index.js +6 -0
- package/dist/es2019/loading-button.js +17 -0
- package/dist/es2019/shared/block-events.js +37 -0
- package/dist/es2019/shared/button-base.js +127 -0
- package/dist/es2019/shared/colors.js +393 -0
- package/dist/es2019/shared/css.js +249 -0
- package/dist/es2019/shared/get-is-only-single-icon.js +19 -0
- package/dist/es2019/shared/loading-spinner.js +33 -0
- package/dist/es2019/types.js +1 -0
- package/dist/es2019/version.json +5 -0
- package/dist/esm/button-group.js +35 -0
- package/dist/esm/button.js +79 -0
- package/dist/esm/custom-theme-button/custom-theme-button-types.js +1 -0
- package/dist/esm/custom-theme-button/custom-theme-button.js +203 -0
- package/dist/esm/custom-theme-button/index.js +2 -0
- package/dist/esm/custom-theme-button/theme.js +90 -0
- package/dist/esm/entry-points/button-group.js +1 -0
- package/dist/esm/entry-points/custom-theme-button.js +1 -0
- package/dist/esm/entry-points/loading-button.js +1 -0
- package/dist/esm/entry-points/standard-button.js +1 -0
- package/dist/esm/entry-points/types.js +1 -0
- package/dist/esm/index.js +6 -0
- package/dist/esm/loading-button.js +19 -0
- package/dist/esm/shared/block-events.js +36 -0
- package/dist/esm/shared/button-base.js +135 -0
- package/dist/esm/shared/colors.js +393 -0
- package/dist/esm/shared/css.js +245 -0
- package/dist/esm/shared/get-is-only-single-icon.js +19 -0
- package/dist/esm/shared/loading-spinner.js +35 -0
- package/dist/esm/types.js +1 -0
- package/dist/esm/version.json +5 -0
- package/dist/types/button-group.d.ts +18 -0
- package/dist/types/button.d.ts +8 -0
- package/dist/types/custom-theme-button/custom-theme-button-types.d.ts +21 -0
- package/dist/types/custom-theme-button/custom-theme-button.d.ts +6 -0
- package/dist/types/custom-theme-button/index.d.ts +2 -0
- package/dist/types/custom-theme-button/theme.d.ts +21 -0
- package/dist/types/entry-points/button-group.d.ts +1 -0
- package/dist/types/entry-points/custom-theme-button.d.ts +2 -0
- package/dist/types/entry-points/loading-button.d.ts +2 -0
- package/dist/types/entry-points/standard-button.d.ts +2 -0
- package/dist/types/entry-points/types.d.ts +4 -0
- package/dist/types/index.d.ts +8 -0
- package/dist/types/loading-button.d.ts +11 -0
- package/dist/types/shared/block-events.d.ts +3 -0
- package/dist/types/shared/button-base.d.ts +10 -0
- package/dist/types/shared/colors.d.ts +31 -0
- package/dist/types/shared/css.d.ts +22 -0
- package/dist/types/shared/get-is-only-single-icon.d.ts +2 -0
- package/dist/types/shared/loading-spinner.d.ts +4 -0
- package/dist/types/types.d.ts +51 -0
- package/extract-react-types/custom-theme-button-props.tsx +7 -0
- package/extract-react-types/loading-button-props.tsx +5 -0
- package/extract-react-types/shared-props.tsx +5 -0
- package/loading-button/package.json +7 -0
- package/package.json +83 -0
- package/standard-button/package.json +7 -0
- package/types/package.json +7 -0
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
export default function getIsOnlySingleIcon({
|
|
2
|
+
children,
|
|
3
|
+
iconBefore,
|
|
4
|
+
iconAfter
|
|
5
|
+
}) {
|
|
6
|
+
if (children) {
|
|
7
|
+
return false;
|
|
8
|
+
}
|
|
9
|
+
|
|
10
|
+
if (iconBefore && !iconAfter) {
|
|
11
|
+
return true;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
if (!iconBefore && iconAfter) {
|
|
15
|
+
return true;
|
|
16
|
+
}
|
|
17
|
+
|
|
18
|
+
return false;
|
|
19
|
+
}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import React from 'react';
|
|
2
|
+
import Spinner from '@atlaskit/spinner';
|
|
3
|
+
|
|
4
|
+
function getSpinnerAppearance({
|
|
5
|
+
appearance,
|
|
6
|
+
isDisabled,
|
|
7
|
+
isSelected
|
|
8
|
+
}) {
|
|
9
|
+
if (isDisabled) {
|
|
10
|
+
return 'inherit';
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
if (isSelected) {
|
|
14
|
+
return 'invert';
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (appearance === 'primary' || appearance === 'danger') {
|
|
18
|
+
return 'invert';
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
return 'inherit';
|
|
22
|
+
}
|
|
23
|
+
|
|
24
|
+
export default function LoadingSpinner({
|
|
25
|
+
spacing = 'default',
|
|
26
|
+
...rest
|
|
27
|
+
}) {
|
|
28
|
+
const size = spacing === 'default' ? 'medium' : 'small';
|
|
29
|
+
return /*#__PURE__*/React.createElement(Spinner, {
|
|
30
|
+
size: size,
|
|
31
|
+
appearance: getSpinnerAppearance(rest)
|
|
32
|
+
});
|
|
33
|
+
}
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { jsx } from '@emotion/core';
|
|
4
|
+
import { gridSize } from '@atlaskit/theme/constants';
|
|
5
|
+
export var groupItemStyles = {
|
|
6
|
+
flex: '1 0 auto',
|
|
7
|
+
display: 'flex',
|
|
8
|
+
|
|
9
|
+
/* margins don't flip when the layout uses dir="rtl", whereas pseudos do */
|
|
10
|
+
'& + &::before': {
|
|
11
|
+
content: "''",
|
|
12
|
+
display: 'inline-block',
|
|
13
|
+
width: "".concat(gridSize() / 2, "px")
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
export default function ButtonGroup(_ref) {
|
|
17
|
+
var appearance = _ref.appearance,
|
|
18
|
+
children = _ref.children;
|
|
19
|
+
return jsx("div", {
|
|
20
|
+
css: {
|
|
21
|
+
display: 'inline-flex'
|
|
22
|
+
}
|
|
23
|
+
}, React.Children.map(children, function (child, idx) {
|
|
24
|
+
if (!child) {
|
|
25
|
+
return null;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
return jsx("div", {
|
|
29
|
+
key: idx,
|
|
30
|
+
css: groupItemStyles
|
|
31
|
+
}, appearance ? /*#__PURE__*/React.cloneElement(child, {
|
|
32
|
+
appearance: appearance
|
|
33
|
+
}) : child);
|
|
34
|
+
}));
|
|
35
|
+
}
|
|
@@ -0,0 +1,79 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
4
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
5
|
+
import GlobalTheme from '@atlaskit/theme/components';
|
|
6
|
+
import ButtonBase from './shared/button-base';
|
|
7
|
+
import { getCss } from './shared/css';
|
|
8
|
+
import getIsOnlySingleIcon from './shared/get-is-only-single-icon';
|
|
9
|
+
|
|
10
|
+
function noop() {}
|
|
11
|
+
|
|
12
|
+
var isFirefox = typeof navigator !== 'undefined' && navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
|
|
13
|
+
var ButtonWithMode = /*#__PURE__*/React.forwardRef(function ButtonWithMode(_ref, ref) {
|
|
14
|
+
var mode = _ref.mode,
|
|
15
|
+
_ref$onMouseDown = _ref.onMouseDown,
|
|
16
|
+
providedOnMouseDown = _ref$onMouseDown === void 0 ? noop : _ref$onMouseDown,
|
|
17
|
+
_ref$onMouseUp = _ref.onMouseUp,
|
|
18
|
+
providedOnMouseUp = _ref$onMouseUp === void 0 ? noop : _ref$onMouseUp,
|
|
19
|
+
rest = _objectWithoutProperties(_ref, ["mode", "onMouseDown", "onMouseUp"]);
|
|
20
|
+
|
|
21
|
+
var appearance = rest.appearance || 'default';
|
|
22
|
+
var spacing = rest.spacing || 'default';
|
|
23
|
+
var shouldFitContainer = Boolean(rest.shouldFitContainer);
|
|
24
|
+
var isSelected = Boolean(rest.isSelected);
|
|
25
|
+
var isOnlySingleIcon = getIsOnlySingleIcon(rest);
|
|
26
|
+
|
|
27
|
+
var _useState = useState(false),
|
|
28
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
29
|
+
isActive = _useState2[0],
|
|
30
|
+
setIsActive = _useState2[1]; // Wrap onMouseDown / onMouseUp to manually trigger active state
|
|
31
|
+
// in Firefox
|
|
32
|
+
|
|
33
|
+
|
|
34
|
+
var onMouseDown = useCallback(function (event) {
|
|
35
|
+
providedOnMouseDown(event);
|
|
36
|
+
|
|
37
|
+
if (isFirefox) {
|
|
38
|
+
setIsActive(true);
|
|
39
|
+
}
|
|
40
|
+
}, [providedOnMouseDown, setIsActive]);
|
|
41
|
+
var onMouseUp = useCallback(function (event) {
|
|
42
|
+
providedOnMouseUp(event);
|
|
43
|
+
|
|
44
|
+
if (isFirefox) {
|
|
45
|
+
setIsActive(false);
|
|
46
|
+
}
|
|
47
|
+
}, [providedOnMouseUp, setIsActive]);
|
|
48
|
+
var buttonCss = useMemo(function () {
|
|
49
|
+
return getCss({
|
|
50
|
+
appearance: appearance,
|
|
51
|
+
spacing: spacing,
|
|
52
|
+
mode: mode,
|
|
53
|
+
isSelected: isSelected,
|
|
54
|
+
shouldFitContainer: shouldFitContainer,
|
|
55
|
+
isOnlySingleIcon: isOnlySingleIcon
|
|
56
|
+
});
|
|
57
|
+
}, [appearance, spacing, mode, isSelected, shouldFitContainer, isOnlySingleIcon]);
|
|
58
|
+
return /*#__PURE__*/React.createElement(ButtonBase, _extends({}, rest, {
|
|
59
|
+
ref: ref,
|
|
60
|
+
buttonCss: buttonCss // Due to how click events are set, we need to set active styles
|
|
61
|
+
// manually in Firefox and wrap onMouseDown/onMouseUp
|
|
62
|
+
,
|
|
63
|
+
"data-firefox-is-active": isActive ? true : undefined,
|
|
64
|
+
onMouseDown: onMouseDown,
|
|
65
|
+
onMouseUp: onMouseUp
|
|
66
|
+
}));
|
|
67
|
+
});
|
|
68
|
+
var Button = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef(function Button(props, ref) {
|
|
69
|
+
return /*#__PURE__*/React.createElement(GlobalTheme.Consumer, null, function (_ref2) {
|
|
70
|
+
var mode = _ref2.mode;
|
|
71
|
+
return /*#__PURE__*/React.createElement(ButtonWithMode, _extends({}, props, {
|
|
72
|
+
ref: ref,
|
|
73
|
+
mode: mode
|
|
74
|
+
}));
|
|
75
|
+
});
|
|
76
|
+
})); // Tools including enzyme rely on components having a display name
|
|
77
|
+
|
|
78
|
+
Button.displayName = 'Button';
|
|
79
|
+
export default Button;
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export {};
|
|
@@ -0,0 +1,203 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import _slicedToArray from "@babel/runtime/helpers/slicedToArray";
|
|
3
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
4
|
+
import _objectWithoutProperties from "@babel/runtime/helpers/objectWithoutProperties";
|
|
5
|
+
|
|
6
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
7
|
+
|
|
8
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
9
|
+
|
|
10
|
+
import React, { useCallback, useState } from 'react';
|
|
11
|
+
import GlobalTheme from '@atlaskit/theme/components';
|
|
12
|
+
import ButtonBase from '../shared/button-base';
|
|
13
|
+
import getIsOnlySingleIcon from '../shared/get-is-only-single-icon';
|
|
14
|
+
import LoadingSpinner from '../shared/loading-spinner';
|
|
15
|
+
import Theme, { defaultThemeFn, getSpecifiers } from './theme';
|
|
16
|
+
|
|
17
|
+
function getInteractionState(_ref) {
|
|
18
|
+
var _ref$isDisabled = _ref.isDisabled,
|
|
19
|
+
isDisabled = _ref$isDisabled === void 0 ? false : _ref$isDisabled,
|
|
20
|
+
_ref$isActive = _ref.isActive,
|
|
21
|
+
isActive = _ref$isActive === void 0 ? false : _ref$isActive,
|
|
22
|
+
_ref$isFocus = _ref.isFocus,
|
|
23
|
+
isFocus = _ref$isFocus === void 0 ? false : _ref$isFocus,
|
|
24
|
+
_ref$isHover = _ref.isHover,
|
|
25
|
+
isHover = _ref$isHover === void 0 ? false : _ref$isHover,
|
|
26
|
+
_ref$isSelected = _ref.isSelected,
|
|
27
|
+
isSelected = _ref$isSelected === void 0 ? false : _ref$isSelected,
|
|
28
|
+
_ref$isLoading = _ref.isLoading,
|
|
29
|
+
isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading;
|
|
30
|
+
|
|
31
|
+
if (isDisabled) {
|
|
32
|
+
return 'disabled';
|
|
33
|
+
}
|
|
34
|
+
|
|
35
|
+
if (isSelected && isFocus) {
|
|
36
|
+
return 'focusSelected';
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
if (isSelected) {
|
|
40
|
+
return 'selected';
|
|
41
|
+
} // not allowing active or focus style changes while loading
|
|
42
|
+
|
|
43
|
+
|
|
44
|
+
if (!isLoading && isActive) {
|
|
45
|
+
return 'active';
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
if (!isLoading && isHover) {
|
|
49
|
+
return 'hover';
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
if (isFocus) {
|
|
53
|
+
return 'focus';
|
|
54
|
+
}
|
|
55
|
+
|
|
56
|
+
return 'default';
|
|
57
|
+
}
|
|
58
|
+
|
|
59
|
+
var initial = {
|
|
60
|
+
isHover: false,
|
|
61
|
+
isActive: false,
|
|
62
|
+
isFocus: false
|
|
63
|
+
};
|
|
64
|
+
var CustomThemeButton = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef(function CustomThemeButton(_ref2, ref) {
|
|
65
|
+
var _ref2$appearance = _ref2.appearance,
|
|
66
|
+
appearance = _ref2$appearance === void 0 ? 'default' : _ref2$appearance,
|
|
67
|
+
_ref2$autoFocus = _ref2.autoFocus,
|
|
68
|
+
autoFocus = _ref2$autoFocus === void 0 ? false : _ref2$autoFocus,
|
|
69
|
+
_ref2$isDisabled = _ref2.isDisabled,
|
|
70
|
+
isDisabled = _ref2$isDisabled === void 0 ? false : _ref2$isDisabled,
|
|
71
|
+
_ref2$isSelected = _ref2.isSelected,
|
|
72
|
+
isSelected = _ref2$isSelected === void 0 ? false : _ref2$isSelected,
|
|
73
|
+
_ref2$shouldFitContai = _ref2.shouldFitContainer,
|
|
74
|
+
shouldFitContainer = _ref2$shouldFitContai === void 0 ? false : _ref2$shouldFitContai,
|
|
75
|
+
_ref2$spacing = _ref2.spacing,
|
|
76
|
+
spacing = _ref2$spacing === void 0 ? 'default' : _ref2$spacing,
|
|
77
|
+
_ref2$isLoading = _ref2.isLoading,
|
|
78
|
+
isLoading = _ref2$isLoading === void 0 ? false : _ref2$isLoading,
|
|
79
|
+
providedOnMouseEnter = _ref2.onMouseEnter,
|
|
80
|
+
providedOnMouseLeave = _ref2.onMouseLeave,
|
|
81
|
+
providedOnMouseDown = _ref2.onMouseDown,
|
|
82
|
+
providedOnMouseUp = _ref2.onMouseUp,
|
|
83
|
+
providedOnFocus = _ref2.onFocus,
|
|
84
|
+
providedOnBlur = _ref2.onBlur,
|
|
85
|
+
_ref2$theme = _ref2.theme,
|
|
86
|
+
theme = _ref2$theme === void 0 ? defaultThemeFn : _ref2$theme,
|
|
87
|
+
rest = _objectWithoutProperties(_ref2, ["appearance", "autoFocus", "isDisabled", "isSelected", "shouldFitContainer", "spacing", "isLoading", "onMouseEnter", "onMouseLeave", "onMouseDown", "onMouseUp", "onFocus", "onBlur", "theme"]);
|
|
88
|
+
|
|
89
|
+
// TODO is there a nicer way to do this?
|
|
90
|
+
// Add default props back into object for spreading
|
|
91
|
+
var restProps = _objectSpread({
|
|
92
|
+
appearance: appearance,
|
|
93
|
+
autoFocus: autoFocus,
|
|
94
|
+
isDisabled: isDisabled,
|
|
95
|
+
isSelected: isSelected,
|
|
96
|
+
shouldFitContainer: shouldFitContainer,
|
|
97
|
+
spacing: spacing
|
|
98
|
+
}, rest);
|
|
99
|
+
|
|
100
|
+
var _useState = useState(initial),
|
|
101
|
+
_useState2 = _slicedToArray(_useState, 2),
|
|
102
|
+
state = _useState2[0],
|
|
103
|
+
setState = _useState2[1];
|
|
104
|
+
|
|
105
|
+
var onMouseEnter = useCallback(function (event) {
|
|
106
|
+
setState(function (current) {
|
|
107
|
+
return _objectSpread(_objectSpread({}, current), {}, {
|
|
108
|
+
isHover: true
|
|
109
|
+
});
|
|
110
|
+
});
|
|
111
|
+
|
|
112
|
+
if (providedOnMouseEnter) {
|
|
113
|
+
providedOnMouseEnter(event);
|
|
114
|
+
}
|
|
115
|
+
}, [providedOnMouseEnter]);
|
|
116
|
+
var onMouseLeave = useCallback(function (event) {
|
|
117
|
+
setState(function (current) {
|
|
118
|
+
return _objectSpread(_objectSpread({}, current), {}, {
|
|
119
|
+
isHover: false,
|
|
120
|
+
isActive: false
|
|
121
|
+
});
|
|
122
|
+
});
|
|
123
|
+
|
|
124
|
+
if (providedOnMouseLeave) {
|
|
125
|
+
providedOnMouseLeave(event);
|
|
126
|
+
}
|
|
127
|
+
}, [providedOnMouseLeave]);
|
|
128
|
+
var onMouseDown = useCallback(function (event) {
|
|
129
|
+
setState(function (current) {
|
|
130
|
+
return _objectSpread(_objectSpread({}, current), {}, {
|
|
131
|
+
isActive: true
|
|
132
|
+
});
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
if (providedOnMouseDown) {
|
|
136
|
+
providedOnMouseDown(event);
|
|
137
|
+
}
|
|
138
|
+
}, [providedOnMouseDown]);
|
|
139
|
+
var onMouseUp = useCallback(function (event) {
|
|
140
|
+
setState(function (current) {
|
|
141
|
+
return _objectSpread(_objectSpread({}, current), {}, {
|
|
142
|
+
isActive: false
|
|
143
|
+
});
|
|
144
|
+
});
|
|
145
|
+
|
|
146
|
+
if (providedOnMouseUp) {
|
|
147
|
+
providedOnMouseUp(event);
|
|
148
|
+
}
|
|
149
|
+
}, [providedOnMouseUp]);
|
|
150
|
+
var onFocus = useCallback(function (event) {
|
|
151
|
+
setState(function (current) {
|
|
152
|
+
return _objectSpread(_objectSpread({}, current), {}, {
|
|
153
|
+
isFocus: true
|
|
154
|
+
});
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
if (providedOnFocus) {
|
|
158
|
+
providedOnFocus(event);
|
|
159
|
+
}
|
|
160
|
+
}, [providedOnFocus]);
|
|
161
|
+
var onBlur = useCallback(function (event) {
|
|
162
|
+
setState(function (current) {
|
|
163
|
+
return _objectSpread(_objectSpread({}, current), {}, {
|
|
164
|
+
isFocus: false
|
|
165
|
+
});
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
if (providedOnBlur) {
|
|
169
|
+
providedOnBlur(event);
|
|
170
|
+
}
|
|
171
|
+
}, [providedOnBlur]);
|
|
172
|
+
return /*#__PURE__*/React.createElement(Theme.Provider, {
|
|
173
|
+
value: theme
|
|
174
|
+
}, /*#__PURE__*/React.createElement(GlobalTheme.Consumer, null, function (_ref3) {
|
|
175
|
+
var mode = _ref3.mode;
|
|
176
|
+
return /*#__PURE__*/React.createElement(Theme.Consumer, _extends({
|
|
177
|
+
mode: mode,
|
|
178
|
+
state: getInteractionState(_objectSpread(_objectSpread({}, state), {}, {
|
|
179
|
+
isLoading: isLoading,
|
|
180
|
+
isSelected: restProps.isSelected,
|
|
181
|
+
isDisabled: restProps.isDisabled
|
|
182
|
+
})),
|
|
183
|
+
iconIsOnlyChild: getIsOnlySingleIcon(restProps),
|
|
184
|
+
isLoading: isLoading
|
|
185
|
+
}, restProps), function (_ref4) {
|
|
186
|
+
var buttonStyles = _ref4.buttonStyles;
|
|
187
|
+
return /*#__PURE__*/React.createElement(ButtonBase, _extends({}, restProps, {
|
|
188
|
+
ref: ref,
|
|
189
|
+
overlay: isLoading ? /*#__PURE__*/React.createElement(LoadingSpinner, restProps) : null,
|
|
190
|
+
onMouseEnter: onMouseEnter,
|
|
191
|
+
onMouseLeave: onMouseLeave,
|
|
192
|
+
onMouseDown: onMouseDown,
|
|
193
|
+
onMouseUp: onMouseUp,
|
|
194
|
+
onFocus: onFocus,
|
|
195
|
+
onBlur: onBlur,
|
|
196
|
+
buttonCss: getSpecifiers(buttonStyles)
|
|
197
|
+
}));
|
|
198
|
+
});
|
|
199
|
+
}));
|
|
200
|
+
})); // Tools including enzyme rely on components having a display name
|
|
201
|
+
|
|
202
|
+
CustomThemeButton.displayName = 'CustomThemeButton';
|
|
203
|
+
export default CustomThemeButton;
|
|
@@ -0,0 +1,90 @@
|
|
|
1
|
+
import _defineProperty from "@babel/runtime/helpers/defineProperty";
|
|
2
|
+
|
|
3
|
+
function ownKeys(object, enumerableOnly) { var keys = Object.keys(object); if (Object.getOwnPropertySymbols) { var symbols = Object.getOwnPropertySymbols(object); if (enumerableOnly) { symbols = symbols.filter(function (sym) { return Object.getOwnPropertyDescriptor(object, sym).enumerable; }); } keys.push.apply(keys, symbols); } return keys; }
|
|
4
|
+
|
|
5
|
+
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
6
|
+
|
|
7
|
+
import { createTheme } from '@atlaskit/theme/components';
|
|
8
|
+
import { getCss } from '../shared/css';
|
|
9
|
+
var stateToSelectorMap = {
|
|
10
|
+
focus: '&:focus',
|
|
11
|
+
focusSelected: '&:focus',
|
|
12
|
+
hover: '&:hover',
|
|
13
|
+
active: '&:active',
|
|
14
|
+
disabled: '&[disabled]'
|
|
15
|
+
}; // Mapping the new clean css back to the legacy theme format.
|
|
16
|
+
// The legacy theme format has all styles at the top level (no nested selectors)
|
|
17
|
+
// and uses `getSpecifiers()` to apply the style to all pseudo states
|
|
18
|
+
|
|
19
|
+
export function getCustomCss(_ref) {
|
|
20
|
+
var _ref$appearance = _ref.appearance,
|
|
21
|
+
appearance = _ref$appearance === void 0 ? 'default' : _ref$appearance,
|
|
22
|
+
_ref$spacing = _ref.spacing,
|
|
23
|
+
spacing = _ref$spacing === void 0 ? 'default' : _ref$spacing,
|
|
24
|
+
_ref$mode = _ref.mode,
|
|
25
|
+
mode = _ref$mode === void 0 ? 'light' : _ref$mode,
|
|
26
|
+
_ref$isSelected = _ref.isSelected,
|
|
27
|
+
isSelected = _ref$isSelected === void 0 ? false : _ref$isSelected,
|
|
28
|
+
_ref$shouldFitContain = _ref.shouldFitContainer,
|
|
29
|
+
shouldFitContainer = _ref$shouldFitContain === void 0 ? false : _ref$shouldFitContain,
|
|
30
|
+
_ref$iconIsOnlyChild = _ref.iconIsOnlyChild,
|
|
31
|
+
iconIsOnlyChild = _ref$iconIsOnlyChild === void 0 ? false : _ref$iconIsOnlyChild,
|
|
32
|
+
_ref$isLoading = _ref.isLoading,
|
|
33
|
+
isLoading = _ref$isLoading === void 0 ? false : _ref$isLoading,
|
|
34
|
+
state = _ref.state;
|
|
35
|
+
var result = getCss({
|
|
36
|
+
appearance: appearance,
|
|
37
|
+
spacing: spacing,
|
|
38
|
+
mode: mode,
|
|
39
|
+
isSelected: isSelected,
|
|
40
|
+
shouldFitContainer: shouldFitContainer,
|
|
41
|
+
isOnlySingleIcon: iconIsOnlyChild
|
|
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
|
+
|
|
45
|
+
result.outline = 'none'; // Pulling relevant styles up to the top level
|
|
46
|
+
|
|
47
|
+
var selector = stateToSelectorMap[state];
|
|
48
|
+
|
|
49
|
+
if (selector) {
|
|
50
|
+
result = _objectSpread(_objectSpread({}, result), result[selector]);
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
if (isLoading) {
|
|
54
|
+
result = _objectSpread(_objectSpread({}, result), result['&[data-has-overlay="true"]']);
|
|
55
|
+
} // Delete all selectors and just keep root styles
|
|
56
|
+
|
|
57
|
+
|
|
58
|
+
Object.keys(result).forEach(function (key) {
|
|
59
|
+
// want to keep this one
|
|
60
|
+
if (key === '&::-moz-focus-inner') {
|
|
61
|
+
return;
|
|
62
|
+
} // Not using .startsWith for ie11
|
|
63
|
+
|
|
64
|
+
|
|
65
|
+
if (key.indexOf('&') === 0) {
|
|
66
|
+
delete result[key];
|
|
67
|
+
}
|
|
68
|
+
});
|
|
69
|
+
return result;
|
|
70
|
+
} // This styling approach works by generating a 'style' and applying with maximum specificity
|
|
71
|
+
// To do this we are overwriting all pseudo selectors
|
|
72
|
+
|
|
73
|
+
export function getSpecifiers(styles) {
|
|
74
|
+
return {
|
|
75
|
+
'&, &:hover, &:active, &:focus, &:visited, &:disabled, &[disabled]': styles
|
|
76
|
+
};
|
|
77
|
+
}
|
|
78
|
+
export function defaultThemeFn(current, values) {
|
|
79
|
+
return current(values);
|
|
80
|
+
}
|
|
81
|
+
var Theme = createTheme(function (themeProps) {
|
|
82
|
+
return {
|
|
83
|
+
buttonStyles: getCustomCss(themeProps),
|
|
84
|
+
// No styles being applied directly to spinner by default
|
|
85
|
+
// Keeping this for legacy compat. We could remove it, but given
|
|
86
|
+
// that we are changing theme soon there is no point
|
|
87
|
+
spinnerStyles: {}
|
|
88
|
+
};
|
|
89
|
+
});
|
|
90
|
+
export default Theme;
|