Skip to content

Commit c568722

Browse files
committed
refactor(material/divider): switch to tokens API
1 parent ffffc82 commit c568722

File tree

3 files changed

+63
-11
lines changed

3 files changed

+63
-11
lines changed
Lines changed: 45 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,45 @@
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, divider);
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+
line-color: theming.get-color-from-palette($foreground, divider)
23+
);
24+
}
25+
26+
// Tokens that can be configured through Angular Material's typography theming API.
27+
@function get-typography-tokens($config) {
28+
@return ();
29+
}
30+
31+
// Tokens that can be configured through Angular Material's density theming API.
32+
@function get-density-tokens($config) {
33+
@return ();
34+
}
35+
36+
// Combines the tokens generated by the above functions into a single map with placeholder values.
37+
// This is used to create token slots.
38+
@function get-token-slots() {
39+
@return sass-utils.deep-merge-all(
40+
get-unthemable-tokens(),
41+
get-color-tokens(token-utils.$placeholder-color-config),
42+
get-typography-tokens(token-utils.$placeholder-typography-config),
43+
get-density-tokens(token-utils.$placeholder-density-config)
44+
);
45+
}

src/material/divider/_divider-theme.scss

Lines changed: 6 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -1,16 +1,15 @@
11
@use 'sass:map';
2+
@use '../core/style/sass-utils';
23
@use '../core/theming/theming';
4+
@use '../core/tokens/token-utils';
5+
@use '../core/tokens/m2/mat/divider' as tokens-mat-divider;
36

47
@mixin color($config-or-theme) {
58
$config: theming.get-color-config($config-or-theme);
6-
$foreground: map.get($config, foreground);
79

8-
.mat-divider {
9-
border-top-color: theming.get-color-from-palette($foreground, divider);
10-
}
11-
12-
.mat-divider-vertical {
13-
border-right-color: theming.get-color-from-palette($foreground, divider);
10+
@include sass-utils.current-selector-or-root() {
11+
@include token-utils.create-token-values(tokens-mat-divider.$prefix,
12+
tokens-mat-divider.get-color-tokens($config));
1413
}
1514
}
1615

src/material/divider/divider.scss

Lines changed: 12 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
@use '../core/tokens/token-utils';
2+
@use '../core/tokens/m2/mat/divider' as tokens-mat-divider;
3+
4+
15
$width: 1px;
26
$inset-margin: 80px;
37

@@ -6,11 +10,15 @@ $inset-margin: 80px;
610
margin: 0;
711
border-top-width: $width;
812
border-top-style: solid;
13+
@include token-utils.use-tokens(tokens-mat-divider.$prefix, tokens-mat-divider.get-token-slots()) {
14+
@include token-utils.create-token-slot(border-top-color, line-color);
915

10-
&.mat-divider-vertical {
11-
border-top: 0;
12-
border-right-width: $width;
13-
border-right-style: solid;
16+
&.mat-divider-vertical {
17+
border-top: 0;
18+
border-right-width: $width;
19+
border-right-style: solid;
20+
@include token-utils.create-token-slot(border-right-color, line-color);
21+
}
1422
}
1523

1624
&.mat-divider-inset {

0 commit comments

Comments
 (0)