Skip to content

Commit c1bbdbe

Browse files
committed
fixup! refactor(material/table): switch to tokens API
1 parent 4167562 commit c1bbdbe

File tree

3 files changed

+42
-41
lines changed

3 files changed

+42
-41
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/core/tokens/m2/mat/_table.scss

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
@use '../../../theming/theming';
33
@use '../../../typography/typography-utils';
44
@use '../../token-utils';
5+
@use '../../../style/sass-utils';
56

67
// The prefix used to generate the fully qualified name for tokens in this file.
78
$prefix: (mat, table);
@@ -87,7 +88,7 @@ $prefix: (mat, table);
8788
// Combines the tokens generated by the above functions into a single map with placeholder values.
8889
// This is used to create token slots.
8990
@function get-token-slots() {
90-
@return token-utils.merge-all(
91+
@return sass-utils.deep-merge-all(
9192
get-unthemable-tokens(),
9293
get-color-tokens(token-utils.$placeholder-color-config),
9394
get-typography-tokens(token-utils.$placeholder-typography-config),

src/material/table/table.scss

Lines changed: 37 additions & 38 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;
@@ -16,56 +15,56 @@
1615
}
1716

1817
@mixin _cell-border {
19-
@include token-utils.create-token-slot(border-bottom-color, row-item-outline-color);
20-
@include token-utils.create-token-slot(border-bottom-width, row-item-outline-width);
18+
@include token-utils.create-token-slot(border-bottom-color, row-item-outline-color, true);
19+
@include token-utils.create-token-slot(border-bottom-width, row-item-outline-width, true);
2120
border-bottom-style: solid;
2221

2322
.mdc-data-table__row:last-child & {
2423
border-bottom: none;
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 {
@@ -119,9 +118,9 @@ mat-row.mat-mdc-row, mat-header-row.mat-mdc-header-row, mat-footer-row.mat-mdc-f
119118
// children. Otherwise, the cells grow larger than the row and the layout breaks.
120119
.mat-mdc-flex-table {
121120
@include token-utils.create-token-values(tokens-mat-table.$prefix, (
122-
header-container-height: unset,
123-
footer-container-height: unset,
124-
row-item-container-height: unset,
121+
header-container-height: auto,
122+
footer-container-height: auto,
123+
row-item-container-height: auto,
125124
));
126125
}
127126

0 commit comments

Comments
 (0)