_circular-progress.scss 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428
  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:math';
  25. @use '@material/animation/functions' as animation-functions;
  26. @use '@material/feature-targeting/feature-targeting';
  27. @use '@material/rtl/rtl';
  28. @use '@material/theme/gss';
  29. @use '@material/theme/theme';
  30. @use './circular-progress-theme';
  31. ///
  32. /// Circular progress core styles.
  33. ///
  34. @mixin core-styles($query: feature-targeting.all()) {
  35. @include circular-progress-theme.color(
  36. circular-progress-theme.$color,
  37. $query
  38. );
  39. @include circular-progress-theme.track-color(
  40. circular-progress-theme.$track-color,
  41. $query: $query
  42. );
  43. @include static-styles($query);
  44. }
  45. @mixin static-styles($query: feature-targeting.all()) {
  46. $feat-structure: feature-targeting.create-target($query, structure);
  47. $feat-animation: feature-targeting.create-target($query, animation);
  48. @include feature-targeting.targets($feat-animation) {
  49. @include container-rotate-keyframes_;
  50. @include spinner-layer-rotate-keyframes_;
  51. @include color-1-fade-in-out-keyframes_;
  52. @include color-2-fade-in-out-keyframes_;
  53. @include color-3-fade-in-out-keyframes_;
  54. @include color-4-fade-in-out-keyframes_;
  55. @include left-spin-keyframes_;
  56. @include right-spin-keyframes_;
  57. }
  58. .mdc-circular-progress {
  59. @include feature-targeting.targets($feat-structure) {
  60. display: inline-flex;
  61. position: relative;
  62. @include rtl.ignore-next-line();
  63. direction: ltr;
  64. line-height: 0;
  65. }
  66. @include feature-targeting.targets($feat-animation) {
  67. transition: animation-functions.exit-temporary(opacity, 250ms);
  68. }
  69. }
  70. .mdc-circular-progress__determinate-container,
  71. .mdc-circular-progress__indeterminate-circle-graphic,
  72. .mdc-circular-progress__indeterminate-container,
  73. .mdc-circular-progress__spinner-layer {
  74. @include feature-targeting.targets($feat-structure) {
  75. position: absolute;
  76. width: 100%;
  77. height: 100%;
  78. }
  79. }
  80. .mdc-circular-progress__determinate-container {
  81. @include feature-targeting.targets($feat-structure) {
  82. @include rtl.ignore-next-line();
  83. transform: rotate(-90deg);
  84. }
  85. }
  86. .mdc-circular-progress__indeterminate-container {
  87. @include feature-targeting.targets($feat-structure) {
  88. // Font size, letter spacing and nowrap are required in order to ignore
  89. // whitespaces between HTML elements.
  90. font-size: 0;
  91. letter-spacing: 0;
  92. white-space: nowrap;
  93. opacity: 0;
  94. }
  95. }
  96. .mdc-circular-progress__determinate-circle-graphic,
  97. .mdc-circular-progress__indeterminate-circle-graphic {
  98. @include feature-targeting.targets($feat-structure) {
  99. fill: transparent;
  100. }
  101. }
  102. .mdc-circular-progress__determinate-circle {
  103. @include feature-targeting.targets($feat-animation) {
  104. transition: animation-functions.enter(stroke-dashoffset, 500ms);
  105. }
  106. }
  107. .mdc-circular-progress__gap-patch {
  108. @include feature-targeting.targets($feat-structure) {
  109. position: absolute;
  110. top: 0;
  111. @include rtl.ignore-next-line();
  112. left: 47.5%;
  113. box-sizing: border-box;
  114. width: 5%;
  115. height: 100%;
  116. overflow: hidden;
  117. }
  118. .mdc-circular-progress__indeterminate-circle-graphic {
  119. @include feature-targeting.targets($feat-structure) {
  120. @include rtl.ignore-next-line();
  121. left: -900%;
  122. width: 2000%;
  123. @include rtl.ignore-next-line();
  124. transform: rotate(180deg);
  125. }
  126. }
  127. }
  128. .mdc-circular-progress__circle-clipper {
  129. @include feature-targeting.targets($feat-structure) {
  130. display: inline-flex;
  131. position: relative;
  132. width: 50%;
  133. height: 100%;
  134. overflow: hidden;
  135. }
  136. .mdc-circular-progress__indeterminate-circle-graphic {
  137. @include feature-targeting.targets($feat-structure) {
  138. width: 200%;
  139. }
  140. }
  141. }
  142. .mdc-circular-progress__circle-right {
  143. .mdc-circular-progress__indeterminate-circle-graphic {
  144. @include feature-targeting.targets($feat-structure) {
  145. @include rtl.ignore-next-line();
  146. left: -100%;
  147. }
  148. }
  149. }
  150. .mdc-circular-progress--indeterminate {
  151. .mdc-circular-progress__determinate-container {
  152. @include feature-targeting.targets($feat-structure) {
  153. opacity: 0;
  154. }
  155. }
  156. .mdc-circular-progress__indeterminate-container {
  157. @include feature-targeting.targets($feat-structure) {
  158. opacity: 1;
  159. }
  160. }
  161. @include indeterminate-active-animations_($query);
  162. }
  163. .mdc-circular-progress--closed {
  164. @include feature-targeting.targets($feat-structure) {
  165. opacity: 0;
  166. }
  167. }
  168. }
  169. // Private mixins
  170. /// Sets the animations for the indicator in indeterminate mode.
  171. /// @access private
  172. @mixin indeterminate-active-animations_($query: feature-targeting.all()) {
  173. $feat-animation: feature-targeting.create-target($query, animation);
  174. .mdc-circular-progress__indeterminate-container {
  175. @include feature-targeting.targets($feat-animation) {
  176. $duration: math.div(
  177. 360deg * circular-progress-theme.$arc-time,
  178. circular-progress-theme.$arc-start-rotation-interval +
  179. (360 - circular-progress-theme.$arc-size)
  180. );
  181. animation: mdc-circular-progress-container-rotate $duration linear
  182. infinite;
  183. }
  184. }
  185. $spinner-rotate-animation: mdc-circular-progress-spinner-layer-rotate 4 *
  186. circular-progress-theme.$arc-time circular-progress-theme.$timing-function
  187. infinite both;
  188. .mdc-circular-progress__spinner-layer {
  189. @include feature-targeting.targets($feat-animation) {
  190. animation: $spinner-rotate-animation;
  191. }
  192. }
  193. @for $i from 1 through 4 {
  194. $color-fade-in-out-animation: mdc-circular-progress-color-#{$i}-fade-in-out
  195. 4 *
  196. circular-progress-theme.$arc-time
  197. circular-progress-theme.$timing-function
  198. infinite
  199. both;
  200. .mdc-circular-progress__color-#{$i} {
  201. @include feature-targeting.targets($feat-animation) {
  202. animation: $spinner-rotate-animation, $color-fade-in-out-animation;
  203. }
  204. }
  205. }
  206. .mdc-circular-progress__circle-left
  207. .mdc-circular-progress__indeterminate-circle-graphic {
  208. @include feature-targeting.targets($feat-animation) {
  209. @include gss.annotate(
  210. (
  211. noflip: true,
  212. )
  213. );
  214. animation: mdc-circular-progress-left-spin
  215. circular-progress-theme.$arc-time
  216. circular-progress-theme.$timing-function infinite both;
  217. }
  218. }
  219. .mdc-circular-progress__circle-right
  220. .mdc-circular-progress__indeterminate-circle-graphic {
  221. @include feature-targeting.targets($feat-animation) {
  222. @include gss.annotate(
  223. (
  224. noflip: true,
  225. )
  226. );
  227. animation: mdc-circular-progress-right-spin
  228. circular-progress-theme.$arc-time
  229. circular-progress-theme.$timing-function infinite both;
  230. }
  231. }
  232. }
  233. /// Keyframes for the persistent rotation of the outermost container
  234. /// @access private
  235. @mixin container-rotate-keyframes_ {
  236. @keyframes mdc-circular-progress-container-rotate {
  237. to {
  238. @include rtl.ignore-next-line();
  239. transform: rotate(360deg);
  240. }
  241. }
  242. }
  243. /// Keyframes for the rotation of the spinner layer
  244. /// @access private
  245. @mixin spinner-layer-rotate-keyframes_ {
  246. @keyframes mdc-circular-progress-spinner-layer-rotate {
  247. @for $i from 1 through 8 {
  248. #{$i * 12.5}% {
  249. @include rtl.ignore-next-line();
  250. transform: rotate($i * 0.5 * circular-progress-theme.$arc-size);
  251. }
  252. }
  253. }
  254. }
  255. /// Keyframes for the fade-in and fade-out of the first color.
  256. /// .99 opacity is used to force subpixel rendering.
  257. /// @access private
  258. @mixin color-1-fade-in-out-keyframes_ {
  259. @keyframes mdc-circular-progress-color-1-fade-in-out {
  260. from {
  261. opacity: 0.99;
  262. }
  263. 25% {
  264. opacity: 0.99;
  265. }
  266. 26% {
  267. opacity: 0;
  268. }
  269. 89% {
  270. opacity: 0;
  271. }
  272. 90% {
  273. opacity: 0.99;
  274. }
  275. to {
  276. opacity: 0.99;
  277. }
  278. }
  279. }
  280. /// Keyframes for the fade-in and fade-out of the second color.
  281. /// .99 opacity is used to force subpixel rendering.
  282. /// @access private
  283. @mixin color-2-fade-in-out-keyframes_ {
  284. @keyframes mdc-circular-progress-color-2-fade-in-out {
  285. from {
  286. opacity: 0;
  287. }
  288. 15% {
  289. opacity: 0;
  290. }
  291. 25% {
  292. opacity: 0.99;
  293. }
  294. 50% {
  295. opacity: 0.99;
  296. }
  297. 51% {
  298. opacity: 0;
  299. }
  300. to {
  301. opacity: 0;
  302. }
  303. }
  304. }
  305. /// Keyframes for the fade-in and fade-out of the third color.
  306. /// .99 opacity is used to force subpixel rendering.
  307. /// @access private
  308. @mixin color-3-fade-in-out-keyframes_ {
  309. @keyframes mdc-circular-progress-color-3-fade-in-out {
  310. from {
  311. opacity: 0;
  312. }
  313. 40% {
  314. opacity: 0;
  315. }
  316. 50% {
  317. opacity: 0.99;
  318. }
  319. 75% {
  320. opacity: 0.99;
  321. }
  322. 76% {
  323. opacity: 0;
  324. }
  325. to {
  326. opacity: 0;
  327. }
  328. }
  329. }
  330. /// Keyframes for the fade-in and fade-out of the fourth color.
  331. /// .99 opacity is used to force subpixel rendering.
  332. /// @access private
  333. @mixin color-4-fade-in-out-keyframes_ {
  334. @keyframes mdc-circular-progress-color-4-fade-in-out {
  335. from {
  336. opacity: 0;
  337. }
  338. 65% {
  339. opacity: 0;
  340. }
  341. 75% {
  342. opacity: 0.99;
  343. }
  344. 90% {
  345. opacity: 0.99;
  346. }
  347. to {
  348. opacity: 0;
  349. }
  350. }
  351. }
  352. /// Keyframes for the expansion and contraction of the arc for the
  353. /// left semi-circle.
  354. /// @access private
  355. @mixin left-spin-keyframes_ {
  356. @keyframes mdc-circular-progress-left-spin {
  357. from {
  358. @include rtl.ignore-next-line();
  359. transform: rotate(265deg);
  360. }
  361. 50% {
  362. @include rtl.ignore-next-line();
  363. transform: rotate(130deg);
  364. }
  365. to {
  366. @include rtl.ignore-next-line();
  367. transform: rotate(265deg);
  368. }
  369. }
  370. }
  371. /// Keyframes for the expansion and contraction of the arc for the
  372. /// right semi-circle.
  373. /// @access private
  374. @mixin right-spin-keyframes_ {
  375. @keyframes mdc-circular-progress-right-spin {
  376. from {
  377. @include rtl.ignore-next-line();
  378. transform: rotate(-265deg);
  379. }
  380. 50% {
  381. @include rtl.ignore-next-line();
  382. transform: rotate(-130deg);
  383. }
  384. to {
  385. @include rtl.ignore-next-line();
  386. transform: rotate(-265deg);
  387. }
  388. }
  389. }