@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.
- package/CONTRIBUTING.md +1 -5
- package/js/constants/design-tokens.js +5389 -2294
- package/js/constants/index.js +107 -134
- package/js/constants/keycodes.js +9 -13
- package/js/custom-colors.js +17 -22
- package/js/types/Callback.js +0 -1
- package/js/types/Falsy.js +0 -1
- package/js/types/GenericProps.js +0 -1
- package/js/types/HasAriaLabelOrLabelledBy.js +0 -1
- package/js/types/HasClassName.js +0 -1
- package/js/types/HasCloseMode.js +0 -1
- package/js/types/HasTheme.js +0 -1
- package/js/types/HeadingElement.js +0 -1
- package/js/types/Point.js +0 -1
- package/js/types/Predicate.js +0 -1
- package/js/types/RectSize.js +0 -1
- package/js/types/TextElement.js +0 -1
- package/js/types/ValueOf.js +0 -1
- package/js/types/index.js +0 -1
- package/js/utils/className/fontColorClass.js +7 -12
- package/js/utils/className/fontColorClass.test.js +14 -16
- package/js/utils/className/getBasicClass.js +19 -24
- package/js/utils/className/getBasicClass.test.js +55 -19
- package/js/utils/className/getRootClassName.js +10 -17
- package/js/utils/className/getRootClassName.test.js +11 -13
- package/js/utils/className/getTypographyClassName.js +3 -7
- package/js/utils/className/getTypographyClassName.test.js +5 -7
- package/js/utils/className/handleBasicClasses.js +27 -31
- package/js/utils/className/handleBasicClasses.test.js +30 -32
- package/js/utils/className/index.js +12 -25
- package/js/utils/className/resolveColorWithVariants.js +4 -9
- package/js/utils/className/resolveColorWithVariants.test.js +26 -28
- package/js/utils/index.js +161 -174
- package/package.json +5 -11
- package/js/components/Icon/Stories.js +0 -40
- package/js/components/Icon/Tests.tsx +0 -120
- package/js/components/Icon/index.tsx +0 -134
- package/js/constants/design-tokens.min.js +0 -1
- package/js/constants/index.min.js +0 -1
- package/js/constants/keycodes.min.js +0 -1
- package/js/custom-colors.min.js +0 -1
- package/js/date-picker.js +0 -71
- package/js/date-picker.min.js +0 -1
- package/js/date-picker.ts +0 -77
- package/js/types/Callback.min.js +0 -1
- package/js/types/Falsy.min.js +0 -1
- package/js/types/GenericProps.min.js +0 -1
- package/js/types/HasAriaLabelOrLabelledBy.min.js +0 -1
- package/js/types/HasClassName.min.js +0 -1
- package/js/types/HasCloseMode.min.js +0 -1
- package/js/types/HasTheme.min.js +0 -1
- package/js/types/HeadingElement.min.js +0 -1
- package/js/types/Point.min.js +0 -1
- package/js/types/Predicate.min.js +0 -1
- package/js/types/RectSize.min.js +0 -1
- package/js/types/TextElement.min.js +0 -1
- package/js/types/ValueOf.min.js +0 -1
- package/js/types/index.min.js +0 -1
- package/js/utils/className/fontColorClass.min.js +0 -1
- package/js/utils/className/fontColorClass.test.min.js +0 -1
- package/js/utils/className/getBasicClass.min.js +0 -1
- package/js/utils/className/getBasicClass.test.min.js +0 -1
- package/js/utils/className/getRootClassName.min.js +0 -1
- package/js/utils/className/getRootClassName.test.min.js +0 -1
- package/js/utils/className/getTypographyClassName.min.js +0 -1
- package/js/utils/className/getTypographyClassName.test.min.js +0 -1
- package/js/utils/className/handleBasicClasses.min.js +0 -1
- package/js/utils/className/handleBasicClasses.test.min.js +0 -1
- package/js/utils/className/index.min.js +0 -1
- package/js/utils/className/resolveColorWithVariants.min.js +0 -1
- package/js/utils/className/resolveColorWithVariants.test.min.js +0 -1
- package/js/utils/index.min.js +0 -1
- package/lumx.min.css +0 -1
- package/stories/controls/color.ts +0 -7
- package/stories/controls/icons.ts +0 -126
- package/stories/controls/selectArgType.ts +0 -8
- package/stories/controls/withUndefined.ts +0 -1
- package/testing/utils/queries.ts +0 -19
package/js/utils/index.js
CHANGED
|
@@ -1,24 +1,16 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
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
|
-
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
|
|
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
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
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
|
-
|
|
59
|
-
|
|
60
|
-
|
|
61
|
-
|
|
62
|
-
|
|
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 =
|
|
75
|
-
|
|
76
|
-
|
|
77
|
-
|
|
78
|
-
|
|
79
|
-
|
|
80
|
-
|
|
81
|
-
|
|
82
|
-
|
|
83
|
-
|
|
84
|
-
|
|
85
|
-
|
|
86
|
-
|
|
87
|
-
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
|
|
94
|
-
|
|
95
|
-
|
|
96
|
-
|
|
97
|
-
|
|
98
|
-
|
|
99
|
-
|
|
100
|
-
|
|
101
|
-
|
|
102
|
-
|
|
103
|
-
|
|
104
|
-
|
|
105
|
-
|
|
106
|
-
|
|
107
|
-
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
|
|
112
|
-
|
|
113
|
-
|
|
114
|
-
|
|
115
|
-
|
|
116
|
-
|
|
117
|
-
|
|
118
|
-
|
|
119
|
-
|
|
120
|
-
|
|
121
|
-
|
|
122
|
-
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
128
|
-
|
|
129
|
-
|
|
130
|
-
|
|
131
|
-
|
|
132
|
-
|
|
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
|
-
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
148
|
-
|
|
149
|
-
|
|
150
|
-
|
|
151
|
-
|
|
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
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
171
|
-
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
178
|
-
|
|
179
|
-
|
|
180
|
-
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
|
|
184
|
-
|
|
185
|
-
|
|
186
|
-
|
|
187
|
-
|
|
188
|
-
|
|
189
|
-
|
|
190
|
-
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
-
|
|
196
|
-
|
|
197
|
-
|
|
198
|
-
|
|
199
|
-
|
|
200
|
-
|
|
201
|
-
|
|
202
|
-
|
|
203
|
-
|
|
204
|
-
|
|
205
|
-
|
|
206
|
-
|
|
207
|
-
|
|
208
|
-
|
|
209
|
-
|
|
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
|
-
|
|
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.
|
|
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-
|
|
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
|
-
};
|