Skip to content

Commit 55373fb

Browse files
devversionandrewseguin
authored andcommitted
refactor: add density mixins to all components
This commit is the initial basis for the upcoming density API. It adds mixins for density to all components, sets up a larger bulk density mixin in the dev-app for testing etc.
1 parent e408228 commit 55373fb

File tree

77 files changed

+1729
-329
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

77 files changed

+1729
-329
lines changed

.github/CODEOWNERS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -97,6 +97,7 @@
9797
/src/material-experimental/mdc-card/** @mmalerba
9898
/src/material-experimental/mdc-checkbox/** @mmalerba
9999
/src/material-experimental/mdc-chips/** @mmalerba
100+
/src/material-experimental/mdc-density/** @devversion
100101
/src/material-experimental/mdc-dialog/** @devversion
101102
/src/material-experimental/mdc-form-field/** @devversion @mmalerba
102103
/src/material-experimental/mdc-helpers/** @mmalerba

src/dev-app/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -96,6 +96,7 @@ sass_binary(
9696
],
9797
deps = [
9898
"//src/material-experimental/column-resize:column_resize_scss_lib",
99+
"//src/material-experimental/mdc-density:all_density",
99100
"//src/material-experimental/mdc-theming:all_themes",
100101
"//src/material-experimental/mdc-typography:all_typography",
101102
"//src/material-experimental/popover-edit:popover_edit_scss_lib",

src/dev-app/dev-app/dev-app-layout.html

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,10 @@ <h1>Angular Material Demos</h1>
4444
title="Toggle between RTL and LTR">
4545
{{dir.value.toUpperCase()}}
4646
</button>
47+
<button mat-button (click)="selectNextDensity()"
48+
title="Use next density scale: {{densityScales[getNextDensityIndex()]}}">
49+
Density scale: {{densityScales[this.currentDensityIndex]}}
50+
</button>
4751
</div>
4852
</div>
4953
</mat-toolbar>

src/dev-app/dev-app/dev-app-layout.ts

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,10 +88,17 @@ export class DevAppLayout {
8888
{name: 'MDC Table', route: '/mdc-table'},
8989
];
9090

91+
/** Currently selected density scale based on the index. */
92+
currentDensityIndex = 0;
93+
94+
/** List of possible global density scale values. */
95+
densityScales = [0, -1, -2, 'minimum', 'maximum'];
96+
9197
constructor(
9298
private _element: ElementRef<HTMLElement>, public rippleOptions: DevAppRippleOptions,
9399
@Inject(Directionality) public dir: DevAppDirectionality, cdr: ChangeDetectorRef) {
94100
dir.change.subscribe(() => cdr.markForCheck());
101+
this.updateDensityClasses();
95102
}
96103

97104
toggleFullscreen() {
@@ -131,4 +138,31 @@ export class DevAppLayout {
131138
document.body.classList.remove(strongFocusClass);
132139
}
133140
}
141+
142+
143+
/** Gets the index of the next density scale that can be selected. */
144+
getNextDensityIndex() {
145+
return (this.currentDensityIndex + 1) % this.densityScales.length;
146+
}
147+
148+
/** Selects the next possible density scale. */
149+
selectNextDensity() {
150+
this.currentDensityIndex = this.getNextDensityIndex();
151+
this.updateDensityClasses();
152+
}
153+
154+
/**
155+
* Updates the density classes on the host element. Applies a unique class for
156+
* a given density scale, so that the density styles are conditionally applied.
157+
*/
158+
updateDensityClasses() {
159+
for (let i = 0; i < this.densityScales.length; i++) {
160+
const className = `demo-density-${this.densityScales[i]}`;
161+
if (i === this.currentDensityIndex) {
162+
this._element.nativeElement.classList.add(className);
163+
} else {
164+
this._element.nativeElement.classList.remove(className);
165+
}
166+
}
167+
}
134168
}

src/dev-app/theme.scss

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
@import '../material-experimental/mdc-helpers/mdc-helpers';
55
@import '../material-experimental/mdc-theming/all-theme';
66
@import '../material-experimental/mdc-typography/all-typography';
7+
@import '../material-experimental/mdc-density/all-density';
78
@import '../material-experimental/popover-edit/popover-edit';
89

