@khanacademy/wonder-blocks-icon-button 3.3.13 → 3.4.2

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
package/CHANGELOG.md ADDED
@@ -0,0 +1,7 @@
1
+ # @khanacademy/wonder-blocks-icon-button
2
+
3
+ ## 3.4.2
4
+ ### Patch Changes
5
+
6
+ - Updated dependencies [901bfe82]
7
+ - @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 { Component, createElement } from 'react';
4
- import { any } from 'prop-types';
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
- render() {
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$1 = ["onClick", "href", "skipClientNav", "tabIndex", "target"],
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
- render() {
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$1);
209
+ sharedProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
212
210
 
213
- const ClickableBehavior = getClickableBehavior(href, skipClientNav, this.context.router);
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 IconButton;
248
+ export { IconButton as default };
package/dist/index.js CHANGED
@@ -89,147 +89,163 @@ module.exports =
89
89
  /* 0 */
90
90
  /***/ (function(module, exports) {
91
91
 
92
- module.exports = require("@khanacademy/wonder-blocks-color");
92
+ module.exports = require("react");
93
93
 
94
94
  /***/ }),
95
95
  /* 1 */
96
96
  /***/ (function(module, exports) {
97
97
 
98
- module.exports = require("react");
98
+ module.exports = require("@khanacademy/wonder-blocks-color");
99
99
 
100
100
  /***/ }),
101
101
  /* 2 */
102
102
  /***/ (function(module, exports) {
103
103
 
104
- function _extends() {
105
- module.exports = _extends = Object.assign || function (target) {
106
- for (var i = 1; i < arguments.length; i++) {
107
- var source = arguments[i];
108
-
109
- for (var key in source) {
110
- if (Object.prototype.hasOwnProperty.call(source, key)) {
111
- target[key] = source[key];
112
- }
113
- }
114
- }
115
-
116
- return target;
117
- };
118
-
119
- module.exports["default"] = module.exports, module.exports.__esModule = true;
120
- return _extends.apply(this, arguments);
121
- }
122
-
123
- module.exports = _extends;
124
- module.exports["default"] = module.exports, module.exports.__esModule = true;
104
+ module.exports = require("react-router");
125
105
 
126
106
  /***/ }),
127
107
  /* 3 */
128
108
  /***/ (function(module, exports) {
129
109
 
130
- function _objectWithoutPropertiesLoose(source, excluded) {
131
- if (source == null) return {};
132
- var target = {};
133
- var sourceKeys = Object.keys(source);
134
- var key, i;
135
-
136
- for (i = 0; i < sourceKeys.length; i++) {
137
- key = sourceKeys[i];
138
- if (excluded.indexOf(key) >= 0) continue;
139
- target[key] = source[key];
140
- }
141
-
142
- return target;
143
- }
144
-
145
- module.exports = _objectWithoutPropertiesLoose;
146
- module.exports["default"] = module.exports, module.exports.__esModule = true;
147
-
148
- /***/ }),
149
- /* 4 */
150
- /***/ (function(module, exports) {
151
-
152
- module.exports = require("prop-types");
153
-
154
- /***/ }),
155
- /* 5 */
156
- /***/ (function(module, exports) {
157
-
158
110
  module.exports = require("@khanacademy/wonder-blocks-clickable");
159
111
 
160
112
  /***/ }),
161
- /* 6 */
113
+ /* 4 */
162
114
  /***/ (function(module, exports) {
163
115
 
164
116
  module.exports = require("@khanacademy/wonder-blocks-core");
165
117
 
166
118
  /***/ }),
167
- /* 7 */
119
+ /* 5 */
168
120
  /***/ (function(module, exports) {
169
121
 
170
122
  module.exports = require("aphrodite");
171
123
 
172
124
  /***/ }),
173
- /* 8 */
174
- /***/ (function(module, exports) {
175
-
176
- module.exports = require("react-router-dom");
177
-
178
- /***/ }),
179
- /* 9 */
180
- /***/ (function(module, exports) {
181
-
182
- module.exports = require("@khanacademy/wonder-blocks-icon");
183
-
184
- /***/ }),
185
- /* 10 */
125
+ /* 6 */
186
126
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
187
127
 
188
128
  "use strict";
189
- // ESM COMPAT FLAG
190
- __webpack_require__.r(__webpack_exports__);
191
-
192
- // EXPORTS
193
- __webpack_require__.d(__webpack_exports__, "default", function() { return /* reexport */ icon_button_IconButton; });
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);
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); }
194
138
 
195
- // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/extends.js
196
- var helpers_extends = __webpack_require__(2);
197
- var extends_default = /*#__PURE__*/__webpack_require__.n(helpers_extends);
198
139
 
