@lumx/core 3.20.1-alpha.3 → 3.20.1-alpha.30
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 +18 -24
- package/js/utils/className/getBasicClass.test.js +54 -19
- package/js/utils/className/getBasicClass.ts +2 -3
- package/js/utils/className/getRootClassName.js +10 -17
- package/js/utils/className/getRootClassName.test.js +11 -13
- package/js/utils/className/getRootClassName.ts +1 -2
- package/js/utils/className/getTypographyClassName.js +3 -7
- package/js/utils/className/getTypographyClassName.test.js +5 -7
- package/js/utils/className/handleBasicClasses.js +26 -31
- package/js/utils/className/handleBasicClasses.test.js +29 -32
- package/js/utils/className/handleBasicClasses.ts +3 -5
- package/js/utils/className/index.js +11 -25
- package/js/utils/className/resolveColorWithVariants.js +4 -9
- package/js/utils/className/resolveColorWithVariants.test.js +26 -28
- package/js/utils/collection/castArray.js +4 -0
- package/js/utils/collection/castArray.test.js +15 -0
- package/js/utils/collection/castArray.test.ts +15 -0
- package/js/utils/collection/castArray.ts +3 -0
- package/js/utils/collection/chunk.js +13 -0
- package/js/utils/collection/chunk.test.js +28 -0
- package/js/utils/collection/chunk.test.ts +38 -0
- package/js/utils/collection/chunk.ts +11 -0
- package/js/utils/collection/isEmpty.js +4 -0
- package/js/utils/collection/isEmpty.test.js +21 -0
- package/js/utils/collection/isEmpty.test.ts +21 -0
- package/js/utils/collection/isEmpty.ts +4 -0
- package/js/utils/collection/last.js +4 -0
- package/js/utils/collection/last.test.js +19 -0
- package/js/utils/collection/last.test.ts +21 -0
- package/js/utils/collection/last.ts +2 -0
- package/js/utils/collection/partitionMulti.js +28 -0
- package/js/utils/collection/partitionMulti.test.js +26 -0
- package/js/utils/collection/partitionMulti.test.ts +35 -0
- package/js/utils/collection/partitionMulti.ts +29 -0
- package/js/utils/collection/range.js +6 -0
- package/js/utils/collection/range.test.js +10 -0
- package/js/utils/collection/range.test.ts +10 -0
- package/js/utils/collection/range.ts +2 -0
- package/js/utils/index.js +159 -174
- package/js/utils/index.ts +4 -6
- package/js/utils/string/kebabCase.js +28 -0
- package/js/utils/string/kebabCase.test.js +41 -0
- package/js/utils/string/kebabCase.test.ts +50 -0
- package/js/utils/string/kebabCase.ts +28 -0
- package/package.json +13 -11
- package/js/components/Icon/index.tsx +0 -133
- 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
|
@@ -1,22 +1,57 @@
|
|
|
1
|
-
|
|
1
|
+
import { getBasicClass } from './getBasicClass.js';
|
|
2
|
+
import '../string/kebabCase.js';
|
|
2
3
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
4
|
+
describe(getBasicClass, () => {
|
|
5
|
+
it('should return correct basic CSS class for different types and values', () => {
|
|
6
|
+
// Test cases with different inputs
|
|
7
|
+
expect(getBasicClass({
|
|
8
|
+
prefix: 'test',
|
|
9
|
+
type: 'color',
|
|
10
|
+
value: 'primary'
|
|
11
|
+
})).toBe('test--color-primary');
|
|
12
|
+
expect(getBasicClass({
|
|
13
|
+
prefix: 'test',
|
|
14
|
+
type: 'variant',
|
|
15
|
+
value: 'button'
|
|
16
|
+
})).toBe('test--variant-button');
|
|
17
|
+
expect(getBasicClass({
|
|
18
|
+
prefix: 'test',
|
|
19
|
+
type: 'isDark',
|
|
20
|
+
value: true
|
|
21
|
+
})).toBe('test--is-dark');
|
|
22
|
+
expect(getBasicClass({
|
|
23
|
+
prefix: 'test',
|
|
24
|
+
type: 'dark',
|
|
25
|
+
value: true
|
|
26
|
+
})).toBe('test--is-dark');
|
|
27
|
+
expect(getBasicClass({
|
|
28
|
+
prefix: 'test',
|
|
29
|
+
type: 'hasDark',
|
|
30
|
+
value: true
|
|
31
|
+
})).toBe('test--has-dark');
|
|
32
|
+
expect(getBasicClass({
|
|
33
|
+
prefix: 'test',
|
|
34
|
+
type: 'isActive',
|
|
35
|
+
value: false
|
|
36
|
+
})).toBe('');
|
|
6
37
|
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
38
|
+
// Additional tests for boolean types
|
|
39
|
+
expect(getBasicClass({
|
|
40
|
+
prefix: 'test',
|
|
41
|
+
type: 'hasBorder',
|
|
42
|
+
value: true
|
|
43
|
+
})).toBe('test--has-border');
|
|
44
|
+
expect(getBasicClass({
|
|
45
|
+
prefix: 'test',
|
|
46
|
+
type: 'isVisible',
|
|
47
|
+
value: false
|
|
48
|
+
})).toBe('');
|
|
49
|
+
|
|
50
|
+
// Tests for undefined
|
|
51
|
+
expect(getBasicClass({
|
|
52
|
+
prefix: 'test',
|
|
53
|
+
type: 'variant',
|
|
54
|
+
value: undefined
|
|
55
|
+
})).toBe('test--variant-undefined');
|
|
56
|
+
});
|
|
22
57
|
});
|
|
@@ -1,5 +1,4 @@
|
|
|
1
|
-
import
|
|
2
|
-
import kebabCase from 'lodash/kebabCase';
|
|
1
|
+
import { kebabCase } from '../string/kebabCase';
|
|
3
2
|
|
|
4
3
|
/**
|
|
5
4
|
* Get the basic CSS class for the given type.
|
|
@@ -18,7 +17,7 @@ export function getBasicClass({
|
|
|
18
17
|
type: string;
|
|
19
18
|
value: string | number | boolean | undefined;
|
|
20
19
|
}): string {
|
|
21
|
-
if (
|
|
20
|
+
if (typeof value === 'boolean') {
|
|
22
21
|
if (!value) {
|
|
23
22
|
// False value should not return a class.
|
|
24
23
|
return '';
|
|
@@ -1,17 +1,10 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var kebabCase = require('lodash/kebabCase');
|
|
6
|
-
var js_constants_index = require('../../constants/index.js');
|
|
7
|
-
require('../../constants/keycodes.js');
|
|
8
|
-
|
|
9
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
10
|
-
|
|
11
|
-
var kebabCase__default = /*#__PURE__*/_interopDefaultLegacy(kebabCase);
|
|
1
|
+
import { CSS_PREFIX } from '../../constants/index.js';
|
|
2
|
+
import { kebabCase } from '../string/kebabCase.js';
|
|
3
|
+
import '../../constants/keycodes.js';
|
|
12
4
|
|
|
13
5
|
// See https://regex101.com/r/YjS1uI/3
|
|
14
6
|
const LAST_PART_CLASSNAME = /^(.*)-(.+)$/gi;
|
|
7
|
+
|
|
15
8
|
/**
|
|
16
9
|
* Get the name of the root CSS class of a component based on its name.
|
|
17
10
|
*
|
|
@@ -23,11 +16,11 @@ const LAST_PART_CLASSNAME = /^(.*)-(.+)$/gi;
|
|
|
23
16
|
* lower-snake-case.
|
|
24
17
|
*/
|
|
25
18
|
function getRootClassName(componentName, subComponent) {
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
|
|
29
|
-
|
|
30
|
-
|
|
19
|
+
const formattedClassName = `${CSS_PREFIX}-${kebabCase(componentName)}`;
|
|
20
|
+
if (subComponent) {
|
|
21
|
+
return formattedClassName.replace(LAST_PART_CLASSNAME, '$1__$2');
|
|
22
|
+
}
|
|
23
|
+
return formattedClassName;
|
|
31
24
|
}
|
|
32
25
|
|
|
33
|
-
|
|
26
|
+
export { getRootClassName };
|
|
@@ -1,15 +1,13 @@
|
|
|
1
|
-
|
|
1
|
+
import { getRootClassName } from './getRootClassName.js';
|
|
2
|
+
import '../../constants/index.js';
|
|
3
|
+
import '../../constants/keycodes.js';
|
|
4
|
+
import '../string/kebabCase.js';
|
|
2
5
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
expect(js_utils_className_getRootClassName.getRootClassName('Table')).toBe('lumx-table');
|
|
11
|
-
});
|
|
12
|
-
it('should transform the sub component name into a lumx class', () => {
|
|
13
|
-
expect(js_utils_className_getRootClassName.getRootClassName('TableBody', true)).toBe('lumx-table__body');
|
|
14
|
-
});
|
|
6
|
+
describe(getRootClassName, () => {
|
|
7
|
+
it('should transform the component name into a lumx class', () => {
|
|
8
|
+
expect(getRootClassName('Table')).toBe('lumx-table');
|
|
9
|
+
});
|
|
10
|
+
it('should transform the sub component name into a lumx class', () => {
|
|
11
|
+
expect(getRootClassName('TableBody', true)).toBe('lumx-table__body');
|
|
12
|
+
});
|
|
15
13
|
});
|
|
@@ -1,13 +1,9 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
1
|
/**
|
|
6
2
|
* Returns the classname associated to the given typography.
|
|
7
3
|
* For example, for `Typography.title` it returns `lumx-typography-title`
|
|
8
4
|
*/
|
|
9
|
-
const getTypographyClassName =
|
|
10
|
-
|
|
5
|
+
const getTypographyClassName = typography => {
|
|
6
|
+
return `lumx-typography-${typography}`;
|
|
11
7
|
};
|
|
12
8
|
|
|
13
|
-
|
|
9
|
+
export { getTypographyClassName };
|
|
@@ -1,9 +1,7 @@
|
|
|
1
|
-
|
|
1
|
+
import { getTypographyClassName } from './getTypographyClassName.js';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
expect(js_utils_className_getTypographyClassName.getTypographyClassName('title')).toBe('lumx-typography-title');
|
|
8
|
-
});
|
|
3
|
+
describe(getTypographyClassName, () => {
|
|
4
|
+
it('should generate lumx typography class', () => {
|
|
5
|
+
expect(getTypographyClassName('title')).toBe('lumx-typography-title');
|
|
6
|
+
});
|
|
9
7
|
});
|
|
@@ -1,18 +1,7 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
var classNames = require('classnames');
|
|
6
|
-
var isBoolean = require('lodash/isBoolean');
|
|
7
|
-
var isEmpty = require('lodash/isEmpty');
|
|
8
|
-
var js_utils_className_getBasicClass = require('./getBasicClass.js');
|
|
9
|
-
require('lodash/kebabCase');
|
|
10
|
-
|
|
11
|
-
function _interopDefaultLegacy (e) { return e && typeof e === 'object' && 'default' in e ? e : { 'default': e }; }
|
|
12
|
-
|
|
13
|
-
var classNames__default = /*#__PURE__*/_interopDefaultLegacy(classNames);
|
|
14
|
-
var isBoolean__default = /*#__PURE__*/_interopDefaultLegacy(isBoolean);
|
|
15
|
-
var isEmpty__default = /*#__PURE__*/_interopDefaultLegacy(isEmpty);
|
|
1
|
+
import classNames from 'classnames';
|
|
2
|
+
import { isEmpty } from '@lumx/core/js/utils/collection/isEmpty';
|
|
3
|
+
import { getBasicClass } from './getBasicClass.js';
|
|
4
|
+
import '../string/kebabCase.js';
|
|
16
5
|
|
|
17
6
|
/**
|
|
18
7
|
* Enhance isEmpty method to also works with numbers.
|
|
@@ -20,12 +9,13 @@ var isEmpty__default = /*#__PURE__*/_interopDefaultLegacy(isEmpty);
|
|
|
20
9
|
* @param value The value to check.
|
|
21
10
|
* @return Whether the input value is empty or != 0.
|
|
22
11
|
*/
|
|
23
|
-
const _isEmpty =
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
12
|
+
const _isEmpty = value => {
|
|
13
|
+
if (typeof value === 'number') {
|
|
14
|
+
return value === 0;
|
|
15
|
+
}
|
|
16
|
+
return isEmpty(value);
|
|
28
17
|
};
|
|
18
|
+
|
|
29
19
|
/**
|
|
30
20
|
* Return all basic LumX CSS classes which are available for every components.
|
|
31
21
|
*
|
|
@@ -37,16 +27,21 @@ const _isEmpty = (value) => {
|
|
|
37
27
|
* be used in the classname to represent the value of the given prop.
|
|
38
28
|
* @return All LumX basic CSS classes.
|
|
39
29
|
*/
|
|
40
|
-
function handleBasicClasses({
|
|
41
|
-
|
|
42
|
-
|
|
43
|
-
|
|
44
|
-
|
|
45
|
-
|
|
46
|
-
|
|
47
|
-
|
|
48
|
-
|
|
49
|
-
|
|
30
|
+
function handleBasicClasses({
|
|
31
|
+
prefix,
|
|
32
|
+
...props
|
|
33
|
+
}) {
|
|
34
|
+
const otherClasses = {};
|
|
35
|
+
if (!isEmpty(props)) {
|
|
36
|
+
Object.keys(props).forEach(prop => {
|
|
37
|
+
otherClasses[getBasicClass({
|
|
38
|
+
prefix,
|
|
39
|
+
type: prop,
|
|
40
|
+
value: props[prop]
|
|
41
|
+
})] = typeof props[prop] === 'boolean' ? props[prop] : !_isEmpty(props[prop]);
|
|
42
|
+
});
|
|
43
|
+
}
|
|
44
|
+
return classNames(prefix, otherClasses);
|
|
50
45
|
}
|
|
51
46
|
|
|
52
|
-
|
|
47
|
+
export { handleBasicClasses };
|
|
@@ -1,35 +1,32 @@
|
|
|
1
|
-
|
|
1
|
+
import { handleBasicClasses } from './handleBasicClasses.js';
|
|
2
|
+
import 'classnames';
|
|
3
|
+
import '@lumx/core/js/utils/collection/isEmpty';
|
|
4
|
+
import './getBasicClass.js';
|
|
5
|
+
import '../string/kebabCase.js';
|
|
2
6
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
color: 'red',
|
|
26
|
-
// False property
|
|
27
|
-
isDisabled: false,
|
|
28
|
-
// Boolean without a prefix (is or has)
|
|
29
|
-
visible: true,
|
|
30
|
-
// Has prefix
|
|
31
|
-
hasButton: true,
|
|
32
|
-
});
|
|
33
|
-
expect(className).toBe('test test--color-red test--is-visible test--has-button');
|
|
7
|
+
describe(handleBasicClasses, () => {
|
|
8
|
+
it('should return correct combined CSS classes based on props', () => {
|
|
9
|
+
const className = handleBasicClasses({
|
|
10
|
+
prefix: 'test',
|
|
11
|
+
// Undefined
|
|
12
|
+
undefined,
|
|
13
|
+
// Null
|
|
14
|
+
null: null,
|
|
15
|
+
// Empty string
|
|
16
|
+
emptyString: '',
|
|
17
|
+
// Empty array
|
|
18
|
+
emptyArray: [],
|
|
19
|
+
// Empty object
|
|
20
|
+
emptyObject: {},
|
|
21
|
+
// String
|
|
22
|
+
color: 'red',
|
|
23
|
+
// False property
|
|
24
|
+
isDisabled: false,
|
|
25
|
+
// Boolean without a prefix (is or has)
|
|
26
|
+
visible: true,
|
|
27
|
+
// Has prefix
|
|
28
|
+
hasButton: true
|
|
34
29
|
});
|
|
30
|
+
expect(className).toBe('test test--color-red test--is-visible test--has-button');
|
|
31
|
+
});
|
|
35
32
|
});
|
|
@@ -1,7 +1,6 @@
|
|
|
1
1
|
import classNames from 'classnames';
|
|
2
2
|
|
|
3
|
-
import
|
|
4
|
-
import isEmpty from 'lodash/isEmpty';
|
|
3
|
+
import { isEmpty } from '@lumx/core/js/utils/collection/isEmpty';
|
|
5
4
|
|
|
6
5
|
import { getBasicClass } from './getBasicClass';
|
|
7
6
|
|
|
@@ -34,9 +33,8 @@ export function handleBasicClasses({ prefix, ...props }: { prefix: string; [prop
|
|
|
34
33
|
const otherClasses: any = {};
|
|
35
34
|
if (!isEmpty(props)) {
|
|
36
35
|
Object.keys(props).forEach((prop) => {
|
|
37
|
-
otherClasses[getBasicClass({ prefix, type: prop, value: props[prop] })] =
|
|
38
|
-
? props[prop]
|
|
39
|
-
: !_isEmpty(props[prop]);
|
|
36
|
+
otherClasses[getBasicClass({ prefix, type: prop, value: props[prop] })] =
|
|
37
|
+
typeof props[prop] === 'boolean' ? props[prop] : !_isEmpty(props[prop]);
|
|
40
38
|
});
|
|
41
39
|
}
|
|
42
40
|
|
|
@@ -1,25 +1,11 @@
|
|
|
1
|
-
|
|
2
|
-
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
require('lodash/isBoolean');
|
|
13
|
-
require('lodash/isEmpty');
|
|
14
|
-
require('lodash/kebabCase');
|
|
15
|
-
require('../../constants/index.js');
|
|
16
|
-
require('../../constants/keycodes.js');
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
exports.handleBasicClasses = js_utils_className_handleBasicClasses.handleBasicClasses;
|
|
21
|
-
exports.getBasicClass = js_utils_className_getBasicClass.getBasicClass;
|
|
22
|
-
exports.getRootClassName = js_utils_className_getRootClassName.getRootClassName;
|
|
23
|
-
exports.getTypographyClassName = js_utils_className_getTypographyClassName.getTypographyClassName;
|
|
24
|
-
exports.fontColorClass = js_utils_className_fontColorClass.fontColorClass;
|
|
25
|
-
exports.resolveColorWithVariants = js_utils_className_resolveColorWithVariants.resolveColorWithVariants;
|
|
1
|
+
export { handleBasicClasses } from './handleBasicClasses.js';
|
|
2
|
+
export { getBasicClass } from './getBasicClass.js';
|
|
3
|
+
export { getRootClassName } from './getRootClassName.js';
|
|
4
|
+
export { getTypographyClassName } from './getTypographyClassName.js';
|
|
5
|
+
export { fontColorClass } from './fontColorClass.js';
|
|
6
|
+
export { resolveColorWithVariants } from './resolveColorWithVariants.js';
|
|
7
|
+
import 'classnames';
|
|
8
|
+
import '@lumx/core/js/utils/collection/isEmpty';
|
|
9
|
+
import '../string/kebabCase.js';
|
|
10
|
+
import '../../constants/index.js';
|
|
11
|
+
import '../../constants/keycodes.js';
|
|
@@ -1,13 +1,8 @@
|
|
|
1
|
-
'use strict';
|
|
2
|
-
|
|
3
|
-
Object.defineProperty(exports, '__esModule', { value: true });
|
|
4
|
-
|
|
5
1
|
/** Resolve color & color variant from a `ColorWithVariants` and optionally a `ColorVariant`. */
|
|
6
2
|
function resolveColorWithVariants(colorWithVariants, colorVariant) {
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
return [color, (colorVariant || baseColorVariant)];
|
|
3
|
+
if (!colorWithVariants) return [undefined, colorVariant];
|
|
4
|
+
const [color, baseColorVariant] = colorWithVariants.split('-');
|
|
5
|
+
return [color, colorVariant || baseColorVariant];
|
|
11
6
|
}
|
|
12
7
|
|
|
13
|
-
|
|
8
|
+
export { resolveColorWithVariants };
|
|
@@ -1,30 +1,28 @@
|
|
|
1
|
-
|
|
1
|
+
import { resolveColorWithVariants } from './resolveColorWithVariants.js';
|
|
2
2
|
|
|
3
|
-
|
|
4
|
-
|
|
5
|
-
|
|
6
|
-
|
|
7
|
-
|
|
8
|
-
|
|
9
|
-
|
|
10
|
-
|
|
11
|
-
|
|
12
|
-
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
20
|
-
|
|
21
|
-
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
|
|
26
|
-
|
|
27
|
-
|
|
28
|
-
expect(result).toEqual(['primary', 'D2']);
|
|
29
|
-
});
|
|
3
|
+
describe(resolveColorWithVariants, () => {
|
|
4
|
+
it('should handle undefined color', () => {
|
|
5
|
+
const result = resolveColorWithVariants(undefined);
|
|
6
|
+
expect(result).toEqual([undefined, undefined]);
|
|
7
|
+
});
|
|
8
|
+
it('should handle undefined color with variant', () => {
|
|
9
|
+
const result = resolveColorWithVariants(undefined, 'L2');
|
|
10
|
+
expect(result).toEqual([undefined, 'L2']);
|
|
11
|
+
});
|
|
12
|
+
it('should handle color with undefined variant', () => {
|
|
13
|
+
const result = resolveColorWithVariants('primary');
|
|
14
|
+
expect(result).toEqual(['primary', undefined]);
|
|
15
|
+
});
|
|
16
|
+
it('should handle color & variant separated', () => {
|
|
17
|
+
const result = resolveColorWithVariants('primary', 'L2');
|
|
18
|
+
expect(result).toEqual(['primary', 'L2']);
|
|
19
|
+
});
|
|
20
|
+
it('should handle color with variant all in one', () => {
|
|
21
|
+
const result = resolveColorWithVariants('primary-L2');
|
|
22
|
+
expect(result).toEqual(['primary', 'L2']);
|
|
23
|
+
});
|
|
24
|
+
it('should override color variant with the given color variant', () => {
|
|
25
|
+
const result = resolveColorWithVariants('primary-L2', 'D2');
|
|
26
|
+
expect(result).toEqual(['primary', 'D2']);
|
|
27
|
+
});
|
|
30
28
|
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { castArray } from '@lumx/core/js/utils/collection/castArray';
|
|
2
|
+
|
|
3
|
+
describe(castArray, () => {
|
|
4
|
+
it('should keep existing array', () => {
|
|
5
|
+
const input = [1, 2];
|
|
6
|
+
const output = castArray(input);
|
|
7
|
+
expect(output).toEqual([1, 2]);
|
|
8
|
+
expect(output).toBe(input);
|
|
9
|
+
});
|
|
10
|
+
it('should cast item to array', () => {
|
|
11
|
+
const input = 1;
|
|
12
|
+
const output = castArray(input);
|
|
13
|
+
expect(output).toEqual([1]);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,15 @@
|
|
|
1
|
+
import { castArray } from '@lumx/core/js/utils/collection/castArray';
|
|
2
|
+
|
|
3
|
+
describe(castArray, () => {
|
|
4
|
+
it('should keep existing array', () => {
|
|
5
|
+
const input = [1, 2];
|
|
6
|
+
const output = castArray(input);
|
|
7
|
+
expect(output).toEqual([1, 2]);
|
|
8
|
+
expect(output).toBe(input);
|
|
9
|
+
});
|
|
10
|
+
it('should cast item to array', () => {
|
|
11
|
+
const input = 1;
|
|
12
|
+
const output = castArray(input);
|
|
13
|
+
expect(output).toEqual([1]);
|
|
14
|
+
});
|
|
15
|
+
});
|
|
@@ -0,0 +1,13 @@
|
|
|
1
|
+
/** Chunk array in slices of given size */
|
|
2
|
+
function chunk(input, size) {
|
|
3
|
+
if (size <= 0) {
|
|
4
|
+
throw new Error('Size must be greater than 0');
|
|
5
|
+
}
|
|
6
|
+
const result = [];
|
|
7
|
+
for (let i = 0; i < input.length; i += size) {
|
|
8
|
+
result.push(input.slice(i, i + size));
|
|
9
|
+
}
|
|
10
|
+
return result;
|
|
11
|
+
}
|
|
12
|
+
|
|
13
|
+
export { chunk };
|
|
@@ -0,0 +1,28 @@
|
|
|
1
|
+
import { chunk } from '@lumx/core/js/utils/collection/chunk';
|
|
2
|
+
|
|
3
|
+
describe(chunk, () => {
|
|
4
|
+
it('should do nothing on empty array', () => {
|
|
5
|
+
expect(chunk([], 2)).toEqual([]);
|
|
6
|
+
});
|
|
7
|
+
it('should work with size larger than input array', () => {
|
|
8
|
+
expect(chunk([1, 2], 4)).toEqual([[1, 2]]);
|
|
9
|
+
});
|
|
10
|
+
it('should chunk array with size not perfectly dividing the array length', () => {
|
|
11
|
+
expect(chunk([1, 2, 3, 4, 5], 2)).toEqual([[1, 2], [3, 4], [5]]);
|
|
12
|
+
});
|
|
13
|
+
it('should chunk array with size perfectly dividing the array length', () => {
|
|
14
|
+
expect(chunk([1, 2, 3, 4], 2)).toEqual([[1, 2], [3, 4]]);
|
|
15
|
+
});
|
|
16
|
+
it('should work with size of 1', () => {
|
|
17
|
+
expect(chunk([1, 2, 3], 1)).toEqual([[1], [2], [3]]);
|
|
18
|
+
});
|
|
19
|
+
it('should work with size equal to array length', () => {
|
|
20
|
+
expect(chunk([1, 2, 3], 3)).toEqual([[1, 2, 3]]);
|
|
21
|
+
});
|
|
22
|
+
it('should throw error when size is 0', () => {
|
|
23
|
+
expect(() => chunk([1, 2, 3], 0)).toThrow('Size must be greater than 0');
|
|
24
|
+
});
|
|
25
|
+
it('should throw error when size is negative', () => {
|
|
26
|
+
expect(() => chunk([1, 2, 3], -1)).toThrow('Size must be greater than 0');
|
|
27
|
+
});
|
|
28
|
+
});
|
|
@@ -0,0 +1,38 @@
|
|
|
1
|
+
import { chunk } from '@lumx/core/js/utils/collection/chunk';
|
|
2
|
+
|
|
3
|
+
describe(chunk, () => {
|
|
4
|
+
it('should do nothing on empty array', () => {
|
|
5
|
+
expect(chunk([], 2)).toEqual([]);
|
|
6
|
+
});
|
|
7
|
+
|
|
8
|
+
it('should work with size larger than input array', () => {
|
|
9
|
+
expect(chunk([1, 2], 4)).toEqual([[1, 2]]);
|
|
10
|
+
});
|
|
11
|
+
|
|
12
|
+
it('should chunk array with size not perfectly dividing the array length', () => {
|
|
13
|
+
expect(chunk([1, 2, 3, 4, 5], 2)).toEqual([[1, 2], [3, 4], [5]]);
|
|
14
|
+
});
|
|
15
|
+
|
|
16
|
+
it('should chunk array with size perfectly dividing the array length', () => {
|
|
17
|
+
expect(chunk([1, 2, 3, 4], 2)).toEqual([
|
|
18
|
+
[1, 2],
|
|
19
|
+
[3, 4],
|
|
20
|
+
]);
|
|
21
|
+
});
|
|
22
|
+
|
|
23
|
+
it('should work with size of 1', () => {
|
|
24
|
+
expect(chunk([1, 2, 3], 1)).toEqual([[1], [2], [3]]);
|
|
25
|
+
});
|
|
26
|
+
|
|
27
|
+
it('should work with size equal to array length', () => {
|
|
28
|
+
expect(chunk([1, 2, 3], 3)).toEqual([[1, 2, 3]]);
|
|
29
|
+
});
|
|
30
|
+
|
|
31
|
+
it('should throw error when size is 0', () => {
|
|
32
|
+
expect(() => chunk([1, 2, 3], 0)).toThrow('Size must be greater than 0');
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it('should throw error when size is negative', () => {
|
|
36
|
+
expect(() => chunk([1, 2, 3], -1)).toThrow('Size must be greater than 0');
|
|
37
|
+
});
|
|
38
|
+
});
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
/** Chunk array in slices of given size */
|
|
2
|
+
export function chunk<T>(input: Array<T>, size: number): T[][] {
|
|
3
|
+
if (size <= 0) {
|
|
4
|
+
throw new Error('Size must be greater than 0');
|
|
5
|
+
}
|
|
6
|
+
const result: T[][] = [];
|
|
7
|
+
for (let i = 0; i < input.length; i += size) {
|
|
8
|
+
result.push(input.slice(i, i + size));
|
|
9
|
+
}
|
|
10
|
+
return result;
|
|
11
|
+
}
|