@khanacademy/wonder-blocks-link 3.7.13 → 3.8.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-link
2
+
3
+ ## 3.8.2
4
+ ### Patch Changes
5
+
6
+ - Updated dependencies [901bfe82]
7
+ - @khanacademy/wonder-blocks-clickable@2.2.2
package/dist/es/index.js CHANGED
@@ -1,18 +1,18 @@
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 as Link$1 } from 'react-router-dom';
8
8
  import { addStyle } from '@khanacademy/wonder-blocks-core';
9
9
  import Color, { mix, fade } from '@khanacademy/wonder-blocks-color';
10
10
 
11
- const _excluded = ["children", "skipClientNav", "focused", "hovered", "href", "kind", "light", "visitable", "pressed", "style", "testId", "waiting"];
11
+ const _excluded$1 = ["children", "skipClientNav", "focused", "hovered", "href", "kind", "light", "visitable", "pressed", "style", "testId", "waiting"];
12
12
  const StyledAnchor = addStyle("a");
13
13
  const StyledLink = addStyle(Link$1);
14
- class LinkCore extends Component {
15
- render() {
14
+ class LinkCore extends React.Component {
15
+ renderInner(router) {
16
16
  const _this$props = this.props,
17
17
  {
18
18
  children,
@@ -27,11 +27,7 @@ class LinkCore extends Component {
27
27
  style,
28
28
  testId
29
29
  } = _this$props,
30
- restProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
31
-
32
- const {
33
- router
34
- } = this.context;
30
+ restProps = _objectWithoutPropertiesLoose(_this$props, _excluded$1);
35
31
 
36
32
  const linkStyles = _generateStyles(kind, light, visitable);
37
33
 
@@ -42,17 +38,18 @@ class LinkCore extends Component {
42
38
  style: [defaultStyles, style]
43
39
  }, restProps);
44
40
 
45
- return router && !skipClientNav && isClientSideUrl(href) ? /*#__PURE__*/createElement(StyledLink, _extends({}, commonProps, {
41
+ return router && !skipClientNav && isClientSideUrl(href) ? /*#__PURE__*/React.createElement(StyledLink, _extends({}, commonProps, {
46
42
  to: href
47
- }), children) : /*#__PURE__*/createElement(StyledAnchor, _extends({}, commonProps, {
43
+ }), children) : /*#__PURE__*/React.createElement(StyledAnchor, _extends({}, commonProps, {
48
44
  href: href
49
45
  }), children);
50
46
  }
51
47
 
48
+ render() {
49
+ return /*#__PURE__*/React.createElement(__RouterContext.Consumer, null, router => this.renderInner(router));
50
+ }
51
+
52
52
  }
53
- LinkCore.contextTypes = {
54
- router: any
55
- };
56
53
  const styles = {};
57
54
  const sharedStyles = StyleSheet.create({
58
55
  shared: {
@@ -115,7 +112,7 @@ const _generateStyles = (kind, light, visitable) => {
115
112
  return styles[buttonType];
116
113
  };
117
114
 
118
- const _excluded$1 = ["onClick", "beforeNav", "safeWithNav", "href", "skipClientNav", "children", "tabIndex", "onKeyDown", "onKeyUp", "target"],
115
+ const _excluded = ["onClick", "beforeNav", "safeWithNav", "href", "skipClientNav", "children", "tabIndex", "onKeyDown", "onKeyUp", "target"],
119
116
  _excluded2 = ["tabIndex"],
120
117
  _excluded3 = ["tabIndex"];
121
118
 
@@ -136,8 +133,8 @@ const _excluded$1 = ["onClick", "beforeNav", "safeWithNav", "href", "skipClientN
136
133
  * </Link>
137
134
  * ```
138
135
  */
139
- class Link extends Component {
140
- render() {
136
+ class Link extends React.Component {
137
+ renderClickableBehavior(router) {
141
138
  const _this$props = this.props,
142
139
  {
143
140
  onClick,
@@ -151,12 +148,12 @@ class Link extends Component {
151
148
  onKeyUp,
152
149
  target = undefined
153
150
  } = _this$props,
154
- sharedProps = _objectWithoutPropertiesLoose(_this$props, _excluded$1);
151
+ sharedProps = _objectWithoutPropertiesLoose(_this$props, _excluded);
155
152
 
156
- const ClickableBehavior = getClickableBehavior(href, skipClientNav, this.context.router);
153
+ const ClickableBehavior = getClickableBehavior(href, skipClientNav, router);
157
154
 
158
155
  if (beforeNav) {
159
- return /*#__PURE__*/createElement(ClickableBehavior, {
156
+ return /*#__PURE__*/React.createElement(ClickableBehavior, {
160
157
  disabled: false,
161
158
  href: href,
162
159
  role: "link",
@@ -171,7 +168,7 @@ class Link extends Component {
171
168
  } = _ref,
172
169
  childrenProps = _objectWithoutPropertiesLoose(_ref, _excluded2);
173
170
 
174
- return /*#__PURE__*/createElement(LinkCore, _extends({}, sharedProps, state, childrenProps, {
171
+ return /*#__PURE__*/React.createElement(LinkCore, _extends({}, sharedProps, state, childrenProps, {
175
172
  skipClientNav: skipClientNav,
176
173
  href: href,
177
174
  target: target // If tabIndex is provide to the component we allow
@@ -182,7 +179,7 @@ class Link extends Component {
182
179
  }), children);
183
180
  });
184
181
  } else {
185
- return /*#__PURE__*/createElement(ClickableBehavior, {
182
+ return /*#__PURE__*/React.createElement(ClickableBehavior, {
186
183
  disabled: false,
187
184
  href: href,
188
185
  role: "link",
@@ -197,7 +194,7 @@ class Link extends Component {
197
194
  } = _ref2,
198
195
  childrenProps = _objectWithoutPropertiesLoose(_ref2, _excluded3);
199
196
 
200
- return /*#__PURE__*/createElement(LinkCore, _extends({}, sharedProps, state, childrenProps, {
197
+ return /*#__PURE__*/React.createElement(LinkCore, _extends({}, sharedProps, state, childrenProps, {
201
198
  skipClientNav: skipClientNav,
202
199
  href: href,
203
200
  target: target // If tabIndex is provide to the component we allow
@@ -210,14 +207,15 @@ class Link extends Component {
210
207
  }
211
208
  }
212
209
 
210
+ render() {
211
+ return /*#__PURE__*/React.createElement(__RouterContext.Consumer, null, router => this.renderClickableBehavior(router));
212
+ }
213
+
213
214
  }
214
- Link.contextTypes = {
215
- router: any
216
- };
217
215
  Link.defaultProps = {
218
216
  kind: "primary",
219
217
  light: false,
220
218
  visitable: false
221
219
  };
222
220
 
223
- export default Link;
221
+ export { Link as default };
package/dist/index.js CHANGED
@@ -89,150 +89,60 @@ module.exports =
89
89
  /* 0 */
90
90
  /***/ (function(module, exports) {
91
91
 
92
- function _extends() {
93
- module.exports = _extends = Object.assign || function (target) {
94
- for (var i = 1; i < arguments.length; i++) {
95
- var source = arguments[i];
96
-
97
- for (var key in source) {
98
- if (Object.prototype.hasOwnProperty.call(source, key)) {
99
- target[key] = source[key];
100
- }
101
- }
102
- }
103
-
104
- return target;
105
- };
106
-
107
- module.exports["default"] = module.exports, module.exports.__esModule = true;
108
- return _extends.apply(this, arguments);
109
- }
110
-
111
- module.exports = _extends;
112
- module.exports["default"] = module.exports, module.exports.__esModule = true;
92
+ module.exports = require("react");
113
93
 
114
94
  /***/ }),
115
95
  /* 1 */
116
96
  /***/ (function(module, exports) {
117
97
 
118
- module.exports = require("react");
98
+ module.exports = require("@khanacademy/wonder-blocks-color");
119
99
 
120
100
  /***/ }),
121
101
  /* 2 */
122
102
  /***/ (function(module, exports) {
123
103
 
124
- module.exports = require("@khanacademy/wonder-blocks-color");
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 */
162
- /***/ (function(module, exports) {
163
-
164
- module.exports = require("aphrodite");
165
-
166
- /***/ }),
167
- /* 7 */
168
- /***/ (function(module, exports) {
169
-
170
- module.exports = require("@khanacademy/wonder-blocks-core");
171
-
172
- /***/ }),
173
- /* 8 */
174
- /***/ (function(module, exports) {
175
-
176
- module.exports = require("react-router-dom");
177
-
178
- /***/ }),
179
- /* 9 */
113
+ /* 4 */
180
114
  /***/ (function(module, __webpack_exports__, __webpack_require__) {
181
115
 
182
116
  "use strict";
183
- // ESM COMPAT FLAG
184
- __webpack_require__.r(__webpack_exports__);
185
-
186
- // EXPORTS
187
- __webpack_require__.d(__webpack_exports__, "default", function() { return /* reexport */ link_Link; });
188
-
189
- // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/extends.js
190
- var helpers_extends = __webpack_require__(0);
191
- var extends_default = /*#__PURE__*/__webpack_require__.n(helpers_extends);
192
-
193
- // EXTERNAL MODULE: ./node_modules/@babel/runtime/helpers/objectWithoutPropertiesLoose.js
194
- var objectWithoutPropertiesLoose = __webpack_require__(3);
195
- var objectWithoutPropertiesLoose_default = /*#__PURE__*/__webpack_require__.n(objectWithoutPropertiesLoose);
196
-
197
- // EXTERNAL MODULE: external "react"
198
- var external_react_ = __webpack_require__(1);
199
-
200
- // EXTERNAL MODULE: external "prop-types"
201
- var external_prop_types_ = __webpack_require__(4);
202
-
203
- // EXTERNAL MODULE: external "@khanacademy/wonder-blocks-clickable"
204
- var wonder_blocks_clickable_ = __webpack_require__(5);
205
-
206
- // EXTERNAL MODULE: external "aphrodite"
207
- var external_aphrodite_ = __webpack_require__(6);
208
-
209
- // EXTERNAL MODULE: external "react-router-dom"
210
- var external_react_router_dom_ = __webpack_require__(8);
211
-
212
- // EXTERNAL MODULE: external "@khanacademy/wonder-blocks-core"
213
- var wonder_blocks_core_ = __webpack_require__(7);
117
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return LinkCore; });
118
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
119
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
120
+ /* harmony import */ var aphrodite__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(5);
121
+ /* harmony import */ var aphrodite__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(aphrodite__WEBPACK_IMPORTED_MODULE_1__);
122
+ /* harmony import */ var react_router_dom__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8);
123
+ /* harmony import */ var react_router_dom__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(react_router_dom__WEBPACK_IMPORTED_MODULE_2__);
124
+ /* harmony import */ var react_router__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(2);
125
+ /* harmony import */ var react_router__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(react_router__WEBPACK_IMPORTED_MODULE_3__);
126
+ /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(6);
127
+ /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_4___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_4__);
128
+ /* harmony import */ var _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(1);
129
+ /* harmony import */ var _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_5___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_5__);
130
+ /* harmony import */ var _khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_6__ = __webpack_require__(3);
131
+ /* harmony import */ var _khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_6___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_6__);
132
+ 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); }
214
133
 
215
- // EXTERNAL MODULE: external "@khanacademy/wonder-blocks-color"
216
- var wonder_blocks_color_ = __webpack_require__(2);
217
- var wonder_blocks_color_default = /*#__PURE__*/__webpack_require__.n(wonder_blocks_color_);
218
134
 
219
- // CONCATENATED MODULE: ./packages/wonder-blocks-link/src/components/link-core.js
220
135
 
221
136
 
222
- const _excluded = ["children", "skipClientNav", "focused", "hovered", "href", "kind", "light", "visitable", "pressed", "style", "testId", "waiting"];
223
137
 
224
138
 
225
139
 
226
140
 
227
-
228
-
229
-
230
- const StyledAnchor = Object(wonder_blocks_core_["addStyle"])("a");
231
- const StyledLink = Object(wonder_blocks_core_["addStyle"])(external_react_router_dom_["Link"]);
232
- class link_core_LinkCore extends external_react_["Component"] {
233
- render() {
234
- const _this$props = this.props,
235
- {
141
+ const StyledAnchor = Object(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_4__["addStyle"])("a");
142
+ const StyledLink = Object(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_4__["addStyle"])(react_router_dom__WEBPACK_IMPORTED_MODULE_2__["Link"]);
143
+ class LinkCore extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
144
+ renderInner(router) {
145
+ const {
236
146
  children,
237
147
  skipClientNav,
238
148
  focused,
@@ -243,36 +153,33 @@ class link_core_LinkCore extends external_react_["Component"] {
243
153
  visitable,
244
154
  pressed,
245
155
  style,
246
- testId
247
- } = _this$props,
248
- restProps = objectWithoutPropertiesLoose_default()(_this$props, _excluded);
249
-
250
- const {
251
- router
252
- } = this.context;
156
+ testId,
157
+ waiting: _,
158
+ ...restProps
159
+ } = this.props;
253
160
 
254
161
  const linkStyles = _generateStyles(kind, light, visitable);
255
162
 
256
163
  const defaultStyles = [sharedStyles.shared, !(hovered || focused || pressed) && linkStyles.default, pressed ? linkStyles.active : (hovered || focused) && linkStyles.focus];
257
-
258
- const commonProps = extends_default()({
164
+ const commonProps = {
259
165
  "data-test-id": testId,
260
- style: [defaultStyles, style]
261
- }, restProps);
262
-
263
- return router && !skipClientNav && Object(wonder_blocks_clickable_["isClientSideUrl"])(href) ? /*#__PURE__*/external_react_["createElement"](StyledLink, extends_default()({}, commonProps, {
166
+ style: [defaultStyles, style],
167
+ ...restProps
168
+ };
169
+ return router && !skipClientNav && Object(_khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_6__["isClientSideUrl"])(href) ? /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](StyledLink, _extends({}, commonProps, {
264
170
  to: href
265
- }), children) : /*#__PURE__*/external_react_["createElement"](StyledAnchor, extends_default()({}, commonProps, {
171
+ }), children) : /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](StyledAnchor, _extends({}, commonProps, {
266
172
  href: href
267
173
  }), children);
268
174
  }
269
175
 
176
+ render() {
177
+ return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](react_router__WEBPACK_IMPORTED_MODULE_3__["__RouterContext"].Consumer, null, router => this.renderInner(router));
178
+ }
179
+
270
180
  }
271
- link_core_LinkCore.contextTypes = {
272
- router: external_prop_types_["any"]
273
- };
274
181
  const styles = {};
275
- const sharedStyles = external_aphrodite_["StyleSheet"].create({
182
+ const sharedStyles = aphrodite__WEBPACK_IMPORTED_MODULE_1__["StyleSheet"].create({
276
183
  shared: {
277
184
  cursor: "pointer",
278
185
  textDecoration: "none",
@@ -301,11 +208,11 @@ const _generateStyles = (kind, light, visitable) => {
301
208
  white,
302
209
  offBlack,
303
210
  offBlack32
304
- } = wonder_blocks_color_default.a;
305
- const linkPurple = Object(wonder_blocks_color_["mix"])(Object(wonder_blocks_color_["fade"])(offBlack, 0.08), purple);
211
+ } = _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_5___default.a;
212
+ const linkPurple = Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_5__["mix"])(Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_5__["fade"])(offBlack, 0.08), purple);
306
213
  const defaultTextColor = kind === "primary" ? light ? white : blue : offBlack;
307
214
  const focusColor = light ? white : blue;
308
- const activeColor = light ? Object(wonder_blocks_color_["mix"])(Object(wonder_blocks_color_["fade"])(blue, 0.32), white) : Object(wonder_blocks_color_["mix"])(offBlack32, blue);
215
+ const activeColor = light ? Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_5__["mix"])(Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_5__["fade"])(blue, 0.32), white) : Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_5__["mix"])(offBlack32, blue);
309
216
  const defaultVisited = visitable ? {
310
217
  ":visited": {
311
218
  color: linkPurple
@@ -313,31 +220,56 @@ const _generateStyles = (kind, light, visitable) => {
313
220
  } : Object.freeze({});
314
221
  const activeVisited = visitable ? {
315
222
  ":visited": {
316
- color: Object(wonder_blocks_color_["mix"])(offBlack32, linkPurple)
223
+ color: Object(_khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_5__["mix"])(offBlack32, linkPurple)
317
224
  }
318
225
  } : Object.freeze({});
319
226
  const newStyles = {
320
- default: extends_default()({
321
- color: defaultTextColor
322
- }, defaultVisited),
323
- focus: extends_default()({
227
+ default: {
228
+ color: defaultTextColor,
229
+ ...defaultVisited
230
+ },
231
+ focus: {
324
232
  textDecoration: "underline currentcolor solid",
325
- color: focusColor
326
- }, defaultVisited),
327
- active: extends_default()({
233
+ color: focusColor,
234
+ ...defaultVisited
235
+ },
236
+ active: {
328
237
  color: activeColor,
329
- textDecoration: "underline currentcolor solid"
330
- }, activeVisited)
238
+ textDecoration: "underline currentcolor solid",
239
+ ...activeVisited
240
+ }
331
241
  };
332
- styles[buttonType] = external_aphrodite_["StyleSheet"].create(newStyles);
242
+ styles[buttonType] = aphrodite__WEBPACK_IMPORTED_MODULE_1__["StyleSheet"].create(newStyles);
333
243
  return styles[buttonType];
334
244
  };
335
- // CONCATENATED MODULE: ./packages/wonder-blocks-link/src/components/link.js
336
245
 
246
+ /***/ }),
247
+ /* 5 */
248
+ /***/ (function(module, exports) {
249
+
250
+ module.exports = require("aphrodite");
251
+
252
+ /***/ }),
253
+ /* 6 */
254
+ /***/ (function(module, exports) {
255
+
256
+ module.exports = require("@khanacademy/wonder-blocks-core");
257
+
258
+ /***/ }),
259
+ /* 7 */
260
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
261
+
262
+ "use strict";
263
+ /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return Link; });
264
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
265
+ /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
266
+ /* harmony import */ var react_router__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2);
267
+ /* harmony import */ var react_router__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(react_router__WEBPACK_IMPORTED_MODULE_1__);
268
+ /* harmony import */ var _khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(3);
269
+ /* harmony import */ var _khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_2___default = /*#__PURE__*/__webpack_require__.n(_khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_2__);
270
+ /* harmony import */ var _link_core_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(4);
271
+ 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); }
337
272
 
338
- const link_excluded = ["onClick", "beforeNav", "safeWithNav", "href", "skipClientNav", "children", "tabIndex", "onKeyDown", "onKeyUp", "target"],
339
- _excluded2 = ["tabIndex"],
340
- _excluded3 = ["tabIndex"];
341
273
 
342
274
 
343
275
 
@@ -360,10 +292,9 @@ const link_excluded = ["onClick", "beforeNav", "safeWithNav", "href", "skipClien
360
292
  * </Link>
361
293
  * ```
362
294
  */
363
- class link_Link extends external_react_["Component"] {
364
- render() {
365
- const _this$props = this.props,
366
- {
295
+ class Link extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
296
+ renderClickableBehavior(router) {
297
+ const {
367
298
  onClick,
368
299
  beforeNav = undefined,
369
300
  safeWithNav,
@@ -373,14 +304,13 @@ class link_Link extends external_react_["Component"] {
373
304
  tabIndex,
374
305
  onKeyDown,
375
306
  onKeyUp,
376
- target = undefined
377
- } = _this$props,
378
- sharedProps = objectWithoutPropertiesLoose_default()(_this$props, link_excluded);
379
-
380
- const ClickableBehavior = Object(wonder_blocks_clickable_["getClickableBehavior"])(href, skipClientNav, this.context.router);
307
+ target = undefined,
308
+ ...sharedProps
309
+ } = this.props;
310
+ const ClickableBehavior = Object(_khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_2__["getClickableBehavior"])(href, skipClientNav, router);
381
311
 
382
312
  if (beforeNav) {
383
- return /*#__PURE__*/external_react_["createElement"](ClickableBehavior, {
313
+ return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](ClickableBehavior, {
384
314
  disabled: false,
385
315
  href: href,
386
316
  role: "link",
@@ -389,13 +319,11 @@ class link_Link extends external_react_["Component"] {
389
319
  safeWithNav: safeWithNav,
390
320
  onKeyDown: onKeyDown,
391
321
  onKeyUp: onKeyUp
392
- }, (state, _ref) => {
393
- let {
394
- tabIndex: clickableTabIndex
395
- } = _ref,
396
- childrenProps = objectWithoutPropertiesLoose_default()(_ref, _excluded2);
397
-
398
- return /*#__PURE__*/external_react_["createElement"](link_core_LinkCore, extends_default()({}, sharedProps, state, childrenProps, {
322
+ }, (state, {
323
+ tabIndex: clickableTabIndex,
324
+ ...childrenProps
325
+ }) => {
326
+ return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_link_core_js__WEBPACK_IMPORTED_MODULE_3__[/* default */ "a"], _extends({}, sharedProps, state, childrenProps, {
399
327
  skipClientNav: skipClientNav,
400
328
  href: href,
401
329
  target: target // If tabIndex is provide to the component we allow
@@ -406,7 +334,7 @@ class link_Link extends external_react_["Component"] {
406
334
  }), children);
407
335
  });
408
336
  } else {
409
- return /*#__PURE__*/external_react_["createElement"](ClickableBehavior, {
337
+ return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](ClickableBehavior, {
410
338
  disabled: false,
411
339
  href: href,
412
340
  role: "link",
@@ -415,13 +343,11 @@ class link_Link extends external_react_["Component"] {
415
343
  target: target,
416
344
  onKeyDown: onKeyDown,
417
345
  onKeyUp: onKeyUp
418
- }, (state, _ref2) => {
419
- let {
420
- tabIndex: clickableTabIndex
421
- } = _ref2,
422
- childrenProps = objectWithoutPropertiesLoose_default()(_ref2, _excluded3);
423
-
424
- return /*#__PURE__*/external_react_["createElement"](link_core_LinkCore, extends_default()({}, sharedProps, state, childrenProps, {
346
+ }, (state, {
347
+ tabIndex: clickableTabIndex,
348
+ ...childrenProps
349
+ }) => {
350
+ return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](_link_core_js__WEBPACK_IMPORTED_MODULE_3__[/* default */ "a"], _extends({}, sharedProps, state, childrenProps, {
425
351
  skipClientNav: skipClientNav,
426
352
  href: href,
427
353
  target: target // If tabIndex is provide to the component we allow
@@ -434,16 +360,32 @@ class link_Link extends external_react_["Component"] {
434
360
  }
435
361
  }
436
362
 
363
+ render() {
364
+ return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](react_router__WEBPACK_IMPORTED_MODULE_1__["__RouterContext"].Consumer, null, router => this.renderClickableBehavior(router));
365
+ }
366
+
437
367
  }
438
- link_Link.contextTypes = {
439
- router: external_prop_types_["any"]
440
- };
441
- link_Link.defaultProps = {
368
+ Link.defaultProps = {
442
369
  kind: "primary",
443
370
  light: false,
444
371
  visitable: false
445
372
  };
446
- // CONCATENATED MODULE: ./packages/wonder-blocks-link/src/index.js
373
+
374
+ /***/ }),
375
+ /* 8 */
376
+ /***/ (function(module, exports) {
377
+
378
+ module.exports = require("react-router-dom");
379
+
380
+ /***/ }),
381
+ /* 9 */
382
+ /***/ (function(module, __webpack_exports__, __webpack_require__) {
383
+
384
+ "use strict";
385
+ __webpack_require__.r(__webpack_exports__);
386
+ /* harmony import */ var _components_link_js__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(7);
387
+ /* harmony reexport (safe) */ __webpack_require__.d(__webpack_exports__, "default", function() { return _components_link_js__WEBPACK_IMPORTED_MODULE_0__["a"]; });
388
+
447
389
 
448
390
 
449
391
 
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-link",
3
- "version": "3.7.13",
3
+ "version": "3.8.2",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"
@@ -15,19 +15,18 @@
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"
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
22
  },
23
23
  "peerDependencies": {
24
24
  "aphrodite": "^1.2.5",
25
- "prop-types": "^15.6.2",
26
- "react": "^16.4.1",
27
- "react-router-dom": "^4.2.2"
25
+ "react": "16.14.0",
26
+ "react-router": "5.2.1",
27
+ "react-router-dom": "5.3.0"
28
28
  },
29
29
  "devDependencies": {
30
- "wb-dev-build-settings": "^0.1.0"
31
- },
32
- "gitHead": "8022bb419eed74be37f71f71c7621854794a731c"
30
+ "wb-dev-build-settings": "^0.2.0"
31
+ }
33
32
  }
@@ -2,6 +2,7 @@
2
2
  import * as React from "react";
3
3
  import {MemoryRouter, Route, Switch} from "react-router-dom";
4
4
  import {mount} from "enzyme";
5
+ import "jest-enzyme";
5
6
 
6
7
  import Link from "../link.js";
7
8
 
@@ -15,7 +16,8 @@ describe("Link", () => {
15
16
  beforeEach(() => {
16
17
  // Note: window.location.assign needs a mock function in the testing
17
18
  // environment.
18
- window.location.assign = jest.fn();
19
+ delete window.location;
20
+ window.location = {assign: jest.fn()};
19
21
  });
20
22
 
21
23
  afterEach(() => {
@@ -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 {addStyle} from "@khanacademy/wonder-blocks-core";
8
8
  import Color, {mix, fade} from "@khanacademy/wonder-blocks-color";
@@ -22,17 +22,11 @@ type Props = {|
22
22
  href: string,
23
23
  |};
24
24
 
25
- type ContextTypes = {|
26
- router: $FlowFixMe,
27
- |};
28
-
29
25
  const StyledAnchor = addStyle<"a">("a");
30
26
  const StyledLink = addStyle<typeof Link>(Link);
31
27
 
32
28
  export default class LinkCore extends React.Component<Props> {
33
- static contextTypes: ContextTypes = {router: PropTypes.any};
34
-
35
- render(): React.Node {
29
+ renderInner(router: any): React.Node {
36
30
  const {
37
31
  children,
38
32
  skipClientNav,
@@ -48,7 +42,6 @@ export default class LinkCore extends React.Component<Props> {
48
42
  waiting: _,
49
43
  ...restProps
50
44
  } = this.props;
51
- const {router} = this.context;
52
45
 
53
46
  const linkStyles = _generateStyles(kind, light, visitable);
54
47
 
@@ -76,6 +69,14 @@ export default class LinkCore extends React.Component<Props> {
76
69
  </StyledAnchor>
77
70
  );
78
71
  }
72
+
73
+ render(): React.Node {
74
+ return (
75
+ <__RouterContext.Consumer>
76
+ {(router) => this.renderInner(router)}
77
+ </__RouterContext.Consumer>
78
+ );
79
+ }
79
80
  }
80
81
 
81
82
  const styles = {};
@@ -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
  import {getClickableBehavior} from "@khanacademy/wonder-blocks-clickable";
5
5
 
6
6
  import type {AriaProps, StyleType} from "@khanacademy/wonder-blocks-core";
@@ -156,10 +156,6 @@ export type SharedProps =
156
156
  beforeNav?: () => Promise<mixed>,
157
157
  |};
158
158
 
159
- type ContextTypes = {|
160
- router: $FlowFixMe,
161
- |};
162
-
163
159
  type DefaultProps = {|
164
160
  kind: $PropertyType<SharedProps, "kind">,
165
161
  light: $PropertyType<SharedProps, "light">,
@@ -184,14 +180,13 @@ type DefaultProps = {|
184
180
  * ```
185
181
  */
186
182
  export default class Link extends React.Component<SharedProps> {
187
- static contextTypes: ContextTypes = {router: PropTypes.any};
188
183
  static defaultProps: DefaultProps = {
189
184
  kind: "primary",
190
185
  light: false,
191
186
  visitable: false,
192
187
  };
193
188
 
194
- render(): React.Node {
189
+ renderClickableBehavior(router: any): React.Node {
195
190
  const {
196
191
  onClick,
197
192
  beforeNav = undefined,
@@ -209,7 +204,7 @@ export default class Link extends React.Component<SharedProps> {
209
204
  const ClickableBehavior = getClickableBehavior(
210
205
  href,
211
206
  skipClientNav,
212
- this.context.router,
207
+ router,
213
208
  );
214
209
 
215
210
  if (beforeNav) {
@@ -284,4 +279,12 @@ export default class Link extends React.Component<SharedProps> {
284
279
  );
285
280
  }
286
281
  }
282
+
283
+ render(): React.Node {
284
+ return (
285
+ <__RouterContext.Consumer>
286
+ {(router) => this.renderClickableBehavior(router)}
287
+ </__RouterContext.Consumer>
288
+ );
289
+ }
287
290
  }
@@ -35,3 +35,9 @@ import Link from "@khanacademy/wonder-blocks-link";
35
35
  </Link>
36
36
  </View>
37
37
  ```
38
+
39
+ ### Running callbacks on navigation
40
+
41
+ The `onClick`, `beforeNav`, and `safeWithNav` props can be used to run callbacks
42
+ when navigating to the new URL. Which prop to use depends on the use case. See
43
+ the [Button](#section-button) documentation for details.
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.