Skip to content

Commit 21c5556

Browse files
Elliott Marquezcopybara-github
authored andcommitted
feat(fab): add theming config
fixes #1545 PiperOrigin-RevId: 324663554
1 parent 21750ff commit 21c5556

File tree

2 files changed

+154
-23
lines changed

2 files changed

+154
-23
lines changed

packages/fab/src/_fab-theme.scss

Lines changed: 129 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -15,7 +15,135 @@ See the License for the specific language governing permissions and
1515
limitations under the License.
1616
*/
1717

18-
$light-theme: ();
18+
@use 'sass:map';
19+
@use 'sass:string';
20+
@use 'sass:selector';
21+
@use '@material/elevation/elevation-theme';
22+
@use '@material/theme/theme';
23+
@use '@material/theme/theme-color';
24+
@use '@material/theme/custom-properties';
25+
@use '@material/theme/shadow-dom';
26+
@use '@material/fab/variables' as fab-variables;
27+
@use '@material/mwc-ripple/src/ripple-theme';
28+
29+
// TODO(b/153370936): replace with theme.resolve()
30+
$light-theme: (
31+
ink-color: theme-color.prop-value(on-secondary),
32+
ink-color-hover: theme-color.prop-value(on-secondary),
33+
ink-color-focus: theme-color.prop-value(on-secondary),
34+
ink-color-press: theme-color.prop-value(on-secondary),
35+
container-color: theme-color.prop-value(secondary),
36+
container-color-hover: theme-color.prop-value(secondary),
37+
container-color-focus: theme-color.prop-value(secondary),
38+
container-color-press: theme-color.prop-value(secondary),
39+
icon-size: 24px,
40+
extended-icon-padding: fab-variables.$extended-icon-padding,
41+
extended-label-padding: fab-variables.$extended-label-padding,
42+
ripple: (
43+
state: currentcolor,
44+
opacity-hover: 0.04,
45+
opacity-focus: 0.12,
46+
opacity-press: 0.1,
47+
),
48+
elevation-shadow-color: black,
49+
icon-font-family: 'Material Icons',
50+
);
1951

2052
@mixin theme($theme: $light-theme) {
53+
$container-color: map.get($theme, container-color);
54+
@if $container-color {
55+
--mdc-theme-secondary: #{$container-color};
56+
}
57+
58+
$icon-font-family: map.get($theme, icon-font-family);
59+
@if $icon-font-family {
60+
--mdc-icon-font: #{$icon-font-family};
61+
}
62+
63+
$ink-color: map.get($theme, ink-color);
64+
@if $ink-color {
65+
--mdc-theme-on-secondary: #{$ink-color};
66+
}
67+
68+
$elevation-shadow-color: map.get($theme, elevation-shadow-color);
69+
@if $elevation-shadow-color {
70+
--mdc-fab-box-shadow: #{elevation-theme.elevation-box-shadow(
71+
6,
72+
$color: $elevation-shadow-color
73+
)};
74+
}
75+
76+
@include shadow-dom.host-aware(selector.append(&, ':hover')) {
77+
$hover-container-color: map.get($theme, container-color-hover);
78+
@if $hover-container-color {
79+
--mdc-theme-secondary: #{$hover-container-color};
80+
}
81+
82+
$hover-ink-color: map.get($theme, ink-color-hover);
83+
@if $hover-ink-color {
84+
--mdc-theme-on-secondary: #{$hover-ink-color};
85+
}
86+
}
87+
88+
@include shadow-dom.host-aware(selector.append(&, ':focus,:focus-within')) {
89+
$focus-container-color: map.get($theme, container-color-focus);
90+
@if $focus-container-color {
91+
--mdc-theme-secondary: #{$focus-container-color};
92+
}
93+
94+
$focus-ink-color: map.get($theme, ink-color-focus);
95+
@if $focus-ink-color {
96+
--mdc-theme-on-secondary: #{$focus-ink-color};
97+
}
98+
}
99+
100+
@include shadow-dom.host-aware(
101+
selector.append(&, ':hover,:focus,:focus-within')
102+
) {
103+
@if $elevation-shadow-color {
104+
--mdc-fab-box-shadow: #{elevation-theme.elevation-box-shadow(
105+
8,
106+
$color: $elevation-shadow-color
107+
)};
108+
}
109+
}
110+
111+
@include shadow-dom.host-aware(selector.append(&, ':active')) {
112+
$press-container-color: map.get($theme, container-color-press);
113+
@if $press-container-color {
114+
--mdc-theme-secondary: #{$press-container-color};
115+
}
116+
117+
$press-ink-color: map.get($theme, ink-color-press);
118+
@if $press-ink-color {
119+
--mdc-theme-on-secondary: #{$press-ink-color};
120+
}
121+
122+
@if $elevation-shadow-color {
123+
--mdc-fab-box-shadow: #{elevation-theme.elevation-box-shadow(
124+
12,
125+
$color: $elevation-shadow-color
126+
)};
127+
}
128+
}
129+
130+
$icon-size: map.get($theme, icon-size);
131+
@if $icon-size {
132+
--mdc-icon-size: #{$icon-size};
133+
}
134+
135+
$extended-icon-padding: map.get($theme, extended-icon-padding);
136+
@if $extended-icon-padding {
137+
--mdc-fab-extended-icon-padding: #{$extended-icon-padding};
138+
}
139+
140+
$extended-label-padding: map.get($theme, extended-label-padding);
141+
@if $extended-label-padding {
142+
--mdc-fab-extended-label-padding: #{$extended-label-padding};
143+
}
144+
145+
$ripple: map.get($theme, ripple);
146+
@if $ripple {
147+
@include ripple-theme.theme($ripple);
148+
}
21149
}

