@lumx/core 3.20.1-alpha.2 → 3.20.1-alpha.20

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.
Files changed (78) hide show
  1. package/CONTRIBUTING.md +1 -5
  2. package/js/constants/design-tokens.js +5389 -2294
  3. package/js/constants/index.js +107 -134
  4. package/js/constants/keycodes.js +9 -13
  5. package/js/custom-colors.js +17 -22
  6. package/js/types/Callback.js +0 -1
  7. package/js/types/Falsy.js +0 -1
  8. package/js/types/GenericProps.js +0 -1
  9. package/js/types/HasAriaLabelOrLabelledBy.js +0 -1
  10. package/js/types/HasClassName.js +0 -1
  11. package/js/types/HasCloseMode.js +0 -1
  12. package/js/types/HasTheme.js +0 -1
  13. package/js/types/HeadingElement.js +0 -1
  14. package/js/types/Point.js +0 -1
  15. package/js/types/Predicate.js +0 -1
  16. package/js/types/RectSize.js +0 -1
  17. package/js/types/TextElement.js +0 -1
  18. package/js/types/ValueOf.js +0 -1
  19. package/js/types/index.js +0 -1
  20. package/js/utils/className/fontColorClass.js +7 -12
  21. package/js/utils/className/fontColorClass.test.js +14 -16
  22. package/js/utils/className/getBasicClass.js +19 -24
  23. package/js/utils/className/getBasicClass.test.js +55 -19
  24. package/js/utils/className/getRootClassName.js +10 -17
  25. package/js/utils/className/getRootClassName.test.js +11 -13
  26. package/js/utils/className/getTypographyClassName.js +3 -7
  27. package/js/utils/className/getTypographyClassName.test.js +5 -7
  28. package/js/utils/className/handleBasicClasses.js +27 -31
  29. package/js/utils/className/handleBasicClasses.test.js +30 -32
  30. package/js/utils/className/index.js +12 -25
  31. package/js/utils/className/resolveColorWithVariants.js +4 -9
  32. package/js/utils/className/resolveColorWithVariants.test.js +26 -28
  33. package/js/utils/index.js +161 -174
  34. package/package.json +5 -11
  35. package/js/components/Icon/Stories.js +0 -40
  36. package/js/components/Icon/Tests.tsx +0 -120
  37. package/js/components/Icon/index.tsx +0 -134
  38. package/js/constants/design-tokens.min.js +0 -1
  39. package/js/constants/index.min.js +0 -1
  40. package/js/constants/keycodes.min.js +0 -1
  41. package/js/custom-colors.min.js +0 -1
  42. package/js/date-picker.js +0 -71
  43. package/js/date-picker.min.js +0 -1
  44. package/js/date-picker.ts +0 -77
  45. package/js/types/Callback.min.js +0 -1
  46. package/js/types/Falsy.min.js +0 -1
  47. package/js/types/GenericProps.min.js +0 -1
  48. package/js/types/HasAriaLabelOrLabelledBy.min.js +0 -1
  49. package/js/types/HasClassName.min.js +0 -1
  50. package/js/types/HasCloseMode.min.js +0 -1
  51. package/js/types/HasTheme.min.js +0 -1
  52. package/js/types/HeadingElement.min.js +0 -1
  53. package/js/types/Point.min.js +0 -1
  54. package/js/types/Predicate.min.js +0 -1
  55. package/js/types/RectSize.min.js +0 -1
  56. package/js/types/TextElement.min.js +0 -1
  57. package/js/types/ValueOf.min.js +0 -1
  58. package/js/types/index.min.js +0 -1
  59. package/js/utils/className/fontColorClass.min.js +0 -1
  60. package/js/utils/className/fontColorClass.test.min.js +0 -1
  61. package/js/utils/className/getBasicClass.min.js +0 -1
  62. package/js/utils/className/getBasicClass.test.min.js +0 -1
  63. package/js/utils/className/getRootClassName.min.js +0 -1
  64. package/js/utils/className/getRootClassName.test.min.js +0 -1
  65. package/js/utils/className/getTypographyClassName.min.js +0 -1
  66. package/js/utils/className/getTypographyClassName.test.min.js +0 -1
  67. package/js/utils/className/handleBasicClasses.min.js +0 -1
  68. package/js/utils/className/handleBasicClasses.test.min.js +0 -1
  69. package/js/utils/className/index.min.js +0 -1
  70. package/js/utils/className/resolveColorWithVariants.min.js +0 -1
  71. package/js/utils/className/resolveColorWithVariants.test.min.js +0 -1
  72. package/js/utils/index.min.js +0 -1
  73. package/lumx.min.css +0 -1
  74. package/stories/controls/color.ts +0 -7
  75. package/stories/controls/icons.ts +0 -126
  76. package/stories/controls/selectArgType.ts +0 -8
  77. package/stories/controls/withUndefined.ts +0 -1
  78. package/testing/utils/queries.ts +0 -19
