@khanacademy/wonder-blocks-link 4.3.0 → 4.4.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 CHANGED
@@ -1,5 +1,30 @@
1
1
  # @khanacademy/wonder-blocks-link
2
2
 
3
+ ## 4.4.0
4
+
5
+ ### Minor Changes
6
+
7
+ - ec6a33a4: Forward refs in Icon
8
+ Use Icon type instead of IconAsset for startIcon and endIcon in Link
9
+
10
+ ### Patch Changes
11
+
12
+ - Updated dependencies [ec6a33a4]
13
+ - Updated dependencies [1344436f]
14
+ - @khanacademy/wonder-blocks-icon@2.1.0
15
+ - @khanacademy/wonder-blocks-core@5.4.0
16
+ - @khanacademy/wonder-blocks-clickable@3.1.3
17
+
18
+ ## 4.3.1
19
+
20
+ ### Patch Changes
21
+
22
+ - 9f3752d4: Used named functions in componenets with forwarded refs
23
+ - Updated dependencies [9f3752d4]
24
+ - @khanacademy/wonder-blocks-core@5.3.1
25
+ - @khanacademy/wonder-blocks-clickable@3.1.2
26
+ - @khanacademy/wonder-blocks-icon@2.0.15
27
+
3
28
  ## 4.3.0
4
29
 
5
30
  ### Minor Changes
