Skip to content

Commit ad8b880

Browse files
authored
refactor(material/bottom-sheet): switch to token API (#27471)
Switches the bottom sheet to use the tokens theming API.
1 parent 439d6fc commit ad8b880

File tree

4 files changed

+92
-14
lines changed

4 files changed

+92
-14
lines changed

src/material/bottom-sheet/BUILD.bazel

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,10 @@ sass_library(
4646
sass_binary(
4747
name = "bottom_sheet_container_scss",
4848
src = "bottom-sheet-container.scss",
49-
deps = ["//src/cdk:sass_lib"],
49+
deps = [
50+
"//src/cdk:sass_lib",
51+
"//src/material/core:core_scss_lib",
52+
],
5053
)
5154

5255
ng_test_library(

src/material/bottom-sheet/_bottom-sheet-theme.scss

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,25 @@
1-
@use 'sass:map';
2-
@use '../core/style/private';
31
@use '../core/typography/typography';
4-
@use '../core/typography/typography-utils';
52
@use '../core/theming/theming';
3+
@use '../core/style/sass-utils';
4+
@use '../core/tokens/token-utils';
5+
@use '../core/tokens/m2/mat/bottom-sheet' as tokens-mat-bottom-sheet;
66

77
@mixin color($config-or-theme) {
88
$config: theming.get-color-config($config-or-theme);
9-
$background: map.get($config, background);
10-
$foreground: map.get($config, foreground);
119

12-
.mat-bottom-sheet-container {
13-
@include private.private-theme-elevation(16, $config);
14-
background: theming.get-color-from-palette($background, dialog);
15-
color: theming.get-color-from-palette($foreground, text);
10+
@include sass-utils.current-selector-or-root() {
11+
@include token-utils.create-token-values(tokens-mat-bottom-sheet.$prefix,
12+
tokens-mat-bottom-sheet.get-color-tokens($config));
1613
}
1714
}
1815

1916
@mixin typography($config-or-theme) {
2017
$config: typography.private-typography-to-2014-config(
2118
theming.get-typography-config($config-or-theme));
22-
.mat-bottom-sheet-container {
23-
@include typography-utils.typography-level($config, body-1);
19+
20+
@include sass-utils.current-selector-or-root() {
21+
@include token-utils.create-token-values(tokens-mat-bottom-sheet.$prefix,
22+
tokens-mat-bottom-sheet.get-typography-tokens($config));
2423
}
2524
}
2625

src/material/bottom-sheet/bottom-sheet-container.scss

Lines changed: 22 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,7 @@
11
@use '@angular/cdk';
2+
@use '../core/style/elevation';
3+
@use '../core/tokens/m2/mat/bottom-sheet' as tokens-mat-bottom-sheet;
4+
@use '../core/tokens/token-utils';
25

36
// The bottom sheet minimum width on larger screen sizes is based
47
// on increments of the toolbar, according to the spec. See:
@@ -8,6 +11,9 @@ $container-vertical-padding: 8px !default;
811
$container-horizontal-padding: 16px !default;
912

1013
.mat-bottom-sheet-container {
14+
@include token-utils.create-token-values(
15+
tokens-mat-bottom-sheet.$prefix, tokens-mat-bottom-sheet.get-unthemable-tokens());
16+
@include elevation.elevation(16);
1117
padding: $container-vertical-padding
1218
$container-horizontal-padding;
1319
min-width: 100vw;
@@ -17,15 +23,29 @@ $container-horizontal-padding: 16px !default;
1723
max-height: 80vh;
1824
overflow: auto;
1925

26+
@include token-utils.use-tokens(
27+
tokens-mat-bottom-sheet.$prefix, tokens-mat-bottom-sheet.get-token-slots()) {
28+
@include token-utils.create-token-slot(background, container-background-color);
29+
@include token-utils.create-token-slot(color, container-text-color);
30+
@include token-utils.create-token-slot(font-family, container-text-font);
31+
@include token-utils.create-token-slot(font-size, container-text-size);
32+
@include token-utils.create-token-slot(line-height, container-text-line-height);
33+
@include token-utils.create-token-slot(font-weight, container-text-weight);
34+
@include token-utils.create-token-slot(letter-spacing, container-text-tracking);
35+
}
36+
2037
@include cdk.high-contrast(active, off) {
2138
outline: 1px solid;
2239
}
2340
}
2441

2542
// Applies a border radius to the bottom sheet. Should only be applied when it's not full-screen.
2643
%_mat-bottom-sheet-container-border-radius {
27-
border-top-left-radius: 4px;
28-
border-top-right-radius: 4px;
44+
@include token-utils.use-tokens(
45+
tokens-mat-bottom-sheet.$prefix, tokens-mat-bottom-sheet.get-token-slots()) {
46+
@include token-utils.create-token-slot(border-top-left-radius, container-shape);
47+
@include token-utils.create-token-slot(border-top-right-radius, container-shape);
48+
}
2949
}
3050

3151
.mat-bottom-sheet-container-medium {
Lines changed: 56 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,56 @@
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, bottom-sheet);
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+
// TODO: will be necessary for M3.
15+
container-shape: 4px,
16+
);
17+
}
18+
19+
// Tokens that can be configured through Angular Material's color theming API.
20+
@function get-color-tokens($config) {
21+
$foreground: map.get($config, foreground);
22+
$background: map.get($config, background);
23+
24+
@return (
25+
container-text-color: theming.get-color-from-palette($foreground, text),
26+
container-background-color: theming.get-color-from-palette($background, dialog),
27+
);
28+
}
29+
30+
// Tokens that can be configured through Angular Material's typography theming API.
31+
@function get-typography-tokens($config) {
32+
@return (
33+
container-text-font: typography-utils.font-family($config, body-1) or
34+
typography-utils.font-family($config),
35+
container-text-line-height: typography-utils.line-height($config, body-1),
36+
container-text-size: typography-utils.font-size($config, body-1),
37+
container-text-tracking: typography-utils.letter-spacing($config, body-1),
38+
container-text-weight: typography-utils.font-weight($config, body-1),
39+
);
40+
}
41+
42+
// Tokens that can be configured through Angular Material's density theming API.
43+
@function get-density-tokens($config) {
44+
@return ();
45+
}
46+
47+
// Combines the tokens generated by the above functions into a single map with placeholder values.
48+
// This is used to create token slots.
49+
@function get-token-slots() {
50+
@return sass-utils.deep-merge-all(
51+
get-unthemable-tokens(),
52+
get-color-tokens(token-utils.$placeholder-color-config),
53+
get-typography-tokens(token-utils.$placeholder-typography-config),
54+
get-density-tokens(token-utils.$placeholder-density-config)
55+
);
56+
}

0 commit comments

Comments
 (0)