Skip to content

Commit 40c7f2e

Browse files
authored
Merge pull request #758 from lumapps/chore/color-css-variables
chore(color): always use colors css variables
2 parents 50f040a + f9fc342 commit 40c7f2e

23 files changed

+1644
-6180
lines changed

CHANGELOG.md

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

88
## [Unreleased]
99

10+
### Changed
11+
12+
- Always use colors css variables.
13+
1014
## [2.1.9][] - 2021-12-15
1115

1216
### Fixed

packages/lumx-core/src/css/design-tokens.css

Lines changed: 171 additions & 602 deletions
Large diffs are not rendered by default.

packages/lumx-core/src/js/constants/design-tokens.ts

Lines changed: 935 additions & 4799 deletions
Large diffs are not rendered by default.

packages/lumx-core/src/scss/_design-tokens.scss

Lines changed: 175 additions & 607 deletions
Large diffs are not rendered by default.
Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,7 @@
11
@function lumx-color-variant($color, $variant) {
22
@if map-has-key($lumx-color-palette, $color) {
3-
@if $color == 'primary' or $color == 'secondary' {
4-
@return var(--lumx-color-#{$color}-#{$variant});
5-
} @else {
6-
@return map-get(map-get($lumx-color-palette, $color), $variant);
7-
}
3+
@return var(--lumx-color-#{$color}-#{$variant});
84
} @else {
9-
@return map-get(map-get($lumx-color-palette, 'dark'), $variant);
5+
@return var(--lumx-color-dark-N);
106
}
117
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
const StyleDictionary = require("style-dictionary");
2+
3+
/**
4+
* Transform group:
5+
*/
6+
const name = "transform-group-custom";
7+
StyleDictionary.registerTransformGroup({
8+
name,
9+
transforms: [
10+
require("./utils/_lumx-variables"),
11+
require("./utils/_color-attributes"),
12+
require("./utils/_color-rgba-value"),
13+
require("./utils/_css-prefer-variable")
14+
]
15+
});
16+
module.exports = name;

packages/lumx-core/style-dictionary/config/gen-css-variables.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
const path = require('path');
2-
const transformGroup = require('./utils/_css-transform-group');
2+
const transformGroup = require('./_transform-group');
33

44
module.exports = () => {
55
const baseDir = `${__dirname}/../`;

packages/lumx-core/style-dictionary/config/gen-scss-variables.js

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
const StyleDictionary = require('style-dictionary');
22
const path = require('path');
3-
const transformGroup = require('./utils/_css-transform-group');
3+
const transformGroup = require('./_transform-group');
44

55
/**
66
* SCSS generator

packages/lumx-core/style-dictionary/config/gen-ts-variables.js

Lines changed: 3 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,15 +1,7 @@
11
const StyleDictionary = require('style-dictionary');
22
const path = require('path');
33
const pickFieldsInTree = require('./utils/_pickFieldsInTree');
4-
5-
/**
6-
* Transform group:
7-
*/
8-
const transformGroup = 'ts-custom';
9-
StyleDictionary.registerTransformGroup({
10-
name: transformGroup,
11-
transforms: ['attribute/cti', 'name/cti/pascal', require('./utils/_color-opacity'), 'color/css', 'attribute/color'],
12-
});
4+
const transformGroup = require('./_transform-group');
135

146
/**
157
* Typescript generator:
@@ -24,7 +16,7 @@ StyleDictionary.registerFormat({
2416
return `
2517
${require('./utils/_genHeader')()}
2618
27-
export const DESIGN_TOKENS = ${JSON.stringify(properties, null, 2)}
19+
export const DESIGN_TOKENS = ${JSON.stringify(properties)}
2820
`;
2921
},
3022
});
@@ -47,11 +39,9 @@ module.exports = () => {
4739
'version',
4840
'comment',
4941
'value',
50-
'attributes.category',
51-
'attributes.type',
52-
'attributes.item',
5342
'attributes.hex',
5443
'attributes.rgb',
44+
'$aliasedFrom'
5545
],
5646
},
5747
],
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
const StyleDictionary = require("style-dictionary");
2+
const tinycolor2 = require("tinycolor2");
3+
4+
/**
5+
* Color value transform to RGBA object with added opacity if provided.
6+
*/
7+
const name = "color/attributes";
8+
9+
StyleDictionary.registerTransform({
10+
name,
11+
type: "attribute",
12+
matcher: (prop) => /\bcolor\b/.exec(prop.name),
13+
transformer: ({ value, attributes = {}, opacity = 1 }) => {
14+
const color = tinycolor2(value);
15+
if (!color.getFormat() || color.getFormat() === "name") {
16+
// Skip if format "name" or undefined.
17+
return attributes;
18+
}
19+
20+
const colorWithAlpha = color.setAlpha(opacity);
21+
return { ...attributes, rgb: colorWithAlpha.toRgb(), hex: colorWithAlpha.toHex() };
22+
}
23+
});
24+
module.exports = name;

0 commit comments

Comments
 (0)