910
// Plus imports for other components in your app.
@@ -13,7 +14,7 @@
1314
// **Be sure that you only ever include this mixin once!**
1415
@include mat-core();
1516
@include angular-material-mdc-typography();
16-
@include mat-edit-typography(mat-typography-config());
17+
@include mat-popover-edit-typography(mat-typography-config());
1718

1819
// Include base styles for strong focus indicators.
1920
.demo-strong-focus {
@@ -24,7 +25,12 @@
2425
// Define the default theme (same as the example above).
2526
$candy-app-primary: mat-palette($mat-indigo);
2627
$candy-app-accent: mat-palette($mat-pink, A200, A100, A400);
27-
$candy-app-theme: mat-light-theme($candy-app-primary, $candy-app-accent);
28+
$candy-app-theme: mat-light-theme((
29+
color: (
30+
primary: $candy-app-primary,
31+
accent: $candy-app-accent
32+
)
33+
));
2834

2935
// Include the default theme styles.
3036
@include angular-material-theme($candy-app-theme);
@@ -36,7 +42,13 @@ $candy-app-theme: mat-light-theme($candy-app-primary, $candy-app-accent);
3642
$dark-primary: mat-palette($mat-blue-grey);
3743
$dark-accent: mat-palette($mat-amber, A200, A100, A400);
3844
$dark-warn: mat-palette($mat-deep-orange);
39-
$dark-theme: mat-dark-theme($dark-primary, $dark-accent, $dark-warn);
45+
$dark-theme: mat-dark-theme((
46+
color: (
47+
primary: $dark-primary,
48+
accent: $dark-accent,
49+
warn: $dark-warn
50+
)
51+
));
4052

4153
// Include the default theme for focus indicators.
4254
.demo-strong-focus {
@@ -60,3 +72,13 @@ $dark-theme: mat-dark-theme($dark-primary, $dark-accent, $dark-warn);
6072
@include mat-strong-focus-indicators-theme($dark-theme);
6173
@include mat-mdc-strong-focus-indicators-theme($dark-theme);
6274
}
75+
76+
// Create classes for all density scales which are supported by all MDC-based components.
77+
// The classes are applied conditionally based on the selected density in the dev-app layout
78+
// component.
79+
$density-scales: (-1, -2, minimum, maximum);
80+
@each $density in$density-scales {
81+
.demo-density-#{$density} {
82+
@include angular-material-density-mdc($density);
83+
}
84+
}

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

Lines changed: 23 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -3,9 +3,9 @@
33
@import '../../material/core/theming/palette';
44
@import '../../material/core/theming/theming';
55

6-
@mixin mat-column-resize-theme($theme) {
7-
$primary: map-get($theme, primary);
8-
$foreground: map-get($theme, foreground);
6+
@mixin mat-column-resize-color($config) {
7+
$primary: map-get($config, primary);
8+
$foreground: map-get($config, foreground);
99

1010
$non-resizable-hover-divider: mat-color($foreground, divider);
1111
$resizable-hover-divider: mat-color($primary, 200);
@@ -94,3 +94,23 @@
9494
}
9595
}
9696
}
97+
98+
@mixin mat-column-resize-typography($config) {}
99+
100+
@mixin mat-column-resize-density($density-scale) {}
101+
102+
@mixin mat-column-resize-theme($theme) {
103+
$color: mat-get-color-config($theme);
104+
$density: mat-get-density-config($theme);
105+
$typography: mat-get-typography-config($theme);
106+
107+
@if $color != null {
108+
@include mat-column-resize-color($color);
109+
}
110+
@if $density != null {
111+
@include mat-column-resize-density($density);
112+
}
113+
@if $typography != null {
114+
@include mat-column-resize-typography($typography);
115+
}
116+
}
Lines changed: 20 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@import '../mdc-helpers/mdc-helpers';
22