199
- // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/objectWithoutPropertiesLoose.js
200
- var objectWithoutPropertiesLoose = __webpack_require__(3);
201
- var objectWithoutPropertiesLoose_default = /*#__PURE__*/__webpack_require__.n(objectWithoutPropertiesLoose);
202
140
 
203
- // EXTERNAL MODULE: external "react"
204
- var external_react_ = __webpack_require__(1);
205
141
 
206
- // EXTERNAL MODULE: external "prop-types"
207
- var external_prop_types_ = __webpack_require__(4);
208
142
 
209
- // EXTERNAL MODULE: external "@khanacademy/wonder-blocks-clickable"
210
- var wonder_blocks_clickable_ = __webpack_require__(5);
211
143
 
212
- // EXTERNAL MODULE: external "aphrodite"
213
- var external_aphrodite_ = __webpack_require__(7);
214
-
215
- // EXTERNAL MODULE: external "react-router-dom"
216
- var external_react_router_dom_ = __webpack_require__(8);
217
-
218
- // EXTERNAL MODULE: external "@khanacademy/wonder-blocks-color"
219
- var wonder_blocks_color_ = __webpack_require__(0);
220
- var wonder_blocks_color_default = /*#__PURE__*/__webpack_require__.n(wonder_blocks_color_);
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
+ }
221
212
 
222
- // EXTERNAL MODULE: external "@khanacademy/wonder-blocks-core"
223
- var wonder_blocks_core_ = __webpack_require__(6);
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
+ }
224
216
 
225
- // EXTERNAL MODULE: external "@khanacademy/wonder-blocks-icon"
226
- var wonder_blocks_icon_ = __webpack_require__(9);
227
- var wonder_blocks_icon_default = /*#__PURE__*/__webpack_require__.n(wonder_blocks_icon_);
217
+ }
218
+ IconButton.defaultProps = {
219
+ color: "default",
220
+ kind: "primary",
221
+ light: false,
222
+ disabled: false
223
+ };
228
224
 
229
- // CONCATENATED MODULE: ./packages/wonder-blocks-icon-button/src/components/icon-button-core.js
225
+ /***/ }),
226
+ /* 7 */
227
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
230
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); }
231
248
 
232
- const _excluded = ["skipClientNav", "color", "disabled", "focused", "hovered", "href", "icon", "kind", "light", "pressed", "style", "testId", "waiting"];
233
249
 
234
250
 
235
251
 
