25
25
// Internal styling for Chip MDC component.
26
26
27
27
@use ' sass:map' ;
28
+ @use ' sass:meta' ;
28
29
@use ' sass:math' ;
29
30
@use ' sass:color' ;
30
31
@use ' @material/dom/dom' ;
@@ -217,6 +218,7 @@ $_custom-property-prefix: 'chip';
217
218
218
219
@mixin theme-styles ($theme , $resolvers : resolvers .$material ) {
219
220
@include theme .validate-theme-styles ($_light-theme , $theme );
221
+ $theme : _resolve-theme ($theme , $resolvers : $resolvers );
220
222
$theme : keys .create-theme-properties (
221
223
$theme ,
222
224
$prefix : $_custom-property-prefix
@@ -230,57 +232,49 @@ $_custom-property-prefix: 'chip';
230
232
map .get ($theme , container-surface-tint-layer-color )
231
233
);
232
234
@include _container-elevation (
233
- map . get ( $resolvers , elevation ),
234
- $shadow-color : map .get ($theme , container-shadow-color ),
235
- $map : ( default : map . get ( $theme , container-elevation ) )
235
+ $map : (
236
+ default : map .get ($theme , container-elevation ),
237
+ )
236
238
);
237
239
@include _container-elevation (
238
- map . get ( $resolvers , elevation ),
239
- $shadow-color : map .get ($theme , flat-container-shadow-color ),
240
- $map : (enabled: map . get ( $theme , flat-container-elevation ) )
240
+ $map : (
241
+ enabled : map .get ($theme , flat-container-elevation ),
242
+ )
241
243
);
242
244
@include _container-elevation (
243
- map .get ($resolvers , elevation ),
244
- $shadow-color : map .get ($theme , elevated-container-shadow-color ),
245
245
$map : (
246
246
enabled: map .get ($theme , elevated-container-elevation ),
247
247
disabled : map .get ($theme , elevated-disabled-container-elevation ),
248
248
hover: map .get ($theme , elevated-hover-container-elevation ),
249
249
focus: map .get ($theme , elevated-focus-container-elevation ),
250
- pressed: map .get ($theme , elevated-pressed-container-elevation )
250
+ pressed: map .get ($theme , elevated-pressed-container-elevation ),
251
251
)
252
252
);
253
253
@include _selected-container-elevation (
254
- map .get ($resolvers , elevation ),
255
- $shadow-color : map .get ($theme , elevated-container-shadow-color ),
256
254
$map : (
257
255
enabled: map .get ($theme , elevated-selected-container-elevation ),
258
256
disabled : map .get ($theme , elevated-selected-disabled-container-elevation ),
259
257
hover: map .get ($theme , elevated-selected-hover-container-elevation ),
260
258
focus: map .get ($theme , elevated-selected-focus-container-elevation ),
261
- pressed: map .get ($theme , elevated-selected-pressed-container-elevation )
259
+ pressed: map .get ($theme , elevated-selected-pressed-container-elevation ),
262
260
)
263
261
);
264
262
@include _selected-container-elevation (
265
- map .get ($resolvers , elevation ),
266
- $shadow-color : map .get ($theme , elevated-container-shadow-color ),
267
263
$map : (
268
264
enabled: map .get ($theme , flat-selected-container-elevation ),
269
265
disabled : map .get ($theme , flat-selected-disabled-container-elevation ),
270
266
hover: map .get ($theme , flat-selected-hover-container-elevation ),
271
267
focus: map .get ($theme , flat-selected-focus-container-elevation ),
272
- pressed: map .get ($theme , flat-selected-pressed-container-elevation )
268
+ pressed: map .get ($theme , flat-selected-pressed-container-elevation ),
273
269
)
274
270
);
275
271
@include _unselected-container-elevation (
276
- map .get ($resolvers , elevation ),
277
- $shadow-color : map .get ($theme , elevated-container-shadow-color ),
278
272
$map : (
279
273
enabled: map .get ($theme , flat-unselected-container-elevation ),
280
274
disabled : map .get ($theme , flat-unselected-disabled-container-elevation ),
281
275
hover: map .get ($theme , flat-unselected-hover-container-elevation ),
282
276
focus: map .get ($theme , flat-unselected-focus-container-elevation ),
283
- pressed: map .get ($theme , flat-unselected-pressed-container-elevation )
277
+ pressed: map .get ($theme , flat-unselected-pressed-container-elevation ),
284
278
)
285
279
);
286
280
@include outline-color (
@@ -468,38 +462,52 @@ $_custom-property-prefix: 'chip';
468
462
469
463
@function _resolve-theme ($theme , $resolvers ) {
470
464
$elevation-resolver : map .get ($resolvers , elevation );
471
- $shadow-color : map .get ($theme , elevated-container-shadow-color );
472
- @if $elevation-resolver == null or $shadow-color == null {
465
+ @if $elevation-resolver == null {
473
466
@return $theme ;
474
467
}
475
468
476
- $elevation-keys : (
477
- container- elevation,
478
- elevated- container- elevation,
479
- elevated- disabled- container- elevation,
480
- elevated- focus- container- elevation,
481
- elevated- hover- container- elevation,
482
- elevated- pressed- container- elevation,
483
- elevated- selected- container- elevation,
484
- flat- container- elevation,
485
- flat- selected- focus- container- elevation,
486
- flat- selected- hover- container- elevation,
487
- flat- selected- pressed- container- elevation,
488
- flat- unselected- focus- container- elevation,
489
- flat- unselected- hover- container- elevation,
490
- flat- unselected- pressed- container- elevation
469
+ $elevation-pairs : (
470
+ container- shadow- color: (
471
+ container- elevation,
472
+ ),
473
+ flat- container- shadow- color: (
474
+ flat- container- elevation,
475
+ ),
476
+ elevated- container- shadow- color: (
477
+ elevated- container- elevation,
478
+ elevated- disabled- container- elevation,
479
+ elevated- focus- container- elevation,
480
+ elevated- hover- container- elevation,
481
+ elevated- pressed- container- elevation,
482
+ elevated- selected- container- elevation,
483
+ elevated- selected- disabled- container- elevation,
484
+ elevated- selected- focus- container- elevation,
485
+ elevated- selected- hover- container- elevation,
486
+ elevated- selected- pressed- container- elevation,
487
+ flat- selected- focus- container- elevation,
488
+ flat- selected- hover- container- elevation,
489
+ flat- selected- pressed- container- elevation,
490
+ flat- unselected- focus- container- elevation,
491
+ flat- unselected- hover- container- elevation,
492
+ flat- unselected- pressed- container- elevation,
493
+ ),
491
494
);
492
495
493
- @each $key in $elevation-keys {
494
- $elevation : map .get ($theme , $key );
495
- @if $elevation != null {
496
- $resolved-value : meta .call (
497
- $resolvers ,
498
- $elevation : $elevation ,
499
- $shadow-color : $shadow-color
500
- );
501
- // Update the key with the resolved value.
502
- $theme : map .set ($theme , $key , $resolved-value );
496
+ @each $shadow-color-key , $elevation-keys in $elevation-pairs {
497
+ $shadow-color : map .get ($theme , $shadow-color-key );
498
+ @if $shadow-color != null {
499
+ @each $key in $elevation-keys {
500
+ $elevation : map .get ($theme , $key );
501
+ @if $elevation != null {
502
+ $resolved-value : meta .call (
503
+ $elevation-resolver ,
504
+ $elevation : $elevation ,
505
+ $shadow-color : $shadow-color
506
+ );
507
+ // Update the key with the resolved value.
508
+ $theme : map .set ($theme , $key , $resolved-value );
509
+ }
510
+ }
503
511
}
504
512
}
505
513
@return $theme ;
@@ -1475,67 +1483,67 @@ $_custom-property-prefix: 'chip';
1475
1483
}
1476
1484
}
1477
1485
1478
- @mixin _container-elevation ($resolver , $shadow-color , $map ) {
1486
+ @mixin _container-elevation-theme ($theme ) {
1487
+ @if map .get ($theme , shadow ) {
1488
+ @include elevation-theme .shadow (map .get ($theme , shadow ));
1489
+ }
1490
+ @if map .get ($theme , overlay-opacity ) {
1491
+ @include elevation-theme .overlay-opacity (map .get ($theme , overlay-opacity ));
1492
+ }
1493
+ }
1494
+
1495
+ // TODO(b/259913622): Use elevation's theme-style() mixin.
1496
+ @mixin _container-elevation ($map ) {
1497
+ $default-state : state .get-default-state ($map );
1498
+ @if $default-state {
1499
+ @include _container-elevation-theme ($default-state );
1500
+ }
1501
+
1479
1502
@include _is-enabled () {
1480
- @if (state .get-enabled-state ($map )) {
1481
- @include elevation-theme .with-resolver (
1482
- $resolver ,
1483
- $elevation : state .get-enabled-state ($map ),
1484
- $shadow-color : $shadow-color
1485
- );
1503
+ $enabled-state : state .get-enabled-state ($map );
1504
+ @if $enabled-state {
1505
+ @include _container-elevation-theme ($enabled-state );
1486
1506
}
1487
1507
}
1488
1508
1489
1509
@include ripple-theme .hover () {
1490
- @if state .get-hover-state ($map ) {
1491
- @include elevation-theme .with-resolver (
1492
- $resolver ,
1493
- $elevation : state .get-hover-state ($map ),
1494
- $shadow-color : $shadow-color
1495
- );
1510
+ $hover-state : state .get-hover-state ($map );
1511
+ @if $hover-state {
1512
+ @include _container-elevation-theme ($hover-state );
1496
1513
}
1497
1514
}
1498
1515
1499
1516
@include ripple-theme .focus () {
1500
- @if (state .get-focus-state ($map )) {
1501
- @include elevation-theme .with-resolver (
1502
- $resolver ,
1503
- $elevation : state .get-focus-state ($map ),
1504
- $shadow-color : $shadow-color
1505
- );
1517
+ $focus-state : state .get-focus-state ($map );
1518
+ @if $focus-state {
1519
+ @include _container-elevation-theme ($focus-state );
1506
1520
}
1507
1521
}
1508
1522
1509
1523
@include ripple-theme .pressed () {
1510
- @if (state .get-pressed-state ($map )) {
1511
- @include elevation-theme .with-resolver (
1512
- $resolver ,
1513
- $elevation : state .get-pressed-state ($map ),
1514
- $shadow-color : $shadow-color
1515
- );
1524
+ $pressed-state : state .get-pressed-state ($map );
1525
+ @if $pressed-state {
1526
+ @include _container-elevation-theme ($pressed-state );
1516
1527
}
1517
1528
}
1518
1529
1519
1530
@include _is-disabled () {
1520
- @if (state .get-disabled-state ($map )) {
1521
- @include elevation-theme .with-resolver (
1522
- $resolver ,
1523
- $elevation : state .get-disabled-state ($map ),
1524
- $shadow-color : $shadow-color
1525
- );
1531
+ $disabled-state : state .get-disabled-state ($map );
1532
+ @if $disabled-state {
1533
+ @include _container-elevation-theme ($disabled-state );
1526
1534
}
1527
1535
}
1528
1536
}
1529
1537
1530
- @mixin _selected-container-elevation ($resolver , $shadow-color , $ map ) {
1538
+ @mixin _selected-container-elevation ($map ) {
1531
1539
@include _is-selected () {
1532
- @include _container-elevation ($resolver , $shadow-color , $ map );
1540
+ @include _container-elevation ($map );
1533
1541
}
1534
1542
}
1535
1543
1536
- @mixin _unselected-container-elevation ($resolver , $shadow-color , $ map ) {
1544
+ @mixin _unselected-container-elevation ($map ) {
1537
1545
@include _is-unselected () {
1538
- @include _container-elevation ($resolver , $shadow-color , $ map );
1546
+ @include _container-elevation ($map );
1539
1547
}
1540
1548
}
1541
1549
0 commit comments