@lumx/core 3.21.1-alpha.0 → 3.21.2-alpha.0

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 (142) hide show
  1. package/CONTRIBUTING.md +1 -5
  2. package/{js/utils/className/resolveColorWithVariants.js → _internal/DPnPEC08.js} +1 -5
  3. package/js/constants/_internal/design-tokens.d.ts +5421 -0
  4. package/js/constants/className/index.d.ts +4 -0
  5. package/js/constants/className/index.js +6 -0
  6. package/js/constants/components/index.d.ts +24 -0
  7. package/js/constants/components/index.js +26 -0
  8. package/js/constants/enums/index.d.ts +200 -0
  9. package/js/constants/enums/index.js +155 -0
  10. package/js/constants/index.d.ts +4 -0
  11. package/js/constants/index.js +4 -218
  12. package/js/constants/keycodes/index.d.ts +36 -0
  13. package/js/constants/{keycodes.js → keycodes/index.js} +1 -13
  14. package/js/types/Direction.d.ts +1 -0
  15. package/js/types/{GenericProps.ts → GenericProps.d.ts} +0 -1
  16. package/js/types/HasAriaLabelOrLabelledBy.d.ts +17 -0
  17. package/js/types/{HasTheme.ts → HasTheme.d.ts} +0 -1
  18. package/js/types/KebabCase.d.ts +2 -0
  19. package/js/types/LumxClassName.d.ts +3 -0
  20. package/js/types/Point.d.ts +7 -0
  21. package/js/types/RectSize.d.ts +7 -0
  22. package/js/types/Spacing.d.ts +1 -0
  23. package/js/types/{TextElement.ts → TextElement.d.ts} +0 -1
  24. package/js/types/{index.ts → index.d.ts} +3 -0
  25. package/js/types/index.js +0 -1
  26. package/js/utils/_internal/className/getBasicClass.d.ts +13 -0
  27. package/js/utils/_internal/className/handleBasicClasses.d.ts +15 -0
  28. package/js/utils/_internal/className/index.d.ts +2 -0
  29. package/js/utils/_internal/color/index.d.ts +1 -0
  30. package/js/utils/_internal/color/resolveColorWithVariants.d.ts +3 -0
  31. package/js/utils/classNames/color/index.d.ts +43 -0
  32. package/js/utils/classNames/color/index.js +50 -0
  33. package/js/utils/classNames/index.d.ts +5 -0
  34. package/js/utils/classNames/index.js +5 -0
  35. package/js/utils/classNames/spacing/index.d.ts +70 -0
  36. package/js/utils/classNames/spacing/index.js +74 -0
  37. package/js/utils/classNames/typography/index.d.ts +6 -0
  38. package/js/utils/classNames/typography/index.js +9 -0
  39. package/js/utils/classNames/visually-hidden/index.d.ts +5 -0
  40. package/js/utils/classNames/visually-hidden/index.js +10 -0
  41. package/js/utils/events/index.d.ts +2 -0
  42. package/js/utils/events/index.js +2 -0
  43. package/js/utils/events/keyboard.d.ts +24 -0
  44. package/js/utils/events/keyboard.js +44 -0
  45. package/js/utils/events/swipe.d.ts +6 -0
  46. package/js/utils/events/swipe.js +79 -0
  47. package/js/utils/index.d.ts +2 -0
  48. package/js/utils/index.js +4 -223
  49. package/lumx.css +7 -6
  50. package/package.json +11 -11
  51. package/scss/components/list/_index.scss +10 -4
  52. package/js/constants/design-tokens.js +0 -2329
  53. package/js/constants/design-tokens.min.js +0 -1
  54. package/js/constants/design-tokens.ts +0 -2324
  55. package/js/constants/index.min.js +0 -1
  56. package/js/constants/index.ts +0 -231
  57. package/js/constants/keycodes.min.js +0 -1
  58. package/js/constants/keycodes.ts +0 -44
  59. package/js/custom-colors.js +0 -48
  60. package/js/custom-colors.min.js +0 -1
  61. package/js/custom-colors.ts +0 -56
  62. package/js/date-picker.js +0 -71
  63. package/js/date-picker.min.js +0 -1
  64. package/js/date-picker.ts +0 -77
  65. package/js/types/Callback.js +0 -2
  66. package/js/types/Callback.min.js +0 -1
  67. package/js/types/Falsy.js +0 -2
  68. package/js/types/Falsy.min.js +0 -1
  69. package/js/types/GenericProps.js +0 -2
  70. package/js/types/GenericProps.min.js +0 -1
  71. package/js/types/HasAriaLabelOrLabelledBy.js +0 -2
  72. package/js/types/HasAriaLabelOrLabelledBy.min.js +0 -1
  73. package/js/types/HasAriaLabelOrLabelledBy.ts +0 -19
  74. package/js/types/HasClassName.js +0 -2
  75. package/js/types/HasClassName.min.js +0 -1
  76. package/js/types/HasCloseMode.js +0 -2
  77. package/js/types/HasCloseMode.min.js +0 -1
  78. package/js/types/HasTheme.js +0 -2
  79. package/js/types/HasTheme.min.js +0 -1
  80. package/js/types/HeadingElement.js +0 -2
  81. package/js/types/HeadingElement.min.js +0 -1
  82. package/js/types/Point.js +0 -2
  83. package/js/types/Point.min.js +0 -1
  84. package/js/types/Point.ts +0 -4
  85. package/js/types/Predicate.js +0 -2
  86. package/js/types/Predicate.min.js +0 -1
  87. package/js/types/RectSize.js +0 -2
  88. package/js/types/RectSize.min.js +0 -1
  89. package/js/types/RectSize.ts +0 -4
  90. package/js/types/TextElement.js +0 -2
  91. package/js/types/TextElement.min.js +0 -1
  92. package/js/types/ValueOf.js +0 -2
  93. package/js/types/ValueOf.min.js +0 -1
  94. package/js/types/index.min.js +0 -1
  95. package/js/utils/className/fontColorClass.js +0 -20
  96. package/js/utils/className/fontColorClass.min.js +0 -1
  97. package/js/utils/className/fontColorClass.test.js +0 -18
  98. package/js/utils/className/fontColorClass.test.min.js +0 -1
  99. package/js/utils/className/fontColorClass.test.ts +0 -15
  100. package/js/utils/className/fontColorClass.ts +0 -12
  101. package/js/utils/className/getBasicClass.js +0 -36
  102. package/js/utils/className/getBasicClass.min.js +0 -1
  103. package/js/utils/className/getBasicClass.test.js +0 -22
  104. package/js/utils/className/getBasicClass.test.min.js +0 -1
  105. package/js/utils/className/getBasicClass.test.ts +0 -20
  106. package/js/utils/className/getBasicClass.ts +0 -36
  107. package/js/utils/className/getRootClassName.js +0 -33
  108. package/js/utils/className/getRootClassName.min.js +0 -1
  109. package/js/utils/className/getRootClassName.test.js +0 -15
  110. package/js/utils/className/getRootClassName.test.min.js +0 -1
  111. package/js/utils/className/getRootClassName.test.ts +0 -11
  112. package/js/utils/className/getRootClassName.ts +0 -25
  113. package/js/utils/className/getTypographyClassName.js +0 -13
  114. package/js/utils/className/getTypographyClassName.min.js +0 -1
  115. package/js/utils/className/getTypographyClassName.test.js +0 -9
  116. package/js/utils/className/getTypographyClassName.test.min.js +0 -1
  117. package/js/utils/className/getTypographyClassName.test.ts +0 -7
  118. package/js/utils/className/getTypographyClassName.ts +0 -9
  119. package/js/utils/className/handleBasicClasses.js +0 -52
  120. package/js/utils/className/handleBasicClasses.min.js +0 -1
  121. package/js/utils/className/handleBasicClasses.test.js +0 -35
  122. package/js/utils/className/handleBasicClasses.test.min.js +0 -1
  123. package/js/utils/className/handleBasicClasses.test.ts +0 -28
  124. package/js/utils/className/handleBasicClasses.ts +0 -44
  125. package/js/utils/className/index.js +0 -25
  126. package/js/utils/className/index.min.js +0 -1
  127. package/js/utils/className/index.ts +0 -6
  128. package/js/utils/className/resolveColorWithVariants.min.js +0 -1
  129. package/js/utils/className/resolveColorWithVariants.test.js +0 -30
  130. package/js/utils/className/resolveColorWithVariants.test.min.js +0 -1
  131. package/js/utils/className/resolveColorWithVariants.test.ts +0 -33
  132. package/js/utils/className/resolveColorWithVariants.ts +0 -11
  133. package/js/utils/index.min.js +0 -1
  134. package/js/utils/index.ts +0 -221
  135. package/lumx.min.css +0 -1
  136. /package/js/types/{Callback.ts → Callback.d.ts} +0 -0
  137. /package/js/types/{Falsy.ts → Falsy.d.ts} +0 -0
  138. /package/js/types/{HasClassName.ts → HasClassName.d.ts} +0 -0
  139. /package/js/types/{HasCloseMode.ts → HasCloseMode.d.ts} +0 -0
  140. /package/js/types/{HeadingElement.ts → HeadingElement.d.ts} +0 -0
  141. /package/js/types/{Predicate.ts → Predicate.d.ts} +0 -0
  142. /package/js/types/{ValueOf.ts → ValueOf.d.ts} +0 -0
