@lumx/react 3.12.1-alpha.1 → 3.12.1-alpha.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/package.json CHANGED
@@ -6,8 +6,8 @@
6
6
  "url": "https://github.com/lumapps/design-system/issues"
7
7
  },
8
8
  "dependencies": {
9
- "@lumx/core": "^3.12.1-alpha.1",
10
- "@lumx/icons": "^3.12.1-alpha.1",
9
+ "@lumx/core": "^3.12.1-alpha.3",
10
+ "@lumx/icons": "^3.12.1-alpha.3",
11
11
  "@popperjs/core": "^2.5.4",
12
12
  "body-scroll-lock": "^3.1.5",
13
13
  "classnames": "^2.3.2",
@@ -110,5 +110,5 @@
110
110
  "build:storybook": "storybook build"
111
111
  },
112
112
  "sideEffects": false,
113
- "version": "3.12.1-alpha.1"
113
+ "version": "3.12.1-alpha.3"
114
114
  }
@@ -1,8 +1,8 @@
1
1
  import React from 'react';
2
2
 
3
- import { ColorPalette, ColorVariant, Typography } from '@lumx/react';
3
+ import { ColorPalette, ColorVariant, Icon, Typography } from '@lumx/react';
4
4
  import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
5
- import { getByClassName, queryByClassName } from '@lumx/react/testing/utils/queries';
5
+ import { getByClassName, queryAllByClassName, queryByClassName } from '@lumx/react/testing/utils/queries';
6
6
  import { render, screen } from '@testing-library/react';
7
7
  import { mdiCheck, mdiPlus } from '@lumx/icons';
8
8
  import { Link, LinkProps } from './Link';
@@ -62,9 +62,19 @@ describe(`<${Link.displayName}>`, () => {
62
62
  });
63
63
 
64
64
  it('should render with icons', () => {
65
- const { rightIcon, leftIcon } = setup({ rightIcon: mdiPlus, leftIcon: mdiCheck });
66
- expect(rightIcon).toBeInTheDocument();
67
- expect(leftIcon).toBeInTheDocument();
65
+ const { link } = setup({
66
+ leftIcon: mdiCheck,
67
+ children: ['Link', <Icon key="icon" icon={mdiCheck} />, 'with icons'],
68
+ rightIcon: mdiPlus,
69
+ });
70
+ const icons = queryAllByClassName(link, Icon.className as string);
71
+ expect(icons).toHaveLength(3);
72
+
73
+ // Icons are all wrapped with spaces
74
+ for (const icon of icons) {
75
+ expect((icon.previousSibling as any).textContent).toEqual(' ');
76
+ expect((icon.nextSibling as any).textContent).toEqual(' ');
77
+ }
68
78
  });
69
79
  });
70
80
 
