@khanacademy/wonder-blocks-link 3.7.14 → 3.8.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 ADDED
@@ -0,0 +1,15 @@
1
+ # @khanacademy/wonder-blocks-link
2
+
3
+ ## 3.8.3
4
+
5
+ ### Patch Changes
6
+
7
+ - @khanacademy/wonder-blocks-clickable@2.2.3
8
+ - @khanacademy/wonder-blocks-core@4.2.1
9
+
10
+ ## 3.8.2
11
+
12
+ ### Patch Changes
13
+
14
+ - Updated dependencies [901bfe82]
15
+ - @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
@@ -101,7 +101,7 @@ module.exports = require("@khanacademy/wonder-blocks-color");
101
101
  /* 2 */
102
102
  /***/ (function(module, exports) {
103
103
 
104
- module.exports = require("prop-types");
104
+ module.exports = require("react-router");
105
105
 
106
106
  /***/ }),
107
107
  /* 3 */
@@ -121,8 +121,8 @@ module.exports = require("@khanacademy/wonder-blocks-clickable");
121
121
  /* harmony import */ var aphrodite__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(aphrodite__WEBPACK_IMPORTED_MODULE_1__);
122
122
  /* harmony import */ var react_router_dom__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(8);
123
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 prop_types__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(2);
125
- /* harmony import */ var prop_types__WEBPACK_IMPORTED_MODULE_3___default = /*#__PURE__*/__webpack_require__.n(prop_types__WEBPACK_IMPORTED_MODULE_3__);
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
126
  /* harmony import */ var _khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_4__ = __webpack_require__(6);
127
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
128
  /* harmony import */ var _khanacademy_wonder_blocks_color__WEBPACK_IMPORTED_MODULE_5__ = __webpack_require__(1);
@@ -141,7 +141,7 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
141
141
  const StyledAnchor = Object(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_4__["addStyle"])("a");
142
142
  const StyledLink = Object(_khanacademy_wonder_blocks_core__WEBPACK_IMPORTED_MODULE_4__["addStyle"])(react_router_dom__WEBPACK_IMPORTED_MODULE_2__["Link"]);
143
143
  class LinkCore extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
144
- render() {
144
+ renderInner(router) {
145
145
  const {
146
146
  children,
147
147
  skipClientNav,
@@ -157,9 +157,6 @@ class LinkCore extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
157
157
  waiting: _,
158
158
  ...restProps
159
159
  } = this.props;
160
- const {
161
- router
162
- } = this.context;
163
160
 
164
161
  const linkStyles = _generateStyles(kind, light, visitable);
165
162
 
@@ -176,10 +173,11 @@ class LinkCore extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
176
173
  }), children);
177
174
  }
178
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
+
179
180
  }
180
- LinkCore.contextTypes = {
181
- router: prop_types__WEBPACK_IMPORTED_MODULE_3__["any"]
182
- };
183
181
  const styles = {};
184
182
  const sharedStyles = aphrodite__WEBPACK_IMPORTED_MODULE_1__["StyleSheet"].create({
185
183
  shared: {
@@ -265,8 +263,8 @@ module.exports = require("@khanacademy/wonder-blocks-core");
265
263
  /* harmony export (binding) */ __webpack_require__.d(__webpack_exports__, "a", function() { return Link; });
266
264
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0__ = __webpack_require__(0);
267
265
  /* harmony import */ var react__WEBPACK_IMPORTED_MODULE_0___default = /*#__PURE__*/__webpack_require__.n(react__WEBPACK_IMPORTED_MODULE_0__);
268
- /* harmony import */ var prop_types__WEBPACK_IMPORTED_MODULE_1__ = __webpack_require__(2);
269
- /* harmony import */ var prop_types__WEBPACK_IMPORTED_MODULE_1___default = /*#__PURE__*/__webpack_require__.n(prop_types__WEBPACK_IMPORTED_MODULE_1__);
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__);
270
268
  /* harmony import */ var _khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_2__ = __webpack_require__(3);
271
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__);
272
270
  /* harmony import */ var _link_core_js__WEBPACK_IMPORTED_MODULE_3__ = __webpack_require__(4);
@@ -295,7 +293,7 @@ function _extends() { _extends = Object.assign || function (target) { for (var i
295
293
  * ```
296
294
  */
297
295
  class Link extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
298
- render() {
296
+ renderClickableBehavior(router) {
299
297
  const {
300
298
  onClick,
301
299
  beforeNav = undefined,
@@ -309,7 +307,7 @@ class Link extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
309
307
  target = undefined,
310
308
  ...sharedProps
311
309
  } = this.props;
312
- const ClickableBehavior = Object(_khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_2__["getClickableBehavior"])(href, skipClientNav, this.context.router);
310
+ const ClickableBehavior = Object(_khanacademy_wonder_blocks_clickable__WEBPACK_IMPORTED_MODULE_2__["getClickableBehavior"])(href, skipClientNav, router);
313
311
 
314
312
  if (beforeNav) {
315
313
  return /*#__PURE__*/react__WEBPACK_IMPORTED_MODULE_0__["createElement"](ClickableBehavior, {
@@ -362,10 +360,11 @@ class Link extends react__WEBPACK_IMPORTED_MODULE_0__["Component"] {
362
360
  }
363
361
  }
364
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
+
365
367
  }
366
- Link.contextTypes = {
367
- router: prop_types__WEBPACK_IMPORTED_MODULE_1__["any"]
368
- };
369
368
  Link.defaultProps = {
370
369
  kind: "primary",
371
370
  light: false,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-link",
3
- "version": "3.7.14",
3
+ "version": "3.8.3",
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.3",
20
- "@khanacademy/wonder-blocks-color": "^1.1.19",
21
- "@khanacademy/wonder-blocks-core": "^3.1.5"
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
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.2"
31
- },
32
- "gitHead": "9a9cc04bf2bbfb425f991a347b4f8b0d0d56e120"
30
+ "wb-dev-build-settings": "^0.3.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.