packages/fab/src/_fab.scss

Lines changed: 25 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -14,31 +14,34 @@ WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
1414
See the License for the specific language governing permissions and
1515
limitations under the License.
1616
*/
17-
@use '@material/mwc-icon/src/_mwc-icon';
18-
@use '@material/elevation';
19-
@use '@material/fab';
20-
@use '@material/rtl';
17+
@use 'sass:map';
18+
@use '@material/elevation/elevation-theme';
19+
@use '@material/fab/mixins' as fab-mixins;
20+
@use '@material/fab/variables' as fab-variables;
21+
@use '@material/rtl/rtl';
2122
@use '@material/animation';
22-
@use '@material/shape';
23-
@use '@material/theme';
23+
@use '@material/shape/shape';
24+
@use '@material/theme/theme';
2425
@use '@material/theme/custom-properties';
26+
@use '@material/mwc-icon/src/mwc-icon';
27+
@use './fab-theme';
2528

26-
$icon-size: 24px;
29+
$icon-size: map.get(fab-theme.$light-theme, icon-size);
2730

2831
@mixin core-styles() {
2932
outline: none;
3033
--mdc-ripple-color: currentcolor;
3134
user-select: none;
3235
-webkit-tap-highlight-color: transparent;
3336

34-
@include fab.without-ripple();
37+
@include fab-mixins.without-ripple();
3538

3639
.mdc-fab {
3740
@include theme.property(
3841
box-shadow,
3942
custom-properties.create(
4043
--mdc-fab-box-shadow,
41-
elevation.elevation-box-shadow(6)
44+
elevation-theme.elevation-box-shadow(6)
4245
)
4346
);
4447

@@ -48,7 +51,7 @@ $icon-size: 24px;
4851
box-shadow,
4952
custom-properties.create(
5053
--mdc-fab-box-shadow,
51-
elevation.elevation-box-shadow(8)
54+
elevation-theme.elevation-box-shadow(8)
5255
)
5356
);
5457
}
@@ -58,7 +61,7 @@ $icon-size: 24px;
5861
box-shadow,
5962
custom-properties.create(
6063
--mdc-fab-box-shadow,
61-
elevation.elevation-box-shadow(12)
64+
elevation-theme.elevation-box-shadow(12)
6265
)
6366
);
6467
}
@@ -72,13 +75,13 @@ $icon-size: 24px;
7275
}
7376

7477
&:not(.mdc-fab--extended) mwc-ripple {
75-
@include shape.radius(fab.$shape-radius);
78+
@include shape.radius(fab-variables.$shape-radius);
7679
}
7780

7881
&.mdc-fab--extended mwc-ripple {
7982
@include shape.radius(
80-
fab.$shape-radius,
81-
$component-height: fab.$extended-height
83+
fab-variables.$shape-radius,
84+
$component-height: fab-variables.$extended-height
8285
);
8386
}
8487

@@ -101,43 +104,43 @@ $icon-size: 24px;
101104
custom-properties.create(--mdc-icon-size, $icon-size)
102105
);
103106

104-
@include fab.icon_();
105-
@include fab.icon-overrides_();
107+
@include fab-mixins.icon_();
108+
@include fab-mixins.icon-overrides_();
106109
}
107110

108111
&.mdc-fab--extended {
109112
$extended-icon-padding: custom-properties.create(
110113
--mdc-fab-extended-icon-padding,
111-
fab.$extended-icon-padding
114+
fab-variables.$extended-icon-padding
112115
);
113116
$extended-label-padding: custom-properties.create(
114117
--mdc-fab-extended-label-padding,
115-
fab.$extended-label-padding
118+
fab-variables.$extended-label-padding
116119
);
117120

118-
@include fab.extended-padding(
121+
@include fab-mixins.extended-padding(
119122
$extended-icon-padding,
120123
$extended-label-padding
121124
);
122125

123126
::slotted([slot='icon']) {
124-
@include fab.extended-icon-padding_(
127+
@include fab-mixins.extended-icon-padding_(
125128
$extended-icon-padding,
126129
$extended-label-padding
127130
);
128131
}
129132

130133
&.icon-end {
131134
.mdc-fab__icon {
132-
@include fab.extended-icon-padding_(
135+
@include fab-mixins.extended-icon-padding_(
133136
$extended-icon-padding,
134137
$extended-label-padding,
135138
$is-icon-at-end: true
136139
);
137140
}
138141

139142
::slotted([slot='icon']) {
140-
@include fab.extended-icon-padding_(
143+
@include fab-mixins.extended-icon-padding_(
141144
$extended-icon-padding,
142145
$extended-label-padding,
143146
$is-icon-at-end: true

0 commit comments

Comments
 (0)