@@ -824,8 +824,26 @@ declare const LinkCore: React.ForwardRefExoticComponent<Readonly<import("../../.
824
824
  target?: "_blank" | undefined;
825
825
  beforeNav?: (() => Promise<unknown>) | undefined;
826
826
  title?: string | undefined;
827
- startIcon?: IconAsset | undefined;
828
- endIcon?: IconAsset | undefined;
827
+ startIcon?: React.ReactElement<React.ForwardRefExoticComponent<Readonly<import("../../../wonder-blocks-core/src/util/aria-types").AriaAttributes> & Readonly<{
828
+ role?: import("../../../wonder-blocks-core/src/util/aria-types").AriaRole | undefined;
829
+ }> & {
830
+ color?: string | undefined;
831
+ icon: IconAsset;
832
+ size?: keyof IconAsset | undefined;
833
+ style?: import("@khanacademy/wonder-blocks-core").StyleType;
834
+ className?: string | undefined;
835
+ testId?: string | undefined;
836
+ } & React.RefAttributes<SVGSVGElement>>, string | React.JSXElementConstructor<any>> | undefined;
837
+ endIcon?: React.ReactElement<React.ForwardRefExoticComponent<Readonly<import("../../../wonder-blocks-core/src/util/aria-types").AriaAttributes> & Readonly<{
838
+ role?: import("../../../wonder-blocks-core/src/util/aria-types").AriaRole | undefined;
839
+ }> & {
840
+ color?: string | undefined;
841
+ icon: IconAsset;
842
+ size?: keyof IconAsset | undefined;
843
+ style?: import("@khanacademy/wonder-blocks-core").StyleType;
844
+ className?: string | undefined;
845
+ testId?: string | undefined;
846
+ } & React.RefAttributes<SVGSVGElement>>, string | React.JSXElementConstructor<any>> | undefined;
829
847
  } & Readonly<{
830
848
  onClick: (e: React.SyntheticEvent<Element, Event>) => unknown;
831
849
  onMouseEnter: (e: React.MouseEvent<Element, MouseEvent>) => unknown;
@@ -2775,8 +2775,42 @@ declare var LinkCore: React.ForwardRefExoticComponent<{|
2775
2775
  target?: "_blank" | void,
2776
2776
  beforeNav?: (() => Promise<mixed>) | void,
2777
2777
  title?: string | void,
2778
- startIcon?: IconAsset | void,
2779
- endIcon?: IconAsset | void,
2778
+ startIcon?: React.Element<
2779
+ React.ForwardRefExoticComponent<{|
2780
+ ...$ReadOnly<$Flowgen$Import$_2e__2e__2f__2e__2e__2f__2e__2e__2f_wonder_2d_blocks_2d_core_2f_src_2f_util_2f_aria_2d_types.AriaAttributes>,
2781
+ ...$ReadOnly<{|
2782
+ role?: $Flowgen$Import$_2e__2e__2f__2e__2e__2f__2e__2e__2f_wonder_2d_blocks_2d_core_2f_src_2f_util_2f_aria_2d_types.AriaRole | void,
2783
+ |}>,
2784
+ ...{|
2785
+ color?: string | void,
2786
+ icon: IconAsset,
2787
+ size?: $Keys<IconAsset> | void,
2788
+ style?: $Flowgen$Import$_40_khanacademy_2f_wonder_2d_blocks_2d_core.StyleType,
2789
+ className?: string | void,
2790
+ testId?: string | void,
2791
+ |},
2792
+ ...React.RefAttributes<SVGSVGElement>,
2793
+ |}>,
2794
+ string | React.JSXElementConstructor<any>
2795
+ > | void,
2796
+ endIcon?: React.Element<
2797
+ React.ForwardRefExoticComponent<{|
2798
+ ...$ReadOnly<$Flowgen$Import$_2e__2e__2f__2e__2e__2f__2e__2e__2f_wonder_2d_blocks_2d_core_2f_src_2f_util_2f_aria_2d_types.AriaAttributes>,
2799
+ ...$ReadOnly<{|
2800
+ role?: $Flowgen$Import$_2e__2e__2f__2e__2e__2f__2e__2e__2f_wonder_2d_blocks_2d_core_2f_src_2f_util_2f_aria_2d_types.AriaRole | void,
2801
+ |}>,
2802
+ ...{|
2803
+ color?: string | void,
2804
+ icon: IconAsset,
2805
+ size?: $Keys<IconAsset> | void,
2806
+ style?: $Flowgen$Import$_40_khanacademy_2f_wonder_2d_blocks_2d_core.StyleType,
2807
+ className?: string | void,
2808
+ testId?: string | void,
2809
+ |},
2810
+ ...React.RefAttributes<SVGSVGElement>,
2811
+ |}>,
2812
+ string | React.JSXElementConstructor<any>
2813
+ > | void,
2780
2814
  |},
2781
2815
  ...$ReadOnly<{|
2782
2816
  onClick: (e: SyntheticEvent<Element>) => mixed,
@@ -1,8 +1,8 @@
1
1
  import * as React from "react";
2
2
  import { Link as ReactRouterLink } from "react-router-dom";
3
3
  import type { AriaProps, StyleType } from "@khanacademy/wonder-blocks-core";
4
+ import Icon from "@khanacademy/wonder-blocks-icon";
4
5
  import type { Typography } from "@khanacademy/wonder-blocks-typography";
5
- import type { IconAsset } from "@khanacademy/wonder-blocks-icon";
6
6
  export type SharedProps = AriaProps & {
7
7
  /**
8
8
  * Text to appear on the link. It can be a plain text or a Typography element.
@@ -124,13 +124,13 @@ export type SharedProps = AriaProps & {
124
124
  /**
125
125
  * An optional icon displayed before the link label.
126
126
  */
127
- startIcon?: IconAsset;
127
+ startIcon?: React.ReactElement<typeof Icon>;
128
128
  /**
129
129
  * An optional icon displayed after the link label.
130
130
  * If `target="_blank"` and `endIcon` is passed in, `endIcon` will override
131
131
  * the default `externalIcon`.
132
132
  */
133
- endIcon?: IconAsset;
133
+ endIcon?: React.ReactElement<typeof Icon>;
134
134
  };
135
135
  /**
136
136
  * Reusable link component.
@@ -273,12 +273,30 @@ declare const Link: React.ForwardRefExoticComponent<Readonly<import("../../../wo
273
273
  /**
274
274
  * An optional icon displayed before the link label.
275
275
  */
276
- startIcon?: IconAsset | undefined;
276
+ startIcon?: React.ReactElement<React.ForwardRefExoticComponent<Readonly<import("../../../wonder-blocks-core/src/util/aria-types").AriaAttributes> & Readonly<{
277
+ role?: import("../../../wonder-blocks-core/src/util/aria-types").AriaRole | undefined;
278
+ }> & {
279
+ color?: string | undefined;
280
+ icon: import("@khanacademy/wonder-blocks-icon").IconAsset;
281
+ size?: keyof import("@khanacademy/wonder-blocks-icon").IconAsset | undefined;
282
+ style?: StyleType;
283
+ className?: string | undefined;
284
+ testId?: string | undefined;
285
+ } & React.RefAttributes<SVGSVGElement>>, string | React.JSXElementConstructor<any>> | undefined;
277
286
  /**
278
287
  * An optional icon displayed after the link label.
279
288
  * If `target="_blank"` and `endIcon` is passed in, `endIcon` will override
280
289
  * the default `externalIcon`.
281
290
  */
282
- endIcon?: IconAsset | undefined;
291
+ endIcon?: React.ReactElement<React.ForwardRefExoticComponent<Readonly<import("../../../wonder-blocks-core/src/util/aria-types").AriaAttributes> & Readonly<{
292
+ role?: import("../../../wonder-blocks-core/src/util/aria-types").AriaRole | undefined;
293
+ }> & {
294
+ color?: string | undefined;
295
+ icon: import("@khanacademy/wonder-blocks-icon").IconAsset;
296
+ size?: keyof import("@khanacademy/wonder-blocks-icon").IconAsset | undefined;
297
+ style?: StyleType;
298
+ className?: string | undefined;
299
+ testId?: string | undefined;
300
+ } & React.RefAttributes<SVGSVGElement>>, string | React.JSXElementConstructor<any>> | undefined;
283
301
  } & React.RefAttributes<HTMLAnchorElement | typeof ReactRouterLink>>;
284
302
  export default Link;
@@ -5,11 +5,12 @@
5
5
  * @flow
6
6
  */
7
7
  import * as $Flowgen$Import$_2e__2e__2f__2e__2e__2f__2e__2e__2f_wonder_2d_blocks_2d_core_2f_src_2f_util_2f_aria_2d_types from "../../../wonder-blocks-core/src/util/aria-types";
8
+ import * as $Flowgen$Import$_40_khanacademy_2f_wonder_2d_blocks_2d_icon from "@khanacademy/wonder-blocks-icon";
8
9
  import * as React from "react";
9
10
  import { Link as ReactRouterLink } from "react-router-dom";
10
11
  import type { AriaProps, StyleType } from "@khanacademy/wonder-blocks-core";
12
+ import Icon from "@khanacademy/wonder-blocks-icon";
11
13
  import type { Typography } from "@khanacademy/wonder-blocks-typography";
12
- import type { IconAsset } from "@khanacademy/wonder-blocks-icon";
13
14
  export type SharedProps = {|
14
15
  ...AriaProps,
15
16
  ...{|
@@ -153,14 +154,14 @@ export type SharedProps = {|
153
154
  /**
154
155
  * An optional icon displayed before the link label.
155
156
  */
156
- startIcon?: IconAsset,
157
+ startIcon?: React.Element<typeof Icon>,
157
158
 
158
159
  /**
159
160
  * An optional icon displayed after the link label.
160
161
  * If `target="_blank"` and `endIcon` is passed in, `endIcon` will override
161
162
  * the default `externalIcon`.
162
163
  */
163
- endIcon?: IconAsset,
164
+ endIcon?: React.Element<typeof Icon>,
164
165
  |},
165
166
  |};
166
167
  /**
@@ -327,14 +328,48 @@ declare var Link: React.ForwardRefExoticComponent<{|
327
328
  /**
328
329
  * An optional icon displayed before the link label.
329
330
  */
330
- startIcon?: IconAsset | void,
331
+ startIcon?: React.Element<
332
+ React.ForwardRefExoticComponent<{|
333
+ ...$ReadOnly<$Flowgen$Import$_2e__2e__2f__2e__2e__2f__2e__2e__2f_wonder_2d_blocks_2d_core_2f_src_2f_util_2f_aria_2d_types.AriaAttributes>,
334
+ ...$ReadOnly<{|
335
+ role?: $Flowgen$Import$_2e__2e__2f__2e__2e__2f__2e__2e__2f_wonder_2d_blocks_2d_core_2f_src_2f_util_2f_aria_2d_types.AriaRole | void,
336
+ |}>,
337
+ ...{|
338
+ color?: string | void,
339
+ icon: $Flowgen$Import$_40_khanacademy_2f_wonder_2d_blocks_2d_icon.IconAsset,
340
+ size?: $Keys<$Flowgen$Import$_40_khanacademy_2f_wonder_2d_blocks_2d_icon.IconAsset> | void,
341
+ style?: StyleType,
342
+ className?: string | void,
343
+ testId?: string | void,
344
+ |},
345
+ ...React.RefAttributes<SVGSVGElement>,
346
+ |}>,
347
+ string | React.JSXElementConstructor<any>
348
+ > | void,
331
349
 
332
350
  /**
333
351
  * An optional icon displayed after the link label.
334
352
  * If `target="_blank"` and `endIcon` is passed in, `endIcon` will override
335
353
  * the default `externalIcon`.
336
354
  */
337
- endIcon?: IconAsset | void,
355
+ endIcon?: React.Element<
356
+ React.ForwardRefExoticComponent<{|
357
+ ...$ReadOnly<$Flowgen$Import$_2e__2e__2f__2e__2e__2f__2e__2e__2f_wonder_2d_blocks_2d_core_2f_src_2f_util_2f_aria_2d_types.AriaAttributes>,
358
+ ...$ReadOnly<{|
359
+ role?: $Flowgen$Import$_2e__2e__2f__2e__2e__2f__2e__2e__2f_wonder_2d_blocks_2d_core_2f_src_2f_util_2f_aria_2d_types.AriaRole | void,
360
+ |}>,
361
+ ...{|
362
+ color?: string | void,
363
+ icon: $Flowgen$Import$_40_khanacademy_2f_wonder_2d_blocks_2d_icon.IconAsset,
364
+ size?: $Keys<$Flowgen$Import$_40_khanacademy_2f_wonder_2d_blocks_2d_icon.IconAsset> | void,
365
+ style?: StyleType,
366
+ className?: string | void,
367
+ testId?: string | void,
368
+ |},
369
+ ...React.RefAttributes<SVGSVGElement>,
370
+ |}>,
371
+ string | React.JSXElementConstructor<any>
372
+ > | void,
338
373
  |},
339
374
  ...React.RefAttributes<HTMLAnchorElement | typeof ReactRouterLink>,
340
375
  |}>;
