@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.
Files changed (103) 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 +18 -24
  23. package/js/utils/className/getBasicClass.test.js +54 -19
  24. package/js/utils/className/getBasicClass.ts +2 -3
  25. package/js/utils/className/getRootClassName.js +10 -17
  26. package/js/utils/className/getRootClassName.test.js +11 -13
  27. package/js/utils/className/getRootClassName.ts +1 -2
  28. package/js/utils/className/getTypographyClassName.js +3 -7
  29. package/js/utils/className/getTypographyClassName.test.js +5 -7
  30. package/js/utils/className/handleBasicClasses.js +26 -31
  31. package/js/utils/className/handleBasicClasses.test.js +29 -32
  32. package/js/utils/className/handleBasicClasses.ts +3 -5
  33. package/js/utils/className/index.js +11 -25
  34. package/js/utils/className/resolveColorWithVariants.js +4 -9
  35. package/js/utils/className/resolveColorWithVariants.test.js +26 -28
  36. package/js/utils/collection/castArray.js +4 -0
  37. package/js/utils/collection/castArray.test.js +15 -0
  38. package/js/utils/collection/castArray.test.ts +15 -0
  39. package/js/utils/collection/castArray.ts +3 -0
  40. package/js/utils/collection/chunk.js +13 -0
  41. package/js/utils/collection/chunk.test.js +28 -0
  42. package/js/utils/collection/chunk.test.ts +38 -0
  43. package/js/utils/collection/chunk.ts +11 -0
  44. package/js/utils/collection/isEmpty.js +4 -0
  45. package/js/utils/collection/isEmpty.test.js +21 -0
  46. package/js/utils/collection/isEmpty.test.ts +21 -0
  47. package/js/utils/collection/isEmpty.ts +4 -0
  48. package/js/utils/collection/last.js +4 -0
  49. package/js/utils/collection/last.test.js +19 -0
  50. package/js/utils/collection/last.test.ts +21 -0
  51. package/js/utils/collection/last.ts +2 -0
  52. package/js/utils/collection/partitionMulti.js +28 -0
  53. package/js/utils/collection/partitionMulti.test.js +26 -0
  54. package/js/utils/collection/partitionMulti.test.ts +35 -0
  55. package/js/utils/collection/partitionMulti.ts +29 -0
  56. package/js/utils/collection/range.js +6 -0
  57. package/js/utils/collection/range.test.js +10 -0
  58. package/js/utils/collection/range.test.ts +10 -0
  59. package/js/utils/collection/range.ts +2 -0
  60. package/js/utils/index.js +159 -174
  61. package/js/utils/index.ts +4 -6
  62. package/js/utils/string/kebabCase.js +28 -0
  63. package/js/utils/string/kebabCase.test.js +41 -0
  64. package/js/utils/string/kebabCase.test.ts +50 -0
  65. package/js/utils/string/kebabCase.ts +28 -0
  66. package/package.json +13 -11
  67. package/js/components/Icon/index.tsx +0 -133
  68. package/js/constants/design-tokens.min.js +0 -1
  69. package/js/constants/index.min.js +0 -1
  70. package/js/constants/keycodes.min.js +0 -1
  71. package/js/custom-colors.min.js +0 -1
  72. package/js/date-picker.js +0 -71
  73. package/js/date-picker.min.js +0 -1
  74. package/js/date-picker.ts +0 -77
  75. package/js/types/Callback.min.js +0 -1
  76. package/js/types/Falsy.min.js +0 -1
  77. package/js/types/GenericProps.min.js +0 -1
  78. package/js/types/HasAriaLabelOrLabelledBy.min.js +0 -1
  79. package/js/types/HasClassName.min.js +0 -1
  80. package/js/types/HasCloseMode.min.js +0 -1
  81. package/js/types/HasTheme.min.js +0 -1
  82. package/js/types/HeadingElement.min.js +0 -1
  83. package/js/types/Point.min.js +0 -1
  84. package/js/types/Predicate.min.js +0 -1
  85. package/js/types/RectSize.min.js +0 -1
  86. package/js/types/TextElement.min.js +0 -1
  87. package/js/types/ValueOf.min.js +0 -1
  88. package/js/types/index.min.js +0 -1
  89. package/js/utils/className/fontColorClass.min.js +0 -1
  90. package/js/utils/className/fontColorClass.test.min.js +0 -1
  91. package/js/utils/className/getBasicClass.min.js +0 -1
  92. package/js/utils/className/getBasicClass.test.min.js +0 -1
  93. package/js/utils/className/getRootClassName.min.js +0 -1
  94. package/js/utils/className/getRootClassName.test.min.js +0 -1
  95. package/js/utils/className/getTypographyClassName.min.js +0 -1
  96. package/js/utils/className/getTypographyClassName.test.min.js +0 -1
  97. package/js/utils/className/handleBasicClasses.min.js +0 -1
  98. package/js/utils/className/handleBasicClasses.test.min.js +0 -1
  99. package/js/utils/className/index.min.js +0 -1
  100. package/js/utils/className/resolveColorWithVariants.min.js +0 -1
  101. package/js/utils/className/resolveColorWithVariants.test.min.js +0 -1
  102. package/js/utils/index.min.js +0 -1
  103. package/lumx.min.css +0 -1
