Skip to content

Commit

Permalink
feat(material-experimental/theming): add M3 icon-button & fab support (
Browse files Browse the repository at this point in the history
…#28157)

* feat(material-experimental/theming): add M3 icon-button support

* feat(material-experimental/theming): add M3 fab support
  • Loading branch information
mmalerba authored Nov 21, 2023
1 parent 4f893dc commit 2963b7a
Show file tree
Hide file tree
Showing 7 changed files with 239 additions and 88 deletions.
6 changes: 6 additions & 0 deletions src/dev-app/theme-m3.scss
Original file line number Diff line number Diff line change
Expand Up @@ -39,8 +39,10 @@ html {
@include mat.card-theme($light-theme);
@include mat.checkbox-theme($light-theme);
@include mat.divider-theme($light-theme);
@include mat.fab-theme($light-theme);
@include mat.form-field-theme($light-theme);
@include mat.grid-list-theme($light-theme);
@include mat.icon-button-theme($light-theme);
@include mat.icon-theme($light-theme);
@include mat.input-theme($light-theme);
@include mat.list-theme($light-theme);
Expand Down Expand Up @@ -74,8 +76,10 @@ html {
@include mat.card-color($dark-theme);
@include mat.checkbox-color($dark-theme);
@include mat.divider-color($dark-theme);
@include mat.fab-color($dark-theme);
@include mat.form-field-color($dark-theme);
@include mat.grid-list-color($dark-theme);
@include mat.icon-button-color($dark-theme);
@include mat.icon-color($dark-theme);
@include mat.input-color($dark-theme);
@include mat.list-color($dark-theme);
Expand Down Expand Up @@ -108,8 +112,10 @@ html {
@include mat.card-density($scale-theme);
@include mat.checkbox-density($scale-theme);
@include mat.divider-density($scale-theme);
@include mat.fab-density($scale-theme);
@include mat.form-field-density($scale-theme);
@include mat.grid-list-density($scale-theme);
@include mat.icon-button-density($scale-theme);
@include mat.icon-density($scale-theme);
@include mat.input-density($scale-theme);
@include mat.list-density($scale-theme);
Expand Down
39 changes: 39 additions & 0 deletions src/material-experimental/theming/_custom-tokens.scss
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,28 @@
);
}

/// Generates custom tokens for the mat-fab.
/// @param {Map} $systems The MDC system tokens
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values
/// @return {Map} A set of custom tokens for the mat-fab
@function fab($systems, $exclude-hardcoded) {
@return (
foreground-color: map.get($systems, md-sys-color, on-primary-container),
state-layer-color: map.get($systems, md-sys-color, primary-container),
ripple-color: mat.private-safe-color-change(
map.get($systems, md-sys-color, on-primary-container),
$alpha: map.get($systems, md-sys-state, pressed-state-layer-opacity)
),
hover-state-layer-opacity: map.get($systems, md-sys-state, hover-state-layer-opacity),
focus-state-layer-opacity: map.get($systems, md-sys-state, focus-state-layer-opacity),
pressed-state-layer-opacity: map.get($systems, md-sys-state, pressed-state-layer-opacity),
disabled-state-container-color: mat.private-safe-color-change(
map.get($systems, md-sys-color, on-surface), $alpha: 0.12),
disabled-state-foreground-color: mat.private-safe-color-change(
map.get($systems, md-sys-color, on-surface), $alpha: 0.38),
);
}

/// Generates custom tokens for the mat-form-field.
/// @param {Map} $systems The MDC system tokens
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values
Expand Down Expand Up @@ -96,6 +118,23 @@
);
}

