Skip to content

Commit 36ddb8b

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 4aa48a1 commit 36ddb8b

File tree

109 files changed

+1120
-790
lines changed

Some content is hidden

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

109 files changed

+1120
-790
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: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
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, 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();

src/dev-app/theme.scss

Lines changed: 35 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
1-
@use '../material/core/color/all-color' as color-all-color;
1+
@use '../material/core/color/all-color';
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;
3+
@use '../material/core/focus-indicators/focus-indicators';
4+
@use '../material/core/focus-indicators/focus-indicators-theme';
5+
@use '../material/core/theming/all-theme';
56
@use '../material-experimental/column-resize/column-resize';
67
@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';
8+
@use '../material-experimental/mdc-helpers/focus-indicators-theme' as mdc-focus-indicators-theme;
9+
@use '../material-experimental/mdc-helpers/focus-indicators' as mdc-focus-indicators;
10+
@use '../material-experimental/mdc-color/all-color' as mdc-all-color;
11+
@use '../material-experimental/mdc-theming/all-theme' as mdc-all-theme;
1012
@use '../material-experimental/mdc-typography/all-typography';
1113
@use '../material-experimental/mdc-density/all-density';
1214
@use '../material-experimental/mdc-slider/slider-theme';
@@ -19,18 +21,18 @@
1921
// Plus imports for other components in your app.
2022

2123
// 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,
24+
$candy-app-primary: theming.define-palette(palette.$indigo-palette);
25+
$candy-app-accent: theming.define-palette(palette.$pink-palette, A200, A100, A400);
26+
$candy-app-theme: theming.define-light-theme((
27+
// Define the default colors for our app.
28+
color: (
29+
primary: $candy-app-primary,
30+
accent: $candy-app-accent
31+
),
32+
// Define the default typography for our app.
33+
typography: all-typography.define-typography-config(),
34+
// Define the default density level for our app.
35+
density: 0,
3436
));
3537

3638
// Include the common styles for Angular Material. We include this here so that you only
@@ -39,21 +41,21 @@ $candy-app-theme: theming.light-theme((
3941
@include core.core($candy-app-theme);
4042

4143
// 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);
44+
@include all-theme.all-component-themes($candy-app-theme);
45+
@include mdc-all-theme.all-mdc-component-themes($candy-app-theme);
4446
@include column-resize.theme($candy-app-theme);
4547
@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`.
48+
// We add this in manually for now, because it isn't included in `all-mdc-component-themes`.
4749
@include slider-theme.theme($candy-app-theme);
4850

4951
.demo-strong-focus {
5052
// Include base styles for strong focus indicators.
51-
@include focus-indicators-focus-indicators.strong-focus-indicators();
5253
@include focus-indicators.strong-focus-indicators();
54+
@include mdc-focus-indicators.strong-focus-indicators();
5355

5456
// 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);
57+
@include focus-indicators-theme.theme($candy-app-theme);
58+
@include mdc-focus-indicators-theme.theme($candy-app-theme);
5759
}
5860

5961
// Include the alternative theme styles inside of a block with a CSS class. You can make this
@@ -62,23 +64,23 @@ $candy-app-theme: theming.light-theme((
6264
// default theme.
6365
.demo-unicorn-dark-theme {
6466
// 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);
67+
$dark-primary: theming.define-palette(palette.$blue-grey-palette);
68+
$dark-accent: theming.define-palette(palette.$amber-palette, A200, A100, A400);
69+
$dark-warn: theming.define-palette(palette.$deep-orange-palette);
70+
$dark-colors: theming.define-dark-theme($dark-primary, $dark-accent, $dark-warn);
6971

7072
// 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);
73+
@include all-color.all-component-colors($dark-colors);
74+
@include mdc-all-color.all-mdc-component-colors($dark-colors);
7375
@include column-resize.color($dark-colors);
7476
@include popover-edit.color($dark-colors);
75-
// We add this in manually for now, because it isn't included in `angular-material-mdc-theme`.
77+
// We add this in manually for now, because it isn't included in `all-mdc-component-themes`.
7678
@include slider-theme.color($dark-colors);
7779

7880
// Include the dark theme colors for focus indicators.
7981
.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);
82+
@include focus-indicators-theme.color($dark-colors);
83+
@include mdc-focus-indicators-theme.color($dark-colors);
8284
}
8385
}
8486

src/e2e-app/theme.scss

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -11,13 +11,13 @@
1111
// have to load a single css file for Angular Material in your app.
1212
// **Be sure that you only ever include this mixin once!**
1313
@include core.core();
14-
@include all-typography.angular-material-mdc-typography();
14+
@include all-typography.all-mdc-component-typographies();
1515

1616
// 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);
17+
$candy-app-primary: theming.define-palette(palette.$indigo-palette);
18+
$candy-app-accent: theming.define-palette(palette.$pink-palette, A200, A100, A400);
19+
$candy-app-theme: theming.define-light-theme($candy-app-primary, $candy-app-accent);
2020

2121
// 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);
22+
@include theming-all-theme.all-component-themes($candy-app-theme);
23+
@include 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
@@ -1,4 +1,4 @@
1-
@use '../../material/core/ripple/ripple';
1+
@use '../../material/core/ripple/ripple-theme';
22
@use '../mdc-helpers/mdc-helpers';
33
@use '../../material/core/theming/theming';
44
@import '@material/button/mixins.import';
@@ -36,7 +36,7 @@ $mat-fab-state-target: '.mdc-fab__ripple';
3636
// which is what the ripple mixin uses. This creates a new theme that sets the color to the
3737
// foreground base to appropriately color the ink.
3838
@mixin _mat-button-ripple-ink-color($mdcColor) {
39-
@include ripple.theme((
39+
@include ripple-theme.theme((
4040
foreground: (
4141
base: mdc-theme-prop-value($mdcColor)
4242
),

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

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

0 commit comments

Comments
 (0)