Skip to content

Commit d679024

Browse files
authored
feat(material/core): move Material 3 support into stable (#28913)
Moves all of the Material 3 theming APIs into stable since they'll be considered stable APIs in v18.
1 parent b5c68e9 commit d679024

31 files changed

+534
-532
lines changed

guides/material-3.md

Lines changed: 24 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -6,21 +6,17 @@
66
system, Material Design. It is the successor to [Material 2 (M2)](https://m2.material.io/), the
77
design system which Angular Material has followed.
88

9-
As of v17.2.0, Angular Material includes experimental support for M3 styling in addition to M2. The
10-
team plans to stabilize support for M3 after a brief period in experimental in order to get feedback
11-
on the design and API.
12-
139
## How to use Material 3 in your app
1410

1511
M3 is implemented in Angular Material as an alternate Sass theme for the same set of Angular
1612
Material components already used by many apps. To use M3 with Angular Material, create your theme
17-
using the `define-theme` function from `@angular/material-experimental`, as opposed to the
13+
using the `define-theme` function from `@angular/material`, as opposed to the
1814
`define-light-theme` or `define-dark-theme` from `@angular/material` that are used to create M2
1915
themes.
2016

2117
### Defining your theme
2218

23-
The simplest usage of the API, `$theme: matx.define-theme()` defines a theme with default values.
19+
The simplest usage of the API, `$theme: mat.define-theme()` defines a theme with default values.
2420
However, like its M2 counterparts, `define-theme` allows you to configure the appearance of your
2521
Angular Material app along three theming dimensions: color, typography, and density, by passing a
2622
theme configuration object. The configuration object may have the following properties.
@@ -34,12 +30,12 @@ theme configuration object. The configuration object may have the following prop
3430
<!-- TODO(mmalerba): Upgrade to embedded example -->
3531

3632
```scss
37-
@use '@angular/material-experimental' as matx;
33+
@use '@angular/material' as mat;
3834

39-
$theme: matx.define-theme((
35+
$theme: mat.define-theme((
4036
color: (
4137
theme-type: dark,
42-
primary: matx.$m3-violet-palette,
38+
primary: mat.$violet-palette,
4339
),
4440
typography: (
4541
brand-family: 'Comic Sans',
@@ -63,20 +59,20 @@ more about these terms):
6359
| `primary` | [Optional] Specifies the palette to use for the app's primary color palette. (Note: the secondary, neutral, and neutral-variant palettes described in the M3 spec will be automatically chosen based on your primary palette, to ensure a harmonious color combination). |
6460
| `tertiary` | [Optional] Specifies the palette to use for the app's tertiary color palette. |
6561

66-
There are a number of color palettes available in `@angular/material-experimental` that can be
62+
There are a number of color palettes available in `@angular/material` that can be
6763
used with the `primary` and `tertiary` options:
6864

69-
- `$m3-red-palette`
70-
- `$m3-green-palette`
71-
- `$m3-blue-palette`
72-
- `$m3-yellow-palette`
73-
- `$m3-cyan-palette`
74-
- `$m3-magenta-palette`
75-
- `$m3-orange-palette`
76-
- `$m3-chartreuse-palette`
77-
- `$m3-azure-palette`
78-
- `$m3-violet-palette`
79-
- `$m3-rose-palette`
65+
- `$red-palette`
66+
- `$green-palette`
67+
- `$blue-palette`
68+
- `$yellow-palette`
69+
- `$cyan-palette`
70+
- `$magenta-palette`
71+
- `$orange-palette`
72+
- `$chartreuse-palette`
73+
- `$azure-palette`
74+
- `$violet-palette`
75+
- `$rose-palette`
8076

8177
Alternatively, a theme can be generated with a custom color with the following schematic:
8278

@@ -161,9 +157,8 @@ can instead apply color variants by passing the `$color-variant` option to a com
161157

162158
```scss
163159
@use '@angular/material' as mat;
164-
@use '@angular/material-experimental' as matx;
165160

166-
$theme: matx.define-theme();
161+
$theme: mat.define-theme();
167162

168163
.tertiary-checkbox {
169164
@include mat.checkbox-color($theme, $color-variant: tertiary);
@@ -231,10 +226,9 @@ overrides on the highest-level selector where they apply.
231226

232227
```scss
233228
@use '@angular/material' as mat;
234-
@use '@angular/material-experimental' as matx;
235229

236-
$light-theme: matx.define-theme();
237-
$dark-theme: matx.define-theme((
230+
$light-theme: mat.define-theme();
231+
$dark-theme: mat.define-theme((
238232
color: (
239233
theme-type: dark
240234
)
@@ -273,7 +267,6 @@ provided by Angular Material to access properties of the theme.
273267

274268
```scss
275269
@use '@angular/material' as mat;
276-
@use '@angular/material-experimental' as matx;
277270

278271
@mixin my-comp-theme($theme) {
279272
.my-comp {
@@ -410,20 +403,19 @@ We recommend _not_ relying on the `color="primary"`, `color="accent"`, or `color
410403
that are offered by a number of Angular Material components for M2 themes. However, if you want to
411404
quickly update to M3 and are willing to accept the extra CSS generated for these variants, you can
412405
enable backwards compatibility styles that restore the behavior of this API. Call the
413-
`color-variants-back-compat` mixin from `@angular/material-experimental` with the M3 theme you want
406+
`color-variants-backwards-compatibility` mixin from `@angular/material` with the M3 theme you want
414407
to generate color variant styles for.
415408

416409
<!-- TODO(mmalerba): Upgrade to embedded example -->
417410

418411
```scss
419412
@use '@angular/material' as mat;
420-
@use '@angular/material-experimental' as matx;
421413

422-
$theme: matx.define-theme();
414+
$theme: mat.define-theme();
423415

424416
html {
425417
@include mat.all-component-themes($theme);
426-
@include matx.color-variants-back-compat($theme);
418+
@include mat.color-variants-backwards-compatibility($theme);
427419
}
428420
```
429421

@@ -441,9 +433,8 @@ styles, pass an additional argument `$back-compat: true` to the mixin.
441433

442434
```scss
443435
@use '@angular/material' as mat;
444-
@use '@angular/material-experimental' as matx;
445436

446-
$theme: matx.define-theme();
437+
$theme: mat.define-theme();
447438

448439
@include mat.typography-hierarchy($theme, $back-compat: true);
449440
```

package.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,7 @@
142142
"@material/textfield": "15.0.0-canary.7f224ddd4.0",
143143
"@material/theme": "15.0.0-canary.7f224ddd4.0",
144144
"@material/tooltip": "15.0.0-canary.7f224ddd4.0",
145+
"@material/tokens": "15.0.0-canary.7f224ddd4.0",
145146
"@material/top-app-bar": "15.0.0-canary.7f224ddd4.0",
146147
"@material/touch-target": "15.0.0-canary.7f224ddd4.0",
147148
"@material/typography": "15.0.0-canary.7f224ddd4.0",

packages.bzl

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -75,6 +75,7 @@ MDC_PACKAGES = [
7575
"@material/textfield",
7676
"@material/theme",
7777
"@material/tooltip",
78+
"@material/tokens",
7879
"@material/top-app-bar",
7980
"@material/touch-target",
8081
"@material/typography",

src/dev-app/theme-m3.scss

Lines changed: 5 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
11
@use '@angular/material' as mat;
2-
@use '@angular/material-experimental' as matx;
32

43
// Plus imports for other components in your app.
54

@@ -8,11 +7,11 @@ mat.$theme-legacy-inspection-api-compatibility: false;
87

98
// Create a theme with the specified color type and density.
109
@function create-theme($type: light, $density: 0) {
11-
@return matx.define-theme((
10+
@return mat.define-theme((
1211
color: (
1312
theme-type: $type,
14-
primary: matx.$m3-azure-palette,
15-
tertiary: matx.$m3-blue-palette,
13+
primary: mat.$azure-palette,
14+
tertiary: mat.$blue-palette,
1615
),
1716
density: (
1817
scale: $density
@@ -78,11 +77,11 @@ $density-scales: (-1, -2, -3, -4, minimum, maximum);
7877

7978
// Enable back-compat CSS for color="..." API & typography hierarchy.
8079
.demo-color-api-back-compat {
81-
@include matx.color-variants-back-compat($light-theme);
80+
@include mat.color-variants-backwards-compatibility($light-theme);
8281
@include mat.typography-hierarchy($light-theme, $back-compat: true);
8382

8483
&.demo-unicorn-dark-theme {
85-
@include matx.color-variants-back-compat($dark-theme);
84+
@include mat.color-variants-backwards-compatibility($dark-theme);
8685
}
8786
}
8887

src/e2e-app/theme.scss

Lines changed: 3 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,12 @@
11
@use '@angular/material' as mat;
2-
@use '@angular/material-experimental' as matx;
32

43
@include mat.core();
54

6-
$theme: matx.define-theme((
5+
$theme: mat.define-theme((
76
color: (
87
theme-type: light,
9-
primary: matx.$m3-azure-palette,
10-
tertiary: matx.$m3-blue-palette,
8+
primary: mat.$azure-palette,
9+
tertiary: mat.$blue-palette,
1110
),
1211
density: (
1312
scale: 0,

src/material-experimental/BUILD.bazel

Lines changed: 1 addition & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,9 +19,7 @@ ts_library(
1919

2020
sass_library(
2121
name = "theming_scss_lib",
22-
srcs = MATERIAL_EXPERIMENTAL_SCSS_LIBS + [
23-
"//src/material-experimental/theming:theming_scss_lib",
24-
],
22+
srcs = MATERIAL_EXPERIMENTAL_SCSS_LIBS,
2523
)
2624

2725
sass_library(

src/material-experimental/_index.scss

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -4,11 +4,4 @@
44
@forward './popover-edit/popover-edit-theme' as popover-edit-* show popover-edit-color,
55
popover-edit-typography, popover-edit-density, popover-edit-theme;
66

7-
// Token-based theming API
8-
@forward './theming/definition' show define-theme, define-colors, define-typography, define-density;
9-
@forward './theming/m3-palettes' as m3-* show $m3-red-palette, $m3-green-palette, $m3-blue-palette,
10-
$m3-yellow-palette, $m3-cyan-palette, $m3-magenta-palette, $m3-orange-palette,
11-
$m3-chartreuse-palette, $m3-azure-palette, $m3-violet-palette, $m3-rose-palette;
12-
@forward './theming/color-api-back-compat' show color-variants-back-compat;
13-
147
// Additional public APIs for individual components

src/material-experimental/theming/BUILD.bazel

Lines changed: 0 additions & 9 deletions
This file was deleted.

src/material-experimental/theming/_color-api-back-compat.scss

Lines changed: 0 additions & 111 deletions
This file was deleted.

src/material/_index.scss

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,13 @@
44
// New theming APIs
55
@forward './core/theming/inspection' show get-theme-version, get-theme-type, get-theme-color,
66
get-theme-typography, get-theme-density, theme-has, theme-remove;
7+
@forward './core/theming/definition' show define-theme, define-colors, define-typography,
8+
define-density;
9+
@forward './core/theming/palettes' show $red-palette, $green-palette, $blue-palette,
10+
$yellow-palette, $cyan-palette, $magenta-palette, $orange-palette,
11+
$chartreuse-palette, $azure-palette, $violet-palette, $rose-palette;
12+
@forward './core/theming/color-api-backwards-compatibility' show
13+
color-variants-backwards-compatibility;
714

815
@forward './core/theming/theming' show $theme-ignore-duplication-warnings,
916
$theme-legacy-inspection-api-compatibility;

0 commit comments

Comments
 (0)