Skip to content

Commit 57644cc

Browse files
authored
Merge pull request #1349 from lumapps/chore/utilities-to-core
chore(lumx): move className utilities into lumx/core
2 parents 132b1bc + 84c6a53 commit 57644cc

File tree

109 files changed

+231
-221
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

109 files changed

+231
-221
lines changed

CHANGELOG.md

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
1111

1212
- `@lumx/core`
1313
- Moved all non React related types and enums into the package
14+
- Moved `className` utilities into the package
1415
- `@lumx/react`:
1516
- Import types and constants from `@lumx/core` and re-export
17+
- Import `className` utilities from `@lumx/core`
1618

1719
## [3.19.0][] - 2025-11-07
1820

packages/lumx-core/package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@
3838
"@rollup/plugin-commonjs": "^19.0.2",
3939
"@rollup/plugin-terser": "^0.4.4",
4040
"@rollup/plugin-typescript": "^12.1.4",
41+
"@types/react": "^17.0.2",
4142
"autoprefixer": "^9.7.4",
4243
"glob": "^7.1.6",
4344
"postcss": "^8.5.6",

packages/lumx-react/src/utils/className/fontColorClass.test.ts renamed to packages/lumx-core/src/js/utils/className/fontColorClass.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { fontColorClass } from '@lumx/react/utils/className/fontColorClass';
1+
import { fontColorClass } from './fontColorClass';
22

33
describe(fontColorClass, () => {
44
it('should get lumx class for font color', () => {

packages/lumx-react/src/utils/className/fontColorClass.ts renamed to packages/lumx-core/src/js/utils/className/fontColorClass.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
1-
import { ColorVariant, ColorWithVariants } from '@lumx/react';
2-
import { resolveColorWithVariants } from '@lumx/react/utils/className';
1+
import { ColorVariant, ColorWithVariants } from '../../constants';
2+
import { resolveColorWithVariants } from './resolveColorWithVariants';
33

44
/**
55
* Returns the classname associated to the given color and variant.

packages/lumx-react/src/utils/className/getBasicClass.test.ts renamed to packages/lumx-core/src/js/utils/className/getBasicClass.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getBasicClass } from '@lumx/core/js/utils';
1+
import { getBasicClass } from './getBasicClass';
22

33
describe(getBasicClass, () => {
44
it('should return correct basic CSS class for different types and values', () => {
Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,36 @@
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+
}

packages/lumx-react/src/utils/className/getRootClassName.test.ts renamed to packages/lumx-core/src/js/utils/className/getRootClassName.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getRootClassName } from '@lumx/react/utils/className/getRootClassName';
1+
import { getRootClassName } from './getRootClassName';
22

33
describe(getRootClassName, () => {
44
it('should transform the component name into a lumx class', () => {

packages/lumx-react/src/utils/className/getRootClassName.ts renamed to packages/lumx-core/src/js/utils/className/getRootClassName.ts

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
1-
import { CSS_PREFIX } from '@lumx/core/js/constants';
21
import kebabCase from 'lodash/kebabCase';
32

3+
import { CSS_PREFIX } from '../../constants';
4+
45
// See https://regex101.com/r/YjS1uI/3
56
const LAST_PART_CLASSNAME = /^(.*)-(.+)$/gi;
67

packages/lumx-react/src/utils/className/getTypographyClassName.test.ts renamed to packages/lumx-core/src/js/utils/className/getTypographyClassName.test.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { getTypographyClassName } from '@lumx/react/utils/className/getTypographyClassName';
1+
import { getTypographyClassName } from './getTypographyClassName';
22

33
describe(getTypographyClassName, () => {
44
it('should generate lumx typography class', () => {

packages/lumx-react/src/utils/className/getTypographyClassName.ts renamed to packages/lumx-core/src/js/utils/className/getTypographyClassName.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
import { Typography } from '@lumx/react';
1+
import { Typography } from '../../constants';
22

33
/**
44
* Returns the classname associated to the given typography.

0 commit comments

Comments
 (0)