Skip to content

Commit 38b392a

Browse files
committed
feat(material/core): expose new @use-based Sass API
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 397710d commit 38b392a

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 {

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,7 @@
4141
}
4242

4343
.demo-custom-autofill-style {
44-
@include text-field.autofill-color(transparent, red);
44+
@include text-field.text-field-autofill-color(transparent, red);
4545
}
4646

4747
.demo-rows {

src/dev-app/theme.scss

Lines changed: 40 additions & 47 deletions
Original file line numberDiff line numberDiff line change
@@ -1,59 +1,52 @@
1-
@use '../material/core/color/all-color' as color-all-color;
1+
@use '../material' as mat;
22
@use '../material/core/density/private/all-density' as private-all-density;
3-
@use '../material/core/focus-indicators/focus-indicators' as focus-indicators-focus-indicators;
4-
@use '../material/core/theming/all-theme' as theming-all-theme;
53
@use '../material-experimental/column-resize/column-resize';
6-
@use '../material-experimental/mdc-helpers/mdc-helpers';
7-
@use '../material-experimental/mdc-helpers/focus-indicators';
8-
@use '../material-experimental/mdc-color/all-color';
9-
@use '../material-experimental/mdc-theming/all-theme';
10-
@use '../material-experimental/mdc-typography/all-typography';
11-
@use '../material-experimental/mdc-density/all-density';
12-
@use '../material-experimental/mdc-slider/slider-theme';
4+
@use '../material-experimental/mdc-helpers/focus-indicators-theme' as mdc-focus-indicators-theme;
5+
@use '../material-experimental/mdc-helpers/focus-indicators' as mdc-focus-indicators;
6+
@use '../material-experimental/mdc-color/all-color' as mdc-all-color;
7+
@use '../material-experimental/mdc-theming/all-theme' as mdc-all-theme;
8+
@use '../material-experimental/mdc-density/all-density' as mdc-all-density;
9+
@use '../material-experimental/mdc-slider/slider-theme' as mdc-slider-theme;
1310
@use '../material-experimental/popover-edit/popover-edit';
14-
@use '../material-experimental/mdc-table/table-theme';
15-
@use '../material/core/core';
16-
@use '../material/core/theming/palette';
17-
@use '../material/core/theming/theming';
1811

1912
// Plus imports for other components in your app.
2013

2114
// Define the default (light) theme.
22-
$candy-app-primary: theming.palette(palette.$indigo);
23-
$candy-app-accent: theming.palette(palette.$pink, A200, A100, A400);
24-
$candy-app-theme: theming.light-theme((
25-
// Define the default colors for our app.
26-
color: (
27-
primary: $candy-app-primary,
28-
accent: $candy-app-accent
29-
),
30-
// Define the default typography for our app.
31-
typography: all-typography.config(),
32-
// Define the default density level for our app.
33-
density: 0,
15+
$candy-app-primary: mat.define-palette(mat.$indigo-palette);
16+
$candy-app-accent: mat.define-palette(mat.$pink-palette, A200, A100, A400);
17+
$candy-app-theme: mat.define-light-theme((
18+
// Define the default colors for our app.
19+
color: (
20+
primary: $candy-app-primary,
21+
accent: $candy-app-accent
22+
),
23+
// Define the default typography for our app.
24+
typography: mat.define-typography-config(),
25+
// Define the default density level for our app.
26+
density: 0,
3427
));
3528

3629
// Include the common styles for Angular Material. We include this here so that you only
3730
// have to load a single css file for Angular Material in your app.
3831
// **Be sure that you only ever include this mixin once!**
39-
@include core.core($candy-app-theme);
32+
@include mat.core($candy-app-theme);
4033

4134
// Include the default theme styles.
42-
@include theming-all-theme.angular-material-theme($candy-app-theme);
43-
@include all-theme.angular-material-mdc-theme($candy-app-theme);
35+
@include mat.all-component-themes($candy-app-theme);
36+
@include mdc-all-theme.all-mdc-component-themes($candy-app-theme);
4437
@include column-resize.theme($candy-app-theme);
4538
@include popover-edit.theme($candy-app-theme);
46-
// We add this in manually for now, because it isn't included in `angular-material-mdc-theme`.
47-
@include slider-theme.theme($candy-app-theme);
39+
// We add this in manually for now, because it isn't included in `all-mdc-component-themes`.
40+
@include mdc-slider-theme.theme($candy-app-theme);
4841

4942
.demo-strong-focus {
5043
// Include base styles for strong focus indicators.
51-
@include focus-indicators-focus-indicators.strong-focus-indicators();
52-
@include focus-indicators.strong-focus-indicators();
44+
@include mat.strong-focus-indicators();
45+
@include mdc-focus-indicators.strong-focus-indicators();
5346

5447
// Include the default theme for focus indicators.
55-
@include focus-indicators-focus-indicators.strong-focus-indicators-theme($candy-app-theme);
56-
@include focus-indicators.strong-focus-indicators-theme($candy-app-theme);
48+
@include mat.strong-focus-indicators-theme($candy-app-theme);
49+
@include mdc-focus-indicators-theme.theme($candy-app-theme);
5750
}
5851

5952
// Include the alternative theme styles inside of a block with a CSS class. You can make this
@@ -62,23 +55,23 @@ $candy-app-theme: theming.light-theme((
6255
// default theme.
6356
.demo-unicorn-dark-theme {
6457
// Create the color palettes used in our dark theme.
65-
$dark-primary: theming.palette(palette.$blue-grey);
66-
$dark-accent: theming.palette(palette.$amber, A200, A100, A400);
67-
$dark-warn: theming.palette(palette.$deep-orange);
68-
$dark-colors: theming.dark-theme($dark-primary, $dark-accent, $dark-warn);
58+
$dark-primary: mat.define-palette(mat.$blue-grey-palette);
59+
$dark-accent: mat.define-palette(mat.$amber-palette, A200, A100, A400);
60+
$dark-warn: mat.define-palette(mat.$deep-orange-palette);
61+
$dark-colors: mat.define-dark-theme($dark-primary, $dark-accent, $dark-warn);
6962

7063
// Include the dark theme color styles.
71-
@include color-all-color.angular-material-color($dark-colors);
72-
@include all-color.angular-material-mdc-color($dark-colors);
64+
@include mat.all-component-colors($dark-colors);
65+
@include mdc-all-color.all-mdc-component-colors($dark-colors);
7366
@include column-resize.color($dark-colors);
7467
@include popover-edit.color($dark-colors);
75-
// We add this in manually for now, because it isn't included in `angular-material-mdc-theme`.
76-
@include slider-theme.color($dark-colors);
68+
// We add this in manually for now, because it isn't included in `all-mdc-component-themes`.
69+
@include mdc-slider-theme.color($dark-colors);
7770

7871
// Include the dark theme colors for focus indicators.
7972
.demo-strong-focus {
80-
@include focus-indicators-focus-indicators.strong-focus-indicators-color($dark-colors);
81-
@include focus-indicators.strong-focus-indicators-color($dark-colors);
73+
@include mat.strong-focus-indicators-color($dark-colors);
74+
@include mdc-focus-indicators-theme.color($dark-colors);
8275
}
8376
}
8477

@@ -88,7 +81,7 @@ $candy-app-theme: theming.light-theme((
8881
$density-scales: (-1, -2, minimum, maximum);
8982
@each $density in $density-scales {
9083
.demo-density-#{$density} {
91-
@include private-all-density.angular-material-density($density);
92-
@include all-density.angular-material-mdc-density($density);
84+
@include private-all-density.all-component-densities($density);
85+
@include mdc-all-density.all-mdc-component-densities($density);
9386
}
9487
}

src/e2e-app/BUILD.bazel

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,7 @@ sass_binary(
7979
"external/npm/node_modules",
8080
],
8181
deps = [
82+
"//src/material:theming_bundle",
8283
"//src/material-experimental/mdc-theming:all_themes",
8384
"//src/material-experimental/mdc-typography:all_typography",
8485
"//src/material/core:theming_scss_lib",

src/e2e-app/theme.scss

Lines changed: 10 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,23 +1,20 @@
1-
@use '../material/core/theming/all-theme' as theming-all-theme;
2-
@use '../material-experimental/mdc-theming/all-theme';
3-
@use '../material-experimental/mdc-typography/all-typography';
4-
@use '../material/core/core';
5-
@use '../material/core/theming/palette';
6-
@use '../material/core/theming/theming';
1+
@use '../material' as mat;
2+
@use '../material-experimental/mdc-theming/all-theme' as mdc-all-theme;
3+
@use '../material-experimental/mdc-typography/all-typography' as mdc-all-typography;
74

85
// Plus imports for other components in your app.
96

107
// Include the common styles for Angular Material. We include this here so that you only
118
// have to load a single css file for Angular Material in your app.
129
// **Be sure that you only ever include this mixin once!**
13-
@include core.core();
14-
@include all-typography.angular-material-mdc-typography();
10+
@include mat.core();
11+
@include mdc-all-typography.all-mdc-component-typographies();
1512

1613
// Define the default theme (same as the example above).
17-
$candy-app-primary: theming.palette(palette.$indigo);
18-
$candy-app-accent: theming.palette(palette.$pink, A200, A100, A400);
19-
$candy-app-theme: theming.light-theme($candy-app-primary, $candy-app-accent);
14+
$candy-app-primary: mat.define-palette(mat.$indigo-palette);
15+
$candy-app-accent: mat.define-palette(mat.$pink-palette, A200, A100, A400);
16+
$candy-app-theme: mat.define-light-theme($candy-app-primary, $candy-app-accent);
2017

2118
// Include the default theme styles.
22-
@include theming-all-theme.angular-material-theme($candy-app-theme);
23-
@include all-theme.angular-material-mdc-theme($candy-app-theme);
19+
@include mat.all-component-themes($candy-app-theme);
20+
@include mdc-all-theme.all-mdc-component-themes($candy-app-theme);

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@
99
$primary: map.get($config, primary);
1010
$foreground: map.get($config, foreground);
1111

12-
$non-resizable-hover-divider: theming.color($foreground, divider);
13-
$resizable-hover-divider: theming.color($primary, 200);
14-
$resizable-active-divider: theming.color($primary, 500);
12+
$non-resizable-hover-divider: theming.get-color-from-palette($foreground, divider);
13+
$resizable-hover-divider: theming.get-color-from-palette($primary, 200);
14+
$resizable-active-divider: theming.get-color-from-palette($primary, 500);
1515

1616
// Required for resizing to work properly.
1717
.mat-column-resize-table.cdk-column-resize-with-resized-column {

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
@use '@material/theme/theme-color' as mdc-theme-color;
88
@use '@material/theme/theme' as mdc-theme;
99
@use '@material/elevation/elevation-theme' as mdc-elevation-theme;
10-
@use '../../material/core/ripple/ripple';
10+
@use '../../material/core/ripple/ripple-theme';
1111
@use '../mdc-helpers/mdc-helpers';
1212
@use '../../material/core/theming/theming';
1313

@@ -39,7 +39,7 @@ $mat-fab-state-target: '.mdc-fab__ripple';
3939
// which is what the ripple mixin uses. This creates a new theme that sets the color to the
4040
// foreground base to appropriately color the ink.
4141
@mixin _mat-button-ripple-ink-color($mdcColor) {
42-
@include ripple.theme((
42+
@include ripple-theme.theme((
4343
foreground: (
4444
base: mdc-theme-color.prop-value($mdcColor)
4545
),

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,7 @@
2525
// Card subtitles are an Angular Material construct (not MDC), so we explicitly set their
2626
// color to secondary text here.
2727
.mat-mdc-card-subtitle {
28-
color: theming.color($foreground, secondary-text);
28+
color: theming.get-color-from-palette($foreground, secondary-text);
2929
}
3030
}
3131

0 commit comments

Comments
 (0)