_circular-progress-theme.scss 5.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173
  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. //
  22. // stylelint-disable selector-class-pattern --
  23. // Selector '.mdc-*' should only be used in this project.
  24. @use 'sass:map';
  25. @use 'sass:string';
  26. @use '@material/theme/color-palette';
  27. @use '@material/feature-targeting/feature-targeting';
  28. @use '@material/theme/keys';
  29. @use '@material/theme/theme';
  30. @use '@material/theme/theme-color';
  31. @use '@material/dom/dom';
  32. $color: primary !default;
  33. $track-color: transparent !default;
  34. /// The rotation position of the arcs that corresponds to their fully contracted state
  35. $base-angle: 135deg !default;
  36. /// Amount of circle the arc takes up
  37. $arc-size: 270deg !default;
  38. /// Time it takes to expand and contract arc
  39. $arc-time: 1333ms !default;
  40. /// Time for inactive indicator to disappear
  41. $shrink-time: 400ms !default;
  42. /// How much the start location of the arc should rotate each time; 216 gives
  43. /// us a 5 pointed star shape (it's 360/5 * 3)
  44. $arc-start-rotation-interval: 216deg !default;
  45. /// The timing function used for the core spinner animations.
  46. $timing-function: cubic-bezier(0.4, 0, 0.2, 1) !default;
  47. $custom-property-prefix: 'circular-progress';
  48. $light-theme: (
  49. active-indicator-color: theme-color.$primary,
  50. active-indicator-width: 4px,
  51. four-color-active-indicator-four-color: color-palette.$cyan-400,
  52. four-color-active-indicator-one-color: color-palette.$brown-400,
  53. four-color-active-indicator-three-color: color-palette.$orange-400,
  54. four-color-active-indicator-two-color: color-palette.$teal-400,
  55. size: 48px,
  56. );
  57. @mixin theme($theme) {
  58. @include theme.validate-theme($light-theme, $theme);
  59. @include keys.declare-custom-properties(
  60. $theme,
  61. $prefix: $custom-property-prefix
  62. );
  63. }
  64. @mixin theme-styles($theme) {
  65. @include theme.validate-theme-styles($light-theme, $theme);
  66. $theme: keys.create-theme-properties(
  67. $theme,
  68. $prefix: $custom-property-prefix
  69. );
  70. @include _active-indicator-color(map.get($theme, active-indicator-color));
  71. @include _active-indicator-width(map.get($theme, active-indicator-width));
  72. @include _four-color-active-indicator(
  73. (
  74. map.get($theme, four-color-active-indicator-one-color),
  75. map.get($theme, four-color-active-indicator-two-color),
  76. map.get($theme, four-color-active-indicator-three-color),
  77. map.get($theme, four-color-active-indicator-four-color)
  78. )
  79. );
  80. @include _size(map.get($theme, size));
  81. }
  82. @mixin _active-indicator-color($color) {
  83. @include color($color);
  84. }
  85. @mixin _active-indicator-width($width) {
  86. circle {
  87. @include theme.property(stroke-width, $width);
  88. }
  89. }
  90. @mixin _four-color-active-indicator($colors) {
  91. .mdc-circular-progress--four-color {
  92. @include indeterminate-colors($colors);
  93. }
  94. }
  95. @mixin _size($size) {
  96. .mdc-circular-progress {
  97. @include theme.property(width, $size, $important: true);
  98. @include theme.property(height, $size, $important: true);
  99. }
  100. }
  101. /// Customizes the stroke-color of the indicator. Applies to the
  102. /// determinate variant, and also the indeterminate variant unless the
  103. /// four-color mixin is applied.
  104. /// @param {Color} $color - The desired stroke color.
  105. /// @see {mixin} indeterminate-colors
  106. @mixin color($color, $query: feature-targeting.all()) {
  107. $feat-color: feature-targeting.create-target($query, color);
  108. .mdc-circular-progress__determinate-circle,
  109. .mdc-circular-progress__indeterminate-circle-graphic {
  110. @include feature-targeting.targets($feat-color) {
  111. @include theme.property(stroke, $color);
  112. @include dom.forced-colors-mode {
  113. @include theme.property(stroke, CanvasText);
  114. }
  115. }
  116. }
  117. }
  118. /// Customizes the track color of the indicator. Applies to the
  119. /// determinate variant only.
  120. /// @param {Color} $color - The desired track color.
  121. @mixin track-color($color, $query: feature-targeting.all()) {
  122. $feat-color: feature-targeting.create-target($query, color);
  123. .mdc-circular-progress__determinate-track {
  124. @include feature-targeting.targets($feat-color) {
  125. @include theme.property(stroke, $color);
  126. }
  127. }
  128. }
  129. /// Applies four animated stroke-colors to the indeterminate indicator.
  130. /// Applicable to the indeterminate variant only and overrides any single color
  131. /// currently set.
  132. /// @param {List} $colors - A list of four desired colors.
  133. /// @see {mixin} color
  134. @mixin indeterminate-colors($colors, $query: feature-targeting.all()) {
  135. $feat-color: feature-targeting.create-target($query, color);
  136. @if length($colors) != 4 {
  137. @error "`mdc-circular-progress-colors` accepts exactly 4 colors";
  138. }
  139. @for $i from 1 through 4 {
  140. .mdc-circular-progress__color-#{$i}
  141. .mdc-circular-progress__indeterminate-circle-graphic {
  142. @include feature-targeting.targets($feat-color) {
  143. @include theme.property(stroke, nth($colors, $i));
  144. @include dom.forced-colors-mode {
  145. @include theme.property(stroke, CanvasText);
  146. }
  147. }
  148. }
  149. }
  150. }