Skip to content

Commit 40ceda2

Browse files
authored
feat(material/core): expose new @use-based Sass API (#22173)
Reworks the public Sass API to take advantage of `@use` in order to allow for a single entry point into `@angular/material` or `@angular/cdk`. Some mixins and variables were renamed in order be a better reflection of what they do. Before: ``` @import '~@angular/material/theming'; @include mat-core(); $candy-app-primary: mat-palette($mat-indigo); $candy-app-accent: mat-palette($mat-pink, A200, A100, A400); $candy-app-warn: mat-palette($mat-red); $candy-app-theme: mat-light-theme(( color: ( primary: $candy-app-primary, accent: $candy-app-accent, warn: $candy-app-warn, ) )); @include angular-material-theme($candy-app-theme); ``` After: ``` @use '~@angular/material' as mat; @include mat.core(); $candy-app-primary: mat.define-palette(mat.$indigo-palette); $candy-app-accent: mat.define-palette(mat.$pink-palette, A200, A100, A400); $candy-app-warn: mat.define-palette(mat.$red-palette); $candy-app-theme: mat.define-light-theme(( color: ( primary: $candy-app-primary, accent: $candy-app-accent, warn: $candy-app-warn, ) )); @include mat.all-component-themes($candy-app-theme); ```
1 parent 263c90c commit 40ceda2

File tree

121 files changed

+1200
-845
lines changed

Some content is hidden

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

121 files changed

+1200
-845
lines changed
File renamed without changes.

src/cdk/BUILD.bazel

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
load("//src/cdk:config.bzl", "CDK_ENTRYPOINTS", "CDK_ENTRYPOINTS_WITH_STYLES", "CDK_SCSS_LIBS", "CDK_TARGETS")
2-
load("//tools:defaults.bzl", "ng_package", "ts_library")
2+
load("//tools:defaults.bzl", "ng_package", "sass_library", "ts_library")
33

44
package(default_visibility = ["//visibility:public"])
55

@@ -49,11 +49,17 @@ rerootedStyleTargets = ["%s_rerooted" % file for [
4949
_,
5050
] in rerootedStyles]
5151

52+
# Makes the public Sass API bundle available in the release output as `angular/cdk`.
53+
sass_library(
54+
name = "sass_index",
55+
srcs = ["_index.scss"],
56+
)
57+
5258
# Creates the @angular/cdk package published to npm.
5359
ng_package(
5460
name = "npm_package",
5561
srcs = ["package.json"],
56-
data = rerootedStyleTargets + CDK_SCSS_LIBS,
62+
data = [":sass_index"] + rerootedStyleTargets + CDK_SCSS_LIBS,
5763
entry_point = ":public-api.ts",
5864
nested_packages = [
5965
"//src/cdk/schematics:npm_package",

src/cdk/_index.scss

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
@forward './overlay/overlay' show overlay;
2+
@forward './a11y/a11y' show a11y-visually-hidden, high-contrast;
3+
@forward './text-field/text-field' show text-field-autosize, text-field-autofill,
4+
text-field-autofill-color;

src/cdk/a11y/_a11y.scss

Lines changed: 6 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
@mixin a11y {
1+
@mixin a11y-visually-hidden {
22
.cdk-visually-hidden {
33
border: 0;
44
clip: rect(0 0 0 0);
@@ -18,6 +18,11 @@
1818
}
1919
}
2020

21+
// @deprecated Use `a11y-visually-hidden`.
22+
@mixin a11y {
23+
@include a11y-visually-hidden;
24+
}
25+
2126
/// Emits the mixin's content nested under `$selector-context` if `$selector-context`
2227
/// is non-empty.
2328
/// @param selector-context The selector under which to nest the mixin's content.

src/cdk/a11y/a11y-prebuilt.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,3 @@
11
@use './a11y';
22

3-
@include a11y.a11y();
3+
@include a11y.a11y-visually-hidden();
Lines changed: 2 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,2 @@
1-
@forward 'text-field' hide $autofill-color-frame-count, autofill-color, text-field;
2-
@forward 'text-field' as cdk-* hide $cdk-autofill-color-frame-count, cdk-autofill-color,
3-
cdk-textarea-autosize-measuring-base;
4-
@forward 'text-field' as cdk-text-field-* hide cdk-text-field-text-field,
5-
cdk-text-field-textarea-autosize-measuring-base;
1+
@forward 'text-field' as cdk-* show cdk-text-field-autofill, cdk-text-field-autofill-color,
2+
cdk-text-field-autosize, cdk-text-field;

src/cdk/text-field/_text-field.scss

Lines changed: 29 additions & 20 deletions
Original file line numberDiff line numberDiff line change
@@ -1,22 +1,5 @@
1-
// Core styles that enable monitoring autofill state of text fields.
2-
@mixin text-field {
3-
// Keyframes that apply no styles, but allow us to monitor when an text field becomes autofilled
4-
// by watching for the animation events that are fired when they start. Note: the /*!*/ comment is
5-
// needed to prevent LibSass from stripping the keyframes out.
6-
// Based on: https://medium.com/@brunn/detecting-autofilled-fields-in-javascript-aed598d25da7
7-
@keyframes cdk-text-field-autofill-start {/*!*/}
8-
@keyframes cdk-text-field-autofill-end {/*!*/}
9-
10-
.cdk-text-field-autofill-monitored:-webkit-autofill {
11-
// Since Chrome 80 we need a 1ms delay, or the animationstart event won't fire.
12-
animation: cdk-text-field-autofill-start 0s 1ms;
13-
}
14-
15-
.cdk-text-field-autofill-monitored:not(:-webkit-autofill) {
16-
// Since Chrome 80 we need a 1ms delay, or the animationstart event won't fire.
17-
animation: cdk-text-field-autofill-end 0s 1ms;
18-
}
19-
1+
// Structural styles for the autosize text fields.
2+
@mixin text-field-autosize() {
203
// Remove the resize handle on autosizing textareas, because whatever height
214
// the user resized to will be overwritten once they start typing again.
225
textarea.cdk-textarea-autosize {
@@ -44,6 +27,26 @@
4427
}
4528
}
4629

30+
// Core styles that enable monitoring autofill state of text fields.
31+
@mixin text-field-autofill() {
32+
// Keyframes that apply no styles, but allow us to monitor when an text field becomes autofilled
33+
// by watching for the animation events that are fired when they start. Note: the /*!*/ comment is
34+
// needed to prevent LibSass from stripping the keyframes out.
35+
// Based on: https://medium.com/@brunn/detecting-autofilled-fields-in-javascript-aed598d25da7
36+
@keyframes cdk-text-field-autofill-start {/*!*/}
37+
@keyframes cdk-text-field-autofill-end {/*!*/}
38+
39+
.cdk-text-field-autofill-monitored:-webkit-autofill {
40+
// Since Chrome 80 we need a 1ms delay, or the animationstart event won't fire.
41+
animation: cdk-text-field-autofill-start 0s 1ms;
42+
}
43+
44+
.cdk-text-field-autofill-monitored:not(:-webkit-autofill) {
45+
// Since Chrome 80 we need a 1ms delay, or the animationstart event won't fire.
46+
animation: cdk-text-field-autofill-end 0s 1ms;
47+
}
48+
}
49+
4750
@mixin _cdk-textarea-autosize-measuring-base {
4851
// Having 2px top and bottom padding seems to fix a bug where Chrome gets an incorrect
4952
// measurement. We just have to account for it later and subtract it off the final result.
@@ -57,7 +60,7 @@ $autofill-color-frame-count: 0;
5760
// Mixin used to apply custom background and foreground colors to an autofilled text field.
5861
// Based on: https://stackoverflow.com/questions/2781549/
5962
// removing-input-background-colour-for-chrome-autocomplete#answer-37432260
60-
@mixin autofill-color($background, $foreground:'') {
63+
@mixin text-field-autofill-color($background, $foreground:'') {
6164
@keyframes cdk-text-field-autofill-color-#{$autofill-color-frame-count} {
6265
to {
6366
background: $background;
@@ -79,3 +82,9 @@ $autofill-color-frame-count: 0;
7982
$autofill-color-frame-count:
8083
$autofill-color-frame-count + 1 !global;
8184
}
85+
86+
// @deprecated Use `autosize` and `autofill` instead.
87+
@mixin text-field {
88+
@include text-field-autosize();
89+
@include text-field-autofill();
90+
}
Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,4 @@
11
@use 'text-field';
22

3-
@include text-field.text-field();
3+
@include text-field.text-field-autosize();
4+
@include text-field.text-field-autofill();

src/dev-app/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -107,6 +107,7 @@ sass_binary(
107107
"external/npm/node_modules",
108108
],
109109
deps = [
110+
"//src/material:theming_bundle",
110111
"//src/material-experimental/column-resize:column_resize_scss_lib",
111112
"//src/material-experimental/mdc-color:all_color",
112113
"//src/material-experimental/mdc-density:all_density",

src/dev-app/input/input-demo.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -33,7 +33,7 @@
3333
}
3434

3535
.demo-custom-autofill-style {
36-
@include text-field.autofill-color(transparent, red);
36+
@include text-field.text-field-autofill-color(transparent, red);
3737
}
3838

3939
.demo-rows {

0 commit comments

Comments
 (0)