@lumx/core 3.20.1-alpha.3 → 3.20.1-alpha.4
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/js/components/Icon/Stories.js +40 -0
- package/js/components/Icon/Tests.tsx +120 -0
- package/js/components/Icon/index.tsx +1 -0
- package/package.json +5 -2
- package/stories/controls/color.ts +7 -0
- package/stories/controls/icons.ts +126 -0
- package/stories/controls/selectArgType.ts +8 -0
- package/stories/controls/withUndefined.ts +1 -0
- package/testing/utils/queries.ts +19 -0
|
@@ -0,0 +1,40 @@
|
|
|
1
|
+
import { mdiEmail } from '@lumx/icons';
|
|
2
|
+
|
|
3
|
+
import { Size } from '@lumx/core/js/constants';
|
|
4
|
+
import { iconArgType } from '@lumx/core/stories/controls/icons';
|
|
5
|
+
import { colorArgType, colorVariantArgType } from '@lumx/react/stories/controls/color';
|
|
6
|
+
import { withUndefined } from '@lumx/react/stories/controls/withUndefined';
|
|
7
|
+
import { Icon } from '.';
|
|
8
|
+
|
|
9
|
+
const iconSizes = [Size.xxs, Size.xs, Size.s, Size.m, Size.l, Size.xl, Size.xxl];
|
|
10
|
+
|
|
11
|
+
export default {
|
|
12
|
+
argTypes: {
|
|
13
|
+
icon: iconArgType,
|
|
14
|
+
hasShape: { control: 'boolean' },
|
|
15
|
+
color: colorArgType,
|
|
16
|
+
colorVariant: colorVariantArgType,
|
|
17
|
+
},
|
|
18
|
+
args: Icon.defaultProps,
|
|
19
|
+
};
|
|
20
|
+
|
|
21
|
+
export const SizeAndShape = {
|
|
22
|
+
args: {
|
|
23
|
+
icon: mdiEmail,
|
|
24
|
+
},
|
|
25
|
+
argTypes: {
|
|
26
|
+
hasShape: { control: false },
|
|
27
|
+
size: { control: false },
|
|
28
|
+
},
|
|
29
|
+
getDecorators: ({ withCombinations }) => [
|
|
30
|
+
withCombinations({
|
|
31
|
+
combinations: {
|
|
32
|
+
cols: { key: 'size', options: withUndefined(iconSizes) },
|
|
33
|
+
rows: {
|
|
34
|
+
Default: {},
|
|
35
|
+
'Has shape': { hasShape: true },
|
|
36
|
+
},
|
|
37
|
+
},
|
|
38
|
+
}),
|
|
39
|
+
],
|
|
40
|
+
};
|
|
@@ -0,0 +1,120 @@
|
|
|
1
|
+
import { mdiAlertCircle } from '@lumx/icons';
|
|
2
|
+
import { ColorPalette, ColorVariant, Size, Theme } from '@lumx/core/js/constants';
|
|
3
|
+
|
|
4
|
+
import { getByClassName, getByTagName } from '@lumx/react/testing/utils/queries';
|
|
5
|
+
import { IconProps, Icon } from '.';
|
|
6
|
+
|
|
7
|
+
const CLASSNAME = Icon.className as string;
|
|
8
|
+
|
|
9
|
+
type SetupProps = Partial<IconProps>;
|
|
10
|
+
|
|
11
|
+
/**
|
|
12
|
+
* Mounts the component and returns common DOM elements / data needed in multiple tests further down.
|
|
13
|
+
*/
|
|
14
|
+
const setup = (propsOverride: SetupProps = {}, { wrapper, render }: any = {}) => {
|
|
15
|
+
const props: IconProps = {
|
|
16
|
+
icon: 'mdiPlus',
|
|
17
|
+
...propsOverride,
|
|
18
|
+
};
|
|
19
|
+
|
|
20
|
+
render(props, { wrapper });
|
|
21
|
+
|
|
22
|
+
const i = getByClassName(document.body, CLASSNAME);
|
|
23
|
+
const svg = getByTagName(i, 'svg');
|
|
24
|
+
const path = getByTagName(svg, 'path');
|
|
25
|
+
|
|
26
|
+
return { i, svg, path, props };
|
|
27
|
+
};
|
|
28
|
+
|
|
29
|
+
export default (render: any) => {
|
|
30
|
+
describe(`<${Icon.displayName}>`, () => {
|
|
31
|
+
describe('Props', () => {
|
|
32
|
+
it('should render default', () => {
|
|
33
|
+
const { i, svg, path, props } = setup({}, { render });
|
|
34
|
+
expect(i).toBeInTheDocument();
|
|
35
|
+
expect(i).toHaveClass(CLASSNAME);
|
|
36
|
+
expect(i?.className).toMatchInlineSnapshot('"lumx-icon lumx-icon--no-shape lumx-icon--path"');
|
|
37
|
+
|
|
38
|
+
expect(svg).toBeInTheDocument();
|
|
39
|
+
expect(svg).toHaveAttribute('aria-hidden', 'true');
|
|
40
|
+
expect(svg).not.toHaveAttribute('role');
|
|
41
|
+
|
|
42
|
+
expect(path).toBeInTheDocument();
|
|
43
|
+
expect(path).toHaveAttribute('d', props.icon);
|
|
44
|
+
});
|
|
45
|
+
|
|
46
|
+
it('should adapt svg with alternate text', () => {
|
|
47
|
+
const { svg, props } = setup({ alt: 'Alternate text' }, { render });
|
|
48
|
+
expect(svg).toHaveAttribute('aria-label', props.alt);
|
|
49
|
+
expect(svg).not.toHaveAttribute('aria-hidden');
|
|
50
|
+
expect(svg).toHaveAttribute('role');
|
|
51
|
+
});
|
|
52
|
+
|
|
53
|
+
describe('size', () => {
|
|
54
|
+
it('should render size', () => {
|
|
55
|
+
const { i } = setup({ size: Size.s }, { render });
|
|
56
|
+
expect(i).toHaveClass('lumx-icon--size-s');
|
|
57
|
+
});
|
|
58
|
+
|
|
59
|
+
it('should adapt xxs size with hasShape', () => {
|
|
60
|
+
const { i } = setup({ hasShape: true, size: Size.xxs }, { render });
|
|
61
|
+
expect(i).toHaveClass('lumx-icon--size-s');
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
it('should adapt xs size with hasShape', () => {
|
|
65
|
+
const { i } = setup({ hasShape: true, size: Size.xs }, { render });
|
|
66
|
+
expect(i).toHaveClass('lumx-icon--size-s');
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it('should adapt xxl size with hasShape', () => {
|
|
70
|
+
const { i } = setup({ hasShape: true, size: Size.xxl }, { render });
|
|
71
|
+
expect(i).toHaveClass('lumx-icon--size-xl');
|
|
72
|
+
});
|
|
73
|
+
|
|
74
|
+
it('should add default size with hasShape', () => {
|
|
75
|
+
const { i } = setup({ hasShape: true }, { render });
|
|
76
|
+
expect(i).toHaveClass('lumx-icon--size-m');
|
|
77
|
+
});
|
|
78
|
+
});
|
|
79
|
+
|
|
80
|
+
describe('color', () => {
|
|
81
|
+
it('should render color and color variant', () => {
|
|
82
|
+
const { i } = setup(
|
|
83
|
+
{
|
|
84
|
+
color: ColorPalette.primary,
|
|
85
|
+
colorVariant: ColorVariant.D1,
|
|
86
|
+
},
|
|
87
|
+
{ render },
|
|
88
|
+
);
|
|
89
|
+
expect(i).toHaveClass('lumx-icon--color-primary lumx-icon--color-variant-D1');
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it('should improve yellow icon color contrast with alert circle icon', () => {
|
|
93
|
+
const { i } = setup(
|
|
94
|
+
{
|
|
95
|
+
color: ColorPalette.yellow,
|
|
96
|
+
icon: mdiAlertCircle,
|
|
97
|
+
},
|
|
98
|
+
{ render },
|
|
99
|
+
);
|
|
100
|
+
expect(i).toHaveClass('lumx-icon--color-yellow lumx-icon--has-dark-layer');
|
|
101
|
+
});
|
|
102
|
+
|
|
103
|
+
it('should set a default color on dark theme', () => {
|
|
104
|
+
const { i } = setup({ theme: Theme.dark }, { render });
|
|
105
|
+
expect(i).toHaveClass('lumx-icon--color-light lumx-icon--theme-dark');
|
|
106
|
+
});
|
|
107
|
+
|
|
108
|
+
it('should set a default color on has shape', () => {
|
|
109
|
+
const { i } = setup({ hasShape: true }, { render });
|
|
110
|
+
expect(i).toHaveClass('lumx-icon--color-dark lumx-icon--has-shape');
|
|
111
|
+
});
|
|
112
|
+
|
|
113
|
+
it('should set a default color variant on has shape & dark color', () => {
|
|
114
|
+
const { i } = setup({ color: ColorPalette.dark, hasShape: true }, { render });
|
|
115
|
+
expect(i).toHaveClass('lumx-icon--color-variant-L2 lumx-icon--color-dark lumx-icon--has-shape');
|
|
116
|
+
});
|
|
117
|
+
});
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
};
|
package/package.json
CHANGED
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
"url": "https://github.com/lumapps/design-system/issues"
|
|
7
7
|
},
|
|
8
8
|
"dependencies": {
|
|
9
|
-
"@lumx/icons": "3.
|
|
9
|
+
"@lumx/icons": "^3.20.1-alpha.4",
|
|
10
10
|
"classnames": "^2.3.2",
|
|
11
11
|
"focus-visible": "^5.0.2",
|
|
12
12
|
"lodash": "4.17.21",
|
|
@@ -34,15 +34,18 @@
|
|
|
34
34
|
"update-version-changelog": "yarn version-changelog ../../CHANGELOG.md"
|
|
35
35
|
},
|
|
36
36
|
"sideEffects": false,
|
|
37
|
-
"version": "3.20.1-alpha.
|
|
37
|
+
"version": "3.20.1-alpha.4",
|
|
38
38
|
"devDependencies": {
|
|
39
39
|
"@rollup/plugin-commonjs": "^19.0.2",
|
|
40
40
|
"@rollup/plugin-terser": "^0.4.4",
|
|
41
41
|
"@rollup/plugin-typescript": "^12.1.4",
|
|
42
|
+
"@testing-library/dom": "^9.3.4",
|
|
43
|
+
"@testing-library/jest-dom": "^5.16.4",
|
|
42
44
|
"@types/react": "^17.0.2",
|
|
43
45
|
"autoprefixer": "^9.7.4",
|
|
44
46
|
"glob": "^7.1.6",
|
|
45
47
|
"postcss": "^8.5.6",
|
|
48
|
+
"react": "^17.0.2",
|
|
46
49
|
"rollup": "^2.79.1",
|
|
47
50
|
"rollup-plugin-cleaner": "^1.0.0",
|
|
48
51
|
"rollup-plugin-copy": "^3.5.0",
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import { ColorPalette, ColorVariant } from '@lumx/core/js/constants';
|
|
2
|
+
import { getSelectArgType } from '@lumx/react/stories/controls/selectArgType';
|
|
3
|
+
import { withUndefined } from '@lumx/react/stories/controls/withUndefined';
|
|
4
|
+
|
|
5
|
+
export const ALL_COLORS = Object.values(ColorPalette);
|
|
6
|
+
export const colorArgType = getSelectArgType(withUndefined(ALL_COLORS));
|
|
7
|
+
export const colorVariantArgType = getSelectArgType(ColorVariant);
|
|
@@ -0,0 +1,126 @@
|
|
|
1
|
+
import {
|
|
2
|
+
mdiAbTesting,
|
|
3
|
+
mdiAbjadArabic,
|
|
4
|
+
mdiAccount,
|
|
5
|
+
mdiAccountBox,
|
|
6
|
+
mdiAlert,
|
|
7
|
+
mdiAlertCircle,
|
|
8
|
+
mdiArrowDown,
|
|
9
|
+
mdiArrowUp,
|
|
10
|
+
mdiAtom,
|
|
11
|
+
mdiBee,
|
|
12
|
+
mdiBell,
|
|
13
|
+
mdiBullhornOutline,
|
|
14
|
+
mdiCheck,
|
|
15
|
+
mdiCheckCircle,
|
|
16
|
+
mdiChevronDown,
|
|
17
|
+
mdiChevronLeft,
|
|
18
|
+
mdiChevronRight,
|
|
19
|
+
mdiChevronUp,
|
|
20
|
+
mdiClose,
|
|
21
|
+
mdiCloseCircle,
|
|
22
|
+
mdiDelete,
|
|
23
|
+
mdiDotsHorizontal,
|
|
24
|
+
mdiDragVertical,
|
|
25
|
+
mdiEarth,
|
|
26
|
+
mdiEmail,
|
|
27
|
+
mdiEye,
|
|
28
|
+
mdiFileEdit,
|
|
29
|
+
mdiFlag,
|
|
30
|
+
mdiFolder,
|
|
31
|
+
mdiFolderGoogleDrive,
|
|
32
|
+
mdiFoodApple,
|
|
33
|
+
mdiGoogleCirclesExtended,
|
|
34
|
+
mdiHeart,
|
|
35
|
+
mdiHome,
|
|
36
|
+
mdiImageBroken,
|
|
37
|
+
mdiInformation,
|
|
38
|
+
mdiLink,
|
|
39
|
+
mdiMagnifyMinusOutline,
|
|
40
|
+
mdiMagnifyPlusOutline,
|
|
41
|
+
mdiMenuDown,
|
|
42
|
+
mdiMessageTextOutline,
|
|
43
|
+
mdiMinus,
|
|
44
|
+
mdiOpenInNew,
|
|
45
|
+
mdiPauseCircleOutline,
|
|
46
|
+
mdiPencil,
|
|
47
|
+
mdiPlay,
|
|
48
|
+
mdiPlayCircleOutline,
|
|
49
|
+
mdiPlus,
|
|
50
|
+
mdiRadioboxBlank,
|
|
51
|
+
mdiRadioboxMarked,
|
|
52
|
+
mdiReply,
|
|
53
|
+
mdiSend,
|
|
54
|
+
mdiStar,
|
|
55
|
+
mdiTextBox,
|
|
56
|
+
mdiTextBoxPlus,
|
|
57
|
+
mdiTram,
|
|
58
|
+
mdiTranslate,
|
|
59
|
+
mdiViewList,
|
|
60
|
+
} from '@lumx/icons';
|
|
61
|
+
|
|
62
|
+
// Small selection of mdi icons to
|
|
63
|
+
export const iconArgType = {
|
|
64
|
+
control: { type: 'select' },
|
|
65
|
+
options: {
|
|
66
|
+
undefined,
|
|
67
|
+
mdiAbTesting,
|
|
68
|
+
mdiAbjadArabic,
|
|
69
|
+
mdiAccount,
|
|
70
|
+
mdiAccountBox,
|
|
71
|
+
mdiAlert,
|
|
72
|
+
mdiAlertCircle,
|
|
73
|
+
mdiArrowDown,
|
|
74
|
+
mdiArrowUp,
|
|
75
|
+
mdiAtom,
|
|
76
|
+
mdiBee,
|
|
77
|
+
mdiBell,
|
|
78
|
+
mdiBullhornOutline,
|
|
79
|
+
mdiCheck,
|
|
80
|
+
mdiCheckCircle,
|
|
81
|
+
mdiChevronDown,
|
|
82
|
+
mdiChevronLeft,
|
|
83
|
+
mdiChevronRight,
|
|
84
|
+
mdiChevronUp,
|
|
85
|
+
mdiClose,
|
|
86
|
+
mdiCloseCircle,
|
|
87
|
+
mdiDelete,
|
|
88
|
+
mdiDotsHorizontal,
|
|
89
|
+
mdiDragVertical,
|
|
90
|
+
mdiEarth,
|
|
91
|
+
mdiEmail,
|
|
92
|
+
mdiEye,
|
|
93
|
+
mdiFileEdit,
|
|
94
|
+
mdiFlag,
|
|
95
|
+
mdiFolder,
|
|
96
|
+
mdiFolderGoogleDrive,
|
|
97
|
+
mdiFoodApple,
|
|
98
|
+
mdiGoogleCirclesExtended,
|
|
99
|
+
mdiHeart,
|
|
100
|
+
mdiHome,
|
|
101
|
+
mdiImageBroken,
|
|
102
|
+
mdiInformation,
|
|
103
|
+
mdiLink,
|
|
104
|
+
mdiMagnifyMinusOutline,
|
|
105
|
+
mdiMagnifyPlusOutline,
|
|
106
|
+
mdiMenuDown,
|
|
107
|
+
mdiMessageTextOutline,
|
|
108
|
+
mdiMinus,
|
|
109
|
+
mdiOpenInNew,
|
|
110
|
+
mdiPauseCircleOutline,
|
|
111
|
+
mdiPencil,
|
|
112
|
+
mdiPlay,
|
|
113
|
+
mdiPlayCircleOutline,
|
|
114
|
+
mdiPlus,
|
|
115
|
+
mdiRadioboxBlank,
|
|
116
|
+
mdiRadioboxMarked,
|
|
117
|
+
mdiReply,
|
|
118
|
+
mdiSend,
|
|
119
|
+
mdiStar,
|
|
120
|
+
mdiTextBox,
|
|
121
|
+
mdiTextBoxPlus,
|
|
122
|
+
mdiTram,
|
|
123
|
+
mdiTranslate,
|
|
124
|
+
mdiViewList,
|
|
125
|
+
},
|
|
126
|
+
};
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
export const withUndefined = <E>(options: Array<E> | Record<string, E>) => [undefined, ...Object.values(options)];
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
import { buildQueries } from '@testing-library/dom';
|
|
2
|
+
|
|
3
|
+
export const queryAllByClassName = (container: HTMLElement, className: string) =>
|
|
4
|
+
Array.from(container.getElementsByClassName(className) as HTMLCollectionOf<HTMLElement>);
|
|
5
|
+
|
|
6
|
+
export const [queryByClassName, getAllByClassName, getByClassName, findAllByClassName, findByClassName] = buildQueries(
|
|
7
|
+
queryAllByClassName,
|
|
8
|
+
(_, className) => `Multiple \`.${className}\` found`,
|
|
9
|
+
(_, className) => `No \`.${className}\` found`,
|
|
10
|
+
);
|
|
11
|
+
|
|
12
|
+
export const queryAllByTagName = (container: HTMLElement, tagName: string) =>
|
|
13
|
+
Array.from(container.getElementsByTagName(tagName) as HTMLCollectionOf<HTMLElement>);
|
|
14
|
+
|
|
15
|
+
export const [queryByTagName, getAllByTagName, getByTagName, findAllByTagName, findByTagName] = buildQueries(
|
|
16
|
+
queryAllByTagName,
|
|
17
|
+
(_, tagName) => `Multiple \`${tagName}\` found`,
|
|
18
|
+
(_, tagName) => `No \`${tagName}\` found`,
|
|
19
|
+
);
|