Skip to content

Commit 1930b1d

Browse files
authored
feat(material-experimental/theming): add M3 tooltip support (#27810)
1 parent cdf852e commit 1930b1d

File tree

5 files changed

+67
-24
lines changed

5 files changed

+67
-24
lines changed

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -38,6 +38,7 @@ $dark-theme: matx.define-theme(map.set($m3-base-config, color, theme-type, dark)
3838
html {
3939
@include mat.checkbox-theme($light-theme);
4040
@include mat.card-theme($light-theme);
41+
@include mat.tooltip-theme($light-theme);
4142
@include mat.toolbar-theme($light-theme);
4243
}
4344

@@ -49,6 +50,7 @@ html {
4950

5051
@include mat.checkbox-color($dark-theme);
5152
@include mat.card-color($dark-theme);
53+
@include mat.tooltip-color($dark-theme);
5254
@include mat.toolbar-color($dark-theme);
5355
}
5456

@@ -59,6 +61,7 @@ html {
5961
.demo-density-#{$scale} {
6062
@include mat.checkbox-density($scale-theme);
6163
@include mat.card-density($scale-theme);
64+
@include mat.tooltip-density($scale-theme);
6265
@include mat.toolbar-density($scale-theme);
6366
}
6467
}

src/material-experimental/theming/_m3-density.scss

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ $_density-tokens: (
2121
(mdc, elevated-card): (),
2222
(mdc, outlined-card): (),
2323
(mat, card): (),
24+
(mdc, plain-tooltip): (),
2425
(mat, toolbar): (
2526
standard-height: (64px, 60px, 56px, 52px),
2627
mobile-height: (56px, 52px, 48px, 44px),

src/material-experimental/theming/_m3-tokens.scss

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -188,6 +188,11 @@
188188
mdc-tokens.md-comp-outlined-card-values($systems, $exclude-hardcoded),
189189
$token-slots
190190
),
191+
_namespace-tokens(
192+
(mdc, plain-tooltip),
193+
mdc-tokens.md-comp-plain-tooltip-values($systems, $exclude-hardcoded),
194+
$token-slots
195+
),
191196
// Choose values for our made up tokens based on MDC system tokens or sensible hardcoded
192197
// values.
193198
_namespace-tokens(

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
@use './mdc/snack-bar' as tokens-mdc-snack-bar;
2121
@use './mdc/tab' as tokens-mdc-tab;
2222
@use './mdc/tab-indicator' as tokens-mdc-tab-indicator;
23+
@use './mdc/plain-tooltip' as tokens-mdc-plain-tooltip;
2324

2425
/// Gets the tokens for the given theme, m2 tokens module, and theming system.
2526
/// @param {Map} $theme The Angular Material theme object to generate token values from.
@@ -82,5 +83,6 @@
8283
_get-tokens-for-module($theme, tokens-mdc-snack-bar),
8384
_get-tokens-for-module($theme, tokens-mdc-tab),
8485
_get-tokens-for-module($theme, tokens-mdc-tab-indicator),
86+
_get-tokens-for-module($theme, tokens-mdc-plain-tooltip),
8587
);
8688
}
Lines changed: 56 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -1,55 +1,87 @@
1+
@use 'sass:map';
12
@use '@material/tooltip/plain-tooltip-theme' as mdc-plain-tooltip-theme;
23
@use '../core/style/sass-utils';
34
@use '../core/theming/theming';
45
@use '../core/theming/inspection';
56
@use '../core/typography/typography';
6-
@use '../core/tokens/m2/mdc/plain-tooltip' as m2-mdc-plain-tooltip;
7+
@use '../core/tokens/m2/mdc/plain-tooltip' as tokens-mdc-plain-tooltip;
78

89
@mixin base($theme) {
9-
// Add default values for tokens not related to color, typography, or density.
10-
@include sass-utils.current-selector-or-root() {
11-
@include mdc-plain-tooltip-theme.theme(m2-mdc-plain-tooltip.get-unthemable-tokens());
10+
@if inspection.get-theme-version($theme) == 1 {
11+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, base));
12+
}
13+
@else {
14+
// Add default values for tokens not related to color, typography, or density.
15+
@include sass-utils.current-selector-or-root() {
16+
@include mdc-plain-tooltip-theme.theme(tokens-mdc-plain-tooltip.get-unthemable-tokens());
17+
}
1218
}
1319
}
1420

