Skip to content

Commit 1d8368f

Browse files
authored
refactor(themes): relative color syntax (#13769)
1 parent 45ed308 commit 1d8368f

File tree

29 files changed

+194
-105
lines changed

29 files changed

+194
-105
lines changed

CHANGELOG.md

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,32 @@ All notable changes for each version of this project will be documented in this
1313
- Added support for vertical alignment. Can be configured via the `vertical` property. Defaults to `false`.
1414
- Added support for showing/hiding the indicator controls (dots). Can be configured via the `indicators` property. Defaults to `true`.
1515

16+
### Themes
17+
- `Palettes`
18+
- All palette colors have been migrated to the [CSS relative colors syntax](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_colors/Relative_colors). This means that color consumed as CSS variables no longer need to be wrapped in an `hsl` function.
19+
20+
Example:
21+
```css
22+
/* 18.1.x and before: */
23+
background: hsl(var(--igx-primary-600));
24+
25+
/* 18.2.0+: */
26+
background: var(--igx-primary-600);
27+
```
28+
29+
This change also opens up the door for declaring the base (500) variants of each color in CSS from any color, including other CSS variables, whereas before the Sass `palette` function was needed to generate color shades from a base color.
30+
31+
Example:
32+
```scss
33+
/* 18.1.x and before: */
34+
$my-palette: palette($primary: #09f, ...);
35+
36+
/* 18.2.0+: */
37+
--ig-primary-500: #09f;
38+
```
39+
40+
This change adds to our continuous effort to make theming configurable in CSS as much as it is in Sass.
41+
1642
#### Scrollbar: New CSS variables
1743

1844
We have introduced new CSS variables to allow for more customizable scrollbars. This enhancement utilizes the available WebKit pseudo-selectors such as `::-webkit-scrollbar-track`. However, please note that these pseudo-selectors are prefixed with `-webkit-` and are only supported in WebKit-based browsers (e.g., Chrome, Safari).

package-lock.json

Lines changed: 5 additions & 5 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"@types/source-map": "0.5.2",
7575
"express": "^4.21.0",
7676
"fflate": "^0.8.1",
77-
"igniteui-theming": "^14.0.0",
77+
"igniteui-theming": "^14.1.0",
7878
"igniteui-trial-watermark": "^3.0.2",
7979
"lodash-es": "^4.17.21",
8080
"rxjs": "^7.8.0",

projects/igniteui-angular/migrations/update-18_2_0/index.spec.ts

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,38 @@ describe(`Update to ${version}`, () => {
8888
);
8989
});
9090

