forked from material-components/material-components-web
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy path_ripple.scss
More file actions
345 lines (303 loc) · 10.7 KB
/
_ripple.scss
File metadata and controls
345 lines (303 loc) · 10.7 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
//
// Copyright 2016 Google Inc.
//
// Permission is hereby granted, free of charge, to any person obtaining a copy
// of this software and associated documentation files (the "Software"), to deal
// in the Software without restriction, including without limitation the rights
// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
// copies of the Software, and to permit persons to whom the Software is
// furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in
// all copies or substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
// THE SOFTWARE.
//
// stylelint-disable selector-class-pattern --
// Selector '.mdc-*' should only be used in this project.
@use 'sass:math';
@use 'sass:color';
@use 'sass:map';
@use '@material/animation/functions' as functions2;
@use '@material/animation/variables' as variables2;
@use '@material/base/mixins' as base-mixins;
@use '@material/theme/custom-properties';
@use '@material/feature-targeting/feature-targeting';
@use '@material/rtl/rtl';
@use '@material/theme/theme';
@use './ripple-theme';
@mixin core-styles($query: feature-targeting.all()) {
@include static-styles($query: $query);
.mdc-ripple-surface {
@include ripple-theme.states($query: $query);
}
}
@mixin static-styles($query: feature-targeting.all()) {
$feat-structure: feature-targeting.create-target($query, structure);
.mdc-ripple-surface {
@include surface($query: $query);
@include radius-bounded($query: $query);
@include surface-styles($query: $query);
}
.mdc-ripple-surface[data-mdc-ripple-is-unbounded],
.mdc-ripple-upgraded--unbounded {
@include radius-unbounded($query: $query);
@include unbounded-styles($query: $query);
}
}
/// Sets all states (including hover, focus, press, activated and selected) with
/// given color as base color.
///
/// This mixin is for internal use only. Use `ripple-theme.states($color)` mixin
/// to set interactive states (hover, focus & press) color.
///
/// @param {Color|String} $color - Target base color. Can be valid CSS color or
/// a color string literal (i.e., `primary`, `secondary`, etc).
@mixin states-for-color($color, $query: feature-targeting.all()) {
@include ripple-theme.states($color, $query: $query);
@include ripple-theme.states-activated($color, $query: $query);
@include ripple-theme.states-selected($color, $query: $query);
}
@mixin surface-styles($query: feature-targeting.all()) {
$feat-structure: feature-targeting.create-target($query, structure);
@include feature-targeting.targets($feat-structure) {
position: relative;
outline: none;
overflow: hidden;
}
}
@mixin unbounded-styles($query: feature-targeting.all()) {
$feat-structure: feature-targeting.create-target($query, structure);
@include feature-targeting.targets($feat-structure) {
overflow: visible;
}
}
@mixin common($query: feature-targeting.all()) {
$feat-animation: feature-targeting.create-target($query, animation);
// Ensure that styles needed by any component using MDC Ripple are emitted, but only once.
// (Every component using MDC Ripple imports these mixins, but doesn't necessarily import
// mdc-ripple.scss.)
@include feature-targeting.targets($feat-animation) {
@include base-mixins.emit-once('mdc-ripple/common/animation') {
@include keyframes_;
}
}
}
@mixin surface(
$query: feature-targeting.all(),
$ripple-target: '&',
$include-will-change: true // TODO(b/151931961): Remove once resolved
) {
$feat-animation: feature-targeting.create-target($query, animation);
$feat-structure: feature-targeting.create-target($query, structure);
@include feature-targeting.targets($feat-structure) {
--mdc-ripple-fg-size: 0;
--mdc-ripple-left: 0;
--mdc-ripple-top: 0;
--mdc-ripple-fg-scale: 1;
--mdc-ripple-fg-translate-end: 0;
--mdc-ripple-fg-translate-start: 0;
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
// TODO(b/151931961): Remove the following block once resolved
@if $include-will-change {
will-change: transform, opacity;
}
}
#{$ripple-target}::before,
#{$ripple-target}::after {
@include feature-targeting.targets($feat-structure) {
position: absolute;
border-radius: 50%;
opacity: 0;
pointer-events: none;
content: '';
}
}
#{$ripple-target}::before {
@include feature-targeting.targets($feat-animation) {
// Also transition background-color to avoid unnatural color flashes when toggling activated/selected state
transition: opacity ripple-theme.$states-wash-duration linear,
background-color ripple-theme.$states-wash-duration linear;
}
@include feature-targeting.targets($feat-structure) {
// Ensure that the ripple wash for hover/focus states is displayed on top of positioned child elements
@include theme.property(
z-index,
custom-properties.create(--mdc-ripple-z-index, 1)
);
}
}
#{$ripple-target}::after {
@include feature-targeting.targets($feat-structure) {
@include theme.property(
z-index,
custom-properties.create(--mdc-ripple-z-index, 0)
);
}
}
// Common styles for upgraded surfaces (some of these depend on custom properties set via JS or other mixins)
&.mdc-ripple-upgraded {
#{$ripple-target}::before {
@include feature-targeting.targets($feat-structure) {
transform: scale(var(--mdc-ripple-fg-scale, 1));
}
}
#{$ripple-target}::after {
@include feature-targeting.targets($feat-structure) {
top: 0;
@include rtl.ignore-next-line();
left: 0;
transform: scale(0);
transform-origin: center center;
}
}
}
&.mdc-ripple-upgraded--unbounded {
#{$ripple-target}::after {
@include feature-targeting.targets($feat-structure) {
top: var(--mdc-ripple-top, 0);
@include rtl.ignore-next-line();
left: var(--mdc-ripple-left, 0);
}
}
}
&.mdc-ripple-upgraded--foreground-activation {
#{$ripple-target}::after {
@include feature-targeting.targets($feat-animation) {
animation: mdc-ripple-fg-radius-in ripple-theme.$translate-duration
forwards,
mdc-ripple-fg-opacity-in ripple-theme.$fade-in-duration forwards;
}
}
}
&.mdc-ripple-upgraded--foreground-deactivation {
#{$ripple-target}::after {
@include feature-targeting.targets($feat-animation) {
animation: mdc-ripple-fg-opacity-out ripple-theme.$fade-out-duration;
}
@include feature-targeting.targets($feat-structure) {
// Retain transform from mdc-ripple-fg-radius-in activation
@include rtl.ignore-next-line();
transform: translate(var(--mdc-ripple-fg-translate-end, 0))
scale(var(--mdc-ripple-fg-scale, 1));
}
}
}
}
@mixin radius-bounded(
$radius: 100%,
$query: feature-targeting.all(),
$ripple-target: '&'
) {
$feat-struture: feature-targeting.create-target($query, structure);
#{$ripple-target}::before,
#{$ripple-target}::after {
@include feature-targeting.targets($feat-struture) {
top: calc(50% - #{$radius});
@include rtl.ignore-next-line();
left: calc(50% - #{$radius});
width: $radius * 2;
height: $radius * 2;
}
}
&.mdc-ripple-upgraded {
#{$ripple-target}::after {
@include feature-targeting.targets($feat-struture) {
width: var(--mdc-ripple-fg-size, $radius);
height: var(--mdc-ripple-fg-size, $radius);
}
}
}
}
@mixin radius-unbounded(
$radius: 100%,
$query: feature-targeting.all(),
$ripple-target: '&'
) {
$feat-struture: feature-targeting.create-target($query, structure);
#{$ripple-target}::before,
#{$ripple-target}::after {
@include feature-targeting.targets($feat-struture) {
top: calc(50% - #{math.div($radius, 2)});
@include rtl.ignore-next-line();
left: calc(50% - #{math.div($radius, 2)});
width: $radius;
height: $radius;
}
}
&.mdc-ripple-upgraded {
#{$ripple-target}::before,
#{$ripple-target}::after {
@include feature-targeting.targets($feat-struture) {
top: var(--mdc-ripple-top, calc(50% - #{math.div($radius, 2)}));
@include rtl.ignore-next-line();
left: var(--mdc-ripple-left, calc(50% - #{math.div($radius, 2)}));
width: var(--mdc-ripple-fg-size, $radius);
height: var(--mdc-ripple-fg-size, $radius);
}
}
#{$ripple-target}::after {
@include feature-targeting.targets($feat-struture) {
width: var(--mdc-ripple-fg-size, $radius);
height: var(--mdc-ripple-fg-size, $radius);
}
}
}
}
// Common styles for a ripple target element.
// Used for components which have an inner ripple target element.
@mixin target-common($query: feature-targeting.all()) {
$feat-structure: feature-targeting.create-target($query, structure);
@include feature-targeting.targets($feat-structure) {
position: absolute;
top: 0;
left: 0;
width: 100%;
height: 100%;
// Necessary for clicks on other inner elements (e.g. close icon in chip)
// to go through.
pointer-events: none;
}
}
@mixin keyframes_ {
@keyframes mdc-ripple-fg-radius-in {
from {
animation-timing-function: variables2.$standard-curve-timing-function;
// NOTE: For these keyframes, we do not need custom property fallbacks because they are only
// used in conjunction with `.mdc-ripple-upgraded`. Since MDCRippleFoundation checks to ensure
// that custom properties are supported within the browser before adding this class, we can
// safely use them without a fallback.
@include rtl.ignore-next-line();
transform: translate(var(--mdc-ripple-fg-translate-start, 0)) scale(1);
}
to {
@include rtl.ignore-next-line();
transform: translate(var(--mdc-ripple-fg-translate-end, 0))
scale(var(--mdc-ripple-fg-scale, 1));
}
}
@keyframes mdc-ripple-fg-opacity-in {
from {
animation-timing-function: linear;
opacity: 0;
}
to {
opacity: var(--mdc-ripple-fg-opacity, 0);
}
}
@keyframes mdc-ripple-fg-opacity-out {
from {
animation-timing-function: linear;
opacity: var(--mdc-ripple-fg-opacity, 0);
}
to {
opacity: 0;
}
}
}