File tree Expand file tree Collapse file tree 3 files changed +37
-12
lines changed Expand file tree Collapse file tree 3 files changed +37
-12
lines changed Original file line number Diff line number Diff line change 16
16
@use ' ./tokens/m2/mat/full-pseudo-checkbox' as tokens-mat-full-pseudo-checkbox ;
17
17
@use ' ./tokens/m2/mat/minimal-pseudo-checkbox' as tokens-mat-minimal-pseudo-checkbox ;
18
18
19
+ $_has-inserted-loaded-marker : false;
20
+
21
+ @mixin _theme-loaded-marker {
22
+ @if not $_has-inserted-loaded-marker {
23
+ $_has-inserted-loaded-marker : true !global;
24
+
25
+ // Marker that is used to determine whether the user has added a theme to their page.
26
+ // Needs to be generated at the root, because themes may be nested inside classes.
27
+ @at-root {
28
+ .mat-theme-loaded-marker {
29
+ display : none ;
30
+ }
31
+ }
32
+ }
33
+ }
34
+
19
35
@mixin base ($theme ) {
20
36
@if inspection .get-theme-version ($theme ) == 1 {
21
37
@include _theme-from-tokens (inspection .get-theme-tokens ($theme , base ));
26
42
@include optgroup-theme .base ($theme );
27
43
@include pseudo-checkbox-theme .base ($theme );
28
44
}
45
+
46
+ // The marker is a concrete style no matter which Material version we're targeting.
47
+ @include _theme-loaded-marker ;
29
48
}
30
49
31
50
@mixin color ($theme ) {
54
73
}
55
74
}
56
75
}
57
-
58
- // TODO(crisbeto): move this into the base.
59
- // Marker that is used to determine whether the user has added a theme to their page.
60
- @at-root {
61
- .mat-theme-loaded-marker {
62
- display : none ;
63
- }
64
- }
65
76
}
66
77
67
78
@mixin typography ($theme ) {
127
138
}
128
139
}
129
140
}
141
+
142
+ // The marker is a concrete style no matter which Material version we're targeting.
143
+ @include _theme-loaded-marker ;
130
144
}
131
145
132
146
@mixin _theme-from-tokens ($tokens , $options ...) {
Original file line number Diff line number Diff line change 1
- import { parse } from 'postcss' ;
1
+ import { parse , Rule } from 'postcss' ;
2
2
import { compileString } from 'sass' ;
3
3
import { runfiles } from '@bazel/runfiles' ;
4
4
import * as path from 'path' ;
@@ -68,14 +68,18 @@ describe('M3 theme', () => {
68
68
root . walkRules ( rule => {
69
69
selectors . push ( rule . selector ) ;
70
70
} ) ;
71
- expect ( selectors ) . toEqual ( [ 'html' ] ) ;
71
+ expect ( selectors ) . toEqual ( [ 'html' , '.mat-theme-loaded-marker' ] ) ;
72
72
} ) ;
73
73
74
74
it ( 'should only emit CSS variables' , ( ) => {
75
75
const root = parse ( transpile ( `html { @include mat.all-component-themes($theme); }` ) ) ;
76
76
const nonVarProps : string [ ] = [ ] ;
77
77
root . walkDecls ( decl => {
78
- if ( ! decl . prop . startsWith ( '--' ) ) {
78
+ if (
79
+ ! decl . prop . startsWith ( '--' ) &&
80
+ // Skip the theme loaded marker since it can't be a variable.
81
+ ( decl . parent as Rule ) . selector !== '.mat-theme-loaded-marker'
82
+ ) {
79
83
nonVarProps . push ( decl . prop ) ;
80
84
}
81
85
} ) ;
Original file line number Diff line number Diff line change @@ -472,7 +472,14 @@ describe('theming inspection api', () => {
472
472
div {
473
473
@include mat.all-component-themes($theme);
474
474
}` ) ;
475
- expect ( css ) . toBe ( '' ) ;
475
+ expect ( css ) . toBe (
476
+ [
477
+ // The marker is always included.
478
+ `.mat-theme-loaded-marker {` ,
479
+ ` display: none;` ,
480
+ `}` ,
481
+ ] . join ( '\n' ) ,
482
+ ) ;
476
483
} ) ;
477
484
} ) ;
478
485
} ) ;
You can’t perform that action at this time.
0 commit comments