91+
it('should remove hsla and hsl functions', async () => {
92+
appTree.create(
93+
`/testSrc/appPrefix/component/test.component.scss`,
94+
`.custom-body {
95+
color: hsla(var(--ig-primary-A100));
96+
background: hsla(var(--ig-gray-100));
97+
}
98+
99+
.custom-header {
100+
color: hsl(var(--ig-secondary-100));
101+
background: hsl(var(--ig-gray-900));
102+
}`
103+
);
104+
105+
const tree = await schematicRunner
106+
.runSchematic(migrationName, {}, appTree);
107+
108+
expect(
109+
tree.readContent('/testSrc/appPrefix/component/test.component.scss')
110+
).toEqual(
111+
`.custom-body {
112+
color: var(--ig-primary-A100);
113+
background: var(--ig-gray-100);
114+
}
115+
116+
.custom-header {
117+
color: var(--ig-secondary-100);
118+
background: var(--ig-gray-900);
119+
}`
120+
);
121+
});
122+
91123
it('should remove the $border-width property from the badge-theme', async () => {
92124
appTree.create(
93125
`/testSrc/appPrefix/component/test.component.scss`,

projects/igniteui-angular/migrations/update-18_2_0/index.ts

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,43 @@ const version = '18.2.0';
99

1010
export default (): Rule => async (host: Tree, context: SchematicContext) => {
1111
context.logger.info(`Applying migration for Ignite UI for Angular to version ${version}`);
12+
1213
const update = new UpdateChanges(__dirname, host, context);
14+
15+
const IG_COLORS = [
16+
'primary-',
17+
'primary-A',
18+
'secondary-',
19+
'secondary-A',
20+
'gray-',
21+
'surface-',
22+
'surface-A',
23+
'info-',
24+
'info-A',
25+
'success-',
26+
'success-A',
27+
'warn-',
28+
'warn-A',
29+
'error-',
30+
'error-A'
31+
];
32+
33+
const hslaColor = 'hsla?\\(var\\(--ig-attr(\\d)00\\)\\)';
34+
35+
for (const entryPath of update.sassFiles) {
36+
let content = host.read(entryPath).toString();
37+
IG_COLORS.forEach(color => {
38+
let prop = hslaColor.replace('attr', color);
39+
const regex = new RegExp(prop, 'g');
40+
if (regex.test(content)) {
41+
let newColor = prop.replace(/hsla\?\\\(var\\\(--ig-/g, 'var\(--ig-');
42+
newColor = newColor.replace('(\\d)', '$1');
43+
newColor = newColor.replace('\\)\\)', ')');
44+
content = content.replace(regex, newColor);
45+
host.overwrite(entryPath, content);
46+
}
47+
});
48+
}
49+
1350
update.applyChanges();
1451
};

projects/igniteui-angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -74,7 +74,7 @@
7474
"igniteui-trial-watermark": "^3.0.2",
7575
"lodash-es": "^4.17.21",
7676
"uuid": "^9.0.0",
77-
"igniteui-theming": "^14.0.0",
77+
"igniteui-theming": "^14.1.0",
7878
"@igniteui/material-icons-extended": "^3.0.0"
7979
},
8080
"peerDependencies": {

projects/igniteui-angular/src/lib/services/overlay/overlay.spec.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3239,7 +3239,7 @@ describe('igxOverlay', () => {
32393239
expect(wrapperElement).toBeDefined();
32403240
const styles = css(wrapperElement);
32413241
expect(styles.findIndex(
3242-
(e) => e.includes('--background-color: var(--igx-overlay-background-color, hsla(var(--ig-gray-500), 0.54));')))
3242+
(e) => e.includes('--background-color: var(--igx-overlay-background-color, hsl(from var(--ig-gray-500) h s l/0.54));')))
32433243
.toBeGreaterThan(-1);
32443244
expect(styles.findIndex(
32453245
(e) => e.includes('background: var(--background-color);')))
@@ -3265,7 +3265,7 @@ describe('igxOverlay', () => {
32653265
.parentElement.getElementsByClassName(CLASS_OVERLAY_WRAPPER_MODAL)[0] as HTMLElement;
32663266
expect(wrapperElement).toBeDefined();
32673267
const styles = css(wrapperElement);
3268-
expect(styles.findIndex((e) => e.includes('--background-color: var(--igx-overlay-background-color, hsla(var(--ig-gray-500), 0.54));'))).toBeGreaterThan(-1);
3268+
expect(styles.findIndex((e) => e.includes('--background-color: var(--igx-overlay-background-color, hsl(from var(--ig-gray-500) h s l/0.54));'))).toBeGreaterThan(-1);
32693269
expect(styles.findIndex((e) => e.includes('background: var(--background-color);'))).toBeGreaterThan(-1);
32703270

32713271
fixture.componentInstance.overlay.detachAll();

src/app/action-strip/action-strip.sample.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@
1919
width: 400px;
2020
height: 200px;
2121
position: relative;
22-
background-color: hsl(var(--ig-gray-200));
22+
background-color: var(--ig-gray-200);
2323
}
2424

2525
.my-action-strip {

src/app/autocomplete/autocomplete.sample.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@
66
max-width: 400px;
77
margin: 0 auto;
88
padding: 16px;
9-
background: hsl(var(--ig-gray-50));
9+
background: var(--ig-gray-50);
1010
border-radius: 4px;
1111
}
1212

src/app/chips/chips.sample.scss

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,7 @@ $padding: 32px;
1717
display: flex;
1818
align-items: center;
1919
justify-content: space-between;
20-
border: 1px solid hsla(var(--ig-gray-300));
20+
border: 1px solid var(--ig-gray-300);
2121
gap: $padding;
2222
margin: 0 auto;
2323

@@ -35,8 +35,8 @@ $padding: 32px;
3535
display: flex;
3636
flex-direction: column;
3737
gap: 8px;
38-
background: hsla(var(--ig-gray-50));
39-
border-left: 1px solid hsla(var(--ig-gray-300));
38+
background: var(--ig-gray-50);
39+
border-left: 1px solid var(--ig-gray-300);
4040
padding: $padding;
4141
}
4242

@@ -58,12 +58,12 @@ $padding: 32px;
5858
justify-content: center;
5959
gap: 4px;
6060
text-decoration: none;
61-
color: hsla(var(--ig-secondary-600));
61+
color: var(--ig-secondary-600);
6262
outline: none;
6363

6464
&:focus,
6565
&:hover {
66-
color: hsla(var(--ig-secondary-300));
66+
color: var(--ig-secondary-300);
6767
}
6868
}
6969
}

0 commit comments

Comments
 (0)