Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit 7161170

Browse files
authored
feat(icon-button): Add disabled state color mixins (#5246)
1 parent db4b4e2 commit 7161170

File tree

4 files changed

+46
-14
lines changed

4 files changed

+46
-14
lines changed

packages/mdc-icon-button/README.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -167,6 +167,7 @@ Mixin | Description
167167
`mdc-icon-button-size($size)` | Sets the padding for the icon button based on overall size.
168168
`mdc-icon-button-icon-size($width, $height, $padding)` | Sets the width, height, font-size and padding for the icon and ripple. `$height` is optional and defaults to `$width`. `$padding` is optional and defaults to `max($width, $height)/2`. `font-size` is set to `max($width, $height)`.
169169
`mdc-icon-button-ink-color($color)` | Sets the font color and the ripple color to the provided color value.
170+
`mdc-icon-button-disabled-ink-color($color)` | Sets the font color to the provided color value for a disabled icon button.
170171

171172
## `MDCIconButtonToggle` Properties and Methods
172173

packages/mdc-icon-button/_mixins.scss

Lines changed: 39 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -144,18 +144,26 @@
144144
}
145145
}
146146

147+
///
148+
/// Sets the font color and the ripple color to the provided color value.
149+
/// @param {Color} $color - The desired font and ripple color.
150+
///
147151
@mixin mdc-icon-button-ink-color($color, $query: mdc-feature-all()) {
148-
$feat-color: mdc-feature-create-target($query, color);
152+
@include mdc-icon-button-ink-color_($color, $query: $query);
153+
@include mdc-states($color, $query: $query);
154+
}
149155

150-
@include mdc-feature-targets($feat-color) {
151-
@include mdc-theme-prop(color, $color);
156+
///
157+
/// Sets the font color to the provided color value for a disabled icon button.
158+
/// @param {Color} $color - The desired font color.
159+
///
160+
@mixin mdc-icon-button-disabled-ink-color($color, $query: mdc-feature-all()) {
161+
@include mdc-icon-button-if-disabled_ {
162+
@include mdc-icon-button-ink-color_($color, $query: $query);
152163
}
153-
154-
@include mdc-states($color, $query: $query);
155164
}
156165

157166
@mixin mdc-icon-button-base_($query: mdc-feature-all()) {
158-
$feat-color: mdc-feature-create-target($query, color);
159167
$feat-structure: mdc-feature-create-target($query, structure);
160168

161169
@include mdc-feature-targets($feat-structure) {
@@ -182,14 +190,35 @@
182190
}
183191
}
184192

185-
&:disabled {
186-
@include mdc-feature-targets($feat-color) {
187-
@include mdc-theme-prop(color, text-disabled-on-light);
188-
}
193+
@include mdc-icon-button-disabled-ink-color(text-disabled-on-light, $query: $query);
189194

195+
@include mdc-icon-button-if-disabled_ {
190196
@include mdc-feature-targets($feat-structure) {
191197
cursor: default;
192198
pointer-events: none;
193199
}
194200
}
195201
}
202+
203+
///
204+
/// Sets the font color to the provided color value. This can be wrapped in
205+
/// a state qualifier such as `mdc-icon-button-if-disabled_`.
206+
/// @access private
207+
///
208+
@mixin mdc-icon-button-ink-color_($color, $query: mdc-feature-all()) {
209+
$feat-color: mdc-feature-create-target($query, color);
210+
211+
@include mdc-feature-targets($feat-color) {
212+
@include mdc-theme-prop(color, $color);
213+
}
214+
}
215+
216+
///
217+
/// Helps style the icon button in its disabled state.
218+
/// @access private
219+
///
220+
@mixin mdc-icon-button-if-disabled_ {
221+
&:disabled {
222+
@content;
223+
}
224+
}

test/screenshot/golden.json

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -720,11 +720,11 @@
720720
}
721721
},
722722
"spec/mdc-icon-button/mixins/ink-color.html": {
723-
"public_url": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2019/05/10/14_25_41_111/spec/mdc-icon-button/mixins/ink-color.html?utm_source=golden_json",
723+
"public_url": "https://storage.googleapis.com/mdc-web-screenshot-tests/allanchen/2019/11/09/03_52_08_759/spec/mdc-icon-button/mixins/ink-color.html?utm_source=golden_json",
724724
"screenshots": {
725-
"desktop_windows_chrome@77": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2019/05/10/14_25_41_111/spec/mdc-icon-button/mixins/ink-color.html.windows_chrome_74.png",
726-
"desktop_windows_firefox@69": "https://storage.googleapis.com/mdc-web-screenshot-tests/travis/2018/09/10/17_42_51_602/spec/mdc-icon-button/mixins/ink-color.html.windows_firefox_62.png",
727-
"desktop_windows_ie@11": "https://storage.googleapis.com/mdc-web-screenshot-tests/advorak/2018/07/17/22_50_36_536/spec/mdc-icon-button/mixins/ink-color.html.windows_ie_11.png"
725+
"desktop_windows_chrome@77": "https://storage.googleapis.com/mdc-web-screenshot-tests/allanchen/2019/11/09/03_52_08_759/spec/mdc-icon-button/mixins/ink-color.html.windows_chrome_77.png",
726+
"desktop_windows_firefox@69": "https://storage.googleapis.com/mdc-web-screenshot-tests/allanchen/2019/11/09/03_52_08_759/spec/mdc-icon-button/mixins/ink-color.html.windows_firefox_69.png",
727+
"desktop_windows_ie@11": "https://storage.googleapis.com/mdc-web-screenshot-tests/allanchen/2019/11/09/03_52_08_759/spec/mdc-icon-button/mixins/ink-color.html.windows_ie_11.png"
728728
}
729729
},
730730
"spec/mdc-image-list/classes/standard-with-text-protection.html": {

test/screenshot/spec/mdc-icon-button/fixture.scss

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
@import "../mixins";
2727

2828
$custom-icon-button-icon-ink-color: $material-color-red-500;
29+
$custom-icon-button-disabled-icon-ink-color: rgba(purple, .3);
2930
$custom-icon-button-size: 36px;
3031

3132
.test-cell--icon-button {
@@ -34,6 +35,7 @@ $custom-icon-button-size: 36px;
3435

3536
.custom-icon-button--ink-color {
3637
@include mdc-icon-button-ink-color($custom-icon-button-icon-ink-color);
38+
@include mdc-icon-button-disabled-ink-color($custom-icon-button-disabled-icon-ink-color);
3739
}
3840

3941
.custom-icon-button--icon-size {

0 commit comments

Comments
 (0)