@khanacademy/wonder-blocks-link 3.7.12 → 3.8.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/es/index.js +147 -369
- package/dist/index.js +191 -276
- package/package.json +10 -9
- package/src/components/__tests__/link.test.js +2 -1
- package/src/components/link-core.js +10 -9
- package/src/components/link.js +11 -8
- package/src/components/link.md +6 -0
- package/src/__tests__/index.test.js +0 -13
|
@@ -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 {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
|
-
|
|
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 = {};
|
package/src/components/link.js
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
// @flow
|
|
2
2
|
import * as React from "react";
|
|
3
|
-
import
|
|
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
|
-
|
|
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
|
-
|
|
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
|
}
|
package/src/components/link.md
CHANGED
|
@@ -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.
|
|
@@ -1,13 +0,0 @@
|
|
|
1
|
-
// @flow
|
|
2
|
-
describe("@khanacademy/wonder-blocks-link", () => {
|
|
3
|
-
test("package exports default", async () => {
|
|
4
|
-
// Arrange
|
|
5
|
-
const importedModule = import("../index.js");
|
|
6
|
-
|
|
7
|
-
// Act
|
|
8
|
-
const result = await importedModule;
|
|
9
|
-
|
|
10
|
-
// Assert
|
|
11
|
-
expect(Object.keys(result).sort()).toEqual(["default"].sort());
|
|
12
|
-
});
|
|
13
|
-
});
|