package/js/utils/index.js CHANGED
@@ -1,24 +1,16 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var noop = require('lodash/noop');
6
- var js_utils_className_handleBasicClasses = require('./className/handleBasicClasses.js');
7
- var js_utils_className_getBasicClass = require('./className/getBasicClass.js');
8
- var js_utils_className_getRootClassName = require('./className/getRootClassName.js');
9
- var js_utils_className_getTypographyClassName = require('./className/getTypographyClassName.js');
10
- var js_utils_className_fontColorClass = require('./className/fontColorClass.js');
11
- var js_utils_className_resolveColorWithVariants = require('./className/resolveColorWithVariants.js');
12
- require('classnames');
13
- require('lodash/isBoolean');
14
- require('lodash/isEmpty');
15
- require('lodash/kebabCase');
16
- require('../constants/index.js');
17
- require('../constants/keycodes.js');
18
-
19
- function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
20
-
21
- var noop__default = /*#__PURE__*/_interopDefaultLegacy(noop);
1
+ import noop from 'lodash/noop';
2
+ export { handleBasicClasses } from './className/handleBasicClasses.js';
3
+ export { getBasicClass } from './className/getBasicClass.js';
4
+ export { getRootClassName } from './className/getRootClassName.js';
5
+ export { getTypographyClassName } from './className/getTypographyClassName.js';
6
+ export { fontColorClass } from './className/fontColorClass.js';
7
+ export { resolveColorWithVariants } from './className/resolveColorWithVariants.js';
8
+ import 'classnames';
9
+ import 'lodash/isBoolean';
10
+ import 'lodash/isEmpty';
11
+ import 'lodash/kebabCase';
12
+ import '../constants/index.js';
13
+ import '../constants/keycodes.js';
22
14
 
23
15
  /**
24
16
  * Make sure the pressed key is the enter key before calling the callback.
@@ -27,13 +19,14 @@ var noop__default = /*#__PURE__*/_interopDefaultLegacy(noop);
27
19
  * @return The decorated function.
28
20
  */
29
21
  function onEnterPressed(handler) {
30
- return (evt) => {
31
- if (evt.key !== 'Enter') {
32
- return;
33
- }
34
- handler(evt);
35
- };
22
+ return evt => {
23
+ if (evt.key !== 'Enter') {
24
+ return;
25
+ }
26
+ handler(evt);
27
+ };
36
28
  }
29
+
37
30
  /**
38
31
  * Make sure the pressed key is the escape key before calling the callback.
39
32
  *
@@ -41,13 +34,14 @@ function onEnterPressed(handler) {
41
34
  * @return The decorated function.
42
35
  */
43
36
  function onEscapePressed(handler) {
44
- return (evt) => {
45
- if (evt.key !== 'Escape') {
46
- return;
47
- }
48
- handler(evt);
49
- };
37
+ return evt => {
38
+ if (evt.key !== 'Escape') {
39
+ return;
40
+ }
41
+ handler(evt);
42
+ };
50
43
  }
