@lumx/react 3.12.1-alpha.0 → 3.12.1-alpha.2
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/index.js +6 -7
- package/index.js.map +1 -1
- package/package.json +3 -3
- package/src/components/link/Link.test.tsx +15 -5
- package/src/components/link/Link.tsx +1 -1
- package/src/components/text/Text.test.tsx +9 -29
- package/src/utils/react/wrapChildrenIconWithSpaces.test.tsx +10 -13
- package/src/utils/react/wrapChildrenIconWithSpaces.tsx +8 -8
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.
|
|
10
|
-
"@lumx/icons": "^3.12.1-alpha.
|
|
9
|
+
"@lumx/core": "^3.12.1-alpha.2",
|
|
10
|
+
"@lumx/icons": "^3.12.1-alpha.2",
|
|
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.
|
|
113
|
+
"version": "3.12.1-alpha.2"
|
|
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 {
|
|
66
|
-
|
|
67
|
-
|
|
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
|
|
|
@@ -101,7 +101,7 @@ export const Link = forwardRef<LinkProps, HTMLAnchorElement | HTMLButtonElement>
|
|
|
101
101
|
{wrapChildrenIconWithSpaces(
|
|
102
102
|
<>
|
|
103
103
|
{leftIcon && <Icon icon={leftIcon} className={`${CLASSNAME}__left-icon`} />}
|
|
104
|
-
{children}
|
|
104
|
+
{children && <span className={`${CLASSNAME}__content`}>{children}</span>}
|
|
105
105
|
{rightIcon && <Icon icon={rightIcon} className={`${CLASSNAME}__right-icon`} />}
|
|
106
106
|
</>,
|
|
107
107
|
)}
|
|
@@ -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
|
-
|
|
73
|
-
expect(
|
|
74
|
-
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
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
|
-
<
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
}
|