@lumx/core 3.20.1-alpha.42 → 3.20.1-alpha.44

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 (46) hide show
  1. package/js/constants/index.d.ts +4 -4
  2. package/js/constants/index.js +6 -3
  3. package/js/types/Direction.d.ts +1 -0
  4. package/js/types/Direction.js +1 -0
  5. package/js/types/KebabCase.d.ts +2 -0
  6. package/js/types/KebabCase.js +1 -0
  7. package/js/types/LumxClassName.d.ts +3 -0
  8. package/js/types/LumxClassName.js +1 -0
  9. package/js/types/Spacing.d.ts +1 -0
  10. package/js/types/Spacing.js +1 -0
  11. package/js/types/index.d.ts +4 -0
  12. package/js/utils/className/bem/block.d.ts +20 -0
  13. package/js/utils/className/bem/block.js +23 -0
  14. package/js/utils/className/bem/element.d.ts +21 -0
  15. package/js/utils/className/bem/element.js +25 -0
  16. package/js/utils/className/bem/generateBEMClass.d.ts +32 -0
  17. package/js/utils/className/bem/generateBEMClass.js +48 -0
  18. package/js/utils/className/bem/index.d.ts +2 -0
  19. package/js/utils/className/bem/index.js +2 -0
  20. package/js/utils/className/color/index.d.ts +43 -0
  21. package/js/utils/className/color/index.js +52 -0
  22. package/js/utils/className/index.d.ts +5 -6
  23. package/js/utils/className/index.js +6 -6
  24. package/js/utils/className/spacing/index.d.ts +70 -0
  25. package/js/utils/className/spacing/index.js +76 -0
  26. package/js/utils/className/typography/index.d.ts +6 -0
  27. package/js/utils/className/typography/index.js +11 -0
  28. package/js/utils/className/visually-hidden/index.d.ts +5 -0
  29. package/js/utils/className/visually-hidden/index.js +9 -0
  30. package/js/utils/color/index.d.ts +1 -0
  31. package/js/utils/color/index.js +1 -0
  32. package/js/utils/{className → color}/resolveColorWithVariants.d.ts +1 -1
  33. package/js/utils/index.d.ts +2 -1
  34. package/js/utils/index.js +3 -6
  35. package/package.json +2 -2
  36. package/js/utils/className/fontColorClass.d.ts +0 -6
  37. package/js/utils/className/fontColorClass.js +0 -15
  38. package/js/utils/className/getBasicClass.d.ts +0 -13
  39. package/js/utils/className/getBasicClass.js +0 -27
  40. package/js/utils/className/getRootClassName.d.ts +0 -11
  41. package/js/utils/className/getRootClassName.js +0 -24
  42. package/js/utils/className/getTypographyClassName.d.ts +0 -6
  43. package/js/utils/className/getTypographyClassName.js +0 -9
  44. package/js/utils/className/handleBasicClasses.d.ts +0 -15
  45. package/js/utils/className/handleBasicClasses.js +0 -41
  46. /package/js/utils/{className → color}/resolveColorWithVariants.js +0 -0
@@ -1,8 +1,4 @@
1
1
  import { ValueOf } from '../types/ValueOf';
2
- /**
3
- * The prefix to use for the CSS classes.
4
- */
5
- export declare const CSS_PREFIX = "lumx";
6
2
  /**
7
3
  * Key codes.
8
4
  */
@@ -230,3 +226,7 @@ export declare const ColorVariant: {
230
226
  export type ColorVariant = ValueOf<typeof ColorVariant>;
231
227
  /** ColorPalette with all possible color variant combination */
232
228
  export type ColorWithVariants = ColorPalette | Exclude<`${ColorPalette}-${ColorVariant}`, `light-D${number}` | `dark-D${number}`>;
229
+ /**
230
+ * Visually hidden a11y utility class name
231
+ */
232
+ export declare const VISUALLY_HIDDEN = "visually-hidden";
@@ -1,9 +1,8 @@
1
1
  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 } from './keycodes.js';
2
2
 
3
3
  /**
4
- * The prefix to use for the CSS classes.
4
+ * Key codes.
5
5
  */
6
- const CSS_PREFIX = 'lumx';
7
6
  /**
8
7
  * Animation duration constants. Take into consideration that if you change one of these variables,
9
8
  * you need to update their scss counterpart as well
@@ -181,5 +180,9 @@ const ColorVariant = {
181
180
  L6: 'L6',
182
181
  N: 'N',
183
182
  };
183
+ /**
184
+ * Visually hidden a11y utility class name
185
+ */
186
+ const VISUALLY_HIDDEN = 'visually-hidden';
184
187
 
