Skip to content

Commit 6d0d47e

Browse files
authored
refactor(material/paginator): switch to tokens API (#27325)
Reworks the paginator use the new tokens theming API.
1 parent 860aa42 commit 6d0d47e

File tree

5 files changed

+118
-56
lines changed

5 files changed

+118
-56
lines changed
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
@use 'sass:map';
2+
@use '../../token-utils';
3+
@use '../../../typography/typography-utils';
4+
@use '../../../theming/theming';
5+
@use '../../../style/sass-utils';
6+
7+
// The prefix used to generate the fully qualified name for tokens in this file.
8+
$prefix: (mat, paginator);
9+
10+
// Tokens that can't be configured through Angular Material's current theming API,
11+
// but may be in a future version of the theming API.
12+
@function get-unthemable-tokens() {
13+
@return ();
14+
}
15+
16+
// Tokens that can be configured through Angular Material's color theming API.
17+
@function get-color-tokens($config) {
18+
$foreground: map.get($config, foreground);
19+
$background: map.get($config, background);
20+
21+
@return (
22+
container-text-color: theming.get-color-from-palette($foreground, base, 0.87),
23+
container-background-color: theming.get-color-from-palette($background, card),
24+
enabled-icon-color: theming.get-color-from-palette($foreground, base, 0.54),
25+
disabled-icon-color: theming.get-color-from-palette($foreground, base, 0.12),
26+
);
27+
}
28+
29+
// Tokens that can be configured through Angular Material's typography theming API.
30+
@function get-typography-tokens($config) {
31+
@return (
32+
container-text-font: typography-utils.font-family($config, caption) or
33+
typography-utils.font-family($config),
34+
container-text-line-height: typography-utils.line-height($config, caption),
35+
container-text-size: typography-utils.font-size($config, caption),
36+
container-text-tracking: typography-utils.letter-spacing($config, caption),
37+
container-text-weight: typography-utils.font-weight($config, caption),
38+
select-trigger-text-size: typography-utils.font-size($config, caption),
39+
);
40+
}
41+
42+
// Tokens that can be configured through Angular Material's density theming API.
43+
@function get-density-tokens($config) {
44+
$density-scale: theming.clamp-density($config, -3);
45+
$size-scale: (
46+
0: 56px,
47+
-1: 52px,
48+
-2: 48px,
49+
-3: 40px,
50+
);
51+
52+
@return (
53+
container-size: map.get($size-scale, $density-scale)
54+
);
55+
}
56+
57+
// Combines the tokens generated by the above functions into a single map with placeholder values.
58+
// This is used to create token slots.
59+
@function get-token-slots() {
60+
@return sass-utils.deep-merge-all(
61+
get-unthemable-tokens(),
62+
get-color-tokens(token-utils.$placeholder-color-config),
63+
get-typography-tokens(token-utils.$placeholder-typography-config),
64+
get-density-tokens(token-utils.$placeholder-density-config)
65+
);
66+
}

src/material/paginator/BUILD.bazel

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,7 +44,9 @@ sass_binary(
4444
name = "paginator_scss",
4545
src = "paginator.scss",
4646
deps = [
47+
"//:mdc_sass_lib",
4748
"//src/cdk:sass_lib",
49+
"//src/material:sass_lib",
4850
],
4951
)
5052

src/material/paginator/_paginator-theme.scss

Lines changed: 15 additions & 56 deletions
Original file line numberDiff line numberDiff line change
@@ -1,76 +1,39 @@
1-
@use 'sass:map';
21
@use 'sass:meta';
3-
@use '@material/density' as mdc-density;
4-
@use '@material/typography' as mdc-typography;
5-
2+
@use '../core/tokens/m2/mat/paginator' as tokens-mat-paginator;
3+
@use '../core/style/sass-utils';
64
@use '../core/typography/typography';
7-
@use '../core/typography/typography-utils';
8-
@use '../core/mdc-helpers/mdc-helpers';
95
@use '../core/theming/theming';
6+
@use '../core/tokens/token-utils';
107
@use '../form-field/form-field-density';
11-
@use './paginator-variables';
128

139
@mixin color($config-or-theme) {
1410
$config: theming.get-color-config($config-or-theme);
15-
$background: map.get($config, background);
16-
$foreground: map.get($config, foreground);
17-
$icon-color: rgba(theming.get-color-from-palette($foreground, base), 0.54);
18-
$disabled-color: rgba(theming.get-color-from-palette($foreground, base), 0.12);
19-
20-
.mat-mdc-paginator {
21-
background: theming.get-color-from-palette($background, card);
22-
color: rgba(theming.get-color-from-palette($foreground, base), 0.87);
23-
}
24-
25-
.mat-mdc-paginator-icon {
26-
fill: $icon-color;
27-
}
28-
29-
.mat-mdc-paginator-decrement,
30-
.mat-mdc-paginator-increment {
31-
border-top: 2px solid $icon-color;
32-
border-right: 2px solid $icon-color;
33-
}
34-
35-
.mat-mdc-paginator-first,
36-
.mat-mdc-paginator-last {
37-
border-top: 2px solid $icon-color;
38-
}
3911

40-
.mat-mdc-icon-button[disabled] {
41-
.mat-mdc-paginator-decrement,
42-
.mat-mdc-paginator-increment,
43-
.mat-mdc-paginator-first,
44-
.mat-mdc-paginator-last {
45-
border-color: $disabled-color;
46-
}
47-
48-
.mat-mdc-paginator-icon {
49-
fill: $disabled-color;
50-
}
12+
@include sass-utils.current-selector-or-root() {
13+
@include token-utils.create-token-values(tokens-mat-paginator.$prefix,
14+
tokens-mat-paginator.get-color-tokens($config));
5115
}
5216
}
5317

5418
@mixin typography($config-or-theme) {
5519
$config: typography.private-typography-to-2018-config(
5620
theming.get-typography-config($config-or-theme));
5721

58-
@include mdc-helpers.using-mdc-typography($config) {
59-
.mat-mdc-paginator {
60-
@include mdc-typography.typography(caption, $query: mdc-helpers.$mdc-typography-styles-query);
61-
}
62-
63-
.mat-mdc-paginator .mat-mdc-select-value {
64-
font-size: typography-utils.font-size($config, caption);
65-
}
22+
@include sass-utils.current-selector-or-root() {
23+
@include token-utils.create-token-values(tokens-mat-paginator.$prefix,
24+
tokens-mat-paginator.get-typography-tokens($config));
6625
}
6726
}
6827

6928
@mixin density($config-or-theme) {
7029
$density-scale: theming.get-density-config($config-or-theme);
71-
$height: mdc-density.prop-value(
72-
paginator-variables.$density-config, $density-scale, height);
7330

31+
@include sass-utils.current-selector-or-root() {
32+
@include token-utils.create-token-values(tokens-mat-paginator.$prefix,
33+
tokens-mat-paginator.get-density-tokens($density-scale));
34+
}
35+
36+
// TODO: this should be done through tokens once the form field has been switched over.
7437
.mat-mdc-paginator {
7538
// We need the form field to be narrower in order to fit into the paginator,
7639
// so we set its density to be -4 or denser.
@@ -82,10 +45,6 @@
8245
@include form-field-density.private-form-field-density($density-scale);
8346
}
8447
}
85-
86-
.mat-mdc-paginator-container {
87-
min-height: $height;
88-
}
8948
}
9049

9150
@mixin theme($theme-or-color-config) {

src/material/paginator/_paginator-variables.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
1+
// TODO: this file isn't used, but is kept for backwards compatibility. It should be deleted in v17.
2+
13
$height: 56px !default;
24
// Minimum height for paginator's in the highest density is determined based on how
35
// much the paginator can shrink until the content exceeds (i.e. navigation buttons).

src/material/paginator/paginator.scss

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
@use '@angular/cdk';
2+
@use '@material/typography/typography' as mdc-typography;
3+
@use '../core/tokens/m2/mat/paginator' as tokens-mat-paginator;
4+
@use '../core/tokens/token-utils';
25

36
$padding: 0 8px;
47
$page-size-margin-right: 8px;
@@ -13,6 +16,22 @@ $button-icon-size: 28px;
1316
.mat-mdc-paginator {
1417
display: block;
1518

19+
@include token-utils.use-tokens(
20+
tokens-mat-paginator.$prefix, tokens-mat-paginator.get-token-slots()) {
21+
@include mdc-typography.smooth-font();
22+
@include token-utils.create-token-slot(color, container-text-color);
23+
@include token-utils.create-token-slot(background-color, container-background-color);
24+
@include token-utils.create-token-slot(font-family, container-text-font);
25+
@include token-utils.create-token-slot(line-height, container-text-line-height);
26+
@include token-utils.create-token-slot(font-size, container-text-size);
27+
@include token-utils.create-token-slot(font-weight, container-text-weight);
28+
@include token-utils.create-token-slot(letter-spacing, container-text-tracking);
29+
30+
.mat-mdc-select-value {
31+
@include token-utils.create-token-slot(font-size, select-trigger-text-size);
32+
}
33+
}
34+
1635
// This element reserves space for hints and error messages.
1736
// Hide it since we know that we won't need it.
1837
.mat-mdc-form-field-subscript-wrapper {
@@ -39,6 +58,11 @@ $button-icon-size: 28px;
3958
padding: $padding;
4059
flex-wrap: wrap-reverse;
4160
width: 100%;
61+
62+
@include token-utils.use-tokens(
63+
tokens-mat-paginator.$prefix, tokens-mat-paginator.get-token-slots()) {
64+
@include token-utils.create-token-slot(min-height, container-size);
65+
}
4266
}
4367

4468
.mat-mdc-paginator-page-size {
@@ -74,6 +98,15 @@ $button-icon-size: 28px;
7498
display: inline-block;
7599
width: $button-icon-size;
76100

101+
@include token-utils.use-tokens(
102+
tokens-mat-paginator.$prefix, tokens-mat-paginator.get-token-slots()) {
103+
@include token-utils.create-token-slot(fill, enabled-icon-color);
104+
105+
.mat-mdc-icon-button[disabled] & {
106+
@include token-utils.create-token-slot(fill, disabled-icon-color);
107+
}
108+
}
109+
77110
[dir='rtl'] & {
78111
transform: rotate(180deg);
79112
}

0 commit comments

Comments
 (0)