/// Generates custom tokens for the mat-icon-button.
/// @param {Map} $systems The MDC system tokens
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values
/// @return {Map} A set of custom tokens for the mat-icon-button
@function icon-button($systems, $exclude-hardcoded) {
@return (
state-layer-color: map.get($systems, md-sys-color, on-surface-variant),
ripple-color: mat.private-safe-color-change(
map.get($systems, md-sys-color, on-surface-variant),
$alpha: map.get($systems, md-sys-state, pressed-state-layer-opacity)
),
hover-state-layer-opacity: map.get($systems, md-sys-state, hover-state-layer-opacity),
focus-state-layer-opacity: map.get($systems, md-sys-state, focus-state-layer-opacity),
pressed-state-layer-opacity: map.get($systems, md-sys-state, pressed-state-layer-opacity),
);
}

/// Generates custom tokens for the mat-menu.
/// @param {Map} $systems The MDC system tokens
/// @param {Boolean} $exclude-hardcoded Whether to exclude hardcoded token values
Expand Down
7 changes: 7 additions & 0 deletions src/material-experimental/theming/_m3-density.scss
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,12 @@ $_density-tokens: (
),
(mdc, circular-progress): (),
(mdc, elevated-card): (),
(mdc, extended-fab): (),
(mdc, fab): (),
(mdc, filled-text-field): (),
(mdc, icon-button): (
state-layer-size: (48px, 44px, 40px, 36px, 32px, 28px),
),
(mdc, linear-progress): (),
(mdc, list): (
list-item-one-line-container-height: (48px, 44px, 40px, 36px, 32px, 24px),
Expand All @@ -45,9 +50,11 @@ $_density-tokens: (
// Custom Angular Material tokens
(mat, card): (),
(mat, divider): (),
(mat, fab): (),
(mat, form-fild): (),
(mat, grid-list): (),
(mat, icon): (),
(mat, icon-button): (),
(mat, menu): (),
(mat, optgroup): (),
(mat, option): (),
Expand Down
25 changes: 25 additions & 0 deletions src/material-experimental/theming/_m3-tokens.scss
Original file line number Diff line number Diff line change
Expand Up @@ -187,11 +187,26 @@
mdc-tokens.md-comp-elevated-card-values($systems, $exclude-hardcoded),
$token-slots
),
_namespace-tokens(
(mdc, fab),
mdc-tokens.md-comp-fab-primary-values($systems, $exclude-hardcoded),
$token-slots
),
_namespace-tokens(
(mdc, extended-fab),
mdc-tokens.md-comp-extended-fab-primary-values($systems, $exclude-hardcoded),
$token-slots
),
_namespace-tokens(
(mdc, filled-text-field),
mdc-tokens.md-comp-filled-text-field-values($systems, $exclude-hardcoded),
$token-slots
),
_namespace-tokens(
(mdc, icon-button),
mdc-tokens.md-comp-icon-button-values($systems, $exclude-hardcoded),
$token-slots
),
_namespace-tokens(
(mdc, linear-progress),
mdc-tokens.md-comp-linear-progress-indicator-values($systems, $exclude-hardcoded),
Expand Down Expand Up @@ -260,6 +275,11 @@
custom-tokens.divider($systems, $exclude-hardcoded),
$token-slots
),
_namespace-tokens(
(mat, fab),
custom-tokens.fab($systems, $exclude-hardcoded),
$token-slots
),
_namespace-tokens(
(mat, form-field),
custom-tokens.form-field($systems, $exclude-hardcoded),
Expand All @@ -275,6 +295,11 @@
custom-tokens.icon($systems, $exclude-hardcoded),
$token-slots
),
_namespace-tokens(
(mat, icon-button),
custom-tokens.icon-button($systems, $exclude-hardcoded),
$token-slots
),
_namespace-tokens(
(mat, menu),
custom-tokens.menu($systems, $exclude-hardcoded),
Expand Down
97 changes: 65 additions & 32 deletions src/material/button/_fab-theme.scss
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
@use 'sass:map';
@use '@material/fab/fab' as mdc-fab;
@use '@material/fab/fab-theme' as mdc-fab-theme;
@use '@material/fab/extended-fab-theme' as mdc-extended-fab-theme;

@use '../core/mdc-helpers/mdc-helpers';
@use '../core/style/sass-utils';
@use '../core/theming/theming';
Expand All @@ -13,12 +13,17 @@
@use '../core/typography/typography';

@mixin base($theme) {
// Add default values for tokens not related to color, typography, or density.
@include sass-utils.current-selector-or-root() {
@include mdc-fab-theme.theme(tokens-mdc-fab.get-unthemable-tokens());
@include mdc-extended-fab-theme.theme(
tokens-mdc-extended-fab.get-unthemable-tokens()
);
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme, base));
}
@else {
// Add default values for tokens not related to color, typography, or density.
@include sass-utils.current-selector-or-root() {
@include mdc-fab-theme.theme(tokens-mdc-fab.get-unthemable-tokens());
@include mdc-extended-fab-theme.theme(
tokens-mdc-extended-fab.get-unthemable-tokens()
);
}
}
}