185
- export { Alignment, AspectRatio, CSS_PREFIX, ColorPalette, ColorVariant, DIALOG_TRANSITION_DURATION, EXPANSION_PANEL_TRANSITION_DURATION, Emphasis, Kind, NOTIFICATION_TRANSITION_DURATION, Orientation, SLIDESHOW_TRANSITION_DURATION, Size, TOOLTIP_HOVER_DELAY, TOOLTIP_LONG_PRESS_DELAY, Theme, Typography, TypographyCustom, TypographyInterface, TypographyTitleCustom, WhiteSpace };
188
+ export { Alignment, AspectRatio, ColorPalette, ColorVariant, DIALOG_TRANSITION_DURATION, EXPANSION_PANEL_TRANSITION_DURATION, Emphasis, Kind, NOTIFICATION_TRANSITION_DURATION, Orientation, SLIDESHOW_TRANSITION_DURATION, Size, TOOLTIP_HOVER_DELAY, TOOLTIP_LONG_PRESS_DELAY, Theme, Typography, TypographyCustom, TypographyInterface, TypographyTitleCustom, VISUALLY_HIDDEN, WhiteSpace };
@@ -0,0 +1 @@
1
+ export type Direction = 'top' | 'right' | 'bottom' | 'left' | 'vertical' | 'horizontal' | 'all';
@@ -0,0 +1 @@
1
+
@@ -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 @@
1
+
@@ -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 @@
1
+
@@ -0,0 +1 @@
1
+ export type Spacing = 'margin' | 'padding';
@@ -0,0 +1 @@
1
+
@@ -6,8 +6,12 @@ export type { HasCloseMode } from './HasCloseMode';
6
6
  export type { HasTheme } from './HasTheme';
7
7
  export type { GenericProps } from './GenericProps';
8
8
  export type { HeadingElement } from './HeadingElement';
9
+ export type { KebabCase } from './KebabCase';
9
10
  export type { Point } from './Point';
10
11
  export type { Predicate } from './Predicate';
11
12
  export type { RectSize } from './RectSize';
12
13
  export type { TextElement } from './TextElement';
13
14
  export type { ValueOf } from './ValueOf';