3-
@mixin mat-mdc-autocomplete-theme($theme) {
4-
@include mat-using-mdc-theme($theme) {
3+
@mixin mat-mdc-autocomplete-color($config) {
4+
@include mat-using-mdc-theme($config) {
55
// TODO: implement MDC-based autocomplete.
66
}
77
}
@@ -11,3 +11,21 @@
1111
// TODO: implement MDC-based autocomplete.
1212
}
1313
}
14+
15+
@mixin mat-mdc-autocomplete-density($density-scale) {}
16+
17+
@mixin mat-mdc-autocomplete-theme($theme) {
18+
$color: mat-get-color-config($theme);
19+
$density: mat-get-density-config($theme);
20+
$typography: mat-get-typography-config($theme);
21+
22+
@if $color != null {
23+
@include mat-mdc-autocomplete-color($color);
24+
}
25+
@if $density != null {
26+
@include mat-mdc-autocomplete-density($density);
27+
}
28+
@if $typography != null {
29+
@include mat-mdc-autocomplete-typography($typography);
30+
}
31+
}

src/material-experimental/mdc-button/_button-theme.scss

Lines changed: 61 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -49,8 +49,8 @@ $mat-button-state-target: '.mdc-button__ripple';
4949
}
5050

5151

52-
@mixin mat-mdc-button-theme($theme) {
53-
@include mat-using-mdc-theme($theme) {
52+
@mixin mat-mdc-button-color($config) {
53+
@include mat-using-mdc-theme($config) {
5454
// Add state interactions for hover, focus, press, active. Colors are changed based on
5555
// the mixin mdc-states-base-color
5656
.mat-mdc-button, .mat-mdc-raised-button, .mat-mdc-unelevated-button, .mat-mdc-outlined-button {
@@ -170,8 +170,26 @@ $mat-button-state-target: '.mdc-button__ripple';
170170
}
171171
}
172172

173-
@mixin mat-mdc-fab-theme($theme) {
174-
@include mat-using-mdc-theme($theme) {
173+
@mixin mat-mdc-button-density($density-scale) {}
174+
175+
@mixin mat-mdc-button-theme($theme) {
176+
$color: mat-get-color-config($theme);
177+
$density: mat-get-density-config($theme);
178+
$typography: mat-get-typography-config($theme);
179+
180+
@if $color != null {
181+
@include mat-mdc-button-color($color);
182+
}
183+
@if $density != null {
184+
@include mat-mdc-button-density($density);
185+
}
186+
@if $typography != null {
187+
@include mat-mdc-button-typography($typography);
188+
}
189+
}
190+
191+
@mixin mat-mdc-fab-color($config) {
192+
@include mat-using-mdc-theme($config) {
175193
.mat-mdc-fab, .mat-mdc-mini-fab {
176194
@include mdc-states(
177195
$query: $mat-theme-styles-query, $ripple-target: $mat-button-state-target);
@@ -225,8 +243,27 @@ $mat-button-state-target: '.mdc-button__ripple';
225243
}
226244
}
227245

228-
@mixin mat-mdc-icon-button-theme($theme) {
229-
@include mat-using-mdc-theme($theme) {
246+
@mixin mat-mdc-fab-density($density-scale) {}
247+
248+
@mixin mat-mdc-fab-theme($theme) {
249+
$color: mat-get-color-config($theme);
250+
$density: mat-get-density-config($theme);
251+
$typography: mat-get-typography-config($theme);
252+
253+
@if $color != null {
254+
@include mat-mdc-fab-color($color);
255+
}
256+
@if $density != null {
257+
@include mat-mdc-fab-density($density);
258+
}
259+
@if $typography != null {
260+
@include mat-mdc-fab-typography($typography);
261+
}
262+
}
263+
264+
265+
@mixin mat-mdc-icon-button-color($config) {
266+
@include mat-using-mdc-theme($config) {
230267
.mat-mdc-icon-button {
231268
@include mdc-states(
232269
$query: $mat-theme-styles-query, $ripple-target: $mat-button-state-target);
@@ -273,3 +310,21 @@ $mat-button-state-target: '.mdc-button__ripple';
273310
@include mdc-icon-button-without-ripple($query: $mat-typography-styles-query);
274311
}
275312
}
313+
314+
@mixin mat-mdc-icon-button-density($density-scale) {}
315+
316+
@mixin mat-mdc-icon-button-theme($theme) {
317+
$color: mat-get-color-config($theme);
318+
$density: mat-get-density-config($theme);
319+
$typography: mat-get-typography-config($theme);
320+
321+
@if $color != null {
322+
@include mat-mdc-icon-button-color($color);
323+
}
324+
@if $density != null {
325+
@include mat-mdc-icon-button-density($density);
326+
}
327+
@if $typography != null {
328+
@include mat-mdc-icon-button-typography($typography);
329+
}
330+
}

src/material-experimental/mdc-card/_card-theme.scss

Lines changed: 22 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -4,14 +4,14 @@
44
@import '@material/typography/mixins.import';
55
@import '../mdc-helpers/mdc-helpers';
66

7-
@mixin mat-mdc-card-theme($theme) {
8-
$foreground: map-get($theme, foreground);
9-
$is-dark-theme: map-get($theme, is-dark);
7+
@mixin mat-mdc-card-color($config) {
8+
$foreground: map-get($config, foreground);
9+
$is-dark-theme: map-get($config, is-dark);
1010

1111
$orig-mdc-card-action-icon-color: $mdc-card-action-icon-color;
1212
$orig-mdc-card-outline-color: $mdc-card-outline-color;
1313

14-
@include mat-using-mdc-theme($theme) {
14+
@include mat-using-mdc-theme($config) {
1515
$mdc-card-action-icon-color:
1616
rgba(mdc-theme-prop-value(on-surface), mdc-theme-text-emphasis(medium)) !global;
1717
$mdc-card-outline-color:
@@ -45,3 +45,21 @@
4545
}
4646
}
4747
}
48+
49+
@mixin mat-mdc-card-density($density-scale) {}
50+
51+
@mixin mat-mdc-card-theme($theme) {
52+
$color: mat-get-color-config($theme);
53+
$density: mat-get-density-config($theme);
54+
$typography: mat-get-typography-config($theme);
55+
56+
@if $color != null {
57+
@include mat-mdc-card-color($color);
58+
}
59+
@if $density != null {
60+
@include mat-mdc-card-density($density);
61+
}
62+
@if $typography != null {
63+
@include mat-mdc-card-typography($typography);
64+
}
65+
}

src/material-experimental/mdc-checkbox/_checkbox-theme.scss

Lines changed: 23 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
@import '@material/theme/functions.import';
66
@import '../mdc-helpers/mdc-helpers';
77

8-
@mixin mat-mdc-checkbox-theme($theme) {
9-
$primary: mat-color(map-get($theme, primary));
10-
$accent: mat-color(map-get($theme, accent));
11-
$warn: mat-color(map-get($theme, warn));
8+
@mixin mat-mdc-checkbox-color($config) {
9+
$primary: mat-color(map-get($config, primary));
10+
$accent: mat-color(map-get($config, accent));
11+
$warn: mat-color(map-get($config, warn));
1212

1313
// Save original values of MDC global variables. We need to save these so we can restore the
1414
// variables to their original values and prevent unintended side effects from using this mixin.
@@ -17,7 +17,7 @@
1717
$orig-mdc-checkbox-border-color: $mdc-checkbox-border-color;
1818
$orig-mdc-checkbox-disabled-color: $mdc-checkbox-disabled-color;
1919

20-
@include mat-using-mdc-theme($theme) {
20+
@include mat-using-mdc-theme($config) {
2121
$mdc-checkbox-mark-color: mdc-theme-prop-value(on-primary) !global;
2222
$mdc-checkbox-baseline-theme-color: primary !global;
2323
$mdc-checkbox-border-color: rgba(mdc-theme-prop-value(on-surface), 0.54) !global;
@@ -76,3 +76,21 @@
7676
@include mdc-form-field-core-styles($query: $mat-typography-styles-query);
7777
}
7878
}
79+
80+
@mixin mat-mdc-checkbox-density($density-scale) {}
81+
82+
@mixin mat-mdc-checkbox-theme($theme) {
83+
$color: mat-get-color-config($theme);
84+
$density: mat-get-density-config($theme);
85+
$typography: mat-get-typography-config($theme);
86+
87+
@if $color != null {
88+
@include mat-mdc-checkbox-color($color);
89+
}
90+
@if $density != null {
91+
@include mat-mdc-checkbox-density($density);
92+
}
93+
@if $typography != null {
94+
@include mat-mdc-checkbox-typography($typography);
95+
}
96+
}

0 commit comments

Comments
 (0)