@khanacademy/wonder-blocks-link 3.8.16 → 3.8.17
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 +8 -0
- package/dist/index.js +216 -0
- package/package.json +4 -4
package/CHANGELOG.md
CHANGED
package/dist/index.js
ADDED
|
@@ -0,0 +1,216 @@
|
|
|
1
|
+
'use strict';
|
|
2
|
+
|
|
3
|
+
var _extends = require('@babel/runtime/helpers/extends');
|
|
4
|
+
var _objectWithoutPropertiesLoose = require('@babel/runtime/helpers/objectWithoutPropertiesLoose');
|
|
5
|
+
var React = require('react');
|
|
6
|
+
var reactRouter = require('react-router');
|
|
7
|
+
var wonderBlocksClickable = require('@khanacademy/wonder-blocks-clickable');
|
|
8
|
+
var aphrodite = require('aphrodite');
|
|
9
|
+
var reactRouterDom = require('react-router-dom');
|
|
10
|
+
var wonderBlocksCore = require('@khanacademy/wonder-blocks-core');
|
|
11
|
+
var Color = require('@khanacademy/wonder-blocks-color');
|
|
12
|
+
|
|
13
|
+
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
14
|
+
|
|
15
|
+
function _interopNamespace(e) {
|
|
16
|
+
if (e && e.__esModule) return e;
|
|
17
|
+
var n = Object.create(null);
|
|
18
|
+
if (e) {
|
|
19
|
+
Object.keys(e).forEach(function (k) {
|
|
20
|
+
if (k !== 'default') {
|
|
21
|
+
var d = Object.getOwnPropertyDescriptor(e, k);
|
|
22
|
+
Object.defineProperty(n, k, d.get ? d : {
|
|
23
|
+
enumerable: true,
|
|
24
|
+
get: function () { return e[k]; }
|
|
25
|
+
});
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
}
|
|
29
|
+
n["default"] = e;
|
|
30
|
+
return Object.freeze(n);
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
var _extends__default = /*#__PURE__*/_interopDefaultLegacy(_extends);
|
|
34
|
+
var _objectWithoutPropertiesLoose__default = /*#__PURE__*/_interopDefaultLegacy(_objectWithoutPropertiesLoose);
|
|
35
|
+
var React__namespace = /*#__PURE__*/_interopNamespace(React);
|
|
36
|
+
var Color__default = /*#__PURE__*/_interopDefaultLegacy(Color);
|
|
37
|
+
|
|
38
|
+
const _excluded$1 = ["children", "skipClientNav", "focused", "hovered", "href", "kind", "light", "visitable", "pressed", "style", "testId", "waiting"];
|
|
39
|
+
const StyledAnchor = wonderBlocksCore.addStyle("a");
|
|
40
|
+
const StyledLink = wonderBlocksCore.addStyle(reactRouterDom.Link);
|
|
41
|
+
class LinkCore extends React__namespace.Component {
|
|
42
|
+
renderInner(router) {
|
|
43
|
+
const _this$props = this.props,
|
|
44
|
+
{
|
|
45
|
+
children,
|
|
46
|
+
skipClientNav,
|
|
47
|
+
focused,
|
|
48
|
+
hovered,
|
|
49
|
+
href,
|
|
50
|
+
kind,
|
|
51
|
+
light,
|
|
52
|
+
visitable,
|
|
53
|
+
pressed,
|
|
54
|
+
style,
|
|
55
|
+
testId
|
|
56
|
+
} = _this$props,
|
|
57
|
+
restProps = _objectWithoutPropertiesLoose__default["default"](_this$props, _excluded$1);
|
|
58
|
+
|
|
59
|
+
const linkStyles = _generateStyles(kind, light, visitable);
|
|
60
|
+
|
|
61
|
+
const defaultStyles = [sharedStyles.shared, !(hovered || focused || pressed) && linkStyles.default, pressed ? linkStyles.active : (hovered || focused) && linkStyles.focus];
|
|
62
|
+
|
|
63
|
+
const commonProps = _extends__default["default"]({
|
|
64
|
+
"data-test-id": testId,
|
|
65
|
+
style: [defaultStyles, style]
|
|
66
|
+
}, restProps);
|
|
67
|
+
|
|
68
|
+
return router && !skipClientNav && wonderBlocksClickable.isClientSideUrl(href) ? React__namespace.createElement(StyledLink, _extends__default["default"]({}, commonProps, {
|
|
69
|
+
to: href
|
|
70
|
+
}), children) : React__namespace.createElement(StyledAnchor, _extends__default["default"]({}, commonProps, {
|
|
71
|
+
href: href
|
|
72
|
+
}), children);
|
|
73
|
+
}
|
|
74
|
+
|
|
75
|
+
render() {
|
|
76
|
+
return React__namespace.createElement(reactRouter.__RouterContext.Consumer, null, router => this.renderInner(router));
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
}
|
|
80
|
+
const styles = {};
|
|
81
|
+
const sharedStyles = aphrodite.StyleSheet.create({
|
|
82
|
+
shared: {
|
|
83
|
+
cursor: "pointer",
|
|
84
|
+
textDecoration: "none",
|
|
85
|
+
outline: "none"
|
|
86
|
+
}
|
|
87
|
+
});
|
|
88
|
+
|
|
89
|
+
const _generateStyles = (kind, light, visitable) => {
|
|
90
|
+
const buttonType = kind + light.toString() + visitable.toString();
|
|
91
|
+
|
|
92
|
+
if (styles[buttonType]) {
|
|
93
|
+
return styles[buttonType];
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
if (kind === "secondary" && light) {
|
|
97
|
+
throw new Error("Secondary Light links are not supported");
|
|
98
|
+
}
|
|
99
|
+
|
|
100
|
+
if (visitable && (kind !== "primary" || kind === "primary" && light)) {
|
|
101
|
+
throw new Error("Only primary (not light) link is visitable");
|
|
102
|
+
}
|
|
103
|
+
|
|
104
|
+
const {
|
|
105
|
+
blue,
|
|
106
|
+
purple,
|
|
107
|
+
white,
|
|
108
|
+
offBlack,
|
|
109
|
+
offBlack32
|
|
110
|
+
} = Color__default["default"];
|
|
111
|
+
const linkPurple = Color.mix(Color.fade(offBlack, 0.08), purple);
|
|
112
|
+
const defaultTextColor = kind === "primary" ? light ? white : blue : offBlack;
|
|
113
|
+
const focusColor = light ? white : blue;
|
|
114
|
+
const activeColor = light ? Color.mix(Color.fade(blue, 0.32), white) : Color.mix(offBlack32, blue);
|
|
115
|
+
const defaultVisited = visitable ? {
|
|
116
|
+
":visited": {
|
|
117
|
+
color: linkPurple
|
|
118
|
+
}
|
|
119
|
+
} : Object.freeze({});
|
|
120
|
+
const activeVisited = visitable ? {
|
|
121
|
+
":visited": {
|
|
122
|
+
color: Color.mix(offBlack32, linkPurple)
|
|
123
|
+
}
|
|
124
|
+
} : Object.freeze({});
|
|
125
|
+
const newStyles = {
|
|
126
|
+
default: _extends__default["default"]({
|
|
127
|
+
color: defaultTextColor
|
|
128
|
+
}, defaultVisited),
|
|
129
|
+
focus: _extends__default["default"]({
|
|
130
|
+
textDecoration: "underline currentcolor solid",
|
|
131
|
+
color: focusColor
|
|
132
|
+
}, defaultVisited),
|
|
133
|
+
active: _extends__default["default"]({
|
|
134
|
+
color: activeColor,
|
|
135
|
+
textDecoration: "underline currentcolor solid"
|
|
136
|
+
}, activeVisited)
|
|
137
|
+
};
|
|
138
|
+
styles[buttonType] = aphrodite.StyleSheet.create(newStyles);
|
|
139
|
+
return styles[buttonType];
|
|
140
|
+
};
|
|
141
|
+
|
|
142
|
+
const _excluded = ["onClick", "beforeNav", "safeWithNav", "href", "skipClientNav", "children", "tabIndex", "onKeyDown", "onKeyUp", "target"];
|
|
143
|
+
class Link extends React__namespace.Component {
|
|
144
|
+
renderClickableBehavior(router) {
|
|
145
|
+
const _this$props = this.props,
|
|
146
|
+
{
|
|
147
|
+
onClick,
|
|
148
|
+
beforeNav = undefined,
|
|
149
|
+
safeWithNav,
|
|
150
|
+
href,
|
|
151
|
+
skipClientNav,
|
|
152
|
+
children,
|
|
153
|
+
tabIndex,
|
|
154
|
+
onKeyDown,
|
|
155
|
+
onKeyUp,
|
|
156
|
+
target = undefined
|
|
157
|
+
} = _this$props,
|
|
158
|
+
sharedProps = _objectWithoutPropertiesLoose__default["default"](_this$props, _excluded);
|
|
159
|
+
|
|
160
|
+
const ClickableBehavior = wonderBlocksClickable.getClickableBehavior(href, skipClientNav, router);
|
|
161
|
+
|
|
162
|
+
if (beforeNav) {
|
|
163
|
+
return React__namespace.createElement(ClickableBehavior, {
|
|
164
|
+
disabled: false,
|
|
165
|
+
href: href,
|
|
166
|
+
role: "link",
|
|
167
|
+
onClick: onClick,
|
|
168
|
+
beforeNav: beforeNav,
|
|
169
|
+
safeWithNav: safeWithNav,
|
|
170
|
+
onKeyDown: onKeyDown,
|
|
171
|
+
onKeyUp: onKeyUp
|
|
172
|
+
}, (state, _ref) => {
|
|
173
|
+
let childrenProps = _extends__default["default"]({}, _ref);
|
|
174
|
+
|
|
175
|
+
return React__namespace.createElement(LinkCore, _extends__default["default"]({}, sharedProps, state, childrenProps, {
|
|
176
|
+
skipClientNav: skipClientNav,
|
|
177
|
+
href: href,
|
|
178
|
+
target: target,
|
|
179
|
+
tabIndex: tabIndex
|
|
180
|
+
}), children);
|
|
181
|
+
});
|
|
182
|
+
} else {
|
|
183
|
+
return React__namespace.createElement(ClickableBehavior, {
|
|
184
|
+
disabled: false,
|
|
185
|
+
href: href,
|
|
186
|
+
role: "link",
|
|
187
|
+
onClick: onClick,
|
|
188
|
+
safeWithNav: safeWithNav,
|
|
189
|
+
target: target,
|
|
190
|
+
onKeyDown: onKeyDown,
|
|
191
|
+
onKeyUp: onKeyUp
|
|
192
|
+
}, (state, _ref2) => {
|
|
193
|
+
let childrenProps = _extends__default["default"]({}, _ref2);
|
|
194
|
+
|
|
195
|
+
return React__namespace.createElement(LinkCore, _extends__default["default"]({}, sharedProps, state, childrenProps, {
|
|
196
|
+
skipClientNav: skipClientNav,
|
|
197
|
+
href: href,
|
|
198
|
+
target: target,
|
|
199
|
+
tabIndex: tabIndex
|
|
200
|
+
}), children);
|
|
201
|
+
});
|
|
202
|
+
}
|
|
203
|
+
}
|
|
204
|
+
|
|
205
|
+
render() {
|
|
206
|
+
return React__namespace.createElement(reactRouter.__RouterContext.Consumer, null, router => this.renderClickableBehavior(router));
|
|
207
|
+
}
|
|
208
|
+
|
|
209
|
+
}
|
|
210
|
+
Link.defaultProps = {
|
|
211
|
+
kind: "primary",
|
|
212
|
+
light: false,
|
|
213
|
+
visitable: false
|
|
214
|
+
};
|
|
215
|
+
|
|
216
|
+
module.exports = Link;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-link",
|
|
3
|
-
"version": "3.8.
|
|
3
|
+
"version": "3.8.17",
|
|
4
4
|
"design": "v1",
|
|
5
5
|
"publishConfig": {
|
|
6
6
|
"access": "public"
|
|
@@ -16,9 +16,9 @@
|
|
|
16
16
|
"license": "MIT",
|
|
17
17
|
"dependencies": {
|
|
18
18
|
"@babel/runtime": "^7.18.6",
|
|
19
|
-
"@khanacademy/wonder-blocks-clickable": "^2.4.
|
|
19
|
+
"@khanacademy/wonder-blocks-clickable": "^2.4.4",
|
|
20
20
|
"@khanacademy/wonder-blocks-color": "^1.2.0",
|
|
21
|
-
"@khanacademy/wonder-blocks-core": "^4.6.
|
|
21
|
+
"@khanacademy/wonder-blocks-core": "^4.6.2"
|
|
22
22
|
},
|
|
23
23
|
"peerDependencies": {
|
|
24
24
|
"aphrodite": "^1.2.5",
|
|
@@ -27,6 +27,6 @@
|
|
|
27
27
|
"react-router-dom": "5.3.0"
|
|
28
28
|
},
|
|
29
29
|
"devDependencies": {
|
|
30
|
-
"wb-dev-build-settings": "^0.
|
|
30
|
+
"wb-dev-build-settings": "^0.7.0"
|
|
31
31
|
}
|
|
32
32
|
}
|