15
+ export type { LumxClassName } from './LumxClassName';
16
+ export type { Direction } from './Direction';
17
+ export type { Spacing } from './Spacing';
@@ -0,0 +1,20 @@
1
+ import type { ClassValue } from 'classnames/types';
2
+ import type { KebabCase } from '@lumx/core/js/types';
3
+ import { type Modifier, type RawModifier } from './generateBEMClass';
4
+ /**
5
+ * Creates a BEM block class generator function for the given base class.
6
+ * Returns a function that generates BEM class names with optional modifiers.
7
+ *
8
+ * @param baseClass - The base BEM block class name (e.g., 'button', 'card')
9
+ * @returns A function that accepts:
10
+ * - modifier - Optional BEM modifier (string, object, or array)
11
+ * - additionalClasses - Optional additional classes to include
12
+ * - modifierLast - Whether to append modifier classes last (default: false)
13
+ *
14
+ * @example
15
+ * const button = block('my-button');
16
+ * button(); // 'my-button'
17
+ * button('primary'); // 'my-button my-button--primary'
18
+ * button({ active: true }); // 'my-button my-button--active'
19
+ */
20
+ export declare const block: <B extends string>(baseClass: KebabCase<B>) => <M extends RawModifier>(modifier?: Modifier<M>, additionalClasses?: ClassValue | ClassValue[], modifierLast?: boolean) => string;
@@ -0,0 +1,23 @@
1
+ import { generateBEMClass } from './generateBEMClass.js';
2
+
3
+ /**
4
+ * Creates a BEM block class generator function for the given base class.
5
+ * Returns a function that generates BEM class names with optional modifiers.
6
+ *
7
+ * @param baseClass - The base BEM block class name (e.g., 'button', 'card')
8
+ * @returns A function that accepts:
9
+ * - modifier - Optional BEM modifier (string, object, or array)
10
+ * - additionalClasses - Optional additional classes to include
11
+ * - modifierLast - Whether to append modifier classes last (default: false)
12
+ *
13
+ * @example
14
+ * const button = block('my-button');
15
+ * button(); // 'my-button'
16
+ * button('primary'); // 'my-button my-button--primary'
17
+ * button({ active: true }); // 'my-button my-button--active'
18
+ */
19
+ const block = (baseClass) => (modifier, additionalClasses, modifierLast) => {
20
+ return generateBEMClass(baseClass, modifier, additionalClasses, modifierLast);
21
+ };
22
+
23
+ export { block };
@@ -0,0 +1,21 @@
1
+ import type { ClassValue } from 'classnames/types';
2
+ import type { KebabCase } from '@lumx/core/js/types';
3
+ import { type Modifier, type RawModifier } from './generateBEMClass';
4
+ /**
5
+ * Creates a BEM element class generator function for the given base class.
6
+ * Returns a function that generates BEM element class names with optional modifiers.
7
+ *
8
+ * @param baseClass - The base BEM block class name (e.g., 'button', 'card')
9
+ * @returns A function that accepts:
10
+ * - elem - The BEM element name (e.g., 'icon', 'title')
11
+ * - modifier - Optional BEM modifier (string, object, or array)
12
+ * - additionalClasses - Optional additional classes to include
13
+ * - modifierLast - Whether to append modifier classes last (default: false)
14
+ *
15
+ * @example
16
+ * const button = element('my-button');
17
+ * button('icon'); // 'my-button__icon'
18
+ * button('icon', 'large'); // 'my-button__icon my-button__icon--large'
19
+ * button('icon', { active: true }); // 'my-button__icon my-button__icon--active'
20
+ */
21
+ export declare const element: <B extends string>(baseClass: KebabCase<B>) => <E extends string, M extends RawModifier>(elem: KebabCase<E>, modifier?: Modifier<M>, additionalClasses?: ClassValue | ClassValue[], modifierLast?: boolean) => string;
@@ -0,0 +1,25 @@
1
+ import { generateBEMClass } from './generateBEMClass.js';
2
+
3
+ /**
4
+ * Creates a BEM element class generator function for the given base class.
5
+ * Returns a function that generates BEM element class names with optional modifiers.
6
+ *
7
+ * @param baseClass - The base BEM block class name (e.g., 'button', 'card')
8
+ * @returns A function that accepts:
9
+ * - elem - The BEM element name (e.g., 'icon', 'title')
10
+ * - modifier - Optional BEM modifier (string, object, or array)
11
+ * - additionalClasses - Optional additional classes to include
12
+ * - modifierLast - Whether to append modifier classes last (default: false)
13
+ *
14
+ * @example
15
+ * const button = element('my-button');
16
+ * button('icon'); // 'my-button__icon'
17
+ * button('icon', 'large'); // 'my-button__icon my-button__icon--large'
18
+ * button('icon', { active: true }); // 'my-button__icon my-button__icon--active'
19
+ */
20
+ const element = (baseClass) => (elem, modifier, additionalClasses, modifierLast) => {
21
+ const elementClassname = `${baseClass}__${elem}`;
22
+ return generateBEMClass(elementClassname, modifier, additionalClasses, modifierLast);
23
+ };
24
+
25
+ export { element };
@@ -0,0 +1,32 @@
1
+ import type { ClassValue } from 'classnames/types';
2
+ import type { KebabCase } from '@lumx/core/js/types';
3
+ export type RawModifier = string | Record<string, boolean> | ClassValue[];
4
+ /**
5
+ * Modifier
6
+ * @example 'is-disabled'
7
+ * @example { 'is-disabled': true, 'is-selected': false }
8
+ * @example ['another-class'] // => Added as-is, not as a BEM modifier suffix
9
+ */
10
+ export type Modifier<T extends RawModifier> = T extends string ? KebabCase<T> : T extends ClassValue[] ? T : {
11
+ [K in keyof T as KebabCase<K>]?: boolean;
12
+ };
13
+ /**
14
+ * Generates a BEM (Block Element Modifier) class name string.
15
+ * Combines a base class with optional modifiers and additional classes.
16
+ *
17
+ * @param baseClass - The base BEM class (block or element)
18
+ * @param modifier - Optional modifier as:
19
+ * - string: creates `baseClass--modifier`
20
+ * - object: creates `baseClass--key` for each truthy value
21
+ * - array: passes through as additional classes
22
+ * @param additionalClasses - Optional additional classes to include
23
+ * @param modifierLast - If true, appends modifier classes after additional classes (default: false)
24
+ * @returns Combined class name string
25
+ *
26
+ * @example
27
+ * generateBEMClass('button'); // 'button'
28
+ * generateBEMClass('button', 'primary'); // 'button button--primary'
29
+ * generateBEMClass('button', { active: true, disabled: false }); // 'button button--active'
30
+ * generateBEMClass('button', 'primary', 'my-class'); // 'button button--primary my-class'
31
+ */
32
+ export declare function generateBEMClass<B extends string, M extends RawModifier>(baseClass: KebabCase<B>, modifier?: Modifier<M>, additionalClasses?: ClassValue | ClassValue[], modifierLast?: boolean): string;
@@ -0,0 +1,48 @@
1
+ import classnames from 'classnames';
2
+
3
+ function parseModifier(baseClass, modifier) {
4
+ const classes = [];
5
+ if (typeof modifier === 'string') {
6
+ classes.push(`${baseClass}--${modifier}`);
7
+ }
8
+ else if (Array.isArray(modifier)) {
9
+ return modifier;
10
+ }
11
+ else if (modifier && typeof modifier === 'object') {
12
+ for (const [key, value] of Object.entries(modifier)) {
13
+ if (value)
14
+ classes.push(`${baseClass}--${key}`);
15
+ }
16
+ }
17
+ return classes;
18
+ }
19
+ /**
20
+ * Generates a BEM (Block Element Modifier) class name string.
21
+ * Combines a base class with optional modifiers and additional classes.
22
+ *
23
+ * @param baseClass - The base BEM class (block or element)
24
+ * @param modifier - Optional modifier as:
25
+ * - string: creates `baseClass--modifier`
26
+ * - object: creates `baseClass--key` for each truthy value
27
+ * - array: passes through as additional classes
28
+ * @param additionalClasses - Optional additional classes to include
29
+ * @param modifierLast - If true, appends modifier classes after additional classes (default: false)
30
+ * @returns Combined class name string
31
+ *
32
+ * @example
33
+ * generateBEMClass('button'); // 'button'
34
+ * generateBEMClass('button', 'primary'); // 'button button--primary'
35
+ * generateBEMClass('button', { active: true, disabled: false }); // 'button button--active'
36
+ * generateBEMClass('button', 'primary', 'my-class'); // 'button button--primary my-class'
37
+ */
38
+ function generateBEMClass(baseClass, modifier, additionalClasses, modifierLast) {
39
+ if (!modifier && !additionalClasses) {
40
+ return baseClass;
41
+ }
42
+ if (modifierLast) {
43
+ return classnames(baseClass, additionalClasses, modifier && parseModifier(baseClass, modifier));
44
+ }
45
+ return classnames(baseClass, modifier && parseModifier(baseClass, modifier), additionalClasses);
46
+ }
47
+
48
+ export { generateBEMClass };
@@ -0,0 +1,2 @@
1
+ export { block } from './block';
2
+ export { element } from './element';
@@ -0,0 +1,2 @@
1
+ export { block } from './block.js';
2
+ export { element } from './element.js';
@@ -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 | undefined;
18
+ /**
19
+ * Generates a Lumx background color class name for the given color and variant.
20
+ *
21
+ * @param col - The color palette name (e.g., 'primary', 'dark', 'light')
22
+ * @param variant - 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: (col?: ColorWithVariants, variant?: ColorVariant) => string | undefined;
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 | undefined;
@@ -0,0 +1,52 @@
1
+ import { ColorVariant } from '../../../constants/index.js';
2
+ import { resolveColorWithVariants } from '../../color/resolveColorWithVariants.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
+ if (!propColor)
21
+ return undefined;
22
+ const [cColor, cColorVariant = ColorVariant.N] = resolveColorWithVariants(propColor, propColorVariant);
23
+ return `lumx-color-${type}-${cColor}-${cColorVariant}`;
24
+ }
25
+ /**
26
+ * Generates a Lumx background color class name for the given color and variant.
27
+ *
28
+ * @param col - The color palette name (e.g., 'primary', 'dark', 'light')
29
+ * @param variant - The color variant (e.g., 'L1', 'L2', 'D1', 'N')
30
+ * @returns The Lumx background color class name
31
+ *
32
+ * @example
33
+ * background('dark', 'L2'); // 'lumx-color-background-dark-L2'
34
+ * background('primary', 'N'); // 'lumx-color-background-primary-N'
35
+ */
36
+ const background = (col, variant) => color('background', col, variant);
37
+ /**
38
+ * Generates a Lumx font color class name for the given color and variant.
39
+ *
40
+ * @param propColor - The color palette name (e.g., 'primary', 'dark') with optional variant suffix (e.g., 'primary-L2')
41
+ * @param propColorVariant - Optional color variant override (e.g., 'L1', 'L2', 'D1', 'N')
42
+ * @returns The Lumx font color class name or undefined if no color is provided
43
+ *
44
+ * @example
45
+ * font('dark', 'L2'); // 'lumx-color-font-dark-L2'
46
+ * font('primary-L2'); // 'lumx-color-font-primary-L2'
47
+ * font('primary'); // 'lumx-color-font-primary-N'
48
+ * font(undefined); // undefined
49
+ */
50
+ const font = (propColor, propColorVariant) => color('font', propColor, propColorVariant);
51
+
52
+ export { background, color, font };
@@ -1,6 +1,5 @@
1
- export { handleBasicClasses } from './handleBasicClasses';
2
- export { getBasicClass } from './getBasicClass';
3
- export { getRootClassName } from './getRootClassName';
4
- export { getTypographyClassName } from './getTypographyClassName';
5
- export { fontColorClass } from './fontColorClass';
6
- export { resolveColorWithVariants } from './resolveColorWithVariants';
1
+ export * from './color';
2
+ export * from './typography';
3
+ export * from './spacing';
4
+ export * from './visually-hidden';
5
+ export * as bem from './bem';
@@ -1,6 +1,6 @@
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';
1
+ export { background, color, font } from './color/index.js';
2
+ export { typography } from './typography/index.js';
3
+ export { margin, margins, padding, paddings, spacing, spacings } from './spacing/index.js';
4
+ export { visuallyHidden } from './visually-hidden/index.js';
5
+ import * as index from './bem/index.js';
6
+ export { index as bem };
@@ -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 const 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,76 @@
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
+ const 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) => {
35
+ return classnames(spacingConfigs.map((spa) => spacing(spa.type, spa.direction, spa.size)));
36
+ };
37
+ /**
38
+ * Returns a lumx margin classname for the given direction and size. For example, for
39
+ * arguments direction='right', size='regular' it returns lumx-spacing-margin-right-regular
40
+ * @param direction - Direction
41
+ * @param size - Size
42
+ * @returns string
43
+ */
44
+ const margin = (direction, size) => spacing('margin', direction, size);
45
+ /**
46
+ * Returns a list of lumx margin classnames for the given directions and sizes. For example, for
47
+ * arguments [
48
+ * { direction: 'right', size: 'regular'},
49
+ * { direction: 'left', size: 'big'},
50
+ * ]
51
+ * it returns lumx-spacing-margin-right-regular lumx-spacing-margin-left-big
52
+ * @param marginConfigs - Array of padding configurations with direction and size
53
+ * @returns string
54
+ */
55
+ const margins = (marginConfigs) => spacings(marginConfigs.map(({ direction, size }) => ({ type: 'margin', direction, size })));
56
+ /**
57
+ * Returns a lumx padding classname for the given direction and size. For example, for
58
+ * arguments direction='right', size='regular' it returns lumx-spacing-padding-right-regular
59
+ * @param direction - Direction
60
+ * @param size - Size
61
+ * @returns string
62
+ */
63
+ const padding = (direction, size) => spacing('padding', direction, size);
64
+ /**
65
+ * Returns a list of lumx padding classnames for the given directions and sizes. For example, for
66
+ * arguments [
67
+ * { direction: 'right', size: 'regular'},
68
+ * { direction: 'left', size: 'big'},
69
+ * ]
70
+ * it returns lumx-spacing-padding-right-regular lumx-spacing-padding-left-big
71
+ * @param paddingConfigs - Array of padding configurations with direction and size
72
+ * @returns Combined padding classnames as a string
73
+ */
74
+ const paddings = (paddingConfigs) => spacings(paddingConfigs.map(({ direction, size }) => ({ type: 'padding', direction, size })));
75
+
76
+ 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 | undefined;
@@ -0,0 +1,11 @@
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
+ if (!typo)
7
+ return undefined;
8
+ return `lumx-typography-${typo}`;
9
+ }
10
+
11
+ 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,9 @@
1
+ import { VISUALLY_HIDDEN } from '../../../constants/index.js';
2
+
3
+ /**
4
+ * Visually hidden class name.
5
+ * Used to hide elements from view but keep them readable from screen readers
6
+ */
7
+ const visuallyHidden = () => VISUALLY_HIDDEN;
8
+
9
+ export { visuallyHidden };
@@ -0,0 +1 @@
1
+ export { resolveColorWithVariants } from './resolveColorWithVariants';
@@ -0,0 +1 @@
1
+ export { resolveColorWithVariants } from './resolveColorWithVariants.js';
@@ -1,3 +1,3 @@
1
- import { ColorPalette, ColorVariant, ColorWithVariants } from '../../constants';
1
+ import type { ColorPalette, ColorVariant, ColorWithVariants } from '../../constants';
2
2
  /** Resolve color & color variant from a `ColorWithVariants` and optionally a `ColorVariant`. */