@@ -24,14 +24,14 @@ export interface LinkProps extends GenericProps {
24
24
  isDisabled?: boolean;
25
25
  /**
26
26
  * Left icon (SVG path).
27
- * @deprecated Just nest `<Icon />` in the children
27
+ * @deprecated Instead, simply nest `<Icon />` in the children
28
28
  */
29
29
  leftIcon?: string;
30
30
  /** Custom react component for the link (can be used to inject react router Link). */
31
31
  linkAs?: 'a' | any;
32
32
  /**
33
33
  * Right icon (SVG path).
34
- * @deprecated Just nest `<Icon />` in the children
34
+ * @deprecated Instead, simply nest `<Icon />` in the children
35
35
  */
36
36
  rightIcon?: string;
37
37
  /** Link target. */
@@ -4,7 +4,7 @@ import { commonTestsSuiteRTL } from '@lumx/react/testing/utils';
4
4
  import { mdiEarth } from '@lumx/icons';
5
5
  import { Icon } from '@lumx/react';
6
6
  import { render } from '@testing-library/react';
7
- import { getByClassName } from '@lumx/react/testing/utils/queries';
7
+ import { getByClassName, queryAllByClassName } from '@lumx/react/testing/utils/queries';
8
8
  import { Text, TextProps } from '.';
9
9
 
10
10
  const setup = (props: Partial<TextProps> = {}) => {
@@ -69,34 +69,14 @@ describe(`<${Text.displayName}>`, () => {
69
69
 
70
70
  it('should wrap icons with spaces', () => {
71
71
  const { element } = setup({ children: ['Some text', <Icon key="icon" icon={mdiEarth} />, 'with icon'] });
72
- // Spaces have been inserted around the icon.
73
- expect(element).toMatchInlineSnapshot(`
74
- <span
75
- class="lumx-text"
76
- >
77
- Some text
78
-
79
- <i
80
- class="lumx-icon lumx-icon--no-shape lumx-icon--path"
81
- >
82
- <svg
83
- aria-hidden="true"
84
- height="1em"
85
- preserveAspectRatio="xMidYMid meet"
86
- style="vertical-align: -0.125em;"
87
- viewBox="0 0 24 24"
88
- width="1em"
89
- >
90
- <path
91
- d="M17.9 17.39A2 2 0 0 0 16 16h-1v-3a1 1 0 0 0-1-1H8v-2h2a1 1 0 0 0 1-1V7h2a2 2 0 0 0 2-2v-.41a7.98 7.98 0 0 1 2.9 12.8M11 19.93a8 8 0 0 1-6.79-9.72L9 15v1a2 2 0 0 0 2 2m1-16A10 10 0 0 0 2 12a10 10 0 0 0 10 10 10 10 0 0 0 10-10A10 10 0 0 0 12 2"
92
- fill="currentColor"
93
- />
94
- </svg>
95
- </i>
96
-
97
- with icon
98
- </span>
99
- `);
72
+ const icons = queryAllByClassName(element, Icon.className as string);
73
+ expect(icons).toHaveLength(1);
74
+
75
+ // Icons are all wrapped with spaces
76
+ for (const icon of icons) {
77
+ expect((icon.previousSibling as any).textContent).toEqual(' ');
78
+ expect((icon.nextSibling as any).textContent).toEqual(' ');
79
+ }
100
80
  });
101
81
 
102
82
  it('should render dangerouslySetInnerHTML', () => {
@@ -1,4 +1,4 @@
1
- import React from 'react';
1
+ import React, { Fragment } from 'react';
2
2
 
3
3
  import { Icon } from '@lumx/react';
4
4
  import { mdiEarth, mdiFoodApple, mdiPencil } from '@lumx/icons';
@@ -23,18 +23,15 @@ describe(wrapChildrenIconWithSpaces, () => {
23
23
  </>,
24
24
  ),
25
25
  ).toEqual([
26
- ' ',
27
- <Icon key=".0" icon={mdiEarth} />,
28
- ' ',
29
- 'a string',
30
- 'some more string with',
31
- ' ',
32
- <Icon key=".1" icon={mdiFoodApple} />,
33
- ' ',
34
- 'array with',
35
- ' ',
36
- <Icon key=".3:$custom-key" icon={mdiPencil} />,
37
- ' ',
26
+ // prettier-ignore
27
+ <Fragment key=".0">
28
+ {' '}
29
+ <Icon key=".0" icon={mdiEarth} />{' '}a string
30
+ <Fragment key=".2">
31
+ some more string with{' '}<Icon key=".1" icon={mdiFoodApple} />{' '}
32
+ </Fragment>
33
+ array with{' '}<Icon key=".3:$custom-key" icon={mdiPencil} />{' '}
34
+ </Fragment>,
38
35
  ]);
39
36
  });
40
37
  });
@@ -6,17 +6,17 @@ import { Icon } from '@lumx/react';
6
6
  export function wrapChildrenIconWithSpaces(children: React.ReactNode): React.ReactNode {
7
7
  if (children === null || children === undefined) return undefined;
8
8
  return Children.toArray(children).flatMap((child) => {
9
- if (!React.isValidElement(child)) {
10
- return child;
11
- }
12
-
13
- if (child.type === React.Fragment) {
14
- return wrapChildrenIconWithSpaces(child.props.children);
15
- }
16
-
17
9
  if (isComponentType(Icon)(child)) {
18
10
  return [' ', child, ' '];
19
11
  }
12
+ if (
13
+ React.isValidElement(child) &&
14
+ child.props &&
15
+ typeof child.props === 'object' &&
16
+ 'children' in child.props
17
+ ) {
18
+ return React.cloneElement(child, undefined, wrapChildrenIconWithSpaces(child.props.children));
19
+ }
20
20
  return child;
21
21
  });
22
22
  }