Skip to content

Commit 2d40fbe

Browse files
author
Andrew Seguin
committed
fix(material-experimental/column-resize): fix m2 colors
1 parent c63d735 commit 2d40fbe

File tree

2 files changed

+41
-15
lines changed

2 files changed

+41
-15
lines changed

src/dev-app/theme-m3.scss

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -38,8 +38,9 @@ html {
3838
@include mat.all-component-themes($light-theme);
3939
@include mat.system-level-colors($light-theme);
4040
@include mat.system-level-typography($light-theme);
41-
// TODO(mmalerba): Support M3 for experimental components.
4241
@include matx.column-resize-theme($light-theme);
42+
43+
// TODO(mmalerba): Support M3 for experimental popover-edit.
4344
// @include matx.popover-edit-theme($light-theme);
4445
}
4546

@@ -52,6 +53,7 @@ html {
5253
typography: Roboto,
5354
density: 0,
5455
));
56+
@include matx.column-resize-theme();
5557
}
5658

5759
@include mat.system-classes();
@@ -76,8 +78,8 @@ body.demo-unicorn-dark-theme {
7678
// Include the dark theme color styles.
7779
@include mat.all-component-colors($dark-theme);
7880
@include mat.system-level-colors($dark-theme);
79-
// TODO(mmalerba): Support M3 for experimental components.
80-
// @include matx.column-resize-color($dark-theme);
81+
@include matx.column-resize-color($dark-theme);
82+
// TODO(mmalerba): Support M3 for experimental popover-edit.
8183
// @include matx.popover-edit-color($dark-theme);
8284
}
8385

src/material-experimental/column-resize/_column-resize-theme.scss

Lines changed: 36 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,17 @@
11
@use '@angular/material' as mat;
22
@use 'sass:map';
33

4-
@mixin color($theme) {
5-
$resizable-hover-divider: mat.get-theme-color($theme, primary, 60);
6-
$resizable-active-divider: mat.get-theme-color($theme, primary, 60);
4+
@mixin color($theme: null) {
5+
// If a theme is provided, use the primary color defined by the system map. Otherwise, let it
6+
// fallback to the CSS variable system token. Wrap CSS variable definition in a root selector, if
7+
// the call was made at the top level without a selector.
8+
@if ($theme) {
9+
@include _current-selector-or-root() {
10+
--mat-column-resize-outline-color: #{map.get($theme, _mat-system, outline)};
11+
--mat-column-resize-hover-color: #{map.get($theme, _mat-system, primary)};
12+
--mat-column-resize-active-color: #{map.get($theme, _mat-system, primary)};
13+
}
14+
}
715

816
// TODO: these styles don't really belong in the `color` part of the theme.
917
// We should figure out a better place for them.
@@ -65,15 +73,15 @@
6573

6674
.mat-header-cell:not(.mat-resizable)::after,
6775
.mat-mdc-header-cell:not(.mat-resizable)::after {
68-
background: map.get($theme, _mat-system, outline);
76+
background: var(--mat-column-resize-border-color, var(--mat-sys-outline));
6977
}
7078

7179
.mat-resizable-handle {
72-
background: $resizable-hover-divider;
80+
background: var(--mat-column-resize-hover-color, var(--mat-sys-primary));
7381
}
7482

7583
.cdk-resizable-resize-disabled > .mat-resizable-handle {
76-
background: map.get($theme, _mat-system, outline);
84+
background: var(--mat-column-resize-border-color, var(--mat-sys-outline));
7785
}
7886
}
7987

@@ -99,6 +107,8 @@
99107
transition: none;
100108
}
101109

110+
$resizable-active-divider: var(--mat-column-resize-active-color, var(--mat-sys-primary));
111+
102112
.mat-resizable-handle:focus,
103113
.mat-header-row.cdk-column-resize-hover-or-active .mat-resizable-handle:focus,
104114
.mat-mdc-header-row.cdk-column-resize-hover-or-active .mat-resizable-handle:focus {
@@ -136,18 +146,32 @@
136146
}
137147
}
138148

139-
@mixin typography($theme) {}
149+
@mixin typography($theme: null) {}
140150

141-
@mixin density($theme) {}
151+
@mixin density($theme: null) {}
142152

143-
@mixin theme($theme) {
144-
@if mat.theme-has($theme, color) {
153+
@mixin theme($theme: null) {
154+
@if mat.theme-has($theme, color) or not $theme {
145155
@include color($theme);
146156
}
147-
@if mat.theme-has($theme, density) {
157+
@if mat.theme-has($theme, density) or not $theme {
148158
@include density($theme);
149159
}
150-
@if mat.theme-has($theme, typography) {
160+
@if mat.theme-has($theme, typography) or not $theme {
151161
@include typography($theme);
152162
}
153163
}
164+
165+
// Copy of Angular Material's `sass-utils.current-selector-or-root` function so
166+
// that variables can be defined at a top-level safely.
167+
// src/material/core/style/_sass-utils.scss
168+
@mixin _current-selector-or-root($root: html) {
169+
@if & {
170+
@content;
171+
}
172+
@else {
173+
#{$root} {
174+
@content;
175+
}
176+
}
177+
}

0 commit comments

Comments
 (0)