Skip to content

Commit eeee16b

Browse files
committed
fixup! refactor(material/table): switch to tokens API
1 parent 92a0978 commit eeee16b

File tree

2 files changed

+35
-35
lines changed

2 files changed

+35
-35
lines changed

src/material/core/tokens/_token-utils.scss

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,12 +71,13 @@ $_component-prefix: null;
7171

7272
// Emits a slot for the given token, provided that it has a non-null value in the token map passed
7373
// to `use-tokens`.
74-
@mixin create-token-slot($property, $token) {
74+
@mixin create-token-slot($property, $token, $emit-fallback: false) {
7575
@if $_component-prefix == null or $_tokens == null {
7676
@error '`create-token-slot` must be used within `use-tokens`';
7777
}
7878
@if map.get($_tokens, $token) != null {
79-
$value: mdc-custom-properties.create('#{$_component-prefix}-#{$token}');
79+
$fallback: if($emit-fallback, map.get($_tokens, $token), null);
80+
$value: mdc-custom-properties.create('#{$_component-prefix}-#{$token}', $fallback: $fallback);
8081
@include mdc-theme.property($property, $value);
8182
}
8283
}

src/material/table/table.scss

Lines changed: 32 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,6 @@
22
@use '@material/data-table/data-table-cell' as mdc-data-table-cell;
33
@use '@material/data-table/data-table-header-cell' as mdc-data-table-header-cell;
44
@use '@material/data-table' as mdc-data-table-theme;
5-
@use '@material/theme/custom-properties' as mdc-custom-properties;
65
@use '../core/mdc-helpers/mdc-helpers';
76
@use '../core/tokens/token-utils';
87
@use '../core/tokens/m2/mat/table' as tokens-mat-table;
@@ -25,47 +24,47 @@
2524
}
2625
}
2726

28-
@include mdc-custom-properties.configure($emit-fallback-values: false, $emit-fallback-vars: false) {
29-
@include mdc-data-table.static-styles($query: mdc-helpers.$mdc-base-styles-query);
30-
@include mdc-data-table-cell.static-styles($query: mdc-helpers.$mdc-base-styles-query);
31-
@include mdc-data-table-header-cell.static-styles($query: mdc-helpers.$mdc-base-styles-query);
32-
@include mdc-data-table-theme.cell-padding(
33-
$leading-padding: mdc-data-table-theme.$cell-leading-padding,
34-
$trailing-padding: mdc-data-table-theme.$cell-trailing-padding,
35-
$query: mdc-helpers.$mdc-base-styles-query
36-
);
37-
@include table-flex-styles.private-table-flex-styles();
38-
39-
.mat-mdc-table {
40-
@include token-utils.create-token-values(
41-
tokens-mat-table.$prefix, tokens-mat-table.get-unthemable-tokens());
42-
43-
// MDC Table applies `table-layout: fixed`, but this is a backwards incompatible
44-
// change since the table did not previously apply it.
45-
// TODO: Add a mixin to MDC to set the layout instead of including this override,
46-
// see this issue: https://github.com/material-components/material-components-web/issues/6412
47-
table-layout: auto;
48-
49-
// The MDC table does not allow text to wrap within the cell. This allows for text to
50-
// wrap when the cell reaches its maximum width.
51-
white-space: normal;
52-
53-
@include token-utils.use-tokens(tokens-mat-table.$prefix, tokens-mat-table.get-token-slots()) {
54-
@include token-utils.create-token-slot(background-color, background-color);
55-
}
27+
@include mdc-data-table.static-styles($query: mdc-helpers.$mdc-base-styles-query);
28+
@include mdc-data-table-cell.static-styles($query: mdc-helpers.$mdc-base-styles-query);
29+
@include mdc-data-table-header-cell.static-styles($query: mdc-helpers.$mdc-base-styles-query);
30+
@include mdc-data-table-theme.cell-padding(
31+
$leading-padding: mdc-data-table-theme.$cell-leading-padding,
32+
$trailing-padding: mdc-data-table-theme.$cell-trailing-padding,
33+
$query: mdc-helpers.$mdc-base-styles-query
34+
);
35+
@include table-flex-styles.private-table-flex-styles();
36+
37+
.mat-mdc-table {
38+
@include token-utils.create-token-values(
39+
tokens-mat-table.$prefix, tokens-mat-table.get-unthemable-tokens());
40+
41+
// MDC Table applies `table-layout: fixed`, but this is a backwards incompatible
42+
// change since the table did not previously apply it.
43+
// TODO: Add a mixin to MDC to set the layout instead of including this override,
44+
// see this issue: https://github.com/material-components/material-components-web/issues/6412
45+
table-layout: auto;
46+
47+
// The MDC table does not allow text to wrap within the cell. This allows for text to
48+
// wrap when the cell reaches its maximum width.
49+
white-space: normal;
50+
51+
@include token-utils.use-tokens(tokens-mat-table.$prefix, tokens-mat-table.get-token-slots()) {
52+
@include token-utils.create-token-slot(background-color, background-color);
5653
}
54+
}
5755

56+
@include mdc-helpers.disable-mdc-fallback-declarations {
5857
@include token-utils.use-tokens(tokens-mat-table.$prefix, tokens-mat-table.get-token-slots()) {
5958
.mat-mdc-header-row {
60-
@include token-utils.create-token-slot(height, header-container-height);
59+
@include token-utils.create-token-slot(height, header-container-height, true);
6160
}
6261

6362
.mat-mdc-row {
64-
@include token-utils.create-token-slot(height, row-item-container-height);
63+
@include token-utils.create-token-slot(height, row-item-container-height, true);
6564
}
6665

6766
.mat-mdc-footer-row {
68-
@include token-utils.create-token-slot(height, footer-container-height);
67+
@include token-utils.create-token-slot(height, footer-container-height, true);
6968
}
7069

7170
.mat-mdc-header-cell {
@@ -75,7 +74,7 @@
7574
@include token-utils.create-token-slot(line-height, header-headline-line-height);
7675
@include token-utils.create-token-slot(font-size, header-headline-size);
7776
@include token-utils.create-token-slot(letter-spacing, header-headline-tracking);
78-
@include token-utils.create-token-slot(font-weight, header-headline-weight);
77+
@include token-utils.create-token-slot(font-weight, header-headline-weight, true);
7978
}
8079

8180
.mat-mdc-cell {

0 commit comments

Comments
 (0)