@lumx/core 3.20.1-alpha.4 → 3.20.1-alpha.40

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 (130) hide show
  1. package/CONTRIBUTING.md +1 -5
  2. package/js/constants/design-tokens.d.ts +5421 -0
  3. package/js/constants/design-tokens.js +1 -5
  4. package/js/constants/index.d.ts +232 -0
  5. package/js/constants/index.js +2 -35
  6. package/js/constants/keycodes.d.ts +36 -0
  7. package/js/constants/keycodes.js +1 -13
  8. package/js/custom-colors.d.ts +25 -0
  9. package/js/custom-colors.js +1 -6
  10. package/js/types/Callback.js +0 -1
  11. package/js/types/Falsy.js +0 -1
  12. package/js/types/{GenericProps.ts → GenericProps.d.ts} +0 -1
  13. package/js/types/GenericProps.js +0 -1
  14. package/js/types/HasAriaLabelOrLabelledBy.d.ts +17 -0
  15. package/js/types/HasAriaLabelOrLabelledBy.js +0 -1
  16. package/js/types/HasClassName.js +0 -1
  17. package/js/types/HasCloseMode.js +0 -1
  18. package/js/types/{HasTheme.ts → HasTheme.d.ts} +0 -1
  19. package/js/types/HasTheme.js +0 -1
  20. package/js/types/HeadingElement.js +0 -1
  21. package/js/types/Point.d.ts +7 -0
  22. package/js/types/Point.js +0 -1
  23. package/js/types/Predicate.js +0 -1
  24. package/js/types/RectSize.d.ts +7 -0
  25. package/js/types/RectSize.js +0 -1
  26. package/js/types/{TextElement.ts → TextElement.d.ts} +0 -1
  27. package/js/types/TextElement.js +0 -1
  28. package/js/types/ValueOf.js +0 -1
  29. package/js/types/index.js +0 -1
  30. package/js/utils/className/fontColorClass.d.ts +6 -0
  31. package/js/utils/className/fontColorClass.js +4 -9
  32. package/js/utils/className/getBasicClass.d.ts +13 -0
  33. package/js/utils/className/getBasicClass.js +7 -16
  34. package/js/utils/className/{getRootClassName.ts → getRootClassName.d.ts} +1 -15
  35. package/js/utils/className/getRootClassName.js +4 -13
  36. package/js/utils/className/{getTypographyClassName.ts → getTypographyClassName.d.ts} +1 -4
  37. package/js/utils/className/getTypographyClassName.js +1 -5
  38. package/js/utils/className/handleBasicClasses.d.ts +15 -0
  39. package/js/utils/className/handleBasicClasses.js +9 -20
  40. package/js/utils/className/index.js +6 -25
  41. package/js/utils/className/resolveColorWithVariants.d.ts +3 -0
  42. package/js/utils/className/resolveColorWithVariants.js +1 -5
  43. package/js/utils/events/index.d.ts +2 -0
  44. package/js/utils/events/index.js +2 -0
  45. package/js/utils/events/keyboard.d.ts +24 -0
  46. package/js/utils/events/keyboard.js +44 -0
  47. package/js/utils/events/swipe.d.ts +6 -0
  48. package/js/utils/events/swipe.js +79 -0
  49. package/js/utils/index.d.ts +2 -0
  50. package/js/utils/index.js +8 -223
  51. package/lumx.css +7 -6
  52. package/package.json +10 -14
  53. package/scss/components/list/_index.scss +10 -4
  54. package/js/components/Icon/Stories.js +0 -40
  55. package/js/components/Icon/Tests.tsx +0 -120
  56. package/js/components/Icon/index.tsx +0 -134
  57. package/js/constants/design-tokens.min.js +0 -1
  58. package/js/constants/design-tokens.ts +0 -2324
  59. package/js/constants/index.min.js +0 -1
  60. package/js/constants/index.ts +0 -231
  61. package/js/constants/keycodes.min.js +0 -1
  62. package/js/constants/keycodes.ts +0 -44
  63. package/js/custom-colors.min.js +0 -1
  64. package/js/custom-colors.ts +0 -56
  65. package/js/date-picker.js +0 -71
  66. package/js/date-picker.min.js +0 -1
  67. package/js/date-picker.ts +0 -77
  68. package/js/types/Callback.min.js +0 -1
  69. package/js/types/Falsy.min.js +0 -1
  70. package/js/types/GenericProps.min.js +0 -1
  71. package/js/types/HasAriaLabelOrLabelledBy.min.js +0 -1
  72. package/js/types/HasAriaLabelOrLabelledBy.ts +0 -19
  73. package/js/types/HasClassName.min.js +0 -1
  74. package/js/types/HasCloseMode.min.js +0 -1
  75. package/js/types/HasTheme.min.js +0 -1
  76. package/js/types/HeadingElement.min.js +0 -1
  77. package/js/types/Point.min.js +0 -1
  78. package/js/types/Point.ts +0 -4
  79. package/js/types/Predicate.min.js +0 -1
  80. package/js/types/RectSize.min.js +0 -1
  81. package/js/types/RectSize.ts +0 -4
  82. package/js/types/TextElement.min.js +0 -1
  83. package/js/types/ValueOf.min.js +0 -1
  84. package/js/types/index.min.js +0 -1
  85. package/js/utils/className/fontColorClass.min.js +0 -1
  86. package/js/utils/className/fontColorClass.test.js +0 -18
  87. package/js/utils/className/fontColorClass.test.min.js +0 -1
  88. package/js/utils/className/fontColorClass.test.ts +0 -15
  89. package/js/utils/className/fontColorClass.ts +0 -12
  90. package/js/utils/className/getBasicClass.min.js +0 -1
  91. package/js/utils/className/getBasicClass.test.js +0 -22
  92. package/js/utils/className/getBasicClass.test.min.js +0 -1
  93. package/js/utils/className/getBasicClass.test.ts +0 -20
  94. package/js/utils/className/getBasicClass.ts +0 -36
  95. package/js/utils/className/getRootClassName.min.js +0 -1
  96. package/js/utils/className/getRootClassName.test.js +0 -15
  97. package/js/utils/className/getRootClassName.test.min.js +0 -1
  98. package/js/utils/className/getRootClassName.test.ts +0 -11
  99. package/js/utils/className/getTypographyClassName.min.js +0 -1
  100. package/js/utils/className/getTypographyClassName.test.js +0 -9
  101. package/js/utils/className/getTypographyClassName.test.min.js +0 -1
  102. package/js/utils/className/getTypographyClassName.test.ts +0 -7
  103. package/js/utils/className/handleBasicClasses.min.js +0 -1
  104. package/js/utils/className/handleBasicClasses.test.js +0 -35
  105. package/js/utils/className/handleBasicClasses.test.min.js +0 -1
  106. package/js/utils/className/handleBasicClasses.test.ts +0 -28
  107. package/js/utils/className/handleBasicClasses.ts +0 -44
  108. package/js/utils/className/index.min.js +0 -1
  109. package/js/utils/className/resolveColorWithVariants.min.js +0 -1
  110. package/js/utils/className/resolveColorWithVariants.test.js +0 -30
  111. package/js/utils/className/resolveColorWithVariants.test.min.js +0 -1
  112. package/js/utils/className/resolveColorWithVariants.test.ts +0 -33
  113. package/js/utils/className/resolveColorWithVariants.ts +0 -11
  114. package/js/utils/index.min.js +0 -1
  115. package/js/utils/index.ts +0 -221
  116. package/lumx.min.css +0 -1
  117. package/stories/controls/color.ts +0 -7
  118. package/stories/controls/icons.ts +0 -126
  119. package/stories/controls/selectArgType.ts +0 -8
  120. package/stories/controls/withUndefined.ts +0 -1
  121. package/testing/utils/queries.ts +0 -19
  122. /package/js/types/{Callback.ts → Callback.d.ts} +0 -0
  123. /package/js/types/{Falsy.ts → Falsy.d.ts} +0 -0
  124. /package/js/types/{HasClassName.ts → HasClassName.d.ts} +0 -0
  125. /package/js/types/{HasCloseMode.ts → HasCloseMode.d.ts} +0 -0
  126. /package/js/types/{HeadingElement.ts → HeadingElement.d.ts} +0 -0
  127. /package/js/types/{Predicate.ts → Predicate.d.ts} +0 -0
  128. /package/js/types/{ValueOf.ts → ValueOf.d.ts} +0 -0
  129. /package/js/types/{index.ts → index.d.ts} +0 -0
  130. /package/js/utils/className/{index.ts → index.d.ts} +0 -0
