Skip to content

Commit 172639e

Browse files
committed
fix(themes): angular element styles don't work
Scope the CSS variables to a dynamic selector based on the prefix metadata stored in the component theme schema.
1 parent 06c0c62 commit 172639e

Some content is hidden

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

45 files changed

+299
-69
lines changed

package-lock.json

Lines changed: 4 additions & 4 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
@@ -75,7 +75,7 @@
7575
"@types/source-map": "0.5.2",
7676
"express": "^5.1.0",
7777
"fflate": "^0.8.1",
78-
"igniteui-theming": "^20.0.0",
78+
"igniteui-theming": "^21.0.0-beta.1",
7979
"igniteui-trial-watermark": "^3.1.0",
8080
"lodash-es": "^4.17.21",
8181
"rxjs": "^7.8.2",

projects/igniteui-angular-elements/src/themes/_util.scss

Lines changed: 40 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -29,9 +29,9 @@ $elements-selector-prefix: 'igc';
2929
$prefix: 'ig';
3030
$result: $theme_schema;
3131

32-
@if map.has-key($theme_schema, "name") {
33-
$name: map.get($theme_schema, "name");
34-
$selector: map.get($theme_schema, "selector") or $name;
32+
@if map.has-key($theme_schema, 'name') {
33+
$name: map.get($theme_schema, 'name');
34+
$element-prefix: map.get($theme_schema, '_meta', 'element-prefix');
3535
$modified: ();
3636

3737
// @debug "name: #{$name}";
@@ -40,29 +40,54 @@ $elements-selector-prefix: 'igc';
4040
$name: list.nth(string.split($name, 'igx-'), -1);
4141
$name: '#{$elements-var-prefix}-#{$name}';
4242
// @debug "name after: #{$name}";
43-
$modified: map.merge($modified, (name: $name));
43+
$modified: map.merge(
44+
$modified,
45+
(
46+
name: $name,
47+
)
48+
);
4449
}
4550

4651
// For exposed components also modify selector with updated element prefix:
47-
@if list.index(vars.$allowed, map.get($theme_schema, "name")) {
48-
// @debug "selector before: #{$selector}";
49-
$selector: updateSelectors($selector);
50-
// @debug "selector after: #{$selector}";
52+
@if list.index(vars.$allowed, map.get($theme_schema, 'name')) {
53+
// @debug "selector before: #{$element-prefix}";
54+
$element-prefix: $elements-selector-prefix;
55+
// @debug "selector after: #{$element-prefix}";
5156
}
5257

53-
$modified: map.merge($modified, (selector: $selector));
58+
$modified: map.merge(
59+
$modified,
60+
(
61+
_meta: map.merge(
62+
map.get($theme_schema, '_meta'),
63+
(
64+
'element-prefix': $element-prefix,
65+
)
66+
),
67+
)
68+
);
5469

5570
@if map.has-key($theme_schema, 'themes') {
5671
$themes: map.get($theme_schema, 'themes');
5772
$newThemes: ();
5873
@each $name, $sub_schema in $themes {
59-
$newThemes: map.set($newThemes, $name, updateElementName($sub_schema));
74+
$newThemes: map.set(
75+
$newThemes,
76+
$name,
77+
updateElementName($sub_schema)
78+
);
6079
}
61-
$modified: map.merge($modified, (themes: $newThemes));
80+
$modified: map.merge(
81+
$modified,
82+
(
83+
themes: $newThemes,
84+
)
85+
);
6286
}
6387

6488
$result: map.merge($result, $modified);
6589
}
90+
6691
@return $result;
6792
}
6893

@@ -72,9 +97,9 @@ $elements-selector-prefix: 'igc';
7297
/// @return {String} - Updated selector(s) with `igc-` prefixed equivalents
7398
@function updateSelectors($selector) {
7499
$result: ();
75-
$selectors: string.split($selector, ", ");
100+
// $selectors: string.split($selector, ", ");
76101

77-
@each $sel in $selectors {
102+
@each $sel in $selector {
78103
$result: list.append($result, $sel, comma);
79104

80105
@if string.index($sel, 'igx-') == 1 {
@@ -84,7 +109,7 @@ $elements-selector-prefix: 'igc';
84109
}
85110
}
86111

87-
@return "#{$result}";
112+
@return '#{$result}';
88113
}
89114

90115
/// Generates an Ignite UI for Angular Elements global theme.
@@ -109,6 +134,6 @@ $elements-selector-prefix: 'igc';
109134
$palette: $palette,
110135
$exclude: $exclude,
111136
$schema: $schema,
112-
$theme-handler: meta.get-function("updateElementName")
137+
$theme-handler: meta.get-function('updateElementName')
113138
);
114139
}

