@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,279 @@
|
|
|
1
|
+
import { NodePath } from 'ast-types/lib/node-path';
|
|
2
|
+
import core, { API, FileInfo, JSXElement, Node, Options } from 'jscodeshift';
|
|
3
|
+
import { Collection } from 'jscodeshift/src/Collection';
|
|
4
|
+
|
|
5
|
+
import { convertButtonType, transformButton } from './helpers/15.0.0-runner';
|
|
6
|
+
import {
|
|
7
|
+
addCommentBefore,
|
|
8
|
+
addCommentToStartOfFile,
|
|
9
|
+
addToImport,
|
|
10
|
+
changeImportFor,
|
|
11
|
+
getDefaultSpecifierName,
|
|
12
|
+
getSafeImportName,
|
|
13
|
+
isOnlyUsingNameForJSX,
|
|
14
|
+
isUsingProp,
|
|
15
|
+
isUsingSupportedSpread,
|
|
16
|
+
Nullable,
|
|
17
|
+
tryCreateImport,
|
|
18
|
+
} from './helpers/helpers-generic';
|
|
19
|
+
|
|
20
|
+
function changeUsage({
|
|
21
|
+
j,
|
|
22
|
+
base,
|
|
23
|
+
packageName,
|
|
24
|
+
}: {
|
|
25
|
+
j: core.JSCodeshift;
|
|
26
|
+
base: Collection<Node>;
|
|
27
|
+
packageName: string;
|
|
28
|
+
}): void {
|
|
29
|
+
// 1. Are we using the default export?
|
|
30
|
+
// If not: we can exit early!
|
|
31
|
+
const defaultName: Nullable<string> = getDefaultSpecifierName({
|
|
32
|
+
j,
|
|
33
|
+
base,
|
|
34
|
+
packageName,
|
|
35
|
+
});
|
|
36
|
+
if (defaultName == null) {
|
|
37
|
+
return;
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
// Only supporting cases where default identifier is only used in JSX
|
|
41
|
+
const isSupported: boolean = isOnlyUsingNameForJSX({
|
|
42
|
+
j,
|
|
43
|
+
base,
|
|
44
|
+
name: defaultName,
|
|
45
|
+
});
|
|
46
|
+
|
|
47
|
+
if (!isSupported) {
|
|
48
|
+
tryCreateImport({
|
|
49
|
+
j,
|
|
50
|
+
base,
|
|
51
|
+
relativeToPackage: '@atlaskit/button',
|
|
52
|
+
packageName: '@atlaskit/button/standard-button',
|
|
53
|
+
});
|
|
54
|
+
addToImport({
|
|
55
|
+
j,
|
|
56
|
+
base,
|
|
57
|
+
// we can safely use the default name, because it was being used before
|
|
58
|
+
importSpecifier: j.importDefaultSpecifier(j.identifier(defaultName)),
|
|
59
|
+
packageName: '@atlaskit/button/standard-button',
|
|
60
|
+
});
|
|
61
|
+
|
|
62
|
+
addCommentBefore({
|
|
63
|
+
j,
|
|
64
|
+
target: base
|
|
65
|
+
.find(j.ImportDeclaration)
|
|
66
|
+
.filter(
|
|
67
|
+
(declaration) =>
|
|
68
|
+
declaration.value.source.value ===
|
|
69
|
+
'@atlaskit/button/standard-button',
|
|
70
|
+
),
|
|
71
|
+
message: `
|
|
72
|
+
This file does not exclusively use Button in JSX.
|
|
73
|
+
The codemod is unable to know which button variant, so it is using
|
|
74
|
+
the standard button: "@atlaskit/button/standard-button".
|
|
75
|
+
|
|
76
|
+
Please validate this decision.
|
|
77
|
+
You might need to change the usage of Button to either LoadingButton or CustomThemeButton
|
|
78
|
+
`,
|
|
79
|
+
});
|
|
80
|
+
return;
|
|
81
|
+
}
|
|
82
|
+
|
|
83
|
+
// Find usages of the Button component
|
|
84
|
+
// There are three possible import statements:
|
|
85
|
+
// 1. import Button from '@atlaskit/button/standard';
|
|
86
|
+
// 2. import LoadingButton from '@atlaskit/button/loading-button';
|
|
87
|
+
// 3. import CustomThemeButton from '@atlaskit/button/custom-theme-button';
|
|
88
|
+
|
|
89
|
+
// What to do if any of the names clash?
|
|
90
|
+
// - In the case of clash: prefix with 'DS' (eg import DSLoadingButton from '@atlaskit/button/loading-button';)
|
|
91
|
+
|
|
92
|
+
// What to do if old Button was aliased? eg "AkButton"
|
|
93
|
+
// - We cannot use that existing alias as we might have three different Button imports in the file
|
|
94
|
+
// - We automatically will be be swapping to the standard names with 'DS' prefix for all imports
|
|
95
|
+
|
|
96
|
+
type Groups = {
|
|
97
|
+
standard: NodePath<JSXElement, JSXElement>[];
|
|
98
|
+
loading: NodePath<JSXElement, JSXElement>[];
|
|
99
|
+
customTheme: NodePath<JSXElement, JSXElement>[];
|
|
100
|
+
};
|
|
101
|
+
|
|
102
|
+
const groups: Groups = {
|
|
103
|
+
standard: [],
|
|
104
|
+
loading: [],
|
|
105
|
+
customTheme: [],
|
|
106
|
+
};
|
|
107
|
+
|
|
108
|
+
base.findJSXElements(defaultName).forEach((path) => {
|
|
109
|
+
const hasThemeProp: boolean = isUsingProp({
|
|
110
|
+
j,
|
|
111
|
+
base,
|
|
112
|
+
element: path,
|
|
113
|
+
propName: 'theme',
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
if (hasThemeProp) {
|
|
117
|
+
groups.customTheme.push(path);
|
|
118
|
+
return;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
if (!isUsingSupportedSpread({ j, base, element: path })) {
|
|
122
|
+
addCommentToStartOfFile({
|
|
123
|
+
j,
|
|
124
|
+
base,
|
|
125
|
+
message: `
|
|
126
|
+
Detected spreading props (<Button {...props} />) that was too complex for our codemod to understand
|
|
127
|
+
Our codemod will only look at inline objects, or objects defined in the same file (ObjectExpression's)
|
|
128
|
+
We have opted for our safest upgrade component in this file: '<CustomThemeButton />'
|
|
129
|
+
`,
|
|
130
|
+
});
|
|
131
|
+
groups.customTheme.push(path);
|
|
132
|
+
return;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
const isUsingThemeInFile: boolean =
|
|
136
|
+
base
|
|
137
|
+
.find(j.ImportDeclaration)
|
|
138
|
+
.filter(
|
|
139
|
+
(declaration) =>
|
|
140
|
+
declaration.value.source.value ===
|
|
141
|
+
'@atlaskit/button/custom-theme-button',
|
|
142
|
+
)
|
|
143
|
+
.find(j.ImportSpecifier)
|
|
144
|
+
.filter((specifier) => specifier.value.imported.name === 'Theme')
|
|
145
|
+
.length > 0;
|
|
146
|
+
|
|
147
|
+
if (isUsingThemeInFile) {
|
|
148
|
+
addCommentToStartOfFile({
|
|
149
|
+
j,
|
|
150
|
+
base,
|
|
151
|
+
message: `
|
|
152
|
+
Using "import { Theme } from '@atlaskit/button/custom-theme-button" in a file
|
|
153
|
+
will cause all buttons in that file to be safely converted to a <CustomThemeButton/>
|
|
154
|
+
`,
|
|
155
|
+
});
|
|
156
|
+
|
|
157
|
+
groups.customTheme.push(path);
|
|
158
|
+
return;
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
const hasIsLoadingProp: boolean = isUsingProp({
|
|
162
|
+
j,
|
|
163
|
+
base,
|
|
164
|
+
element: path,
|
|
165
|
+
propName: 'isLoading',
|
|
166
|
+
});
|
|
167
|
+
|
|
168
|
+
if (hasIsLoadingProp) {
|
|
169
|
+
groups.loading.push(path);
|
|
170
|
+
return;
|
|
171
|
+
}
|
|
172
|
+
|
|
173
|
+
groups.standard.push(path);
|
|
174
|
+
return;
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
convertButtonType({
|
|
178
|
+
j,
|
|
179
|
+
base,
|
|
180
|
+
elements: groups.standard,
|
|
181
|
+
name: getSafeImportName({
|
|
182
|
+
j,
|
|
183
|
+
base,
|
|
184
|
+
currentDefaultSpecifierName: defaultName,
|
|
185
|
+
desiredName: 'Button',
|
|
186
|
+
fallbackName: 'DSButton',
|
|
187
|
+
}),
|
|
188
|
+
newPackageName: '@atlaskit/button/standard-button',
|
|
189
|
+
});
|
|
190
|
+
|
|
191
|
+
convertButtonType({
|
|
192
|
+
j,
|
|
193
|
+
base,
|
|
194
|
+
elements: groups.loading,
|
|
195
|
+
newPackageName: '@atlaskit/button/loading-button',
|
|
196
|
+
name: getSafeImportName({
|
|
197
|
+
j,
|
|
198
|
+
base,
|
|
199
|
+
desiredName: 'LoadingButton',
|
|
200
|
+
fallbackName: 'DSLoadingButton',
|
|
201
|
+
currentDefaultSpecifierName: defaultName,
|
|
202
|
+
}),
|
|
203
|
+
});
|
|
204
|
+
convertButtonType({
|
|
205
|
+
j,
|
|
206
|
+
base,
|
|
207
|
+
elements: groups.customTheme,
|
|
208
|
+
newPackageName: '@atlaskit/button/custom-theme-button',
|
|
209
|
+
name: getSafeImportName({
|
|
210
|
+
j,
|
|
211
|
+
base,
|
|
212
|
+
currentDefaultSpecifierName: defaultName,
|
|
213
|
+
desiredName: 'CustomThemeButton',
|
|
214
|
+
fallbackName: 'DSCustomThemeButton',
|
|
215
|
+
}),
|
|
216
|
+
});
|
|
217
|
+
}
|
|
218
|
+
|
|
219
|
+
export default function transformer(
|
|
220
|
+
file: FileInfo,
|
|
221
|
+
{ jscodeshift: j }: API,
|
|
222
|
+
options: Options,
|
|
223
|
+
) {
|
|
224
|
+
return transformButton({
|
|
225
|
+
j,
|
|
226
|
+
file,
|
|
227
|
+
custom: (base: Collection<any>) => {
|
|
228
|
+
changeImportFor({
|
|
229
|
+
j,
|
|
230
|
+
base,
|
|
231
|
+
option: {
|
|
232
|
+
type: 'keep-name',
|
|
233
|
+
name: 'ButtonProps',
|
|
234
|
+
behaviour: 'keep-as-named-import',
|
|
235
|
+
},
|
|
236
|
+
oldPackagePath: '@atlaskit/button',
|
|
237
|
+
newPackagePath: '@atlaskit/button/types',
|
|
238
|
+
});
|
|
239
|
+
|
|
240
|
+
const isUsingButtonPropsType: boolean =
|
|
241
|
+
base
|
|
242
|
+
.find(j.ImportDeclaration)
|
|
243
|
+
.filter(
|
|
244
|
+
(declaration) =>
|
|
245
|
+
declaration.value.source.value === '@atlaskit/button/types',
|
|
246
|
+
)
|
|
247
|
+
.find(j.ImportSpecifier)
|
|
248
|
+
.filter(
|
|
249
|
+
(specifier) => specifier.value.imported.name === 'ButtonProps',
|
|
250
|
+
).length > 0;
|
|
251
|
+
|
|
252
|
+
if (isUsingButtonPropsType) {
|
|
253
|
+
const target = base
|
|
254
|
+
.find(j.ImportDeclaration)
|
|
255
|
+
.filter(
|
|
256
|
+
(declaration) =>
|
|
257
|
+
declaration.value.source.value === '@atlaskit/button/types',
|
|
258
|
+
);
|
|
259
|
+
addCommentBefore({
|
|
260
|
+
j,
|
|
261
|
+
target,
|
|
262
|
+
message: `
|
|
263
|
+
Verify ButtonProps is the right prop type
|
|
264
|
+
You might need the LoadingButtonProps, CustomButtonProps types which can be imported from '@atlaskit/button/types'
|
|
265
|
+
`,
|
|
266
|
+
});
|
|
267
|
+
}
|
|
268
|
+
|
|
269
|
+
changeUsage({
|
|
270
|
+
j,
|
|
271
|
+
base,
|
|
272
|
+
packageName: '@atlaskit/button',
|
|
273
|
+
});
|
|
274
|
+
},
|
|
275
|
+
});
|
|
276
|
+
}
|
|
277
|
+
|
|
278
|
+
// Note: not exporting a 'parser' because doing so
|
|
279
|
+
// will prevent consumers overriding it
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
We are using the `optimistic-` prefix so that the optimistic codemod won't be run in branch deploys
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
{
|
|
2
|
+
"name": "@atlaskit/button/custom-theme-button",
|
|
3
|
+
"main": "../dist/cjs/entry-points/custom-theme-button.js",
|
|
4
|
+
"module": "../dist/esm/entry-points/custom-theme-button.js",
|
|
5
|
+
"module:es2019": "../dist/es2019/entry-points/custom-theme-button.js",
|
|
6
|
+
"types": "../dist/types/entry-points/custom-theme-button.d.ts"
|
|
7
|
+
}
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.default = ButtonGroup;
|
|
9
|
+
exports.groupItemStyles = void 0;
|
|
10
|
+
|
|
11
|
+
var _react = _interopRequireDefault(require("react"));
|
|
12
|
+
|
|
13
|
+
var _core = require("@emotion/core");
|
|
14
|
+
|
|
15
|
+
var _constants = require("@atlaskit/theme/constants");
|
|
16
|
+
|
|
17
|
+
/** @jsx jsx */
|
|
18
|
+
var groupItemStyles = {
|
|
19
|
+
flex: '1 0 auto',
|
|
20
|
+
display: 'flex',
|
|
21
|
+
|
|
22
|
+
/* margins don't flip when the layout uses dir="rtl", whereas pseudos do */
|
|
23
|
+
'& + &::before': {
|
|
24
|
+
content: "''",
|
|
25
|
+
display: 'inline-block',
|
|
26
|
+
width: "".concat((0, _constants.gridSize)() / 2, "px")
|
|
27
|
+
}
|
|
28
|
+
};
|
|
29
|
+
exports.groupItemStyles = groupItemStyles;
|
|
30
|
+
|
|
31
|
+
function ButtonGroup(_ref) {
|
|
32
|
+
var appearance = _ref.appearance,
|
|
33
|
+
children = _ref.children;
|
|
34
|
+
return (0, _core.jsx)("div", {
|
|
35
|
+
css: {
|
|
36
|
+
display: 'inline-flex'
|
|
37
|
+
}
|
|
38
|
+
}, _react.default.Children.map(children, function (child, idx) {
|
|
39
|
+
if (!child) {
|
|
40
|
+
return null;
|
|
41
|
+
}
|
|
42
|
+
|
|
43
|
+
return (0, _core.jsx)("div", {
|
|
44
|
+
key: idx,
|
|
45
|
+
css: groupItemStyles
|
|
46
|
+
}, appearance ? /*#__PURE__*/_react.default.cloneElement(child, {
|
|
47
|
+
appearance: appearance
|
|
48
|
+
}) : child);
|
|
49
|
+
}));
|
|
50
|
+
}
|
|
@@ -0,0 +1,104 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
var _typeof = require("@babel/runtime/helpers/typeof");
|
|
6
|
+
|
|
7
|
+
Object.defineProperty(exports, "__esModule", {
|
|
8
|
+
value: true
|
|
9
|
+
});
|
|
10
|
+
exports.default = void 0;
|
|
11
|
+
|
|
12
|
+
var _extends2 = _interopRequireDefault(require("@babel/runtime/helpers/extends"));
|
|
13
|
+
|
|
14
|
+
var _slicedToArray2 = _interopRequireDefault(require("@babel/runtime/helpers/slicedToArray"));
|
|
15
|
+
|
|
16
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
17
|
+
|
|
18
|
+
var _react = _interopRequireWildcard(require("react"));
|
|
19
|
+
|
|
20
|
+
var _components = _interopRequireDefault(require("@atlaskit/theme/components"));
|
|
21
|
+
|
|
22
|
+
var _buttonBase = _interopRequireDefault(require("./shared/button-base"));
|
|
23
|
+
|
|
24
|
+
var _css = require("./shared/css");
|
|
25
|
+
|
|
26
|
+
var _getIsOnlySingleIcon = _interopRequireDefault(require("./shared/get-is-only-single-icon"));
|
|
27
|
+
|
|
28
|
+
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); }
|
|
29
|
+
|
|
30
|
+
function _interopRequireWildcard(obj, nodeInterop) { if (!nodeInterop && obj && obj.__esModule) { return obj; } if (obj === null || _typeof(obj) !== "object" && typeof obj !== "function") { return { default: obj }; } var cache = _getRequireWildcardCache(nodeInterop); if (cache && cache.has(obj)) { return cache.get(obj); } var newObj = {}; var hasPropertyDescriptor = Object.defineProperty && Object.getOwnPropertyDescriptor; for (var key in obj) { if (key !== "default" && Object.prototype.hasOwnProperty.call(obj, key)) { var desc = hasPropertyDescriptor ? Object.getOwnPropertyDescriptor(obj, key) : null; if (desc && (desc.get || desc.set)) { Object.defineProperty(newObj, key, desc); } else { newObj[key] = obj[key]; } } } newObj.default = obj; if (cache) { cache.set(obj, newObj); } return newObj; }
|
|
31
|
+
|
|
32
|
+
function noop() {}
|
|
33
|
+
|
|
34
|
+
var isFirefox = typeof navigator !== 'undefined' && navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
|
|
35
|
+
|
|
36
|
+
var ButtonWithMode = /*#__PURE__*/_react.default.forwardRef(function ButtonWithMode(_ref, ref) {
|
|
37
|
+
var mode = _ref.mode,
|
|
38
|
+
_ref$onMouseDown = _ref.onMouseDown,
|
|
39
|
+
providedOnMouseDown = _ref$onMouseDown === void 0 ? noop : _ref$onMouseDown,
|
|
40
|
+
_ref$onMouseUp = _ref.onMouseUp,
|
|
41
|
+
providedOnMouseUp = _ref$onMouseUp === void 0 ? noop : _ref$onMouseUp,
|
|
42
|
+
rest = (0, _objectWithoutProperties2.default)(_ref, ["mode", "onMouseDown", "onMouseUp"]);
|
|
43
|
+
var appearance = rest.appearance || 'default';
|
|
44
|
+
var spacing = rest.spacing || 'default';
|
|
45
|
+
var shouldFitContainer = Boolean(rest.shouldFitContainer);
|
|
46
|
+
var isSelected = Boolean(rest.isSelected);
|
|
47
|
+
var isOnlySingleIcon = (0, _getIsOnlySingleIcon.default)(rest);
|
|
48
|
+
|
|
49
|
+
var _useState = (0, _react.useState)(false),
|
|
50
|
+
_useState2 = (0, _slicedToArray2.default)(_useState, 2),
|
|
51
|
+
isActive = _useState2[0],
|
|
52
|
+
setIsActive = _useState2[1]; // Wrap onMouseDown / onMouseUp to manually trigger active state
|
|
53
|
+
// in Firefox
|
|
54
|
+
|
|
55
|
+
|
|
56
|
+
var onMouseDown = (0, _react.useCallback)(function (event) {
|
|
57
|
+
providedOnMouseDown(event);
|
|
58
|
+
|
|
59
|
+
if (isFirefox) {
|
|
60
|
+
setIsActive(true);
|
|
61
|
+
}
|
|
62
|
+
}, [providedOnMouseDown, setIsActive]);
|
|
63
|
+
var onMouseUp = (0, _react.useCallback)(function (event) {
|
|
64
|
+
providedOnMouseUp(event);
|
|
65
|
+
|
|
66
|
+
if (isFirefox) {
|
|
67
|
+
setIsActive(false);
|
|
68
|
+
}
|
|
69
|
+
}, [providedOnMouseUp, setIsActive]);
|
|
70
|
+
var buttonCss = (0, _react.useMemo)(function () {
|
|
71
|
+
return (0, _css.getCss)({
|
|
72
|
+
appearance: appearance,
|
|
73
|
+
spacing: spacing,
|
|
74
|
+
mode: mode,
|
|
75
|
+
isSelected: isSelected,
|
|
76
|
+
shouldFitContainer: shouldFitContainer,
|
|
77
|
+
isOnlySingleIcon: isOnlySingleIcon
|
|
78
|
+
});
|
|
79
|
+
}, [appearance, spacing, mode, isSelected, shouldFitContainer, isOnlySingleIcon]);
|
|
80
|
+
return /*#__PURE__*/_react.default.createElement(_buttonBase.default, (0, _extends2.default)({}, rest, {
|
|
81
|
+
ref: ref,
|
|
82
|
+
buttonCss: buttonCss // Due to how click events are set, we need to set active styles
|
|
83
|
+
// manually in Firefox and wrap onMouseDown/onMouseUp
|
|
84
|
+
,
|
|
85
|
+
"data-firefox-is-active": isActive ? true : undefined,
|
|
86
|
+
onMouseDown: onMouseDown,
|
|
87
|
+
onMouseUp: onMouseUp
|
|
88
|
+
}));
|
|
89
|
+
});
|
|
90
|
+
|
|
91
|
+
var Button = /*#__PURE__*/_react.default.memo( /*#__PURE__*/_react.default.forwardRef(function Button(props, ref) {
|
|
92
|
+
return /*#__PURE__*/_react.default.createElement(_components.default.Consumer, null, function (_ref2) {
|
|
93
|
+
var mode = _ref2.mode;
|
|
94
|
+
return /*#__PURE__*/_react.default.createElement(ButtonWithMode, (0, _extends2.default)({}, props, {
|
|
95
|
+
ref: ref,
|
|
96
|
+
mode: mode
|
|
97
|
+
}));
|
|
98
|
+
});
|
|
99
|
+
})); // Tools including enzyme rely on components having a display name
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
Button.displayName = 'Button';
|
|
103
|
+
var _default = Button;
|
|
104
|
+
exports.default = _default;
|