@@ -1,7 +1,3 @@
1
- 'use strict';
2
-
3
- Object.defineProperty(exports, '__esModule', { value: true });
4
-
5
1
  /**
6
2
  * The down key code.
7
3
  */
@@ -39,12 +35,4 @@ const UP_KEY_CODE = 38;
39
35
  */
40
36
  const BACKSPACE_KEY_CODE = 8;
41
37
 
42
- exports.BACKSPACE_KEY_CODE = BACKSPACE_KEY_CODE;
43
- exports.DOWN_KEY_CODE = DOWN_KEY_CODE;
44
- exports.ENTER_KEY_CODE = ENTER_KEY_CODE;
45
- exports.ESCAPE_KEY_CODE = ESCAPE_KEY_CODE;
46
- exports.LEFT_KEY_CODE = LEFT_KEY_CODE;
47
- exports.RIGHT_KEY_CODE = RIGHT_KEY_CODE;
48
- exports.SPACE_KEY_CODE = SPACE_KEY_CODE;
49
- exports.TAB_KEY_CODE = TAB_KEY_CODE;
50
- exports.UP_KEY_CODE = UP_KEY_CODE;
38
+ export { BACKSPACE_KEY_CODE, DOWN_KEY_CODE, ENTER_KEY_CODE, ESCAPE_KEY_CODE, LEFT_KEY_CODE, RIGHT_KEY_CODE, SPACE_KEY_CODE, TAB_KEY_CODE, UP_KEY_CODE };
@@ -0,0 +1 @@
1
+ export type Direction = 'top' | 'right' | 'bottom' | 'left' | 'vertical' | 'horizontal' | 'all';
@@ -1,5 +1,4 @@
1
1
  import type { HasClassName } from './HasClassName';
