Skip to content

Commit

Permalink
refactor(material/divider): switch to tokens API (#27478)
Browse files Browse the repository at this point in the history
(cherry picked from commit cc02ea8)
  • Loading branch information
behzadmehrabi authored and crisbeto committed Jul 21, 2023
1 parent 1de57bf commit 5bd9a56
Show file tree
Hide file tree
Showing 4 changed files with 72 additions and 14 deletions.
45 changes: 45 additions & 0 deletions src/material/core/tokens/m2/mat/_divider.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,45 @@
@use 'sass:map';
@use '../../token-utils';
@use '../../../theming/theming';
@use '../../../style/sass-utils';

// The prefix used to generate the fully qualified name for tokens in this file.
$prefix: (mat, divider);

// Tokens that can't be configured through Angular Material's current theming API,
// but may be in a future version of the theming API.
@function get-unthemable-tokens() {
@return (
width: 1px
);
}

// Tokens that can be configured through Angular Material's color theming API.
@function get-color-tokens($config) {
$foreground: map.get($config, foreground);

@return (
color: theming.get-color-from-palette($foreground, divider)
);
}

// Tokens that can be configured through Angular Material's typography theming API.
@function get-typography-tokens($config) {
@return ();
}

// Tokens that can be configured through Angular Material's density theming API.
@function get-density-tokens($config) {
@return ();
}

// Combines the tokens generated by the above functions into a single map with placeholder values.
// This is used to create token slots.
@function get-token-slots() {
@return sass-utils.deep-merge-all(
get-unthemable-tokens(),
get-color-tokens(token-utils.$placeholder-color-config),
get-typography-tokens(token-utils.$placeholder-typography-config),
get-density-tokens(token-utils.$placeholder-density-config)
);
}
4 changes: 4 additions & 0 deletions src/material/divider/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,10 @@ sass_library(
sass_binary(
name = "divider_scss",
src = "divider.scss",
deps = [
":divider_scss_lib",
"//src/material/core:core_scss_lib",
],
)

ng_test_library(
Expand Down
14 changes: 6 additions & 8 deletions src/material/divider/_divider-theme.scss
Original file line number Diff line number Diff line change
@@ -1,16 +1,14 @@
@use 'sass:map';
@use '../core/style/sass-utils';
@use '../core/theming/theming';
@use '../core/tokens/token-utils';
@use '../core/tokens/m2/mat/divider' as tokens-mat-divider;

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

.mat-divider {
border-top-color: theming.get-color-from-palette($foreground, divider);
}

.mat-divider-vertical {
border-right-color: theming.get-color-from-palette($foreground, divider);
@include sass-utils.current-selector-or-root() {
@include token-utils.create-token-values(tokens-mat-divider.$prefix,
tokens-mat-divider.get-color-tokens($config));
}
}

Expand Down
23 changes: 17 additions & 6 deletions src/material/divider/divider.scss
Original file line number Diff line number Diff line change
@@ -1,16 +1,27 @@
$width: 1px;
@use '../core/tokens/token-utils';
@use '../core/tokens/m2/mat/divider' as tokens-mat-divider;


$inset-margin: 80px;

.mat-divider {
@include token-utils.create-token-values(
tokens-mat-divider.$prefix, tokens-mat-divider.get-unthemable-tokens());

display: block;
margin: 0;
border-top-width: $width;
border-top-style: solid;
@include token-utils.use-tokens(
tokens-mat-divider.$prefix, tokens-mat-divider.get-token-slots()) {
@include token-utils.create-token-slot(border-top-color, color);
@include token-utils.create-token-slot(border-top-width, width);

&.mat-divider-vertical {
border-top: 0;
border-right-width: $width;
border-right-style: solid;
&.mat-divider-vertical {
border-top: 0;
border-right-style: solid;
@include token-utils.create-token-slot(border-right-color, color);
@include token-utils.create-token-slot(border-right-width, width);
}
}

&.mat-divider-inset {
Expand Down

0 comments on commit 5bd9a56

Please sign in to comment.