projects/igniteui-angular/package.json

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@
7373
"tslib": "^2.3.0",
7474
"igniteui-trial-watermark": "^3.1.0",
7575
"lodash-es": "^4.17.21",
76-
"igniteui-theming": "^20.0.0",
76+
"igniteui-theming": "^21.0.0-beta.1",
7777
"@igniteui/material-icons-extended": "^3.1.0"
7878
},
7979
"peerDependencies": {

projects/igniteui-angular/src/lib/core/styles/base/_functions.scss

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -63,3 +63,12 @@
6363
}
6464
@return $items;
6565
}
66+
67+
/// Prefixes a CSS selector with the given string.
68+
/// @access private
69+
/// @param {String} $prefix - The prefix to add.
70+
/// @param {String} $selector - The selector to be prefixed.
71+
/// @return {String} - The prefixed selector.
72+
@function prefix-selector($prefix, $selector) {
73+
@return string.insert($selector, #{$prefix}-, 1);
74+
}

projects/igniteui-angular/src/lib/core/styles/components/avatar/_avatar-theme.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
/// @see {mixin} css-vars
77
/// @param {Map} $theme - The theme used to style the component.
88
@mixin avatar($theme) {
9-
@include css-vars($theme, 'igx-avatar');
9+
$prefix: map.get($theme, '_meta', 'element-prefix');
10+
$selectors: (
11+
prefix-selector($prefix, 'avatar'),
12+
);
13+
14+
@include css-vars($theme, $selectors);
1015

1116
$variant: map.get($theme, '_meta', 'theme');
1217

projects/igniteui-angular/src/lib/core/styles/components/badge/_badge-theme.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,12 @@
55
/// @see {mixin} css-vars
66
/// @param {Map} $theme - The theme used to style the component.
77
@mixin badge($theme) {
8-
@include css-vars($theme, 'igx-badge');
8+
$prefix: map.get($theme, '_meta', 'element-prefix');
9+
$selectors: (
10+
prefix-selector($prefix, 'badge'),
11+
);
12+
13+
@include css-vars($theme, $selectors);
914

1015
$variant: map.get($theme, '_meta', 'theme');
1116

projects/igniteui-angular/src/lib/core/styles/components/banner/_banner-theme.scss

Lines changed: 8 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,14 @@
55
/// @see {mixin} css-vars
66
/// @param {Map} $theme - The theme used to style the component.
77
@mixin banner($theme) {
8-
@include css-vars($theme, 'igx-banner, .igx-banner');
8+
$prefix: map.get($theme, '_meta', 'element-prefix');
9+
$selectors: (
10+
prefix-selector($prefix, 'banner'),
11+
#{'.' + prefix-selector($prefix, 'banner')},
12+
);
13+
14+
15+
@include css-vars($theme, $selectors);
916
$variant: map.get($theme, '_meta', 'theme');
1017

1118
%igx-banner-host {

projects/igniteui-angular/src/lib/core/styles/components/bottom-nav/_bottom-nav-theme.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
/// @see {mixin} css-vars
77
/// @param {Map} $theme - The theme used to style the component.
88
@mixin bottom-nav($theme) {
9-
@include css-vars($theme, 'igx-bottom-nav');
9+
$prefix: map.get($theme, '_meta', 'element-prefix');
10+
$selectors: (
11+
prefix-selector($prefix, 'bottom-nav'),
12+
);
13+
14+
@include css-vars($theme, $selectors);
1015

1116
$variant: map.get($theme, '_meta', 'theme');
1217
$menu-height: rem(56px);

projects/igniteui-angular/src/lib/core/styles/components/button-group/_button-group-theme.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66
/// @see {mixin} css-vars
77
/// @param {Map} $theme - The theme used to style the component.
88
@mixin button-group($theme) {
9-
@include css-vars($theme, 'igx-buttongroup');
9+
$prefix: map.get($theme, '_meta', 'element-prefix');
10+
$selectors: (
11+
prefix-selector($prefix, 'buttongroup'),
12+
);
13+
14+
@include css-vars($theme, $selectors);
1015

1116
$group-item-border-thickness: rem(1px);
1217
$group-items-margin: rem(10px, 16px);

0 commit comments

Comments
 (0)