@@ -1 +0,0 @@
1
- "use strict";var e=require("./getBasicClass.min.js");require("lodash/isBoolean"),require("lodash/kebabCase"),describe(e.getBasicClass,()=>{it("should return correct basic CSS class for different types and values",()=>{expect(e.getBasicClass({prefix:"test",type:"color",value:"primary"})).toBe("test--color-primary"),expect(e.getBasicClass({prefix:"test",type:"variant",value:"button"})).toBe("test--variant-button"),expect(e.getBasicClass({prefix:"test",type:"isDark",value:!0})).toBe("test--is-dark"),expect(e.getBasicClass({prefix:"test",type:"dark",value:!0})).toBe("test--is-dark"),expect(e.getBasicClass({prefix:"test",type:"hasDark",value:!0})).toBe("test--has-dark"),expect(e.getBasicClass({prefix:"test",type:"isActive",value:!1})).toBe(""),expect(e.getBasicClass({prefix:"test",type:"hasBorder",value:!0})).toBe("test--has-border"),expect(e.getBasicClass({prefix:"test",type:"isVisible",value:!1})).toBe(""),expect(e.getBasicClass({prefix:"test",type:"variant",value:void 0})).toBe("test--variant-undefined")})});
@@ -1,20 +0,0 @@
1
- import { getBasicClass } from './getBasicClass';
2
-
3
- describe(getBasicClass, () => {
4
- it('should return correct basic CSS class for different types and values', () => {
5
- // Test cases with different inputs
6
- expect(getBasicClass({ prefix: 'test', type: 'color', value: 'primary' })).toBe('test--color-primary');
7
- expect(getBasicClass({ prefix: 'test', type: 'variant', value: 'button' })).toBe('test--variant-button');
8
- expect(getBasicClass({ prefix: 'test', type: 'isDark', value: true })).toBe('test--is-dark');
9
- expect(getBasicClass({ prefix: 'test', type: 'dark', value: true })).toBe('test--is-dark');
10
- expect(getBasicClass({ prefix: 'test', type: 'hasDark', value: true })).toBe('test--has-dark');
11
- expect(getBasicClass({ prefix: 'test', type: 'isActive', value: false })).toBe('');
12
-
13
- // Additional tests for boolean types
14
- expect(getBasicClass({ prefix: 'test', type: 'hasBorder', value: true })).toBe('test--has-border');
15
- expect(getBasicClass({ prefix: 'test', type: 'isVisible', value: false })).toBe('');
16
-
17
- // Tests for undefined
18
- expect(getBasicClass({ prefix: 'test', type: 'variant', value: undefined })).toBe('test--variant-undefined');
19
- });
20
- });
@@ -1,36 +0,0 @@
1
- import isBoolean from 'lodash/isBoolean';
2
- import kebabCase from 'lodash/kebabCase';
3
-
4
- /**
5
- * Get the basic CSS class for the given type.
6
- *
7
- * @param prefix The class name prefix for the generated CSS class.
8
- * @param type The type of CSS class we want to generate (e.g.: 'color', 'variant', ...).
9
- * @param value The value of the type of the CSS class (e.g.: 'primary', 'button', ...).
10
- * @return The basic CSS class.
11
- */
12
- export function getBasicClass({
13
- prefix,
14
- type,
15
- value,
16
- }: {
17
- prefix: string;
18
- type: string;
19
- value: string | number | boolean | undefined;
20
- }): string {
21
- if (isBoolean(value)) {
22
- if (!value) {
23
- // False value should not return a class.
24
- return '';
25
- }
26
- const booleanPrefixes = ['has', 'is'];
27
-
28
- if (booleanPrefixes.some((booleanPrefix) => type.toString().startsWith(booleanPrefix))) {
29
- return `${prefix}--${kebabCase(type)}`;
30
- }
31
-
32
- return `${prefix}--is-${kebabCase(type)}`;
33
- }
34
-
35
- return `${prefix}--${kebabCase(type)}-${value}`;
36
- }
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("lodash/kebabCase"),t=require("../../constants/index.min.js");function r(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("../../constants/keycodes.min.js");var s=r(e);const n=/^(.*)-(.+)$/gi;exports.getRootClassName=function(e,r){const o=`${t.CSS_PREFIX}-${s.default(e)}`;return r?o.replace(n,"$1__$2"):o};
@@ -1,15 +0,0 @@
1
- 'use strict';
2
-
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
- });
15
- });
@@ -1 +0,0 @@
1
- "use strict";var e=require("./getRootClassName.min.js");require("lodash/kebabCase"),require("../../constants/index.min.js"),require("../../constants/keycodes.min.js"),describe(e.getRootClassName,()=>{it("should transform the component name into a lumx class",()=>{expect(e.getRootClassName("Table")).toBe("lumx-table")}),it("should transform the sub component name into a lumx class",()=>{expect(e.getRootClassName("TableBody",!0)).toBe("lumx-table__body")})});
@@ -1,11 +0,0 @@
1
- import { getRootClassName } from './getRootClassName';
2
-
3
- describe(getRootClassName, () => {
4
- it('should transform the component name into a lumx class', () => {
5
- expect(getRootClassName('Table')).toBe('lumx-table');
6
- });
7
-
8
- it('should transform the sub component name into a lumx class', () => {
9
- expect(getRootClassName('TableBody', true)).toBe('lumx-table__body');
10
- });
11
- });
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});exports.getTypographyClassName=e=>`lumx-typography-${e}`;
@@ -1,9 +0,0 @@
1
- 'use strict';
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
- });
9
- });
@@ -1 +0,0 @@
1
- "use strict";var e=require("./getTypographyClassName.min.js");describe(e.getTypographyClassName,()=>{it("should generate lumx typography class",()=>{expect(e.getTypographyClassName("title")).toBe("lumx-typography-title")})});
@@ -1,7 +0,0 @@
1
- import { getTypographyClassName } from './getTypographyClassName';
2
-
3
- describe(getTypographyClassName, () => {
4
- it('should generate lumx typography class', () => {
5
- expect(getTypographyClassName('title')).toBe('lumx-typography-title');
6
- });
7
- });
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("classnames"),a=require("lodash/isBoolean"),s=require("lodash/isEmpty"),r=require("./getBasicClass.min.js");function t(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("lodash/kebabCase");var u=t(e),i=t(a),l=t(s);exports.handleBasicClasses=function({prefix:e,...a}){const s={};return l.default(a)||Object.keys(a).forEach(t=>{var u;s[r.getBasicClass({prefix:e,type:t,value:a[t]})]=i.default(a[t])?a[t]:!("number"==typeof(u=a[t])?0===u:l.default(u))}),u.default(e,s)};
@@ -1,35 +0,0 @@
1
- 'use strict';
2
-
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');
34
- });
35
- });
@@ -1 +0,0 @@
1
- "use strict";var e=require("./handleBasicClasses.min.js");require("classnames"),require("lodash/isBoolean"),require("lodash/isEmpty"),require("./getBasicClass.min.js"),require("lodash/kebabCase"),describe(e.handleBasicClasses,()=>{it("should return correct combined CSS classes based on props",()=>{const s=e.handleBasicClasses({prefix:"test",undefined:void 0,null:null,emptyString:"",emptyArray:[],emptyObject:{},color:"red",isDisabled:!1,visible:!0,hasButton:!0});expect(s).toBe("test test--color-red test--is-visible test--has-button")})});
@@ -1,28 +0,0 @@
1
- import { handleBasicClasses } from './handleBasicClasses';
2
-
3
- describe(handleBasicClasses, () => {
4
- it('should return correct combined CSS classes based on props', () => {
5
- const className = handleBasicClasses({
6
- prefix: 'test',
7
- // Undefined
8
- undefined,
9
- // Null
10
- null: null,
11
- // Empty string
12
- emptyString: '',
13
- // Empty array
14
- emptyArray: [],
15
- // Empty object
16
- emptyObject: {},
17
- // String
18
- color: 'red',
19
- // False property
20
- isDisabled: false,
21
- // Boolean without a prefix (is or has)
22
- visible: true,
23
- // Has prefix
24
- hasButton: true,
25
- });
26
- expect(className).toBe('test test--color-red test--is-visible test--has-button');
27
- });
28
- });
@@ -1,44 +0,0 @@
1
- import classNames from 'classnames';
2
-
3
- import isBoolean from 'lodash/isBoolean';
4
- import isEmpty from 'lodash/isEmpty';
5
-
6
- import { getBasicClass } from './getBasicClass';
7
-
8
- /**
9
- * Enhance isEmpty method to also works with numbers.
10
- *
11
- * @param value The value to check.
12
- * @return Whether the input value is empty or != 0.
13
- */
14
- const _isEmpty = (value: any) => {
15
- if (typeof value === 'number') {
16
- return value === 0;
17
- }
18
-
19
- return isEmpty(value);
20
- };
21
-
22
- /**
23
- * Return all basic LumX CSS classes which are available for every components.
24
- *
25
- * @see {@link /src/components/index.d.ts} for the possible values of each parameter.
26
- *
27
- * @param prefix The class name prefix for the generated CSS class.
28
- * @param props All the other props you want to generate a class.
29
- * The rule of thumb: the key is the name of the prop in the class, the value a string that will
30
- * be used in the classname to represent the value of the given prop.
31
- * @return All LumX basic CSS classes.
32
- */
33
- export function handleBasicClasses({ prefix, ...props }: { prefix: string; [prop: string]: any }): string {
34
- const otherClasses: any = {};
35
- if (!isEmpty(props)) {
36
- Object.keys(props).forEach((prop) => {
37
- otherClasses[getBasicClass({ prefix, type: prop, value: props[prop] })] = isBoolean(props[prop])
38
- ? props[prop]
39
- : !_isEmpty(props[prop]);
40
- });
41
- }
42
-
43
- return classNames(prefix, otherClasses);
44
- }
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var s=require("./handleBasicClasses.min.js"),e=require("./getBasicClass.min.js"),a=require("./getRootClassName.min.js"),r=require("./getTypographyClassName.min.js"),o=require("./fontColorClass.min.js"),i=require("./resolveColorWithVariants.min.js");require("classnames"),require("lodash/isBoolean"),require("lodash/isEmpty"),require("lodash/kebabCase"),require("../../constants/index.min.js"),require("../../constants/keycodes.min.js"),exports.handleBasicClasses=s.handleBasicClasses,exports.getBasicClass=e.getBasicClass,exports.getRootClassName=a.getRootClassName,exports.getTypographyClassName=r.getTypographyClassName,exports.fontColorClass=o.fontColorClass,exports.resolveColorWithVariants=i.resolveColorWithVariants;
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0}),exports.resolveColorWithVariants=function(e,t){if(!e)return[void 0,t];const[r,o]=e.split("-");return[r,t||o]};
@@ -1,30 +0,0 @@
1
- 'use strict';
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
- });
30
- });
@@ -1 +0,0 @@
1
- "use strict";var o=require("./resolveColorWithVariants.min.js");describe(o.resolveColorWithVariants,()=>{it("should handle undefined color",()=>{const r=o.resolveColorWithVariants(void 0);expect(r).toEqual([void 0,void 0])}),it("should handle undefined color with variant",()=>{const r=o.resolveColorWithVariants(void 0,"L2");expect(r).toEqual([void 0,"L2"])}),it("should handle color with undefined variant",()=>{const r=o.resolveColorWithVariants("primary");expect(r).toEqual(["primary",void 0])}),it("should handle color & variant separated",()=>{const r=o.resolveColorWithVariants("primary","L2");expect(r).toEqual(["primary","L2"])}),it("should handle color with variant all in one",()=>{const r=o.resolveColorWithVariants("primary-L2");expect(r).toEqual(["primary","L2"])}),it("should override color variant with the given color variant",()=>{const r=o.resolveColorWithVariants("primary-L2","D2");expect(r).toEqual(["primary","D2"])})});
@@ -1,33 +0,0 @@
1
- import { resolveColorWithVariants } from './resolveColorWithVariants';
2
-
3
- describe(resolveColorWithVariants, () => {
4
- it('should handle undefined color', () => {
5
- const result = resolveColorWithVariants(undefined);
6
- expect(result).toEqual([undefined, undefined]);
7
- });
8
-
9
- it('should handle undefined color with variant', () => {
10
- const result = resolveColorWithVariants(undefined, 'L2');
11
- expect(result).toEqual([undefined, 'L2']);
12
- });
13
-
14
- it('should handle color with undefined variant', () => {
15
- const result = resolveColorWithVariants('primary');
16
- expect(result).toEqual(['primary', undefined]);
17
- });
18
-
19
- it('should handle color & variant separated', () => {
20
- const result = resolveColorWithVariants('primary', 'L2');
21
- expect(result).toEqual(['primary', 'L2']);
22
- });
23
-
24
- it('should handle color with variant all in one', () => {
25
- const result = resolveColorWithVariants('primary-L2');
26
- expect(result).toEqual(['primary', 'L2']);
27
- });
28
-
29
- it('should override color variant with the given color variant', () => {
30
- const result = resolveColorWithVariants('primary-L2', 'D2');
31
- expect(result).toEqual(['primary', 'D2']);
32
- });
33
- });
@@ -1,11 +0,0 @@
1
- import { ColorPalette, ColorVariant, ColorWithVariants } from '../../constants';
2
-
3
- /** Resolve color & color variant from a `ColorWithVariants` and optionally a `ColorVariant`. */
4
- export function resolveColorWithVariants(
5
- colorWithVariants?: ColorWithVariants,
6
- colorVariant?: ColorVariant,
7
- ): [color?: ColorPalette, colorVariant?: ColorVariant] {
8
- if (!colorWithVariants) return [undefined, colorVariant];
9
- const [color, baseColorVariant] = colorWithVariants.split('-');
10
- return [color as ColorPalette, (colorVariant || baseColorVariant) as ColorVariant];
11
- }
@@ -1 +0,0 @@
1
- "use strict";Object.defineProperty(exports,"__esModule",{value:!0});var e=require("lodash/noop"),t=require("./className/handleBasicClasses.min.js"),s=require("./className/getBasicClass.min.js"),r=require("./className/getRootClassName.min.js"),a=require("./className/getTypographyClassName.min.js"),n=require("./className/fontColorClass.min.js"),o=require("./className/resolveColorWithVariants.min.js");function i(e){return e&&"object"==typeof e&&"default"in e?e:{default:e}}require("classnames"),require("lodash/isBoolean"),require("lodash/isEmpty"),require("lodash/kebabCase"),require("../constants/index.min.js"),require("../constants/keycodes.min.js");var u=i(e);exports.handleBasicClasses=t.handleBasicClasses,exports.getBasicClass=s.getBasicClass,exports.getRootClassName=r.getRootClassName,exports.getTypographyClassName=a.getTypographyClassName,exports.fontColorClass=n.fontColorClass,exports.resolveColorWithVariants=o.resolveColorWithVariants,exports.detectHorizontalSwipe=function(e,t){let s,r,a,n,o;const i=e=>{const[t]=Array.from(e.changedTouches);s=t.pageX,r=t.pageY,n=(new Date).getTime(),o=!1},c=e=>{if(o)return;if(a=(new Date).getTime()-n,a>300)return;const[i]=Array.from(e.changedTouches),u=i.pageX-s,c=i.pageY-r;if(!(Math.abs(u)>=150&&Math.abs(c)<=150))return;t(u<0?"left":"right"),o=!0},l=!!function(){let e=!1;try{const t=Object.defineProperty({},"passive",{get(){e=!0}});window.addEventListener("testPassiveEventSupport",u.default,t),window.removeEventListener("testPassiveEventSupport",u.default,t)}catch(e){}return e}()&&{passive:!0};return e.addEventListener("touchstart",i,l),e.addEventListener("touchmove",c,l),()=>{e.removeEventListener("touchstart",i,l),e.removeEventListener("touchmove",c,l)}},exports.detectSwipe=function(e,t=u.default){let s,r,a,n,o,i,c;const l=e=>{const[t]=Array.from(e.changedTouches);o="none",a=t.pageX,n=t.pageY,c=(new Date).getTime(),e.preventDefault()},p=e=>{e.preventDefault()},d=e=>{const[u]=Array.from(e.changedTouches);s=u.pageX-a,r=u.pageY-n,i=(new Date).getTime()-c,i<=300&&(Math.abs(s)>=150&&Math.abs(r)<=100?o=s<0?"left":"right":Math.abs(r)>=150&&Math.abs(s)<=100&&(o=r<0?"up":"down")),t(o),e.preventDefault()};return e.addEventListener("touchstart",l,!1),e.addEventListener("touchmove",p,!1),e.addEventListener("touchend",d,!1),()=>{e.removeEventListener("touchstart",l,!1),e.removeEventListener("touchmove",p,!1),e.removeEventListener("touchend",d,!1)}},exports.onButtonPressed=function(e){return t=>{"Enter"!==t.key&&" "!==t.key||e(t)}},exports.onEnterPressed=function(e){return t=>{"Enter"===t.key&&e(t)}},exports.onEscapePressed=function(e){return t=>{"Escape"===t.key&&e(t)}};
package/js/utils/index.ts DELETED
@@ -1,221 +0,0 @@
1
- import type { KeyboardEvent as ReactKeyboardEvent } from 'react';
2
-
3
- import noop from 'lodash/noop';
4
-
5
- export * from './className';
6
-
7
- type KeyboardEventHandler<E extends KeyboardEvent | ReactKeyboardEvent> = (event: E) => void;
8
-
9
- /**
10
- * Make sure the pressed key is the enter key before calling the callback.
11
- *
12
- * @param handler The handler to call on enter/return press.
13
- * @return The decorated function.
14
- */
15
- export function onEnterPressed<E extends KeyboardEvent | ReactKeyboardEvent>(
16
- handler: KeyboardEventHandler<E>,
17
- ): KeyboardEventHandler<E> {
18
- return (evt) => {
19
- if (evt.key !== 'Enter') {
20
- return;
21
- }
22
- handler(evt);
23
- };
24
- }
25
-
26
- /**
27
- * Make sure the pressed key is the escape key before calling the callback.
28
- *
29
- * @param handler The handler to call on enter/return press.
30
- * @return The decorated function.
31
- */
32
- export function onEscapePressed<E extends KeyboardEvent | ReactKeyboardEvent>(
33
- handler: KeyboardEventHandler<E>,
34
- ): KeyboardEventHandler<E> {
35
- return (evt) => {
36
- if (evt.key !== 'Escape') {
37
- return;
38
- }
39
- handler(evt);
40
- };
41
- }
42
-
43
- /**
44
- * Handle button key pressed (Enter + Space).
45
- *
46
- * @param handler The handler to call.
47
- * @return The decorated function.
48
- */
49
- export function onButtonPressed<E extends KeyboardEvent | ReactKeyboardEvent>(
50
- handler: KeyboardEventHandler<E>,
51
- ): KeyboardEventHandler<E> {
52
- return (evt) => {
53
- if (evt.key !== 'Enter' && evt.key !== ' ') {
54
- return;
55
- }
56
- handler(evt);
57
- };
58
- }
59
-
60
- declare type SwipeDirection = 'none' | 'up' | 'down' | 'left' | 'right';
61
-
62
- /**
63
- * Detects swipe direction.
64
- * Credits: http://javascriptkit.com/javatutors/touchevents2.shtml.
65
- *
66
- * @deprecated use `detectHorizontalSwipe` instead if possible (better performance and does not block scroll)
67
- * @param touchSurface Element that will hold touch events.
68
- * @param handleSwipe Callback function.
69
- * @return Function to remove listeners.
70
- */
71
- export function detectSwipe(touchSurface: Element, handleSwipe: (direction: SwipeDirection) => void = noop) {
72
- let distX: number;
73
- let distY: number;
74
- let startX: number;
75
- let startY: number;
76
- let direction: SwipeDirection;
77
- // Required min distance traveled to be considered swipe.
78
- const threshold = 150;
79
- // Maximum distance allowed at the same time in perpendicular direction.
80
- const restraint = 100;
81
- // Maximum time allowed to travel that distance.
82
- const allowedTime = 300;
83
- let elapsedTime: number;
84
- let startTime: number;
85
-
86
- const onTouchStart = (evt: Event) => {
87
- const [touch] = Array.from((evt as TouchEvent).changedTouches);
88
- direction = 'none';
89
- // Const dist = 0;
90
- startX = touch.pageX;
91
- startY = touch.pageY;
92
- // Record time when finger first makes contact with surface.
93
- startTime = new Date().getTime();
94
- evt.preventDefault();
95
- };
96
-
97
- const onTouchMove = (evt: Event) => {
98
- // Prevent scrolling when inside DIV.
99
- evt.preventDefault();
100
- };
101
-
102
- const onTouchEnd = (evt: Event) => {
103
- const [touch] = Array.from((evt as TouchEvent).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
- } else if (Math.abs(distY) >= threshold && Math.abs(distX) <= restraint) {
117
- // 2nd condition for vertical swipe met.
118
- // If dist traveled is negative, it indicates up swipe.
119
- direction = distY < 0 ? 'up' : 'down';
120
- }
121
- }
122
- handleSwipe(direction);
123
- evt.preventDefault();
124
- };
125
-
126
- touchSurface.addEventListener('touchstart', onTouchStart, false);
127
- touchSurface.addEventListener('touchmove', onTouchMove, false);
128
- touchSurface.addEventListener('touchend', onTouchEnd, false);
129
-
130
- return () => {
131
- touchSurface.removeEventListener('touchstart', onTouchStart, false);
132
- touchSurface.removeEventListener('touchmove', onTouchMove, false);
133
- touchSurface.removeEventListener('touchend', onTouchEnd, false);
134
- };
135
- }
136
-
137
- /**
138
- * Checks whether or not the browser support passive events.
139
- * @see https://github.com/Modernizr/Modernizr/blob/6d56d814b9682843313b16060adb25a58d83a317/feature-detects/dom/passiveeventlisteners.js
140
- */
141
- function isPassiveEventAvailable() {
142
- let supportsPassiveOption = false;
143
- try {
144
- const opts = Object.defineProperty({}, 'passive', {
145
- get() {
146
- supportsPassiveOption = true;
147
- },
148
- });
149
- window.addEventListener('testPassiveEventSupport', noop, opts);
150
- window.removeEventListener('testPassiveEventSupport', noop, opts);
151
- } catch (e) {
152
- // ignored
153
- }
154
- return supportsPassiveOption;
155
- }
156
-
157
- /**
158
- * Detects horizontal swipe direction without blocking the browser scroll using passive event.
159
- * @see http://javascriptkit.com/javatutors/touchevents2.shtml
160
- * @see https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
161
- */
162
- export function detectHorizontalSwipe(touchSurface: Element, handleSwipe: (direction: 'right' | 'left') => void) {
163
- let startX: number;
164
- let startY: number;
165
- // Required min distance traveled to be considered swipe.
166
- const threshold = 150;
167
- // Maximum distance allowed at the same time in perpendicular direction.
168
- const restraint = 150;
169
- // Maximum time allowed to travel that distance.
170
- const allowedTime = 300;
171
- let elapsedTime: number;
172
- let startTime: number;
173
- let finished: boolean;
174
-
175
- const onTouchStart = (evt: Event) => {
176
- const [touch] = Array.from((evt as TouchEvent).changedTouches);
177
- startX = touch.pageX;
178
- startY = touch.pageY;
179
- // Record time when finger first makes contact with surface.
180
- startTime = new Date().getTime();
181
- finished = false;
182
- };
183
-
184
- const onTouchMove = (evt: Event) => {
185
- if (finished) {
186
- return;
187
- }
188
-
189
- elapsedTime = new Date().getTime() - startTime;
190
- if (elapsedTime > allowedTime) {
191
- // Touch swipe too long to be considered.
192
- return;
193
- }
194
-
195
- const [touch] = Array.from((evt as TouchEvent).changedTouches);
196
- // Get horizontal dist traveled by finger while in contact with surface.
197
- const distX = touch.pageX - startX;
198
- // Get vertical dist traveled by finger while in contact with surface.
199
- const distY = touch.pageY - startY;
200
-
201
- if (!(Math.abs(distX) >= threshold && Math.abs(distY) <= restraint)) {
202
- // Swipe is not horizontal.
203
- return;
204
- }
205
- // Swipe direction.
206
- const direction = distX < 0 ? 'left' : 'right';
207
-
208
- handleSwipe(direction);
209
- finished = true;
210
- };
211
-
212
- // Activate passive event if possible for better scrolling performance.
213
- const eventOptions: any = isPassiveEventAvailable() ? { passive: true } : false;
214
- touchSurface.addEventListener('touchstart', onTouchStart, eventOptions);
215
- touchSurface.addEventListener('touchmove', onTouchMove, eventOptions);
216
-
217
- return () => {
218
- touchSurface.removeEventListener('touchstart', onTouchStart, eventOptions);
219
- touchSurface.removeEventListener('touchmove', onTouchMove, eventOptions);
220
- };
221
- }