1521
@mixin color($theme) {
16-
$mdc-tooltip-color-tokens: m2-mdc-plain-tooltip.get-color-tokens($theme);
22+
@if inspection.get-theme-version($theme) == 1 {
23+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, color));
24+
}
25+
@else {
26+
$mdc-tooltip-color-tokens: tokens-mdc-plain-tooltip.get-color-tokens($theme);
1727

18-
// Add values for MDC tooltip tokens.
19-
@include sass-utils.current-selector-or-root() {
20-
@include mdc-plain-tooltip-theme.theme($mdc-tooltip-color-tokens);
28+
// Add values for MDC tooltip tokens.
29+
@include sass-utils.current-selector-or-root() {
30+
@include mdc-plain-tooltip-theme.theme($mdc-tooltip-color-tokens);
31+
}
2132
}
2233
}
2334

2435
@mixin typography($theme) {
25-
$mdc-tooltip-typography-tokens: m2-mdc-plain-tooltip.get-typography-tokens($theme);
36+
@if inspection.get-theme-version($theme) == 1 {
37+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, typography));
38+
}
39+
@else {
40+
$mdc-tooltip-typography-tokens: tokens-mdc-plain-tooltip.get-typography-tokens($theme);
2641

27-
// Add values for MDC tooltip tokens.
28-
@include sass-utils.current-selector-or-root() {
29-
@include mdc-plain-tooltip-theme.theme($mdc-tooltip-typography-tokens);
42+
// Add values for MDC tooltip tokens.
43+
@include sass-utils.current-selector-or-root() {
44+
@include mdc-plain-tooltip-theme.theme($mdc-tooltip-typography-tokens);
45+
}
3046
}
3147
}
3248

3349
@mixin density($theme) {
34-
$mdc-tooltip-density-tokens: m2-mdc-plain-tooltip.get-density-tokens($theme);
50+
@if inspection.get-theme-version($theme) == 1 {
51+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, density));
52+
}
53+
@else {
54+
$mdc-tooltip-density-tokens: tokens-mdc-plain-tooltip.get-density-tokens($theme);
3555

36-
// Add values for MDC tooltip tokens.
37-
@include sass-utils.current-selector-or-root() {
38-
@include mdc-plain-tooltip-theme.theme($mdc-tooltip-density-tokens);
56+
// Add values for MDC tooltip tokens.
57+
@include sass-utils.current-selector-or-root() {
58+
@include mdc-plain-tooltip-theme.theme($mdc-tooltip-density-tokens);
59+
}
3960
}
4061
}
4162

4263
@mixin theme($theme) {
4364
@include theming.private-check-duplicate-theme-styles($theme, 'mat-tooltip') {
44-
@include base($theme);
45-
@if inspection.theme-has($theme, color) {
46-
@include color($theme);
47-
}
48-
@if inspection.theme-has($theme, density) {
49-
@include density($theme);
65+
@if inspection.get-theme-version($theme) == 1 {
66+
@include _theme-from-tokens(inspection.get-theme-tokens($theme));
5067
}
51-
@if inspection.theme-has($theme, typography) {
52-
@include typography($theme);
68+
@else {
69+
@include base($theme);
70+
@if inspection.theme-has($theme, color) {
71+
@include color($theme);
72+
}
73+
@if inspection.theme-has($theme, density) {
74+
@include density($theme);
75+
}
76+
@if inspection.theme-has($theme, typography) {
77+
@include typography($theme);
78+
}
5379
}
5480
}
5581
}
82+
83+
@mixin _theme-from-tokens($tokens) {
84+
@if $tokens != () {
85+
@include mdc-plain-tooltip-theme.theme(map.get($tokens, tokens-mdc-plain-tooltip.$prefix));
86+
}
87+
}

0 commit comments

Comments
 (0)