Expand All @@ -38,51 +43,79 @@
}

@mixin color($theme) {
@include sass-utils.current-selector-or-root() {
@include _fab-variant($theme, null);
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme, color));
}
@else {
@include sass-utils.current-selector-or-root() {
@include _fab-variant($theme, null);

.mat-mdc-fab,
.mat-mdc-mini-fab {
&.mat-primary {
@include _fab-variant($theme, primary);
}
.mat-mdc-fab,
.mat-mdc-mini-fab {
&.mat-primary {
@include _fab-variant($theme, primary);
}

&.mat-accent {
@include _fab-variant($theme, accent);
}
&.mat-accent {
@include _fab-variant($theme, accent);
}

&.mat-warn {
@include _fab-variant($theme, warn);
&.mat-warn {
@include _fab-variant($theme, warn);
}
}
}
}
}

@mixin typography($theme) {
@include mdc-helpers.using-mdc-typography($theme) {
@include mdc-fab.without-ripple($query: mdc-helpers.$mdc-typography-styles-query);
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme, typography));
}
@else {
@include mdc-helpers.using-mdc-typography($theme) {
@include mdc-fab.without-ripple($query: mdc-helpers.$mdc-typography-styles-query);
}

$typography-tokens: tokens-mdc-extended-fab.get-typography-tokens($theme);
@include sass-utils.current-selector-or-root() {
@include mdc-extended-fab-theme.theme($typography-tokens);
$typography-tokens: tokens-mdc-extended-fab.get-typography-tokens($theme);
@include sass-utils.current-selector-or-root() {
@include mdc-extended-fab-theme.theme($typography-tokens);
}
}
}

@mixin density($theme) {
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme, density));
}
@else {}
}

@mixin theme($theme) {
@include theming.private-check-duplicate-theme-styles($theme, 'mat-fab') {
@include base($theme);
@if inspection.theme-has($theme, color) {
@include color($theme);
}
@if inspection.theme-has($theme, density) {
@include density($theme);
@if inspection.get-theme-version($theme) == 1 {
@include _theme-from-tokens(inspection.get-theme-tokens($theme));
}
@if inspection.theme-has($theme, typography) {
@include typography($theme);
@else {
@include base($theme);
@if inspection.theme-has($theme, color) {
@include color($theme);
}
@if inspection.theme-has($theme, density) {
@include density($theme);
}
@if inspection.theme-has($theme, typography) {
@include typography($theme);
}
}
}
}

@mixin _theme-from-tokens($tokens) {
@if ($tokens != ()) {
@include mdc-extended-fab-theme.theme(map.get($tokens, tokens-mdc-extended-fab.$prefix));
@include mdc-fab-theme.theme(map.get($tokens, tokens-mdc-fab.$prefix));
@include token-utils.create-token-values(
tokens-mat-fab.$prefix, map.get($tokens, tokens-mat-fab.$prefix));
}
}
Loading

0 comments on commit 2963b7a

Please sign in to comment.