@khanacademy/wonder-blocks-icon-button 3.3.12 → 3.4.1
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/dist/es/index.js +109 -331
- package/dist/index.js +193 -280
- package/package.json +11 -10
- package/src/components/__tests__/icon-button.test.js +13 -2
- package/src/components/icon-button-core.js +10 -9
- package/src/components/icon-button.js +13 -16
- package/src/__tests__/index.test.js +0 -13
package/dist/es/index.js
CHANGED
|
@@ -1,5 +1,7 @@
|
|
|
1
|
-
import
|
|
2
|
-
import
|
|
1
|
+
import _extends from '@babel/runtime/helpers/extends';
|
|
2
|
+
import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/objectWithoutPropertiesLoose';
|
|
3
|
+
import { Component, createElement } from 'react';
|
|
4
|
+
import { __RouterContext } from 'react-router';
|
|
3
5
|
import { isClientSideUrl, getClickableBehavior } from '@khanacademy/wonder-blocks-clickable';
|
|
4
6
|
import { StyleSheet } from 'aphrodite';
|
|
5
7
|
import { Link } from 'react-router-dom';
|
|
@@ -7,284 +9,66 @@ import Color, { SemanticColor, mix, fade } from '@khanacademy/wonder-blocks-colo
|
|
|
7
9
|
import { addStyle } from '@khanacademy/wonder-blocks-core';
|
|
8
10
|
import Icon from '@khanacademy/wonder-blocks-icon';
|
|
9
11
|
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
}
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
35
|
-
|
|
36
|
-
|
|
37
|
-
|
|
38
|
-
|
|
39
|
-
|
|
40
|
-
|
|
41
|
-
|
|
42
|
-
}
|
|
43
|
-
|
|
44
|
-
return obj;
|
|
45
|
-
}
|
|
46
|
-
|
|
47
|
-
function _extends() {
|
|
48
|
-
_extends = Object.assign || function (target) {
|
|
49
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
50
|
-
var source = arguments[i];
|
|
51
|
-
|
|
52
|
-
for (var key in source) {
|
|
53
|
-
if (Object.prototype.hasOwnProperty.call(source, key)) {
|
|
54
|
-
target[key] = source[key];
|
|
55
|
-
}
|
|
56
|
-
}
|
|
57
|
-
}
|
|
58
|
-
|
|
59
|
-
return target;
|
|
60
|
-
};
|
|
61
|
-
|
|
62
|
-
return _extends.apply(this, arguments);
|
|
63
|
-
}
|
|
64
|
-
|
|
65
|
-
function ownKeys(object, enumerableOnly) {
|
|
66
|
-
var keys = Object.keys(object);
|
|
67
|
-
|
|
68
|
-
if (Object.getOwnPropertySymbols) {
|
|
69
|
-
var symbols = Object.getOwnPropertySymbols(object);
|
|
70
|
-
if (enumerableOnly) symbols = symbols.filter(function (sym) {
|
|
71
|
-
return Object.getOwnPropertyDescriptor(object, sym).enumerable;
|
|
12
|
+
const _excluded = ["skipClientNav", "color", "disabled", "focused", "hovered", "href", "icon", "kind", "light", "pressed", "style", "testId", "waiting"];
|
|
13
|
+
const StyledAnchor = addStyle("a");
|
|
14
|
+
const StyledButton = addStyle("button");
|
|
15
|
+
const StyledLink = addStyle(Link);
|
|
16
|
+
class IconButtonCore extends Component {
|
|
17
|
+
renderInner(router) {
|
|
18
|
+
const _this$props = this.props,
|
|
19
|
+
{
|
|
20
|
+
skipClientNav,
|
|
21
|
+
color,
|
|
22
|
+
disabled,
|
|
23
|
+
focused,
|
|
24
|
+
hovered,
|
|
25
|
+
href,
|
|
26
|
+
icon,
|
|
27
|
+
kind,
|
|
28
|
+
light,
|
|
29
|
+
pressed,
|
|
30
|
+
style,
|
|
31
|
+
testId
|
|
32
|
+
} = _this$props,
|
|
33
|
+
restProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
|
|
34
|
+
|
|
35
|
+
const buttonColor = color === "destructive" ? SemanticColor.controlDestructive : SemanticColor.controlDefault;
|
|
36
|
+
|
|
37
|
+
const buttonStyles = _generateStyles(buttonColor, kind, light);
|
|
38
|
+
|
|
39
|
+
const defaultStyle = [sharedStyles.shared, disabled && sharedStyles.disabled, buttonStyles.default, disabled && buttonStyles.disabled, !disabled && (pressed ? buttonStyles.active : (hovered || focused) && buttonStyles.focus)];
|
|
40
|
+
const child = /*#__PURE__*/createElement(Icon, {
|
|
41
|
+
size: "medium",
|
|
42
|
+
color: "currentColor",
|
|
43
|
+
icon: icon
|
|
72
44
|
});
|
|
73
|
-
keys.push.apply(keys, symbols);
|
|
74
|
-
}
|
|
75
|
-
|
|
76
|
-
return keys;
|
|
77
|
-
}
|
|
78
|
-
|
|
79
|
-
function _objectSpread2(target) {
|
|
80
|
-
for (var i = 1; i < arguments.length; i++) {
|
|
81
|
-
var source = arguments[i] != null ? arguments[i] : {};
|
|
82
45
|
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
46
|
+
const commonProps = _extends({
|
|
47
|
+
"data-test-id": testId,
|
|
48
|
+
style: [defaultStyle, style]
|
|
49
|
+
}, restProps);
|
|
50
|
+
|
|
51
|
+
if (href && !disabled) {
|
|
52
|
+
return router && !skipClientNav && isClientSideUrl(href) ? /*#__PURE__*/createElement(StyledLink, _extends({}, commonProps, {
|
|
53
|
+
to: href
|
|
54
|
+
}), child) : /*#__PURE__*/createElement(StyledAnchor, _extends({}, commonProps, {
|
|
55
|
+
href: href
|
|
56
|
+
}), child);
|
|
89
57
|
} else {
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
}
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
return target;
|
|
97
|
-
}
|
|
98
|
-
|
|
99
|
-
function _inherits(subClass, superClass) {
|
|
100
|
-
if (typeof superClass !== "function" && superClass !== null) {
|
|
101
|
-
throw new TypeError("Super expression must either be null or a function");
|
|
102
|
-
}
|
|
103
|
-
|
|
104
|
-
subClass.prototype = Object.create(superClass && superClass.prototype, {
|
|
105
|
-
constructor: {
|
|
106
|
-
value: subClass,
|
|
107
|
-
writable: true,
|
|
108
|
-
configurable: true
|
|
109
|
-
}
|
|
110
|
-
});
|
|
111
|
-
if (superClass) _setPrototypeOf(subClass, superClass);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
function _getPrototypeOf(o) {
|
|
115
|
-
_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) {
|
|
116
|
-
return o.__proto__ || Object.getPrototypeOf(o);
|
|
117
|
-
};
|
|
118
|
-
return _getPrototypeOf(o);
|
|
119
|
-
}
|
|
120
|
-
|
|
121
|
-
function _setPrototypeOf(o, p) {
|
|
122
|
-
_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) {
|
|
123
|
-
o.__proto__ = p;
|
|
124
|
-
return o;
|
|
125
|
-
};
|
|
126
|
-
|
|
127
|
-
return _setPrototypeOf(o, p);
|
|
128
|
-
}
|
|
129
|
-
|
|
130
|
-
function _isNativeReflectConstruct() {
|
|
131
|
-
if (typeof Reflect === "undefined" || !Reflect.construct) return false;
|
|
132
|
-
if (Reflect.construct.sham) return false;
|
|
133
|
-
if (typeof Proxy === "function") return true;
|
|
134
|
-
|
|
135
|
-
try {
|
|
136
|
-
Date.prototype.toString.call(Reflect.construct(Date, [], function () {}));
|
|
137
|
-
return true;
|
|
138
|
-
} catch (e) {
|
|
139
|
-
return false;
|
|
140
|
-
}
|
|
141
|
-
}
|
|
142
|
-
|
|
143
|
-
function _objectWithoutPropertiesLoose(source, excluded) {
|
|
144
|
-
if (source == null) return {};
|
|
145
|
-
var target = {};
|
|
146
|
-
var sourceKeys = Object.keys(source);
|
|
147
|
-
var key, i;
|
|
148
|
-
|
|
149
|
-
for (i = 0; i < sourceKeys.length; i++) {
|
|
150
|
-
key = sourceKeys[i];
|
|
151
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
152
|
-
target[key] = source[key];
|
|
153
|
-
}
|
|
154
|
-
|
|
155
|
-
return target;
|
|
156
|
-
}
|
|
157
|
-
|
|
158
|
-
function _objectWithoutProperties(source, excluded) {
|
|
159
|
-
if (source == null) return {};
|
|
160
|
-
|
|
161
|
-
var target = _objectWithoutPropertiesLoose(source, excluded);
|
|
162
|
-
|
|
163
|
-
var key, i;
|
|
164
|
-
|
|
165
|
-
if (Object.getOwnPropertySymbols) {
|
|
166
|
-
var sourceSymbolKeys = Object.getOwnPropertySymbols(source);
|
|
167
|
-
|
|
168
|
-
for (i = 0; i < sourceSymbolKeys.length; i++) {
|
|
169
|
-
key = sourceSymbolKeys[i];
|
|
170
|
-
if (excluded.indexOf(key) >= 0) continue;
|
|
171
|
-
if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue;
|
|
172
|
-
target[key] = source[key];
|
|
58
|
+
return /*#__PURE__*/createElement(StyledButton, _extends({
|
|
59
|
+
type: "button"
|
|
60
|
+
}, commonProps, {
|
|
61
|
+
disabled: disabled
|
|
62
|
+
}), child);
|
|
173
63
|
}
|
|
174
64
|
}
|
|
175
65
|
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
function _assertThisInitialized(self) {
|
|
180
|
-
if (self === void 0) {
|
|
181
|
-
throw new ReferenceError("this hasn't been initialised - super() hasn't been called");
|
|
66
|
+
render() {
|
|
67
|
+
return /*#__PURE__*/createElement(__RouterContext.Consumer, null, router => this.renderInner(router));
|
|
182
68
|
}
|
|
183
69
|
|
|
184
|
-
return self;
|
|
185
|
-
}
|
|
186
|
-
|
|
187
|
-
function _possibleConstructorReturn(self, call) {
|
|
188
|
-
if (call && (typeof call === "object" || typeof call === "function")) {
|
|
189
|
-
return call;
|
|
190
|
-
}
|
|
191
|
-
|
|
192
|
-
return _assertThisInitialized(self);
|
|
193
|
-
}
|
|
194
|
-
|
|
195
|
-
function _createSuper(Derived) {
|
|
196
|
-
var hasNativeReflectConstruct = _isNativeReflectConstruct();
|
|
197
|
-
|
|
198
|
-
return function _createSuperInternal() {
|
|
199
|
-
var Super = _getPrototypeOf(Derived),
|
|
200
|
-
result;
|
|
201
|
-
|
|
202
|
-
if (hasNativeReflectConstruct) {
|
|
203
|
-
var NewTarget = _getPrototypeOf(this).constructor;
|
|
204
|
-
|
|
205
|
-
result = Reflect.construct(Super, arguments, NewTarget);
|
|
206
|
-
} else {
|
|
207
|
-
result = Super.apply(this, arguments);
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
return _possibleConstructorReturn(this, result);
|
|
211
|
-
};
|
|
212
70
|
}
|
|
213
|
-
|
|
214
|
-
var StyledAnchor = addStyle("a");
|
|
215
|
-
var StyledButton = addStyle("button");
|
|
216
|
-
var StyledLink = addStyle(Link);
|
|
217
|
-
|
|
218
|
-
var IconButtonCore = /*#__PURE__*/function (_React$Component) {
|
|
219
|
-
_inherits(IconButtonCore, _React$Component);
|
|
220
|
-
|
|
221
|
-
var _super = _createSuper(IconButtonCore);
|
|
222
|
-
|
|
223
|
-
function IconButtonCore() {
|
|
224
|
-
_classCallCheck(this, IconButtonCore);
|
|
225
|
-
|
|
226
|
-
return _super.apply(this, arguments);
|
|
227
|
-
}
|
|
228
|
-
|
|
229
|
-
_createClass(IconButtonCore, [{
|
|
230
|
-
key: "render",
|
|
231
|
-
value: function render() {
|
|
232
|
-
var _this$props = this.props,
|
|
233
|
-
skipClientNav = _this$props.skipClientNav,
|
|
234
|
-
color = _this$props.color,
|
|
235
|
-
disabled = _this$props.disabled,
|
|
236
|
-
focused = _this$props.focused,
|
|
237
|
-
hovered = _this$props.hovered,
|
|
238
|
-
href = _this$props.href,
|
|
239
|
-
icon = _this$props.icon,
|
|
240
|
-
kind = _this$props.kind,
|
|
241
|
-
light = _this$props.light,
|
|
242
|
-
pressed = _this$props.pressed,
|
|
243
|
-
style = _this$props.style,
|
|
244
|
-
testId = _this$props.testId,
|
|
245
|
-
_ = _this$props.waiting,
|
|
246
|
-
restProps = _objectWithoutProperties(_this$props, ["skipClientNav", "color", "disabled", "focused", "hovered", "href", "icon", "kind", "light", "pressed", "style", "testId", "waiting"]);
|
|
247
|
-
|
|
248
|
-
var router = this.context.router;
|
|
249
|
-
var buttonColor = color === "destructive" ? SemanticColor.controlDestructive : SemanticColor.controlDefault;
|
|
250
|
-
|
|
251
|
-
var buttonStyles = _generateStyles(buttonColor, kind, light);
|
|
252
|
-
|
|
253
|
-
var defaultStyle = [sharedStyles.shared, disabled && sharedStyles.disabled, buttonStyles.default, disabled && buttonStyles.disabled, !disabled && (pressed ? buttonStyles.active : (hovered || focused) && buttonStyles.focus)];
|
|
254
|
-
var child = /*#__PURE__*/createElement(Icon, {
|
|
255
|
-
size: "medium",
|
|
256
|
-
color: "currentColor",
|
|
257
|
-
icon: icon
|
|
258
|
-
});
|
|
259
|
-
|
|
260
|
-
var commonProps = _objectSpread2({
|
|
261
|
-
"data-test-id": testId,
|
|
262
|
-
style: [defaultStyle, style]
|
|
263
|
-
}, restProps);
|
|
264
|
-
|
|
265
|
-
if (href && !disabled) {
|
|
266
|
-
return router && !skipClientNav && isClientSideUrl(href) ? /*#__PURE__*/createElement(StyledLink, _extends({}, commonProps, {
|
|
267
|
-
to: href
|
|
268
|
-
}), child) : /*#__PURE__*/createElement(StyledAnchor, _extends({}, commonProps, {
|
|
269
|
-
href: href
|
|
270
|
-
}), child);
|
|
271
|
-
} else {
|
|
272
|
-
return /*#__PURE__*/createElement(StyledButton, _extends({
|
|
273
|
-
type: "button"
|
|
274
|
-
}, commonProps, {
|
|
275
|
-
disabled: disabled
|
|
276
|
-
}), child);
|
|
277
|
-
}
|
|
278
|
-
}
|
|
279
|
-
}]);
|
|
280
|
-
|
|
281
|
-
return IconButtonCore;
|
|
282
|
-
}(Component);
|
|
283
|
-
|
|
284
|
-
_defineProperty(IconButtonCore, "contextTypes", {
|
|
285
|
-
router: any
|
|
286
|
-
});
|
|
287
|
-
var sharedStyles = StyleSheet.create({
|
|
71
|
+
const sharedStyles = StyleSheet.create({
|
|
288
72
|
shared: {
|
|
289
73
|
position: "relative",
|
|
290
74
|
display: "inline-flex",
|
|
@@ -312,10 +96,10 @@ var sharedStyles = StyleSheet.create({
|
|
|
312
96
|
cursor: "default"
|
|
313
97
|
}
|
|
314
98
|
});
|
|
315
|
-
|
|
99
|
+
const styles = {};
|
|
316
100
|
|
|
317
|
-
|
|
318
|
-
|
|
101
|
+
const _generateStyles = (color, kind, light) => {
|
|
102
|
+
const buttonType = color + kind + light.toString();
|
|
319
103
|
|
|
320
104
|
if (styles[buttonType]) {
|
|
321
105
|
return styles[buttonType];
|
|
@@ -325,11 +109,13 @@ var _generateStyles = function _generateStyles(color, kind, light) {
|
|
|
325
109
|
throw new Error("Light is only supported for primary IconButtons");
|
|
326
110
|
}
|
|
327
111
|
|
|
328
|
-
|
|
329
|
-
|
|
330
|
-
|
|
331
|
-
|
|
332
|
-
|
|
112
|
+
const {
|
|
113
|
+
white,
|
|
114
|
+
offBlack32,
|
|
115
|
+
offBlack64,
|
|
116
|
+
offBlack
|
|
117
|
+
} = Color;
|
|
118
|
+
const newStyles = {
|
|
333
119
|
default: {},
|
|
334
120
|
focus: {
|
|
335
121
|
color: light ? white : color,
|
|
@@ -371,6 +157,9 @@ var _generateStyles = function _generateStyles(color, kind, light) {
|
|
|
371
157
|
return styles[buttonType];
|
|
372
158
|
};
|
|
373
159
|
|
|
160
|
+
const _excluded$1 = ["onClick", "href", "skipClientNav", "tabIndex", "target"],
|
|
161
|
+
_excluded2 = ["tabIndex"];
|
|
162
|
+
|
|
374
163
|
/**
|
|
375
164
|
* An IconButton is a button whose contents are an SVG image.
|
|
376
165
|
*
|
|
@@ -407,64 +196,53 @@ var _generateStyles = function _generateStyles(color, kind, light) {
|
|
|
407
196
|
* />
|
|
408
197
|
* ```
|
|
409
198
|
*/
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
|
|
414
|
-
|
|
415
|
-
|
|
416
|
-
|
|
417
|
-
|
|
418
|
-
|
|
419
|
-
|
|
420
|
-
|
|
421
|
-
|
|
422
|
-
|
|
423
|
-
|
|
424
|
-
|
|
425
|
-
|
|
426
|
-
|
|
427
|
-
|
|
428
|
-
|
|
429
|
-
|
|
430
|
-
|
|
431
|
-
|
|
432
|
-
|
|
433
|
-
|
|
434
|
-
|
|
199
|
+
class IconButton extends Component {
|
|
200
|
+
renderClickableBehavior(router) {
|
|
201
|
+
const _this$props = this.props,
|
|
202
|
+
{
|
|
203
|
+
onClick,
|
|
204
|
+
href,
|
|
205
|
+
skipClientNav,
|
|
206
|
+
tabIndex,
|
|
207
|
+
target
|
|
208
|
+
} = _this$props,
|
|
209
|
+
sharedProps = _objectWithoutPropertiesLoose(_this$props, _excluded$1);
|
|
210
|
+
|
|
211
|
+
const ClickableBehavior = getClickableBehavior(href, skipClientNav, router);
|
|
212
|
+
return /*#__PURE__*/createElement(ClickableBehavior, {
|
|
213
|
+
disabled: sharedProps.disabled,
|
|
214
|
+
href: href,
|
|
215
|
+
onClick: onClick,
|
|
216
|
+
role: "button",
|
|
217
|
+
target: target
|
|
218
|
+
}, (state, _ref) => {
|
|
219
|
+
let {
|
|
220
|
+
tabIndex: clickableTabIndex
|
|
221
|
+
} = _ref,
|
|
222
|
+
childrenProps = _objectWithoutPropertiesLoose(_ref, _excluded2);
|
|
223
|
+
|
|
224
|
+
return /*#__PURE__*/createElement(IconButtonCore, _extends({}, sharedProps, state, childrenProps, {
|
|
225
|
+
skipClientNav: skipClientNav,
|
|
435
226
|
href: href,
|
|
436
|
-
|
|
437
|
-
|
|
438
|
-
|
|
439
|
-
|
|
440
|
-
|
|
441
|
-
|
|
442
|
-
|
|
443
|
-
|
|
444
|
-
skipClientNav: skipClientNav,
|
|
445
|
-
href: href,
|
|
446
|
-
target: target // If tabIndex is provide to the component we allow
|
|
447
|
-
// it to override the tabIndex provide to use by
|
|
448
|
-
// ClickableBehavior.
|
|
449
|
-
,
|
|
450
|
-
tabIndex: tabIndex || clickableTabIndex
|
|
451
|
-
}));
|
|
452
|
-
});
|
|
453
|
-
}
|
|
454
|
-
}]);
|
|
455
|
-
|
|
456
|
-
return IconButton;
|
|
457
|
-
}(Component);
|
|
227
|
+
target: target // If tabIndex is provide to the component we allow
|
|
228
|
+
// it to override the tabIndex provide to use by
|
|
229
|
+
// ClickableBehavior.
|
|
230
|
+
,
|
|
231
|
+
tabIndex: tabIndex || clickableTabIndex
|
|
232
|
+
}));
|
|
233
|
+
});
|
|
234
|
+
}
|
|
458
235
|
|
|
459
|
-
|
|
460
|
-
|
|
461
|
-
}
|
|
236
|
+
render() {
|
|
237
|
+
return /*#__PURE__*/createElement(__RouterContext.Consumer, null, router => this.renderClickableBehavior(router));
|
|
238
|
+
}
|
|
462
239
|
|
|
463
|
-
|
|
240
|
+
}
|
|
241
|
+
IconButton.defaultProps = {
|
|
464
242
|
color: "default",
|
|
465
243
|
kind: "primary",
|
|
466
244
|
light: false,
|
|
467
245
|
disabled: false
|
|
468
|
-
}
|
|
246
|
+
};
|
|
469
247
|
|
|
470
248
|
export default IconButton;
|
package/dist/index.js
CHANGED
|
@@ -82,26 +82,26 @@ module.exports =
|
|
|
82
82
|
/******/
|
|
83
83
|
/******/
|
|
84
84
|
/******/ // Load entry module and return exports
|
|
85
|
-
/******/ return __webpack_require__(__webpack_require__.s =
|
|
85
|
+
/******/ return __webpack_require__(__webpack_require__.s = 10);
|
|
86
86
|
/******/ })
|
|
87
87
|
/************************************************************************/
|
|
88
88
|
/******/ ([
|
|
89
89
|
/* 0 */
|
|
90
90
|
/***/ (function(module, exports) {
|
|
91
91
|
|
|
92
|
-
module.exports = require("
|
|
92
|
+
module.exports = require("react");
|
|
93
93
|
|
|
94
94
|
/***/ }),
|
|
95
95
|
/* 1 */
|
|
96
96
|
/***/ (function(module, exports) {
|
|
97
97
|
|
|
98
|
-
module.exports = require("
|
|
98
|
+
module.exports = require("@khanacademy/wonder-blocks-color");
|
|
99
99
|
|
|
100
100
|
/***/ }),
|
|
101
101
|
/* 2 */
|
|
102
102
|
/***/ (function(module, exports) {
|
|
103
103
|
|
|
104
|
-
module.exports = require("
|
|
104
|
+
module.exports = require("react-router");
|
|
105
105
|
|
|
106
106
|
/***/ }),
|
|
107
107
|
/* 3 */
|
|
@@ -123,89 +123,128 @@ module.exports = require("aphrodite");
|
|
|
123
123
|
|
|
124
124
|
/***/ }),
|
|
125
125
|
/* 6 */
|
|
126
|
-
/***/ (function(module, exports) {
|
|
127
|
-
|
|
128
|
-
module.exports = require("react-router-dom");
|
|
129
|
-
|
|
130
|
-
/***/ }),
|
|
131
|
-
/* 7 */
|
|
132
|
-
/***/ (function(module, exports) {
|
|
133
|
-
|
|
134
|
-
module.exports = require("@khanacademy/wonder-blocks-icon");
|
|
135
|
-
|
|
136
|
-
/***/ }),
|
|
137
|
-
/* 8 */
|
|
138
126
|
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
139
127
|
|
|
140
128
|
"use strict";
|
|
141
|
-
|
|
142
|
-
__webpack_require__
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
var
|
|
149
|
-
|
|
150
|
-
// EXTERNAL MODULE: external "prop-types"
|
|
151
|
-
var external_prop_types_ = __webpack_require__(2);
|
|
152
|
-
|
|
153
|
-
// EXTERNAL MODULE: external "@khanacademy/wonder-blocks-clickable"
|
|
154
|
-
var wonder_blocks_clickable_ = __webpack_require__(3);
|
|
155
|
-
|
|
156
|
-
// EXTERNAL MODULE: external "aphrodite"
|
|
157
|
-
var external_aphrodite_ = __webpack_require__(5);
|
|
158
|
-
|
|
159
|
-
// EXTERNAL MODULE: external "react-router-dom"
|
|
160
|
-
var external_react_router_dom_ = __webpack_require__(6);
|
|
161
|
-
|
|
162
|
-
// EXTERNAL MODULE: external "@khanacademy/wonder-blocks-color"
|
|
163
|
-
var wonder_blocks_color_ = __webpack_require__(0);
|
|
164
|
-
var wonder_blocks_color_default = /*#__PURE__*/__webpack_require__.n(wonder_blocks_color_);
|
|
165
|
-
|
|
166
|
-
// EXTERNAL MODULE: external "@khanacademy/wonder-blocks-core"
|
|
167
|
-
var wonder_blocks_core_ = __webpack_require__(4);
|
|
168
|
-
|
|
169
|
-
// EXTERNAL MODULE: external "@khanacademy/wonder-blocks-icon"
|
|
170
|
-
var wonder_blocks_icon_ = __webpack_require__(7);
|
|
171
|
-
var wonder_blocks_icon_default = /*#__PURE__*/__webpack_require__.n(wonder_blocks_icon_);
|
|
172
|
-
|
|
173
|
-
// CONCATENATED MODULE: ./packages/wonder-blocks-icon-button/src/components/icon-button-core.js
|
|
174
|
-
function _typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { _typeof = function _typeof(obj) { return typeof obj; }; } else { _typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return _typeof(obj); }
|
|
175
|
-
|
|
129
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return IconButton; });
|
|
130
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
|
|
131
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
132
|
+
/* harmony import */ var react_router__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2);
|
|
133
|
+
/* harmony import */ var react_router__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react_router__WEBPACK_IMPORTED_MODULE_1__);
|
|
134
|
+
/* harmony import */ var _khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(3);
|
|
135
|
+
/* harmony import */ var _khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_2__);
|
|
136
|
+
/* harmony import */ var _icon_button_core_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(7);
|
|
176
137
|
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
177
138
|
|
|
178
|
-
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; }
|
|
179
|
-
|
|
180
|
-
function _objectSpread(target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i] != null ? arguments[i] : {}; if (i % 2) { ownKeys(Object(source), true).forEach(function (key) { _defineProperty(target, key, source[key]); }); } else if (Object.getOwnPropertyDescriptors) { Object.defineProperties(target, Object.getOwnPropertyDescriptors(source)); } else { ownKeys(Object(source)).forEach(function (key) { Object.defineProperty(target, key, Object.getOwnPropertyDescriptor(source, key)); }); } } return target; }
|
|
181
|
-
|
|
182
|
-
function _objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = _objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
183
|
-
|
|
184
|
-
function _objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
185
|
-
|
|
186
|
-
function _classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
187
|
-
|
|
188
|
-
function _defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
189
139
|
|
|
190
|
-
function _createClass(Constructor, protoProps, staticProps) { if (protoProps) _defineProperties(Constructor.prototype, protoProps); if (staticProps) _defineProperties(Constructor, staticProps); return Constructor; }
|
|
191
140
|
|
|
192
|
-
function _inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) _setPrototypeOf(subClass, superClass); }
|
|
193
141
|
|
|
194
|
-
function _setPrototypeOf(o, p) { _setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return _setPrototypeOf(o, p); }
|
|
195
142
|
|
|
196
|
-
function _createSuper(Derived) { var hasNativeReflectConstruct = _isNativeReflectConstruct(); return function _createSuperInternal() { var Super = _getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = _getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return _possibleConstructorReturn(this, result); }; }
|
|
197
143
|
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
144
|
+
/**
|
|
145
|
+
* An IconButton is a button whose contents are an SVG image.
|
|
146
|
+
*
|
|
147
|
+
* To use, supply an onClick function, a wonder-blocks icon asset (see
|
|
148
|
+
* the Icon section) and an aria-label to describe the button functionality.
|
|
149
|
+
* Optionally specify href (URL), clientSideNav, color
|
|
150
|
+
* (Wonder Blocks Blue or Red), kind ("primary", "secondary", or "tertiary"),
|
|
151
|
+
* light (whether the IconButton will be rendered on a dark background),
|
|
152
|
+
* disabled , test ID, and custom styling.
|
|
153
|
+
*
|
|
154
|
+
* The size of an IconButton matches the size of icon it wraps which is 24x24
|
|
155
|
+
* pixels. The focus ring which is displayed on hover and focus is much
|
|
156
|
+
* larger but does not affect its size. This matches the behavior of Button.
|
|
157
|
+
*
|
|
158
|
+
* IconButtons require a certain amount of space between them to ensure the
|
|
159
|
+
* focus rings don't overlap. The minimum amount of spacing is 16px, but
|
|
160
|
+
* you should refer to the mocks provided by design. Using a Strut in between
|
|
161
|
+
* IconButtons is the preferred way to for adding this spacing.
|
|
162
|
+
*
|
|
163
|
+
* Many layouts require alignment of visual left (or right) side of an
|
|
164
|
+
* IconButton. This requires a little bit of pixel nudging since each icon
|
|
165
|
+
* as a different amount of internal padding.
|
|
166
|
+
*
|
|
167
|
+
* See the Toolbar documentation for examples of IconButton use that follow
|
|
168
|
+
* the best practices described above.
|
|
169
|
+
*
|
|
170
|
+
* ```js
|
|
171
|
+
* import {icons} from "@khanacademy/wonder-blocks-icon";
|
|
172
|
+
*
|
|
173
|
+
* <IconButton
|
|
174
|
+
* icon={icons.anIcon}
|
|
175
|
+
* aria-label="An Icon"
|
|
176
|
+
* onClick={(e) => console.log("Hello, world!")}
|
|
177
|
+
* />
|
|
178
|
+
* ```
|
|
179
|
+
*/
|
|
180
|
+
class IconButton extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
|
|
181
|
+
renderClickableBehavior(router) {
|
|
182
|
+
const {
|
|
183
|
+
onClick,
|
|
184
|
+
href,
|
|
185
|
+
skipClientNav,
|
|
186
|
+
tabIndex,
|
|
187
|
+
target,
|
|
188
|
+
...sharedProps
|
|
189
|
+
} = this.props;
|
|
190
|
+
const ClickableBehavior = Object(_khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_2__["getClickableBehavior"])(href, skipClientNav, router);
|
|
191
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](ClickableBehavior, {
|
|
192
|
+
disabled: sharedProps.disabled,
|
|
193
|
+
href: href,
|
|
194
|
+
onClick: onClick,
|
|
195
|
+
role: "button",
|
|
196
|
+
target: target
|
|
197
|
+
}, (state, {
|
|
198
|
+
tabIndex: clickableTabIndex,
|
|
199
|
+
...childrenProps
|
|
200
|
+
}) => {
|
|
201
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_icon_button_core_js__WEBPACK_IMPORTED_MODULE_3__[/* default */ "a"], _extends({}, sharedProps, state, childrenProps, {
|
|
202
|
+
skipClientNav: skipClientNav,
|
|
203
|
+
href: href,
|
|
204
|
+
target: target // If tabIndex is provide to the component we allow
|
|
205
|
+
// it to override the tabIndex provide to use by
|
|
206
|
+
// ClickableBehavior.
|
|
207
|
+
,
|
|
208
|
+
tabIndex: tabIndex || clickableTabIndex
|
|
209
|
+
}));
|
|
210
|
+
});
|
|
211
|
+
}
|
|
203
212
|
|
|
204
|
-
|
|
213
|
+
render() {
|
|
214
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](react_router__WEBPACK_IMPORTED_MODULE_1__["__RouterContext"].Consumer, null, router => this.renderClickableBehavior(router));
|
|
215
|
+
}
|
|
205
216
|
|
|
206
|
-
|
|
217
|
+
}
|
|
218
|
+
IconButton.defaultProps = {
|
|
219
|
+
color: "default",
|
|
220
|
+
kind: "primary",
|
|
221
|
+
light: false,
|
|
222
|
+
disabled: false
|
|
223
|
+
};
|
|
207
224
|
|
|
225
|
+
/***/ }),
|
|
226
|
+
/* 7 */
|
|
227
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
208
228
|
|
|
229
|
+
"use strict";
|
|
230
|
+
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return IconButtonCore; });
|
|
231
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
|
|
232
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
233
|
+
/* harmony import */ var aphrodite__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(5);
|
|
234
|
+
/* harmony import */ var aphrodite__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(aphrodite__WEBPACK_IMPORTED_MODULE_1__);
|
|
235
|
+
/* harmony import */ var react_router_dom__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8);
|
|
236
|
+
/* harmony import */ var react_router_dom__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(react_router_dom__WEBPACK_IMPORTED_MODULE_2__);
|
|
237
|
+
/* harmony import */ var react_router__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(2);
|
|
238
|
+
/* harmony import */ var react_router__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(react_router__WEBPACK_IMPORTED_MODULE_3__);
|
|
239
|
+
/* harmony import */ var _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(1);
|
|
240
|
+
/* harmony import */ var _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_4__);
|
|
241
|
+
/* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(4);
|
|
242
|
+
/* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_5__);
|
|
243
|
+
/* harmony import */ var _khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(3);
|
|
244
|
+
/* harmony import */ var _khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_6__);
|
|
245
|
+
/* harmony import */ var _khanacademy_wonder_blocks_icon__WEBPACK_IMPORTED_MODULE_7__ = __webpack_require__(9);
|
|
246
|
+
/* harmony import */ var _khanacademy_wonder_blocks_icon__WEBPACK_IMPORTED_MODULE_7___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_icon__WEBPACK_IMPORTED_MODULE_7__);
|
|
247
|
+
function _extends() { _extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return _extends.apply(this, arguments); }
|
|
209
248
|
|
|
210
249
|
|
|
211
250
|
|
|
@@ -213,82 +252,66 @@ function _defineProperty(obj, key, value) { if (key in obj) { Object.definePrope
|
|
|
213
252
|
|
|
214
253
|
|
|
215
254
|
|
|
216
|
-
var StyledAnchor = Object(wonder_blocks_core_["addStyle"])("a");
|
|
217
|
-
var StyledButton = Object(wonder_blocks_core_["addStyle"])("button");
|
|
218
|
-
var StyledLink = Object(wonder_blocks_core_["addStyle"])(external_react_router_dom_["Link"]);
|
|
219
255
|
|
|
220
|
-
var icon_button_core_IconButtonCore = /*#__PURE__*/function (_React$Component) {
|
|
221
|
-
_inherits(IconButtonCore, _React$Component);
|
|
222
256
|
|
|
223
|
-
|
|
257
|
+
const StyledAnchor = Object(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_5__["addStyle"])("a");
|
|
258
|
+
const StyledButton = Object(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_5__["addStyle"])("button");
|
|
259
|
+
const StyledLink = Object(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_5__["addStyle"])(react_router_dom__WEBPACK_IMPORTED_MODULE_2__["Link"]);
|
|
260
|
+
class IconButtonCore extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
|
|
261
|
+
renderInner(router) {
|
|
262
|
+
const {
|
|
263
|
+
skipClientNav,
|
|
264
|
+
color,
|
|
265
|
+
disabled,
|
|
266
|
+
focused,
|
|
267
|
+
hovered,
|
|
268
|
+
href,
|
|
269
|
+
icon,
|
|
270
|
+
kind,
|
|
271
|
+
light,
|
|
272
|
+
pressed,
|
|
273
|
+
style,
|
|
274
|
+
testId,
|
|
275
|
+
waiting: _,
|
|
276
|
+
...restProps
|
|
277
|
+
} = this.props;
|
|
278
|
+
const buttonColor = color === "destructive" ? _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_4__["SemanticColor"].controlDestructive : _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_4__["SemanticColor"].controlDefault;
|
|
224
279
|
|
|
225
|
-
|
|
226
|
-
_classCallCheck(this, IconButtonCore);
|
|
280
|
+
const buttonStyles = _generateStyles(buttonColor, kind, light);
|
|
227
281
|
|
|
228
|
-
|
|
229
|
-
|
|
282
|
+
const defaultStyle = [sharedStyles.shared, disabled && sharedStyles.disabled, buttonStyles.default, disabled && buttonStyles.disabled, !disabled && (pressed ? buttonStyles.active : (hovered || focused) && buttonStyles.focus)];
|
|
283
|
+
const child = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_icon__WEBPACK_IMPORTED_MODULE_7___default.a, {
|
|
284
|
+
size: "medium",
|
|
285
|
+
color: "currentColor",
|
|
286
|
+
icon: icon
|
|
287
|
+
});
|
|
288
|
+
const commonProps = {
|
|
289
|
+
"data-test-id": testId,
|
|
290
|
+
style: [defaultStyle, style],
|
|
291
|
+
...restProps
|
|
292
|
+
};
|
|
230
293
|
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
242
|
-
|
|
243
|
-
light = _this$props.light,
|
|
244
|
-
pressed = _this$props.pressed,
|
|
245
|
-
style = _this$props.style,
|
|
246
|
-
testId = _this$props.testId,
|
|
247
|
-
_ = _this$props.waiting,
|
|
248
|
-
restProps = _objectWithoutProperties(_this$props, ["skipClientNav", "color", "disabled", "focused", "hovered", "href", "icon", "kind", "light", "pressed", "style", "testId", "waiting"]);
|
|
249
|
-
|
|
250
|
-
var router = this.context.router;
|
|
251
|
-
var buttonColor = color === "destructive" ? wonder_blocks_color_["SemanticColor"].controlDestructive : wonder_blocks_color_["SemanticColor"].controlDefault;
|
|
252
|
-
|
|
253
|
-
var buttonStyles = icon_button_core_generateStyles(buttonColor, kind, light);
|
|
254
|
-
|
|
255
|
-
var defaultStyle = [sharedStyles.shared, disabled && sharedStyles.disabled, buttonStyles.default, disabled && buttonStyles.disabled, !disabled && (pressed ? buttonStyles.active : (hovered || focused) && buttonStyles.focus)];
|
|
256
|
-
var child = /*#__PURE__*/external_react_["createElement"](wonder_blocks_icon_default.a, {
|
|
257
|
-
size: "medium",
|
|
258
|
-
color: "currentColor",
|
|
259
|
-
icon: icon
|
|
260
|
-
});
|
|
261
|
-
|
|
262
|
-
var commonProps = _objectSpread({
|
|
263
|
-
"data-test-id": testId,
|
|
264
|
-
style: [defaultStyle, style]
|
|
265
|
-
}, restProps);
|
|
266
|
-
|
|
267
|
-
if (href && !disabled) {
|
|
268
|
-
return router && !skipClientNav && Object(wonder_blocks_clickable_["isClientSideUrl"])(href) ? /*#__PURE__*/external_react_["createElement"](StyledLink, _extends({}, commonProps, {
|
|
269
|
-
to: href
|
|
270
|
-
}), child) : /*#__PURE__*/external_react_["createElement"](StyledAnchor, _extends({}, commonProps, {
|
|
271
|
-
href: href
|
|
272
|
-
}), child);
|
|
273
|
-
} else {
|
|
274
|
-
return /*#__PURE__*/external_react_["createElement"](StyledButton, _extends({
|
|
275
|
-
type: "button"
|
|
276
|
-
}, commonProps, {
|
|
277
|
-
disabled: disabled
|
|
278
|
-
}), child);
|
|
279
|
-
}
|
|
294
|
+
if (href && !disabled) {
|
|
295
|
+
return router && !skipClientNav && Object(_khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_6__["isClientSideUrl"])(href) ? /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](StyledLink, _extends({}, commonProps, {
|
|
296
|
+
to: href
|
|
297
|
+
}), child) : /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](StyledAnchor, _extends({}, commonProps, {
|
|
298
|
+
href: href
|
|
299
|
+
}), child);
|
|
300
|
+
} else {
|
|
301
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](StyledButton, _extends({
|
|
302
|
+
type: "button"
|
|
303
|
+
}, commonProps, {
|
|
304
|
+
disabled: disabled
|
|
305
|
+
}), child);
|
|
280
306
|
}
|
|
281
|
-
}
|
|
282
|
-
|
|
283
|
-
return IconButtonCore;
|
|
284
|
-
}(external_react_["Component"]);
|
|
285
|
-
|
|
286
|
-
_defineProperty(icon_button_core_IconButtonCore, "contextTypes", {
|
|
287
|
-
router: external_prop_types_["any"]
|
|
288
|
-
});
|
|
307
|
+
}
|
|
289
308
|
|
|
309
|
+
render() {
|
|
310
|
+
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](react_router__WEBPACK_IMPORTED_MODULE_3__["__RouterContext"].Consumer, null, router => this.renderInner(router));
|
|
311
|
+
}
|
|
290
312
|
|
|
291
|
-
|
|
313
|
+
}
|
|
314
|
+
const sharedStyles = aphrodite__WEBPACK_IMPORTED_MODULE_1__["StyleSheet"].create({
|
|
292
315
|
shared: {
|
|
293
316
|
position: "relative",
|
|
294
317
|
display: "inline-flex",
|
|
@@ -316,10 +339,10 @@ var sharedStyles = external_aphrodite_["StyleSheet"].create({
|
|
|
316
339
|
cursor: "default"
|
|
317
340
|
}
|
|
318
341
|
});
|
|
319
|
-
|
|
342
|
+
const styles = {};
|
|
320
343
|
|
|
321
|
-
|
|
322
|
-
|
|
344
|
+
const _generateStyles = (color, kind, light) => {
|
|
345
|
+
const buttonType = color + kind + light.toString();
|
|
323
346
|
|
|
324
347
|
if (styles[buttonType]) {
|
|
325
348
|
return styles[buttonType];
|
|
@@ -329,11 +352,13 @@ var icon_button_core_generateStyles = function _generateStyles(color, kind, ligh
|
|
|
329
352
|
throw new Error("Light is only supported for primary IconButtons");
|
|
330
353
|
}
|
|
331
354
|
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
355
|
+
const {
|
|
356
|
+
white,
|
|
357
|
+
offBlack32,
|
|
358
|
+
offBlack64,
|
|
359
|
+
offBlack
|
|
360
|
+
} = _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_4___default.a;
|
|
361
|
+
const newStyles = {
|
|
337
362
|
default: {},
|
|
338
363
|
focus: {
|
|
339
364
|
color: light ? white : color,
|
|
@@ -343,14 +368,14 @@ var icon_button_core_generateStyles = function _generateStyles(color, kind, ligh
|
|
|
343
368
|
borderRadius: 4
|
|
344
369
|
},
|
|
345
370
|
active: {
|
|
346
|
-
color: light ? Object(
|
|
371
|
+
color: light ? Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_4__["mix"])(Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_4__["fade"])(color, 0.32), white) : Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_4__["mix"])(offBlack32, color),
|
|
347
372
|
borderWidth: 2,
|
|
348
|
-
borderColor: light ? Object(
|
|
373
|
+
borderColor: light ? Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_4__["mix"])(Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_4__["fade"])(color, 0.32), white) : Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_4__["mix"])(offBlack32, color),
|
|
349
374
|
borderStyle: "solid",
|
|
350
375
|
borderRadius: 4
|
|
351
376
|
},
|
|
352
377
|
disabled: {
|
|
353
|
-
color: light ? Object(
|
|
378
|
+
color: light ? Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_4__["mix"])(Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_4__["fade"])(white, 0.32), color) : offBlack32,
|
|
354
379
|
cursor: "default"
|
|
355
380
|
}
|
|
356
381
|
};
|
|
@@ -371,143 +396,31 @@ var icon_button_core_generateStyles = function _generateStyles(color, kind, ligh
|
|
|
371
396
|
throw new Error("IconButton kind not recognized");
|
|
372
397
|
}
|
|
373
398
|
|
|
374
|
-
styles[buttonType] =
|
|
399
|
+
styles[buttonType] = aphrodite__WEBPACK_IMPORTED_MODULE_1__["StyleSheet"].create(newStyles);
|
|
375
400
|
return styles[buttonType];
|
|
376
401
|
};
|
|
377
|
-
// CONCATENATED MODULE: ./packages/wonder-blocks-icon-button/src/components/icon-button.js
|
|
378
|
-
function icon_button_typeof(obj) { "@babel/helpers - typeof"; if (typeof Symbol === "function" && typeof Symbol.iterator === "symbol") { icon_button_typeof = function _typeof(obj) { return typeof obj; }; } else { icon_button_typeof = function _typeof(obj) { return obj && typeof Symbol === "function" && obj.constructor === Symbol && obj !== Symbol.prototype ? "symbol" : typeof obj; }; } return icon_button_typeof(obj); }
|
|
379
|
-
|
|
380
|
-
function icon_button_extends() { icon_button_extends = Object.assign || function (target) { for (var i = 1; i < arguments.length; i++) { var source = arguments[i]; for (var key in source) { if (Object.prototype.hasOwnProperty.call(source, key)) { target[key] = source[key]; } } } return target; }; return icon_button_extends.apply(this, arguments); }
|
|
381
|
-
|
|
382
|
-
function icon_button_objectWithoutProperties(source, excluded) { if (source == null) return {}; var target = icon_button_objectWithoutPropertiesLoose(source, excluded); var key, i; if (Object.getOwnPropertySymbols) { var sourceSymbolKeys = Object.getOwnPropertySymbols(source); for (i = 0; i < sourceSymbolKeys.length; i++) { key = sourceSymbolKeys[i]; if (excluded.indexOf(key) >= 0) continue; if (!Object.prototype.propertyIsEnumerable.call(source, key)) continue; target[key] = source[key]; } } return target; }
|
|
383
|
-
|
|
384
|
-
function icon_button_objectWithoutPropertiesLoose(source, excluded) { if (source == null) return {}; var target = {}; var sourceKeys = Object.keys(source); var key, i; for (i = 0; i < sourceKeys.length; i++) { key = sourceKeys[i]; if (excluded.indexOf(key) >= 0) continue; target[key] = source[key]; } return target; }
|
|
385
|
-
|
|
386
|
-
function icon_button_classCallCheck(instance, Constructor) { if (!(instance instanceof Constructor)) { throw new TypeError("Cannot call a class as a function"); } }
|
|
387
|
-
|
|
388
|
-
function icon_button_defineProperties(target, props) { for (var i = 0; i < props.length; i++) { var descriptor = props[i]; descriptor.enumerable = descriptor.enumerable || false; descriptor.configurable = true; if ("value" in descriptor) descriptor.writable = true; Object.defineProperty(target, descriptor.key, descriptor); } }
|
|
389
|
-
|
|
390
|
-
function icon_button_createClass(Constructor, protoProps, staticProps) { if (protoProps) icon_button_defineProperties(Constructor.prototype, protoProps); if (staticProps) icon_button_defineProperties(Constructor, staticProps); return Constructor; }
|
|
391
|
-
|
|
392
|
-
function icon_button_inherits(subClass, superClass) { if (typeof superClass !== "function" && superClass !== null) { throw new TypeError("Super expression must either be null or a function"); } subClass.prototype = Object.create(superClass && superClass.prototype, { constructor: { value: subClass, writable: true, configurable: true } }); if (superClass) icon_button_setPrototypeOf(subClass, superClass); }
|
|
393
|
-
|
|
394
|
-
function icon_button_setPrototypeOf(o, p) { icon_button_setPrototypeOf = Object.setPrototypeOf || function _setPrototypeOf(o, p) { o.__proto__ = p; return o; }; return icon_button_setPrototypeOf(o, p); }
|
|
395
|
-
|
|
396
|
-
function icon_button_createSuper(Derived) { var hasNativeReflectConstruct = icon_button_isNativeReflectConstruct(); return function _createSuperInternal() { var Super = icon_button_getPrototypeOf(Derived), result; if (hasNativeReflectConstruct) { var NewTarget = icon_button_getPrototypeOf(this).constructor; result = Reflect.construct(Super, arguments, NewTarget); } else { result = Super.apply(this, arguments); } return icon_button_possibleConstructorReturn(this, result); }; }
|
|
397
|
-
|
|
398
|
-
function icon_button_possibleConstructorReturn(self, call) { if (call && (icon_button_typeof(call) === "object" || typeof call === "function")) { return call; } return icon_button_assertThisInitialized(self); }
|
|
399
|
-
|
|
400
|
-
function icon_button_assertThisInitialized(self) { if (self === void 0) { throw new ReferenceError("this hasn't been initialised - super() hasn't been called"); } return self; }
|
|
401
|
-
|
|
402
|
-
function icon_button_isNativeReflectConstruct() { if (typeof Reflect === "undefined" || !Reflect.construct) return false; if (Reflect.construct.sham) return false; if (typeof Proxy === "function") return true; try { Date.prototype.toString.call(Reflect.construct(Date, [], function () {})); return true; } catch (e) { return false; } }
|
|
403
|
-
|
|
404
|
-
function icon_button_getPrototypeOf(o) { icon_button_getPrototypeOf = Object.setPrototypeOf ? Object.getPrototypeOf : function _getPrototypeOf(o) { return o.__proto__ || Object.getPrototypeOf(o); }; return icon_button_getPrototypeOf(o); }
|
|
405
|
-
|
|
406
|
-
function icon_button_defineProperty(obj, key, value) { if (key in obj) { Object.defineProperty(obj, key, { value: value, enumerable: true, configurable: true, writable: true }); } else { obj[key] = value; } return obj; }
|
|
407
|
-
|
|
408
|
-
|
|
409
|
-
|
|
410
|
-
|
|
411
|
-
|
|
412
|
-
|
|
413
|
-
/**
|
|
414
|
-
* An IconButton is a button whose contents are an SVG image.
|
|
415
|
-
*
|
|
416
|
-
* To use, supply an onClick function, a wonder-blocks icon asset (see
|
|
417
|
-
* the Icon section) and an aria-label to describe the button functionality.
|
|
418
|
-
* Optionally specify href (URL), clientSideNav, color
|
|
419
|
-
* (Wonder Blocks Blue or Red), kind ("primary", "secondary", or "tertiary"),
|
|
420
|
-
* light (whether the IconButton will be rendered on a dark background),
|
|
421
|
-
* disabled , test ID, and custom styling.
|
|
422
|
-
*
|
|
423
|
-
* The size of an IconButton matches the size of icon it wraps which is 24x24
|
|
424
|
-
* pixels. The focus ring which is displayed on hover and focus is much
|
|
425
|
-
* larger but does not affect its size. This matches the behavior of Button.
|
|
426
|
-
*
|
|
427
|
-
* IconButtons require a certain amount of space between them to ensure the
|
|
428
|
-
* focus rings don't overlap. The minimum amount of spacing is 16px, but
|
|
429
|
-
* you should refer to the mocks provided by design. Using a Strut in between
|
|
430
|
-
* IconButtons is the preferred way to for adding this spacing.
|
|
431
|
-
*
|
|
432
|
-
* Many layouts require alignment of visual left (or right) side of an
|
|
433
|
-
* IconButton. This requires a little bit of pixel nudging since each icon
|
|
434
|
-
* as a different amount of internal padding.
|
|
435
|
-
*
|
|
436
|
-
* See the Toolbar documentation for examples of IconButton use that follow
|
|
437
|
-
* the best practices described above.
|
|
438
|
-
*
|
|
439
|
-
* ```js
|
|
440
|
-
* import {icons} from "@khanacademy/wonder-blocks-icon";
|
|
441
|
-
*
|
|
442
|
-
* <IconButton
|
|
443
|
-
* icon={icons.anIcon}
|
|
444
|
-
* aria-label="An Icon"
|
|
445
|
-
* onClick={(e) => console.log("Hello, world!")}
|
|
446
|
-
* />
|
|
447
|
-
* ```
|
|
448
|
-
*/
|
|
449
|
-
var icon_button_IconButton = /*#__PURE__*/function (_React$Component) {
|
|
450
|
-
icon_button_inherits(IconButton, _React$Component);
|
|
451
|
-
|
|
452
|
-
var _super = icon_button_createSuper(IconButton);
|
|
453
402
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
return _super.apply(this, arguments);
|
|
458
|
-
}
|
|
403
|
+
/***/ }),
|
|
404
|
+
/* 8 */
|
|
405
|
+
/***/ (function(module, exports) {
|
|
459
406
|
|
|
460
|
-
|
|
461
|
-
key: "render",
|
|
462
|
-
value: function render() {
|
|
463
|
-
var _this$props = this.props,
|
|
464
|
-
onClick = _this$props.onClick,
|
|
465
|
-
href = _this$props.href,
|
|
466
|
-
skipClientNav = _this$props.skipClientNav,
|
|
467
|
-
tabIndex = _this$props.tabIndex,
|
|
468
|
-
target = _this$props.target,
|
|
469
|
-
sharedProps = icon_button_objectWithoutProperties(_this$props, ["onClick", "href", "skipClientNav", "tabIndex", "target"]);
|
|
470
|
-
|
|
471
|
-
var ClickableBehavior = Object(wonder_blocks_clickable_["getClickableBehavior"])(href, skipClientNav, this.context.router);
|
|
472
|
-
return /*#__PURE__*/external_react_["createElement"](ClickableBehavior, {
|
|
473
|
-
disabled: sharedProps.disabled,
|
|
474
|
-
href: href,
|
|
475
|
-
onClick: onClick,
|
|
476
|
-
role: "button",
|
|
477
|
-
target: target
|
|
478
|
-
}, function (state, _ref) {
|
|
479
|
-
var clickableTabIndex = _ref.tabIndex,
|
|
480
|
-
childrenProps = icon_button_objectWithoutProperties(_ref, ["tabIndex"]);
|
|
481
|
-
|
|
482
|
-
return /*#__PURE__*/external_react_["createElement"](icon_button_core_IconButtonCore, icon_button_extends({}, sharedProps, state, childrenProps, {
|
|
483
|
-
skipClientNav: skipClientNav,
|
|
484
|
-
href: href,
|
|
485
|
-
target: target // If tabIndex is provide to the component we allow
|
|
486
|
-
// it to override the tabIndex provide to use by
|
|
487
|
-
// ClickableBehavior.
|
|
488
|
-
,
|
|
489
|
-
tabIndex: tabIndex || clickableTabIndex
|
|
490
|
-
}));
|
|
491
|
-
});
|
|
492
|
-
}
|
|
493
|
-
}]);
|
|
407
|
+
module.exports = require("react-router-dom");
|
|
494
408
|
|
|
495
|
-
|
|
496
|
-
|
|
409
|
+
/***/ }),
|
|
410
|
+
/* 9 */
|
|
411
|
+
/***/ (function(module, exports) {
|
|
497
412
|
|
|
498
|
-
|
|
499
|
-
router: external_prop_types_["any"]
|
|
500
|
-
});
|
|
413
|
+
module.exports = require("@khanacademy/wonder-blocks-icon");
|
|
501
414
|
|
|
502
|
-
|
|
503
|
-
|
|
504
|
-
|
|
505
|
-
light: false,
|
|
506
|
-
disabled: false
|
|
507
|
-
});
|
|
415
|
+
/***/ }),
|
|
416
|
+
/* 10 */
|
|
417
|
+
/***/ (function(module, __webpack_exports__, __webpack_require__) {
|
|
508
418
|
|
|
419
|
+
"use strict";
|
|
420
|
+
__webpack_require__.r(__webpack_exports__);
|
|
421
|
+
/* harmony import */ var _components_icon_button_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(6);
|
|
422
|
+
/* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _components_icon_button_js__WEBPACK_IMPORTED_MODULE_0__["a"]; });
|
|
509
423
|
|
|
510
|
-
// CONCATENATED MODULE: ./packages/wonder-blocks-icon-button/src/index.js
|
|
511
424
|
|
|
512
425
|
|
|
513
426
|
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-icon-button",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.4.1",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -15,19 +15,20 @@
|
|
|
15
15
|
"author": "",
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@
|
|
19
|
-
"@khanacademy/wonder-blocks-
|
|
20
|
-
"@khanacademy/wonder-blocks-
|
|
21
|
-
"@khanacademy/wonder-blocks-
|
|
18
|
+
"@babel/runtime": "^7.16.3",
|
|
19
|
+
"@khanacademy/wonder-blocks-clickable": "^2.2.1",
|
|
20
|
+
"@khanacademy/wonder-blocks-color": "^1.1.20",
|
|
21
|
+
"@khanacademy/wonder-blocks-core": "^4.0.0",
|
|
22
|
+
"@khanacademy/wonder-blocks-icon": "^1.2.24"
|
|
22
23
|
},
|
|
23
24
|
"peerDependencies": {
|
|
24
25
|
"aphrodite": "^1.2.5",
|
|
25
|
-
"
|
|
26
|
-
"react": "
|
|
27
|
-
"react-router-dom": "
|
|
26
|
+
"react": "16.14.0",
|
|
27
|
+
"react-router": "5.2.1",
|
|
28
|
+
"react-router-dom": "5.3.0"
|
|
28
29
|
},
|
|
29
30
|
"devDependencies": {
|
|
30
|
-
"wb-dev-build-settings": "^0.0
|
|
31
|
+
"wb-dev-build-settings": "^0.2.0"
|
|
31
32
|
},
|
|
32
|
-
"gitHead": "
|
|
33
|
+
"gitHead": "9ebea88533e702011165072f090a377e02fa3f0f"
|
|
33
34
|
}
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import {mount
|
|
3
|
+
import {mount} from "enzyme";
|
|
4
4
|
|
|
5
5
|
import {MemoryRouter, Route, Switch} from "react-router-dom";
|
|
6
6
|
import {icons} from "@khanacademy/wonder-blocks-icon";
|
|
@@ -9,8 +9,19 @@ import expectRenderError from "../../../../../utils/testing/expect-render-error.
|
|
|
9
9
|
import IconButton from "../icon-button.js";
|
|
10
10
|
|
|
11
11
|
describe("IconButton", () => {
|
|
12
|
+
const {location} = window;
|
|
13
|
+
|
|
14
|
+
beforeAll(() => {
|
|
15
|
+
delete window.location;
|
|
16
|
+
window.location = {assign: jest.fn()};
|
|
17
|
+
});
|
|
18
|
+
|
|
19
|
+
afterAll(() => {
|
|
20
|
+
window.location = location;
|
|
21
|
+
});
|
|
22
|
+
|
|
12
23
|
test("render an icon", (done) => {
|
|
13
|
-
const wrapper =
|
|
24
|
+
const wrapper = mount(
|
|
14
25
|
<IconButton
|
|
15
26
|
icon={icons.search}
|
|
16
27
|
aria-label="search"
|
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
import * as React from "react";
|
|
3
3
|
import {StyleSheet} from "aphrodite";
|
|
4
4
|
import {Link} from "react-router-dom";
|
|
5
|
-
import
|
|
5
|
+
import {__RouterContext} from "react-router";
|
|
6
6
|
|
|
7
7
|
import Color, {
|
|
8
8
|
SemanticColor,
|
|
@@ -33,18 +33,12 @@ type Props = {|
|
|
|
33
33
|
href?: string,
|
|
34
34
|
|};
|
|
35
35
|
|
|
36
|
-
type ContextTypes = {|
|
|
37
|
-
router: $FlowFixMe,
|
|
38
|
-
|};
|
|
39
|
-
|
|
40
36
|
const StyledAnchor = addStyle("a");
|
|
41
37
|
const StyledButton = addStyle("button");
|
|
42
38
|
const StyledLink = addStyle(Link);
|
|
43
39
|
|
|
44
40
|
export default class IconButtonCore extends React.Component<Props> {
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
render(): React.Node {
|
|
41
|
+
renderInner(router: any): React.Node {
|
|
48
42
|
const {
|
|
49
43
|
skipClientNav,
|
|
50
44
|
color,
|
|
@@ -61,7 +55,6 @@ export default class IconButtonCore extends React.Component<Props> {
|
|
|
61
55
|
waiting: _,
|
|
62
56
|
...restProps
|
|
63
57
|
} = this.props;
|
|
64
|
-
const {router} = this.context;
|
|
65
58
|
|
|
66
59
|
const buttonColor =
|
|
67
60
|
color === "destructive"
|
|
@@ -111,6 +104,14 @@ export default class IconButtonCore extends React.Component<Props> {
|
|
|
111
104
|
);
|
|
112
105
|
}
|
|
113
106
|
}
|
|
107
|
+
|
|
108
|
+
render(): React.Node {
|
|
109
|
+
return (
|
|
110
|
+
<__RouterContext.Consumer>
|
|
111
|
+
{(router) => this.renderInner(router)}
|
|
112
|
+
</__RouterContext.Consumer>
|
|
113
|
+
);
|
|
114
|
+
}
|
|
114
115
|
}
|
|
115
116
|
|
|
116
117
|
const sharedStyles = StyleSheet.create({
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import
|
|
3
|
+
import {__RouterContext} from "react-router";
|
|
4
4
|
|
|
5
5
|
import {getClickableBehavior} from "@khanacademy/wonder-blocks-clickable";
|
|
6
6
|
import type {IconAsset} from "@khanacademy/wonder-blocks-icon";
|
|
@@ -126,10 +126,6 @@ export type SharedProps = {|
|
|
|
126
126
|
onClick?: (e: SyntheticEvent<>) => mixed,
|
|
127
127
|
|};
|
|
128
128
|
|
|
129
|
-
type ContextTypes = {|
|
|
130
|
-
router: $FlowFixMe,
|
|
131
|
-
|};
|
|
132
|
-
|
|
133
129
|
type DefaultProps = {|
|
|
134
130
|
color: $PropertyType<SharedProps, "color">,
|
|
135
131
|
kind: $PropertyType<SharedProps, "kind">,
|
|
@@ -174,7 +170,6 @@ type DefaultProps = {|
|
|
|
174
170
|
* ```
|
|
175
171
|
*/
|
|
176
172
|
export default class IconButton extends React.Component<SharedProps> {
|
|
177
|
-
static contextTypes: ContextTypes = {router: PropTypes.any};
|
|
178
173
|
static defaultProps: DefaultProps = {
|
|
179
174
|
color: "default",
|
|
180
175
|
kind: "primary",
|
|
@@ -182,20 +177,14 @@ export default class IconButton extends React.Component<SharedProps> {
|
|
|
182
177
|
disabled: false,
|
|
183
178
|
};
|
|
184
179
|
|
|
185
|
-
|
|
186
|
-
const {
|
|
187
|
-
|
|
188
|
-
href,
|
|
189
|
-
skipClientNav,
|
|
190
|
-
tabIndex,
|
|
191
|
-
target,
|
|
192
|
-
...sharedProps
|
|
193
|
-
} = this.props;
|
|
180
|
+
renderClickableBehavior(router: any): React.Node {
|
|
181
|
+
const {onClick, href, skipClientNav, tabIndex, target, ...sharedProps} =
|
|
182
|
+
this.props;
|
|
194
183
|
|
|
195
184
|
const ClickableBehavior = getClickableBehavior(
|
|
196
185
|
href,
|
|
197
186
|
skipClientNav,
|
|
198
|
-
|
|
187
|
+
router,
|
|
199
188
|
);
|
|
200
189
|
|
|
201
190
|
return (
|
|
@@ -225,4 +214,12 @@ export default class IconButton extends React.Component<SharedProps> {
|
|
|
225
214
|
</ClickableBehavior>
|
|
226
215
|
);
|
|
227
216
|
}
|
|
217
|
+
|
|
218
|
+
render(): React.Node {
|
|
219
|
+
return (
|
|
220
|
+
<__RouterContext.Consumer>
|
|
221
|
+
{(router) => this.renderClickableBehavior(router)}
|
|
222
|
+
</__RouterContext.Consumer>
|
|
223
|
+
);
|
|
224
|
+
}
|
|
228
225
|
}
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
describe("@khanacademy/wonder-blocks-icon-button", () => {
|
|
3
|
-
test("package exports default", async () => {
|
|
4
|
-
// Arrange
|
|
5
|
-
const importedModule = import("../index.js");
|
|
6
|
-
|
|
7
|
-
// Act
|
|
8
|
-
const result = await importedModule;
|
|
9
|
-
|
|
10
|
-
// Assert
|
|
11
|
-
expect(Object.keys(result).sort()).toEqual(["default"].sort());
|
|
12
|
-
});
|
|
13
|
-
});
|