2
-
3
2
  /**
4
3
  * Define a generic props types.
5
4
  */
@@ -0,0 +1,17 @@
1
+ /**
2
+ * Require either `aria-label` or `arial-labelledby` prop.
3
+ * If none are set, the order will prioritize `aria-labelledby` over `aria-label` as it
4
+ * needs a visible element.
5
+ */
6
+ export type HasAriaLabelOrLabelledBy<T = string | undefined> = T extends string ? {
7
+ /**
8
+ * The id of the element to use as title of the dialog. Can be within or out of the dialog.
9
+ * Although it is not recommended, aria-label can be used instead if no visible element is available.
10
+ */
11
+ 'aria-labelledby': T;
12
+ /** The label of the dialog. */
13
+ 'aria-label'?: undefined;
14
+ } : {
15
+ 'aria-label': string;
16
+ 'aria-labelledby'?: undefined;
17
+ };
@@ -1,5 +1,4 @@
1
1
  import type { Theme } from '../constants';
2
-
3
2
  export interface HasTheme {
4
3
  /**
5
4
  * Theme adapting the component to light or dark background.
@@ -0,0 +1,2 @@
1
+ /** Transform a string literal into kebab case */
2
+ export type KebabCase<S> = S extends `${infer C}${infer T}` ? T extends Uncapitalize<T> ? `${Uncapitalize<C>}${KebabCase<T>}` : `${Uncapitalize<C>}-${KebabCase<T>}` : S;
@@ -0,0 +1,3 @@
1
+ import type { KebabCase } from './KebabCase';
2
+ /** Transform the component name into the lumx class name. */
3
+ export type LumxClassName<TComponentName extends string> = `lumx-${KebabCase<TComponentName>}`;
@@ -0,0 +1,7 @@
1
+ /**
2
+ * A point coordinate in 2D space
3
+ */
4
+ export type Point = {
5
+ x: number;
6
+ y: number;
7
+ };
@@ -0,0 +1,7 @@
1
+ /**
2
+ * Rectangle size
3
+ */
4
+ export type RectSize = {
5
+ width: number;
6
+ height: number;
7
+ };
@@ -0,0 +1 @@
1
+ export type Spacing = 'margin' | 'padding';
@@ -1,4 +1,3 @@
1
1
  import type { HeadingElement } from './HeadingElement';
2
-
3
2
  /** Union type of all text elements */
4
3
  export type TextElement = 'span' | 'p' | HeadingElement;
@@ -11,3 +11,6 @@ export type { Predicate } from './Predicate';
11
11
  export type { RectSize } from './RectSize';
12
12
  export type { TextElement } from './TextElement';
13
13
  export type { ValueOf } from './ValueOf';
14
+ export type { LumxClassName } from './LumxClassName';
15
+ export type { Direction } from './Direction';
16
+ export type { Spacing } from './Spacing';
package/js/types/index.js CHANGED
@@ -1,2 +1 @@
1
- 'use strict';
2
1
 
@@ -0,0 +1,13 @@
1
+ /**
2
+ * Get the basic CSS class for the given type.
3
+ *
4
+ * @param prefix The class name prefix for the generated CSS class.
5
+ * @param type The type of CSS class we want to generate (e.g.: 'color', 'variant', ...).
6
+ * @param value The value of the type of the CSS class (e.g.: 'primary', 'button', ...).
7
+ * @return The basic CSS class.
8
+ */
9
+ export declare function getBasicClass({ prefix, type, value, }: {
10
+ prefix: string;
11
+ type: string;
12
+ value: string | number | boolean | undefined;
13
+ }): string;
@@ -0,0 +1,15 @@
1
+ /**
2
+ * Return all basic LumX CSS classes which are available for every components.
3
+ *
4
+ * @see {@link /src/components/index.d.ts} for the possible values of each parameter.
5
+ *
6
+ * @param prefix The class name prefix for the generated CSS class.
7
+ * @param props All the other props you want to generate a class.
8
+ * The rule of thumb: the key is the name of the prop in the class, the value a string that will
9
+ * be used in the classname to represent the value of the given prop.
10
+ * @return All LumX basic CSS classes.
11
+ */
12
+ export declare function handleBasicClasses({ prefix, ...props }: {
13
+ prefix: string;
14
+ [prop: string]: any;
15
+ }): string;
@@ -0,0 +1,2 @@
1
+ export { handleBasicClasses } from './handleBasicClasses';
2
+ export { getBasicClass } from './getBasicClass';
@@ -0,0 +1 @@
1
+ export { resolveColorWithVariants } from './resolveColorWithVariants';
@@ -0,0 +1,3 @@
1
+ import type { ColorPalette, ColorVariant, ColorWithVariants } from '@lumx/core/js/constants';
2
+ /** Resolve color & color variant from a `ColorWithVariants` and optionally a `ColorVariant`. */
3
+ export declare function resolveColorWithVariants(colorWithVariants?: ColorWithVariants, colorVariant?: ColorVariant): [color?: ColorPalette, colorVariant?: ColorVariant];
@@ -0,0 +1,43 @@
1
+ import { ColorVariant, ColorWithVariants } from '@lumx/core/js/constants';
2
+ /**
3
+ * Generates a Lumx color class name for the given type, color and variant.
4
+ * This is the base function used by font() and background() utilities.
5
+ *
6
+ * @param type - The color class type ('font' or 'background')
7
+ * @param propColor - The color palette name (e.g., 'primary', 'dark') with optional variant suffix (e.g., 'primary-L2')
8
+ * @param propColorVariant - Optional color variant override (e.g., 'L1', 'L2', 'D1', 'N')
9
+ * @returns The Lumx color class name or undefined if no color is provided
10
+ *
11
+ * @example
12
+ * color('font', 'dark', 'L2'); // 'lumx-color-font-dark-L2'
13
+ * color('background', 'primary'); // 'lumx-color-background-primary-N'
14
+ * color('font', 'primary-L2'); // 'lumx-color-font-primary-L2'
15
+ * color('font', undefined); // undefined
16
+ */
17
+ export declare function color(type: 'font' | 'background', propColor: ColorWithVariants, propColorVariant?: ColorVariant): string;
18
+ /**
19
+ * Generates a Lumx background color class name for the given color and variant.
20
+ *
21
+ * @param propColor - The color palette name (e.g., 'primary', 'dark', 'light')
22
+ * @param propColorVariant - The color variant (e.g., 'L1', 'L2', 'D1', 'N')
23
+ * @returns The Lumx background color class name
24
+ *
25
+ * @example
26
+ * background('dark', 'L2'); // 'lumx-color-background-dark-L2'
27
+ * background('primary', 'N'); // 'lumx-color-background-primary-N'
28
+ */
29
+ export declare const background: (propColor: ColorWithVariants, propColorVariant?: ColorVariant) => string;
30
+ /**
31
+ * Generates a Lumx font color class name for the given color and variant.
32
+ *
33
+ * @param propColor - The color palette name (e.g., 'primary', 'dark') with optional variant suffix (e.g., 'primary-L2')
34
+ * @param propColorVariant - Optional color variant override (e.g., 'L1', 'L2', 'D1', 'N')
35
+ * @returns The Lumx font color class name or undefined if no color is provided
36
+ *
37
+ * @example
38
+ * font('dark', 'L2'); // 'lumx-color-font-dark-L2'
39
+ * font('primary-L2'); // 'lumx-color-font-primary-L2'
40
+ * font('primary'); // 'lumx-color-font-primary-N'
41
+ * font(undefined); // undefined
42
+ */
43
+ export declare const font: (propColor: ColorWithVariants, propColorVariant?: ColorVariant) => string;
@@ -0,0 +1,50 @@
1
+ import { ColorVariant } from '../../../constants/enums/index.js';
2
+ import { resolveColorWithVariants } from '../../../../_internal/DPnPEC08.js';
3
+
4
+ /**
5
+ * Generates a Lumx color class name for the given type, color and variant.
6
+ * This is the base function used by font() and background() utilities.
7
+ *
8
+ * @param type - The color class type ('font' or 'background')
9
+ * @param propColor - The color palette name (e.g., 'primary', 'dark') with optional variant suffix (e.g., 'primary-L2')
10
+ * @param propColorVariant - Optional color variant override (e.g., 'L1', 'L2', 'D1', 'N')
11
+ * @returns The Lumx color class name or undefined if no color is provided
12
+ *
13
+ * @example
14
+ * color('font', 'dark', 'L2'); // 'lumx-color-font-dark-L2'
15
+ * color('background', 'primary'); // 'lumx-color-background-primary-N'
16
+ * color('font', 'primary-L2'); // 'lumx-color-font-primary-L2'
17
+ * color('font', undefined); // undefined
18
+ */
19
+ function color(type, propColor, propColorVariant) {
20
+ const [cColor, cColorVariant = ColorVariant.N] = resolveColorWithVariants(propColor, propColorVariant);
21
+ return `lumx-color-${type}-${cColor}-${cColorVariant}`;
22
+ }
23
+ /**
24
+ * Generates a Lumx background color class name for the given color and variant.
25
+ *
26
+ * @param propColor - The color palette name (e.g., 'primary', 'dark', 'light')
27
+ * @param propColorVariant - The color variant (e.g., 'L1', 'L2', 'D1', 'N')
28
+ * @returns The Lumx background color class name
29
+ *
30
+ * @example
31
+ * background('dark', 'L2'); // 'lumx-color-background-dark-L2'
32
+ * background('primary', 'N'); // 'lumx-color-background-primary-N'
33
+ */
34
+ const background = (propColor, propColorVariant) => color('background', propColor, propColorVariant);
35
+ /**
36
+ * Generates a Lumx font color class name for the given color and variant.
37
+ *
38
+ * @param propColor - The color palette name (e.g., 'primary', 'dark') with optional variant suffix (e.g., 'primary-L2')
39
+ * @param propColorVariant - Optional color variant override (e.g., 'L1', 'L2', 'D1', 'N')
40
+ * @returns The Lumx font color class name or undefined if no color is provided
41
+ *
42
+ * @example
43
+ * font('dark', 'L2'); // 'lumx-color-font-dark-L2'
44
+ * font('primary-L2'); // 'lumx-color-font-primary-L2'
45
+ * font('primary'); // 'lumx-color-font-primary-N'
46
+ * font(undefined); // undefined
47
+ */
48
+ const font = (propColor, propColorVariant) => color('font', propColor, propColorVariant);
49
+
50
+ export { background, color, font };
@@ -0,0 +1,5 @@
1
+ export { default as join } from 'classnames';
2
+ export * from './color';
3
+ export * from './typography';
4
+ export * from './spacing';
5
+ export * from './visually-hidden';
@@ -0,0 +1,5 @@
1
+ export { default as join } from 'classnames';
2
+ export { background, color, font } from './color/index.js';
3
+ export { typography } from './typography/index.js';
4
+ export { margin, margins, padding, paddings, spacing, spacings } from './spacing/index.js';
5
+ export { visuallyHidden } from './visually-hidden/index.js';
@@ -0,0 +1,70 @@
1
+ import type { Direction, Spacing } from '@lumx/core/js/types';
2
+ import type { Size } from '@lumx/core/js/constants';
3
+ /**
4
+ * Returns a lumx classname for the given type, direction and size. For example, for
5
+ * arguments type='padding', direction='right', size='regular' it returns lumx-spacing-padding-right-regular
6
+ * @param type - margin or padding
7
+ * @param direction - Direction
8
+ * @param size - Size
9
+ * @returns string
10
+ */
11
+ export declare function spacing(type: Spacing, direction?: Direction, size?: Size | null): string;
12
+ /**
13
+ * Returns a list of lumx classnames for the given types, directions and sizes. For example, for
14
+ * arguments [
15
+ * { type: 'padding', direction: 'right', size: 'regular'},
16
+ * { type: 'margin', direction: 'left', size: 'big'},
17
+ * ]
18
+ * it returns lumx-spacing-padding-right-regular lumx-spacing-margin-left-big
19
+ * @param spacingConfigs - Array of spacing configurations with direction and size
20
+ * @returns string
21
+ */
22
+ export declare const spacings: (spacingConfigs: {
23
+ type: Spacing;
24
+ direction?: Direction;
25
+ size?: Size | null;
26
+ }[]) => string;
27
+ /**
28
+ * Returns a lumx margin classname for the given direction and size. For example, for
29
+ * arguments direction='right', size='regular' it returns lumx-spacing-margin-right-regular
30
+ * @param direction - Direction
31
+ * @param size - Size
32
+ * @returns string
33
+ */
34
+ export declare const margin: (direction?: Direction, size?: Size | null) => string;
35
+ /**
36
+ * Returns a list of lumx margin classnames for the given directions and sizes. For example, for
37
+ * arguments [
38
+ * { direction: 'right', size: 'regular'},
39
+ * { direction: 'left', size: 'big'},
40
+ * ]
41
+ * it returns lumx-spacing-margin-right-regular lumx-spacing-margin-left-big
42
+ * @param marginConfigs - Array of padding configurations with direction and size
43
+ * @returns string
44
+ */
45
+ export declare const margins: (marginConfigs: {
46
+ direction?: Direction;
47
+ size?: Size | null;
48
+ }[]) => string;
49
+ /**
50
+ * Returns a lumx padding classname for the given direction and size. For example, for
51
+ * arguments direction='right', size='regular' it returns lumx-spacing-padding-right-regular
52
+ * @param direction - Direction
53
+ * @param size - Size
54
+ * @returns string
55
+ */
56
+ export declare const padding: (direction?: Direction, size?: Size | null) => string;
57
+ /**
58
+ * Returns a list of lumx padding classnames for the given directions and sizes. For example, for
59
+ * arguments [
60
+ * { direction: 'right', size: 'regular'},
61
+ * { direction: 'left', size: 'big'},
62
+ * ]
63
+ * it returns lumx-spacing-padding-right-regular lumx-spacing-padding-left-big
64
+ * @param paddingConfigs - Array of padding configurations with direction and size
65
+ * @returns Combined padding classnames as a string
66
+ */
67
+ export declare const paddings: (paddingConfigs: {
68
+ direction?: Direction;
69
+ size?: Size | null;
70
+ }[]) => string;
@@ -0,0 +1,74 @@
1
+ import classnames from 'classnames';
2
+
3
+ /**
4
+ * Returns a lumx classname for the given type, direction and size. For example, for
5
+ * arguments type='padding', direction='right', size='regular' it returns lumx-spacing-padding-right-regular
6
+ * @param type - margin or padding
7
+ * @param direction - Direction
8
+ * @param size - Size
9
+ * @returns string
10
+ */
11
+ function spacing(type, direction, size) {
12
+ let baseClass = `lumx-spacing-${type}`;
13
+ if (direction && direction !== 'all') {
14
+ baseClass = `${baseClass}-${direction}`;
15
+ }
16
+ if (size) {
17
+ baseClass = `${baseClass}-${size}`;
18
+ }
19
+ else if (size === null) {
20
+ baseClass = `${baseClass}-none`;
21
+ }
22
+ return baseClass;
23
+ }
24
+ /**
25
+ * Returns a list of lumx classnames for the given types, directions and sizes. For example, for
26
+ * arguments [
27
+ * { type: 'padding', direction: 'right', size: 'regular'},
28
+ * { type: 'margin', direction: 'left', size: 'big'},
29
+ * ]
30
+ * it returns lumx-spacing-padding-right-regular lumx-spacing-margin-left-big
31
+ * @param spacingConfigs - Array of spacing configurations with direction and size
32
+ * @returns string
33
+ */
34
+ const spacings = (spacingConfigs) => classnames(spacingConfigs.map((spa) => spacing(spa.type, spa.direction, spa.size)));
35
+ /**
36
+ * Returns a lumx margin classname for the given direction and size. For example, for
37
+ * arguments direction='right', size='regular' it returns lumx-spacing-margin-right-regular
38
+ * @param direction - Direction
39
+ * @param size - Size
40
+ * @returns string
41
+ */
42
+ const margin = (direction, size) => spacing('margin', direction, size);
43
+ /**
44
+ * Returns a list of lumx margin classnames for the given directions and sizes. For example, for
45
+ * arguments [
46
+ * { direction: 'right', size: 'regular'},
47
+ * { direction: 'left', size: 'big'},
48
+ * ]
49
+ * it returns lumx-spacing-margin-right-regular lumx-spacing-margin-left-big
50
+ * @param marginConfigs - Array of padding configurations with direction and size
51
+ * @returns string
52
+ */
53
+ const margins = (marginConfigs) => spacings(marginConfigs.map(({ direction, size }) => ({ type: 'margin', direction, size })));
54
+ /**
55
+ * Returns a lumx padding classname for the given direction and size. For example, for
56
+ * arguments direction='right', size='regular' it returns lumx-spacing-padding-right-regular
57
+ * @param direction - Direction
58
+ * @param size - Size
59
+ * @returns string
60
+ */
61
+ const padding = (direction, size) => spacing('padding', direction, size);
62
+ /**
63
+ * Returns a list of lumx padding classnames for the given directions and sizes. For example, for
64
+ * arguments [
65
+ * { direction: 'right', size: 'regular'},
66
+ * { direction: 'left', size: 'big'},
67
+ * ]
68
+ * it returns lumx-spacing-padding-right-regular lumx-spacing-padding-left-big
69
+ * @param paddingConfigs - Array of padding configurations with direction and size
70
+ * @returns Combined padding classnames as a string
71
+ */
72
+ const paddings = (paddingConfigs) => spacings(paddingConfigs.map(({ direction, size }) => ({ type: 'padding', direction, size })));
73
+
74
+ export { margin, margins, padding, paddings, spacing, spacings };
@@ -0,0 +1,6 @@
1
+ import type { Typography } from '@lumx/core/js/constants';
2
+ /**
3
+ * Returns the classname associated to the given typography. For example, for Typography.title it returns
4
+ * lumx-typography-title
5
+ */
6
+ export declare function typography(typo: Typography): string;
@@ -0,0 +1,9 @@
1
+ /**
2
+ * Returns the classname associated to the given typography. For example, for Typography.title it returns
3
+ * lumx-typography-title
4
+ */
5
+ function typography(typo) {
6
+ return `lumx-typography-${typo}`;
7
+ }
8
+
9
+ export { typography };
@@ -0,0 +1,5 @@
1
+ /**
2
+ * Visually hidden class name.
3
+ * Used to hide elements from view but keep them readable from screen readers
4
+ */
5
+ export declare const visuallyHidden: () => string;
@@ -0,0 +1,10 @@
1
+ import '../../../constants/enums/index.js';
2
+ import { VISUALLY_HIDDEN } from '../../../constants/className/index.js';
3
+
4
+ /**
5
+ * Visually hidden class name.
6
+ * Used to hide elements from view but keep them readable from screen readers
7
+ */
8
+ const visuallyHidden = () => VISUALLY_HIDDEN;
9
+
10
+ export { visuallyHidden };
@@ -0,0 +1,2 @@
1
+ export * from './keyboard';
2
+ export * from './swipe';
@@ -0,0 +1,2 @@
1
+ export { onButtonPressed, onEnterPressed, onEscapePressed } from './keyboard.js';
2
+ export { detectHorizontalSwipe } from './swipe.js';
@@ -0,0 +1,24 @@
1
+ import type { KeyboardEvent as ReactKeyboardEvent } from 'react';
2
+ type KeyboardEventHandler<E extends KeyboardEvent | ReactKeyboardEvent> = (event: E) => void;
3
+ /**
4
+ * Make sure the pressed key is the enter key before calling the callback.
5
+ *
6
+ * @param handler The handler to call on enter/return press.
7
+ * @return The decorated function.
8
+ */
9
+ export declare function onEnterPressed<E extends KeyboardEvent | ReactKeyboardEvent>(handler: KeyboardEventHandler<E>): KeyboardEventHandler<E>;
10
+ /**
11
+ * Make sure the pressed key is the escape key before calling the callback.
12
+ *
13
+ * @param handler The handler to call on enter/return press.
14
+ * @return The decorated function.
15
+ */
16
+ export declare function onEscapePressed<E extends KeyboardEvent | ReactKeyboardEvent>(handler: KeyboardEventHandler<E>): KeyboardEventHandler<E>;
17
+ /**
18
+ * Handle button key pressed (Enter + Space).
19
+ *
20
+ * @param handler The handler to call.
21
+ * @return The decorated function.
22
+ */
23
+ export declare function onButtonPressed<E extends KeyboardEvent | ReactKeyboardEvent>(handler: KeyboardEventHandler<E>): KeyboardEventHandler<E>;
24
+ export {};
@@ -0,0 +1,44 @@
1
+ /**
2
+ * Make sure the pressed key is the enter key before calling the callback.
3
+ *
4
+ * @param handler The handler to call on enter/return press.
5
+ * @return The decorated function.
6
+ */
7
+ function onEnterPressed(handler) {
8
+ return (evt) => {
9
+ if (evt.key !== 'Enter') {
10
+ return;
11
+ }
12
+ handler(evt);
13
+ };
14
+ }
15
+ /**
16
+ * Make sure the pressed key is the escape key before calling the callback.
17
+ *
18
+ * @param handler The handler to call on enter/return press.
19
+ * @return The decorated function.
20
+ */
21
+ function onEscapePressed(handler) {
22
+ return (evt) => {
23
+ if (evt.key !== 'Escape') {
24
+ return;
25
+ }
26
+ handler(evt);
27
+ };
28
+ }
29
+ /**
30
+ * Handle button key pressed (Enter + Space).
31
+ *
32
+ * @param handler The handler to call.
33
+ * @return The decorated function.
34
+ */
35
+ function onButtonPressed(handler) {
36
+ return (evt) => {
37
+ if (evt.key !== 'Enter' && evt.key !== ' ') {
38
+ return;
39
+ }
40
+ handler(evt);
41
+ };
42
+ }
43
+
44
+ export { onButtonPressed, onEnterPressed, onEscapePressed };
@@ -0,0 +1,6 @@
1
+ /**
2
+ * Detects horizontal swipe direction without blocking the browser scroll using passive event.
3
+ * @see http://javascriptkit.com/javatutors/touchevents2.shtml
4
+ * @see https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
5
+ */
6
+ export declare function detectHorizontalSwipe(touchSurface: Element, handleSwipe: (direction: 'right' | 'left') => void): () => void;
@@ -0,0 +1,79 @@
1
+ /**
2
+ * Checks whether the browser support passive events.
3
+ * @see https://github.com/Modernizr/Modernizr/blob/6d56d814b9682843313b16060adb25a58d83a317/feature-detects/dom/passiveeventlisteners.js
4
+ */
5
+ function isPassiveEventAvailable() {
6
+ let supportsPassiveOption = false;
7
+ try {
8
+ const opts = Object.defineProperty({}, 'passive', {
9
+ get() {
10
+ supportsPassiveOption = true;
11
+ },
12
+ });
13
+ window.addEventListener('testPassiveEventSupport', () => { }, opts);
14
+ window.removeEventListener('testPassiveEventSupport', () => { }, opts);
15
+ }
16
+ catch (e) {
17
+ // ignored
18
+ }
19
+ return supportsPassiveOption;
20
+ }
21
+ /**
22
+ * Detects horizontal swipe direction without blocking the browser scroll using passive event.
23
+ * @see http://javascriptkit.com/javatutors/touchevents2.shtml
24
+ * @see https://github.com/WICG/EventListenerOptions/blob/gh-pages/explainer.md
25
+ */
26
+ function detectHorizontalSwipe(touchSurface, handleSwipe) {
27
+ let startX;
28
+ let startY;
29
+ // Required min distance traveled to be considered swipe.
30
+ const threshold = 150;
31
+ // Maximum distance allowed at the same time in perpendicular direction.
32
+ const restraint = 150;
33
+ // Maximum time allowed to travel that distance.
34
+ const allowedTime = 300;
35
+ let elapsedTime;
36
+ let startTime;
37
+ let finished;
38
+ const onTouchStart = (evt) => {
39
+ const [touch] = Array.from(evt.changedTouches);
40
+ startX = touch.pageX;
41
+ startY = touch.pageY;
42
+ // Record time when finger first makes contact with surface.
43
+ startTime = new Date().getTime();
44
+ finished = false;
45
+ };
46
+ const onTouchMove = (evt) => {
47
+ if (finished) {
48
+ return;
49
+ }
50
+ elapsedTime = new Date().getTime() - startTime;
51
+ if (elapsedTime > allowedTime) {
52
+ // Touch swipe too long to be considered.
53
+ return;
54
+ }
55
+ const [touch] = Array.from(evt.changedTouches);
56
+ // Get horizontal dist traveled by finger while in contact with surface.
57
+ const distX = touch.pageX - startX;
58
+ // Get vertical dist traveled by finger while in contact with surface.
59
+ const distY = touch.pageY - startY;
60
+ if (!(Math.abs(distX) >= threshold && Math.abs(distY) <= restraint)) {
61
+ // Swipe is not horizontal.
62
+ return;
63
+ }
64
+ // Swipe direction.
65
+ const direction = distX < 0 ? 'left' : 'right';
66
+ handleSwipe(direction);
67
+ finished = true;
68
+ };
69
+ // Activate passive event if possible for better scrolling performance.
70
+ const eventOptions = isPassiveEventAvailable() ? { passive: true } : false;
71
+ touchSurface.addEventListener('touchstart', onTouchStart, eventOptions);
72
+ touchSurface.addEventListener('touchmove', onTouchMove, eventOptions);
73
+ return () => {
74
+ touchSurface.removeEventListener('touchstart', onTouchStart, eventOptions);
75
+ touchSurface.removeEventListener('touchmove', onTouchMove, eventOptions);
76
+ };
77
+ }
78
+
79
+ export { detectHorizontalSwipe };
@@ -0,0 +1,2 @@
1
+ export * as classNames from './classNames';
2
+ export * from './events';