_card-shared-theme.scss 4.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //
  2. // Copyright 2022 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. // stylelint-disable selector-class-pattern --
  22. // Selector '.mdc-*' should only be used in this project.
  23. @use './mixins' as card;
  24. @use '@material/elevation/elevation-theme';
  25. @use '@material/ripple/ripple-theme';
  26. @use '@material/theme/state';
  27. @use 'sass:map';
  28. $ripple-target: '.mdc-card__ripple';
  29. @mixin theme($theme, $resolver) {
  30. @include card.shape-radius(map.get($theme, container-shape));
  31. @include card.fill-color(map.get($theme, container-color));
  32. .mdc-card {
  33. &::after {
  34. // Adjust shape-radius for transparent card border for high-contrast mode;
  35. @include card.shape-radius(map.get($theme, container-shape));
  36. }
  37. }
  38. @include elevation-theme.overlay-container-color(
  39. map.get($theme, container-surface-tint-layer-color)
  40. );
  41. @include _container-elevation(
  42. $resolver,
  43. $shadow-color: map.get($theme, container-shadow-color),
  44. $map: (
  45. default: map.get($theme, container-elevation),
  46. hover: map.get($theme, hover-container-elevation),
  47. focus: map.get($theme, focus-container-elevation),
  48. pressed: map.get($theme, pressed-container-elevation)
  49. )
  50. );
  51. .mdc-card__primary-action {
  52. // States styles
  53. // TODO(b/191298796): Unique state layer colors for each interactive state is not supported. Ripple mixin currently only uses the hover state layer color and ignores focus and pressed colors.
  54. @include ripple-theme.theme-styles(
  55. (
  56. focus-state-layer-color: map.get($theme, focus-state-layer-color),
  57. focus-state-layer-opacity: map.get($theme, focus-state-layer-opacity),
  58. hover-state-layer-color: map.get($theme, hover-state-layer-color),
  59. hover-state-layer-opacity: map.get($theme, hover-state-layer-opacity),
  60. pressed-state-layer-color: map.get($theme, pressed-state-layer-color),
  61. pressed-state-layer-opacity:
  62. map.get($theme, pressed-state-layer-opacity),
  63. ),
  64. $ripple-target: $ripple-target
  65. );
  66. }
  67. }
  68. @mixin _container-elevation($resolver, $shadow-color, $map) {
  69. $elevation-resolver: map.get($resolver, elevation);
  70. .mdc-card {
  71. @if state.get-default-state($map) {
  72. @include elevation-theme.with-resolver(
  73. $elevation-resolver,
  74. $elevation: state.get-default-state($map),
  75. $shadow-color: $shadow-color
  76. );
  77. }
  78. @include ripple-theme.hover() {
  79. @if state.get-hover-state($map) {
  80. @include elevation-theme.with-resolver(
  81. $elevation-resolver,
  82. $elevation: state.get-hover-state($map),
  83. $shadow-color: $shadow-color
  84. );
  85. }
  86. }
  87. @include ripple-theme.focus() {
  88. @if state.get-focus-state($map) {
  89. @include elevation-theme.with-resolver(
  90. $elevation-resolver,
  91. $elevation: state.get-focus-state($map),
  92. $shadow-color: $shadow-color
  93. );
  94. }
  95. }
  96. @include ripple-theme.pressed() {
  97. @if state.get-pressed-state($map) {
  98. @include elevation-theme.with-resolver(
  99. $elevation-resolver,
  100. $elevation: state.get-pressed-state($map),
  101. $shadow-color: $shadow-color
  102. );
  103. }
  104. }
  105. }
  106. }