44
+
51
45
  /**
52
46
  * Handle button key pressed (Enter + Space).
53
47
  *
@@ -55,12 +49,12 @@ function onEscapePressed(handler) {
55
49
  * @return The decorated function.
56
50
  */
57
51
  function onButtonPressed(handler) {
58
- return (evt) => {
59
- if (evt.key !== 'Enter' && evt.key !== ' ') {
60
- return;
61
- }
62
- handler(evt);
63
- };
52
+ return evt => {
53
+ if (evt.key !== 'Enter' && evt.key !== ' ') {
54
+ return;
55
+ }
56
+ handler(evt);
57
+ };
64
58
  }
65
59
  /**
66
60
  * Detects swipe direction.
@@ -71,153 +65,146 @@ function onButtonPressed(handler) {
71
65
  * @param handleSwipe Callback function.
72
66
  * @return Function to remove listeners.
73
67
  */
74
- function detectSwipe(touchSurface, handleSwipe = noop__default["default"]) {
75
- let distX;
76
- let distY;
77
- let startX;
78
- let startY;
79
- let direction;
80
- // Required min distance traveled to be considered swipe.
81
- const threshold = 150;
82
- // Maximum distance allowed at the same time in perpendicular direction.
83
- const restraint = 100;
84
- // Maximum time allowed to travel that distance.
85
- const allowedTime = 300;
86
- let elapsedTime;
87
- let startTime;
88
- const onTouchStart = (evt) => {
89
- const [touch] = Array.from(evt.changedTouches);
90
- direction = 'none';
91
- // Const dist = 0;
92
- startX = touch.pageX;
93
- startY = touch.pageY;
94
- // Record time when finger first makes contact with surface.
95
- startTime = new Date().getTime();
96
- evt.preventDefault();
97
- };
98
- const onTouchMove = (evt) => {
99
- // Prevent scrolling when inside DIV.
100
- evt.preventDefault();
101
- };
102
- const onTouchEnd = (evt) => {
103
- const [touch] = Array.from(evt.changedTouches);
104
- // Get horizontal dist traveled by finger while in contact with surface.
105
- distX = touch.pageX - startX;
106
- // Get vertical dist traveled by finger while in contact with surface.
107
- distY = touch.pageY - startY;
108
- // Get time elapsed.
109
- elapsedTime = new Date().getTime() - startTime;
110
- if (elapsedTime <= allowedTime) {
111
- // First condition for awipe met.
112
- if (Math.abs(distX) >= threshold && Math.abs(distY) <= restraint) {
113
- // 2nd condition for horizontal swipe met.
114
- // If dist traveled is negative, it indicates left swipe.
115
- direction = distX < 0 ? 'left' : 'right';
116
- }
117
- else if (Math.abs(distY) >= threshold && Math.abs(distX) <= restraint) {
118
- // 2nd condition for vertical swipe met.
119
- // If dist traveled is negative, it indicates up swipe.
120
- direction = distY < 0 ? 'up' : 'down';
121
- }
122
- }
123
- handleSwipe(direction);
124
- evt.preventDefault();
125
- };
126
- touchSurface.addEventListener('touchstart', onTouchStart, false);
127
- touchSurface.addEventListener('touchmove', onTouchMove, false);
128
- touchSurface.addEventListener('touchend', onTouchEnd, false);
129
- return () => {
130
- touchSurface.removeEventListener('touchstart', onTouchStart, false);
131
- touchSurface.removeEventListener('touchmove', onTouchMove, false);
132
- touchSurface.removeEventListener('touchend', onTouchEnd, false);
133
- };
68
+ function detectSwipe(touchSurface, handleSwipe = noop) {
69
+ let distX;
70
+ let distY;
71
+ let startX;
72
+ let startY;
73
+ let direction;
74
+ // Required min distance traveled to be considered swipe.
75
+ const threshold = 150;
76
+ // Maximum distance allowed at the same time in perpendicular direction.
77
+ const restraint = 100;
78
+ // Maximum time allowed to travel that distance.
79
+ const allowedTime = 300;
80
+ let elapsedTime;
81
+ let startTime;
82
+ const onTouchStart = evt => {
83
+ const [touch] = Array.from(evt.changedTouches);
84
+ direction = 'none';
85
+ // Const dist = 0;
86
+ startX = touch.pageX;
87
+ startY = touch.pageY;
88
+ // Record time when finger first makes contact with surface.
89
+ startTime = new Date().getTime();
90
+ evt.preventDefault();
91
+ };
92
+ const onTouchMove = evt => {
93
+ // Prevent scrolling when inside DIV.
94
+ evt.preventDefault();
95
+ };
96
+ const onTouchEnd = evt => {
97
+ const [touch] = Array.from(evt.changedTouches);
98
+ // Get horizontal dist traveled by finger while in contact with surface.
99
+ distX = touch.pageX - startX;
100
+ // Get vertical dist traveled by finger while in contact with surface.
101
+ distY = touch.pageY - startY;
102
+ // Get time elapsed.
103
+ elapsedTime = new Date().getTime() - startTime;
104
+ if (elapsedTime <= allowedTime) {
105
+ // First condition for awipe met.
106
+ if (Math.abs(distX) >= threshold && Math.abs(distY) <= restraint) {
107
+ // 2nd condition for horizontal swipe met.
108
+ // If dist traveled is negative, it indicates left swipe.
109
+ direction = distX < 0 ? 'left' : 'right';
110
+ } else if (Math.abs(distY) >= threshold && Math.abs(distX) <= restraint) {
111
+ // 2nd condition for vertical swipe met.
112
+ // If dist traveled is negative, it indicates up swipe.
113
+ direction = distY < 0 ? 'up' : 'down';
114
+ }
115
+ }
116
+ handleSwipe(direction);
117
+ evt.preventDefault();
118
+ };
119
+ touchSurface.addEventListener('touchstart', onTouchStart, false);
120
+ touchSurface.addEventListener('touchmove', onTouchMove, false);
121
+ touchSurface.addEventListener('touchend', onTouchEnd, false);
122
+ return () => {
123
+ touchSurface.removeEventListener('touchstart', onTouchStart, false);
124
+ touchSurface.removeEventListener('touchmove', onTouchMove, false);
125
+ touchSurface.removeEventListener('touchend', onTouchEnd, false);
126
+ };
134
127
  }
128
+
135
129
  /**
136
130
  * Checks whether or not the browser support passive events.
137
131
  * @see https://github.com/Modernizr/Modernizr/blob/6d56d814b9682843313b16060adb25a58d83a317/feature-detects/dom/passiveeventlisteners.js
138
132
  */
139
133
  function isPassiveEventAvailable() {
140
- let supportsPassiveOption = false;
141
- try {
142
- const opts = Object.defineProperty({}, 'passive', {
143
- get() {
144
- supportsPassiveOption = true;
145
- },
146
- });
147
- window.addEventListener('testPassiveEventSupport', noop__default["default"], opts);
148
- window.removeEventListener('testPassiveEventSupport', noop__default["default"], opts);
149
- }
150
- catch (e) {
151
- // ignored
152
- }
153
- return supportsPassiveOption;
134
+ let supportsPassiveOption = false;
135
+ try {
136
+ const opts = Object.defineProperty({}, 'passive', {
137
+ get() {
138
+ supportsPassiveOption = true;
139
+ }
140
+ });
141
+ window.addEventListener('testPassiveEventSupport', noop, opts);
142
+ window.removeEventListener('testPassiveEventSupport', noop, opts);
143
+ } catch (e) {
144
+ // ignored
145
+ }
146
+ return supportsPassiveOption;
154
147
  }
148
+
155
149
  /**
156
150
  * Detects horizontal swipe direction without blocking the browser scroll using passive event.
157
151
  * @see http://javascriptkit.com/javatutors/touchevents2.shtml
158
152
  * @see https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
159
153
  */
160
154
  function detectHorizontalSwipe(touchSurface, handleSwipe) {
161
- let startX;
162
- let startY;
163
- // Required min distance traveled to be considered swipe.
164
- const threshold = 150;
165
- // Maximum distance allowed at the same time in perpendicular direction.
166
- const restraint = 150;
167
- // Maximum time allowed to travel that distance.
168
- const allowedTime = 300;
169
- let elapsedTime;
170
- let startTime;
171
- let finished;
172
- const onTouchStart = (evt) => {
173
- const [touch] = Array.from(evt.changedTouches);
174
- startX = touch.pageX;
175
- startY = touch.pageY;
176
- // Record time when finger first makes contact with surface.
177
- startTime = new Date().getTime();
178
- finished = false;
179
- };
180
- const onTouchMove = (evt) => {
181
- if (finished) {
182
- return;
183
- }
184
- elapsedTime = new Date().getTime() - startTime;
185
- if (elapsedTime > allowedTime) {
186
- // Touch swipe too long to be considered.
187
- return;
188
- }
189
- const [touch] = Array.from(evt.changedTouches);
190
- // Get horizontal dist traveled by finger while in contact with surface.
191
- const distX = touch.pageX - startX;
192
- // Get vertical dist traveled by finger while in contact with surface.
193
- const distY = touch.pageY - startY;
194
- if (!(Math.abs(distX) >= threshold && Math.abs(distY) <= restraint)) {
195
- // Swipe is not horizontal.
196
- return;
197
- }
198
- // Swipe direction.
199
- const direction = distX < 0 ? 'left' : 'right';
200
- handleSwipe(direction);
201
- finished = true;
202
- };
203
- // Activate passive event if possible for better scrolling performance.
204
- const eventOptions = isPassiveEventAvailable() ? { passive: true } : false;
205
- touchSurface.addEventListener('touchstart', onTouchStart, eventOptions);
206
- touchSurface.addEventListener('touchmove', onTouchMove, eventOptions);
207
- return () => {
208
- touchSurface.removeEventListener('touchstart', onTouchStart, eventOptions);
209
- touchSurface.removeEventListener('touchmove', onTouchMove, eventOptions);
210
- };
155
+ let startX;
156
+ let startY;
157
+ // Required min distance traveled to be considered swipe.
158
+ const threshold = 150;
159
+ // Maximum distance allowed at the same time in perpendicular direction.
160
+ const restraint = 150;
161
+ // Maximum time allowed to travel that distance.
162
+ const allowedTime = 300;
163
+ let elapsedTime;
164
+ let startTime;
165
+ let finished;
166
+ const onTouchStart = evt => {
167
+ const [touch] = Array.from(evt.changedTouches);
168
+ startX = touch.pageX;
169
+ startY = touch.pageY;
170
+ // Record time when finger first makes contact with surface.
171
+ startTime = new Date().getTime();
172
+ finished = false;
173
+ };
174
+ const onTouchMove = evt => {
175
+ if (finished) {
176
+ return;
177
+ }
178
+ elapsedTime = new Date().getTime() - startTime;
179
+ if (elapsedTime > allowedTime) {
180
+ // Touch swipe too long to be considered.
181
+ return;
182
+ }
183
+ const [touch] = Array.from(evt.changedTouches);
184
+ // Get horizontal dist traveled by finger while in contact with surface.
185
+ const distX = touch.pageX - startX;
186
+ // Get vertical dist traveled by finger while in contact with surface.
187
+ const distY = touch.pageY - startY;
188
+ if (!(Math.abs(distX) >= threshold && Math.abs(distY) <= restraint)) {
189
+ // Swipe is not horizontal.
190
+ return;
191
+ }
192
+ // Swipe direction.
193
+ const direction = distX < 0 ? 'left' : 'right';
194
+ handleSwipe(direction);
195
+ finished = true;
196
+ };
197
+
198
+ // Activate passive event if possible for better scrolling performance.
199
+ const eventOptions = isPassiveEventAvailable() ? {
200
+ passive: true
201
+ } : false;
202
+ touchSurface.addEventListener('touchstart', onTouchStart, eventOptions);
203
+ touchSurface.addEventListener('touchmove', onTouchMove, eventOptions);
204
+ return () => {
205
+ touchSurface.removeEventListener('touchstart', onTouchStart, eventOptions);
206
+ touchSurface.removeEventListener('touchmove', onTouchMove, eventOptions);
207
+ };
211
208
  }
212
209
 
213
- exports.handleBasicClasses = js_utils_className_handleBasicClasses.handleBasicClasses;
214
- exports.getBasicClass = js_utils_className_getBasicClass.getBasicClass;
215
- exports.getRootClassName = js_utils_className_getRootClassName.getRootClassName;
216
- exports.getTypographyClassName = js_utils_className_getTypographyClassName.getTypographyClassName;
217
- exports.fontColorClass = js_utils_className_fontColorClass.fontColorClass;
218
- exports.resolveColorWithVariants = js_utils_className_resolveColorWithVariants.resolveColorWithVariants;
219
- exports.detectHorizontalSwipe = detectHorizontalSwipe;
220
- exports.detectSwipe = detectSwipe;
221
- exports.onButtonPressed = onButtonPressed;
222
- exports.onEnterPressed = onEnterPressed;
223
- exports.onEscapePressed = onEscapePressed;
210
+ export { detectHorizontalSwipe, detectSwipe, onButtonPressed, onEnterPressed, onEscapePressed };
package/package.json CHANGED
@@ -6,7 +6,6 @@
6
6
  "url": "https://github.com/lumapps/design-system/issues"
7
7
  },