3
3
  export declare function resolveColorWithVariants(colorWithVariants?: ColorWithVariants, colorVariant?: ColorVariant): [color?: ColorPalette, colorVariant?: ColorVariant];
@@ -1,2 +1,3 @@
1
- export * from './className';
1
+ export * as cls from './className';
2
+ export * from './color';
2
3
  export * from './events';
package/js/utils/index.js CHANGED
@@ -1,8 +1,5 @@
1
- export { handleBasicClasses } from './className/handleBasicClasses.js';
2
- export { getBasicClass } from './className/getBasicClass.js';
3
- export { getRootClassName } from './className/getRootClassName.js';
4
- export { getTypographyClassName } from './className/getTypographyClassName.js';
5
- export { fontColorClass } from './className/fontColorClass.js';
6
- export { resolveColorWithVariants } from './className/resolveColorWithVariants.js';
1
+ import * as index from './className/index.js';
2
+ export { index as cls };
3
+ export { resolveColorWithVariants } from './color/resolveColorWithVariants.js';
7
4
  export { onButtonPressed, onEnterPressed, onEscapePressed } from './events/keyboard.js';
8
5
  export { detectHorizontalSwipe } from './events/swipe.js';
package/package.json CHANGED
@@ -29,13 +29,13 @@
29
29
  "url": "git+https://github.com/lumapps/design-system.git"
