Skip to content

Commit 956ad5d

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 956ad5d

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

src/material-experimental/mdc-checkbox/_checkbox-theme.scss

Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,10 +1,10 @@
11
@use '@material/checkbox/checkbox-theme' as checkbox-theme;
2-
@use '@material/ripple/ripple-theme' as ripple-theme;
2+
@use '@material/ripple/ripple-theme' as mdc-ripple-theme;
33
@use '@material/theme/theme';
44
@use 'sass:map';
55
@use '../mdc-helpers/mdc-helpers';
66
@use '../../material/core/theming/theming';
7-
@use '../../material/core/ripple/ripple';
7+
@use '../../material/core/ripple/ripple-theme';
88

99
@import '@material/checkbox/mixins.import';
1010
@import '@material/checkbox/variables.import';
@@ -25,9 +25,9 @@
2525
outline-color: rgba(mdc-theme-prop-value(on-surface), 0.54),
2626
outline-hover-color: null,
2727
ripple-color: mdc-theme-prop-value(on-surface),
28-
ripple-opacity: ripple-theme.$dark-ink-opacities,
28+
ripple-opacity: mdc-ripple-theme.$dark-ink-opacities,
2929
ripple-checked-color: $color,
30-
ripple-checked-opacity: ripple-theme.$dark-ink-opacities,
30+
ripple-checked-opacity: mdc-ripple-theme.$dark-ink-opacities,
3131
)
3232
);
3333
}
@@ -37,9 +37,9 @@
3737
@mixin _selected-ripple-colors($theme, $mdcColor) {
3838
.mdc-checkbox--selected ~ {
3939
.mat-mdc-checkbox-ripple {
40-
@include ripple.theme((
40+
@include ripple-theme.theme((
4141
foreground: (
42-
base: mdc-theme-prop-value($mdcColor)
42+
base: mdc-theme-prop-value($mdcColor)
4343
),
4444
));
4545
}
@@ -52,9 +52,9 @@
5252

5353
@mixin color($config-or-theme) {
5454
$config: theming.get-color-config($config-or-theme);
55-
$primary: theming.color(map.get($config, primary));
56-
$accent: theming.color(map.get($config, accent));
57-
$warn: theming.color(map.get($config, warn));
55+
$primary: theming.get-color-from-palette(map.get($config, primary));
56+
$accent: theming.get-color-from-palette(map.get($config, accent));
57+
$warn: theming.get-color-from-palette(map.get($config, warn));
5858

5959
// Save original values of MDC global variables. We need to save these so we can restore the
6060
// variables to their original values and prevent unintended side effects from using this mixin.
@@ -74,7 +74,7 @@
7474
.mat-mdc-checkbox {
7575
@include private-checkbox-styles-with-color(primary);
7676
@include mdc-form-field-core-styles($query: mdc-helpers.$mat-theme-styles-query);
77-
@include ripple.theme((
77+
@include ripple-theme.theme((
7878
foreground: (
7979
base: mdc-theme-prop-value(on-surface)
8080
),

src/material-experimental/mdc-chips/_chips-theme.scss

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,11 +21,11 @@
2121

2222
@mixin color($config-or-theme) {
2323
$config: theming.get-color-config($config-or-theme);
24-
$primary: theming.color(map.get($config, primary));
25-
$accent: theming.color(map.get($config, accent));
26-
$warn: theming.color(map.get($config, warn));
24+
$primary: theming.get-color-from-palette(map.get($config, primary));
25+
$accent: theming.get-color-from-palette(map.get($config, accent));
26+
$warn: theming.get-color-from-palette(map.get($config, warn));
2727
$background: map.get($config, background);
28-
$unselected-background: theming.color($background, unselected-chip);
28+
$unselected-background: theming.get-color-from-palette($background, unselected-chip);
2929

3030
// Save original values of MDC global variables. We need to save these so we can restore the
3131
// variables to their original values and prevent unintended side effects from using this mixin.

src/material-experimental/mdc-color/_all-color.scss

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
@use '../mdc-theming/all-theme';
22
@use '../../material/core/theming/theming';
33

4-
@mixin angular-material-mdc-color($config-or-theme) {
4+
@mixin all-mdc-component-colors($config-or-theme) {
55
// In case a theme object has been passed instead of a configuration for
66
// the color system, extract the color config from the theme object.
77
$config: if(theming.private-is-theme-object($config-or-theme),
@@ -11,7 +11,7 @@
1111
@error 'No color configuration specified.';
1212
}
1313

14-
@include all-theme.angular-material-mdc-theme((
14+
@include all-theme.all-mdc-component-themes((
1515
color: $config,
1616
typography: null,
1717
density: null,

src/material-experimental/mdc-density/_all-density.scss

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@
1111
@error 'No density configuration specified.';
1212
}
1313

14-
@include all-theme.angular-material-mdc-theme((
14+
@include all-theme.all-mdc-component-themes((
1515
color: null,
1616
typography: null,
1717
density: $config,
Lines changed: 48 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,48 @@
1+
@use 'sass:meta';
2+
@use 'sass:map';
3+
@use '../../material/core/theming/theming';
4+
5+
// Mixin that applies the border color for the focus indicators.
6+
@mixin _mat-mdc-strong-focus-indicators-border-color($color) {
7+
.mat-mdc-focus-indicator::before {
8+
border-color: $color;
9+
}
10+
}
11+
12+
@mixin color($config-or-theme) {
13+
$config: theming.get-color-config($config-or-theme);
14+
$border-color: theming.get-color-from-palette(map.get($config, primary));
15+
@include _mat-mdc-strong-focus-indicators-border-color($border-color);
16+
}
17+
18+
/// Mixin that sets the color of the focus indicators.
19+
///
20+
/// @param {color|map} $theme-or-color
21+
/// If theme, focus indicators are set to the primary color of the theme. If
22+
/// color, focus indicators are set to that color.
23+
///
24+
/// @example
25+
/// .demo-dark-theme {
26+
/// @include mat-mdc-strong-focus-indicators-theme($dark-theme-map);
27+
/// }
28+
///
29+
/// @example
30+
/// .demo-red-theme {
31+
/// @include mat-mdc-strong-focus-indicators-theme(#f00);
32+
/// }
33+
/* stylelint-disable-next-line material/theme-mixin-api */
34+
@mixin theme($theme-or-color) {
35+
@if meta.type-of($theme-or-color) != 'map' {
36+
@include _mat-mdc-strong-focus-indicators-border-color($theme-or-color);
37+
}
38+
@else {
39+
$theme: theming.private-legacy-get-theme($theme-or-color);
40+
@include theming.private-check-duplicate-theme-styles($theme,
41+
'mat-mdc-strong-focus-indicators') {
42+
$color: theming.get-color-config($theme);
43+
@if $color != null {
44+
@include strong-focus-indicators-color($color);
45+
}
46+
}
47+
}
48+
}

src/material-experimental/mdc-helpers/_focus-indicators.import.scss

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,8 @@
11
@forward '../../material/core/focus-indicators/focus-indicators.import';
2-
@forward 'focus-indicators' hide strong-focus-indicators, strong-focus-indicators-color,
3-
strong-focus-indicators-theme;
2+
@forward 'focus-indicators' hide strong-focus-indicators;
3+
@forward 'focus-indicators-theme' hide color, theme;
44
@forward 'focus-indicators' as mat-mdc-* hide mat-mdc-strong-focus-indicators-border-color;
5+
@forward 'focus-indicators-theme' as mat-mdc-strong-focus-indicators-*;
56

67
@import '../../material/core/theming/theming';
78
@import '../../material/core/style/layout-common';

0 commit comments

Comments
 (0)