8
8
  "dependencies": {
9
- "@lumx/icons": "^3.20.1-alpha.2",
10
9
  "classnames": "^2.3.2",
11
10
  "focus-visible": "^5.0.2",
12
11
  "lodash": "4.17.21",
@@ -20,6 +19,7 @@
20
19
  "LumX"
21
20
  ],
22
21
  "license": "MIT",
22
+ "type": "module",
23
23
  "name": "@lumx/core",
24
24
  "publishConfig": {
25
25
  "directory": "dist"
@@ -34,18 +34,16 @@
34
34
  "update-version-changelog": "yarn version-changelog ../../CHANGELOG.md"
35
35
  },
36
36
  "sideEffects": false,
37
- "version": "3.20.1-alpha.2",
37
+ "version": "3.20.1-alpha.20",
38
38
  "devDependencies": {
39
+ "@babel/preset-typescript": "^7.26.0",
40
+ "@rollup/plugin-babel": "^6.0.4",
39
41
  "@rollup/plugin-commonjs": "^19.0.2",
40
- "@rollup/plugin-terser": "^0.4.4",
41
- "@rollup/plugin-typescript": "^12.1.4",
42
- "@testing-library/dom": "^9.3.4",
43
- "@testing-library/jest-dom": "^5.16.4",
42
+ "@rollup/plugin-node-resolve": "16.0.0",
44
43
  "@types/react": "^17.0.2",
45
44
  "autoprefixer": "^9.7.4",
46
45
  "glob": "^7.1.6",
47
46
  "postcss": "^8.5.6",
48
- "react": "^17.0.2",
49
47
  "rollup": "^2.79.1",
50
48
  "rollup-plugin-cleaner": "^1.0.0",
51
49
  "rollup-plugin-copy": "^3.5.0",
@@ -53,9 +51,5 @@
53
51
  "style-dictionary": "^3.9.0",
54
52
  "tinycolor2": "^1.4.1",
55
53
  "version-changelog": "^3.1.1"
56
- },
57
- "peerDependencies": {
58
- "moment": ">= 2",
59
- "moment-range": "^4.0.2"
60
54
  }
61
55
  }
@@ -1,40 +0,0 @@
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
- };
@@ -1,120 +0,0 @@
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
- };