This repository was archived by the owner on Jan 13, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Copy path_notched-outline-theme.scss
369 lines (332 loc) · 12.1 KB
/
_notched-outline-theme.scss
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
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
//
// Copyright 2023 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:list';
@use 'sass:meta';
@use '@material/theme/custom-properties';
@use '@material/theme/theme';
@use '@material/shape/functions' as shape-functions;
@use '@material/shape/mixins' as shape-mixins;
@use '@material/floating-label/mixins' as floating-label-mixins;
@use '@material/feature-targeting/feature-targeting';
@use '@material/rtl/rtl';
// Keep this in sync with constants.numbers.MIN_LEADING_STROKE_EDGE_POSITION
$min-leading-stroke-edge-position: 12px !default;
// The gap between the stroke end and floating label
// Keep this in sync with constants.numbers.NOTCH_GUTTER_SIZE
$notch-gutter-size: 4px !default;
$border-width: 1px !default;
$leading-width: 12px !default;
$padding: 4px !default;
// This variable keeps the before/after JS label centered in the notch when the font-size is changed.
$label-adjust: 14% !default;
/// Label box height when it is floating above for notched upgraded. This value is used to put the label vertically in
/// the middle when it is notched.
$label-box-height: 13.5px !default;
/// Label adjust offset applied to floating label when it is notched. Since notch without upgraded has different font
/// size we add additional offset value.
$label-adjust-absolute: 2.5px !default;
@mixin theme-styles($query: feature-targeting.all()) {
$feat-structure: feature-targeting.create-target($query, structure);
.mdc-notched-outline {
&__leading,
&__notch,
&__trailing {
@include feature-targeting.targets($feat-structure) {
border-top: $border-width solid;
border-bottom: $border-width solid;
}
}
&__leading {
@include feature-targeting.targets($feat-structure) {
@include rtl.reflexive-property(border, $border-width solid, none);
width: $leading-width;
}
}
&__trailing {
@include feature-targeting.targets($feat-structure) {
@include rtl.reflexive-property(border, none, $border-width solid);
}
}
&__notch {
@include feature-targeting.targets($feat-structure) {
max-width: calc(100% - #{$leading-width} * 2);
}
}
}
}
@mixin color($color, $query: feature-targeting.all()) {
$feat-color: feature-targeting.create-target($query, color);
.mdc-notched-outline__leading,
.mdc-notched-outline__notch,
.mdc-notched-outline__trailing {
@include feature-targeting.targets($feat-color) {
@include theme.property(border-color, $color);
}
}
}
@mixin stroke-width($width, $query: feature-targeting.all()) {
$feat-structure: feature-targeting.create-target($query, structure);
.mdc-notched-outline__leading,
.mdc-notched-outline__notch,
.mdc-notched-outline__trailing {
@include feature-targeting.targets($feat-structure) {
@include theme.property(border-width, $width);
}
}
}
///
/// Adds top offset to compensate for border width box size when it is notched.
/// Use this when floating label is aligned to center to prevent label jump on focus.
/// @param {Number} $stroke-width Stroke width of notched outline that needs to be offset.
///
@mixin notch-offset($stroke-width, $query: feature-targeting.all()) {
$feat-structure: feature-targeting.create-target($query, structure);
.mdc-notched-outline--notched .mdc-notched-outline__notch {
@include feature-targeting.targets($feat-structure) {
padding-top: $stroke-width;
}
}
}
@mixin shape-radius(
$radius,
$rtl-reflexive: false,
$component-height: null,
$query: feature-targeting.all()
) {
$feat-structure: feature-targeting.create-target($query, structure);
// Resolve the radius relative to the notched outline component's height. The
// component should provide its current height from its density. The resolved
// radius allows percentage radii to be converted to pixels.
$resolved-radius: shape-functions.resolve-radius(
$radius,
$component-height: $component-height
);
// Grab the top-left radius. We'll need it to adjust the leading for the
// label notch if the resulting radius shape is larger than the default
// leading.
$top-left-radius: list.nth(
shape-functions.unpack-radius($resolved-radius),
1
);
$top-left-is-custom-prop: custom-properties.is-custom-prop($top-left-radius);
$top-left-radius-px: $top-left-radius;
@if ($top-left-is-custom-prop) {
$top-left-radius-px: custom-properties.get-fallback($top-left-radius);
}
.mdc-notched-outline__leading {
// mask the leading to apply the top-left and bottom-left corners
@include shape-mixins.radius(
shape-functions.mask-radius($radius, 1 0 0 1),
$rtl-reflexive: true,
$component-height: $component-height,
$query: $query
);
@include feature-targeting.targets($feat-structure) {
@if ($top-left-radius-px > $leading-width) {
// If the radius is bigger than the default leading width, we need to
// increase the leading width
width: $top-left-radius-px;
@if ($top-left-is-custom-prop) {
// The radius may be a custom property, in which case the above width
// is the IE11 fallback value.
/* @alternate */
}
}
@if ($top-left-is-custom-prop) {
// If the top-left radius is dynamic, the width of the leading is
// the max of whichever is larger: the default leading width or the
// value of the custom property.
$var: custom-properties.create-var($top-left-radius);
// Interpolation is a workaround for sass/sass#3259.
@supports (top: max(#{0%})) {
width: max(#{$leading-width}, #{$var});
}
}
}
}
// Similar to above, adjust the max-width of the notch if we adjusted the
// leading's width.
.mdc-notched-outline__notch {
@include feature-targeting.targets($feat-structure) {
@if ($top-left-radius-px > $leading-width) {
max-width: calc(100% - #{$top-left-radius-px} * 2);
@if ($top-left-is-custom-prop) {
/* @alternate */
}
}
@if ($top-left-is-custom-prop) {
$var: custom-properties.create-var($top-left-radius);
// Interpolation is a workaround for sass/sass#3259.
@supports (top: max(#{0%})) {
max-width: calc(100% - max(#{$leading-width}, #{$var}) * 2);
}
}
}
}
.mdc-notched-outline__trailing {
// mask the leading to apply the top-right and bottom-right corners
@include shape-mixins.radius(
shape-functions.mask-radius($radius, 0 1 1 0),
$rtl-reflexive: true,
$component-height: $component-height,
$query: $query
);
}
}
@mixin floating-label-float-position(
$positionY,
$positionX: 0%,
$scale: 0.75,
$query: feature-targeting.all()
) {
$feat-structure: feature-targeting.create-target($query, structure);
@include floating-label-mixins.float-position(
$positionY + $label-adjust,
$positionX,
1,
$query: $query
);
.mdc-floating-label--float-above {
@include feature-targeting.targets($feat-structure) {
font-size: ($scale * 1rem);
}
}
// Two selectors to ensure we select the appropriate class when applied from this component or a parent component.
&.mdc-notched-outline--upgraded,
.mdc-notched-outline--upgraded {
@include floating-label-mixins.float-position(
$positionY,
$positionX,
$scale,
$query: $query
);
.mdc-floating-label--float-above {
@include feature-targeting.targets($feat-structure) {
font-size: 1rem;
}
}
}
}
///
/// Sets floating label position in notched outline when label is afloat.
///
/// @param {Number} $positionY Absolute Y-axis position in `px`.
/// @param {Number} $positionX Absolute X-axis position in `px`. Defaults to `0`.
/// @param {Number} $scale Defaults to `.75`.
/// @param {Number} $font-size Defaults to `1rem`.
///
/// @todo Replace mixin `mdc-notched-outline-floating-label-float-position` with this mixin when floating label is
/// center aligned in all the places.
///
@mixin floating-label-float-position-absolute(
$positionY,
$positionX: 0,
$scale: 0.75,
$font-size: 1rem,
$query: feature-targeting.all()
) {
$feat-structure: feature-targeting.create-target($query, structure);
$float-positionY: if(
meta.type-of($positionY) == 'calculation',
calc($positionY + $label-adjust-absolute),
$positionY + $label-adjust-absolute
);
@include floating-label-mixins.float-position(
$float-positionY,
$positionX,
$scale: 1,
$query: $query
);
// Two selectors to ensure we select the appropriate class when applied from this component or a parent component.
&.mdc-notched-outline--upgraded,
.mdc-notched-outline--upgraded {
@include floating-label-mixins.float-position(
$positionY,
$positionX,
$scale,
$query: $query
);
}
@include floating-label-float-font-size(
$scale: $scale,
$font-size: $font-size,
$query: $query
);
}
///
/// Sets floating label font size in notched outline when label is afloat.
///
/// @param {Number} $scale Defaults to `.75`.
/// @param {Number} $font-size Defaults to `1rem`.
///
@mixin floating-label-float-font-size(
$scale: 0.75,
$font-size: 1rem,
$query: feature-targeting.all()
) {
$font-size-value: if(
custom-properties.is-custom-prop($font-size),
custom-properties.get-declaration-value($font-size),
$font-size
);
// Check if $font-size-value is null. This mixin is typically called from a
// component's `theme-styles` mixin, meaning the $font-size value will be
// passed in via a call to map.get(...). When the value is missing from the
// theme map, a `null` value will be passed in -- which does NOT result in
// the default 1rem value we've set in the mixin definition being used. Due
// to our call to `calc()` in this mixin, $font-size values of `null` results
// in BUILD errors. To avoid having to perform null checks in all the mixin
// calls that eventually lead down to this one, we just do a null check in
// this mixin.
$font-size-value: if($font-size-value, $font-size-value, 1rem);
$feat-structure: feature-targeting.create-target($query, structure);
.mdc-floating-label--float-above {
@include feature-targeting.targets($feat-structure) {
font-size: calc($scale * $font-size-value);
}
}
// Two selectors to ensure we select the appropriate class when applied from
// this component or a parent component.
&.mdc-notched-outline--upgraded,
.mdc-notched-outline--upgraded {
.mdc-floating-label--float-above {
@include feature-targeting.targets($feat-structure) {
font-size: $font-size-value;
}
}
}
}
///
/// Sets the max-width for the notch
///
/// @param {Number} $max-width Max-width for the notch
///
@mixin notch-max-width($max-width, $query: feature-targeting.all()) {
$feat-structure: feature-targeting.create-target($query, structure);
:not(.mdc-notched-outline--notched) .mdc-notched-outline__notch {
@include feature-targeting.targets($feat-structure) {
max-width: $max-width;
}
}
}