Skip to content

Commit f018e82

Browse files
committed
feat: support global density setting
1 parent 35b0f31 commit f018e82

File tree

4 files changed

+19
-20
lines changed

4 files changed

+19
-20
lines changed

README.md

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -156,7 +156,15 @@ $mat-css-default-light-theme: map-merge(
156156
);
157157
158158
@include mat-css-main.init-material-css-vars();
159+
```
160+
161+
### Set global density
162+
To set the global density level, just pass the `$density` variable to the `init-material-css-vars()` mixin like the following:
163+
164+
```scss
165+
@use 'angular-material-css-vars/main' as mat-css-main;
159166
167+
@include mat-css-main.init-material-css-vars($density: -2);
160168
```
161169
162170
## IE 11

projects/material-css-vars/src/lib/_main.scss

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -12,7 +12,7 @@
1212
@include internal-helper.root($default-theme);
1313
}
1414

15-
@mixin init-mat-theme($dark-theme-selector, $typography-config: mat.define-typography-config()) {
15+
@mixin init-mat-theme($dark-theme-selector, $typography-config: mat.define-typography-config(), $density) {
1616
@include mat.core();
1717

1818
$primary: mat.define-palette(variables.$palette-primary);
@@ -26,7 +26,7 @@
2626
warn: $warn,
2727
),
2828
typography: $typography-config,
29-
density: 0,
29+
density: $density,
3030
));
3131

3232
$dark-theme: mat.define-dark-theme((
@@ -36,7 +36,7 @@
3636
warn: $warn,
3737
),
3838
typography: $typography-config,
39-
density: 0,
39+
density: $density,
4040
));
4141

4242
// set global variable so passed-in content can use the theme
@@ -70,9 +70,10 @@
7070
$dark-theme-selector: variables.$dark-theme-selector,
7171
$default-theme-text: variables.$text,
7272
$typography-config: mat.define-typography-config(),
73+
$density: 0,
7374
) {
7475
@include init-css-vars($default-theme, $default-theme-text);
75-
@include init-mat-theme($dark-theme-selector, $typography-config) using ($mat-css-theme) {
76+
@include init-mat-theme($dark-theme-selector, $typography-config, $density) using ($mat-css-theme) {
7677
@content($mat-css-theme);
7778
}
7879
}

src/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,7 @@
1515
<link href="https://fonts.googleapis.com/icon?family=Material+Icons"
1616
rel="stylesheet">
1717
</head>
18-
<body>
18+
<body class="mat-app-background">
1919
<app-root></app-root>
2020
</body>
2121

src/styles.scss

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,34 +1,24 @@
11
@use '/projects/material-css-vars/src/lib/main' as mat-css-main;
22
@use '/projects/material-css-vars/src/lib/public-util' as mat-css-utilities;
33
@use '@angular/material' as mat;
4-
@use '@angular/material/theming' as mat-theming;
54

65
@import './app/app.theme';
76

87
$custom-typography: mat.define-typography-config(
98
$font-family: 'Roboto, monospace',
10-
$body-1: mat-theming.mat-typography-level(16px, 24px, 500),
11-
$headline-1: mat-theming.mat-typography-level(16px, 24px, 500)
9+
$body-1: mat.define-typography-level(16px, 24px, 500),
10+
$headline-1: mat.define-typography-level(16px, 24px, 500)
1211
);
1312

1413
@include mat-css-main.init-material-css-vars($typography-config: $custom-typography) using($mat-css-theme) {
1514
@include app-theme($mat-css-theme);
1615
};
1716

18-
@include mat-css-utilities.mat-css-set-palette-defaults(mat-theming.$mat-light-blue, 'primary');
19-
@include mat-css-utilities.mat-css-set-palette-defaults(mat-theming.$mat-pink, 'accent');
20-
@include mat-css-utilities.mat-css-set-palette-defaults(mat-theming.$mat-red, 'warn');
21-
17+
@include mat-css-utilities.mat-css-set-palette-defaults(mat.$light-blue-palette, 'primary');
18+
@include mat-css-utilities.mat-css-set-palette-defaults(mat.$pink-palette, 'accent');
19+
@include mat-css-utilities.mat-css-set-palette-defaults(mat.$red-palette, 'warn');
2220

2321
body {
2422
padding: 0;
2523
margin: 0;
26-
27-
&.isDarkTheme {
28-
background: rgb(39, 39, 39);
29-
}
30-
}
31-
32-
* {
33-
box-sizing: border-box;
3424
}

0 commit comments

Comments
 (0)