@khanacademy/wonder-blocks-link 4.2.8 → 4.3.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/CHANGELOG.md +24 -0
- package/dist/components/link-core.d.ts +850 -9
- package/dist/components/link-core.js.flow +2798 -14
- package/dist/components/link.d.ts +137 -16
- package/dist/components/link.js.flow +164 -15
- package/dist/es/index.js +51 -47
- package/dist/index.js +51 -47
- package/package.json +4 -4
- package/src/components/link-core.tsx +29 -18
- package/src/components/link.tsx +46 -42
- package/tsconfig-build.tsbuildinfo +1 -1
package/dist/index.js
CHANGED
|
@@ -70,27 +70,26 @@ function _objectWithoutPropertiesLoose(source, excluded) {
|
|
|
70
70
|
const _excluded$1 = ["children", "skipClientNav", "focused", "hovered", "href", "inline", "kind", "light", "visitable", "pressed", "style", "testId", "waiting", "target", "startIcon", "endIcon"];
|
|
71
71
|
const StyledAnchor = wonderBlocksCore.addStyle("a");
|
|
72
72
|
const StyledLink = wonderBlocksCore.addStyle(reactRouterDom.Link);
|
|
73
|
-
|
|
74
|
-
renderInner
|
|
75
|
-
const
|
|
76
|
-
{
|
|
73
|
+
const LinkCore = React__namespace.forwardRef(function LinkCore(props, ref) {
|
|
74
|
+
const renderInner = router => {
|
|
75
|
+
const {
|
|
77
76
|
children,
|
|
78
77
|
skipClientNav,
|
|
79
78
|
focused,
|
|
80
79
|
hovered,
|
|
81
80
|
href,
|
|
82
|
-
inline,
|
|
83
|
-
kind,
|
|
84
|
-
light,
|
|
85
|
-
visitable,
|
|
81
|
+
inline = false,
|
|
82
|
+
kind = "primary",
|
|
83
|
+
light = false,
|
|
84
|
+
visitable = false,
|
|
86
85
|
pressed,
|
|
87
86
|
style,
|
|
88
87
|
testId,
|
|
89
88
|
target,
|
|
90
89
|
startIcon,
|
|
91
90
|
endIcon
|
|
92
|
-
} =
|
|
93
|
-
restProps = _objectWithoutPropertiesLoose(
|
|
91
|
+
} = props,
|
|
92
|
+
restProps = _objectWithoutPropertiesLoose(props, _excluded$1);
|
|
94
93
|
const linkStyles = _generateStyles(inline, kind, light, visitable);
|
|
95
94
|
const restingStyles = inline ? linkStyles.restingInline : linkStyles.resting;
|
|
96
95
|
const defaultStyles = [sharedStyles.shared, restingStyles, pressed && linkStyles.active, !pressed && hovered && linkStyles.hover, !pressed && focused && linkStyles.focus];
|
|
@@ -124,15 +123,15 @@ class LinkCore extends React__namespace.Component {
|
|
|
124
123
|
"aria-hidden": "true"
|
|
125
124
|
}) : isExternalLink && target === "_blank" && externalIcon);
|
|
126
125
|
return router && !skipClientNav && wonderBlocksClickable.isClientSideUrl(href) ? React__namespace.createElement(StyledLink, _extends({}, commonProps, {
|
|
127
|
-
to: href
|
|
126
|
+
to: href,
|
|
127
|
+
ref: ref
|
|
128
128
|
}), linkContent) : React__namespace.createElement(StyledAnchor, _extends({}, commonProps, {
|
|
129
|
-
href: href
|
|
129
|
+
href: href,
|
|
130
|
+
ref: ref
|
|
130
131
|
}), linkContent);
|
|
131
|
-
}
|
|
132
|
-
|
|
133
|
-
|
|
134
|
-
}
|
|
135
|
-
}
|
|
132
|
+
};
|
|
133
|
+
return React__namespace.createElement(reactRouter.__RouterContext.Consumer, null, router => renderInner(router));
|
|
134
|
+
});
|
|
136
135
|
const styles = {};
|
|
137
136
|
const linkContentStyles = aphrodite.StyleSheet.create({
|
|
138
137
|
startIcon: {
|
|
@@ -222,23 +221,26 @@ const _generateStyles = (inline, kind, light, visitable) => {
|
|
|
222
221
|
return styles[buttonType];
|
|
223
222
|
};
|
|
224
223
|
|
|
225
|
-
const _excluded = ["onClick", "beforeNav", "safeWithNav", "href", "skipClientNav", "children", "tabIndex", "onKeyDown", "onKeyUp", "target"];
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
229
|
-
|
|
230
|
-
|
|
231
|
-
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
237
|
-
|
|
238
|
-
|
|
239
|
-
|
|
240
|
-
|
|
241
|
-
|
|
224
|
+
const _excluded = ["onClick", "beforeNav", "safeWithNav", "href", "skipClientNav", "children", "tabIndex", "onKeyDown", "onKeyUp", "target", "inline", "kind", "light", "visitable"];
|
|
225
|
+
const Link = React__namespace.forwardRef(function Link(props, ref) {
|
|
226
|
+
const {
|
|
227
|
+
onClick,
|
|
228
|
+
beforeNav = undefined,
|
|
229
|
+
safeWithNav,
|
|
230
|
+
href,
|
|
231
|
+
skipClientNav,
|
|
232
|
+
children,
|
|
233
|
+
tabIndex,
|
|
234
|
+
onKeyDown,
|
|
235
|
+
onKeyUp,
|
|
236
|
+
target = undefined,
|
|
237
|
+
inline = false,
|
|
238
|
+
kind = "primary",
|
|
239
|
+
light = false,
|
|
240
|
+
visitable = false
|
|
241
|
+
} = props,
|
|
242
|
+
sharedProps = _objectWithoutPropertiesLoose(props, _excluded);
|
|
243
|
+
const renderClickableBehavior = router => {
|
|
242
244
|
const ClickableBehavior = wonderBlocksClickable.getClickableBehavior(href, skipClientNav, router);
|
|
243
245
|
if (beforeNav) {
|
|
244
246
|
return React__namespace.createElement(ClickableBehavior, {
|
|
@@ -256,7 +258,12 @@ class Link extends React__namespace.Component {
|
|
|
256
258
|
skipClientNav: skipClientNav,
|
|
257
259
|
href: href,
|
|
258
260
|
target: target,
|
|
259
|
-
tabIndex: tabIndex
|
|
261
|
+
tabIndex: tabIndex,
|
|
262
|
+
inline: inline,
|
|
263
|
+
kind: kind,
|
|
264
|
+
light: light,
|
|
265
|
+
visitable: visitable,
|
|
266
|
+
ref: ref
|
|
260
267
|
}), children);
|
|
261
268
|
});
|
|
262
269
|
} else {
|
|
@@ -275,20 +282,17 @@ class Link extends React__namespace.Component {
|
|
|
275
282
|
skipClientNav: skipClientNav,
|
|
276
283
|
href: href,
|
|
277
284
|
target: target,
|
|
278
|
-
tabIndex: tabIndex
|
|
285
|
+
tabIndex: tabIndex,
|
|
286
|
+
inline: inline,
|
|
287
|
+
kind: kind,
|
|
288
|
+
light: light,
|
|
289
|
+
visitable: visitable,
|
|
290
|
+
ref: ref
|
|
279
291
|
}), children);
|
|
280
292
|
});
|
|
281
293
|
}
|
|
282
|
-
}
|
|
283
|
-
|
|
284
|
-
|
|
285
|
-
}
|
|
286
|
-
}
|
|
287
|
-
Link.defaultProps = {
|
|
288
|
-
inline: false,
|
|
289
|
-
kind: "primary",
|
|
290
|
-
light: false,
|
|
291
|
-
visitable: false
|
|
292
|
-
};
|
|
294
|
+
};
|
|
295
|
+
return React__namespace.createElement(reactRouter.__RouterContext.Consumer, null, router => renderClickableBehavior(router));
|
|
296
|
+
});
|
|
293
297
|
|
|
294
298
|
module.exports = Link;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-link",
|
|
3
|
-
"version": "4.
|
|
3
|
+
"version": "4.3.1",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -16,10 +16,10 @@
|
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@babel/runtime": "^7.18.6",
|
|
19
|
-
"@khanacademy/wonder-blocks-clickable": "^3.1.
|
|
19
|
+
"@khanacademy/wonder-blocks-clickable": "^3.1.2",
|
|
20
20
|
"@khanacademy/wonder-blocks-color": "^2.0.1",
|
|
21
|
-
"@khanacademy/wonder-blocks-core": "^5.
|
|
22
|
-
"@khanacademy/wonder-blocks-icon": "^2.0.
|
|
21
|
+
"@khanacademy/wonder-blocks-core": "^5.3.1",
|
|
22
|
+
"@khanacademy/wonder-blocks-icon": "^2.0.15",
|
|
23
23
|
"@khanacademy/wonder-blocks-spacing": "^4.0.1"
|
|
24
24
|
},
|
|
25
25
|
"peerDependencies": {
|
|
@@ -26,18 +26,21 @@ type Props = SharedProps &
|
|
|
26
26
|
const StyledAnchor = addStyle("a");
|
|
27
27
|
const StyledLink = addStyle(Link);
|
|
28
28
|
|
|
29
|
-
|
|
30
|
-
|
|
29
|
+
const LinkCore = React.forwardRef(function LinkCore(
|
|
30
|
+
props: Props,
|
|
31
|
+
ref: React.ForwardedRef<typeof Link | HTMLAnchorElement>,
|
|
32
|
+
) {
|
|
33
|
+
const renderInner = (router: any): React.ReactNode => {
|
|
31
34
|
const {
|
|
32
35
|
children,
|
|
33
36
|
skipClientNav,
|
|
34
37
|
focused,
|
|
35
38
|
hovered,
|
|
36
39
|
href,
|
|
37
|
-
inline,
|
|
38
|
-
kind,
|
|
39
|
-
light,
|
|
40
|
-
visitable,
|
|
40
|
+
inline = false,
|
|
41
|
+
kind = "primary",
|
|
42
|
+
light = false,
|
|
43
|
+
visitable = false,
|
|
41
44
|
pressed,
|
|
42
45
|
style,
|
|
43
46
|
testId,
|
|
@@ -46,7 +49,7 @@ export default class LinkCore extends React.Component<Props> {
|
|
|
46
49
|
startIcon,
|
|
47
50
|
endIcon,
|
|
48
51
|
...restProps
|
|
49
|
-
} =
|
|
52
|
+
} = props;
|
|
50
53
|
|
|
51
54
|
const linkStyles = _generateStyles(inline, kind, light, visitable);
|
|
52
55
|
const restingStyles = inline
|
|
@@ -123,24 +126,30 @@ export default class LinkCore extends React.Component<Props> {
|
|
|
123
126
|
);
|
|
124
127
|
|
|
125
128
|
return router && !skipClientNav && isClientSideUrl(href) ? (
|
|
126
|
-
<StyledLink
|
|
129
|
+
<StyledLink
|
|
130
|
+
{...commonProps}
|
|
131
|
+
to={href}
|
|
132
|
+
ref={ref as React.ForwardedRef<typeof Link>}
|
|
133
|
+
>
|
|
127
134
|
{linkContent}
|
|
128
135
|
</StyledLink>
|
|
129
136
|
) : (
|
|
130
|
-
<StyledAnchor
|
|
137
|
+
<StyledAnchor
|
|
138
|
+
{...commonProps}
|
|
139
|
+
href={href}
|
|
140
|
+
ref={ref as React.ForwardedRef<HTMLAnchorElement>}
|
|
141
|
+
>
|
|
131
142
|
{linkContent}
|
|
132
143
|
</StyledAnchor>
|
|
133
144
|
);
|
|
134
|
-
}
|
|
145
|
+
};
|
|
135
146
|
|
|
136
|
-
|
|
137
|
-
|
|
138
|
-
|
|
139
|
-
|
|
140
|
-
|
|
141
|
-
|
|
142
|
-
}
|
|
143
|
-
}
|
|
147
|
+
return (
|
|
148
|
+
<__RouterContext.Consumer>
|
|
149
|
+
{(router) => renderInner(router)}
|
|
150
|
+
</__RouterContext.Consumer>
|
|
151
|
+
);
|
|
152
|
+
});
|
|
144
153
|
|
|
145
154
|
const styles: Record<string, any> = {};
|
|
146
155
|
|
|
@@ -276,3 +285,5 @@ const _generateStyles = (
|
|
|
276
285
|
styles[buttonType] = StyleSheet.create(newStyles);
|
|
277
286
|
return styles[buttonType];
|
|
278
287
|
};
|
|
288
|
+
|
|
289
|
+
export default LinkCore;
|
package/src/components/link.tsx
CHANGED
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
import * as React from "react";
|
|
2
2
|
import {__RouterContext} from "react-router";
|
|
3
|
+
import {Link as ReactRouterLink} from "react-router-dom";
|
|
3
4
|
import {getClickableBehavior} from "@khanacademy/wonder-blocks-clickable";
|
|
4
5
|
|
|
5
6
|
import type {AriaProps, StyleType} from "@khanacademy/wonder-blocks-core";
|
|
@@ -26,20 +27,20 @@ export type SharedProps = AriaProps & {
|
|
|
26
27
|
* This styles the link with an underline to distinguish it
|
|
27
28
|
* from surrounding text.
|
|
28
29
|
*/
|
|
29
|
-
inline
|
|
30
|
+
inline?: boolean;
|
|
30
31
|
/**
|
|
31
32
|
* Kind of Link. Note: Secondary light Links are not supported.
|
|
32
33
|
*/
|
|
33
|
-
kind
|
|
34
|
+
kind?: "primary" | "secondary";
|
|
34
35
|
/**
|
|
35
36
|
* Whether the button is on a dark/colored background.
|
|
36
37
|
*/
|
|
37
|
-
light
|
|
38
|
+
light?: boolean;
|
|
38
39
|
/**
|
|
39
40
|
* Whether the link should change color once it's visited.
|
|
40
41
|
* secondary or primary (light) links are not allowed to be visitable.
|
|
41
42
|
*/
|
|
42
|
-
visitable
|
|
43
|
+
visitable?: boolean;
|
|
43
44
|
/**
|
|
44
45
|
* Specifies the type of relationship between the current document and the
|
|
45
46
|
* linked document. Should only be used when `href` is specified. This
|
|
@@ -153,13 +154,6 @@ export type SharedProps = AriaProps & {
|
|
|
153
154
|
endIcon?: IconAsset;
|
|
154
155
|
};
|
|
155
156
|
|
|
156
|
-
type DefaultProps = {
|
|
157
|
-
inline: SharedProps["inline"];
|
|
158
|
-
kind: SharedProps["kind"];
|
|
159
|
-
light: SharedProps["light"];
|
|
160
|
-
visitable: SharedProps["visitable"];
|
|
161
|
-
};
|
|
162
|
-
|
|
163
157
|
/**
|
|
164
158
|
* Reusable link component.
|
|
165
159
|
*
|
|
@@ -178,29 +172,29 @@ type DefaultProps = {
|
|
|
178
172
|
* </Link>
|
|
179
173
|
* ```
|
|
180
174
|
*/
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
} = this.props;
|
|
175
|
+
const Link = React.forwardRef(function Link(
|
|
176
|
+
props: SharedProps,
|
|
177
|
+
ref: React.ForwardedRef<typeof ReactRouterLink | HTMLAnchorElement>,
|
|
178
|
+
) {
|
|
179
|
+
const {
|
|
180
|
+
onClick,
|
|
181
|
+
beforeNav = undefined,
|
|
182
|
+
safeWithNav,
|
|
183
|
+
href,
|
|
184
|
+
skipClientNav,
|
|
185
|
+
children,
|
|
186
|
+
tabIndex,
|
|
187
|
+
onKeyDown,
|
|
188
|
+
onKeyUp,
|
|
189
|
+
target = undefined,
|
|
190
|
+
inline = false,
|
|
191
|
+
kind = "primary",
|
|
192
|
+
light = false,
|
|
193
|
+
visitable = false,
|
|
194
|
+
...sharedProps
|
|
195
|
+
} = props;
|
|
203
196
|
|
|
197
|
+
const renderClickableBehavior = (router: any): React.ReactNode => {
|
|
204
198
|
const ClickableBehavior = getClickableBehavior(
|
|
205
199
|
href,
|
|
206
200
|
skipClientNav,
|
|
@@ -229,6 +223,11 @@ export default class Link extends React.Component<SharedProps> {
|
|
|
229
223
|
href={href}
|
|
230
224
|
target={target}
|
|
231
225
|
tabIndex={tabIndex}
|
|
226
|
+
inline={inline}
|
|
227
|
+
kind={kind}
|
|
228
|
+
light={light}
|
|
229
|
+
visitable={visitable}
|
|
230
|
+
ref={ref}
|
|
232
231
|
>
|
|
233
232
|
{children}
|
|
234
233
|
</LinkCore>
|
|
@@ -258,6 +257,11 @@ export default class Link extends React.Component<SharedProps> {
|
|
|
258
257
|
href={href}
|
|
259
258
|
target={target}
|
|
260
259
|
tabIndex={tabIndex}
|
|
260
|
+
inline={inline}
|
|
261
|
+
kind={kind}
|
|
262
|
+
light={light}
|
|
263
|
+
visitable={visitable}
|
|
264
|
+
ref={ref}
|
|
261
265
|
>
|
|
262
266
|
{children}
|
|
263
267
|
</LinkCore>
|
|
@@ -266,13 +270,13 @@ export default class Link extends React.Component<SharedProps> {
|
|
|
266
270
|
</ClickableBehavior>
|
|
267
271
|
);
|
|
268
272
|
}
|
|
269
|
-
}
|
|
273
|
+
};
|
|
270
274
|
|
|
271
|
-
|
|
272
|
-
|
|
273
|
-
|
|
274
|
-
|
|
275
|
-
|
|
276
|
-
|
|
277
|
-
|
|
278
|
-
|
|
275
|
+
return (
|
|
276
|
+
<__RouterContext.Consumer>
|
|
277
|
+
{(router) => renderClickableBehavior(router)}
|
|
278
|
+
</__RouterContext.Consumer>
|
|
279
|
+
);
|
|
280
|
+
});
|
|
281
|
+
|
|
282
|
+
export default Link;
|