30
30
  },
31
31
  "scripts": {
32
- "generate:design-tokens": "yarn node style-dictionary",
32
+ "generate:design-tokens": "yarn node style-dictionary/index.cjs",
33
33
  "build": "rollup -c",
34
34
  "test": "vitest run",
35
35
  "update-version-changelog": "yarn version-changelog ../../CHANGELOG.md"
36
36
  },
37
37
  "sideEffects": false,
38
- "version": "3.20.1-alpha.42",
38
+ "version": "3.20.1-alpha.44",
39
39
  "devDependencies": {
40
40
  "@rollup/plugin-typescript": "^12.3.0",
41
41
  "@types/react": "^17.0.2",
@@ -1,6 +0,0 @@
1
- import { ColorVariant, ColorWithVariants } from '../../constants';
2
- /**
3
- * Returns the classname associated to the given color and variant.
4
- * For example, for 'dark' and 'L2' it returns `lumx-color-font-dark-L2`
5
- */
6
- export declare function fontColorClass(propColor?: ColorWithVariants, propColorVariant?: ColorVariant): string | undefined;
@@ -1,15 +0,0 @@
1
- import { ColorVariant } from '../../constants/index.js';
2
- import { resolveColorWithVariants } from './resolveColorWithVariants.js';
3
-
4
- /**
5
- * Returns the classname associated to the given color and variant.
6
- * For example, for 'dark' and 'L2' it returns `lumx-color-font-dark-L2`
7
- */
8
- function fontColorClass(propColor, propColorVariant) {
9
- if (!propColor)
10
- return undefined;
11
- const [color, colorVariant = ColorVariant.N] = resolveColorWithVariants(propColor, propColorVariant);
12
- return `lumx-color-font-${color}-${colorVariant}`;
13
- }
14
-
15
- export { fontColorClass };
@@ -1,13 +0,0 @@
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;
@@ -1,27 +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
- function getBasicClass({ prefix, type, value, }) {
13
- if (isBoolean(value)) {
14
- if (!value) {
15
- // False value should not return a class.
16
- return '';
17
- }
18
- const booleanPrefixes = ['has', 'is'];
19
- if (booleanPrefixes.some((booleanPrefix) => type.toString().startsWith(booleanPrefix))) {
20
- return `${prefix}--${kebabCase(type)}`;
21
- }
22
- return `${prefix}--is-${kebabCase(type)}`;
23
- }
24
- return `${prefix}--${kebabCase(type)}-${value}`;
25
- }
26
-
27
- export { getBasicClass };
@@ -1,11 +0,0 @@
1
- /**
2
- * Get the name of the root CSS class of a component based on its name.
3
- *
4
- * @param componentName The name of the component. This name should contains the component prefix and be
5
- * written in PascalCase.
6
- * @param subComponent Whether the current component is a sub component, if true, define the class according
7
- * to BEM standards.
8
- * @return The name of the root CSS class. This classname include the CSS classname prefix and is written in
9
- * lower-snake-case.
10
- */
11
- export declare function getRootClassName(componentName: string, subComponent?: boolean): string;
@@ -1,24 +0,0 @@
1
- import kebabCase from 'lodash/kebabCase';
2
- import { CSS_PREFIX } from '../../constants/index.js';
3
-
4
- // See https://regex101.com/r/YjS1uI/3
5
- const LAST_PART_CLASSNAME = /^(.*)-(.+)$/gi;
6
- /**
7
- * Get the name of the root CSS class of a component based on its name.
8
- *
9
- * @param componentName The name of the component. This name should contains the component prefix and be
10
- * written in PascalCase.
11
- * @param subComponent Whether the current component is a sub component, if true, define the class according
12
- * to BEM standards.
13
- * @return The name of the root CSS class. This classname include the CSS classname prefix and is written in
14
- * lower-snake-case.
15
- */
16
- function getRootClassName(componentName, subComponent) {
17
- const formattedClassName = `${CSS_PREFIX}-${kebabCase(componentName)}`;
18
- if (subComponent) {
19
- return formattedClassName.replace(LAST_PART_CLASSNAME, '$1__$2');
20
- }
21
- return formattedClassName;
22
- }
23
-
24
- export { getRootClassName };
@@ -1,6 +0,0 @@
1
- import { Typography } from '../../constants';
2
- /**
3
- * Returns the classname associated to the given typography.
4
- * For example, for `Typography.title` it returns `lumx-typography-title`
5
- */
6
- export declare const getTypographyClassName: (typography: Typography) => string;
@@ -1,9 +0,0 @@
1
- /**
2
- * Returns the classname associated to the given typography.
3
- * For example, for `Typography.title` it returns `lumx-typography-title`
4
- */
5
- const getTypographyClassName = (typography) => {
6
- return `lumx-typography-${typography}`;
7
- };
8
-
9
- export { getTypographyClassName };
@@ -1,15 +0,0 @@
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;
@@ -1,41 +0,0 @@
1
- import classNames from 'classnames';
2
- import isBoolean from 'lodash/isBoolean';
3
- import isEmpty from 'lodash/isEmpty';
4
- import { getBasicClass } from './getBasicClass.js';
5
-
6
- /**
7
- * Enhance isEmpty method to also works with numbers.
8
- *
9
- * @param value The value to check.
10
- * @return Whether the input value is empty or != 0.
11
- */
12
- const _isEmpty = (value) => {
13
- if (typeof value === 'number') {
14
- return value === 0;
15
- }
16
- return isEmpty(value);
17
- };
18
- /**
19
- * Return all basic LumX CSS classes which are available for every components.
20
- *
21
- * @see {@link /src/components/index.d.ts} for the possible values of each parameter.
22
- *
23
- * @param prefix The class name prefix for the generated CSS class.
24
- * @param props All the other props you want to generate a class.
25
- * The rule of thumb: the key is the name of the prop in the class, the value a string that will
26
- * be used in the classname to represent the value of the given prop.
27
- * @return All LumX basic CSS classes.
28
- */
29
- function handleBasicClasses({ prefix, ...props }) {
30
- const otherClasses = {};
31
- if (!isEmpty(props)) {
32
- Object.keys(props).forEach((prop) => {
33
- otherClasses[getBasicClass({ prefix, type: prop, value: props[prop] })] = isBoolean(props[prop])
34
- ? props[prop]
35
- : !_isEmpty(props[prop]);
36
- });
37
- }
38
- return classNames(prefix, otherClasses);
39
- }
40
-
41
- export { handleBasicClasses };