@khanacademy/wonder-blocks-link 3.8.16 → 3.9.0
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 +18 -0
- package/dist/es/index.js +44 -18
- package/dist/index.js +242 -0
- package/package.json +4 -4
- package/src/__tests__/__snapshots__/custom-snapshot.test.js.snap +1445 -62
- package/src/__tests__/custom-snapshot.test.js +30 -27
- package/src/components/__docs__/link.argtypes.js +8 -0
- package/src/components/__docs__/link.stories.js +326 -36
- package/src/components/__tests__/link.test.js +102 -0
- package/src/components/link-core.js +62 -22
- package/src/components/link.js +9 -0
package/CHANGELOG.md
CHANGED
|
@@ -1,5 +1,23 @@
|
|
|
1
1
|
# @khanacademy/wonder-blocks-link
|
|
2
2
|
|
|
3
|
+
## 3.9.0
|
|
4
|
+
|
|
5
|
+
### Minor Changes
|
|
6
|
+
|
|
7
|
+
- 4fa99654: Add inline variant and update styles
|
|
8
|
+
|
|
9
|
+
### Patch Changes
|
|
10
|
+
|
|
11
|
+
- 48aceaad: Updated hover and outline styles.
|
|
12
|
+
|
|
13
|
+
## 3.8.17
|
|
14
|
+
|
|
15
|
+
### Patch Changes
|
|
16
|
+
|
|
17
|
+
- Updated dependencies [496119f2]
|
|
18
|
+
- @khanacademy/wonder-blocks-clickable@2.4.4
|
|
19
|
+
- @khanacademy/wonder-blocks-core@4.6.2
|
|
20
|
+
|
|
3
21
|
## 3.8.16
|
|
4
22
|
|
|
5
23
|
### Patch Changes
|
package/dist/es/index.js
CHANGED
|
@@ -8,7 +8,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$1 = ["children", "skipClientNav", "focused", "hovered", "href", "kind", "light", "visitable", "pressed", "style", "testId", "waiting"];
|
|
11
|
+
const _excluded$1 = ["children", "skipClientNav", "focused", "hovered", "href", "inline", "kind", "light", "visitable", "pressed", "style", "testId", "waiting"];
|
|
12
12
|
const StyledAnchor = addStyle("a");
|
|
13
13
|
const StyledLink = addStyle(Link$1);
|
|
14
14
|
class LinkCore extends React.Component {
|
|
@@ -20,6 +20,7 @@ class LinkCore extends React.Component {
|
|
|
20
20
|
focused,
|
|
21
21
|
hovered,
|
|
22
22
|
href,
|
|
23
|
+
inline,
|
|
23
24
|
kind,
|
|
24
25
|
light,
|
|
25
26
|
visitable,
|
|
@@ -29,9 +30,10 @@ class LinkCore extends React.Component {
|
|
|
29
30
|
} = _this$props,
|
|
30
31
|
restProps = _objectWithoutPropertiesLoose(_this$props, _excluded$1);
|
|
31
32
|
|
|
32
|
-
const linkStyles = _generateStyles(kind, light, visitable);
|
|
33
|
+
const linkStyles = _generateStyles(inline, kind, light, visitable);
|
|
33
34
|
|
|
34
|
-
const
|
|
35
|
+
const restingStyles = inline ? linkStyles.restingInline : linkStyles.resting;
|
|
36
|
+
const defaultStyles = [sharedStyles.shared, !(hovered || focused || pressed) && restingStyles, pressed && linkStyles.active, !pressed && hovered && linkStyles.hover, !pressed && focused && linkStyles.focus];
|
|
35
37
|
|
|
36
38
|
const commonProps = _extends({
|
|
37
39
|
"data-test-id": testId,
|
|
@@ -55,12 +57,15 @@ const sharedStyles = StyleSheet.create({
|
|
|
55
57
|
shared: {
|
|
56
58
|
cursor: "pointer",
|
|
57
59
|
textDecoration: "none",
|
|
58
|
-
outline: "none"
|
|
60
|
+
outline: "none",
|
|
61
|
+
display: "inline-flex",
|
|
62
|
+
fontSize: 16,
|
|
63
|
+
lineHeight: "22px"
|
|
59
64
|
}
|
|
60
65
|
});
|
|
61
66
|
|
|
62
|
-
const _generateStyles = (kind, light, visitable) => {
|
|
63
|
-
const buttonType = kind
|
|
67
|
+
const _generateStyles = (inline, kind, light, visitable) => {
|
|
68
|
+
const buttonType = `${kind}-${inline.toString()}-${light.toString()}-${visitable.toString()}`;
|
|
64
69
|
|
|
65
70
|
if (styles[buttonType]) {
|
|
66
71
|
return styles[buttonType];
|
|
@@ -70,42 +75,62 @@ const _generateStyles = (kind, light, visitable) => {
|
|
|
70
75
|
throw new Error("Secondary Light links are not supported");
|
|
71
76
|
}
|
|
72
77
|
|
|
73
|
-
if (visitable &&
|
|
74
|
-
throw new Error("Only primary
|
|
78
|
+
if (visitable && kind !== "primary") {
|
|
79
|
+
throw new Error("Only primary link is visitable");
|
|
75
80
|
}
|
|
76
81
|
|
|
77
82
|
const {
|
|
78
83
|
blue,
|
|
84
|
+
pink,
|
|
79
85
|
purple,
|
|
80
86
|
white,
|
|
81
87
|
offBlack,
|
|
82
|
-
offBlack32
|
|
88
|
+
offBlack32,
|
|
89
|
+
offBlack64
|
|
83
90
|
} = Color;
|
|
84
91
|
const linkPurple = mix(fade(offBlack, 0.08), purple);
|
|
85
|
-
const
|
|
86
|
-
const
|
|
87
|
-
const
|
|
92
|
+
const fadedBlue = mix(fade(blue, 0.32), white);
|
|
93
|
+
const activeLightVisited = mix(fade(white, 0.32), pink);
|
|
94
|
+
const activeDefaultPrimary = mix(offBlack32, blue);
|
|
95
|
+
const primaryDefaultTextColor = light ? white : blue;
|
|
96
|
+
const secondaryDefaultTextColor = inline ? offBlack : offBlack64;
|
|
97
|
+
const defaultTextColor = kind === "primary" ? primaryDefaultTextColor : secondaryDefaultTextColor;
|
|
98
|
+
const primaryActiveColor = light ? fadedBlue : activeDefaultPrimary;
|
|
99
|
+
const secondaryActiveColor = inline ? activeDefaultPrimary : offBlack;
|
|
100
|
+
const activeColor = kind === "primary" ? primaryActiveColor : secondaryActiveColor;
|
|
88
101
|
const defaultVisited = visitable ? {
|
|
89
102
|
":visited": {
|
|
90
|
-
color: linkPurple
|
|
103
|
+
color: light ? pink : linkPurple
|
|
91
104
|
}
|
|
92
105
|
} : Object.freeze({});
|
|
93
106
|
const activeVisited = visitable ? {
|
|
94
107
|
":visited": {
|
|
95
|
-
color: mix(offBlack32, linkPurple)
|
|
108
|
+
color: light ? activeLightVisited : mix(offBlack32, linkPurple)
|
|
96
109
|
}
|
|
97
110
|
} : Object.freeze({});
|
|
98
111
|
const newStyles = {
|
|
99
|
-
|
|
112
|
+
resting: _extends({
|
|
100
113
|
color: defaultTextColor
|
|
101
114
|
}, defaultVisited),
|
|
115
|
+
restingInline: _extends({
|
|
116
|
+
color: defaultTextColor,
|
|
117
|
+
textDecoration: "underline currentcolor solid 1px",
|
|
118
|
+
textUnderlineOffset: 4
|
|
119
|
+
}, defaultVisited),
|
|
120
|
+
hover: _extends({
|
|
121
|
+
textDecoration: "underline currentcolor dashed 2px",
|
|
122
|
+
color: defaultTextColor,
|
|
123
|
+
textUnderlineOffset: 4
|
|
124
|
+
}, defaultVisited),
|
|
102
125
|
focus: _extends({
|
|
103
|
-
|
|
104
|
-
|
|
126
|
+
color: defaultTextColor,
|
|
127
|
+
outline: `1px solid ${light ? white : blue}`,
|
|
128
|
+
borderRadius: 3
|
|
105
129
|
}, defaultVisited),
|
|
106
130
|
active: _extends({
|
|
107
131
|
color: activeColor,
|
|
108
|
-
textDecoration: "underline currentcolor solid"
|
|
132
|
+
textDecoration: "underline currentcolor solid 1px",
|
|
133
|
+
textUnderlineOffset: 4
|
|
109
134
|
}, activeVisited)
|
|
110
135
|
};
|
|
111
136
|
styles[buttonType] = StyleSheet.create(newStyles);
|
|
@@ -181,6 +206,7 @@ class Link extends React.Component {
|
|
|
181
206
|
|
|
182
207
|
}
|
|
183
208
|
Link.defaultProps = {
|
|
209
|
+
inline: false,
|
|
184
210
|
kind: "primary",
|
|
185
211
|
light: false,
|
|
186
212
|
visitable: false
|
package/dist/index.js
ADDED
|
@@ -0,0 +1,242 @@
|
|
|
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", "inline", "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
|
+
inline,
|
|
51
|
+
kind,
|
|
52
|
+
light,
|
|
53
|
+
visitable,
|
|
54
|
+
pressed,
|
|
55
|
+
style,
|
|
56
|
+
testId
|
|
57
|
+
} = _this$props,
|
|
58
|
+
restProps = _objectWithoutPropertiesLoose__default["default"](_this$props, _excluded$1);
|
|
59
|
+
|
|
60
|
+
const linkStyles = _generateStyles(inline, kind, light, visitable);
|
|
61
|
+
|
|
62
|
+
const restingStyles = inline ? linkStyles.restingInline : linkStyles.resting;
|
|
63
|
+
const defaultStyles = [sharedStyles.shared, !(hovered || focused || pressed) && restingStyles, pressed && linkStyles.active, !pressed && hovered && linkStyles.hover, !pressed && focused && linkStyles.focus];
|
|
64
|
+
|
|
65
|
+
const commonProps = _extends__default["default"]({
|
|
66
|
+
"data-test-id": testId,
|
|
67
|
+
style: [defaultStyles, style]
|
|
68
|
+
}, restProps);
|
|
69
|
+
|
|
70
|
+
return router && !skipClientNav && wonderBlocksClickable.isClientSideUrl(href) ? React__namespace.createElement(StyledLink, _extends__default["default"]({}, commonProps, {
|
|
71
|
+
to: href
|
|
72
|
+
}), children) : React__namespace.createElement(StyledAnchor, _extends__default["default"]({}, commonProps, {
|
|
73
|
+
href: href
|
|
74
|
+
}), children);
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
render() {
|
|
78
|
+
return React__namespace.createElement(reactRouter.__RouterContext.Consumer, null, router => this.renderInner(router));
|
|
79
|
+
}
|
|
80
|
+
|
|
81
|
+
}
|
|
82
|
+
const styles = {};
|
|
83
|
+
const sharedStyles = aphrodite.StyleSheet.create({
|
|
84
|
+
shared: {
|
|
85
|
+
cursor: "pointer",
|
|
86
|
+
textDecoration: "none",
|
|
87
|
+
outline: "none",
|
|
88
|
+
display: "inline-flex",
|
|
89
|
+
fontSize: 16,
|
|
90
|
+
lineHeight: "22px"
|
|
91
|
+
}
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
const _generateStyles = (inline, kind, light, visitable) => {
|
|
95
|
+
const buttonType = `${kind}-${inline.toString()}-${light.toString()}-${visitable.toString()}`;
|
|
96
|
+
|
|
97
|
+
if (styles[buttonType]) {
|
|
98
|
+
return styles[buttonType];
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
if (kind === "secondary" && light) {
|
|
102
|
+
throw new Error("Secondary Light links are not supported");
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
if (visitable && kind !== "primary") {
|
|
106
|
+
throw new Error("Only primary link is visitable");
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
const {
|
|
110
|
+
blue,
|
|
111
|
+
pink,
|
|
112
|
+
purple,
|
|
113
|
+
white,
|
|
114
|
+
offBlack,
|
|
115
|
+
offBlack32,
|
|
116
|
+
offBlack64
|
|
117
|
+
} = Color__default["default"];
|
|
118
|
+
const linkPurple = Color.mix(Color.fade(offBlack, 0.08), purple);
|
|
119
|
+
const fadedBlue = Color.mix(Color.fade(blue, 0.32), white);
|
|
120
|
+
const activeLightVisited = Color.mix(Color.fade(white, 0.32), pink);
|
|
121
|
+
const activeDefaultPrimary = Color.mix(offBlack32, blue);
|
|
122
|
+
const primaryDefaultTextColor = light ? white : blue;
|
|
123
|
+
const secondaryDefaultTextColor = inline ? offBlack : offBlack64;
|
|
124
|
+
const defaultTextColor = kind === "primary" ? primaryDefaultTextColor : secondaryDefaultTextColor;
|
|
125
|
+
const primaryActiveColor = light ? fadedBlue : activeDefaultPrimary;
|
|
126
|
+
const secondaryActiveColor = inline ? activeDefaultPrimary : offBlack;
|
|
127
|
+
const activeColor = kind === "primary" ? primaryActiveColor : secondaryActiveColor;
|
|
128
|
+
const defaultVisited = visitable ? {
|
|
129
|
+
":visited": {
|
|
130
|
+
color: light ? pink : linkPurple
|
|
131
|
+
}
|
|
132
|
+
} : Object.freeze({});
|
|
133
|
+
const activeVisited = visitable ? {
|
|
134
|
+
":visited": {
|
|
135
|
+
color: light ? activeLightVisited : Color.mix(offBlack32, linkPurple)
|
|
136
|
+
}
|
|
137
|
+
} : Object.freeze({});
|
|
138
|
+
const newStyles = {
|
|
139
|
+
resting: _extends__default["default"]({
|
|
140
|
+
color: defaultTextColor
|
|
141
|
+
}, defaultVisited),
|
|
142
|
+
restingInline: _extends__default["default"]({
|
|
143
|
+
color: defaultTextColor,
|
|
144
|
+
textDecoration: "underline currentcolor solid 1px",
|
|
145
|
+
textUnderlineOffset: 4
|
|
146
|
+
}, defaultVisited),
|
|
147
|
+
hover: _extends__default["default"]({
|
|
148
|
+
textDecoration: "underline currentcolor dashed 2px",
|
|
149
|
+
color: defaultTextColor,
|
|
150
|
+
textUnderlineOffset: 4
|
|
151
|
+
}, defaultVisited),
|
|
152
|
+
focus: _extends__default["default"]({
|
|
153
|
+
color: defaultTextColor,
|
|
154
|
+
outline: `1px solid ${light ? white : blue}`,
|
|
155
|
+
borderRadius: 3
|
|
156
|
+
}, defaultVisited),
|
|
157
|
+
active: _extends__default["default"]({
|
|
158
|
+
color: activeColor,
|
|
159
|
+
textDecoration: "underline currentcolor solid 1px",
|
|
160
|
+
textUnderlineOffset: 4
|
|
161
|
+
}, activeVisited)
|
|
162
|
+
};
|
|
163
|
+
styles[buttonType] = aphrodite.StyleSheet.create(newStyles);
|
|
164
|
+
return styles[buttonType];
|
|
165
|
+
};
|
|
166
|
+
|
|
167
|
+
const _excluded = ["onClick", "beforeNav", "safeWithNav", "href", "skipClientNav", "children", "tabIndex", "onKeyDown", "onKeyUp", "target"];
|
|
168
|
+
class Link extends React__namespace.Component {
|
|
169
|
+
renderClickableBehavior(router) {
|
|
170
|
+
const _this$props = this.props,
|
|
171
|
+
{
|
|
172
|
+
onClick,
|
|
173
|
+
beforeNav = undefined,
|
|
174
|
+
safeWithNav,
|
|
175
|
+
href,
|
|
176
|
+
skipClientNav,
|
|
177
|
+
children,
|
|
178
|
+
tabIndex,
|
|
179
|
+
onKeyDown,
|
|
180
|
+
onKeyUp,
|
|
181
|
+
target = undefined
|
|
182
|
+
} = _this$props,
|
|
183
|
+
sharedProps = _objectWithoutPropertiesLoose__default["default"](_this$props, _excluded);
|
|
184
|
+
|
|
185
|
+
const ClickableBehavior = wonderBlocksClickable.getClickableBehavior(href, skipClientNav, router);
|
|
186
|
+
|
|
187
|
+
if (beforeNav) {
|
|
188
|
+
return React__namespace.createElement(ClickableBehavior, {
|
|
189
|
+
disabled: false,
|
|
190
|
+
href: href,
|
|
191
|
+
role: "link",
|
|
192
|
+
onClick: onClick,
|
|
193
|
+
beforeNav: beforeNav,
|
|
194
|
+
safeWithNav: safeWithNav,
|
|
195
|
+
onKeyDown: onKeyDown,
|
|
196
|
+
onKeyUp: onKeyUp
|
|
197
|
+
}, (state, _ref) => {
|
|
198
|
+
let childrenProps = _extends__default["default"]({}, _ref);
|
|
199
|
+
|
|
200
|
+
return React__namespace.createElement(LinkCore, _extends__default["default"]({}, sharedProps, state, childrenProps, {
|
|
201
|
+
skipClientNav: skipClientNav,
|
|
202
|
+
href: href,
|
|
203
|
+
target: target,
|
|
204
|
+
tabIndex: tabIndex
|
|
205
|
+
}), children);
|
|
206
|
+
});
|
|
207
|
+
} else {
|
|
208
|
+
return React__namespace.createElement(ClickableBehavior, {
|
|
209
|
+
disabled: false,
|
|
210
|
+
href: href,
|
|
211
|
+
role: "link",
|
|
212
|
+
onClick: onClick,
|
|
213
|
+
safeWithNav: safeWithNav,
|
|
214
|
+
target: target,
|
|
215
|
+
onKeyDown: onKeyDown,
|
|
216
|
+
onKeyUp: onKeyUp
|
|
217
|
+
}, (state, _ref2) => {
|
|
218
|
+
let childrenProps = _extends__default["default"]({}, _ref2);
|
|
219
|
+
|
|
220
|
+
return React__namespace.createElement(LinkCore, _extends__default["default"]({}, sharedProps, state, childrenProps, {
|
|
221
|
+
skipClientNav: skipClientNav,
|
|
222
|
+
href: href,
|
|
223
|
+
target: target,
|
|
224
|
+
tabIndex: tabIndex
|
|
225
|
+
}), children);
|
|
226
|
+
});
|
|
227
|
+
}
|
|
228
|
+
}
|
|
229
|
+
|
|
230
|
+
render() {
|
|
231
|
+
return React__namespace.createElement(reactRouter.__RouterContext.Consumer, null, router => this.renderClickableBehavior(router));
|
|
232
|
+
}
|
|
233
|
+
|
|
234
|
+
}
|
|
235
|
+
Link.defaultProps = {
|
|
236
|
+
inline: false,
|
|
237
|
+
kind: "primary",
|
|
238
|
+
light: false,
|
|
239
|
+
visitable: false
|
|
240
|
+
};
|
|
241
|
+
|
|
242
|
+
module.exports = Link;
|
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@khanacademy/wonder-blocks-link",
|
|
3
|
-
"version": "3.
|
|
3
|
+
"version": "3.9.0",
|
|
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
|
}
|