Skip to content

Commit 6f781e5

Browse files
committed
refactor(material/grid-list): switch to tokens theming API (#27533)
Reworks the grid list to use tokens for theming. (cherry picked from commit 3e23676)
1 parent 10d107d commit 6f781e5

File tree

3 files changed

+73
-6
lines changed

3 files changed

+73
-6
lines changed
Lines changed: 46 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,46 @@
1+
@use '../../token-utils';
2+
@use '../../../typography/typography-utils';
3+
@use '../../../style/sass-utils';
4+
5+
// The prefix used to generate the fully qualified name for tokens in this file.
6+
$prefix: (mat, grid-list);
7+
8+
// Tokens that can't be configured through Angular Material's current theming API,
9+
// but may be in a future version of the theming API.
10+
@function get-unthemable-tokens() {
11+
@return ();
12+
}
13+
14+
// Tokens that can be configured through Angular Material's color theming API.
15+
@function get-color-tokens($config) {
16+
@return ();
17+
}
18+
19+
// Tokens that can be configured through Angular Material's typography theming API.
20+
@function get-typography-tokens($config) {
21+
@return (
22+
// TODO(crisbeto): other components have tokens for all typography dimensions.
23+
// Here we only set the font size to maintain the same appearance as the pre-tokens
24+
// theming API. Consider adding more tokens for letter spacing, font weight etc.
25+
tile-header-primary-text-size: typography-utils.font-size($config, body-1),
26+
tile-header-secondary-text-size: typography-utils.font-size($config, caption),
27+
tile-footer-primary-text-size: typography-utils.font-size($config, body-1),
28+
tile-footer-secondary-text-size: typography-utils.font-size($config, caption),
29+
);
30+
}
31+
32+
// Tokens that can be configured through Angular Material's density theming API.
33+
@function get-density-tokens($config) {
34+
@return ();
35+
}
36+
37+
// Combines the tokens generated by the above functions into a single map with placeholder values.
38+
// This is used to create token slots.
39+
@function get-token-slots() {
40+
@return sass-utils.deep-merge-all(
41+
get-unthemable-tokens(),
42+
get-color-tokens(token-utils.$placeholder-color-config),
43+
get-typography-tokens(token-utils.$placeholder-typography-config),
44+
get-density-tokens(token-utils.$placeholder-density-config)
45+
);
46+
}

src/material/grid-list/_grid-list-theme.scss

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
@use '../core/theming/theming';
22
@use '../core/typography/typography';
3-
@use '../core/typography/typography-utils';
4-
@use '../core/style/list-common';
3+
@use '../core/tokens/m2/mat/grid-list' as tokens-mat-grid-list;
4+
@use '../core/style/sass-utils';
5+
@use '../core/tokens/token-utils';
56

67

78
// Include this empty mixin for consistency with the other components.
@@ -10,10 +11,10 @@
1011
@mixin typography($config-or-theme) {
1112
$config: typography.private-typography-to-2014-config(
1213
theming.get-typography-config($config-or-theme));
13-
.mat-grid-tile-header,
14-
.mat-grid-tile-footer {
15-
@include list-common.base(typography-utils.font-size($config, caption));
16-
font-size: typography-utils.font-size($config, body-1);
14+
15+
@include sass-utils.current-selector-or-root() {
16+
@include token-utils.create-token-values(tokens-mat-grid-list.$prefix,
17+
tokens-mat-grid-list.get-typography-tokens($config));
1718
}
1819
}
1920

src/material/grid-list/grid-list.scss

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
@use '../core/style/list-common';
22
@use '../core/style/layout-common';
3+
@use '../core/tokens/m2/mat/grid-list' as tokens-mat-grid-list;
4+
@use '../core/tokens/token-utils';
35

46

57
// height of tile header or footer if it has one line
@@ -68,6 +70,24 @@ $text-padding: 16px;
6870
}
6971
}
7072

73+
.mat-grid-tile-header {
74+
@include token-utils.use-tokens(
75+
tokens-mat-grid-list.$prefix, tokens-mat-grid-list.get-token-slots()) {
76+
$secondary-token-name: token-utils.get-token-variable(tile-header-secondary-text-size);
77+
@include list-common.base(var(#{$secondary-token-name}));
78+
@include token-utils.create-token-slot(font-size, tile-header-primary-text-size);
79+
}
80+
}
81+
82+
.mat-grid-tile-footer {
83+
@include token-utils.use-tokens(
84+
tokens-mat-grid-list.$prefix, tokens-mat-grid-list.get-token-slots()) {
85+
$secondary-token-name: token-utils.get-token-variable(tile-footer-secondary-text-size);
86+
@include list-common.base(var(#{$secondary-token-name}));
87+
@include token-utils.create-token-slot(font-size, tile-footer-primary-text-size);
88+
}
89+
}
90+
7191
.mat-grid-tile-content {
7292
@include layout-common.fill;
7393
display: flex;

0 commit comments

Comments
 (0)