package/dist/es/index.js CHANGED
@@ -43,7 +43,7 @@ function _objectWithoutPropertiesLoose(source, excluded) {
43
43
  const _excluded$1 = ["children", "skipClientNav", "focused", "hovered", "href", "inline", "kind", "light", "visitable", "pressed", "style", "testId", "waiting", "target", "startIcon", "endIcon"];
44
44
  const StyledAnchor = addStyle("a");
45
45
  const StyledLink = addStyle(Link$1);
46
- const LinkCore = React.forwardRef((props, ref) => {
46
+ const LinkCore = React.forwardRef(function LinkCore(props, ref) {
47
47
  const renderInner = router => {
48
48
  const {
49
49
  children,
@@ -82,19 +82,23 @@ const LinkCore = React.forwardRef((props, ref) => {
82
82
  style: [linkContentStyles.endIcon, linkContentStyles.centered],
83
83
  testId: "external-icon"
84
84
  });
85
- const linkContent = React.createElement(React.Fragment, null, startIcon && React.createElement(Icon, {
86
- icon: startIcon,
87
- size: "small",
88
- style: [linkContentStyles.startIcon, linkContentStyles.centered],
89
- testId: "start-icon",
90
- "aria-hidden": "true"
91
- }), children, endIcon ? React.createElement(Icon, {
92
- icon: endIcon,
93
- size: "small",
94
- style: [linkContentStyles.endIcon, linkContentStyles.centered],
95
- testId: "end-icon",
96
- "aria-hidden": "true"
97
- }) : isExternalLink && target === "_blank" && externalIcon);
85
+ let startIconElement;
86
+ let endIconElement;
87
+ if (startIcon) {
88
+ startIconElement = React.cloneElement(startIcon, _extends({
89
+ style: [linkContentStyles.startIcon, linkContentStyles.centered],
90
+ testId: "start-icon",
91
+ "aria-hidden": "true"
92
+ }, startIcon.props));
93
+ }
94
+ if (endIcon) {
95
+ endIconElement = React.cloneElement(endIcon, _extends({
96
+ style: [linkContentStyles.endIcon, linkContentStyles.centered],
97
+ testId: "end-icon",
98
+ "aria-hidden": "true"
99
+ }, endIcon.props));
100
+ }
101
+ const linkContent = React.createElement(React.Fragment, null, startIcon && startIconElement, children, endIcon ? endIconElement : isExternalLink && target === "_blank" && externalIcon);
98
102
  return router && !skipClientNav && isClientSideUrl(href) ? React.createElement(StyledLink, _extends({}, commonProps, {
99
103
  to: href,
100
104
  ref: ref
@@ -195,7 +199,7 @@ const _generateStyles = (inline, kind, light, visitable) => {
195
199
  };
196
200
 
197
201
  const _excluded = ["onClick", "beforeNav", "safeWithNav", "href", "skipClientNav", "children", "tabIndex", "onKeyDown", "onKeyUp", "target", "inline", "kind", "light", "visitable"];
198
- const Link = React.forwardRef((props, ref) => {
202
+ const Link = React.forwardRef(function Link(props, ref) {
199
203
  const {
200
204
  onClick,
201
205
  beforeNav = undefined,
package/dist/index.js CHANGED
@@ -70,7 +70,7 @@ 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
- const LinkCore = React__namespace.forwardRef((props, ref) => {
73
+ const LinkCore = React__namespace.forwardRef(function LinkCore(props, ref) {
74
74
  const renderInner = router => {
75
75
  const {
76
76
  children,
@@ -109,19 +109,23 @@ const LinkCore = React__namespace.forwardRef((props, ref) => {
109
109
  style: [linkContentStyles.endIcon, linkContentStyles.centered],
110
110
  testId: "external-icon"
111
111
  });
112
- const linkContent = React__namespace.createElement(React__namespace.Fragment, null, startIcon && React__namespace.createElement(Icon__default["default"], {
113
- icon: startIcon,
114
- size: "small",
115
- style: [linkContentStyles.startIcon, linkContentStyles.centered],
116
- testId: "start-icon",
117
- "aria-hidden": "true"
118
- }), children, endIcon ? React__namespace.createElement(Icon__default["default"], {
119
- icon: endIcon,
120
- size: "small",
121
- style: [linkContentStyles.endIcon, linkContentStyles.centered],
122
- testId: "end-icon",
123
- "aria-hidden": "true"
124
- }) : isExternalLink && target === "_blank" && externalIcon);
112
+ let startIconElement;
113
+ let endIconElement;
114
+ if (startIcon) {
115
+ startIconElement = React__namespace.cloneElement(startIcon, _extends({
116
+ style: [linkContentStyles.startIcon, linkContentStyles.centered],
117
+ testId: "start-icon",
118
+ "aria-hidden": "true"
119
+ }, startIcon.props));
120
+ }
121
+ if (endIcon) {
122
+ endIconElement = React__namespace.cloneElement(endIcon, _extends({
123
+ style: [linkContentStyles.endIcon, linkContentStyles.centered],
124
+ testId: "end-icon",
125
+ "aria-hidden": "true"
126
+ }, endIcon.props));
127
+ }
128
+ const linkContent = React__namespace.createElement(React__namespace.Fragment, null, startIcon && startIconElement, children, endIcon ? endIconElement : isExternalLink && target === "_blank" && externalIcon);
125
129
  return router && !skipClientNav && wonderBlocksClickable.isClientSideUrl(href) ? React__namespace.createElement(StyledLink, _extends({}, commonProps, {
126
130
  to: href,
127
131
  ref: ref
@@ -222,7 +226,7 @@ const _generateStyles = (inline, kind, light, visitable) => {
222
226
  };
223
227
 
224
228
  const _excluded = ["onClick", "beforeNav", "safeWithNav", "href", "skipClientNav", "children", "tabIndex", "onKeyDown", "onKeyUp", "target", "inline", "kind", "light", "visitable"];
225
- const Link = React__namespace.forwardRef((props, ref) => {
229
+ const Link = React__namespace.forwardRef(function Link(props, ref) {
226
230
  const {
227
231
  onClick,
228
232
  beforeNav = undefined,
package/package.json CHANGED
@@ -1,6 +1,6 @@
1
1
  {
2
2
  "name": "@khanacademy/wonder-blocks-link",
3
- "version": "4.3.0",
3
+ "version": "4.4.0",
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.1",
19
+ "@khanacademy/wonder-blocks-clickable": "^3.1.3",
20
20
  "@khanacademy/wonder-blocks-color": "^2.0.1",
21
- "@khanacademy/wonder-blocks-core": "^5.3.0",
22
- "@khanacademy/wonder-blocks-icon": "^2.0.14",
21
+ "@khanacademy/wonder-blocks-core": "^5.4.0",
22
+ "@khanacademy/wonder-blocks-icon": "^2.1.0",
23
23
  "@khanacademy/wonder-blocks-spacing": "^4.0.1"
24
24
  },
25
25
  "peerDependencies": {
@@ -3,7 +3,7 @@ import {MemoryRouter, Route, Switch} from "react-router-dom";
3
3
  import {fireEvent, render, screen, waitFor} from "@testing-library/react";
4
4
  import userEvent from "@testing-library/user-event";
5
5
 
6
- import {icons} from "@khanacademy/wonder-blocks-icon";
6
+ import Icon, {icons} from "@khanacademy/wonder-blocks-icon";
7
7
 
8
8
  import Link from "../link";
9
9
 
@@ -412,7 +412,10 @@ describe("Link", () => {
412
412
  test("render icon with link when startIcon prop is passed in", () => {
413
413
  // Arrange
414
414
  render(
415
- <Link href="https://www.khanacademy.org/" startIcon={icons.add}>
415
+ <Link
416
+ href="https://www.khanacademy.org/"
417
+ startIcon={<Icon icon={icons.add} />}
418
+ >
416
419
  Add new item
417
420
  </Link>,
418
421
  );
@@ -440,7 +443,10 @@ describe("Link", () => {
440
443
  test("startIcon prop passed down correctly", () => {
441
444
  // Arrange
442
445
  render(
443
- <Link href="https://www.khanacademy.org/" startIcon={icons.add}>
446
+ <Link
447
+ href="https://www.khanacademy.org/"
448
+ startIcon={<Icon icon={icons.add} />}
449
+ >
444
450
  Add new item
445
451
  </Link>,
446
452
  );
@@ -461,7 +467,7 @@ describe("Link", () => {
461
467
  render(
462
468
  <Link
463
469
  href="https://www.khanacademy.org/"
464
- endIcon={icons.caretRight}
470
+ endIcon={<Icon icon={icons.caretRight} />}
465
471
  >
466
472
  Click to go back
467
473
  </Link>,
@@ -492,7 +498,7 @@ describe("Link", () => {
492
498
  render(
493
499
  <Link
494
500
  href="https://www.google.com/"
495
- endIcon={icons.caretRight}
501
+ endIcon={<Icon icon={icons.caretRight} />}
496
502
  target="_blank"
497
503
  >
498
504
  Open a new tab
@@ -511,7 +517,7 @@ describe("Link", () => {
511
517
  render(
512
518
  <Link
513
519
  href="https://www.google.com/"
514
- endIcon={icons.caretRight}
520
+ endIcon={<Icon icon={icons.caretRight} />}
515
521
  target="_blank"
516
522
  >
517
523
  Open a new tab
@@ -530,7 +536,7 @@ describe("Link", () => {
530
536
  test("endIcon prop passed down correctly", () => {
531
537
  // Arrange
532
538
  render(
533
- <Link href="/" endIcon={icons.caretRight}>
539
+ <Link href="/" endIcon={<Icon icon={icons.caretRight} />}>
534
540
  Click to go back
535
541
  </Link>,
536
542
  );