21
21
//
22
22
23
23
@import " @material/animation/functions" ;
24
+ @import " @material/density/functions" ;
24
25
@import " @material/feature-targeting/functions" ;
25
26
@import " @material/feature-targeting/mixins" ;
26
27
@import " @material/ripple/mixins" ;
@@ -48,22 +49,20 @@ $mdc-radio-ripple-target: ".mdc-radio__ripple";
48
49
$feat-color : mdc-feature-create-target ($query , color );
49
50
$feat-structure : mdc-feature-create-target ($query , structure );
50
51
51
- @include mdc-radio-touch-target ($size : $mdc-radio-touch-area , $query : $query );
52
-
53
52
.mdc-radio {
54
53
@include mdc-radio-unchecked-stroke-color ($mdc-radio-unchecked-color , $query );
55
54
@include mdc-radio-checked-stroke-color ($mdc-radio-baseline-theme-color , $query );
56
55
@include mdc-radio-ink-color ($mdc-radio-baseline-theme-color , $query );
57
56
@include mdc-radio-focus-indicator-color ($mdc-radio-baseline-theme-color , $query );
57
+ @include mdc-radio-density ($mdc-radio-density-scale , $query );
58
58
59
59
@include mdc-feature-targets ($feat-structure ) {
60
60
display : inline-block ;
61
61
position : relative ;
62
62
flex : 0 0 auto ;
63
- box-sizing : border-box ;
64
- width : $mdc-radio-touch-area ;
65
- height : $mdc-radio-touch-area ;
66
- padding : ($mdc-radio-touch-area - $mdc-radio-ui-size ) / 2 ;
63
+ box-sizing : content-box ;
64
+ width : $mdc-radio-icon-size ;
65
+ height : $mdc-radio-icon-size ;
67
66
cursor : pointer ;
68
67
/* @alternate */
69
68
will-change : opacity , transform , border-color , color ;
@@ -73,20 +72,15 @@ $mdc-radio-ripple-target: ".mdc-radio__ripple";
73
72
& __background {
74
73
@include mdc-feature-targets ($feat-structure ) {
75
74
display : inline-block ;
76
- position : absolute ;
77
- left : ($mdc-radio-touch-area - $mdc-radio-ui-size ) / 2 ;
75
+ position : relative ;
78
76
box-sizing : border-box ;
79
- width : $mdc-radio-ui-pct ;
80
- height : $mdc-radio-ui-pct ;
77
+ width : $mdc-radio-icon-size ;
78
+ height : $mdc-radio-icon-size ;
81
79
}
82
80
83
81
& ::before {
84
82
@include mdc-feature-targets ($feat-structure ) {
85
83
position : absolute ;
86
- top : 0 ;
87
- left : 0 ;
88
- width : 100% ;
89
- height : 100% ;
90
84
transform : scale (0 , 0 );
91
85
border-radius : 50% ;
92
86
opacity : 0 ;
@@ -142,8 +136,6 @@ $mdc-radio-ripple-target: ".mdc-radio__ripple";
142
136
& __native-control {
143
137
@include mdc-feature-targets ($feat-structure ) {
144
138
position : absolute ;
145
- width : 100% ;
146
- height : 100% ;
147
139
margin : 0 ;
148
140
padding : 0 ;
149
141
opacity : 0 ;
@@ -154,8 +146,8 @@ $mdc-radio-ripple-target: ".mdc-radio__ripple";
154
146
155
147
& --touch {
156
148
@include mdc-touch-target-component (
157
- $component-height : $mdc-radio-touch-area ,
158
- $component-width : $mdc-radio-touch-area ,
149
+ $component-height : $mdc-radio-ripple-size ,
150
+ $component-width : $mdc-radio-ripple-size ,
159
151
$query : $query );
160
152
@include mdc-radio-touch-target ($size : $mdc-touch-target-height , $query : $query );
161
153
}
@@ -233,7 +225,7 @@ $mdc-radio-ripple-target: ".mdc-radio__ripple";
233
225
.mdc-radio__native-control :focus {
234
226
+ .mdc-radio__background ::before {
235
227
@include mdc-feature-targets ($feat-structure ) {
236
- transform : scale (2 , 2 );
228
+ transform : scale (1 );
237
229
opacity : map-get ($mdc-ripple-dark-ink-opacities , focus );
238
230
}
239
231
@@ -318,9 +310,19 @@ $mdc-radio-ripple-target: ".mdc-radio__ripple";
318
310
}
319
311
}
320
312
321
- @mixin mdc-radio-touch-target ($size : $mdc-radio-touch-area , $query : mdc-feature-all ()) {
313
+ ///
314
+ /// Sets radio touch target size which can be more than the ripple size. Param `$ripple-size` is required for custom
315
+ /// ripple size.
316
+ ///
317
+ /// @param {Number} $size Size of touch target (Native input) in `px`.
318
+ /// @param {Number} $ripple-size Size of ripple in `px`. Required only for custom ripple size.
319
+ ///
320
+ @mixin mdc-radio-touch-target (
321
+ $size : $mdc-radio-ripple-size ,
322
+ $ripple-size : $mdc-radio-ripple-size ,
323
+ $query : mdc-feature-all ()) {
322
324
$feat-structure : mdc-feature-create-target ($query , structure );
323
- $offset : ($mdc-radio-touch-area - $size ) / 2 ;
325
+ $offset : ($ripple-size - $size ) / 2 ;
324
326
325
327
.mdc-radio__native-control {
326
328
@include mdc-feature-targets ($feat-structure ) {
@@ -332,3 +334,62 @@ $mdc-radio-ripple-target: ".mdc-radio__ripple";
332
334
}
333
335
}
334
336
}
337
+
338
+ ///
339
+ /// Sets density scale for radio.
340
+ ///
341
+ /// @param {Number | String} $density-scale - Density scale value for component. Supported density scale values
342
+ /// `-3`, `-2`, `-1`, `0`.
343
+ ///
344
+ @mixin mdc-radio-density ($density-scale , $query : mdc-feature-all ()) {
345
+ $size : mdc-density-prop-value (
346
+ $density-config : $mdc-radio-density-config ,
347
+ $density-scale : $density-scale ,
348
+ $property-name : size ,
349
+ );
350
+
351
+ @include mdc-radio-ripple-size ($size , $query : $query );
352
+ // Sets touch target size same as ripple size.
353
+ @include mdc-radio-touch-target ($size : $size , $ripple-size : $size , $query : $query );
354
+
355
+ @if $density-scale != 0 {
356
+ @include mdc-radio-touch-target-reset_ ($query : $query );
357
+ }
358
+ }
359
+
360
+ ///
361
+ /// Sets radio ripple size.
362
+ ///
363
+ /// @param {Number} $size - Ripple size in `px`.
364
+ ///
365
+ @mixin mdc-radio-ripple-size ($size , $query : mdc-feature-all ()) {
366
+ $feat-structure : mdc-feature-create-target ($query , structure );
367
+ $padding : ($size - $mdc-radio-icon-size ) / 2 ;
368
+
369
+ @include mdc-feature-targets ($feat-structure ) {
370
+ padding : $padding ;
371
+ }
372
+
373
+ .mdc-radio__background ::before {
374
+ @include mdc-feature-targets ($feat-structure ) {
375
+ top : - $padding ;
376
+ left : - $padding ;
377
+ width : $size ;
378
+ height : $size ;
379
+ }
380
+ }
381
+ }
382
+
383
+ ///
384
+ /// Resets touch target-related styles. This is called from the density mixin to
385
+ /// automatically remove the increased touch target, since dense components
386
+ /// don't have the same default a11y requirements.
387
+ /// @access private
388
+ ///
389
+ @mixin mdc-radio-touch-target-reset_ ($query : mdc-feature-all ()) {
390
+ $feat-structure : mdc-feature-create-target ($query , structure );
391
+
392
+ @include mdc-feature-targets ($feat-structure ) {
393
+ margin : 0 ;
394
+ }
395
+ }
0 commit comments