@khanacademy/wonder-blocks-button 2.9.13
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/LICENSE +21 -0
- package/dist/es/index.js +402 -0
- package/dist/index.js +668 -0
- package/dist/index.js.flow +2 -0
- package/docs.md +0 -0
- package/package.json +37 -0
- package/src/__tests__/__snapshots__/custom-snapshot.test.js.snap +8710 -0
- package/src/__tests__/__snapshots__/generated-snapshot.test.js.snap +4774 -0
- package/src/__tests__/custom-snapshot.test.js +117 -0
- package/src/__tests__/generated-snapshot.test.js +727 -0
- package/src/components/__tests__/button.flowtest.js +53 -0
- package/src/components/__tests__/button.test.js +826 -0
- package/src/components/button-core.js +375 -0
- package/src/components/button.js +347 -0
- package/src/components/button.md +810 -0
- package/src/components/button.stories.js +276 -0
- package/src/index.js +6 -0
package/dist/index.js
ADDED
|
@@ -0,0 +1,668 @@
|
|
|
1
|
+
module.exports =
|
|
2
|
+
/******/ (function(modules) { // webpackBootstrap
|
|
3
|
+
/******/ // The module cache
|
|
4
|
+
/******/ var installedModules = {};
|
|
5
|
+
/******/
|
|
6
|
+
/******/ // The require function
|
|
7
|
+
/******/ function __webpack_require__(moduleId) {
|
|
8
|
+
/******/
|
|
9
|
+
/******/ // Check if module is in cache
|
|
10
|
+
/******/ if(installedModules[moduleId]) {
|
|
11
|
+
/******/ return installedModules[moduleId].exports;
|
|
12
|
+
/******/ }
|
|
13
|
+
/******/ // Create a new module (and put it into the cache)
|
|
14
|
+
/******/ var module = installedModules[moduleId] = {
|
|
15
|
+
/******/ i: moduleId,
|
|
16
|
+
/******/ l: false,
|
|
17
|
+
/******/ exports: {}
|
|
18
|
+
/******/ };
|
|
19
|
+
/******/
|
|
20
|
+
/******/ // Execute the module function
|
|
21
|
+
/******/ modules[moduleId].call(module.exports, module, module.exports, __webpack_require__);
|
|
22
|
+
/******/
|
|
23
|
+
/******/ // Flag the module as loaded
|
|
24
|
+
/******/ module.l = true;
|
|
25
|
+
/******/
|
|
26
|
+
/******/ // Return the exports of the module
|
|
27
|
+
/******/ return module.exports;
|
|
28
|
+
/******/ }
|
|
29
|
+
/******/
|
|
30
|
+
/******/
|
|
31
|
+
/******/ // expose the modules object (__webpack_modules__)
|
|
32
|
+
/******/ __webpack_require__.m = modules;
|
|
33
|
+
/******/
|
|
34
|
+
/******/ // expose the module cache
|
|
35
|
+
/******/ __webpack_require__.c = installedModules;
|
|
36
|
+
/******/
|
|
37
|
+
/******/ // define getter function for harmony exports
|
|
38
|
+
/******/ __webpack_require__.d = function(exports, name, getter) {
|
|
39
|
+
/******/ if(!__webpack_require__.o(exports, name)) {
|
|
40
|
+
/******/ Object.defineProperty(exports, name, { enumerable: true, get: getter });
|
|
41
|
+
/******/ }
|
|
42
|
+
/******/ };
|
|
43
|
+
/******/
|
|
44
|
+
/******/ // define __esModule on exports
|
|
45
|
+
/******/ __webpack_require__.r = function(exports) {
|
|
46
|
+
/******/ if(typeof Symbol !== 'undefined' && Symbol.toStringTag) {
|
|
47
|
+
/******/ Object.defineProperty(exports, Symbol.toStringTag, { value: 'Module' });
|
|
48
|
+
/******/ }
|
|
49
|
+
/******/ Object.defineProperty(exports, '__esModule', { value: true });
|
|
50
|
+
/******/ };
|
|
51
|
+
/******/
|
|
52
|
+
/******/ // create a fake namespace object
|
|
53
|
+
/******/ // mode & 1: value is a module id, require it
|
|
54
|
+
/******/ // mode & 2: merge all properties of value into the ns
|
|
55
|
+
/******/ // mode & 4: return value when already ns object
|
|
56
|
+
/******/ // mode & 8|1: behave like require
|
|
57
|
+
/******/ __webpack_require__.t = function(value, mode) {
|
|
58
|
+
/******/ if(mode & 1) value = __webpack_require__(value);
|
|
59
|
+
/******/ if(mode & 8) return value;
|
|
60
|
+
/******/ if((mode & 4) && typeof value === 'object' && value && value.__esModule) return value;
|
|
61
|
+
/******/ var ns = Object.create(null);
|
|
62
|
+
/******/ __webpack_require__.r(ns);
|
|
63
|
+
/******/ Object.defineProperty(ns, 'default', { enumerable: true, value: value });
|
|
64
|
+
/******/ if(mode & 2 && typeof value != 'string') for(var key in value) __webpack_require__.d(ns, key, function(key) { return value[key]; }.bind(null, key));
|
|
65
|
+
/******/ return ns;
|
|
66
|
+
/******/ };
|
|
67
|
+
/******/
|
|
68
|
+
/******/ // getDefaultExport function for compatibility with non-harmony modules
|
|
69
|
+
/******/ __webpack_require__.n = function(module) {
|
|
70
|
+
/******/ var getter = module && module.__esModule ?
|
|
71
|
+
/******/ function getDefault() { return module['default']; } :
|
|
72
|
+
/******/ function getModuleExports() { return module; };
|
|
73
|
+
/******/ __webpack_require__.d(getter, 'a', getter);
|
|
74
|
+
/******/ return getter;
|
|
75
|
+
/******/ };
|
|
76
|
+
/******/
|
|
77
|
+
/******/ // Object.prototype.hasOwnProperty.call
|
|
78
|
+
/******/ __webpack_require__.o = function(object, property) { return Object.prototype.hasOwnProperty.call(object, property); };
|
|
79
|
+
/******/
|
|
80
|
+
/******/ // __webpack_public_path__
|
|
81
|
+
/******/ __webpack_require__.p = "";
|
|
82
|
+
/******/
|
|
83
|
+
/******/
|
|
84
|
+
/******/ // Load entry module and return exports
|
|
85
|
+
/******/ return __webpack_require__(__webpack_require__.s = 13);
|
|
86
|
+
/******/ })
|
|
87
|
+
/************************************************************************/
|
|
88
|
+
/******/ ([
|
|
89
|
+
/* 0 */
|
|
90
|
+
/***/ (function(module, exports) {
|
|
91
|
+
|
|
92
|
+
module.exports = require("react");
|
|
93
|
+
|
|
94
|
+
/***/ }),
|
|
95
|
+
/* 1 */
|
|
96
|
+
/***/ (function(module, exports) {
|
|
97
|
+
|
|
98
|
+
function _extends() {
|
|
99
|
+
module.exports = _extends = Object.assign || function (target) {
|
|
100
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
101
|
+
var source = arguments[i];
|
|
102
|
+
|
|
103
|
+
for (var key in source) {
|
|
104
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
105
|
+
target[key] = source[key];
|
|
106
|
+
}
|
|
107
|
+
}
|
|
108
|
+
}
|
|
109
|
+
|
|
110
|
+
return target;
|
|
111
|
+
};
|
|
112
|
+
|
|
113
|
+
module.exports["default"] = module.exports, module.exports.__esModule = true;
|
|
114
|
+
return _extends.apply(this, arguments);
|
|
115
|
+
}
|
|
116
|
+
|
|
117
|
+
module.exports = _extends;
|
|
118
|
+
module.exports["default"] = module.exports, module.exports.__esModule = true;
|
|
119
|
+
|
|
120
|
+
/***/ }),
|
|
121
|
+
/* 2 */
|
|
122
|
+
/***/ (function(module, exports) {
|
|
123
|
+
|
|
124
|
+
module.exports = require("@khanacademy/wonder-blocks-color");
|
|
125
|
+
|
|
126
|
+
/***/ }),
|
|
127
|
+
/* 3 */
|
|
128
|
+
/***/ (function(module, exports) {
|
|
129
|
+
|
|
130
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
131
|
+
if (source == null) return {};
|
|
132
|
+
var target = {};
|
|
133
|
+
var sourceKeys = Object.keys(source);
|
|
134
|
+
var key, i;
|
|
135
|
+
|
|
136
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
137
|
+
key = sourceKeys[i];
|
|
138
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
139
|
+
target[key] = source[key];
|
|
140
|
+
}
|
|
141
|
+
|
|
142
|
+
return target;
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
module.exports = _objectWithoutPropertiesLoose;
|
|
146
|
+
module.exports["default"] = module.exports, module.exports.__esModule = true;
|
|
147
|
+
|
|
148
|
+
/***/ }),
|
|
149
|
+
/* 4 */
|
|
150
|
+
/***/ (function(module, exports) {
|
|
151
|
+
|
|
152
|
+
module.exports = require("prop-types");
|
|
153
|
+
|
|
154
|
+
/***/ }),
|
|
155
|
+
/* 5 */
|
|
156
|
+
/***/ (function(module, exports) {
|
|
157
|
+
|
|
158
|
+
module.exports = require("@khanacademy/wonder-blocks-clickable");
|
|
159
|
+
|
|
160
|
+
/***/ }),
|
|
161
|
+
/* 6 */
|
|
162
|
+
/***/ (function(module, exports) {
|
|
163
|
+
|
|
164
|
+
module.exports = require("@khanacademy/wonder-blocks-core");
|
|
165
|
+
|
|
166
|
+
/***/ }),
|
|
167
|
+
/* 7 */
|
|
168
|
+
/***/ (function(module, exports) {
|
|
169
|
+
|
|
170
|
+
module.exports = require("@khanacademy/wonder-blocks-spacing");
|
|
171
|
+
|
|
172
|
+
/***/ }),
|
|
173
|
+
/* 8 */
|
|
174
|
+
/***/ (function(module, exports) {
|
|
175
|
+
|
|
176
|
+
module.exports = require("aphrodite");
|
|
177
|
+
|
|
178
|
+
/***/ }),
|
|
179
|
+
/* 9 */
|
|
180
|
+
/***/ (function(module, exports) {
|
|
181
|
+
|
|
182
|
+
module.exports = require("@khanacademy/wonder-blocks-typography");
|
|
183
|
+
|
|
184
|
+
/***/ }),
|
|
185
|
+
/* 10 */
|
|
186
|
+
/***/ (function(module, exports) {
|
|
187
|
+
|
|
188
|
+
module.exports = require("react-router-dom");
|
|
189
|
+
|
|
190
|
+
/***/ }),
|
|
191
|
+
/* 11 */
|
|
192
|
+
/***/ (function(module, exports) {
|
|
193
|
+
|
|
194
|
+
module.exports = require("@khanacademy/wonder-blocks-progress-spinner");
|
|
195
|
+
|
|
196
|
+
/***/ }),
|
|
197
|
+
/* 12 */
|
|
198
|
+
/***/ (function(module, exports) {
|
|
199
|
+
|
|
200
|
+
module.exports = require("@khanacademy/wonder-blocks-icon");
|
|
201
|
+
|
|
202
|
+
/***/ }),
|
|
203
|
+
/* 13 */
|
|
204
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
205
|
+
|
|
206
|
+
"use strict";
|
|
207
|
+
// ESM COMPAT FLAG
|
|
208
|
+
__webpack_require__.r(__webpack_exports__);
|
|
209
|
+
|
|
210
|
+
// EXPORTS
|
|
211
|
+
__webpack_require__.d(__webpack_exports__, "default", function() { return /* reexport */ button_Button; });
|
|
212
|
+
|
|
213
|
+
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/extends.js
|
|
214
|
+
var helpers_extends = __webpack_require__(1);
|
|
215
|
+
var extends_default = /*#__PURE__*/__webpack_require__.n(helpers_extends);
|
|
216
|
+
|
|
217
|
+
// EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/objectWithoutPropertiesLoose.js
|
|
218
|
+
var objectWithoutPropertiesLoose = __webpack_require__(3);
|
|
219
|
+
var objectWithoutPropertiesLoose_default = /*#__PURE__*/__webpack_require__.n(objectWithoutPropertiesLoose);
|
|
220
|
+
|
|
221
|
+
// EXTERNAL MODULE: external "react"
|
|
222
|
+
var external_react_ = __webpack_require__(0);
|
|
223
|
+
|
|
224
|
+
// EXTERNAL MODULE: external "prop-types"
|
|
225
|
+
var external_prop_types_ = __webpack_require__(4);
|
|
226
|
+
|
|
227
|
+
// EXTERNAL MODULE: external "@khanacademy/wonder-blocks-clickable"
|
|
228
|
+
var wonder_blocks_clickable_ = __webpack_require__(5);
|
|
229
|
+
|
|
230
|
+
// EXTERNAL MODULE: external "aphrodite"
|
|
231
|
+
var external_aphrodite_ = __webpack_require__(8);
|
|
232
|
+
|
|
233
|
+
// EXTERNAL MODULE: external "react-router-dom"
|
|
234
|
+
var external_react_router_dom_ = __webpack_require__(10);
|
|
235
|
+
|
|
236
|
+
// EXTERNAL MODULE: external "@khanacademy/wonder-blocks-typography"
|
|
237
|
+
var wonder_blocks_typography_ = __webpack_require__(9);
|
|
238
|
+
|
|
239
|
+
// EXTERNAL MODULE: external "@khanacademy/wonder-blocks-color"
|
|
240
|
+
var wonder_blocks_color_ = __webpack_require__(2);
|
|
241
|
+
var wonder_blocks_color_default = /*#__PURE__*/__webpack_require__.n(wonder_blocks_color_);
|
|
242
|
+
|
|
243
|
+
// EXTERNAL MODULE: external "@khanacademy/wonder-blocks-core"
|
|
244
|
+
var wonder_blocks_core_ = __webpack_require__(6);
|
|
245
|
+
|
|
246
|
+
// EXTERNAL MODULE: external "@khanacademy/wonder-blocks-progress-spinner"
|
|
247
|
+
var wonder_blocks_progress_spinner_ = __webpack_require__(11);
|
|
248
|
+
|
|
249
|
+
// EXTERNAL MODULE: external "@khanacademy/wonder-blocks-icon"
|
|
250
|
+
var wonder_blocks_icon_ = __webpack_require__(12);
|
|
251
|
+
var wonder_blocks_icon_default = /*#__PURE__*/__webpack_require__.n(wonder_blocks_icon_);
|
|
252
|
+
|
|
253
|
+
// EXTERNAL MODULE: external "@khanacademy/wonder-blocks-spacing"
|
|
254
|
+
var wonder_blocks_spacing_ = __webpack_require__(7);
|
|
255
|
+
var wonder_blocks_spacing_default = /*#__PURE__*/__webpack_require__.n(wonder_blocks_spacing_);
|
|
256
|
+
|
|
257
|
+
// CONCATENATED MODULE: ./packages/wonder-blocks-button/src/components/button-core.js
|
|
258
|
+
|
|
259
|
+
|
|
260
|
+
const _excluded = ["children", "skipClientNav", "color", "disabled", "focused", "hovered", "href", "kind", "light", "pressed", "size", "style", "testId", "type", "spinner", "icon", "id", "waiting"];
|
|
261
|
+
|
|
262
|
+
|
|
263
|
+
|
|
264
|
+
|
|
265
|
+
|
|
266
|
+
|
|
267
|
+
|
|
268
|
+
|
|
269
|
+
|
|
270
|
+
|
|
271
|
+
|
|
272
|
+
const StyledAnchor = Object(wonder_blocks_core_["addStyle"])("a");
|
|
273
|
+
const StyledButton = Object(wonder_blocks_core_["addStyle"])("button");
|
|
274
|
+
const StyledLink = Object(wonder_blocks_core_["addStyle"])(external_react_router_dom_["Link"]);
|
|
275
|
+
class button_core_ButtonCore extends external_react_["Component"] {
|
|
276
|
+
render() {
|
|
277
|
+
const _this$props = this.props,
|
|
278
|
+
{
|
|
279
|
+
children,
|
|
280
|
+
skipClientNav,
|
|
281
|
+
color,
|
|
282
|
+
disabled: disabledProp,
|
|
283
|
+
focused,
|
|
284
|
+
hovered,
|
|
285
|
+
href = undefined,
|
|
286
|
+
kind,
|
|
287
|
+
light,
|
|
288
|
+
pressed,
|
|
289
|
+
size,
|
|
290
|
+
style,
|
|
291
|
+
testId,
|
|
292
|
+
type = undefined,
|
|
293
|
+
spinner,
|
|
294
|
+
icon,
|
|
295
|
+
id
|
|
296
|
+
} = _this$props,
|
|
297
|
+
restProps = objectWithoutPropertiesLoose_default()(_this$props, _excluded);
|
|
298
|
+
|
|
299
|
+
const {
|
|
300
|
+
router
|
|
301
|
+
} = this.context;
|
|
302
|
+
const buttonColor = color === "destructive" ? wonder_blocks_color_["SemanticColor"].controlDestructive : wonder_blocks_color_["SemanticColor"].controlDefault;
|
|
303
|
+
const iconWidth = icon ? (size === "small" ? 16 : 24) + 8 : 0;
|
|
304
|
+
|
|
305
|
+
const buttonStyles = _generateStyles(buttonColor, kind, light, iconWidth, size);
|
|
306
|
+
|
|
307
|
+
const disabled = spinner || disabledProp;
|
|
308
|
+
const defaultStyle = [sharedStyles.shared, disabled && sharedStyles.disabled, icon && sharedStyles.withIcon, buttonStyles.default, disabled && buttonStyles.disabled, // apply focus effect only to default and secondary buttons
|
|
309
|
+
kind !== "tertiary" && !disabled && (pressed ? buttonStyles.active : (hovered || focused) && buttonStyles.focus), size === "small" && sharedStyles.small, size === "xlarge" && sharedStyles.xlarge];
|
|
310
|
+
|
|
311
|
+
const commonProps = extends_default()({
|
|
312
|
+
"data-test-id": testId,
|
|
313
|
+
id: id,
|
|
314
|
+
role: "button",
|
|
315
|
+
style: [defaultStyle, style]
|
|
316
|
+
}, restProps);
|
|
317
|
+
|
|
318
|
+
const Label = size === "small" ? wonder_blocks_typography_["LabelSmall"] : wonder_blocks_typography_["LabelLarge"];
|
|
319
|
+
const label = /*#__PURE__*/external_react_["createElement"](Label, {
|
|
320
|
+
style: [sharedStyles.text, size === "xlarge" && sharedStyles.xlargeText, icon && sharedStyles.textWithIcon, spinner && sharedStyles.hiddenText, kind === "tertiary" && sharedStyles.textWithFocus, // apply focus effect on the label instead
|
|
321
|
+
kind === "tertiary" && !disabled && (pressed ? buttonStyles.active : (hovered || focused) && buttonStyles.focus)]
|
|
322
|
+
}, icon && /*#__PURE__*/external_react_["createElement"](wonder_blocks_icon_default.a, {
|
|
323
|
+
size: size,
|
|
324
|
+
color: "currentColor",
|
|
325
|
+
icon: icon,
|
|
326
|
+
style: sharedStyles.icon
|
|
327
|
+
}), children);
|
|
328
|
+
const contents = /*#__PURE__*/external_react_["createElement"](external_react_["Fragment"], null, label, spinner && /*#__PURE__*/external_react_["createElement"](wonder_blocks_progress_spinner_["CircularSpinner"], {
|
|
329
|
+
style: sharedStyles.spinner,
|
|
330
|
+
size: {
|
|
331
|
+
medium: "small",
|
|
332
|
+
small: "xsmall",
|
|
333
|
+
xlarge: "medium"
|
|
334
|
+
}[size],
|
|
335
|
+
light: kind === "primary"
|
|
336
|
+
}));
|
|
337
|
+
|
|
338
|
+
if (href && !disabled) {
|
|
339
|
+
return router && !skipClientNav && Object(wonder_blocks_clickable_["isClientSideUrl"])(href) ? /*#__PURE__*/external_react_["createElement"](StyledLink, extends_default()({}, commonProps, {
|
|
340
|
+
to: href
|
|
341
|
+
}), contents) : /*#__PURE__*/external_react_["createElement"](StyledAnchor, extends_default()({}, commonProps, {
|
|
342
|
+
href: href
|
|
343
|
+
}), contents);
|
|
344
|
+
} else {
|
|
345
|
+
return /*#__PURE__*/external_react_["createElement"](StyledButton, extends_default()({
|
|
346
|
+
type: type || "button"
|
|
347
|
+
}, commonProps, {
|
|
348
|
+
disabled: disabled
|
|
349
|
+
}), contents);
|
|
350
|
+
}
|
|
351
|
+
}
|
|
352
|
+
|
|
353
|
+
}
|
|
354
|
+
button_core_ButtonCore.contextTypes = {
|
|
355
|
+
router: external_prop_types_["any"]
|
|
356
|
+
};
|
|
357
|
+
const sharedStyles = external_aphrodite_["StyleSheet"].create({
|
|
358
|
+
shared: {
|
|
359
|
+
position: "relative",
|
|
360
|
+
display: "inline-flex",
|
|
361
|
+
alignItems: "center",
|
|
362
|
+
justifyContent: "center",
|
|
363
|
+
height: 40,
|
|
364
|
+
paddingTop: 0,
|
|
365
|
+
paddingBottom: 0,
|
|
366
|
+
paddingLeft: 16,
|
|
367
|
+
paddingRight: 16,
|
|
368
|
+
border: "none",
|
|
369
|
+
borderRadius: 4,
|
|
370
|
+
cursor: "pointer",
|
|
371
|
+
outline: "none",
|
|
372
|
+
textDecoration: "none",
|
|
373
|
+
boxSizing: "border-box",
|
|
374
|
+
// This removes the 300ms click delay on mobile browsers by indicating that
|
|
375
|
+
// "double-tap to zoom" shouldn't be used on this element.
|
|
376
|
+
touchAction: "manipulation",
|
|
377
|
+
userSelect: "none",
|
|
378
|
+
":focus": {
|
|
379
|
+
// Mobile: Removes a blue highlight style shown when the user clicks a button
|
|
380
|
+
WebkitTapHighlightColor: "rgba(0,0,0,0)"
|
|
381
|
+
}
|
|
382
|
+
},
|
|
383
|
+
withIcon: {
|
|
384
|
+
// The left padding for the button with icon should have 4px less padding
|
|
385
|
+
paddingLeft: 12
|
|
386
|
+
},
|
|
387
|
+
disabled: {
|
|
388
|
+
cursor: "auto"
|
|
389
|
+
},
|
|
390
|
+
small: {
|
|
391
|
+
height: 32
|
|
392
|
+
},
|
|
393
|
+
xlarge: {
|
|
394
|
+
height: 60
|
|
395
|
+
},
|
|
396
|
+
text: {
|
|
397
|
+
alignItems: "center",
|
|
398
|
+
fontWeight: "bold",
|
|
399
|
+
whiteSpace: "nowrap",
|
|
400
|
+
overflow: "hidden",
|
|
401
|
+
textOverflow: "ellipsis",
|
|
402
|
+
display: "inline-block",
|
|
403
|
+
// allows the button text to truncate
|
|
404
|
+
pointerEvents: "none" // fix Safari bug where the browser was eating mouse events
|
|
405
|
+
|
|
406
|
+
},
|
|
407
|
+
xlargeText: {
|
|
408
|
+
fontSize: 18,
|
|
409
|
+
lineHeight: "20px"
|
|
410
|
+
},
|
|
411
|
+
textWithIcon: {
|
|
412
|
+
display: "flex" // allows the text and icon to sit nicely together
|
|
413
|
+
|
|
414
|
+
},
|
|
415
|
+
textWithFocus: {
|
|
416
|
+
position: "relative" // allows the tertiary button border to use the label width
|
|
417
|
+
|
|
418
|
+
},
|
|
419
|
+
hiddenText: {
|
|
420
|
+
visibility: "hidden"
|
|
421
|
+
},
|
|
422
|
+
spinner: {
|
|
423
|
+
position: "absolute"
|
|
424
|
+
},
|
|
425
|
+
icon: {
|
|
426
|
+
paddingRight: wonder_blocks_spacing_default.a.xSmall_8
|
|
427
|
+
}
|
|
428
|
+
});
|
|
429
|
+
const styles = {};
|
|
430
|
+
|
|
431
|
+
const _generateStyles = (color, kind, light, iconWidth, size) => {
|
|
432
|
+
const buttonType = color + kind + light.toString() + iconWidth.toString() + size;
|
|
433
|
+
|
|
434
|
+
if (styles[buttonType]) {
|
|
435
|
+
return styles[buttonType];
|
|
436
|
+
}
|
|
437
|
+
|
|
438
|
+
const {
|
|
439
|
+
white,
|
|
440
|
+
white50,
|
|
441
|
+
white64,
|
|
442
|
+
offBlack32,
|
|
443
|
+
offBlack50,
|
|
444
|
+
darkBlue
|
|
445
|
+
} = wonder_blocks_color_default.a;
|
|
446
|
+
const fadedColor = Object(wonder_blocks_color_["mix"])(Object(wonder_blocks_color_["fade"])(color, 0.32), white);
|
|
447
|
+
const activeColor = Object(wonder_blocks_color_["mix"])(offBlack32, color);
|
|
448
|
+
const padding = size === "xlarge" ? wonder_blocks_spacing_default.a.xLarge_32 : wonder_blocks_spacing_default.a.medium_16;
|
|
449
|
+
let newStyles = {};
|
|
450
|
+
|
|
451
|
+
if (kind === "primary") {
|
|
452
|
+
newStyles = {
|
|
453
|
+
default: {
|
|
454
|
+
background: light ? white : color,
|
|
455
|
+
color: light ? color : white,
|
|
456
|
+
paddingLeft: padding,
|
|
457
|
+
paddingRight: padding
|
|
458
|
+
},
|
|
459
|
+
focus: {
|
|
460
|
+
// This assumes a background of white for the regular button and
|
|
461
|
+
// a background of darkBlue for the light version. The inner
|
|
462
|
+
// box shadow/ring is also small enough for a slight variation
|
|
463
|
+
// in the background color not to matter too much.
|
|
464
|
+
boxShadow: `0 0 0 1px ${light ? darkBlue : white}, 0 0 0 3px ${light ? white : color}`
|
|
465
|
+
},
|
|
466
|
+
active: {
|
|
467
|
+
boxShadow: `0 0 0 1px ${light ? darkBlue : white}, 0 0 0 3px ${light ? fadedColor : activeColor}`,
|
|
468
|
+
background: light ? fadedColor : activeColor,
|
|
469
|
+
color: light ? activeColor : fadedColor
|
|
470
|
+
},
|
|
471
|
+
disabled: {
|
|
472
|
+
background: light ? fadedColor : offBlack32,
|
|
473
|
+
color: light ? color : white64,
|
|
474
|
+
cursor: "default"
|
|
475
|
+
}
|
|
476
|
+
};
|
|
477
|
+
} else if (kind === "secondary") {
|
|
478
|
+
newStyles = {
|
|
479
|
+
default: {
|
|
480
|
+
background: "none",
|
|
481
|
+
color: light ? white : color,
|
|
482
|
+
borderColor: light ? white50 : offBlack50,
|
|
483
|
+
borderStyle: "solid",
|
|
484
|
+
borderWidth: 1,
|
|
485
|
+
paddingLeft: iconWidth ? padding - 4 : padding,
|
|
486
|
+
paddingRight: padding
|
|
487
|
+
},
|
|
488
|
+
focus: {
|
|
489
|
+
background: light ? "transparent" : white,
|
|
490
|
+
borderColor: light ? white : color,
|
|
491
|
+
borderWidth: 2,
|
|
492
|
+
// The left padding for the button with icon should have 4px
|
|
493
|
+
// less padding
|
|
494
|
+
paddingLeft: iconWidth ? padding - 5 : padding - 1,
|
|
495
|
+
paddingRight: padding - 1
|
|
496
|
+
},
|
|
497
|
+
active: {
|
|
498
|
+
background: light ? activeColor : fadedColor,
|
|
499
|
+
color: light ? fadedColor : activeColor,
|
|
500
|
+
borderColor: light ? fadedColor : activeColor,
|
|
501
|
+
borderWidth: 2,
|
|
502
|
+
// The left padding for the button with icon should have 4px
|
|
503
|
+
// less padding
|
|
504
|
+
paddingLeft: iconWidth ? padding - 5 : padding - 1,
|
|
505
|
+
paddingRight: padding - 1
|
|
506
|
+
},
|
|
507
|
+
disabled: {
|
|
508
|
+
color: light ? white50 : offBlack32,
|
|
509
|
+
borderColor: light ? fadedColor : offBlack32,
|
|
510
|
+
cursor: "default"
|
|
511
|
+
}
|
|
512
|
+
};
|
|
513
|
+
} else if (kind === "tertiary") {
|
|
514
|
+
newStyles = {
|
|
515
|
+
default: {
|
|
516
|
+
background: "none",
|
|
517
|
+
color: light ? white : color,
|
|
518
|
+
paddingLeft: 0,
|
|
519
|
+
paddingRight: 0
|
|
520
|
+
},
|
|
521
|
+
focus: {
|
|
522
|
+
":after": {
|
|
523
|
+
content: "''",
|
|
524
|
+
position: "absolute",
|
|
525
|
+
height: 2,
|
|
526
|
+
width: `calc(100% - ${iconWidth}px)`,
|
|
527
|
+
right: 0,
|
|
528
|
+
bottom: 0,
|
|
529
|
+
background: light ? white : color,
|
|
530
|
+
borderRadius: 2
|
|
531
|
+
}
|
|
532
|
+
},
|
|
533
|
+
active: {
|
|
534
|
+
color: light ? fadedColor : activeColor,
|
|
535
|
+
":after": {
|
|
536
|
+
content: "''",
|
|
537
|
+
position: "absolute",
|
|
538
|
+
height: 2,
|
|
539
|
+
width: `calc(100% - ${iconWidth}px)`,
|
|
540
|
+
right: 0,
|
|
541
|
+
bottom: "calc(50% - 11px)",
|
|
542
|
+
background: light ? fadedColor : activeColor,
|
|
543
|
+
borderRadius: 2
|
|
544
|
+
}
|
|
545
|
+
},
|
|
546
|
+
disabled: {
|
|
547
|
+
color: light ? fadedColor : offBlack32,
|
|
548
|
+
cursor: "default"
|
|
549
|
+
}
|
|
550
|
+
};
|
|
551
|
+
} else {
|
|
552
|
+
throw new Error("Button kind not recognized");
|
|
553
|
+
}
|
|
554
|
+
|
|
555
|
+
styles[buttonType] = external_aphrodite_["StyleSheet"].create(newStyles);
|
|
556
|
+
return styles[buttonType];
|
|
557
|
+
};
|
|
558
|
+
// CONCATENATED MODULE: ./packages/wonder-blocks-button/src/components/button.js
|
|
559
|
+
|
|
560
|
+
|
|
561
|
+
const button_excluded = ["href", "type", "children", "skipClientNav", "spinner", "disabled", "onClick", "beforeNav", "safeWithNav", "tabIndex", "target", "rel"],
|
|
562
|
+
_excluded2 = ["tabIndex"];
|
|
563
|
+
|
|
564
|
+
|
|
565
|
+
|
|
566
|
+
|
|
567
|
+
|
|
568
|
+
/**
|
|
569
|
+
* Reusable button component.
|
|
570
|
+
*
|
|
571
|
+
* Consisting of a [`ClickableBehavior`](#clickablebehavior) surrounding a
|
|
572
|
+
* `ButtonCore`. `ClickableBehavior` handles interactions and state changes.
|
|
573
|
+
* `ButtonCore` is a stateless component which displays the different states
|
|
574
|
+
* the `Button` can take.
|
|
575
|
+
*
|
|
576
|
+
* Example usage:
|
|
577
|
+
* ```jsx
|
|
578
|
+
* <Button
|
|
579
|
+
* onClick={(e) => console.log("Hello, world!")}
|
|
580
|
+
* >
|
|
581
|
+
* Label
|
|
582
|
+
* </Button>
|
|
583
|
+
* ```
|
|
584
|
+
*/
|
|
585
|
+
class button_Button extends external_react_["Component"] {
|
|
586
|
+
render() {
|
|
587
|
+
const _this$props = this.props,
|
|
588
|
+
{
|
|
589
|
+
href = undefined,
|
|
590
|
+
type = undefined,
|
|
591
|
+
children,
|
|
592
|
+
skipClientNav,
|
|
593
|
+
spinner,
|
|
594
|
+
disabled,
|
|
595
|
+
onClick,
|
|
596
|
+
beforeNav = undefined,
|
|
597
|
+
safeWithNav = undefined,
|
|
598
|
+
tabIndex,
|
|
599
|
+
target,
|
|
600
|
+
rel
|
|
601
|
+
} = _this$props,
|
|
602
|
+
sharedButtonCoreProps = objectWithoutPropertiesLoose_default()(_this$props, button_excluded);
|
|
603
|
+
|
|
604
|
+
const ClickableBehavior = Object(wonder_blocks_clickable_["getClickableBehavior"])(href, skipClientNav, this.context.router);
|
|
605
|
+
|
|
606
|
+
const renderProp = (state, _ref) => {
|
|
607
|
+
let {
|
|
608
|
+
tabIndex: clickableTabIndex
|
|
609
|
+
} = _ref,
|
|
610
|
+
restChildProps = objectWithoutPropertiesLoose_default()(_ref, _excluded2);
|
|
611
|
+
|
|
612
|
+
return /*#__PURE__*/external_react_["createElement"](button_core_ButtonCore, extends_default()({}, sharedButtonCoreProps, state, restChildProps, {
|
|
613
|
+
disabled: disabled,
|
|
614
|
+
spinner: spinner || state.waiting,
|
|
615
|
+
skipClientNav: skipClientNav,
|
|
616
|
+
href: href,
|
|
617
|
+
target: target,
|
|
618
|
+
type: type // If tabIndex is provide to the component we allow
|
|
619
|
+
// it to override the tabIndex provide to use by
|
|
620
|
+
// ClickableBehavior.
|
|
621
|
+
,
|
|
622
|
+
tabIndex: tabIndex || clickableTabIndex
|
|
623
|
+
}), children);
|
|
624
|
+
};
|
|
625
|
+
|
|
626
|
+
if (beforeNav) {
|
|
627
|
+
return /*#__PURE__*/external_react_["createElement"](ClickableBehavior, {
|
|
628
|
+
disabled: spinner || disabled,
|
|
629
|
+
href: href,
|
|
630
|
+
role: "button",
|
|
631
|
+
type: type,
|
|
632
|
+
onClick: onClick,
|
|
633
|
+
beforeNav: beforeNav,
|
|
634
|
+
safeWithNav: safeWithNav,
|
|
635
|
+
rel: rel
|
|
636
|
+
}, renderProp);
|
|
637
|
+
} else {
|
|
638
|
+
return /*#__PURE__*/external_react_["createElement"](ClickableBehavior, {
|
|
639
|
+
disabled: spinner || disabled,
|
|
640
|
+
href: href,
|
|
641
|
+
role: "button",
|
|
642
|
+
type: type,
|
|
643
|
+
onClick: onClick,
|
|
644
|
+
safeWithNav: safeWithNav,
|
|
645
|
+
target: target,
|
|
646
|
+
rel: rel
|
|
647
|
+
}, renderProp);
|
|
648
|
+
}
|
|
649
|
+
}
|
|
650
|
+
|
|
651
|
+
}
|
|
652
|
+
button_Button.contextTypes = {
|
|
653
|
+
router: external_prop_types_["any"]
|
|
654
|
+
};
|
|
655
|
+
button_Button.defaultProps = {
|
|
656
|
+
color: "default",
|
|
657
|
+
kind: "primary",
|
|
658
|
+
light: false,
|
|
659
|
+
size: "medium",
|
|
660
|
+
disabled: false,
|
|
661
|
+
spinner: false
|
|
662
|
+
};
|
|
663
|
+
// CONCATENATED MODULE: ./packages/wonder-blocks-button/src/index.js
|
|
664
|
+
|
|
665
|
+
|
|
666
|
+
|
|
667
|
+
/***/ })
|
|
668
|
+
/******/ ]);
|
package/docs.md
ADDED
|
File without changes
|