@khanacademy/wonder-blocks-link 4.2.1 → 4.2.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 CHANGED
@@ -1,5 +1,17 @@
1
1
  # @khanacademy/wonder-blocks-link
2
2
 
3
+ ## 4.2.3
4
+
5
+ ### Patch Changes
6
+
7
+ - 7e30a174: Update link alignment with icons and remove external icon if path is relative
8
+
9
+ ## 4.2.2
10
+
11
+ ### Patch Changes
12
+
13
+ - cf4aca8d: Remove span element from link without icons
14
+
3
15
  ## 4.2.1
4
16
 
5
17
  ### Patch Changes
package/dist/es/index.js CHANGED
@@ -65,14 +65,17 @@ class LinkCore extends React.Component {
65
65
  endIcon
66
66
  } = _this$props,
67
67
  restProps = _objectWithoutPropertiesLoose(_this$props, _excluded$1);
68
+ const withIcon = startIcon || endIcon || target === "_blank";
68
69
  const linkStyles = _generateStyles(inline, kind, light, visitable);
69
70
  const restingStyles = inline ? linkStyles.restingInline : linkStyles.resting;
70
- const defaultStyles = [sharedStyles.shared, restingStyles, pressed && linkStyles.active, !pressed && hovered && linkStyles.hover, !pressed && focused && linkStyles.focus];
71
+ const defaultStyles = [sharedStyles.shared, restingStyles, pressed && linkStyles.active, !pressed && hovered && linkStyles.hover, !pressed && focused && linkStyles.focus, withIcon && sharedStyles.withIcon];
71
72
  const commonProps = _extends({
72
73
  "data-test-id": testId,
73
74
  style: [defaultStyles, style],
74
75
  target
75
76
  }, restProps);
77
+ const linkUrl = new URL(href, window.location.origin);
78
+ const isExternalLink = linkUrl.origin !== window.location.origin;
76
79
  const externalIconPath = {
77
80
  small: "M14 6.5C14 6.63261 13.9473 6.75979 13.8536 6.85355C13.7598 6.94732 13.6326 7 13.5 7C13.3674 7 13.2402 6.94732 13.1464 6.85355C13.0527 6.75979 13 6.63261 13 6.5V3.7075L8.85437 7.85375C8.76055 7.94757 8.63331 8.00028 8.50062 8.00028C8.36794 8.00028 8.2407 7.94757 8.14688 7.85375C8.05306 7.75993 8.00035 7.63268 8.00035 7.5C8.00035 7.36732 8.05306 7.24007 8.14688 7.14625L12.2925 3H9.5C9.36739 3 9.24021 2.94732 9.14645 2.85355C9.05268 2.75979 9 2.63261 9 2.5C9 2.36739 9.05268 2.24021 9.14645 2.14645C9.24021 2.05268 9.36739 2 9.5 2H13.5C13.6326 2 13.7598 2.05268 13.8536 2.14645C13.9473 2.24021 14 2.36739 14 2.5V6.5ZM11.5 8C11.3674 8 11.2402 8.05268 11.1464 8.14645C11.0527 8.24021 11 8.36739 11 8.5V13H3V5H7.5C7.63261 5 7.75979 4.94732 7.85355 4.85355C7.94732 4.75979 8 4.63261 8 4.5C8 4.36739 7.94732 4.24021 7.85355 4.14645C7.75979 4.05268 7.63261 4 7.5 4H3C2.73478 4 2.48043 4.10536 2.29289 4.29289C2.10536 4.48043 2 4.73478 2 5V13C2 13.2652 2.10536 13.5196 2.29289 13.7071C2.48043 13.8946 2.73478 14 3 14H11C11.2652 14 11.5196 13.8946 11.7071 13.7071C11.8946 13.5196 12 13.2652 12 13V8.5C12 8.36739 11.9473 8.24021 11.8536 8.14645C11.7598 8.05268 11.6326 8 11.5 8Z"
78
81
  };
