Skip to content

Commit 1abf880

Browse files
committed
feat(material-experimental/theming): add M3 paginator support (#28164)
(cherry picked from commit 2cb7ada)
1 parent 4424c0b commit 1abf880

File tree

6 files changed

+93
-29
lines changed

6 files changed

+93
-29
lines changed

src/dev-app/theme-m3.scss

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ html {
4848
@include mat.menu-theme($light-theme);
4949
@include mat.optgroup-theme($light-theme);
5050
@include mat.option-theme($light-theme);
51+
@include mat.paginator-theme($light-theme);
5152
@include mat.progress-bar-theme($light-theme);
5253
@include mat.progress-spinner-theme($light-theme);
5354
@include mat.radio-theme($light-theme);
@@ -84,6 +85,7 @@ html {
8485
@include mat.menu-color($dark-theme);
8586
@include mat.optgroup-color($dark-theme);
8687
@include mat.option-color($dark-theme);
88+
@include mat.paginator-color($dark-theme);
8789
@include mat.progress-bar-color($dark-theme);
8890
@include mat.progress-spinner-color($dark-theme);
8991
@include mat.radio-color($dark-theme);
@@ -119,6 +121,7 @@ html {
119121
@include mat.menu-density($scale-theme);
120122
@include mat.optgroup-density($scale-theme);
121123
@include mat.option-density($scale-theme);
124+
@include mat.paginator-density($scale-theme);
122125
@include mat.progress-bar-density($scale-theme);
123126
@include mat.progress-spinner-density($scale-theme);
124127
@include mat.radio-density($scale-theme);

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

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,6 +156,24 @@
156156
);
157157
}
158158

159+
/// Generates custom tokens for the mat-paginator.
160+
/// @param {Map} $systems The MDC system tokens
161+
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values
162+
/// @return {Map} A set of custom tokens for the mat-paginator
163+
@function paginator($systems, $exclude-hardcoded) {
164+
@return mat.private-merge-all(
165+
_generate-typography-tokens($systems, container-text, body-small),
166+
(
167+
container-text-color: map.get($systems, md-sys-color, on-surface),
168+
container-background-color: map.get($systems, md-sys-color, surface),
169+
enabled-icon-color: map.get($systems, md-sys-color, on-surface-variant),
170+
disabled-icon-color: mat.private-safe-color-change(
171+
map.get($systems, md-sys-color, on-surface), $alpha: 0.38),
172+
select-trigger-text-size: map.get($systems, md-sys-typescale, body-small-size),
173+
)
174+
);
175+
}
176+
159177
/// Generates custom tokens for the mat-radio.
160178
/// @param {Map} $systems The MDC system tokens
161179
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -52,6 +52,9 @@ $_density-tokens: (
5252
(mat, menu): (),
5353
(mat, optgroup): (),
5454
(mat, option): (),
55+
(mat, paginator): (
56+
container-size: (56px, 52px, 48px, 40px),
57+
),
5558
(mat, radio): (),
5659
(mat, ripple): (),
5760
(mat, select): (),

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -295,6 +295,11 @@
295295
custom-tokens.option($systems, $exclude-hardcoded),
296296
$token-slots
297297
),
298+
_namespace-tokens(
299+
(mat, paginator),
300+
custom-tokens.paginator($systems, $exclude-hardcoded),
301+
$token-slots
302+
),
298303
_namespace-tokens(
299304
(mat, radio),
300305
custom-tokens.radio($systems, $exclude-hardcoded),

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,7 @@
99
@use './mat/menu' as tokens-mat-menu;
1010
@use './mat/option' as tokens-mat-option;
1111
@use './mat/optgroup' as tokens-mat-optgroup;
12+
@use './mat/paginator' as tokens-mat-paginator;
1213
@use './mat/radio' as tokens-mat-radio;
1314
@use './mat/ripple' as tokens-mat-ripple;
1415
@use './mat/select' as tokens-mat-select;
@@ -92,6 +93,7 @@
9293
_get-tokens-for-module($theme, tokens-mat-menu),
9394
_get-tokens-for-module($theme, tokens-mat-optgroup),
9495
_get-tokens-for-module($theme, tokens-mat-option),
96+
_get-tokens-for-module($theme, tokens-mat-paginator),
9597
_get-tokens-for-module($theme, tokens-mat-radio),
9698
_get-tokens-for-module($theme, tokens-mat-ripple),
9799
_get-tokens-for-module($theme, tokens-mat-select),
Lines changed: 62 additions & 29 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
1+
@use 'sass:map';
12
@use 'sass:meta';
23
@use '../core/tokens/m2/mat/paginator' as tokens-mat-paginator;
34
@use '../core/style/sass-utils';
@@ -7,55 +8,87 @@
78
@use '../core/tokens/token-utils';
89
@use '../form-field/form-field-density';
910

10-
@mixin base($theme) {}
11+
@mixin base($theme) {
12+
@if inspection.get-theme-version($theme) == 1 {
13+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, base));
14+
}
15+
@else {}
16+
}
1117

1218
@mixin color($theme) {
13-
@include sass-utils.current-selector-or-root() {
14-
@include token-utils.create-token-values(tokens-mat-paginator.$prefix,
15-
tokens-mat-paginator.get-color-tokens($theme));
19+
@if inspection.get-theme-version($theme) == 1 {
20+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, color));
21+
}
22+
@else {
23+
@include sass-utils.current-selector-or-root() {
24+
@include token-utils.create-token-values(tokens-mat-paginator.$prefix,
25+
tokens-mat-paginator.get-color-tokens($theme));
26+
}
1627
}
1728
}
1829

