Skip to content

Commit 73cea87

Browse files
allan-chencopybara-github
authored andcommitted
feat(button): m3 elevation + icon base theme modules
PiperOrigin-RevId: 397814721
1 parent 7d8ca0a commit 73cea87

File tree

6 files changed

+197
-3
lines changed

6 files changed

+197
-3
lines changed

components/button/lib/_elevated-button.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
@use './elevation';
8+
79
@mixin static-styles() {
8-
// Intentionally blank for future-proofing.
10+
@include elevation.static-styles;
911
}
Lines changed: 102 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,102 @@
1+
/**
2+
* @license
3+
* Copyright 2021 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
@use 'sass:map';
8+
@use 'sass:meta';
9+
@use '@material/elevation/elevation-theme';
10+
@use '@material/ripple/ripple-theme';
11+
@use '@material/theme/state';
12+
@use '@material/theme/theme';
13+
@use '@material/tokens/resolvers';
14+
15+
@use './button-theme';
16+
17+
$_selectors: button-theme.$selectors;
18+
19+
@mixin theme-styles($theme, $resolvers) {
20+
$elevation-resolver: map.get($resolvers, elevation);
21+
@include _elevation(
22+
$elevation-resolver,
23+
$elevation-map: (
24+
default: map.get($theme, container-elevation),
25+
disabled: map.get($theme, disabled-container-elevation),
26+
focus: map.get($theme, focus-container-elevation),
27+
hover: map.get($theme, hover-container-elevation),
28+
pressed: map.get($theme, pressed-container-elevation)
29+
),
30+
$shadow-color: map.get($theme, container-shadow-color)
31+
);
32+
}
33+
34+
@mixin _elevation($elevation-resolver, $elevation-map, $shadow-color) {
35+
@include state.default($_selectors) {
36+
@include elevation-theme.with-resolver(
37+
$elevation-resolver,
38+
$elevation: state.get-default-state($elevation-map),
39+
$shadow-color: $shadow-color
40+
);
41+
}
42+
43+
@include state.focus($_selectors) {
44+
@include elevation-theme.with-resolver(
45+
$elevation-resolver,
46+
$elevation: state.get-focus-state($elevation-map),
47+
$shadow-color: $shadow-color
48+
);
49+
}
50+
51+
@include state.hover($_selectors) {
52+
@include elevation-theme.with-resolver(
53+
$elevation-resolver,
54+
$elevation: state.get-hover-state($elevation-map),
55+
$shadow-color: $shadow-color
56+
);
57+
}
58+
59+
@include state.pressed($_selectors) {
60+
@include elevation-theme.with-resolver(
61+
$elevation-resolver,
62+
$elevation: state.get-pressed-state($elevation-map),
63+
$shadow-color: $shadow-color
64+
);
65+
}
66+
67+
@include state.disabled($_selectors) {
68+
@include elevation-theme.with-resolver(
69+
$elevation-resolver,
70+
$elevation: state.get-disabled-state($elevation-map),
71+
$shadow-color: $shadow-color
72+
);
73+
}
74+
}
75+
76+
@function resolve-theme-elevation-keys($theme, $resolver) {
77+
$elevation-resolver: map.get($resolver, elevation);
78+
$shadow-color: map.get($theme, container-shadow-color);
79+
@if $elevation-resolver == null {
80+
@return $theme;
81+
}
82+
83+
$elevation-keys: (
84+
container-elevation,
85+
hover-container-elevation,
86+
focus-container-elevation,
87+
pressed-container-elevation,
88+
disabled-container-elevation
89+
);
90+
91+
@each $key in $elevation-keys {
92+
$elevation: map.get($theme, $key);
93+
$resolved-value: meta.call(
94+
$resolver,
95+
$elevation: $elevation,
96+
$shadow-color: $shadow-color
97+
);
98+
// Update the key with the resolved value.
99+
$theme: map.set($theme, $key, $resolved-value);
100+
}
101+
@return $theme;
102+
}
Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,16 @@
1+
/**
2+
* @license
3+
* Copyright 2021 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// stylelint-disable selector-class-pattern --
8+
// Selector '.mdc-*' should only be used in this project.
9+
10+
@use '@material/elevation/elevation-theme';
11+
12+
@mixin static-styles() {
13+
.mdc-button {
14+
transition: elevation-theme.transition-value();
15+
}
16+
}

components/button/lib/_filled-button.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
@use './elevation';
8+
79
@mixin static-styles() {
8-
// Intentionally blank for future-proofing.
10+
@include elevation.static-styles;
911
}
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
/**
2+
* @license
3+
* Copyright 2021 Google LLC
4+
* SPDX-License-Identifier: Apache-2.0
5+
*/
6+
7+
// stylelint-disable selector-class-pattern --
8+
// Selector '.mdc-*' should only be used in this project.
9+
10+
@use 'sass:map';
11+
@use '@material/ripple/ripple-theme';
12+
@use '@material/theme/state';
13+
@use '@material/theme/theme';
14+
@use '@material/typography/typography';
15+
@use './button-theme';
16+
17+
$_selectors: button-theme.$selectors;
18+
19+
@mixin theme-styles($theme, $resolver) {
20+
@include _set-icon-color(
21+
(
22+
default: map.get($theme, with-icon-icon-color),
23+
hover: map.get($theme, with-icon-hover-icon-color),
24+
focus: map.get($theme, with-icon-focus-icon-color),
25+
pressed: map.get($theme, with-icon-pressed-icon-color),
26+
disabled: map.get($theme, with-icon-disabled-icon-color),
27+
)
28+
);
29+
30+
@include _set-icon-size(map.get($theme, with-icon-icon-size));
31+
}
32+
33+
@mixin _set-icon-color($colors) {
34+
@include state.default($_selectors) {
35+
@include _icon-color(state.get-default-state($colors));
36+
}
37+
38+
@include state.hover($_selectors) {
39+
@include _icon-color(state.get-hover-state($colors));
40+
}
41+
42+
@include state.focus($_selectors) {
43+
@include _icon-color(state.get-focus-state($colors));
44+
}
45+
46+
@include state.pressed($_selectors) {
47+
@include _icon-color(state.get-pressed-state($colors));
48+
}
49+
50+
@include state.disabled($_selectors) {
51+
@include _icon-color(state.get-disabled-state($colors));
52+
}
53+
}
54+
55+
@mixin _icon-color($color) {
56+
::slotted(*),
57+
.mdc-button__icon {
58+
@include theme.property(color, $color);
59+
}
60+
}
61+
62+
@mixin _set-icon-size($size-px) {
63+
$size-rem: typography.px-to-rem($size-px);
64+
::slotted(*),
65+
.mdc-button__icon {
66+
@include theme.property(font-size, $size-rem);
67+
@include theme.property(width, $size-rem);
68+
@include theme.property(height, $size-rem);
69+
}
70+
}

components/button/lib/_tonal-button.scss

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,8 @@
44
* SPDX-License-Identifier: Apache-2.0
55
*/
66

7+
@use './elevation';
8+
79
@mixin static-styles() {
8-
// Intentionally blank for future-proofing.
10+
@include elevation.static-styles;
911
}

0 commit comments

Comments
 (0)