@@ -88,15 +91,15 @@ class LinkCore extends React.Component {
88
91
  style: [linkContentStyles.startIcon, linkContentStyles.centered],
89
92
  testId: "start-icon",
90
93
  "aria-hidden": "true"
91
- }), React.createElement(StyledSpan, {
94
+ }), withIcon ? React.createElement(StyledSpan, {
92
95
  style: linkContentStyles.centered
93
- }, children), endIcon ? React.createElement(Icon, {
96
+ }, children) : children, endIcon ? React.createElement(Icon, {
94
97
  icon: endIcon,
95
98
  size: "small",
96
99
  style: [linkContentStyles.endIcon, linkContentStyles.centered],
97
100
  testId: "end-icon",
98
101
  "aria-hidden": "true"
99
- }) : target === "_blank" && externalIcon);
102
+ }) : isExternalLink && target === "_blank" && externalIcon);
100
103
  return router && !skipClientNav && isClientSideUrl(href) ? React.createElement(StyledLink, _extends({}, commonProps, {
101
104
  to: href
102
105
  }), linkContent) : React.createElement(StyledAnchor, _extends({}, commonProps, {
@@ -124,9 +127,11 @@ const sharedStyles = StyleSheet.create({
124
127
  cursor: "pointer",
125
128
  textDecoration: "none",
126
129
  outline: "none",
127
- verticalAlign: "bottom",
128
- textUnderlineOffset: "3px",
129
130
  alignItems: "center"
131
+ },
132
+ withIcon: {
133
+ verticalAlign: "bottom",
134
+ textUnderlineOffset: 4
130
135
  }
131
136
  });
132
137
  const _generateStyles = (inline, kind, light, visitable) => {
@@ -175,7 +180,8 @@ const _generateStyles = (inline, kind, light, visitable) => {
175
180
  }, defaultVisited),
176
181
  restingInline: _extends({
177
182
  color: defaultTextColor,
178
- textDecoration: "underline currentcolor solid"
183
+ textDecoration: "underline currentcolor solid",
184
+ textUnderlineOffset: 2
179
185
  }, defaultVisited),
180
186
  hover: _extends({
181
187
  textDecoration: "underline currentcolor solid",
package/dist/index.js CHANGED
@@ -92,14 +92,17 @@ class LinkCore extends React__namespace.Component {
92
92
  endIcon
93
93
  } = _this$props,
94
94
  restProps = _objectWithoutPropertiesLoose(_this$props, _excluded$1);
95
+ const withIcon = startIcon || endIcon || target === "_blank";
95
96
  const linkStyles = _generateStyles(inline, kind, light, visitable);
96
97
  const restingStyles = inline ? linkStyles.restingInline : linkStyles.resting;
97
- const defaultStyles = [sharedStyles.shared, restingStyles, pressed && linkStyles.active, !pressed && hovered && linkStyles.hover, !pressed && focused && linkStyles.focus];
98
+ const defaultStyles = [sharedStyles.shared, restingStyles, pressed && linkStyles.active, !pressed && hovered && linkStyles.hover, !pressed && focused && linkStyles.focus, withIcon && sharedStyles.withIcon];
98
99
  const commonProps = _extends({
99
100
  "data-test-id": testId,
100
101
  style: [defaultStyles, style],
101
102
  target
102
103
  }, restProps);
104
+ const linkUrl = new URL(href, window.location.origin);
105
+ const isExternalLink = linkUrl.origin !== window.location.origin;
103
106
  const externalIconPath = {
104
107
  small: "M14 6.5C14 6.63261 13.9473 6.75979 13.8536 6.85355C13.7598 6.94732 13.6326 7 13.5 7C13.3674 7 13.2402 6.94732 13.1464 6.85355C13.0527 6.75979 13 6.63261 13 6.5V3.7075L8.85437 7.85375C8.76055 7.94757 8.63331 8.00028 8.50062 8.00028C8.36794 8.00028 8.2407 7.94757 8.14688 7.85375C8.05306 7.75993 8.00035 7.63268 8.00035 7.5C8.00035 7.36732 8.05306 7.24007 8.14688 7.14625L12.2925 3H9.5C9.36739 3 9.24021 2.94732 9.14645 2.85355C9.05268 2.75979 9 2.63261 9 2.5C9 2.36739 9.05268 2.24021 9.14645 2.14645C9.24021 2.05268 9.36739 2 9.5 2H13.5C13.6326 2 13.7598 2.05268 13.8536 2.14645C13.9473 2.24021 14 2.36739 14 2.5V6.5ZM11.5 8C11.3674 8 11.2402 8.05268 11.1464 8.14645C11.0527 8.24021 11 8.36739 11 8.5V13H3V5H7.5C7.63261 5 7.75979 4.94732 7.85355 4.85355C7.94732 4.75979 8 4.63261 8 4.5C8 4.36739 7.94732 4.24021 7.85355 4.14645C7.75979 4.05268 7.63261 4 7.5 4H3C2.73478 4 2.48043 4.10536 2.29289 4.29289C2.10536 4.48043 2 4.73478 2 5V13C2 13.2652 2.10536 13.5196 2.29289 13.7071C2.48043 13.8946 2.73478 14 3 14H11C11.2652 14 11.5196 13.8946 11.7071 13.7071C11.8946 13.5196 12 13.2652 12 13V8.5C12 8.36739 11.9473 8.24021 11.8536 8.14645C11.7598 8.05268 11.6326 8 11.5 8Z"
105
108
  };
@@ -115,15 +118,15 @@ class LinkCore extends React__namespace.Component {
115
118
  style: [linkContentStyles.startIcon, linkContentStyles.centered],
116
119
  testId: "start-icon",
117
120
  "aria-hidden": "true"
118
- }), React__namespace.createElement(StyledSpan, {
121
+ }), withIcon ? React__namespace.createElement(StyledSpan, {
119
122
  style: linkContentStyles.centered
120
- }, children), endIcon ? React__namespace.createElement(Icon__default["default"], {
123
+ }, children) : children, endIcon ? React__namespace.createElement(Icon__default["default"], {
121
124
  icon: endIcon,
122
125
  size: "small",
123
126
  style: [linkContentStyles.endIcon, linkContentStyles.centered],
124
127
  testId: "end-icon",
125
128
  "aria-hidden": "true"
126
- }) : target === "_blank" && externalIcon);
129
+ }) : isExternalLink && target === "_blank" && externalIcon);
127
130
  return router && !skipClientNav && wonderBlocksClickable.isClientSideUrl(href) ? React__namespace.createElement(StyledLink, _extends({}, commonProps, {
128
131
  to: href
129
132
  }), linkContent) : React__namespace.createElement(StyledAnchor, _extends({}, commonProps, {
@@ -151,9 +154,11 @@ const sharedStyles = aphrodite.StyleSheet.create({
151
154
  cursor: "pointer",
152
155
  textDecoration: "none",
153
156
  outline: "none",
154
- verticalAlign: "bottom",
155
- textUnderlineOffset: "3px",
156
157
  alignItems: "center"
158
+ },
159
+ withIcon: {
160
+ verticalAlign: "bottom",
161
+ textUnderlineOffset: 4
157
162
  }
158
163
  });
159
164
  const _generateStyles = (inline, kind, light, visitable) => {
@@ -202,7 +207,8 @@ const _generateStyles = (inline, kind, light, visitable) => {
202
207
  }, defaultVisited),
203
208
  restingInline: _extends({
204
209
  color: defaultTextColor,
205
- textDecoration: "underline currentcolor solid"
210
+ textDecoration: "underline currentcolor solid",
211
+ textUnderlineOffset: 2
206
212
  }, defaultVisited),
207
213
  hover: _extends({
208
214
  textDecoration: "underline currentcolor solid",
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-link",
3
- "version": "4.2.1",
3
+ "version": "4.2.3",
4
4
  "design": "v1",
5
5
  "publishConfig": {
6
6
  "access": "public"