Skip to content

Commit

Permalink
feat(material/core): move Material 3 support into stable (#28913)
Browse files Browse the repository at this point in the history
Moves all of the Material 3 theming APIs into stable since they'll be considered stable APIs in v18.
  • Loading branch information
crisbeto committed Apr 19, 2024
1 parent b5c68e9 commit d679024
Show file tree
Hide file tree
Showing 31 changed files with 534 additions and 532 deletions.
57 changes: 24 additions & 33 deletions guides/material-3.md
Original file line number Diff line number Diff line change
Expand Up @@ -6,21 +6,17 @@
system, Material Design. It is the successor to [Material 2 (M2)](https://m2.material.io/), the
design system which Angular Material has followed.

As of v17.2.0, Angular Material includes experimental support for M3 styling in addition to M2. The
team plans to stabilize support for M3 after a brief period in experimental in order to get feedback
on the design and API.

## How to use Material 3 in your app

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

### Defining your theme

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

```scss
@use '@angular/material-experimental' as matx;
@use '@angular/material' as mat;

$theme: matx.define-theme((
$theme: mat.define-theme((
color: (
theme-type: dark,
primary: matx.$m3-violet-palette,
primary: mat.$violet-palette,
),
typography: (
brand-family: 'Comic Sans',
Expand All @@ -63,20 +59,20 @@ more about these terms):
| `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). |
| `tertiary` | [Optional] Specifies the palette to use for the app's tertiary color palette. |

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

- `$m3-red-palette`
- `$m3-green-palette`
- `$m3-blue-palette`
- `$m3-yellow-palette`
- `$m3-cyan-palette`
- `$m3-magenta-palette`
- `$m3-orange-palette`
- `$m3-chartreuse-palette`
- `$m3-azure-palette`
- `$m3-violet-palette`
- `$m3-rose-palette`
- `$red-palette`
- `$green-palette`
- `$blue-palette`
- `$yellow-palette`
- `$cyan-palette`
- `$magenta-palette`
- `$orange-palette`
- `$chartreuse-palette`
- `$azure-palette`
- `$violet-palette`
- `$rose-palette`

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

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

```scss
@use '@angular/material' as mat;
@use '@angular/material-experimental' as matx;

$theme: matx.define-theme();
$theme: mat.define-theme();

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

```scss
@use '@angular/material' as mat;
@use '@angular/material-experimental' as matx;

$light-theme: matx.define-theme();
$dark-theme: matx.define-theme((
$light-theme: mat.define-theme();
$dark-theme: mat.define-theme((
color: (
theme-type: dark
)
Expand Down Expand Up @@ -273,7 +267,6 @@ provided by Angular Material to access properties of the theme.

```scss
@use '@angular/material' as mat;
@use '@angular/material-experimental' as matx;

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

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

```scss
@use '@angular/material' as mat;
@use '@angular/material-experimental' as matx;

$theme: matx.define-theme();
$theme: mat.define-theme();

html {
@include mat.all-component-themes($theme);
@include matx.color-variants-back-compat($theme);
@include mat.color-variants-backwards-compatibility($theme);
}
```

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

```scss
@use '@angular/material' as mat;
@use '@angular/material-experimental' as matx;

$theme: matx.define-theme();
$theme: mat.define-theme();

@include mat.typography-hierarchy($theme, $back-compat: true);
```
Expand Down
1 change: 1 addition & 0 deletions package.json
Original file line number Diff line number Diff line change
Expand Up @@ -142,6 +142,7 @@
"@material/textfield": "15.0.0-canary.7f224ddd4.0",
"@material/theme": "15.0.0-canary.7f224ddd4.0",
"@material/tooltip": "15.0.0-canary.7f224ddd4.0",
"@material/tokens": "15.0.0-canary.7f224ddd4.0",
"@material/top-app-bar": "15.0.0-canary.7f224ddd4.0",
"@material/touch-target": "15.0.0-canary.7f224ddd4.0",
"@material/typography": "15.0.0-canary.7f224ddd4.0",
Expand Down
1 change: 1 addition & 0 deletions packages.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ MDC_PACKAGES = [
"@material/textfield",
"@material/theme",
"@material/tooltip",
"@material/tokens",
"@material/top-app-bar",
"@material/touch-target",
"@material/typography",
Expand Down
11 changes: 5 additions & 6 deletions src/dev-app/theme-m3.scss
Original file line number Diff line number Diff line change
@@ -1,5 +1,4 @@
@use '@angular/material' as mat;
@use '@angular/material-experimental' as matx;

// Plus imports for other components in your app.

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

// Create a theme with the specified color type and density.
@function create-theme($type: light, $density: 0) {
@return matx.define-theme((
@return mat.define-theme((
color: (
theme-type: $type,
primary: matx.$m3-azure-palette,
tertiary: matx.$m3-blue-palette,
primary: mat.$azure-palette,
tertiary: mat.$blue-palette,
),
density: (
scale: $density
Expand Down Expand Up @@ -78,11 +77,11 @@ $density-scales: (-1, -2, -3, -4, minimum, maximum);

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

&.demo-unicorn-dark-theme {
@include matx.color-variants-back-compat($dark-theme);
@include mat.color-variants-backwards-compatibility($dark-theme);
}
}

Expand Down
7 changes: 3 additions & 4 deletions src/e2e-app/theme.scss
Original file line number Diff line number Diff line change
@@ -1,13 +1,12 @@
@use '@angular/material' as mat;
@use '@angular/material-experimental' as matx;

@include mat.core();

$theme: matx.define-theme((
$theme: mat.define-theme((
color: (
theme-type: light,
primary: matx.$m3-azure-palette,
tertiary: matx.$m3-blue-palette,
primary: mat.$azure-palette,
tertiary: mat.$blue-palette,
),
density: (
scale: 0,
Expand Down
4 changes: 1 addition & 3 deletions src/material-experimental/BUILD.bazel
Original file line number Diff line number Diff line change
Expand Up @@ -19,9 +19,7 @@ ts_library(

sass_library(
name = "theming_scss_lib",
srcs = MATERIAL_EXPERIMENTAL_SCSS_LIBS + [
"//src/material-experimental/theming:theming_scss_lib",
],
srcs = MATERIAL_EXPERIMENTAL_SCSS_LIBS,
)

sass_library(
Expand Down
7 changes: 0 additions & 7 deletions src/material-experimental/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,11 +4,4 @@
@forward './popover-edit/popover-edit-theme' as popover-edit-* show popover-edit-color,
popover-edit-typography, popover-edit-density, popover-edit-theme;

// Token-based theming API
@forward './theming/definition' show define-theme, define-colors, define-typography, define-density;
@forward './theming/m3-palettes' as m3-* show $m3-red-palette, $m3-green-palette, $m3-blue-palette,
$m3-yellow-palette, $m3-cyan-palette, $m3-magenta-palette, $m3-orange-palette,
$m3-chartreuse-palette, $m3-azure-palette, $m3-violet-palette, $m3-rose-palette;
@forward './theming/color-api-back-compat' show color-variants-back-compat;

// Additional public APIs for individual components
9 changes: 0 additions & 9 deletions src/material-experimental/theming/BUILD.bazel

This file was deleted.

111 changes: 0 additions & 111 deletions src/material-experimental/theming/_color-api-back-compat.scss

This file was deleted.

7 changes: 7 additions & 0 deletions src/material/_index.scss
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,13 @@
// New theming APIs
@forward './core/theming/inspection' show get-theme-version, get-theme-type, get-theme-color,
get-theme-typography, get-theme-density, theme-has, theme-remove;
@forward './core/theming/definition' show define-theme, define-colors, define-typography,
define-density;
@forward './core/theming/palettes' show $red-palette, $green-palette, $blue-palette,
$yellow-palette, $cyan-palette, $magenta-palette, $orange-palette,
$chartreuse-palette, $azure-palette, $violet-palette, $rose-palette;
@forward './core/theming/color-api-backwards-compatibility' show
color-variants-backwards-compatibility;

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

0 comments on commit d679024

Please sign in to comment.