Skip to content

Commit a3a5e82

Browse files
committed
fixup! Add the new mat.theme API
1 parent 2ce0c77 commit a3a5e82

File tree

23 files changed

+50
-33
lines changed

23 files changed

+50
-33
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -131,10 +131,10 @@
131131
# Material experimental package
132132
/src/material-experimental/* @andrewseguin
133133
/src/material-experimental/column-resize/** @andrewseguin
134-
/src/material-experimental/mdc-tooltip/** @crisbeto
135134
/src/material-experimental/menubar/** @jelbourn
136135
/src/material-experimental/popover-edit/** @andrewseguin
137136
/src/material-experimental/selection/** @andrewseguin
137+
/src/material-experimental/theming/** @mmalerba
138138

139139
# CDK experimental package
140140
/src/cdk-experimental/* @andrewseguin

src/dev-app/theme-token-api.scss

Lines changed: 9 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -43,11 +43,13 @@ $dark-theme: mat.define-dark-theme((
4343
// Set up dark theme.
4444

4545
.demo-unicorn-dark-theme {
46-
@include material-experimental.theme($tokens: mat.m2-tokens-from-theme($dark-theme), $components: (
47-
material-experimental.checkbox((
48-
(mdc, checkbox): (
49-
selected-checkmark-color: red,
50-
)
51-
)),
52-
));
46+
@include material-experimental.theme(
47+
$tokens: mat.m2-tokens-from-theme($dark-theme),
48+
$components: (
49+
material-experimental.checkbox((
50+
(mdc, checkbox): (
51+
selected-checkmark-color: red,
52+
)
53+
)),
54+
));
5355
}

src/material-experimental/BUILD.bazel

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,9 @@ ts_library(
1919

2020
sass_library(
2121
name = "theming_scss_lib",
22-
srcs = MATERIAL_EXPERIMENTAL_SCSS_LIBS,
22+
srcs = MATERIAL_EXPERIMENTAL_SCSS_LIBS + [
23+
"//src/material-experimental/theming:theming_scss_lib",
24+
],
2325
)
2426

2527
sass_library(
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
load("//tools:defaults.bzl", "sass_library")
2+
3+
package(default_visibility = ["//visibility:public"])
4+
5+
sass_library(
6+
name = "theming_scss_lib",
7+
srcs = glob(["**/_*.scss"]),
8+
deps = ["//src/material:sass_lib"],
9+
)

src/material-experimental/theming/_theming.scss

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
@use 'sass:list';
22
@use 'sass:map';
33
@use 'sass:meta';
4-
@use 'sass:string';
54
@use '@angular/material' as mat;
65

76
// Whether to throw an error when a required dep is not configured. If false, the dep will be
@@ -17,9 +16,11 @@ $_error-on-missing-dep: false;
1716
// supported, the configuration data will contain a reference to its own theme mixin.
1817
@if $id == 'mat.card' {
1918
@include mat.private-apply-card-theme-from-tokens($tokens);
20-
} @else if $id == 'mat.checkbox' {
19+
}
20+
@else if $id == 'mat.checkbox' {
2121
@include mat.private-apply-checkbox-theme-from-tokens($tokens);
22-
} @else {
22+
}
23+
@else {
2324
@error 'Unrecognized component theme: #{id}';
2425
}
2526
}
@@ -41,7 +42,8 @@ $_error-on-missing-dep: false;
4142
@if $_error-on-missing-dep {
4243
@error 'Missing theme: `#{map.get($component, id)}` depends on `#{$dep-id}`.' +
4344
' Please configure the theme for `#{$dep-id}` in your call to `mat.theme`';
44-
} @else {
45+
}
46+
@else {
4547
$configured: map.set($configured, $dep-id, true);
4648
$new-deps: list.append($new-deps, $dep);
4749
}

