_mixins.scss 3.4 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788
  1. //
  2. // Copyright 2017 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. //
  22. @use "sass:map";
  23. @use "@material/feature-targeting/functions" as feature-targeting-functions;
  24. @use "@material/feature-targeting/mixins";
  25. @use "./variables";
  26. @use "./functions";
  27. @mixin core-styles($query: feature-targeting-functions.all()) {
  28. $feat-color: feature-targeting-functions.create-target($query, color);
  29. :root {
  30. @include mixins.targets($feat-color) {
  31. @each $style in map.keys(variables.$property-values) {
  32. --mdc-theme-#{$style}: #{map.get(variables.$property-values, $style)};
  33. }
  34. }
  35. }
  36. @each $style in map.keys(variables.$property-values) {
  37. @if $style != "background" and $style != "surface" {
  38. .mdc-theme--#{$style} {
  39. @include mixins.targets($feat-color) {
  40. @include prop(color, $style, true);
  41. }
  42. }
  43. } @else {
  44. .mdc-theme--#{$style} {
  45. @include mixins.targets($feat-color) {
  46. @include prop(background-color, $style);
  47. }
  48. }
  49. }
  50. }
  51. // CSS rules for using primary and secondary (plus light/dark variants) as background colors.
  52. @each $style in ("primary", "secondary") {
  53. .mdc-theme--#{$style}-bg {
  54. @include mixins.targets($feat-color) {
  55. @include prop(background-color, $style, true);
  56. }
  57. }
  58. }
  59. }
  60. // Applies the correct theme color style to the specified property.
  61. // $property is typically color or background-color, but can be any CSS property that accepts color values.
  62. // $style should be one of the map keys in $mdc-theme-property-values (_variables.scss), or a color value.
  63. @mixin prop($property, $style, $important: false) {
  64. $important-rule: if($important, "!important", "");
  65. @if functions.is-var-with-fallback_($style) {
  66. #{$property}: functions.get-var-fallback_($style) #{$important-rule};
  67. /* @alternate */
  68. #{$property}: functions.var_($style) #{$important-rule};
  69. } @else if variables.is-valid-theme-prop-value_($style) {
  70. #{$property}: $style #{$important-rule};
  71. } @else {
  72. @if not map.has-key(variables.$property-values, $style) {
  73. @error "Invalid style: '#{$style}'. Choose one of: #{map.keys(variables.$property-values)}";
  74. }
  75. $value: map.get(variables.$property-values, $style);
  76. #{$property}: $value #{$important-rule};
  77. /* @alternate */
  78. #{$property}: var(--mdc-theme-#{$style}, $value) #{$important-rule};
  79. }
  80. }