Skip to content

Commit 27a9e1b

Browse files
authored
Merge pull request #130 from johannesjo/feature/mdc
MDC fixes
2 parents 5b2fb5c + 444a9dd commit 27a9e1b

13 files changed

+693
-629
lines changed

README.md

Lines changed: 3 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -183,42 +183,10 @@ $custom-typography: mat.mat-typography-config(
183183
};
184184
```
185185
186-
## Updating to Angular v15
187-
Angular Material v15 introduces MDC based components, which is basically a re-write for a lot of the available components. If you want to update to Angular v15, you need to update `angular-material-css-vars` to v4+.
186+
## Legacy components support
187+
Angular Material v15 introduces MDC based components, which is basically a re-write for a lot of the available components. `angular-material-css-vars` v5+ only supports MDC components.
188188
189-
With Angular v15, you can decide whether to keep using the legacy components, or to switch to the MDC based components.
190-
191-
### Switch to MDC based components
192-
193-
No further action is required, just import the `init-material-css-vars` mixin like before:
194-
195-
```scss
196-
@use 'angular-material-css-vars/main' as mat-css-main;
197-
198-
@include mat-css-main.init-material-css-vars;
199-
```
200-
201-
### Keep using the legacy components
202-
203-
Please pass the following configuration to the mixin:
204-
205-
```scss
206-
@use 'angular-material-css-vars/main' as mat-css-main;
207-
208-
@include mat-css-main.init-material-css-vars($load-legacy-components: true, $load-mdc-components: false);
209-
```
210-
211-
### Use legacy and MDC based components in parallel
212-
213-
> Warning: this will increase your bundle size significantly
214-
215-
Please pass the following configuration to the mixin:
216-
217-
```scss
218-
@use 'angular-material-css-vars/main' as mat-css-main;
219-
220-
@include mat-css-main.init-material-css-vars($load-legacy-components: true, $load-mdc-components: true);
221-
```
189+
In case you are still using the legacy components, you can use the package [angular-material-css-vars-legacy](https://github.com/json-derulo/angular-material-css-vars-legacy).
222190
223191
## upgrading to angular v12
224192
Angular material v12 interoduces some big changes, which leaves you with two options when upgrading to ng12: You can either stay at angular material v11 and angular-material-css-vars v1.2.0 or you can use v2+ which thanks to @pedrojrivera adds full support for the new version.

package-lock.json

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

package.json

Lines changed: 22 additions & 21 deletions
Original file line numberDiff line numberDiff line change
@@ -26,49 +26,50 @@
2626
"minor-release": "npm run minor-release_",
2727
"major-release_": "run-s lib demo major pub",
2828
"major-release": "npm run major-release_",
29-
"dryBuild": "run-s lib demo"
29+
"dryBuild": "run-s lib demo",
30+
"update": "npx npm-check-updates -u"
3031
},
3132
"dependencies": {
32-
"@angular/animations": "^15.0.0",
33-
"@angular/cdk": "^15.0.0",
34-
"@angular/common": "^15.0.0",
35-
"@angular/compiler": "^15.0.0",
36-
"@angular/core": "^15.0.0",
37-
"@angular/forms": "^15.0.0",
38-
"@angular/material": "^15.0.0",
39-
"@angular/platform-browser": "^15.0.0",
40-
"@angular/platform-browser-dynamic": "^15.0.0",
41-
"@angular/router": "^15.0.0",
42-
"@ctrl/tinycolor": "^3.4.0",
33+
"@angular/animations": "^15.2.8",
34+
"@angular/cdk": "^15.2.8",
35+
"@angular/common": "^15.2.8",
36+
"@angular/compiler": "^15.2.8",
37+
"@angular/core": "^15.2.8",
38+
"@angular/forms": "^15.2.8",
39+
"@angular/material": "^15.2.8",
40+
"@angular/platform-browser": "^15.2.8",
41+
"@angular/platform-browser-dynamic": "^15.2.8",
42+
"@angular/router": "^15.2.8",
43+
"@ctrl/tinycolor": "^3.5.0",
4344
"ngx-color-picker": "^13.0.0",
44-
"rxjs": "~7.5.7",
45-
"tslib": "^2.3.0",
45+
"rxjs": "~7.8.0",
46+
"tslib": "^2.5.0",
4647
"zone.js": "~0.12.0"
4748
},
4849
"devDependencies": {
49-
"@angular-devkit/build-angular": "^15.0.0",
50+
"@angular-devkit/build-angular": "^15.2.6",
5051
"@angular-eslint/builder": "^15.2.1",
5152
"@angular-eslint/eslint-plugin": "^15.2.1",
5253
"@angular-eslint/eslint-plugin-template": "^15.2.1",
5354
"@angular-eslint/schematics": "^15.2.1",
5455
"@angular-eslint/template-parser": "^15.2.1",
55-
"@angular/cli": "^15.0.0",
56-
"@angular/compiler-cli": "^15.0.0",
57-
"@angular/language-service": "^15.0.0",
56+
"@angular/cli": "^15.2.6",
57+
"@angular/compiler-cli": "^15.2.8",
58+
"@angular/language-service": "^15.2.8",
5859
"@types/jasmine": "^4.3.0",
5960
"@typescript-eslint/eslint-plugin": "^5.59.0",
6061
"@typescript-eslint/parser": "^5.59.0",
6162
"copyfiles": "^2.1.1",
6263
"eslint": "^8.39.0",
6364
"gh-pages": "^4.0.0",
6465
"jasmine-core": "^4.5.0",
65-
"karma": "^6.3.16",
66+
"karma": "^6.4.1",
6667
"karma-chrome-launcher": "~3.1.0",
6768
"karma-coverage-istanbul-reporter": "~3.0.2",
6869
"karma-jasmine": "~5.1.0",
6970
"karma-jasmine-html-reporter": "^2.0.0",
70-
"ng-packagr": "^15.0.0",
71+
"ng-packagr": "^15.1.1",
7172
"npm-run-all": "^4.1.5",
72-
"typescript": "~4.8.0"
73+
"typescript": "~4.9.4"
7374
}
7475
}

projects/material-css-vars/src/lib/_internal-helper.scss

Lines changed: 12 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,11 +1,11 @@
11
// used to circumvent node sass issue: https://github.com/sass/node-sass/issues/2251
22
@function rgb($r, $g: null, $b: null ) {
33
@if ($g == null) {
4-
@return unquote('#{$r}');
4+
@return unquote("#{$r}");
55
}
66

77
@if ($g and $b) {
8-
@return unquote('#{$r}, #{$g}, #{$b}');
8+
@return unquote("#{$r}, #{$g}, #{$b}");
99
}
1010

1111
@error "wrong number of arguments";
@@ -14,17 +14,17 @@
1414
// used to circumvent node sass issue: https://github.com/sass/node-sass/issues/2251
1515
@function rgba($r, $g, $b: null, $a: null ) {
1616
@if ($b == null) {
17-
@return unquote('#{$r}, #{$g}');
17+
@return unquote("#{$r}, #{$g}");
1818
}
1919

2020
@if ($b and $a) {
21-
@return unquote('#{$r}, #{$g}, #{$b}, #{$a}');
21+
@return unquote("#{$r}, #{$g}, #{$b}, #{$a}");
2222
}
2323

2424
@error "wrong number of arguments";
2525
}
2626

27-
@function str-replace($string, $search, $replace: '') {
27+
@function str-replace($string, $search, $replace: "") {
2828
$index: str-index($string, $search);
2929

3030
@if $index {
@@ -48,15 +48,15 @@
4848

4949
@function strip-variable($color) {
5050
$var: $color;
51-
@if (str-index($var, 'rgba(')) {
52-
$var: str-replace($var, 'rgba(', '');
51+
@if (str-index($var, "rgba(")) {
52+
$var: str-replace($var, "rgba(", "");
5353
}
54-
@if (str-index($var, 'rgb(')) {
55-
$var: str-replace($var, 'rgb(', '');
54+
@if (str-index($var, "rgb(")) {
55+
$var: str-replace($var, "rgb(", "");
5656
}
57-
@if (str-index($var, 'var(')) {
58-
$var: str-replace($var, ')', ''); // remove excess ")"
59-
$var: $var + ')';
57+
@if (str-index($var, "var(")) {
58+
$var: str-replace($var, ")", ""); // remove excess ")"
59+
$var: $var + ")";
6060
}
6161
@return $var;
6262
}
Lines changed: 20 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,19 @@
1-
@use '@angular/material'as mat;
2-
@use 'internal-helper' as helper;
3-
@use '@angular/material/theming' as theming;
4-
@use 'variables' as variables;
5-
@use 'public-util';
1+
@use "@angular/material" as mat;
2+
@use "variables";
3+
@use "internal-helper";
4+
@use "public-util";
65
// contains main overwrite of `mat-color` to make it all work
7-
// needs to come after '~@angular/material/theming'
8-
@use 'mat-lib-overwrites' as overwrites;
6+
// needs to come after "@angular/material"
7+
@use "mat-lib-overwrites";
98

10-
@mixin init-css-vars($default-theme, $text, $default-foreground, $default-background) {
9+
@mixin init-css-vars($default-theme, $text) {
1110
// init css variables
12-
@include helper.root($text);
13-
@include helper.root($default-theme);
14-
@include helper.root($default-foreground);
15-
@include helper.root($default-background);
11+
@include internal-helper.root($text);
12+
@include internal-helper.root($default-theme);
1613
}
1714

18-
@mixin init-mat-theme($dark-theme-selector, $typography-config: mat.define-typography-config(), $load-mdc-components, $load-legacy-components) {
19-
@if $load-mdc-components {
20-
@include mat.core();
21-
}
22-
@if $load-legacy-components {
23-
@include mat.legacy-core();
24-
}
15+
@mixin init-mat-theme($dark-theme-selector, $typography-config: mat.define-typography-config()) {
16+
@include mat.core();
2517

2618
$primary: mat.define-palette(variables.$palette-primary);
2719
$accent: mat.define-palette(variables.$palette-accent);
@@ -31,32 +23,27 @@
3123
color: (
3224
primary: $primary,
3325
accent: $accent,
34-
warn: $warn
26+
warn: $warn,
3527
),
3628
typography: $typography-config,
37-
density: 0
29+
density: 0,
3830
));
3931

4032
$dark-theme: mat.define-dark-theme((
4133
color: (
4234
primary: $primary,
4335
accent: $accent,
44-
warn: $warn
36+
warn: $warn,
4537
),
4638
typography: $typography-config,
47-
density: 0
39+
density: 0,
4840
));
4941

5042
// set global variable so passed-in content can use the theme
5143
$mat-css-theme: $theme !global; // stays for backwards-compatibility
5244

5345
// NOTE: light theme is the default theme
54-
@if $load-mdc-components {
55-
@include mat.all-component-themes($theme);
56-
}
57-
@if $load-legacy-components {
58-
@include mat.all-legacy-component-themes($theme);
59-
}
46+
@include mat.all-component-themes($theme);
6047

6148
// Fix mat-typography class, see https://github.com/angular/components/issues/26184
6249
@include mat.typography-hierarchy($theme);
@@ -66,19 +53,14 @@
6653
@if $dark-theme-selector {
6754
$mat-css-theme: $dark-theme !global;
6855
#{$dark-theme-selector} {
69-
@if $load-mdc-components {
70-
@include mat.all-component-colors($dark-theme);
71-
}
72-
@if $load-legacy-components {
73-
@include mat.all-legacy-component-colors($dark-theme);
74-
}
56+
@include mat.all-component-colors($dark-theme);
7557
// add content passed in, which can use the $theme variable to apply the dark theme to
7658
// other theme mixins needed by the app
7759
@content($mat-css-theme);
7860
}
7961
}
8062

81-
@include overwrites.other-overwrites;
63+
@include mat-lib-overwrites.other-overwrites;
8264

8365
$mat-css-theme: null !global;
8466
}
@@ -88,13 +70,9 @@
8870
$dark-theme-selector: variables.$dark-theme-selector,
8971
$default-theme-text: variables.$text,
9072
$typography-config: mat.define-typography-config(),
91-
$default-foreground: variables.$default-foreground,
92-
$default-background: variables.$default-background,
93-
$load-mdc-components: true,
94-
$load-legacy-components: false,
9573
) {
96-
@include init-css-vars($default-theme, $default-theme-text, $default-foreground, $default-background);
97-
@include init-mat-theme($dark-theme-selector, $typography-config, $load-mdc-components, $load-legacy-components) using ($mat-css-theme) {
74+
@include init-css-vars($default-theme, $default-theme-text);
75+
@include init-mat-theme($dark-theme-selector, $typography-config) using ($mat-css-theme) {
9876
@content($mat-css-theme);
9977
}
10078
}

0 commit comments

Comments
 (0)