UNPKG

7.85 kBSCSSView Raw
1//
2// Copyright 2020 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/elevation/elevation';
27@use '@material/elevation/elevation-theme';
28@use '@material/feature-targeting/feature-targeting';
29@use '@material/ripple/ripple-theme';
30@use '@material/rtl/rtl';
31@use '@material/dom/dom';
32@use '@material/touch-target/touch-target';
33@use '@material/focus-ring/focus-ring';
34@use '@material/typography/typography';
35@use './button-shared-theme';
36
37@mixin static-styles($query: feature-targeting.all()) {
38 @include _static-styles-base($query: $query);
39 @include _typography-styles($query: $query);
40}
41
42@mixin _static-styles-base($query: feature-targeting.all()) {
43 $feat-structure: feature-targeting.create-target($query, structure);
44
45 @include touch-target.wrapper($query); // COPYBARA_COMMENT_THIS_LINE
46 // prettier-ignore
47 @include elevation.overlay-common($query); // COPYBARA_COMMENT_THIS_LINE
48
49 // postcss-bem-linter: define button
50 .mdc-button {
51 @include _root-structure($query);
52 // The icon CSS class overrides styles defined in the .material-icons CSS
53 // class, which is loaded separately so the order of CSS definitions is not
54 // guaranteed. Therefore, increase specifity by nesting this class to ensure
55 // overrides apply.
56 .mdc-button__icon {
57 @include feature-targeting.targets($feat-structure) {
58 @include _icon-structure;
59 }
60 }
61
62 .mdc-button__label {
63 @include feature-targeting.targets($feat-structure) {
64 // Necessary such that label is stacked on top of ripple
65 // (since ripple is a positioned element, non-positioned elements
66 // appear under it).
67 position: relative;
68 }
69 }
70
71 .mdc-button__focus-ring {
72 @include feature-targeting.targets($feat-structure) {
73 display: none;
74 }
75 }
76
77 @include ripple-theme.focus {
78 .mdc-button__focus-ring {
79 @include dom.forced-colors-mode($exclude-ie11: true) {
80 @include focus-ring.focus-ring($query: $query);
81
82 @include feature-targeting.targets($feat-structure) {
83 display: block;
84 }
85 }
86 }
87 }
88
89 .mdc-button__touch {
90 @include touch-target.touch-target($query: $query);
91 }
92 }
93
94 .mdc-button__label + .mdc-button__icon {
95 @include feature-targeting.targets($feat-structure) {
96 @include icon-trailing;
97 }
98 }
99
100 svg.mdc-button__icon {
101 @include feature-targeting.targets($feat-structure) {
102 @include icon-svg;
103 }
104 }
105
106 .mdc-button--touch {
107 // Touch target doesn't change with height. It simply gets removed if
108 // density (height) changes. Therefore, it is a static style.
109 @include touch-target.margin(
110 $component-height: button-shared-theme.$height,
111 $query: $query
112 );
113 }
114 // postcss-bem-linter: end
115}
116
117@mixin _typography-styles($query) {
118 .mdc-button {
119 // Exclude properties declared in theme styles.
120 @include typography.typography(
121 button,
122 $exclude-props: (
123 font-size,
124 line-height,
125 font-weight,
126 letter-spacing,
127 text-transform
128 ),
129 $query: $query
130 );
131 }
132}
133
134/// @deprecated Contains typography declarations now part of theme-styles.
135@mixin deprecated-static-styles-without-ripple(
136 $query: feature-targeting.all()
137) {
138 @include _deprecated-typography-styles($query: $query);
139 @include _static-styles-base($query: $query);
140}
141
142@mixin _deprecated-typography-styles($query) {
143 .mdc-button {
144 @include typography.typography(button, $query);
145 }
146}
147
148@mixin deprecated-base($query) {
149 @include base($query);
150}
151
152@mixin base($query) {
153 @include typography.typography(button, $query);
154 @include _root-structure($query: $query);
155}
156
157@mixin _root-structure($query) {
158 $feat-structure: feature-targeting.create-target($query, structure);
159
160 @include elevation-theme.overlay-surface-position($query: $query);
161 @include elevation-theme.overlay-dimensions(100%, $query: $query);
162
163 @include feature-targeting.targets($feat-structure) {
164 display: inline-flex;
165 // position: relative; already set in mdc-elevation-overlay-surface-position
166 align-items: center;
167 justify-content: center;
168 box-sizing: border-box;
169 min-width: 64px;
170 border: none;
171 outline: none;
172 /* @alternate */
173 line-height: inherit;
174 user-select: none;
175 -webkit-appearance: none;
176 // Even though `visible` is the default, IE 11 computes the property as
177 // `hidden` in some cases, unless it's explicitly defined here.
178 overflow: visible;
179 vertical-align: middle;
180 background: transparent;
181 }
182
183 &::-moz-focus-inner {
184 @include feature-targeting.targets($feat-structure) {
185 padding: 0;
186 border: 0;
187 }
188 }
189
190 // postcss-bem-linter: ignore
191 &:active {
192 @include feature-targeting.targets($feat-structure) {
193 outline: none;
194 }
195 }
196
197 &:hover {
198 @include feature-targeting.targets($feat-structure) {
199 cursor: pointer;
200 }
201 }
202
203 &:disabled {
204 @include feature-targeting.targets($feat-structure) {
205 cursor: default;
206 pointer-events: none;
207 }
208 }
209}
210
211@mixin icon {
212 @include _icon-structure;
213 @include _icon-size(18px);
214}
215
216@mixin _icon-structure {
217 @include rtl.reflexive-box(margin, right, 8px);
218
219 display: inline-block;
220 position: relative;
221 vertical-align: top;
222}
223
224@mixin _icon-size($size-px) {
225 $icon-size: typography.px-to-rem($size-px);
226
227 font-size: $icon-size;
228 height: $icon-size;
229 width: $icon-size;
230}
231
232@mixin icon-trailing {
233 @include rtl.reflexive-box(margin, left, 8px);
234}
235
236@mixin icon-svg {
237 fill: currentColor;
238}
239
240@mixin icon-contained {
241 @include rtl.reflexive-property(margin, -4px, 8px);
242}
243
244@mixin icon-contained-trailing {
245 @include rtl.reflexive-property(margin, 8px, -4px);
246}
247
248@mixin raised-transition($query: feature-targeting.all()) {
249 $feat-animation: feature-targeting.create-target($query, animation);
250
251 @include feature-targeting.targets($feat-animation) {
252 transition: elevation-theme.transition-value();
253 }
254}
255
256/// @deprecated Private style mixin for partners; not available for public use.
257@mixin deprecated-icon {
258 @include icon;
259}
260
261/// @deprecated Private style mixin for partners; not available for public use.
262@mixin deprecated-icon-trailing {
263 @include icon-trailing;
264}
265
266/// @deprecated Private style mixin for partners; not available for public use.
267@mixin deprecated-icon-svg {
268 @include icon-svg;
269}
270
271/// @deprecated Private style mixin for partners; not available for public use.
272@mixin deprecated-icon-contained {
273 @include icon-contained;
274}
275
276/// @deprecated Private style mixin for partners; not available for public use.
277@mixin deprecated-icon-contained-trailing {
278 @include icon-contained-trailing;
279}