Skip to content

Commit b04dea0

Browse files
authored
chore: format code with prettier (#141)
1 parent c8be16a commit b04dea0

40 files changed

+1446
-1279
lines changed

.eslintrc.json

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,11 @@
11
{
22
"root": true,
3-
"ignorePatterns": [
4-
"projects/**/*"
5-
],
3+
"ignorePatterns": ["projects/**/*"],
64
"overrides": [
75
{
8-
"files": [
9-
"*.ts"
10-
],
6+
"files": ["*.ts"],
117
"parserOptions": {
12-
"project": [
13-
"tsconfig.json"
14-
],
8+
"project": ["tsconfig.json"],
159
"createDefaultProgram": true
1610
},
1711
"extends": [
@@ -38,12 +32,8 @@
3832
}
3933
},
4034
{
41-
"files": [
42-
"*.html"
43-
],
44-
"extends": [
45-
"plugin:@angular-eslint/template/recommended"
46-
],
35+
"files": ["*.html"],
36+
"extends": ["plugin:@angular-eslint/template/recommended"],
4737
"rules": {}
4838
}
4939
]

.github/workflows/verify-build.yml

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ name: Verify build
33
on:
44
workflow_dispatch:
55
pull_request_target:
6-
types: [ opened, synchronize, reopened ]
6+
types: [opened, synchronize, reopened]
77

88
jobs:
99
build:
@@ -44,3 +44,15 @@ jobs:
4444

4545
- name: test
4646
run: npm run test -- --watch=false --browsers=ChromeHeadless
47+
48+
prettier:
49+
runs-on: ubuntu-latest
50+
steps:
51+
- name: Checkout
52+
uses: actions/checkout@v3
53+
54+
- name: install
55+
run: npm ci
56+
57+
- name: prettier
58+
run: npm run prettier-check

README.md

Lines changed: 66 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -5,61 +5,70 @@ You want to style your angular material dynamically with all the colors in the r
55
[Check out the Demo!](https://johannesjo.github.io/angular-material-css-vars/)
66

77
## Setup
8+
89
1. Install:
9-
```bash
10-
npm i angular-material-css-vars -S
11-
```
10+
```bash
11+
npm i angular-material-css-vars -S
12+
```
1213
2. If @angular/material is already configured remove `@include mat.core()` from your main stylesheet file if present.
1314
3. Add this to your main stylesheet instead:
14-
```scss
15-
@use 'angular-material-css-vars' as mat-css-vars;
16-
17-
@include mat-css-vars.init-material-css-vars();
18-
```
15+
16+
```scss
17+
@use "angular-material-css-vars" as mat-css-vars;
18+
19+
@include mat-css-vars.init-material-css-vars();
20+
```
21+
1922
4. Add to your main module:
23+
2024
```typescript
21-
import {MaterialCssVarsModule} from 'angular-material-css-vars';
25+
import { MaterialCssVarsModule } from "angular-material-css-vars";
2226

2327
@NgModule({
2428
imports: [
2529
MaterialCssVarsModule.forRoot({
2630
// all optional
2731
isAutoContrast: true,
28-
primary: '#3f51b5',
32+
primary: "#3f51b5",
2933
// ...
3034
}),
3135
],
3236
})
33-
export class AppModule {
34-
}
37+
export class AppModule {}
3538
```
39+
3640
5. If you want to adjust the theme at runtime, you can use `MaterialCssVarsService`:
37-
```typescript
38-
import {MaterialCssVarsService} from 'angular-material-css-vars';
39-
40-
export class SomeComponentOrService {
41-
constructor(public materialCssVarsService: MaterialCssVarsService) {
42-
const hex = '#3f51b5';
43-
this.materialCssVarsService.setDarkTheme(true);
44-
this.materialCssVarsService.setPrimaryColor(hex);
45-
this.materialCssVarsService.setAccentColor('#333');
46-
}
47-
}
48-
```
41+
42+
```typescript
43+
import { MaterialCssVarsService } from "angular-material-css-vars";
44+
45+
export class SomeComponentOrService {
46+
constructor(public materialCssVarsService: MaterialCssVarsService) {
47+
const hex = "#3f51b5";
48+
this.materialCssVarsService.setDarkTheme(true);
49+
this.materialCssVarsService.setPrimaryColor(hex);
50+
this.materialCssVarsService.setAccentColor("#333");
51+
}
52+
}
53+
```
54+
4955
## Additional Features
50-
* Auto or manually set contrast color via
51-
* `setAutoContrastEnabled(bool)`
52-
* `setContrastColorThreshold(hueVal: HueValue)`
53-
* Helper to set all variables
54-
* `setVariable(cssVarName: MaterialCssVariables, value: string)`
55-
* You can use the `MaterialCssVariables` enum [from here](https://github.com/johannesjo/angular-material-css-vars/blob/master/projects/material-css-vars/src/lib/model.ts) to make sure you get the variable name right.
56-
* Rudimentary dark theme support via body class
57-
* `setDarkTheme(isDark: boolean)`
56+
57+
- Auto or manually set contrast color via
58+
- `setAutoContrastEnabled(bool)`
59+
- `setContrastColorThreshold(hueVal: HueValue)`
60+
- Helper to set all variables
61+
- `setVariable(cssVarName: MaterialCssVariables, value: string)`
62+
- You can use the `MaterialCssVariables` enum [from here](https://github.com/johannesjo/angular-material-css-vars/blob/master/projects/material-css-vars/src/lib/model.ts) to make sure you get the variable name right.
63+
- Rudimentary dark theme support via body class
64+
- `setDarkTheme(isDark: boolean)`
5865

5966
## Utility
67+
6068
There are also several [utility functions and mixins](https://github.com/johannesjo/angular-material-css-vars/blob/master/projects/material-css-vars/src/lib/_public-util.scss).
69+
6170
```scss
62-
@use 'angular-material-css-vars' as mat-css-vars;
71+
@use "angular-material-css-vars" as mat-css-vars;
6372

6473
.with-color {
6574
border-color: mat-css-vars.mat-css-color-primary(300);
@@ -77,7 +86,9 @@ There are also several [utility functions and mixins](https://github.com/johanne
7786
There are also [some additional hacks](additional-hacks.md) (e.g. adding a color to the elevation shadow) available in case you need them.
7887

7988
## Initialization Options
89+
8090
You can provide different options before initialization to change the body class used for the dark theme and to provide different default styles:
91+
8192
```scss
8293
...
8394
@use 'angular-material-css-vars' as mat-css-vars with (
@@ -91,20 +102,24 @@ You can provide different options before initialization to change the body class
91102
```
92103

93104
### Set default (fallback palettes)
105+
94106
There are two ways to set the default fallback theme. One is using the `mat-css-palette-defaults` mixin.
107+
95108
```scss
96-
@use 'angular-material-css-vars' as mat-css-vars;
97-
@use '@angular/material' as mat;
109+
@use "angular-material-css-vars" as mat-css-vars;
110+
@use "@angular/material" as mat;
98111

99112
@include mat-css-vars.init-material-css-vars();
100113

101-
@include mat-css-vars.mat-css-set-palette-defaults(mat.$light-blue-palette, 'primary');
102-
@include mat-css-vars.mat-css-set-palette-defaults(mat.$pink-palette, 'accent');
103-
@include mat-css-vars.mat-css-set-palette-defaults(mat.$red-palette, 'warn');
114+
@include mat-css-vars.mat-css-set-palette-defaults(mat.$light-blue-palette, "primary");
115+
@include mat-css-vars.mat-css-set-palette-defaults(mat.$pink-palette, "accent");
116+
@include mat-css-vars.mat-css-set-palette-defaults(mat.$red-palette, "warn");
104117
```
118+
105119
The other is to include your own variables for [$default-light-theme](https://github.com/johannesjo/angular-material-css-vars/blob/master/projects/material-css-vars/src/lib/_variables.scss).
120+
106121
```scss
107-
@use 'angular-material-css-vars' as mat-css-vars with (
122+
@use "angular-material-css-vars" as mat-css-vars with (
108123
$default-light-theme: (
109124
--palette-primary-50: mat-css-vars.hex-to-rgb(#e1f5fe),
110125
--palette-primary-100: mat-css-vars.hex-to-rgb(#b3e5fc),
@@ -120,58 +135,64 @@ The other is to include your own variables for [$default-light-theme](https://gi
120135
```
121136

122137
### Set global density
138+
123139
To set the global density level, just pass the `$density` variable to the `init-material-css-vars()` mixin like the following:
124140

125141
```scss
126-
@use 'angular-material-css-vars' as mat-css-vars;
142+
@use "angular-material-css-vars" as mat-css-vars;
127143

128144
@include mat-css-vars.init-material-css-vars($density: -2);
129145
```
130146

131147
## App Theme Mixins
148+
132149
The `init-material-css-vars` mixin allows content to be passed into it. This allows you to create app themes that can take advantage of the dynamic theme created inside this mixin. It may be possible to do all theming using the utility mixins outlined above, but in other cases, you may need access to the theme palette, including foreground and background palettes.
133150

134151
See the Material guide on [Theming your custom component](https://material.angular.io/guide/theming-your-components) for more information.
135152

136153
## Font config
154+
137155
If needed the typography can be adjusted as well. You can introduce your own CSS variables, if you wish.
156+
138157
```scss
139-
@use 'angular-material-css-vars' as mat-css-vars;
140-
@use '@angular/material' as mat;
158+
@use "angular-material-css-vars" as mat-css-vars;
159+
@use "@angular/material" as mat;
141160

142161
// example
143162
$custom-typography: mat.define-typography-config(
144163
// optionally, you introduce your own CSS variables: `$font-family: var(--my-custom-font-family)`
145-
$font-family: 'Roboto, monospace',
164+
$font-family: "Roboto, monospace",
146165
$headline: mat.define-typography-level(32px, 48px, 700),
147166
$body-1: mat.define-typography-level(16px, 24px, 500)
148167
);
149168

150169
@include mat-css-vars.init-material-css-vars($typography-config: $custom-typography) using($mat-css-theme) {
151170
@include app-theme($mat-css-theme);
152-
};
171+
}
153172

154173
@mixin app-theme($theme) {
155174
// Your app theme
156175
}
157176
```
158177

159178
## Legacy components support
179+
160180
Angular Material v15 introduces MDC based components, which is basically a re-write for a lot of the available components. `angular-material-css-vars` v5+ only supports MDC components.
161181

162182
In case you are still using the legacy components, you can use the package [angular-material-css-vars-legacy](https://github.com/json-derulo/angular-material-css-vars-legacy).
163183

164184
## Angular compatibility table
165185

166186
| Angular | angular-material-css-vars |
167-
|---------|---------------------------|
187+
| ------- | ------------------------- |
168188
| 16 | 5.x |
169189
| 15 | 4.x |
170190
| 13/14 | 3.x |
171191
| 12 | 2.x |
172192
| 11 | 1.x |
173193

174194
## Credit...
195+
175196
...goes to @zbirizdo [project](https://github.com/zbirizdo/material-css-vars) on which parts of this are based which is in turn supposedly based on [this gist](https://gist.github.com/shprink/c7f333e3ad51830f14a6383f3ab35439).
176197

177198
...and to @pedrojrivera without whom there would be no support for @angular/material v12.

additional-hacks.md

Lines changed: 6 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,13 @@
11
## Custom elevation shadow color
2+
23
In case you also want to add a color to your shadows, you can include the following mixin directly before you execute `@include initMaterialCssVars();`. Thanks goes to @picc09 for finding this out.
34

45
```scss
56
$mat-css-palette-foreground: map-merge(
67
// if you don't want to enter ALL the properties
78
$mat-css-palette-foreground,
89
(
9-
elevation: var(--your-elevation-color-variable)
10-
// ...
10+
elevation: var(--your-elevation-color-variable),
1111
)
1212
);
1313
@@ -28,9 +28,10 @@ $mat-css-palette-foreground: map-merge(
2828
$color-ambient: rgba($color, $opacity * 0.12);
2929
}
3030
31-
box-shadow: #{map-get(_get-umbra-map($color-umbra, $opacity), $zValue)},
32-
#{map-get(_get-penumbra-map($color-penumbra, $opacity), $zValue)},
33-
#{map-get(_get-ambient-map($color-ambient, $opacity), $zValue)};
31+
box-shadow:
32+
#{map-get(_get-umbra-map($color-umbra, $opacity), $zValue)},
33+
#{map-get(_get-penumbra-map($color-penumbra, $opacity), $zValue)},
34+
#{map-get(_get-ambient-map($color-ambient, $opacity), $zValue)};
3435
}
3536
3637
// finally initialize

angular.json

Lines changed: 5 additions & 17 deletions
Original file line numberDiff line numberDiff line change
@@ -22,13 +22,8 @@
2222
"main": "src/main.ts",
2323
"polyfills": "src/polyfills.ts",
2424
"tsConfig": "tsconfig.app.json",
25-
"assets": [
26-
"src/favicon.ico",
27-
"src/assets"
28-
],
29-
"styles": [
30-
"src/styles.scss"
31-
],
25+
"assets": ["src/favicon.ico", "src/assets"],
26+
"styles": ["src/styles.scss"],
3227
"scripts": [],
3328
"vendorChunk": true,
3429
"extractLicenses": false,
@@ -98,10 +93,7 @@
9893
"lint": {
9994
"builder": "@angular-eslint/builder:lint",
10095
"options": {
101-
"lintFilePatterns": [
102-
"src/**/*.ts",
103-
"src/**/*.html"
104-
]
96+
"lintFilePatterns": ["src/**/*.ts", "src/**/*.html"]
10597
}
10698
}
10799
}
@@ -125,9 +117,7 @@
125117
"main": "projects/material-css-vars/src/test.ts",
126118
"tsConfig": "projects/material-css-vars/tsconfig.spec.json",
127119
"karmaConfig": "projects/material-css-vars/karma.conf.js",
128-
"styles": [
129-
"projects/material-css-vars/src/test/global-styles.scss"
130-
]
120+
"styles": ["projects/material-css-vars/src/test/global-styles.scss"]
131121
}
132122
},
133123
"lint": {
@@ -147,8 +137,6 @@
147137
"cache": {
148138
"enabled": false
149139
},
150-
"schematicCollections": [
151-
"@angular-eslint/schematics"
152-
]
140+
"schematicCollections": ["@angular-eslint/schematics"]
153141
}
154142
}

package-lock.json

Lines changed: 16 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)