src/material/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,7 @@ sass_library(
2424
srcs = [
2525
"_index.scss",
2626
"_theming.scss",
27+
"_token-theming.scss",
2728
],
2829
deps = [
2930
"//src/material/core:core_scss_lib",

src/material/button/_icon-button-theme.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
@use 'sass:map';
22
@use 'sass:math';
33
@use '@material/density/functions' as mdc-density-functions;
4-
@use '@material/icon-button/mixins' as mdc-icon-button;
54
@use '@material/icon-button/icon-button-theme' as mdc-icon-button-theme;
65
@use '@material/theme/theme-color' as mdc-theme-color;
76
@use '../core/tokens/m2/mdc/icon-button' as tokens-mdc-icon-button;
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
1-
@forward 'card-theme' hide color, density, theme, typography;
1+
@forward 'card-theme' hide color, density, theme, typography, theme-from-tokens;
22
@forward 'card-theme' as mat-mdc-card-* hide $mat-mdc-card-mdc-card-action-icon-color,
33
$mat-mdc-card-mdc-card-outline-color;

src/material/checkbox/_checkbox-theme.import.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@forward 'checkbox-theme' hide color, density, private-checkbox-styles-with-color, theme,
2-
typography;
2+
typography, theme-from-tokens;
33
@forward 'checkbox-theme' as mat-mdc-* hide $mat-mdc-mdc-checkbox-border-color,
44
$mat-mdc-mdc-checkbox-disabled-color, mat-mdc-background-focus-density,
55
mat-mdc-background-focus-indicator-checked-color, mat-mdc-background-focus-indicator-color,

src/material/core/style/_sass-utils.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
@use 'sass:list';
21
@use 'sass:map';
32
@use 'sass:meta';
43

src/material/core/tokens/_token-utils.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -51,7 +51,8 @@ $_component-prefix: null;
5151
@mixin _configure-token-prefix($first, $rest...) {
5252
$_component-prefix: '' !global;
5353
@each $item in $rest {
54-
$_component-prefix: if($_component-prefix == '', $item, '#{$_component-prefix}-#{$item}') !global;
54+
$_component-prefix:
55+
if($_component-prefix == '', $item, '#{$_component-prefix}-#{$item}') !global;
5556
}
5657
@include mdc-custom-properties.configure($varname-prefix: $first) {
5758
@content;

src/material/core/tokens/m2/_index.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
@use 'sass:list';
21
@use 'sass:map';
32
@use 'sass:meta';
43
@use '../../theming/palette';

src/material/core/tokens/m2/mdc/_checkbox.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,8 @@ $prefix: (mdc, checkbox);
5959
$disabled-color: theming.get-color-from-palette($foreground, base, 0.38);
6060
$selected-color: theming.get-color-from-palette($accent);
6161
$border-color: theming.get-color-from-palette($foreground, base, 0.54);
62-
$active-border-color: theming.get-color-from-palette(palette.$gray-palette, if($is-dark, 200, 900));
62+
$active-border-color:
63+
theming.get-color-from-palette(palette.$gray-palette, if($is-dark, 200, 900));
6364

6465
@return (
6566
// The color of the checkbox fill when the checkbox is selected and disabled.

src/material/core/tokens/m2/mdc/_chip.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
1-
@use 'sass:color';
21
@use 'sass:map';
32
@use '../../token-utils';
43
@use '../../../mdc-helpers/mdc-helpers';
4+
@use '../../../style/sass-utils';
55
@use '../../../theming/theming';
66
@use '../../../typography/typography-utils';
77

@@ -304,7 +304,7 @@ $prefix: (mdc, chip);
304304
// Combines the tokens generated by the above functions into a single map with placeholder values.
305305
// This is used to create token slots.
306306
@function get-token-slots() {
307-
@return token-utils.merge-all(
307+
@return sass-utils.deep-merge-all(
308308
get-unthemable-tokens(),
309309
get-color-tokens(token-utils.$placeholder-color-config),
310310
get-typography-tokens(token-utils.$placeholder-typography-config),

src/material/core/tokens/m2/mdc/_icon-button.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,3 @@
1-
@use 'sass:map';
21
@use '../../../style/sass-utils';
32
@use '../../token-utils';
43

src/material/core/tokens/m2/mdc/_list.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -87,7 +87,8 @@ $prefix: (mdc, list);
8787
$foreground: map.get($config, foreground);
8888
$is-dark: map.get($config, is-dark);
8989
$foreground-base: theming.get-color-from-palette($foreground, base);
90-
$text-icon-on-background: theming.get-color-from-palette($foreground, base, if($is-dark, 0.5, 0.38));
90+
$text-icon-on-background:
91+
stheming.get-color-from-palette($foreground, base, if($is-dark, 0.5, 0.38));
9192

9293
@return (
9394
// Text color of the list item primary text.

src/material/core/tokens/tests/test-validate-tokens.scss

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,6 @@
66
@use '@material/checkbox/checkbox-theme' as mdc-checkbox-theme;
77
@use '@material/circular-progress/circular-progress-theme' as mdc-circular-progress-theme;
88
@use '@material/icon-button/icon-button-theme' as mdc-icon-button-theme;
9-
@use '@material/linear-progress/linear-progress-theme' as mdc-linear-progress-theme;
109
@use '@material/list/list-theme' as mdc-list-theme;
1110
@use '@material/tooltip/plain-tooltip-theme' as mdc-plaintip-tooltip-theme;
1211
@use '@material/radio/radio-theme' as mdc-radio-theme;
@@ -20,7 +19,6 @@
2019
@use '../m2/mdc/elevated-card' as tokens-mdc-elevated-card;
2120
@use '../m2/mdc/icon-button' as tokens-mdc-icon-button;
2221
@use '../m2/mdc/checkbox' as tokens-mdc-checkbox;
23-
@use '../m2/mdc/linear-progress' as tokens-mdc-linear-progress;
2422
@use '../m2/mdc/list' as tokens-mdc-list;
2523
@use '../m2/mdc/outlined-card' as tokens-mdc-outlined-card;
2624
@use '../m2/mdc/plain-tooltip' as tokens-mdc-plain-tooltip;

src/material/legacy-radio/radio.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
@use '@angular/cdk';
33

44
@use '../core/style/variables';
5-
@use '../core/ripple/ripple';
65
@use '../core/style/vendor-prefixes';
76

87

src/material/legacy-slide-toggle/slide-toggle.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33

44
@use '../core/style/vendor-prefixes';
55
@use '../core/style/variables';
6-
@use '../core/ripple/ripple';
76
@use '../core/style/list-common';
87

98
$thumb-size: 20px !default;

src/material/slide-toggle/slide-toggle.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
@use '@material/form-field' as mdc-form-field;
66
@use '@material/ripple' as mdc-ripple;
77
@use '../core/mdc-helpers/mdc-helpers';
8-
@use '../core/style/_layout-common.scss';
98

109

1110
@include mdc-helpers.disable-mdc-fallback-declarations {

src/material/stepper/stepper.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,6 @@
11
@use '@angular/cdk';
22
@use 'sass:math';
33

4-
@use '../core/style/variables';
54
@use './stepper-variables';
65

76
.mat-stepper-vertical,

src/material/tabs/_tabs-theme.scss

Lines changed: 0 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
@use 'sass:map';
22
@use '@material/tab-indicator/tab-indicator-theme' as mdc-tab-indicator-theme;
3-
@use '@material/tab' as mdc-tab;
43
@use '@material/tab/tab-theme' as mdc-tab-theme;
54
@use '../core/tokens/m2/mdc/tab' as tokens-mdc-tab;
65
@use '../core/tokens/m2/mdc/tab-indicator' as tokens-mdc-tab-indicator;

tools/stylelint/no-unused-import.ts

Lines changed: 11 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,21 @@ const messages = utils.ruleMessages(ruleName, {
99
`imports Stylelint rule likely needs to be updated.`,
1010
});
1111

12+
function stripCommentsAndAtUse(content: string) {
13+
return content
14+
.replace(/@use.*?;/g, '')
15+
.replace(/\/\/.*?\n/g, '')
16+
.replace(/\/\*.*?\*\//g, '');
17+
}
18+
1219
/** Stylelint plugin that flags unused `@use` statements. */
1320
const ruleFn: Rule<boolean, string> = (isEnabled, _options, context) => {
1421
return (root, result) => {
1522
if (!isEnabled) {
1623
return;
1724
}
1825

19-
const fileContent = root.toString();
26+
const fileContent = stripCommentsAndAtUse(root.toString());
2027

2128
root.walkAtRules(rule => {
2229
if (rule.name === 'use') {
@@ -30,7 +37,9 @@ const ruleFn: Rule<boolean, string> = (isEnabled, _options, context) => {
3037
message: messages.invalid(rule.params),
3138
node: rule,
3239
});
33-
} else if (!fileContent.includes(namespace + '.')) {
40+
} else if (!fileContent.match('[^\\w$@-]' + namespace + '[^\\w-]')) {
41+
// We use a broader match than just `${namespace}.`, because this doesn't catch the case
42+
// where we use the module as an argument to something like `meta.get-function`.
3443
if (context.fix) {
3544
rule.remove();
3645
} else {

0 commit comments

Comments
 (0)