@@ -1,22 +1,57 @@
1
- 'use strict';
1
+ import { getBasicClass } from './getBasicClass.js';
2
+ import '../string/kebabCase.js';
2
3
 
3
- var js_utils_className_getBasicClass = require('./getBasicClass.js');
4
- require('lodash/isBoolean');
5
- require('lodash/kebabCase');
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
- describe(js_utils_className_getBasicClass.getBasicClass, () => {
8
- it('should return correct basic CSS class for different types and values', () => {
9
- // Test cases with different inputs
10
- expect(js_utils_className_getBasicClass.getBasicClass({ prefix: 'test', type: 'color', value: 'primary' })).toBe('test--color-primary');
11
- expect(js_utils_className_getBasicClass.getBasicClass({ prefix: 'test', type: 'variant', value: 'button' })).toBe('test--variant-button');
12
- expect(js_utils_className_getBasicClass.getBasicClass({ prefix: 'test', type: 'isDark', value: true })).toBe('test--is-dark');
13
- expect(js_utils_className_getBasicClass.getBasicClass({ prefix: 'test', type: 'dark', value: true })).toBe('test--is-dark');
14
- expect(js_utils_className_getBasicClass.getBasicClass({ prefix: 'test', type: 'hasDark', value: true })).toBe('test--has-dark');
15
- expect(js_utils_className_getBasicClass.getBasicClass({ prefix: 'test', type: 'isActive', value: false })).toBe('');
16
- // Additional tests for boolean types
17
- expect(js_utils_className_getBasicClass.getBasicClass({ prefix: 'test', type: 'hasBorder', value: true })).toBe('test--has-border');
18
- expect(js_utils_className_getBasicClass.getBasicClass({ prefix: 'test', type: 'isVisible', value: false })).toBe('');
19
- // Tests for undefined
20
- expect(js_utils_className_getBasicClass.getBasicClass({ prefix: 'test', type: 'variant', value: undefined })).toBe('test--variant-undefined');
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 isBoolean from 'lodash/isBoolean';
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 (isBoolean(value)) {
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
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
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
- const formattedClassName = `${js_constants_index.CSS_PREFIX}-${kebabCase__default["default"](componentName)}`;
27
- if (subComponent) {
28
- return formattedClassName.replace(LAST_PART_CLASSNAME, '$1__$2');
29
- }
30
- return formattedClassName;
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
- exports.getRootClassName = getRootClassName;
26
+ export { getRootClassName };
@@ -1,15 +1,13 @@
1
- 'use strict';
1
+ import { getRootClassName } from './getRootClassName.js';
2
+ import '../../constants/index.js';
3
+ import '../../constants/keycodes.js';
4
+ import '../string/kebabCase.js';
2
5
 
3
- var js_utils_className_getRootClassName = require('./getRootClassName.js');
4
- require('lodash/kebabCase');
5
- require('../../constants/index.js');
6
- require('../../constants/keycodes.js');
7
-
8
- describe(js_utils_className_getRootClassName.getRootClassName, () => {
9
- it('should transform the component name into a lumx class', () => {
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,6 +1,5 @@
1
- import kebabCase from 'lodash/kebabCase';
2
-
3
1
  import { CSS_PREFIX } from '../../constants';
2
+ import { kebabCase } from '../string/kebabCase';
4
3
 
5
4
  // See https://regex101.com/r/YjS1uI/3
6
5
  const LAST_PART_CLASSNAME = /^(.*)-(.+)$/gi;
@@ -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 = (typography) => {
10
- return `lumx-typography-${typography}`;
5
+ const getTypographyClassName = typography => {
6
+ return `lumx-typography-${typography}`;
11
7
  };
12
8
 
13
- exports.getTypographyClassName = getTypographyClassName;
9
+ export { getTypographyClassName };
@@ -1,9 +1,7 @@
1
- 'use strict';
1
+ import { getTypographyClassName } from './getTypographyClassName.js';
2
2
 
3
- var js_utils_className_getTypographyClassName = require('./getTypographyClassName.js');
4
-
5
- describe(js_utils_className_getTypographyClassName.getTypographyClassName, () => {
6
- it('should generate lumx typography class', () => {
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
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
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 = (value) => {
24
- if (typeof value === 'number') {
25
- return value === 0;
26
- }
27
- return isEmpty__default["default"](value);
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({ prefix, ...props }) {
41
- const otherClasses = {};
42
- if (!isEmpty__default["default"](props)) {
43
- Object.keys(props).forEach((prop) => {
44
- otherClasses[js_utils_className_getBasicClass.getBasicClass({ prefix, type: prop, value: props[prop] })] = isBoolean__default["default"](props[prop])
45
- ? props[prop]
46
- : !_isEmpty(props[prop]);
47
- });
48
- }
49
- return classNames__default["default"](prefix, otherClasses);
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
- exports.handleBasicClasses = handleBasicClasses;
47
+ export { handleBasicClasses };
@@ -1,35 +1,32 @@
1
- 'use strict';
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
- var js_utils_className_handleBasicClasses = require('./handleBasicClasses.js');
4
- require('classnames');
5
- require('lodash/isBoolean');
6
- require('lodash/isEmpty');
7
- require('./getBasicClass.js');
8
- require('lodash/kebabCase');
9
-
10
- describe(js_utils_className_handleBasicClasses.handleBasicClasses, () => {
11
- it('should return correct combined CSS classes based on props', () => {
12
- const className = js_utils_className_handleBasicClasses.handleBasicClasses({
13
- prefix: 'test',
14
- // Undefined
15
- undefined,
16
- // Null
17
- null: null,
18
- // Empty string
19
- emptyString: '',
20
- // Empty array
21
- emptyArray: [],
22
- // Empty object
23
- emptyObject: {},
24
- // String
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 isBoolean from 'lodash/isBoolean';
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] })] = isBoolean(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
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
- var js_utils_className_handleBasicClasses = require('./handleBasicClasses.js');
6
- var js_utils_className_getBasicClass = require('./getBasicClass.js');
7
- var js_utils_className_getRootClassName = require('./getRootClassName.js');
8
- var js_utils_className_getTypographyClassName = require('./getTypographyClassName.js');
9
- var js_utils_className_fontColorClass = require('./fontColorClass.js');
10
- var js_utils_className_resolveColorWithVariants = require('./resolveColorWithVariants.js');
11
- require('classnames');
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
- if (!colorWithVariants)
8
- return [undefined, colorVariant];
9
- const [color, baseColorVariant] = colorWithVariants.split('-');
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
- exports.resolveColorWithVariants = resolveColorWithVariants;
8
+ export { resolveColorWithVariants };
@@ -1,30 +1,28 @@
1
- 'use strict';
1
+ import { resolveColorWithVariants } from './resolveColorWithVariants.js';
2
2
 
3
- var js_utils_className_resolveColorWithVariants = require('./resolveColorWithVariants.js');
4
-
5
- describe(js_utils_className_resolveColorWithVariants.resolveColorWithVariants, () => {
6
- it('should handle undefined color', () => {
7
- const result = js_utils_className_resolveColorWithVariants.resolveColorWithVariants(undefined);
8
- expect(result).toEqual([undefined, undefined]);
9
- });
10
- it('should handle undefined color with variant', () => {
11
- const result = js_utils_className_resolveColorWithVariants.resolveColorWithVariants(undefined, 'L2');
12
- expect(result).toEqual([undefined, 'L2']);
13
- });
14
- it('should handle color with undefined variant', () => {
15
- const result = js_utils_className_resolveColorWithVariants.resolveColorWithVariants('primary');
16
- expect(result).toEqual(['primary', undefined]);
17
- });
18
- it('should handle color & variant separated', () => {
19
- const result = js_utils_className_resolveColorWithVariants.resolveColorWithVariants('primary', 'L2');
20
- expect(result).toEqual(['primary', 'L2']);
21
- });
22
- it('should handle color with variant all in one', () => {
23
- const result = js_utils_className_resolveColorWithVariants.resolveColorWithVariants('primary-L2');
24
- expect(result).toEqual(['primary', 'L2']);
25
- });
26
- it('should override color variant with the given color variant', () => {
27
- const result = js_utils_className_resolveColorWithVariants.resolveColorWithVariants('primary-L2', 'D2');
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,4 @@
1
+ /** Cast a value into an array if needed */
2
+ const castArray = arrayOrElement => Array.isArray(arrayOrElement) ? arrayOrElement : [arrayOrElement];
3
+
4
+ export { castArray };
@@ -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,3 @@
1
+ /** Cast a value into an array if needed */
2
+ export const castArray = <T>(arrayOrElement: T[] | T) =>
3
+ Array.isArray(arrayOrElement) ? arrayOrElement : [arrayOrElement];
@@ -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
+ }
@@ -0,0 +1,4 @@
1
+ /** Check if object or array is empty (true on falsy values) */
2
+ const isEmpty = obj => !obj || Object.entries(obj).length === 0;
3
+
4
+ export { isEmpty };