UNPKG

5.18 kBSCSSView Raw
1//
2// Copyright 2021 Google Inc.
3//
4// Permission is hereby granted, free of charge, to any person obtaining a copy
5// of this software and associated documentation files (the "Software"), to deal
6// in the Software without restriction, including without limitation the rights
7// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8// copies of the Software, and to permit persons to whom the Software is
9// furnished to do so, subject to the following conditions:
10//
11// The above copyright notice and this permission notice shall be included in
12// all copies or substantial portions of the Software.
13//
14// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
20// THE SOFTWARE.
21//
22
23// stylelint-disable selector-class-pattern --
24// Selector '.mdc-*' should only be used in this project.
25
26@use '@material/feature-targeting/feature-targeting';
27@use '@material/ripple/ripple';
28@use '@material/ripple/ripple-theme';
29@use '@material/touch-target/mixins' as touch-target-mixins;
30@use './icon-button-theme';
31
32@mixin core-styles($query: feature-targeting.all()) {
33 @include without-ripple($query);
34 @include ripple($query);
35}
36
37@mixin static-styles($query: feature-targeting.all()) {
38 $feat-structure: feature-targeting.create-target($query, structure);
39
40 // postcss-bem-linter: define icon-button
41 .mdc-icon-button {
42 @include feature-targeting.targets($feat-structure) {
43 display: inline-block;
44 position: relative;
45 box-sizing: border-box;
46 border: none;
47 outline: none;
48 background-color: transparent;
49 fill: currentColor;
50 color: inherit;
51 text-decoration: none;
52 cursor: pointer;
53 user-select: none;
54 z-index: 0; // Added to render above the container in IE11 tests.
55 overflow: visible; // Added to fix IE11 touch target tests.
56 }
57
58 .mdc-icon-button__touch {
59 @include touch-target-mixins.touch-target(
60 $set-width: true,
61 $query: $query
62 );
63 }
64
65 @include if-disabled_ {
66 @include feature-targeting.targets($feat-structure) {
67 cursor: default;
68 pointer-events: none;
69 }
70 }
71 }
72
73 .mdc-icon-button--display-flex {
74 @include feature-targeting.targets($feat-structure) {
75 align-items: center;
76 display: inline-flex;
77 justify-content: center;
78 }
79 }
80
81 .mdc-icon-button__icon {
82 @include feature-targeting.targets($feat-structure) {
83 display: inline-block;
84 }
85
86 &.mdc-icon-button__icon--on {
87 @include feature-targeting.targets($feat-structure) {
88 display: none;
89 }
90 }
91 }
92
93 .mdc-icon-button--on {
94 .mdc-icon-button__icon {
95 @include feature-targeting.targets($feat-structure) {
96 display: none;
97 }
98
99 &.mdc-icon-button__icon--on {
100 @include feature-targeting.targets($feat-structure) {
101 display: inline-block;
102 }
103 }
104 }
105 }
106 // postcss-bem-linter: end
107
108 .mdc-icon-button__link {
109 @include feature-targeting.targets($feat-structure) {
110 height: 100%;
111 left: 0;
112 outline: none;
113 position: absolute;
114 top: 0;
115 width: 100%;
116 }
117 }
118}
119
120@mixin without-ripple($query: feature-targeting.all()) {
121 $feat-structure: feature-targeting.create-target($query, structure);
122
123 .mdc-icon-button {
124 @include feature-targeting.targets($feat-structure) {
125 font-size: icon-button-theme.$icon-size;
126 }
127
128 @include icon-button-theme.density(0, $query: $query);
129
130 @include icon-button-theme.disabled-ink-color(
131 text-disabled-on-light,
132 $query: $query
133 );
134
135 svg,
136 img {
137 @include feature-targeting.targets($feat-structure) {
138 width: icon-button-theme.$icon-size;
139 height: icon-button-theme.$icon-size;
140 }
141 }
142 }
143
144 @include static-styles($query: $query);
145}
146
147@mixin ripple($query: feature-targeting.all()) {
148 @include ripple.common($query); // COPYBARA_COMMENT_THIS_LINE
149
150 .mdc-icon-button {
151 @include ripple.surface(
152 $query: $query,
153 $ripple-target: icon-button-theme.$ripple-target
154 );
155 @include ripple.radius-unbounded(
156 $query: $query,
157 $ripple-target: icon-button-theme.$ripple-target
158 );
159 @include ripple-theme.states(
160 $query: $query,
161 $ripple-target: icon-button-theme.$ripple-target
162 );
163
164 .mdc-icon-button__ripple {
165 $feat-structure: feature-targeting.create-target($query, structure);
166 @include feature-targeting.targets($feat-structure) {
167 height: 100%;
168 left: 0px;
169 pointer-events: none;
170 position: absolute;
171 top: 0px;
172 width: 100%;
173 z-index: -1;
174 }
175 }
176 }
177}
178
179///
180/// Helps style the icon button in its disabled state.
181/// @access private
182///
183@mixin if-disabled_ {
184 &:disabled {
185 @content;
186 }
187}