1930
@mixin typography($theme) {
20-
@include sass-utils.current-selector-or-root() {
21-
@include token-utils.create-token-values(tokens-mat-paginator.$prefix,
22-
tokens-mat-paginator.get-typography-tokens($theme));
31+
@if inspection.get-theme-version($theme) == 1 {
32+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, typography));
33+
}
34+
@else {
35+
@include sass-utils.current-selector-or-root() {
36+
@include token-utils.create-token-values(tokens-mat-paginator.$prefix,
37+
tokens-mat-paginator.get-typography-tokens($theme));
38+
}
2339
}
2440
}
2541

2642
@mixin density($theme) {
27-
$density-scale: inspection.get-theme-density($theme);
28-
29-
@include sass-utils.current-selector-or-root() {
30-
@include token-utils.create-token-values(tokens-mat-paginator.$prefix,
31-
tokens-mat-paginator.get-density-tokens($theme));
43+
@if inspection.get-theme-version($theme) == 1 {
44+
@include _theme-from-tokens(inspection.get-theme-tokens($theme, density));
3245
}
46+
@else {
47+
$density-scale: inspection.get-theme-density($theme);
3348

34-
// TODO: this should be done through tokens once the form field has been switched over.
35-
.mat-mdc-paginator {
36-
// We need the form field to be narrower in order to fit into the paginator,
37-
// so we set its density to be -4 or denser.
38-
@if ((meta.type-of($density-scale) == 'number' and $density-scale >= -4) or
39-
$density-scale == maximum) {
40-
@include form-field-density.private-form-field-density(-4);
49+
@include sass-utils.current-selector-or-root() {
50+
@include token-utils.create-token-values(tokens-mat-paginator.$prefix,
51+
tokens-mat-paginator.get-density-tokens($theme));
4152
}
42-
@else {
43-
@include form-field-density.private-form-field-density($density-scale);
53+
54+
// TODO: this should be done through tokens once the form field has been switched over.
55+
.mat-mdc-paginator {
56+
// We need the form field to be narrower in order to fit into the paginator,
57+
// so we set its density to be -4 or denser.
58+
@if ((meta.type-of($density-scale) == 'number' and $density-scale >= -4) or
59+
$density-scale == maximum) {
60+
@include form-field-density.private-form-field-density(-4);
61+
}
62+
@else {
63+
@include form-field-density.private-form-field-density($density-scale);
64+
}
4465
}
4566
}
4667
}
4768

4869
@mixin theme($theme) {
4970
@include theming.private-check-duplicate-theme-styles($theme, 'mat-paginator') {
50-
@include base($theme);
51-
@if inspection.theme-has($theme, color) {
52-
@include color($theme);
53-
}
54-
@if inspection.theme-has($theme, density) {
55-
@include density($theme);
71+
@if inspection.get-theme-version($theme) == 1 {
72+
@include _theme-from-tokens(inspection.get-theme-tokens($theme));
5673
}
57-
@if inspection.theme-has($theme, typography) {
58-
@include typography($theme);
74+
@else {
75+
@include base($theme);
76+
@if inspection.theme-has($theme, color) {
77+
@include color($theme);
78+
}
79+
@if inspection.theme-has($theme, density) {
80+
@include density($theme);
81+
}
82+
@if inspection.theme-has($theme, typography) {
83+
@include typography($theme);
84+
}
5985
}
6086
}
6187
}
88+
89+
@mixin _theme-from-tokens($tokens) {
90+
@if ($tokens != ()) {
91+
@include token-utils.create-token-values(
92+
tokens-mat-paginator.$prefix, map.get($tokens, tokens-mat-paginator.$prefix));
93+
}
94+
}

0 commit comments

Comments
 (0)