@@ -238,13 +254,12 @@ const _excluded = ["skipClientNav", "color", "disabled", "focused", "hovered", "
238
254
 
239
255
 
240
256
 
241
- const StyledAnchor = Object(wonder_blocks_core_["addStyle"])("a");
242
- const StyledButton = Object(wonder_blocks_core_["addStyle"])("button");
243
- const StyledLink = Object(wonder_blocks_core_["addStyle"])(external_react_router_dom_["Link"]);
244
- class icon_button_core_IconButtonCore extends external_react_["Component"] {
245
- render() {
246
- const _this$props = this.props,
247
- {
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 {
248
263
  skipClientNav,
249
264
  color,
250
265
  disabled,
@@ -256,37 +271,34 @@ class icon_button_core_IconButtonCore extends external_react_["Component"] {
256
271
  light,
257
272
  pressed,
258
273
  style,
259
- testId
260
- } = _this$props,
261
- restProps = objectWithoutPropertiesLoose_default()(_this$props, _excluded);
262
-
263
- const {
264
- router
265
- } = this.context;
266
- const buttonColor = color === "destructive" ? wonder_blocks_color_["SemanticColor"].controlDestructive : wonder_blocks_color_["SemanticColor"].controlDefault;
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;
267
279
 
268
280
  const buttonStyles = _generateStyles(buttonColor, kind, light);
269
281
 
270
282
  const defaultStyle = [sharedStyles.shared, disabled && sharedStyles.disabled, buttonStyles.default, disabled && buttonStyles.disabled, !disabled && (pressed ? buttonStyles.active : (hovered || focused) && buttonStyles.focus)];
271
- const child = /*#__PURE__*/external_react_["createElement"](wonder_blocks_icon_default.a, {
283
+ const child = /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_khanacademy_wonder_blocks_icon__WEBPACK_IMPORTED_MODULE_7___default.a, {
272
284
  size: "medium",
273
285
  color: "currentColor",
274
286
  icon: icon
275
287
  });
276
-
277
- const commonProps = extends_default()({
288
+ const commonProps = {
278
289
  "data-test-id": testId,
279
- style: [defaultStyle, style]
280
- }, restProps);
290
+ style: [defaultStyle, style],
291
+ ...restProps
292
+ };
281
293
 
282
294
  if (href && !disabled) {
283
- return router && !skipClientNav && Object(wonder_blocks_clickable_["isClientSideUrl"])(href) ? /*#__PURE__*/external_react_["createElement"](StyledLink, extends_default()({}, commonProps, {
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, {
284
296
  to: href
285
- }), child) : /*#__PURE__*/external_react_["createElement"](StyledAnchor, extends_default()({}, commonProps, {
297
+ }), child) : /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](StyledAnchor, _extends({}, commonProps, {
286
298
  href: href
287
299
  }), child);
288
300
  } else {
289
- return /*#__PURE__*/external_react_["createElement"](StyledButton, extends_default()({
301
+ return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](StyledButton, _extends({
290
302
  type: "button"
291
303
  }, commonProps, {
292
304
  disabled: disabled
@@ -294,11 +306,12 @@ class icon_button_core_IconButtonCore extends external_react_["Component"] {
294
306
  }
295
307
  }
296
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
+
297
313
  }
298
- icon_button_core_IconButtonCore.contextTypes = {
299
- router: external_prop_types_["any"]
300
- };
301
- const sharedStyles = external_aphrodite_["StyleSheet"].create({
314
+ const sharedStyles = aphrodite__WEBPACK_IMPORTED_MODULE_1__["StyleSheet"].create({
302
315
  shared: {
303
316
  position: "relative",
304
317
  display: "inline-flex",
@@ -344,7 +357,7 @@ const _generateStyles = (color, kind, light) => {
344
357
  offBlack32,
345
358
  offBlack64,
346
359
  offBlack
347
- } = wonder_blocks_color_default.a;
360
+ } = _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_4___default.a;
348
361
  const newStyles = {
349
362
  default: {},
350
363
  focus: {
@@ -355,14 +368,14 @@ const _generateStyles = (color, kind, light) => {
355
368
  borderRadius: 4
356
369
  },
357
370
  active: {
358
- color: light ? Object(wonder_blocks_color_["mix"])(Object(wonder_blocks_color_["fade"])(color, 0.32), white) : Object(wonder_blocks_color_["mix"])(offBlack32, color),
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),
359
372
  borderWidth: 2,
360
- borderColor: light ? Object(wonder_blocks_color_["mix"])(Object(wonder_blocks_color_["fade"])(color, 0.32), white) : Object(wonder_blocks_color_["mix"])(offBlack32, color),
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),
361
374
  borderStyle: "solid",
362
375
  borderRadius: 4
363
376
  },
364
377
  disabled: {
365
- color: light ? Object(wonder_blocks_color_["mix"])(Object(wonder_blocks_color_["fade"])(white, 0.32), color) : offBlack32,
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,
366
379
  cursor: "default"
367
380
  }
368
381
  };
@@ -383,103 +396,31 @@ const _generateStyles = (color, kind, light) => {
383
396
  throw new Error("IconButton kind not recognized");
384
397
  }
385
398
 
386
- styles[buttonType] = external_aphrodite_["StyleSheet"].create(newStyles);
399
+ styles[buttonType] = aphrodite__WEBPACK_IMPORTED_MODULE_1__["StyleSheet"].create(newStyles);
387
400
  return styles[buttonType];
388
401
  };
389
- // CONCATENATED MODULE: ./packages/wonder-blocks-icon-button/src/components/icon-button.js
390
-
391
-
392
- const icon_button_excluded = ["onClick", "href", "skipClientNav", "tabIndex", "target"],
393
- _excluded2 = ["tabIndex"];
394
-
395
402
 
403
+ /***/ }),
404
+ /* 8 */
405
+ /***/ (function(module, exports) {
396
406
 
407
+ module.exports = require("react-router-dom");
397
408
 
409
+ /***/ }),
410
+ /* 9 */
411
+ /***/ (function(module, exports) {
398
412
 
399
- /**
400
- * An IconButton is a button whose contents are an SVG image.
401
- *
402
- * To use, supply an onClick function, a wonder-blocks icon asset (see
403
- * the Icon section) and an aria-label to describe the button functionality.
404
- * Optionally specify href (URL), clientSideNav, color
405
- * (Wonder Blocks Blue or Red), kind ("primary", "secondary", or "tertiary"),
406
- * light (whether the IconButton will be rendered on a dark background),
407
- * disabled , test ID, and custom styling.
408
- *
409
- * The size of an IconButton matches the size of icon it wraps which is 24x24
410
- * pixels. The focus ring which is displayed on hover and focus is much
411
- * larger but does not affect its size. This matches the behavior of Button.
412
- *
413
- * IconButtons require a certain amount of space between them to ensure the
414
- * focus rings don't overlap. The minimum amount of spacing is 16px, but
415
- * you should refer to the mocks provided by design. Using a Strut in between
416
- * IconButtons is the preferred way to for adding this spacing.
417
- *
418
- * Many layouts require alignment of visual left (or right) side of an
419
- * IconButton. This requires a little bit of pixel nudging since each icon
420
- * as a different amount of internal padding.
421
- *
422
- * See the Toolbar documentation for examples of IconButton use that follow
423
- * the best practices described above.
424
- *
425
- * ```js
426
- * import {icons} from "@khanacademy/wonder-blocks-icon";
427
- *
428
- * <IconButton
429
- * icon={icons.anIcon}
430
- * aria-label="An Icon"
431
- * onClick={(e) => console.log("Hello, world!")}
432
- * />
433
- * ```
434
- */
435
- class icon_button_IconButton extends external_react_["Component"] {
436
- render() {
437
- const _this$props = this.props,
438
- {
439
- onClick,
440
- href,
441
- skipClientNav,
442
- tabIndex,
443
- target
444
- } = _this$props,
445
- sharedProps = objectWithoutPropertiesLoose_default()(_this$props, icon_button_excluded);
413
+ module.exports = require("@khanacademy/wonder-blocks-icon");
446
414
 
447
- const ClickableBehavior = Object(wonder_blocks_clickable_["getClickableBehavior"])(href, skipClientNav, this.context.router);
448
- return /*#__PURE__*/external_react_["createElement"](ClickableBehavior, {
449
- disabled: sharedProps.disabled,
450
- href: href,
451
- onClick: onClick,
452
- role: "button",
453
- target: target
454
- }, (state, _ref) => {
455
- let {
456
- tabIndex: clickableTabIndex
457
- } = _ref,
458
- childrenProps = objectWithoutPropertiesLoose_default()(_ref, _excluded2);
415
+ /***/ }),
416
+ /* 10 */
417
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
459
418
 
460
- return /*#__PURE__*/external_react_["createElement"](icon_button_core_IconButtonCore, extends_default()({}, sharedProps, state, childrenProps, {
461
- skipClientNav: skipClientNav,
462
- href: href,
463
- target: target // If tabIndex is provide to the component we allow
464
- // it to override the tabIndex provide to use by
465
- // ClickableBehavior.
466
- ,
467
- tabIndex: tabIndex || clickableTabIndex
468
- }));
469
- });
470
- }
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"]; });
471
423
 
472
- }
473
- icon_button_IconButton.contextTypes = {
474
- router: external_prop_types_["any"]
475
- };
476
- icon_button_IconButton.defaultProps = {
477
- color: "default",
478
- kind: "primary",
479
- light: false,
480
- disabled: false
481
- };
482
- // CONCATENATED MODULE: ./packages/wonder-blocks-icon-button/src/index.js
483
424
 
484
425
 
485
426
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-icon-button",
3
- "version": "3.3.13",
3
+ "version": "3.4.2",
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.13.10",
19
- "@khanacademy/wonder-blocks-clickable": "^2.1.2",
20
- "@khanacademy/wonder-blocks-color": "^1.1.18",
21
- "@khanacademy/wonder-blocks-core": "^3.1.4",
22
- "@khanacademy/wonder-blocks-icon": "^1.2.21"
18
+ "@babel/runtime": "^7.16.3",
19
+ "@khanacademy/wonder-blocks-clickable": "^2.2.2",
20
+ "@khanacademy/wonder-blocks-color": "^1.1.20",
21
+ "@khanacademy/wonder-blocks-core": "^4.0.0",
22
+ "@khanacademy/wonder-blocks-icon": "^1.2.24"
23
23
  },
24
24
  "peerDependencies": {
25
25
  "aphrodite": "^1.2.5",
26
- "prop-types": "^15.6.2",
27
- "react": "^16.4.1",
28
- "react-router-dom": "^4.2.2"
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.1.0"
32
- },
33
- "gitHead": "8022bb419eed74be37f71f71c7621854794a731c"
31
+ "wb-dev-build-settings": "^0.2.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={-1}
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={-1}
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, shallow} from "enzyme";
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 = shallow(
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 * as PropTypes from "prop-types";
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
- static contextTypes: ContextTypes = {router: PropTypes.any};
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 * as PropTypes from "prop-types";
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
- render(): React.Node {
186
- const {
187
- onClick,
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
- this.context.router,
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.