Skip to content

Commit 1ec0264

Browse files
committed
tweaks based on recent feedback and discussions
1 parent 9e2df58 commit 1ec0264

File tree

3 files changed

+28
-24
lines changed

3 files changed

+28
-24
lines changed

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

Lines changed: 20 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
@use '@angular/material' as mat;
2-
@use '@angular/material-experimental';
2+
@use '@angular/material-experimental' as matx;
33

44
dev-app {
55
&::before {
@@ -23,6 +23,15 @@ dev-app {
2323

2424
@include mat.core();
2525

26+
$light-theme: mat.define-light-theme((
27+
color: (
28+
primary: mat.define-palette(mat.$indigo-palette),
29+
accent: mat.define-palette(mat.$pink-palette),
30+
),
31+
typography: mat.define-typography-config(),
32+
density: 0,
33+
));
34+
2635
$dark-theme: mat.define-dark-theme((
2736
color: (
2837
primary: mat.define-palette(mat.$blue-grey-palette),
@@ -35,18 +44,22 @@ $dark-theme: mat.define-dark-theme((
3544

3645
// Set up light theme.
3746

38-
@include material-experimental.theme($components: (
39-
material-experimental.card(),
40-
material-experimental.checkbox(),
41-
));
47+
html {
48+
@include matx.theme(
49+
$tokens: mat.m2-tokens-from-theme($light-theme),
50+
$components: (
51+
matx.card(),
52+
matx.checkbox(),
53+
));
54+
}
4255

4356
// Set up dark theme.
4457

4558
.demo-unicorn-dark-theme {
46-
@include material-experimental.theme(
59+
@include matx.theme(
4760
$tokens: mat.m2-tokens-from-theme($dark-theme),
4861
$components: (
49-
material-experimental.checkbox((
62+
matx.checkbox((
5063
(mdc, checkbox): (
5164
selected-checkmark-color: red,
5265
)

src/material-experimental/theming/_theming.scss

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -60,16 +60,14 @@ $_error-on-missing-dep: false;
6060

6161
@mixin _theme($tokens, $components) {
6262
// Call the theme mixin for each configured component.
63-
@at-root #{& or body} {
64-
@each $component in $components {
65-
@include _apply-theme($tokens, $component);
66-
}
63+
@each $component in $components {
64+
@include _apply-theme($tokens, $component);
6765
}
6866
}
6967

7068
// Takes the full list of tokens and a list of components to configure, and outputs all theme
7169
// tokens for the configured components.
72-
@mixin theme($tokens: mat.m2-tokens-from-theme(), $components) {
70+
@mixin theme($tokens, $components) {
7371
@include _theme($tokens, _get-transitive-deps(mat.private-normalize-args-list($components)));
7472
}
7573

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

Lines changed: 5 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,9 @@
3030
@return meta.call(
3131
meta.get-function(get-#{$system}-tokens, $module: $module));
3232
}
33+
@if not map.get($theme, $system) {
34+
@return ();
35+
}
3336
@return meta.call(
3437
meta.get-function(get-#{$system}-tokens, $module: $module), map.get($theme, $system));
3538
}
@@ -44,23 +47,13 @@
4447
@return map.set((), map.get(meta.module-variables($module), prefix), $tokens);
4548
}
4649

47-
// Gets the full set of m2 tokens for the given theme object. If parts of the theme are missing
48-
// (color, density, etc), defaults are used. Returned format:
50+
// Gets the full set of m2 tokens for the given theme object. Returned format:
4951
// (
5052
// (fully, qualified, namespace): (
5153
// token: value
5254
// )
5355
// )
54-
@function m2-tokens-from-theme($theme: ()) {
55-
$theme: map.merge((
56-
color: theming.define-light-theme(
57-
theming.define-palette(palette.$indigo-palette),
58-
theming.define-palette(palette.$pink-palette),
59-
),
60-
typography: all-typography.define-typography-config(),
61-
density: 0
62-
), $theme);
63-
56+
@function m2-tokens-from-theme($theme) {
6457
@return sass-utils.deep-merge-all(
6558
_get-tokens-for-module($theme, tokens-mat-card),
6659
_get-tokens-for-module($theme, tokens-mat-radio),

0 commit comments

Comments
 (0)