|
1 | 1 | @use '@angular/material' as mat; |
2 | 2 |
|
| 3 | +// We want to emit only the overrides, because the backwards compatibility styles are usually |
| 4 | +// emitted after all the tokens have been included once already. This allows us to save ~50kb |
| 5 | +// from the bundle. |
| 6 | +$_overrides-only: true; |
| 7 | + |
3 | 8 | @mixin color-variant-styles($theme, $color-variant) { |
| 9 | + $primary-options: (color-variant: $color-variant, emit-overrides-only: $_overrides-only); |
| 10 | + |
4 | 11 | // Some components use the secondary color rather than primary color for `.mat-primary`. |
5 | 12 | // Those components should use the $secondary-color-variant. |
6 | | - $secondary-color-variant: if($color-variant == primary, secondary, $color-variant); |
| 13 | + $secondary-options: ( |
| 14 | + color-variant: if($color-variant == primary, secondary, $color-variant), |
| 15 | + emit-overrides-only: $_overrides-only |
| 16 | + ); |
7 | 17 |
|
8 | | - @include mat.option-color($theme, $color-variant: $secondary-color-variant); |
9 | | - @include mat.progress-spinner-color($theme, $color-variant: $color-variant); |
10 | | - @include mat.pseudo-checkbox-color($theme, $color-variant: $color-variant); |
11 | | - @include mat.stepper-color($theme, $color-variant: $color-variant); |
| 18 | + @include mat.option-color($theme, $secondary-options...); |
| 19 | + @include mat.progress-spinner-color($theme, $primary-options...); |
| 20 | + @include mat.pseudo-checkbox-color($theme, $primary-options...); |
| 21 | + @include mat.stepper-color($theme, $primary-options...); |
12 | 22 |
|
13 | 23 | &.mat-icon { |
14 | | - @include mat.icon-color($theme, $color-variant: $color-variant); |
| 24 | + @include mat.icon-color($theme, $primary-options...); |
15 | 25 | } |
16 | 26 |
|
17 | 27 | &.mat-mdc-checkbox { |
18 | | - @include mat.checkbox-color($theme, $color-variant: $color-variant); |
| 28 | + @include mat.checkbox-color($theme, $primary-options...); |
19 | 29 | } |
20 | 30 |
|
21 | 31 | &.mat-mdc-slider { |
22 | | - @include mat.slider-color($theme, $color-variant: $color-variant); |
| 32 | + @include mat.slider-color($theme, $primary-options...); |
23 | 33 | } |
24 | 34 |
|
25 | 35 | &.mat-mdc-tab-group, |
26 | 36 | &.mat-mdc-tab-nav-bar { |
27 | | - @include mat.tabs-color($theme, $color-variant: $color-variant); |
| 37 | + @include mat.tabs-color($theme, $primary-options...); |
28 | 38 | } |
29 | 39 |
|
30 | 40 | &.mat-mdc-slide-toggle { |
31 | | - @include mat.slide-toggle-color($theme, $color-variant: $color-variant); |
| 41 | + @include mat.slide-toggle-color($theme, $primary-options...); |
32 | 42 | } |
33 | 43 |
|
34 | 44 | &.mat-mdc-form-field { |
35 | | - @include mat.select-color($theme, $color-variant: $color-variant); |
| 45 | + @include mat.select-color($theme, $primary-options...); |
36 | 46 | } |
37 | 47 |
|
38 | 48 | &.mat-mdc-radio-button { |
39 | | - @include mat.radio-color($theme, $color-variant: $color-variant); |
| 49 | + @include mat.radio-color($theme, $primary-options...); |
40 | 50 | } |
41 | 51 |
|
42 | 52 | &.mat-mdc-progress-bar { |
43 | | - @include mat.progress-bar-color($theme, $color-variant: $color-variant); |
| 53 | + @include mat.progress-bar-color($theme, $primary-options...); |
44 | 54 | } |
45 | 55 |
|
46 | 56 | &.mat-mdc-form-field { |
47 | | - @include mat.form-field-color($theme, $color-variant: $color-variant); |
| 57 | + @include mat.form-field-color($theme, $primary-options...); |
48 | 58 | } |
49 | 59 |
|
50 | 60 | &.mat-datepicker-content { |
51 | | - @include mat.datepicker-color($theme, $color-variant: $color-variant); |
| 61 | + @include mat.datepicker-color($theme, $primary-options...); |
52 | 62 | } |
53 | 63 |
|
54 | 64 | &.mat-mdc-button-base { |
55 | | - @include mat.button-color($theme, $color-variant: $color-variant); |
| 65 | + @include mat.button-color($theme, $primary-options...); |
56 | 66 | } |
57 | 67 |
|
58 | 68 | &.mat-mdc-standard-chip { |
59 | | - @include mat.chips-color($theme, $color-variant: $secondary-color-variant); |
| 69 | + @include mat.chips-color($theme, $secondary-options...); |
60 | 70 | } |
61 | 71 |
|
62 | 72 | .mdc-list-item__start, |
63 | 73 | .mdc-list-item__end { |
64 | | - @include mat.checkbox-color($theme, $color-variant: $color-variant); |
65 | | - @include mat.radio-color($theme, $color-variant: $color-variant); |
| 74 | + @include mat.checkbox-color($theme, $primary-options...); |
| 75 | + @include mat.radio-color($theme, $primary-options...); |
66 | 76 | } |
67 | 77 |
|
68 | 78 | // M3 dropped support for warn/error color FABs. |
69 | 79 | @if $color-variant != error { |
70 | 80 | &.mat-mdc-fab, |
71 | 81 | &.mat-mdc-mini-fab { |
72 | | - @include mat.fab-color($theme, $color-variant: $color-variant); |
| 82 | + @include mat.fab-color($theme, $primary-options...); |
73 | 83 | } |
74 | 84 | } |
75 | 85 | } |
|
79 | 89 | @include color-variant-styles($theme, primary); |
80 | 90 | } |
81 | 91 | .mat-badge { |
82 | | - @include mat.badge-color($theme, $color-variant: primary); |
| 92 | + @include mat.badge-color($theme, $color-variant: primary, |
| 93 | + $emit-overrides-only: $_overrides-only); |
83 | 94 | } |
84 | 95 |
|
85 | 96 | .mat-accent { |
86 | 97 | @include color-variant-styles($theme, tertiary); |
87 | 98 | } |
88 | 99 | .mat-badge-accent { |
89 | | - @include mat.badge-color($theme, $color-variant: tertiary); |
| 100 | + @include mat.badge-color($theme, $color-variant: tertiary, |
| 101 | + $emit-overrides-only: $_overrides-only); |
90 | 102 | } |
91 | 103 |
|
92 | 104 | .mat-warn { |
93 | 105 | @include color-variant-styles($theme, error); |
94 | 106 | } |
95 | 107 | .mat-badge-warn { |
96 | | - @include mat.badge-color($theme, $color-variant: error); |
| 108 | + @include mat.badge-color($theme, $color-variant: error, |
| 109 | + $emit-overrides-only: $_overrides-only); |
97 | 110 | } |
98 | 111 | } |
0 commit comments