-
Notifications
You must be signed in to change notification settings - Fork 6.8k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(material/schematics): Add custom M3 theme schematic (#28766)
* feat(material/schematics): Add custom M3 theme schematic * fix(material/schematics): Add generated file comment and color source comment to output theme file * fix(material/schematics): Create README and update docs theme example * fix(material/schematics): Move more of the m3-schematic docs into the README and link to it from the m3 and schematics guide
- Loading branch information
Showing
14 changed files
with
1,020 additions
and
7 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
108 changes: 108 additions & 0 deletions
108
src/material/schematics/ng-generate/m3-theme/BUILD.bazel
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,108 @@ | ||
load("@build_bazel_rules_nodejs//:index.bzl", "copy_to_bin") | ||
load("//tools:defaults.bzl", "esbuild", "jasmine_node_test", "pkg_npm", "spec_bundle", "ts_library") | ||
|
||
package(default_visibility = ["//visibility:public"]) | ||
|
||
STATIC_ASSETS = [ | ||
"schema.json", | ||
] | ||
|
||
ts_library( | ||
name = "m3_theme_lib", | ||
srcs = glob( | ||
["**/*.ts"], | ||
exclude = ["**/*.spec.ts"] + ["rules/components/test-setup-helper.ts"], | ||
), | ||
deps = [ | ||
"//src/cdk/schematics", | ||
"@npm//@angular-devkit/schematics", | ||
"@npm//@material/material-color-utilities", | ||
"@npm//@types/node", | ||
"@npm//sass", | ||
"@npm//typescript", | ||
], | ||
) | ||
|
||
esbuild( | ||
name = "m3_theme_bundle", | ||
entry_point = ":index.ts", | ||
external = [ | ||
"@angular/cdk/schematics", | ||
"@angular/material-experimental/", | ||
"@angular-devkit/schematics", | ||
"@angular-devkit/core", | ||
"typescript", | ||
], | ||
format = "cjs", | ||
output = "index_bundled.js", | ||
platform = "node", | ||
target = "es2015", | ||
deps = [ | ||
":m3_theme_lib", | ||
"//src/material:sass_lib", | ||
"//src/material-experimental:sass_lib", | ||
], | ||
) | ||
|
||
pkg_npm( | ||
name = "npm_package", | ||
srcs = STATIC_ASSETS, | ||
deps = [":m3_theme_bundle"], | ||
) | ||
|
||
######################################## | ||
# Testing configuration # | ||
######################################## | ||
|
||
ts_library( | ||
name = "unit_tests_lib", | ||
testonly = True, | ||
srcs = glob(["**/*.spec.ts"] + ["rules/components/test-setup-helper.ts"]), | ||
devmode_module = "commonjs", | ||
deps = [ | ||
":m3_theme_lib", | ||
"//src/cdk/schematics/testing", | ||
"//tools/sass:sass_lib", | ||
"@npm//@angular-devkit/schematics", | ||
"@npm//@bazel/runfiles", | ||
"@npm//@material/material-color-utilities", | ||
"@npm//@types/jasmine", | ||
"@npm//@types/node", | ||
"@npm//sass", | ||
], | ||
) | ||
|
||
spec_bundle( | ||
name = "unit_tests_bundle", | ||
# Exclude the `node` devkit entry-point to avoid bundling native modules like | ||
# `chokidar` and `fsevents`. These rely on native bindings and break with ESBuild. | ||
external = ["@angular-devkit/core/node"], | ||
platform = "node", | ||
target = "es2020", | ||
deps = [":unit_tests_lib"], | ||
) | ||
|
||
copy_to_bin( | ||
name = "unit_tests_assets", | ||
testonly = True, | ||
srcs = STATIC_ASSETS, | ||
) | ||
|
||
jasmine_node_test( | ||
name = "unit_tests", | ||
data = [ | ||
":m3_theme_bundle", | ||
":unit_tests_assets", | ||
"//src/material/schematics:collection_assets", | ||
"//src/material/schematics:ng_generate_assets", | ||
], | ||
shard_count = 10, | ||
deps = [ | ||
":unit_tests_bundle", | ||
# Runtime dependencies needed by the test and actual migration sources. These need | ||
# to be specified explicitly here because they are not captured by the bundling. | ||
"@npm//@schematics/angular", | ||
"//src/material:sass_lib", | ||
"//src/material-experimental:sass_lib", | ||
], | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,52 @@ | ||
# Material 3 Custom Theme schematic | ||
|
||
```shell | ||
ng generate @angular/material:m3-theme | ||
``` | ||
|
||
This schematic allows users to create new Material 3 theme configurations based | ||
on custom colors by using [Material Color Utilities](https://github.com/material-foundation/material-color-utilities). | ||
|
||
The generated [color palettes](https://m3.material.io/styles/color/roles) are | ||
optimized to have enough contrast to be more accessible. See [Science of Color Design](https://material.io/blog/science-of-color-design) for more information about Material's color design. | ||
|
||
For more customization, custom palette colors can be also be provided for the | ||
secondary, tertiary, and neutral colors. It is recommended to choose colors that | ||
are contrastful, Material has more detailed guidance for [accessible design](https://m3.material.io/foundations/accessible-design/patterns). | ||
|
||
The output of the schematic will create a file named `m3-theme.scss` at the | ||
specified directory or the project root with the generated themes. The exported | ||
themes (`$light-theme` and/or `$dark-theme`) can be provided to component theme | ||
mixins. | ||
|
||
```scss | ||
@use '@angular/material' as mat; | ||
@use './path/to/my-theme'; | ||
|
||
@include mat.core(); | ||
|
||
// Apply the light theme by default | ||
@include mat.core-theme(my-theme.$light-theme); | ||
@include mat.button-theme(my-theme.$light-theme); | ||
``` | ||
|
||
## Options | ||
|
||
### Required | ||
|
||
* `primaryColor` - Color to use for app's primary color palette (Note: the other | ||
palettes described in the Material 3 spec will be automatically chosen based on | ||
your primary palette unless specified, to ensure a harmonious color combination). | ||
|
||
### Optional | ||
|
||
* `secondaryColor` - Color to use for app's secondary color palette. Defaults to | ||
secondary color generated from Material based on the primary. | ||
* `tertiaryColor` - Color to use for app's tertiary color palette. Defaults to | ||
tertiary color generated from Material based on the primary. | ||
* `neutralColor` - Color to use for app's neutral color palette. Defaults to | ||
neutral color generated from Material based on the primary. | ||
* `directory` - Relative path to a directory within the project that the | ||
generated theme file should be created in. Defaults to the project root. | ||
* `themeTypes` - List of theme types (light and dark) to generate themes for. | ||
Defaults to both light and dark. |
Oops, something went wrong.