@khanacademy/wonder-blocks-button 3.0.13 → 3.0.15
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 +46 -0
- package/dist/components/button-core.d.ts +9 -0
- package/dist/components/button-core.js.flow +18 -0
- package/dist/components/button.d.ts +178 -0
- package/dist/components/button.js.flow +203 -0
- package/dist/es/index.js +108 -75
- package/dist/index.d.ts +4 -0
- package/dist/index.js +127 -96
- package/dist/index.js.flow +11 -2
- package/package.json +10 -10
- package/src/__tests__/{custom-snapshot.test.js → custom-snapshot.test.tsx} +13 -14
- package/src/components/__tests__/{button.flowtest.js → button.flowtest.tsx} +1 -6
- package/src/components/__tests__/{button.test.js → button.test.tsx} +17 -19
- package/src/components/{button-core.js → button-core.tsx} +24 -25
- package/src/components/button.tsx +298 -0
- package/src/index.ts +5 -0
- package/tsconfig.json +17 -0
- package/tsconfig.tsbuildinfo +1 -0
- package/src/components/__docs__/accessibility.stories.mdx +0 -92
- package/src/components/__docs__/best-practices.stories.mdx +0 -107
- package/src/components/__docs__/button.argtypes.js +0 -231
- package/src/components/__docs__/button.stories.js +0 -508
- package/src/components/__docs__/navigation-callbacks.stories.mdx +0 -187
- package/src/components/button.js +0 -347
- package/src/index.js +0 -6
- /package/src/__tests__/__snapshots__/{custom-snapshot.test.js.snap → custom-snapshot.test.tsx.snap} +0 -0
package/dist/es/index.js
CHANGED
|
@@ -1,5 +1,3 @@
|
|
|
1
|
-
import _extends from '@babel/runtime/helpers/extends';
|
|
2
|
-
import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/objectWithoutPropertiesLoose';
|
|
3
1
|
import * as React from 'react';
|
|
4
2
|
import { __RouterContext } from 'react-router';
|
|
5
3
|
import { isClientSideUrl, getClickableBehavior } from '@khanacademy/wonder-blocks-clickable';
|
|
@@ -12,49 +10,91 @@ import { CircularSpinner } from '@khanacademy/wonder-blocks-progress-spinner';
|
|
|
12
10
|
import Icon from '@khanacademy/wonder-blocks-icon';
|
|
13
11
|
import Spacing from '@khanacademy/wonder-blocks-spacing';
|
|
14
12
|
|
|
13
|
+
function _extends() {
|
|
14
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
15
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
16
|
+
var source = arguments[i];
|
|
17
|
+
for (var key in source) {
|
|
18
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
19
|
+
target[key] = source[key];
|
|
20
|
+
}
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
return target;
|
|
24
|
+
};
|
|
25
|
+
return _extends.apply(this, arguments);
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
29
|
+
if (source == null) return {};
|
|
30
|
+
var target = {};
|
|
31
|
+
var sourceKeys = Object.keys(source);
|
|
32
|
+
var key, i;
|
|
33
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
34
|
+
key = sourceKeys[i];
|
|
35
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
36
|
+
target[key] = source[key];
|
|
37
|
+
}
|
|
38
|
+
return target;
|
|
39
|
+
}
|
|
40
|
+
|
|
41
|
+
function _setPrototypeOf(o, p) {
|
|
42
|
+
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
43
|
+
o.__proto__ = p;
|
|
44
|
+
return o;
|
|
45
|
+
};
|
|
46
|
+
return _setPrototypeOf(o, p);
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
function _inheritsLoose(subClass, superClass) {
|
|
50
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
51
|
+
subClass.prototype.constructor = subClass;
|
|
52
|
+
_setPrototypeOf(subClass, superClass);
|
|
53
|
+
}
|
|
54
|
+
|
|
15
55
|
const _excluded$1 = ["children", "skipClientNav", "color", "disabled", "focused", "hovered", "href", "kind", "light", "pressed", "size", "style", "testId", "type", "spinner", "icon", "id", "waiting"];
|
|
16
56
|
const StyledAnchor = addStyle("a");
|
|
17
57
|
const StyledButton = addStyle("button");
|
|
18
58
|
const StyledLink = addStyle(Link);
|
|
19
|
-
|
|
20
|
-
|
|
59
|
+
let ButtonCore = function (_React$Component) {
|
|
60
|
+
_inheritsLoose(ButtonCore, _React$Component);
|
|
61
|
+
function ButtonCore() {
|
|
62
|
+
return _React$Component.apply(this, arguments) || this;
|
|
63
|
+
}
|
|
64
|
+
var _proto = ButtonCore.prototype;
|
|
65
|
+
_proto.renderInner = function renderInner(router) {
|
|
21
66
|
const _this$props = this.props,
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
|
|
67
|
+
{
|
|
68
|
+
children,
|
|
69
|
+
skipClientNav,
|
|
70
|
+
color,
|
|
71
|
+
disabled: disabledProp,
|
|
72
|
+
focused,
|
|
73
|
+
hovered,
|
|
74
|
+
href = undefined,
|
|
75
|
+
kind,
|
|
76
|
+
light,
|
|
77
|
+
pressed,
|
|
78
|
+
size,
|
|
79
|
+
style,
|
|
80
|
+
testId,
|
|
81
|
+
type = undefined,
|
|
82
|
+
spinner,
|
|
83
|
+
icon,
|
|
84
|
+
id
|
|
85
|
+
} = _this$props,
|
|
86
|
+
restProps = _objectWithoutPropertiesLoose(_this$props, _excluded$1);
|
|
43
87
|
const buttonColor = color === "destructive" ? SemanticColor.controlDestructive : SemanticColor.controlDefault;
|
|
44
88
|
const iconWidth = icon ? (size === "small" ? 16 : 24) + 8 : 0;
|
|
45
|
-
|
|
46
89
|
const buttonStyles = _generateStyles(buttonColor, kind, light, iconWidth, size);
|
|
47
|
-
|
|
48
90
|
const disabled = spinner || disabledProp;
|
|
49
91
|
const defaultStyle = [sharedStyles.shared, disabled && sharedStyles.disabled, icon && sharedStyles.withIcon, buttonStyles.default, disabled && buttonStyles.disabled, kind !== "tertiary" && !disabled && (pressed ? buttonStyles.active : (hovered || focused) && buttonStyles.focus), size === "small" && sharedStyles.small, size === "large" && sharedStyles.large];
|
|
50
|
-
|
|
51
92
|
const commonProps = _extends({
|
|
52
93
|
"data-test-id": testId,
|
|
53
94
|
id: id,
|
|
54
95
|
role: "button",
|
|
55
96
|
style: [defaultStyle, style]
|
|
56
97
|
}, restProps);
|
|
57
|
-
|
|
58
98
|
const Label = size === "small" ? LabelSmall : LabelLarge;
|
|
59
99
|
const iconSize = size === "small" ? "small" : "medium";
|
|
60
100
|
const label = React.createElement(Label, {
|
|
@@ -65,17 +105,17 @@ class ButtonCore extends React.Component {
|
|
|
65
105
|
icon: icon,
|
|
66
106
|
style: sharedStyles.icon
|
|
67
107
|
}), children);
|
|
108
|
+
const sizeMapping = {
|
|
109
|
+
medium: "small",
|
|
110
|
+
small: "xsmall",
|
|
111
|
+
large: "medium"
|
|
112
|
+
};
|
|
68
113
|
const contents = React.createElement(React.Fragment, null, label, spinner && React.createElement(CircularSpinner, {
|
|
69
114
|
style: sharedStyles.spinner,
|
|
70
|
-
size:
|
|
71
|
-
medium: "small",
|
|
72
|
-
small: "xsmall",
|
|
73
|
-
large: "medium"
|
|
74
|
-
}[size],
|
|
115
|
+
size: sizeMapping[size],
|
|
75
116
|
light: kind === "primary",
|
|
76
117
|
testId: `${testId || "button"}-spinner`
|
|
77
118
|
}));
|
|
78
|
-
|
|
79
119
|
if (href && !disabled) {
|
|
80
120
|
return router && !skipClientNav && isClientSideUrl(href) ? React.createElement(StyledLink, _extends({}, commonProps, {
|
|
81
121
|
to: href
|
|
@@ -89,13 +129,12 @@ class ButtonCore extends React.Component {
|
|
|
89
129
|
"aria-disabled": disabled
|
|
90
130
|
}), contents);
|
|
91
131
|
}
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
render() {
|
|
132
|
+
};
|
|
133
|
+
_proto.render = function render() {
|
|
95
134
|
return React.createElement(__RouterContext.Consumer, null, router => this.renderInner(router));
|
|
96
|
-
}
|
|
97
|
-
|
|
98
|
-
}
|
|
135
|
+
};
|
|
136
|
+
return ButtonCore;
|
|
137
|
+
}(React.Component);
|
|
99
138
|
const sharedStyles = StyleSheet.create({
|
|
100
139
|
shared: {
|
|
101
140
|
position: "relative",
|
|
@@ -162,14 +201,11 @@ const sharedStyles = StyleSheet.create({
|
|
|
162
201
|
}
|
|
163
202
|
});
|
|
164
203
|
const styles = {};
|
|
165
|
-
|
|
166
204
|
const _generateStyles = (color, kind, light, iconWidth, size) => {
|
|
167
205
|
const buttonType = color + kind + light.toString() + iconWidth.toString() + size;
|
|
168
|
-
|
|
169
206
|
if (styles[buttonType]) {
|
|
170
207
|
return styles[buttonType];
|
|
171
208
|
}
|
|
172
|
-
|
|
173
209
|
const {
|
|
174
210
|
white,
|
|
175
211
|
white50,
|
|
@@ -182,7 +218,6 @@ const _generateStyles = (color, kind, light, iconWidth, size) => {
|
|
|
182
218
|
const activeColor = mix(offBlack32, color);
|
|
183
219
|
const padding = size === "large" ? Spacing.xLarge_32 : Spacing.medium_16;
|
|
184
220
|
let newStyles = {};
|
|
185
|
-
|
|
186
221
|
if (kind === "primary") {
|
|
187
222
|
newStyles = {
|
|
188
223
|
default: {
|
|
@@ -299,36 +334,36 @@ const _generateStyles = (color, kind, light, iconWidth, size) => {
|
|
|
299
334
|
} else {
|
|
300
335
|
throw new Error("Button kind not recognized");
|
|
301
336
|
}
|
|
302
|
-
|
|
303
337
|
styles[buttonType] = StyleSheet.create(newStyles);
|
|
304
338
|
return styles[buttonType];
|
|
305
339
|
};
|
|
306
340
|
|
|
307
341
|
const _excluded = ["href", "type", "children", "skipClientNav", "spinner", "disabled", "onClick", "beforeNav", "safeWithNav", "tabIndex", "target", "rel"];
|
|
308
|
-
|
|
309
|
-
|
|
342
|
+
let Button = function (_React$Component) {
|
|
343
|
+
_inheritsLoose(Button, _React$Component);
|
|
344
|
+
function Button() {
|
|
345
|
+
return _React$Component.apply(this, arguments) || this;
|
|
346
|
+
}
|
|
347
|
+
var _proto = Button.prototype;
|
|
348
|
+
_proto.renderClickableBehavior = function renderClickableBehavior(router) {
|
|
310
349
|
const _this$props = this.props,
|
|
311
|
-
|
|
312
|
-
|
|
313
|
-
|
|
314
|
-
|
|
315
|
-
|
|
316
|
-
|
|
317
|
-
|
|
318
|
-
|
|
319
|
-
|
|
320
|
-
|
|
321
|
-
|
|
322
|
-
|
|
323
|
-
|
|
324
|
-
|
|
325
|
-
|
|
326
|
-
|
|
350
|
+
{
|
|
351
|
+
href = undefined,
|
|
352
|
+
type = undefined,
|
|
353
|
+
children,
|
|
354
|
+
skipClientNav,
|
|
355
|
+
spinner,
|
|
356
|
+
disabled,
|
|
357
|
+
onClick,
|
|
358
|
+
beforeNav = undefined,
|
|
359
|
+
safeWithNav = undefined,
|
|
360
|
+
tabIndex,
|
|
361
|
+
target,
|
|
362
|
+
rel
|
|
363
|
+
} = _this$props,
|
|
364
|
+
sharedButtonCoreProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
|
|
327
365
|
const ClickableBehavior = getClickableBehavior(href, skipClientNav, router);
|
|
328
|
-
|
|
329
|
-
const renderProp = (state, _ref) => {
|
|
330
|
-
let restChildProps = _extends({}, _ref);
|
|
331
|
-
|
|
366
|
+
const renderProp = (state, restChildProps) => {
|
|
332
367
|
return React.createElement(ButtonCore, _extends({}, sharedButtonCoreProps, state, restChildProps, {
|
|
333
368
|
disabled: disabled,
|
|
334
369
|
spinner: spinner || state.waiting,
|
|
@@ -339,7 +374,6 @@ class Button extends React.Component {
|
|
|
339
374
|
tabIndex: tabIndex
|
|
340
375
|
}), children);
|
|
341
376
|
};
|
|
342
|
-
|
|
343
377
|
if (beforeNav) {
|
|
344
378
|
return React.createElement(ClickableBehavior, {
|
|
345
379
|
disabled: spinner || disabled,
|
|
@@ -363,13 +397,12 @@ class Button extends React.Component {
|
|
|
363
397
|
rel: rel
|
|
364
398
|
}, renderProp);
|
|
365
399
|
}
|
|
366
|
-
}
|
|
367
|
-
|
|
368
|
-
render() {
|
|
400
|
+
};
|
|
401
|
+
_proto.render = function render() {
|
|
369
402
|
return React.createElement(__RouterContext.Consumer, null, router => this.renderClickableBehavior(router));
|
|
370
|
-
}
|
|
371
|
-
|
|
372
|
-
}
|
|
403
|
+
};
|
|
404
|
+
return Button;
|
|
405
|
+
}(React.Component);
|
|
373
406
|
Button.defaultProps = {
|
|
374
407
|
color: "default",
|
|
375
408
|
kind: "primary",
|
package/dist/index.d.ts
ADDED
package/dist/index.js
CHANGED
|
@@ -1,7 +1,5 @@
|
|
|
1
1
|
'use strict';
|
|
2
2
|
|
|
3
|
-
var _extends = require('@babel/runtime/helpers/extends');
|
|
4
|
-
var _objectWithoutPropertiesLoose = require('@babel/runtime/helpers/objectWithoutPropertiesLoose');
|
|
5
3
|
var React = require('react');
|
|
6
4
|
var reactRouter = require('react-router');
|
|
7
5
|
var wonderBlocksClickable = require('@khanacademy/wonder-blocks-clickable');
|
|
@@ -17,73 +15,113 @@ var Spacing = require('@khanacademy/wonder-blocks-spacing');
|
|
|
17
15
|
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
18
16
|
|
|
19
17
|
function _interopNamespace(e) {
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
});
|
|
30
|
-
}
|
|
18
|
+
if (e && e.__esModule) return e;
|
|
19
|
+
var n = Object.create(null);
|
|
20
|
+
if (e) {
|
|
21
|
+
Object.keys(e).forEach(function (k) {
|
|
22
|
+
if (k !== 'default') {
|
|
23
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
24
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
25
|
+
enumerable: true,
|
|
26
|
+
get: function () { return e[k]; }
|
|
31
27
|
});
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
28
|
+
}
|
|
29
|
+
});
|
|
30
|
+
}
|
|
31
|
+
n["default"] = e;
|
|
32
|
+
return Object.freeze(n);
|
|
35
33
|
}
|
|
36
34
|
|
|
37
|
-
var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
38
|
-
var _objectWithoutPropertiesLoose__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutPropertiesLoose);
|
|
39
35
|
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
40
36
|
var Color__default = /*#__PURE__*/_interopDefaultLegacy(Color);
|
|
41
37
|
var Icon__default = /*#__PURE__*/_interopDefaultLegacy(Icon);
|
|
42
38
|
var Spacing__default = /*#__PURE__*/_interopDefaultLegacy(Spacing);
|
|
43
39
|
|
|
40
|
+
function _extends() {
|
|
41
|
+
_extends = Object.assign ? Object.assign.bind() : function (target) {
|
|
42
|
+
for (var i = 1; i < arguments.length; i++) {
|
|
43
|
+
var source = arguments[i];
|
|
44
|
+
for (var key in source) {
|
|
45
|
+
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
46
|
+
target[key] = source[key];
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
}
|
|
50
|
+
return target;
|
|
51
|
+
};
|
|
52
|
+
return _extends.apply(this, arguments);
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
56
|
+
if (source == null) return {};
|
|
57
|
+
var target = {};
|
|
58
|
+
var sourceKeys = Object.keys(source);
|
|
59
|
+
var key, i;
|
|
60
|
+
for (i = 0; i < sourceKeys.length; i++) {
|
|
61
|
+
key = sourceKeys[i];
|
|
62
|
+
if (excluded.indexOf(key) >= 0) continue;
|
|
63
|
+
target[key] = source[key];
|
|
64
|
+
}
|
|
65
|
+
return target;
|
|
66
|
+
}
|
|
67
|
+
|
|
68
|
+
function _setPrototypeOf(o, p) {
|
|
69
|
+
_setPrototypeOf = Object.setPrototypeOf ? Object.setPrototypeOf.bind() : function _setPrototypeOf(o, p) {
|
|
70
|
+
o.__proto__ = p;
|
|
71
|
+
return o;
|
|
72
|
+
};
|
|
73
|
+
return _setPrototypeOf(o, p);
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
function _inheritsLoose(subClass, superClass) {
|
|
77
|
+
subClass.prototype = Object.create(superClass.prototype);
|
|
78
|
+
subClass.prototype.constructor = subClass;
|
|
79
|
+
_setPrototypeOf(subClass, superClass);
|
|
80
|
+
}
|
|
81
|
+
|
|
44
82
|
const _excluded$1 = ["children", "skipClientNav", "color", "disabled", "focused", "hovered", "href", "kind", "light", "pressed", "size", "style", "testId", "type", "spinner", "icon", "id", "waiting"];
|
|
45
83
|
const StyledAnchor = wonderBlocksCore.addStyle("a");
|
|
46
84
|
const StyledButton = wonderBlocksCore.addStyle("button");
|
|
47
85
|
const StyledLink = wonderBlocksCore.addStyle(reactRouterDom.Link);
|
|
48
|
-
|
|
49
|
-
|
|
86
|
+
let ButtonCore = function (_React$Component) {
|
|
87
|
+
_inheritsLoose(ButtonCore, _React$Component);
|
|
88
|
+
function ButtonCore() {
|
|
89
|
+
return _React$Component.apply(this, arguments) || this;
|
|
90
|
+
}
|
|
91
|
+
var _proto = ButtonCore.prototype;
|
|
92
|
+
_proto.renderInner = function renderInner(router) {
|
|
50
93
|
const _this$props = this.props,
|
|
51
|
-
|
|
52
|
-
|
|
53
|
-
|
|
54
|
-
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
66
|
-
|
|
67
|
-
|
|
68
|
-
|
|
69
|
-
|
|
70
|
-
|
|
71
|
-
|
|
94
|
+
{
|
|
95
|
+
children,
|
|
96
|
+
skipClientNav,
|
|
97
|
+
color,
|
|
98
|
+
disabled: disabledProp,
|
|
99
|
+
focused,
|
|
100
|
+
hovered,
|
|
101
|
+
href = undefined,
|
|
102
|
+
kind,
|
|
103
|
+
light,
|
|
104
|
+
pressed,
|
|
105
|
+
size,
|
|
106
|
+
style,
|
|
107
|
+
testId,
|
|
108
|
+
type = undefined,
|
|
109
|
+
spinner,
|
|
110
|
+
icon,
|
|
111
|
+
id
|
|
112
|
+
} = _this$props,
|
|
113
|
+
restProps = _objectWithoutPropertiesLoose(_this$props, _excluded$1);
|
|
72
114
|
const buttonColor = color === "destructive" ? Color.SemanticColor.controlDestructive : Color.SemanticColor.controlDefault;
|
|
73
115
|
const iconWidth = icon ? (size === "small" ? 16 : 24) + 8 : 0;
|
|
74
|
-
|
|
75
116
|
const buttonStyles = _generateStyles(buttonColor, kind, light, iconWidth, size);
|
|
76
|
-
|
|
77
117
|
const disabled = spinner || disabledProp;
|
|
78
118
|
const defaultStyle = [sharedStyles.shared, disabled && sharedStyles.disabled, icon && sharedStyles.withIcon, buttonStyles.default, disabled && buttonStyles.disabled, kind !== "tertiary" && !disabled && (pressed ? buttonStyles.active : (hovered || focused) && buttonStyles.focus), size === "small" && sharedStyles.small, size === "large" && sharedStyles.large];
|
|
79
|
-
|
|
80
|
-
const commonProps = _extends__default["default"]({
|
|
119
|
+
const commonProps = _extends({
|
|
81
120
|
"data-test-id": testId,
|
|
82
121
|
id: id,
|
|
83
122
|
role: "button",
|
|
84
123
|
style: [defaultStyle, style]
|
|
85
124
|
}, restProps);
|
|
86
|
-
|
|
87
125
|
const Label = size === "small" ? wonderBlocksTypography.LabelSmall : wonderBlocksTypography.LabelLarge;
|
|
88
126
|
const iconSize = size === "small" ? "small" : "medium";
|
|
89
127
|
const label = React__namespace.createElement(Label, {
|
|
@@ -94,37 +132,36 @@ class ButtonCore extends React__namespace.Component {
|
|
|
94
132
|
icon: icon,
|
|
95
133
|
style: sharedStyles.icon
|
|
96
134
|
}), children);
|
|
135
|
+
const sizeMapping = {
|
|
136
|
+
medium: "small",
|
|
137
|
+
small: "xsmall",
|
|
138
|
+
large: "medium"
|
|
139
|
+
};
|
|
97
140
|
const contents = React__namespace.createElement(React__namespace.Fragment, null, label, spinner && React__namespace.createElement(wonderBlocksProgressSpinner.CircularSpinner, {
|
|
98
141
|
style: sharedStyles.spinner,
|
|
99
|
-
size:
|
|
100
|
-
medium: "small",
|
|
101
|
-
small: "xsmall",
|
|
102
|
-
large: "medium"
|
|
103
|
-
}[size],
|
|
142
|
+
size: sizeMapping[size],
|
|
104
143
|
light: kind === "primary",
|
|
105
144
|
testId: `${testId || "button"}-spinner`
|
|
106
145
|
}));
|
|
107
|
-
|
|
108
146
|
if (href && !disabled) {
|
|
109
|
-
return router && !skipClientNav && wonderBlocksClickable.isClientSideUrl(href) ? React__namespace.createElement(StyledLink,
|
|
147
|
+
return router && !skipClientNav && wonderBlocksClickable.isClientSideUrl(href) ? React__namespace.createElement(StyledLink, _extends({}, commonProps, {
|
|
110
148
|
to: href
|
|
111
|
-
}), contents) : React__namespace.createElement(StyledAnchor,
|
|
149
|
+
}), contents) : React__namespace.createElement(StyledAnchor, _extends({}, commonProps, {
|
|
112
150
|
href: href
|
|
113
151
|
}), contents);
|
|
114
152
|
} else {
|
|
115
|
-
return React__namespace.createElement(StyledButton,
|
|
153
|
+
return React__namespace.createElement(StyledButton, _extends({
|
|
116
154
|
type: type || "button"
|
|
117
155
|
}, commonProps, {
|
|
118
156
|
"aria-disabled": disabled
|
|
119
157
|
}), contents);
|
|
120
158
|
}
|
|
121
|
-
}
|
|
122
|
-
|
|
123
|
-
render() {
|
|
159
|
+
};
|
|
160
|
+
_proto.render = function render() {
|
|
124
161
|
return React__namespace.createElement(reactRouter.__RouterContext.Consumer, null, router => this.renderInner(router));
|
|
125
|
-
}
|
|
126
|
-
|
|
127
|
-
}
|
|
162
|
+
};
|
|
163
|
+
return ButtonCore;
|
|
164
|
+
}(React__namespace.Component);
|
|
128
165
|
const sharedStyles = aphrodite.StyleSheet.create({
|
|
129
166
|
shared: {
|
|
130
167
|
position: "relative",
|
|
@@ -191,14 +228,11 @@ const sharedStyles = aphrodite.StyleSheet.create({
|
|
|
191
228
|
}
|
|
192
229
|
});
|
|
193
230
|
const styles = {};
|
|
194
|
-
|
|
195
231
|
const _generateStyles = (color, kind, light, iconWidth, size) => {
|
|
196
232
|
const buttonType = color + kind + light.toString() + iconWidth.toString() + size;
|
|
197
|
-
|
|
198
233
|
if (styles[buttonType]) {
|
|
199
234
|
return styles[buttonType];
|
|
200
235
|
}
|
|
201
|
-
|
|
202
236
|
const {
|
|
203
237
|
white,
|
|
204
238
|
white50,
|
|
@@ -211,7 +245,6 @@ const _generateStyles = (color, kind, light, iconWidth, size) => {
|
|
|
211
245
|
const activeColor = Color.mix(offBlack32, color);
|
|
212
246
|
const padding = size === "large" ? Spacing__default["default"].xLarge_32 : Spacing__default["default"].medium_16;
|
|
213
247
|
let newStyles = {};
|
|
214
|
-
|
|
215
248
|
if (kind === "primary") {
|
|
216
249
|
newStyles = {
|
|
217
250
|
default: {
|
|
@@ -328,37 +361,37 @@ const _generateStyles = (color, kind, light, iconWidth, size) => {
|
|
|
328
361
|
} else {
|
|
329
362
|
throw new Error("Button kind not recognized");
|
|
330
363
|
}
|
|
331
|
-
|
|
332
364
|
styles[buttonType] = aphrodite.StyleSheet.create(newStyles);
|
|
333
365
|
return styles[buttonType];
|
|
334
366
|
};
|
|
335
367
|
|
|
336
368
|
const _excluded = ["href", "type", "children", "skipClientNav", "spinner", "disabled", "onClick", "beforeNav", "safeWithNav", "tabIndex", "target", "rel"];
|
|
337
|
-
|
|
338
|
-
|
|
369
|
+
let Button = function (_React$Component) {
|
|
370
|
+
_inheritsLoose(Button, _React$Component);
|
|
371
|
+
function Button() {
|
|
372
|
+
return _React$Component.apply(this, arguments) || this;
|
|
373
|
+
}
|
|
374
|
+
var _proto = Button.prototype;
|
|
375
|
+
_proto.renderClickableBehavior = function renderClickableBehavior(router) {
|
|
339
376
|
const _this$props = this.props,
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
377
|
+
{
|
|
378
|
+
href = undefined,
|
|
379
|
+
type = undefined,
|
|
380
|
+
children,
|
|
381
|
+
skipClientNav,
|
|
382
|
+
spinner,
|
|
383
|
+
disabled,
|
|
384
|
+
onClick,
|
|
385
|
+
beforeNav = undefined,
|
|
386
|
+
safeWithNav = undefined,
|
|
387
|
+
tabIndex,
|
|
388
|
+
target,
|
|
389
|
+
rel
|
|
390
|
+
} = _this$props,
|
|
391
|
+
sharedButtonCoreProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
|
|
356
392
|
const ClickableBehavior = wonderBlocksClickable.getClickableBehavior(href, skipClientNav, router);
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
let restChildProps = _extends__default["default"]({}, _ref);
|
|
360
|
-
|
|
361
|
-
return React__namespace.createElement(ButtonCore, _extends__default["default"]({}, sharedButtonCoreProps, state, restChildProps, {
|
|
393
|
+
const renderProp = (state, restChildProps) => {
|
|
394
|
+
return React__namespace.createElement(ButtonCore, _extends({}, sharedButtonCoreProps, state, restChildProps, {
|
|
362
395
|
disabled: disabled,
|
|
363
396
|
spinner: spinner || state.waiting,
|
|
364
397
|
skipClientNav: skipClientNav,
|
|
@@ -368,7 +401,6 @@ class Button extends React__namespace.Component {
|
|
|
368
401
|
tabIndex: tabIndex
|
|
369
402
|
}), children);
|
|
370
403
|
};
|
|
371
|
-
|
|
372
404
|
if (beforeNav) {
|
|
373
405
|
return React__namespace.createElement(ClickableBehavior, {
|
|
374
406
|
disabled: spinner || disabled,
|
|
@@ -392,13 +424,12 @@ class Button extends React__namespace.Component {
|
|
|
392
424
|
rel: rel
|
|
393
425
|
}, renderProp);
|
|
394
426
|
}
|
|
395
|
-
}
|
|
396
|
-
|
|
397
|
-
render() {
|
|
427
|
+
};
|
|
428
|
+
_proto.render = function render() {
|
|
398
429
|
return React__namespace.createElement(reactRouter.__RouterContext.Consumer, null, router => this.renderClickableBehavior(router));
|
|
399
|
-
}
|
|
400
|
-
|
|
401
|
-
}
|
|
430
|
+
};
|
|
431
|
+
return Button;
|
|
432
|
+
}(React__namespace.Component);
|
|
402
433
|
Button.defaultProps = {
|
|
403
434
|
color: "default",
|
|
404
435
|
kind: "primary",
|
package/dist/index.js.flow
CHANGED
|
@@ -1,2 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
1
|
+
/**
|
|
2
|
+
* Flowtype definitions for index
|
|
3
|
+
* Generated by Flowgen from a Typescript Definition
|
|
4
|
+
* Flowgen v1.21.0
|
|
5
|
+
* @flow
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
import Button from "./components/button";
|
|
9
|
+
import type { SharedProps } from "./components/button";
|
|
10
|
+
export type { SharedProps as ButtonProps };
|
|
11
|
+
declare export { Button as default };
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-button",
|
|
3
|
-
"version": "3.0.
|
|
3
|
+
"version": "3.0.15",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
"description": "",
|
|
9
9
|
"main": "dist/index.js",
|
|
10
10
|
"module": "dist/es/index.js",
|
|
11
|
-
"
|
|
11
|
+
"types": "dist/index.d.ts",
|
|
12
12
|
"scripts": {
|
|
13
13
|
"test": "echo \"Error: no test specified\" && exit 1"
|
|
14
14
|
},
|
|
@@ -16,13 +16,13 @@
|
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@babel/runtime": "^7.18.6",
|
|
19
|
-
"@khanacademy/wonder-blocks-clickable": "^2.4.
|
|
20
|
-
"@khanacademy/wonder-blocks-color": "^1.2.
|
|
21
|
-
"@khanacademy/wonder-blocks-core": "^4.
|
|
22
|
-
"@khanacademy/wonder-blocks-icon": "^1.2.
|
|
23
|
-
"@khanacademy/wonder-blocks-progress-spinner": "^1.1.
|
|
24
|
-
"@khanacademy/wonder-blocks-spacing": "^3.0.
|
|
25
|
-
"@khanacademy/wonder-blocks-typography": "^1.1.
|
|
19
|
+
"@khanacademy/wonder-blocks-clickable": "^2.4.6",
|
|
20
|
+
"@khanacademy/wonder-blocks-color": "^1.2.2",
|
|
21
|
+
"@khanacademy/wonder-blocks-core": "^4.8.0",
|
|
22
|
+
"@khanacademy/wonder-blocks-icon": "^1.2.38",
|
|
23
|
+
"@khanacademy/wonder-blocks-progress-spinner": "^1.1.41",
|
|
24
|
+
"@khanacademy/wonder-blocks-spacing": "^3.0.6",
|
|
25
|
+
"@khanacademy/wonder-blocks-typography": "^1.1.39"
|
|
26
26
|
},
|
|
27
27
|
"peerDependencies": {
|
|
28
28
|
"aphrodite": "^1.2.5",
|
|
@@ -31,6 +31,6 @@
|
|
|
31
31
|
"react-router-dom": "5.3.0"
|
|
32
32
|
},
|
|
33
33
|
"devDependencies": {
|
|
34
|
-
"wb-dev-build-settings": "^0.7.
|
|
34
|
+
"wb-dev-build-settings": "^0.7.2"
|
|
35
35
|
}
|
|
36
36
|
}
|