@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,265 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
var _interopRequireDefault = require("@babel/runtime/helpers/interopRequireDefault");
|
|
4
|
+
|
|
5
|
+
Object.defineProperty(exports, "__esModule", {
|
|
6
|
+
value: true
|
|
7
|
+
});
|
|
8
|
+
exports.getCss = getCss;
|
|
9
|
+
exports.getIconStyle = getIconStyle;
|
|
10
|
+
exports.getContentStyle = getContentStyle;
|
|
11
|
+
exports.getFadingCss = getFadingCss;
|
|
12
|
+
exports.overlayCss = void 0;
|
|
13
|
+
|
|
14
|
+
var _defineProperty2 = _interopRequireDefault(require("@babel/runtime/helpers/defineProperty"));
|
|
15
|
+
|
|
16
|
+
var _constants = require("@atlaskit/theme/constants");
|
|
17
|
+
|
|
18
|
+
var _colors = _interopRequireDefault(require("./colors"));
|
|
19
|
+
|
|
20
|
+
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; }
|
|
21
|
+
|
|
22
|
+
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) { (0, _defineProperty2.default)(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; }
|
|
23
|
+
|
|
24
|
+
var borderRadius = (0, _constants.borderRadius)();
|
|
25
|
+
var gridSize = (0, _constants.gridSize)();
|
|
26
|
+
var fontSize = (0, _constants.fontSize)(); // ## Button layout
|
|
27
|
+
//
|
|
28
|
+
// /------------------------------------------------------------------------------------------------------------------\
|
|
29
|
+
// | → | ← | | → | ← | | → | ← | | → | ← |
|
|
30
|
+
// | 10px → | ← 2px | icon | 2px → | ← 2px | | 2px → | ← 2px | icon | 2px → | ← 10px |
|
|
31
|
+
// | padding | margin | before | margin | margin | content | margin | margin | after | margin | padding |
|
|
32
|
+
// | (12px total) | | (4px total) | | (4px total) | | (12px total) |
|
|
33
|
+
// | → | ← | | → | ← | | → | ← | | → | ← |
|
|
34
|
+
// \------------------------------------------------------------------------------------------------------------------/
|
|
35
|
+
// ↑ ↑
|
|
36
|
+
// Margins don't collapse with inline-flex
|
|
37
|
+
//
|
|
38
|
+
|
|
39
|
+
var heights = {
|
|
40
|
+
default: "".concat(gridSize * 4 / fontSize, "em"),
|
|
41
|
+
// 32px
|
|
42
|
+
compact: "".concat(gridSize * 3 / fontSize, "em"),
|
|
43
|
+
none: 'auto'
|
|
44
|
+
};
|
|
45
|
+
var lineHeights = {
|
|
46
|
+
default: heights.default,
|
|
47
|
+
compact: heights.compact,
|
|
48
|
+
none: 'inherit'
|
|
49
|
+
};
|
|
50
|
+
var padding = {
|
|
51
|
+
// 10px gutter
|
|
52
|
+
default: "0 ".concat(gridSize + gridSize / 4, "px"),
|
|
53
|
+
compact: "0 ".concat(gridSize + gridSize / 4, "px"),
|
|
54
|
+
none: '0'
|
|
55
|
+
};
|
|
56
|
+
var singleIconPadding = {
|
|
57
|
+
// 2px gutter
|
|
58
|
+
compact: "0 ".concat(gridSize / 4, "px"),
|
|
59
|
+
default: "0 ".concat(gridSize / 4, "px"),
|
|
60
|
+
none: '0'
|
|
61
|
+
};
|
|
62
|
+
var verticalAlign = {
|
|
63
|
+
default: 'middle',
|
|
64
|
+
compact: 'middle',
|
|
65
|
+
none: 'baseline'
|
|
66
|
+
};
|
|
67
|
+
var innerMargin = {
|
|
68
|
+
content: "0 ".concat(gridSize / 4, "px"),
|
|
69
|
+
icon: "0 ".concat(gridSize / 4, "px")
|
|
70
|
+
};
|
|
71
|
+
|
|
72
|
+
function getColor(_ref) {
|
|
73
|
+
var group = _ref.group,
|
|
74
|
+
key = _ref.key,
|
|
75
|
+
mode = _ref.mode;
|
|
76
|
+
var rule = group[key] || group.default;
|
|
77
|
+
return rule[mode];
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
function getColors(_ref2) {
|
|
81
|
+
var appearance = _ref2.appearance,
|
|
82
|
+
key = _ref2.key,
|
|
83
|
+
mode = _ref2.mode;
|
|
84
|
+
return {
|
|
85
|
+
background: getColor({
|
|
86
|
+
group: _colors.default.background[appearance],
|
|
87
|
+
key: key,
|
|
88
|
+
mode: mode
|
|
89
|
+
}),
|
|
90
|
+
// Needing to add !important to overcome specificity issue caused by deprecated AtlaskitThemeProvider
|
|
91
|
+
color: "".concat(getColor({
|
|
92
|
+
group: _colors.default.color[appearance],
|
|
93
|
+
key: key,
|
|
94
|
+
mode: mode
|
|
95
|
+
}), " !important")
|
|
96
|
+
};
|
|
97
|
+
}
|
|
98
|
+
|
|
99
|
+
function getCss(_ref3) {
|
|
100
|
+
var appearance = _ref3.appearance,
|
|
101
|
+
spacing = _ref3.spacing,
|
|
102
|
+
mode = _ref3.mode,
|
|
103
|
+
isSelected = _ref3.isSelected,
|
|
104
|
+
shouldFitContainer = _ref3.shouldFitContainer,
|
|
105
|
+
isOnlySingleIcon = _ref3.isOnlySingleIcon;
|
|
106
|
+
var baseColors = getColors({
|
|
107
|
+
appearance: appearance,
|
|
108
|
+
key: isSelected ? 'selected' : 'default',
|
|
109
|
+
mode: mode
|
|
110
|
+
});
|
|
111
|
+
return _objectSpread(_objectSpread({
|
|
112
|
+
// 0px margin added to css-reset
|
|
113
|
+
alignItems: 'baseline',
|
|
114
|
+
borderWidth: 0,
|
|
115
|
+
borderRadius: borderRadius,
|
|
116
|
+
boxSizing: 'border-box',
|
|
117
|
+
display: 'inline-flex',
|
|
118
|
+
fontSize: 'inherit',
|
|
119
|
+
fontStyle: 'normal',
|
|
120
|
+
// Chrome recently changed button so that they use 'arial' as the font family
|
|
121
|
+
fontFamily: 'inherit',
|
|
122
|
+
fontWeight: 500,
|
|
123
|
+
// margin for button has been applied to css reset
|
|
124
|
+
maxWidth: '100%',
|
|
125
|
+
// Needed to position overlay
|
|
126
|
+
position: 'relative',
|
|
127
|
+
textAlign: 'center',
|
|
128
|
+
textDecoration: 'none',
|
|
129
|
+
transition: 'background 0.1s ease-out, box-shadow 0.15s cubic-bezier(0.47, 0.03, 0.49, 1.38)',
|
|
130
|
+
whiteSpace: 'nowrap'
|
|
131
|
+
}, baseColors), {}, {
|
|
132
|
+
cursor: 'pointer',
|
|
133
|
+
height: heights[spacing],
|
|
134
|
+
lineHeight: lineHeights[spacing],
|
|
135
|
+
padding: isOnlySingleIcon ? singleIconPadding[spacing] : padding[spacing],
|
|
136
|
+
verticalAlign: verticalAlign[spacing],
|
|
137
|
+
width: shouldFitContainer ? '100%' : 'auto',
|
|
138
|
+
// justifyContent required for shouldFitContainer buttons with an icon inside
|
|
139
|
+
justifyContent: 'center',
|
|
140
|
+
// Note: we cannot disable pointer events when there is an overlay.
|
|
141
|
+
// That would be easy for styling, but it would start letting events through on disabled buttons
|
|
142
|
+
// Disabling visited styles (just using the base colors)
|
|
143
|
+
'&:visited': _objectSpread({}, baseColors),
|
|
144
|
+
'&:hover': _objectSpread(_objectSpread({}, getColors({
|
|
145
|
+
appearance: appearance,
|
|
146
|
+
key: isSelected ? 'selected' : 'hover',
|
|
147
|
+
mode: mode
|
|
148
|
+
})), {}, {
|
|
149
|
+
textDecoration: !isSelected && (appearance === 'link' || appearance === 'subtle-link') ? 'underline' : 'inherit',
|
|
150
|
+
// background, box-shadow
|
|
151
|
+
transitionDuration: '0s, 0.15s'
|
|
152
|
+
}),
|
|
153
|
+
'&:focus': _objectSpread(_objectSpread({}, getColors({
|
|
154
|
+
appearance: appearance,
|
|
155
|
+
key: isSelected ? 'focusSelected' : 'focus',
|
|
156
|
+
mode: mode
|
|
157
|
+
})), {}, {
|
|
158
|
+
boxShadow: "0 0 0 2px ".concat(_colors.default.boxShadowColor[appearance].focus[mode]),
|
|
159
|
+
// background, box-shadow
|
|
160
|
+
transitionDuration: '0s, 0.2s',
|
|
161
|
+
// disabling browser focus outline
|
|
162
|
+
outline: 'none'
|
|
163
|
+
}),
|
|
164
|
+
// giving active styles preference by listing them after focus
|
|
165
|
+
'&:active': _objectSpread(_objectSpread({}, getColors({
|
|
166
|
+
appearance: appearance,
|
|
167
|
+
key: isSelected ? 'selected' : 'active',
|
|
168
|
+
mode: mode
|
|
169
|
+
})), {}, {
|
|
170
|
+
// background, box-shadow
|
|
171
|
+
transitionDuration: '0s, 0s'
|
|
172
|
+
}),
|
|
173
|
+
// preventDefault prevents regular active styles from applying in Firefox
|
|
174
|
+
'&[data-firefox-is-active="true"]': _objectSpread(_objectSpread({}, getColors({
|
|
175
|
+
appearance: appearance,
|
|
176
|
+
key: isSelected ? 'selected' : 'active',
|
|
177
|
+
mode: mode
|
|
178
|
+
})), {}, {
|
|
179
|
+
// background, box-shadow
|
|
180
|
+
transitionDuration: '0s, 0s'
|
|
181
|
+
}),
|
|
182
|
+
// Giving disabled styles preference over active by listing them after.
|
|
183
|
+
// Not using '&:disabled' because :disabled is not a valid state for all element types
|
|
184
|
+
// so we are targeting the attribute
|
|
185
|
+
// Attributes have the same specificity a pseudo classes so we are overriding :disabled here
|
|
186
|
+
'&[disabled]': _objectSpread(_objectSpread({}, getColors({
|
|
187
|
+
appearance: appearance,
|
|
188
|
+
key: 'disabled',
|
|
189
|
+
mode: mode
|
|
190
|
+
})), {}, {
|
|
191
|
+
cursor: 'not-allowed',
|
|
192
|
+
textDecoration: 'none'
|
|
193
|
+
}),
|
|
194
|
+
'&[data-has-overlay="true"]': {
|
|
195
|
+
cursor: 'default',
|
|
196
|
+
textDecoration: 'none'
|
|
197
|
+
},
|
|
198
|
+
// disabling hover and active color changes when there is an overlay, but the button is not disabled
|
|
199
|
+
'&[data-has-overlay="true"]:not([disabled]):hover, &[data-has-overlay="true"]:not([disabled]):active': _objectSpread({}, getColors({
|
|
200
|
+
appearance: appearance,
|
|
201
|
+
key: isSelected ? 'selected' : 'default',
|
|
202
|
+
mode: mode
|
|
203
|
+
})),
|
|
204
|
+
'&::-moz-focus-inner': {
|
|
205
|
+
border: 0,
|
|
206
|
+
margin: 0,
|
|
207
|
+
padding: 0
|
|
208
|
+
}
|
|
209
|
+
});
|
|
210
|
+
} // inline-flex child
|
|
211
|
+
|
|
212
|
+
|
|
213
|
+
function getIconStyle(_ref4) {
|
|
214
|
+
var spacing = _ref4.spacing;
|
|
215
|
+
return {
|
|
216
|
+
alignSelf: 'center',
|
|
217
|
+
display: 'flex',
|
|
218
|
+
// icon size cannot grow and shrink
|
|
219
|
+
flexGrow: 0,
|
|
220
|
+
flexShrink: 0,
|
|
221
|
+
lineHeight: 0,
|
|
222
|
+
fontSize: 0,
|
|
223
|
+
userSelect: 'none',
|
|
224
|
+
margin: spacing === 'none' ? 0 : innerMargin.icon
|
|
225
|
+
};
|
|
226
|
+
} // inline-flex child
|
|
227
|
+
|
|
228
|
+
|
|
229
|
+
function getContentStyle(_ref5) {
|
|
230
|
+
var spacing = _ref5.spacing;
|
|
231
|
+
return {
|
|
232
|
+
margin: spacing === 'none' ? 0 : innerMargin.content,
|
|
233
|
+
// content can grow and shrink
|
|
234
|
+
flexGrow: 1,
|
|
235
|
+
flexShrink: 1,
|
|
236
|
+
// ellipsis for overflow text
|
|
237
|
+
overflow: 'hidden',
|
|
238
|
+
textOverflow: 'ellipsis',
|
|
239
|
+
whiteSpace: 'nowrap'
|
|
240
|
+
};
|
|
241
|
+
}
|
|
242
|
+
|
|
243
|
+
function getFadingCss(_ref6) {
|
|
244
|
+
var hasOverlay = _ref6.hasOverlay;
|
|
245
|
+
return {
|
|
246
|
+
transition: 'opacity 0.3s',
|
|
247
|
+
opacity: hasOverlay ? 0 : 1
|
|
248
|
+
};
|
|
249
|
+
}
|
|
250
|
+
|
|
251
|
+
var overlayCss = {
|
|
252
|
+
// stretching to full width / height of button
|
|
253
|
+
// this is important as we need it to still block
|
|
254
|
+
// event if clicking in the button's own padding
|
|
255
|
+
position: 'absolute',
|
|
256
|
+
left: 0,
|
|
257
|
+
top: 0,
|
|
258
|
+
right: 0,
|
|
259
|
+
bottom: 0,
|
|
260
|
+
// Putting all children in the center
|
|
261
|
+
display: 'flex',
|
|
262
|
+
justifyContent: 'center',
|
|
263
|
+
alignItems: 'center'
|
|
264
|
+
};
|
|
265
|
+
exports.overlayCss = overlayCss;
|
|
@@ -0,0 +1,26 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
|
|
3
|
+
Object.defineProperty(exports, "__esModule", {
|
|
4
|
+
value: true
|
|
5
|
+
});
|
|
6
|
+
exports.default = getIsOnlySingleIcon;
|
|
7
|
+
|
|
8
|
+
function getIsOnlySingleIcon(_ref) {
|
|
9
|
+
var children = _ref.children,
|
|
10
|
+
iconBefore = _ref.iconBefore,
|
|
11
|
+
iconAfter = _ref.iconAfter;
|
|
12
|
+
|
|
13
|
+
if (children) {
|
|
14
|
+
return false;
|
|
15
|
+
}
|
|
16
|
+
|
|
17
|
+
if (iconBefore && !iconAfter) {
|
|
18
|
+
return true;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
if (!iconBefore && iconAfter) {
|
|
22
|
+
return true;
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
return false;
|
|
26
|
+
}
|
|
@@ -0,0 +1,45 @@
|
|
|
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 = LoadingSpinner;
|
|
9
|
+
|
|
10
|
+
var _objectWithoutProperties2 = _interopRequireDefault(require("@babel/runtime/helpers/objectWithoutProperties"));
|
|
11
|
+
|
|
12
|
+
var _react = _interopRequireDefault(require("react"));
|
|
13
|
+
|
|
14
|
+
var _spinner = _interopRequireDefault(require("@atlaskit/spinner"));
|
|
15
|
+
|
|
16
|
+
function getSpinnerAppearance(_ref) {
|
|
17
|
+
var appearance = _ref.appearance,
|
|
18
|
+
isDisabled = _ref.isDisabled,
|
|
19
|
+
isSelected = _ref.isSelected;
|
|
20
|
+
|
|
21
|
+
if (isDisabled) {
|
|
22
|
+
return 'inherit';
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
if (isSelected) {
|
|
26
|
+
return 'invert';
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
if (appearance === 'primary' || appearance === 'danger') {
|
|
30
|
+
return 'invert';
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
return 'inherit';
|
|
34
|
+
}
|
|
35
|
+
|
|
36
|
+
function LoadingSpinner(_ref2) {
|
|
37
|
+
var _ref2$spacing = _ref2.spacing,
|
|
38
|
+
spacing = _ref2$spacing === void 0 ? 'default' : _ref2$spacing,
|
|
39
|
+
rest = (0, _objectWithoutProperties2.default)(_ref2, ["spacing"]);
|
|
40
|
+
var size = spacing === 'default' ? 'medium' : 'small';
|
|
41
|
+
return /*#__PURE__*/_react.default.createElement(_spinner.default, {
|
|
42
|
+
size: size,
|
|
43
|
+
appearance: getSpinnerAppearance(rest)
|
|
44
|
+
});
|
|
45
|
+
}
|
|
@@ -0,0 +1,36 @@
|
|
|
1
|
+
/** @jsx jsx */
|
|
2
|
+
import React from 'react';
|
|
3
|
+
import { jsx } from '@emotion/core';
|
|
4
|
+
import { gridSize } from '@atlaskit/theme/constants';
|
|
5
|
+
export const 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: `${gridSize() / 2}px`
|
|
14
|
+
}
|
|
15
|
+
};
|
|
16
|
+
export default function ButtonGroup({
|
|
17
|
+
appearance,
|
|
18
|
+
children
|
|
19
|
+
}) {
|
|
20
|
+
return jsx("div", {
|
|
21
|
+
css: {
|
|
22
|
+
display: 'inline-flex'
|
|
23
|
+
}
|
|
24
|
+
}, React.Children.map(children, (child, idx) => {
|
|
25
|
+
if (!child) {
|
|
26
|
+
return null;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
return jsx("div", {
|
|
30
|
+
key: idx,
|
|
31
|
+
css: groupItemStyles
|
|
32
|
+
}, appearance ? /*#__PURE__*/React.cloneElement(child, {
|
|
33
|
+
appearance
|
|
34
|
+
}) : child);
|
|
35
|
+
}));
|
|
36
|
+
}
|
|
@@ -0,0 +1,69 @@
|
|
|
1
|
+
import _extends from "@babel/runtime/helpers/extends";
|
|
2
|
+
import React, { useCallback, useMemo, useState } from 'react';
|
|
3
|
+
import GlobalTheme from '@atlaskit/theme/components';
|
|
4
|
+
import ButtonBase from './shared/button-base';
|
|
5
|
+
import { getCss } from './shared/css';
|
|
6
|
+
import getIsOnlySingleIcon from './shared/get-is-only-single-icon';
|
|
7
|
+
|
|
8
|
+
function noop() {}
|
|
9
|
+
|
|
10
|
+
const isFirefox = typeof navigator !== 'undefined' && navigator.userAgent.toLowerCase().indexOf('firefox') > -1;
|
|
11
|
+
const ButtonWithMode = /*#__PURE__*/React.forwardRef(function ButtonWithMode({
|
|
12
|
+
mode,
|
|
13
|
+
onMouseDown: providedOnMouseDown = noop,
|
|
14
|
+
onMouseUp: providedOnMouseUp = noop,
|
|
15
|
+
...rest
|
|
16
|
+
}, ref) {
|
|
17
|
+
const appearance = rest.appearance || 'default';
|
|
18
|
+
const spacing = rest.spacing || 'default';
|
|
19
|
+
const shouldFitContainer = Boolean(rest.shouldFitContainer);
|
|
20
|
+
const isSelected = Boolean(rest.isSelected);
|
|
21
|
+
const isOnlySingleIcon = getIsOnlySingleIcon(rest);
|
|
22
|
+
const [isActive, setIsActive] = useState(false); // Wrap onMouseDown / onMouseUp to manually trigger active state
|
|
23
|
+
// in Firefox
|
|
24
|
+
|
|
25
|
+
const onMouseDown = useCallback(event => {
|
|
26
|
+
providedOnMouseDown(event);
|
|
27
|
+
|
|
28
|
+
if (isFirefox) {
|
|
29
|
+
setIsActive(true);
|
|
30
|
+
}
|
|
31
|
+
}, [providedOnMouseDown, setIsActive]);
|
|
32
|
+
const onMouseUp = useCallback(event => {
|
|
33
|
+
providedOnMouseUp(event);
|
|
34
|
+
|
|
35
|
+
if (isFirefox) {
|
|
36
|
+
setIsActive(false);
|
|
37
|
+
}
|
|
38
|
+
}, [providedOnMouseUp, setIsActive]);
|
|
39
|
+
const buttonCss = useMemo(() => getCss({
|
|
40
|
+
appearance,
|
|
41
|
+
spacing,
|
|
42
|
+
mode,
|
|
43
|
+
isSelected,
|
|
44
|
+
shouldFitContainer,
|
|
45
|
+
isOnlySingleIcon
|
|
46
|
+
}), [appearance, spacing, mode, isSelected, shouldFitContainer, isOnlySingleIcon]);
|
|
47
|
+
return /*#__PURE__*/React.createElement(ButtonBase, _extends({}, rest, {
|
|
48
|
+
ref: ref,
|
|
49
|
+
buttonCss: buttonCss // Due to how click events are set, we need to set active styles
|
|
50
|
+
// manually in Firefox and wrap onMouseDown/onMouseUp
|
|
51
|
+
,
|
|
52
|
+
"data-firefox-is-active": isActive ? true : undefined,
|
|
53
|
+
onMouseDown: onMouseDown,
|
|
54
|
+
onMouseUp: onMouseUp
|
|
55
|
+
}));
|
|
56
|
+
});
|
|
57
|
+
const Button = /*#__PURE__*/React.memo( /*#__PURE__*/React.forwardRef(function Button(props, ref) {
|
|
58
|
+
return /*#__PURE__*/React.createElement(GlobalTheme.Consumer, null, ({
|
|
59
|
+
mode
|
|
60
|
+
}) => {
|
|
61
|
+
return /*#__PURE__*/React.createElement(ButtonWithMode, _extends({}, props, {
|
|
62
|
+
ref: ref,
|
|
63
|
+
mode: mode
|
|
64
|
+
}));
|
|
65
|
+
});
|
|
66
|
+
})); // Tools including enzyme rely on components having a display name
|
|
67
|
+
|
|
68
|
+
Button.displayName = 'Button';
|
|
69
|
+
export default Button;
|