@khanacademy/wonder-blocks-icon-button 3.3.14 → 3.4.3
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 +16 -0
- package/dist/es/index.js +26 -27
- package/dist/index.js +21 -22
- package/package.json +11 -12
- package/src/__tests__/__snapshots__/generated-snapshot.test.js.snap +2 -2
- package/src/components/__tests__/icon-button.test.js +14 -2
- package/src/components/icon-button-core.js +10 -9
- package/src/components/icon-button.js +13 -16
- package/LICENSE +0 -21
package/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
# @khanacademy/wonder-blocks-icon-button
|
|
2
|
+
|
|
3
|
+
## 3.4.3
|
|
4
|
+
|
|
5
|
+
### Patch Changes
|
|
6
|
+
|
|
7
|
+
- @khanacademy/wonder-blocks-clickable@2.2.3
|
|
8
|
+
- @khanacademy/wonder-blocks-core@4.2.1
|
|
9
|
+
- @khanacademy/wonder-blocks-icon@1.2.25
|
|
10
|
+
|
|
11
|
+
## 3.4.2
|
|
12
|
+
|
|
13
|
+
### Patch Changes
|
|
14
|
+
|
|
15
|
+
- Updated dependencies [901bfe82]
|
|
16
|
+
- @khanacademy/wonder-blocks-clickable@2.2.2
|
package/dist/es/index.js
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
import _extends from '@babel/runtime/helpers/extends';
|
|
2
2
|
import _objectWithoutPropertiesLoose from '@babel/runtime/helpers/objectWithoutPropertiesLoose';
|
|
3
|
-
import
|
|
4
|
-
import {
|
|
3
|
+
import * as React from 'react';
|
|
4
|
+
import { __RouterContext } from 'react-router';
|
|
5
5
|
import { isClientSideUrl, getClickableBehavior } from '@khanacademy/wonder-blocks-clickable';
|
|
6
6
|
import { StyleSheet } from 'aphrodite';
|
|
7
7
|
import { Link } from 'react-router-dom';
|
|
@@ -9,12 +9,12 @@ import Color, { SemanticColor, mix, fade } from '@khanacademy/wonder-blocks-colo
|
|
|
9
9
|
import { addStyle } from '@khanacademy/wonder-blocks-core';
|
|
10
10
|
import Icon from '@khanacademy/wonder-blocks-icon';
|
|
11
11
|
|
|
12
|
-
const _excluded = ["skipClientNav", "color", "disabled", "focused", "hovered", "href", "icon", "kind", "light", "pressed", "style", "testId", "waiting"];
|
|
12
|
+
const _excluded$1 = ["skipClientNav", "color", "disabled", "focused", "hovered", "href", "icon", "kind", "light", "pressed", "style", "testId", "waiting"];
|
|
13
13
|
const StyledAnchor = addStyle("a");
|
|
14
14
|
const StyledButton = addStyle("button");
|
|
15
15
|
const StyledLink = addStyle(Link);
|
|
16
|
-
class IconButtonCore extends Component {
|
|
17
|
-
|
|
16
|
+
class IconButtonCore extends React.Component {
|
|
17
|
+
renderInner(router) {
|
|
18
18
|
const _this$props = this.props,
|
|
19
19
|
{
|
|
20
20
|
skipClientNav,
|
|
@@ -30,17 +30,14 @@ class IconButtonCore extends Component {
|
|
|
30
30
|
style,
|
|
31
31
|
testId
|
|
32
32
|
} = _this$props,
|
|
33
|
-
restProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
|
|
33
|
+
restProps = _objectWithoutPropertiesLoose(_this$props, _excluded$1);
|
|
34
34
|
|
|
35
|
-
const {
|
|
36
|
-
router
|
|
37
|
-
} = this.context;
|
|
38
35
|
const buttonColor = color === "destructive" ? SemanticColor.controlDestructive : SemanticColor.controlDefault;
|
|
39
36
|
|
|
40
37
|
const buttonStyles = _generateStyles(buttonColor, kind, light);
|
|
41
38
|
|
|
42
39
|
const defaultStyle = [sharedStyles.shared, disabled && sharedStyles.disabled, buttonStyles.default, disabled && buttonStyles.disabled, !disabled && (pressed ? buttonStyles.active : (hovered || focused) && buttonStyles.focus)];
|
|
43
|
-
const child = /*#__PURE__*/createElement(Icon, {
|
|
40
|
+
const child = /*#__PURE__*/React.createElement(Icon, {
|
|
44
41
|
size: "medium",
|
|
45
42
|
color: "currentColor",
|
|
46
43
|
icon: icon
|
|
@@ -52,13 +49,13 @@ class IconButtonCore extends Component {
|
|
|
52
49
|
}, restProps);
|
|
53
50
|
|
|
54
51
|
if (href && !disabled) {
|
|
55
|
-
return router && !skipClientNav && isClientSideUrl(href) ? /*#__PURE__*/createElement(StyledLink, _extends({}, commonProps, {
|
|
52
|
+
return router && !skipClientNav && isClientSideUrl(href) ? /*#__PURE__*/React.createElement(StyledLink, _extends({}, commonProps, {
|
|
56
53
|
to: href
|
|
57
|
-
}), child) : /*#__PURE__*/createElement(StyledAnchor, _extends({}, commonProps, {
|
|
54
|
+
}), child) : /*#__PURE__*/React.createElement(StyledAnchor, _extends({}, commonProps, {
|
|
58
55
|
href: href
|
|
59
56
|
}), child);
|
|
60
57
|
} else {
|
|
61
|
-
return /*#__PURE__*/createElement(StyledButton, _extends({
|
|
58
|
+
return /*#__PURE__*/React.createElement(StyledButton, _extends({
|
|
62
59
|
type: "button"
|
|
63
60
|
}, commonProps, {
|
|
64
61
|
disabled: disabled
|
|
@@ -66,10 +63,11 @@ class IconButtonCore extends Component {
|
|
|
66
63
|
}
|
|
67
64
|
}
|
|
68
65
|
|
|
66
|
+
render() {
|
|
67
|
+
return /*#__PURE__*/React.createElement(__RouterContext.Consumer, null, router => this.renderInner(router));
|
|
68
|
+
}
|
|
69
|
+
|
|
69
70
|
}
|
|
70
|
-
IconButtonCore.contextTypes = {
|
|
71
|
-
router: any
|
|
72
|
-
};
|
|
73
71
|
const sharedStyles = StyleSheet.create({
|
|
74
72
|
shared: {
|
|
75
73
|
position: "relative",
|
|
@@ -159,7 +157,7 @@ const _generateStyles = (color, kind, light) => {
|
|
|
159
157
|
return styles[buttonType];
|
|
160
158
|
};
|
|
161
159
|
|
|
162
|
-
const _excluded
|
|
160
|
+
const _excluded = ["onClick", "href", "skipClientNav", "tabIndex", "target"],
|
|
163
161
|
_excluded2 = ["tabIndex"];
|
|
164
162
|
|
|
165
163
|
/**
|
|
@@ -198,8 +196,8 @@ const _excluded$1 = ["onClick", "href", "skipClientNav", "tabIndex", "target"],
|
|
|
198
196
|
* />
|
|
199
197
|
* ```
|
|
200
198
|
*/
|
|
201
|
-
class IconButton extends Component {
|
|
202
|
-
|
|
199
|
+
class IconButton extends React.Component {
|
|
200
|
+
renderClickableBehavior(router) {
|
|
203
201
|
const _this$props = this.props,
|
|
204
202
|
{
|
|
205
203
|
onClick,
|
|
@@ -208,10 +206,10 @@ class IconButton extends Component {
|
|
|
208
206
|
tabIndex,
|
|
209
207
|
target
|
|
210
208
|
} = _this$props,
|
|
211
|
-
sharedProps = _objectWithoutPropertiesLoose(_this$props, _excluded
|
|
209
|
+
sharedProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
|
|
212
210
|
|
|
213
|
-
const ClickableBehavior = getClickableBehavior(href, skipClientNav,
|
|
214
|
-
return /*#__PURE__*/createElement(ClickableBehavior, {
|
|
211
|
+
const ClickableBehavior = getClickableBehavior(href, skipClientNav, router);
|
|
212
|
+
return /*#__PURE__*/React.createElement(ClickableBehavior, {
|
|
215
213
|
disabled: sharedProps.disabled,
|
|
216
214
|
href: href,
|
|
217
215
|
onClick: onClick,
|
|
@@ -223,7 +221,7 @@ class IconButton extends Component {
|
|
|
223
221
|
} = _ref,
|
|
224
222
|
childrenProps = _objectWithoutPropertiesLoose(_ref, _excluded2);
|
|
225
223
|
|
|
226
|
-
return /*#__PURE__*/createElement(IconButtonCore, _extends({}, sharedProps, state, childrenProps, {
|
|
224
|
+
return /*#__PURE__*/React.createElement(IconButtonCore, _extends({}, sharedProps, state, childrenProps, {
|
|
227
225
|
skipClientNav: skipClientNav,
|
|
228
226
|
href: href,
|
|
229
227
|
target: target // If tabIndex is provide to the component we allow
|
|
@@ -235,10 +233,11 @@ class IconButton extends Component {
|
|
|
235
233
|
});
|
|
236
234
|
}
|
|
237
235
|
|
|
236
|
+
render() {
|
|
237
|
+
return /*#__PURE__*/React.createElement(__RouterContext.Consumer, null, router => this.renderClickableBehavior(router));
|
|
238
|
+
}
|
|
239
|
+
|
|
238
240
|
}
|
|
239
|
-
IconButton.contextTypes = {
|
|
240
|
-
router: any
|
|
241
|
-
};
|
|
242
241
|
IconButton.defaultProps = {
|
|
243
242
|
color: "default",
|
|
244
243
|
kind: "primary",
|
|
@@ -246,4 +245,4 @@ IconButton.defaultProps = {
|
|
|
246
245
|
disabled: false
|
|
247
246
|
};
|
|
248
247
|
|
|
249
|
-
export default
|
|
248
|
+
export { IconButton as default };
|
package/dist/index.js
CHANGED
|
@@ -89,19 +89,19 @@ module.exports =
|
|
|
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 */
|
|
@@ -127,10 +127,10 @@ module.exports = require("aphrodite");
|
|
|
127
127
|
|
|
128
128
|
"use strict";
|
|
129
129
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return IconButton; });
|
|
130
|
-
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(
|
|
130
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
|
|
131
131
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
132
|
-
/* harmony import */ var
|
|
133
|
-
/* harmony import */ var
|
|
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
134
|
/* harmony import */ var _khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(3);
|
|
135
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
136
|
/* harmony import */ var _icon_button_core_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(7);
|
|
@@ -178,7 +178,7 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
|
|
|
178
178
|
* ```
|
|
179
179
|
*/
|
|
180
180
|
class IconButton extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
|
|
181
|
-
|
|
181
|
+
renderClickableBehavior(router) {
|
|
182
182
|
const {
|
|
183
183
|
onClick,
|
|
184
184
|
href,
|
|
@@ -187,7 +187,7 @@ class IconButton extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
|
|
|
187
187
|
target,
|
|
188
188
|
...sharedProps
|
|
189
189
|
} = this.props;
|
|
190
|
-
const ClickableBehavior = Object(_khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_2__["getClickableBehavior"])(href, skipClientNav,
|
|
190
|
+
const ClickableBehavior = Object(_khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_2__["getClickableBehavior"])(href, skipClientNav, router);
|
|
191
191
|
return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](ClickableBehavior, {
|
|
192
192
|
disabled: sharedProps.disabled,
|
|
193
193
|
href: href,
|
|
@@ -210,10 +210,11 @@ class IconButton extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
|
|
|
210
210
|
});
|
|
211
211
|
}
|
|
212
212
|
|
|
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
|
+
}
|
|
216
|
+
|
|
213
217
|
}
|
|
214
|
-
IconButton.contextTypes = {
|
|
215
|
-
router: prop_types__WEBPACK_IMPORTED_MODULE_1__["any"]
|
|
216
|
-
};
|
|
217
218
|
IconButton.defaultProps = {
|
|
218
219
|
color: "default",
|
|
219
220
|
kind: "primary",
|
|
@@ -227,15 +228,15 @@ IconButton.defaultProps = {
|
|
|
227
228
|
|
|
228
229
|
"use strict";
|
|
229
230
|
/* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return IconButtonCore; });
|
|
230
|
-
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(
|
|
231
|
+
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
|
|
231
232
|
/* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
|
|
232
233
|
/* harmony import */ var aphrodite__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(5);
|
|
233
234
|
/* harmony import */ var aphrodite__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(aphrodite__WEBPACK_IMPORTED_MODULE_1__);
|
|
234
235
|
/* harmony import */ var react_router_dom__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8);
|
|
235
236
|
/* harmony import */ var react_router_dom__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(react_router_dom__WEBPACK_IMPORTED_MODULE_2__);
|
|
236
|
-
/* harmony import */ var
|
|
237
|
-
/* harmony import */ var
|
|
238
|
-
/* harmony import */ var _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(
|
|
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);
|
|
239
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__);
|
|
240
241
|
/* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(4);
|
|
241
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__);
|
|
@@ -257,7 +258,7 @@ const StyledAnchor = Object(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MO
|
|
|
257
258
|
const StyledButton = Object(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_5__["addStyle"])("button");
|
|
258
259
|
const StyledLink = Object(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_5__["addStyle"])(react_router_dom__WEBPACK_IMPORTED_MODULE_2__["Link"]);
|
|
259
260
|
class IconButtonCore extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
|
|
260
|
-
|
|
261
|
+
renderInner(router) {
|
|
261
262
|
const {
|
|
262
263
|
skipClientNav,
|
|
263
264
|
color,
|
|
@@ -274,9 +275,6 @@ class IconButtonCore extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
|
|
|
274
275
|
waiting: _,
|
|
275
276
|
...restProps
|
|
276
277
|
} = this.props;
|
|
277
|
-
const {
|
|
278
|
-
router
|
|
279
|
-
} = this.context;
|
|
280
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;
|
|
281
279
|
|
|
282
280
|
const buttonStyles = _generateStyles(buttonColor, kind, light);
|
|
@@ -308,10 +306,11 @@ class IconButtonCore extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
|
|
|
308
306
|
}
|
|
309
307
|
}
|
|
310
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
|
+
}
|
|
312
|
+
|
|
311
313
|
}
|
|
312
|
-
IconButtonCore.contextTypes = {
|
|
313
|
-
router: prop_types__WEBPACK_IMPORTED_MODULE_3__["any"]
|
|
314
|
-
};
|
|
315
314
|
const sharedStyles = aphrodite__WEBPACK_IMPORTED_MODULE_1__["StyleSheet"].create({
|
|
316
315
|
shared: {
|
|
317
316
|
position: "relative",
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-icon-button",
|
|
3
|
-
"version": "3.3
|
|
3
|
+
"version": "3.4.3",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -15,20 +15,19 @@
|
|
|
15
15
|
"author": "",
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"dependencies": {
|
|
18
|
-
"@babel/runtime": "^7.
|
|
19
|
-
"@khanacademy/wonder-blocks-clickable": "^2.
|
|
20
|
-
"@khanacademy/wonder-blocks-color": "^1.1.
|
|
21
|
-
"@khanacademy/wonder-blocks-core": "^
|
|
22
|
-
"@khanacademy/wonder-blocks-icon": "^1.2.
|
|
18
|
+
"@babel/runtime": "^7.16.3",
|
|
19
|
+
"@khanacademy/wonder-blocks-clickable": "^2.2.3",
|
|
20
|
+
"@khanacademy/wonder-blocks-color": "^1.1.20",
|
|
21
|
+
"@khanacademy/wonder-blocks-core": "^4.2.1",
|
|
22
|
+
"@khanacademy/wonder-blocks-icon": "^1.2.25"
|
|
23
23
|
},
|
|
24
24
|
"peerDependencies": {
|
|
25
25
|
"aphrodite": "^1.2.5",
|
|
26
|
-
"
|
|
27
|
-
"react": "
|
|
28
|
-
"react-router-dom": "
|
|
26
|
+
"react": "16.14.0",
|
|
27
|
+
"react-router": "5.2.1",
|
|
28
|
+
"react-router-dom": "5.3.0"
|
|
29
29
|
},
|
|
30
30
|
"devDependencies": {
|
|
31
|
-
"wb-dev-build-settings": "^0.
|
|
32
|
-
}
|
|
33
|
-
"gitHead": "9a9cc04bf2bbfb425f991a347b4f8b0d0d56e120"
|
|
31
|
+
"wb-dev-build-settings": "^0.3.0"
|
|
32
|
+
}
|
|
34
33
|
}
|
|
@@ -335,7 +335,7 @@ exports[`wonder-blocks-icon-button example 1 1`] = `
|
|
|
335
335
|
"width": 40,
|
|
336
336
|
}
|
|
337
337
|
}
|
|
338
|
-
tabIndex={
|
|
338
|
+
tabIndex={0}
|
|
339
339
|
type="button"
|
|
340
340
|
>
|
|
341
341
|
<svg
|
|
@@ -427,7 +427,7 @@ exports[`wonder-blocks-icon-button example 1 1`] = `
|
|
|
427
427
|
"width": 40,
|
|
428
428
|
}
|
|
429
429
|
}
|
|
430
|
-
tabIndex={
|
|
430
|
+
tabIndex={0}
|
|
431
431
|
type="button"
|
|
432
432
|
>
|
|
433
433
|
<svg
|
|
@@ -1,6 +1,7 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import {mount
|
|
3
|
+
import {mount} from "enzyme";
|
|
4
|
+
import "jest-enzyme";
|
|
4
5
|
|
|
5
6
|
import {MemoryRouter, Route, Switch} from "react-router-dom";
|
|
6
7
|
import {icons} from "@khanacademy/wonder-blocks-icon";
|
|
@@ -9,8 +10,19 @@ import expectRenderError from "../../../../../utils/testing/expect-render-error.
|
|
|
9
10
|
import IconButton from "../icon-button.js";
|
|
10
11
|
|
|
11
12
|
describe("IconButton", () => {
|
|
13
|
+
const {location} = window;
|
|
14
|
+
|
|
15
|
+
beforeAll(() => {
|
|
16
|
+
delete window.location;
|
|
17
|
+
window.location = {assign: jest.fn()};
|
|
18
|
+
});
|
|
19
|
+
|
|
20
|
+
afterAll(() => {
|
|
21
|
+
window.location = location;
|
|
22
|
+
});
|
|
23
|
+
|
|
12
24
|
test("render an icon", (done) => {
|
|
13
|
-
const wrapper =
|
|
25
|
+
const wrapper = mount(
|
|
14
26
|
<IconButton
|
|
15
27
|
icon={icons.search}
|
|
16
28
|
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
|
}
|
package/LICENSE
DELETED
|
@@ -1,21 +0,0 @@
|
|
|
1
|
-
MIT License
|
|
2
|
-
|
|
3
|
-
Copyright (c) 2018 Khan Academy
|
|
4
|
-
|
|
5
|
-
Permission is hereby granted, free of charge, to any person obtaining a copy
|
|
6
|
-
of this software and associated documentation files (the "Software"), to deal
|
|
7
|
-
in the Software without restriction, including without limitation the rights
|
|
8
|
-
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
|
9
|
-
copies of the Software, and to permit persons to whom the Software is
|
|
10
|
-
furnished to do so, subject to the following conditions:
|
|
11
|
-
|
|
12
|
-
The above copyright notice and this permission notice shall be included in all
|
|
13
|
-
copies or substantial portions of the Software.
|
|
14
|
-
|
|
15
|
-
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
|
16
|
-
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
|
17
|
-
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
|
18
|
-
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
|
19
|
-
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
|
20
|
-
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
|
|
21
|
-
SOFTWARE.
|