_linear-progress.scss 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540
  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. // stylelint-disable selector-class-pattern --
  23. // Selector '.mdc-*' should only be used in this project.
  24. @use '@material/animation/functions' as animation-functions;
  25. @use '@material/dom/dom';
  26. @use '@material/feature-targeting/feature-targeting';
  27. @use '@material/rtl/rtl';
  28. @use '@material/theme/custom-properties';
  29. @use '@material/theme/theme';
  30. @use './linear-progress-theme';
  31. /// @deprecated Use static-styles() and theme-styles() instead.
  32. @mixin core-styles($query: feature-targeting.all()) {
  33. @include linear-progress-theme.bar-color(primary, $query: $query);
  34. @include linear-progress-theme.buffer-color(
  35. linear-progress-theme.$baseline-buffer-color,
  36. $query: $query
  37. );
  38. @include linear-progress-theme.bar-and-track-height(
  39. linear-progress-theme.$height,
  40. $query: $query
  41. );
  42. @include linear-progress-theme.buffering-keyframes(
  43. linear-progress-theme.$height,
  44. $query: $query
  45. );
  46. @include static-styles($query);
  47. }
  48. @mixin static-styles($query: feature-targeting.all()) {
  49. $feat-structure: feature-targeting.create-target($query, structure);
  50. $feat-animation: feature-targeting.create-target($query, animation);
  51. @include feature-targeting.targets($feat-animation) {
  52. @include primary-indeterminate-translate-keyframes_;
  53. @include primary-indeterminate-scale-keyframes_;
  54. @include secondary-indeterminate-translate-keyframes_;
  55. @include secondary-indeterminate-scale-keyframes_;
  56. @include primary-indeterminate-translate-reverse-keyframes_;
  57. @include secondary-indeterminate-translate-reverse-keyframes_;
  58. @include buffering-reverse-keyframes_;
  59. }
  60. .mdc-linear-progress {
  61. @include feature-targeting.targets($feat-structure) {
  62. position: relative;
  63. width: 100%;
  64. transform: translateZ(0);
  65. // Create a border around the bar in Windows High Contrast Mode.
  66. outline: 1px solid transparent;
  67. overflow-x: hidden;
  68. @include dom.forced-colors-mode($exclude-ie11: true) {
  69. outline-color: CanvasText;
  70. }
  71. }
  72. @include feature-targeting.targets($feat-animation) {
  73. transition: animation-functions.exit-temporary(opacity, 250ms);
  74. }
  75. &__bar {
  76. @include feature-targeting.targets($feat-structure) {
  77. position: absolute;
  78. top: 0;
  79. bottom: 0;
  80. margin: auto 0; // Vertically center
  81. width: 100%;
  82. animation: none;
  83. transform-origin: top left;
  84. }
  85. @include feature-targeting.targets($feat-animation) {
  86. transition: animation-functions.exit-temporary(transform, 250ms);
  87. }
  88. }
  89. &__bar-inner {
  90. @include feature-targeting.targets($feat-structure) {
  91. display: inline-block;
  92. position: absolute;
  93. width: 100%;
  94. animation: none;
  95. // border-top is used rather than background-color to ensure that the
  96. // bar is visible in Windows High Contrast Mode.
  97. border-top-style: solid;
  98. }
  99. }
  100. &__buffer {
  101. @include feature-targeting.targets($feat-structure) {
  102. display: flex;
  103. position: absolute;
  104. top: 0;
  105. bottom: 0;
  106. margin: auto 0; // Vertically center
  107. width: 100%;
  108. overflow: hidden;
  109. }
  110. }
  111. &__buffer-dots {
  112. @include feature-targeting.targets($feat-structure) {
  113. background-repeat: repeat-x;
  114. flex: auto;
  115. @include rtl.ignore-next-line();
  116. transform: rotate(180deg);
  117. // Use SVG mask for non-IE11 browsers
  118. // SVG is optimized for data URI (https://codepen.io/tigt/post/optimizing-svgs-in-data-uris)
  119. $svg: "data:image/svg+xml,%3Csvg version='1.1' xmlns='http://www.w3.org/2000/svg' xmlns:xlink='http://www.w3.org/1999/xlink' x='0px' y='0px' enable-background='new 0 0 5 2' xml:space='preserve' viewBox='0 0 5 2' preserveAspectRatio='xMinYMin slice'%3E%3Ccircle cx='1' cy='1' r='1'/%3E%3C/svg%3E";
  120. -webkit-mask-image: url($svg);
  121. mask-image: url($svg);
  122. }
  123. @include feature-targeting.targets($feat-animation) {
  124. // stylelint-disable-next-line no-unknown-animations --
  125. // animation is in _linear-progress-theme.scss
  126. animation: mdc-linear-progress-buffering 250ms infinite linear;
  127. }
  128. }
  129. &__buffer-bar {
  130. @include feature-targeting.targets($feat-structure) {
  131. flex: 0 1 100%;
  132. }
  133. @include feature-targeting.targets($feat-animation) {
  134. transition: animation-functions.exit-temporary(flex-basis, 250ms);
  135. }
  136. }
  137. &__primary-bar {
  138. @include feature-targeting.targets($feat-structure) {
  139. transform: scaleX(0);
  140. }
  141. }
  142. &__secondary-bar {
  143. @include feature-targeting.targets($feat-structure) {
  144. display: none;
  145. }
  146. }
  147. @include indeterminate_($query: $query);
  148. @include rtl.rtl() {
  149. // The rtl() mixin does not account for nested `dir` attributes. Set
  150. // `dir` attribute on root to take highest priority.
  151. &:not([dir='ltr']) {
  152. @include _rtl-styles($query: $query);
  153. }
  154. }
  155. &--closed {
  156. @include feature-targeting.targets($feat-structure) {
  157. opacity: 0;
  158. }
  159. }
  160. &--closed-animation-off {
  161. .mdc-linear-progress__buffer-dots {
  162. @include feature-targeting.targets($feat-animation) {
  163. animation: none;
  164. }
  165. }
  166. &.mdc-linear-progress--indeterminate {
  167. .mdc-linear-progress__bar,
  168. .mdc-linear-progress__bar .mdc-linear-progress__bar-inner {
  169. @include feature-targeting.targets($feat-animation) {
  170. animation: none;
  171. }
  172. }
  173. }
  174. }
  175. }
  176. }
  177. // Private mixins.
  178. @mixin indeterminate_($query: feature-targeting.all()) {
  179. $feat-structure: feature-targeting.create-target($query, structure);
  180. $feat-animation: feature-targeting.create-target($query, animation);
  181. &--indeterminate {
  182. .mdc-linear-progress__bar {
  183. @include feature-targeting.targets($feat-structure) {
  184. transition: none;
  185. }
  186. }
  187. .mdc-linear-progress__primary-bar {
  188. @include feature-targeting.targets($feat-structure) {
  189. left: -145.166611%;
  190. }
  191. }
  192. .mdc-linear-progress__secondary-bar {
  193. @include feature-targeting.targets($feat-structure) {
  194. left: -54.888891%;
  195. display: block;
  196. }
  197. }
  198. &.mdc-linear-progress--animation-ready {
  199. .mdc-linear-progress__primary-bar {
  200. @include feature-targeting.targets($feat-animation) {
  201. animation: mdc-linear-progress-primary-indeterminate-translate 2s
  202. infinite linear;
  203. }
  204. > .mdc-linear-progress__bar-inner {
  205. @include feature-targeting.targets($feat-animation) {
  206. animation: mdc-linear-progress-primary-indeterminate-scale 2s
  207. infinite linear;
  208. }
  209. }
  210. }
  211. .mdc-linear-progress__secondary-bar {
  212. @include feature-targeting.targets($feat-animation) {
  213. animation: mdc-linear-progress-secondary-indeterminate-translate 2s
  214. infinite linear;
  215. }
  216. > .mdc-linear-progress__bar-inner {
  217. @include feature-targeting.targets($feat-animation) {
  218. animation: mdc-linear-progress-secondary-indeterminate-scale 2s
  219. infinite linear;
  220. }
  221. }
  222. }
  223. }
  224. }
  225. }
  226. @mixin _rtl-styles($query: $query) {
  227. $feat-structure: feature-targeting.create-target($query, structure);
  228. $feat-animation: feature-targeting.create-target($query, animation);
  229. .mdc-linear-progress__bar {
  230. @include feature-targeting.targets($feat-structure) {
  231. @include rtl.ignore-next-line();
  232. right: 0;
  233. @include rtl.ignore-next-line();
  234. -webkit-transform-origin: center right;
  235. @include rtl.ignore-next-line();
  236. transform-origin: center right;
  237. }
  238. }
  239. &.mdc-linear-progress--animation-ready {
  240. .mdc-linear-progress__primary-bar {
  241. @include feature-targeting.targets($feat-animation) {
  242. animation-name: mdc-linear-progress-primary-indeterminate-translate-reverse;
  243. }
  244. }
  245. .mdc-linear-progress__secondary-bar {
  246. @include feature-targeting.targets($feat-animation) {
  247. animation-name: mdc-linear-progress-secondary-indeterminate-translate-reverse;
  248. }
  249. }
  250. }
  251. .mdc-linear-progress__buffer-dots {
  252. @include feature-targeting.targets($feat-animation) {
  253. animation: mdc-linear-progress-buffering-reverse 250ms infinite linear;
  254. }
  255. @include feature-targeting.targets($feat-structure) {
  256. @include rtl.ignore-next-line();
  257. transform: rotate(0);
  258. }
  259. }
  260. &.mdc-linear-progress--indeterminate {
  261. .mdc-linear-progress__primary-bar {
  262. @include feature-targeting.targets($feat-structure) {
  263. @include rtl.ignore-next-line();
  264. right: -145.166611%;
  265. @include rtl.ignore-next-line();
  266. left: auto;
  267. }
  268. }
  269. .mdc-linear-progress__secondary-bar {
  270. @include feature-targeting.targets($feat-structure) {
  271. @include rtl.ignore-next-line();
  272. right: -54.888891%;
  273. @include rtl.ignore-next-line();
  274. left: auto;
  275. }
  276. }
  277. }
  278. }
  279. // Keyframes.
  280. @mixin primary-indeterminate-translate-keyframes_ {
  281. @keyframes mdc-linear-progress-primary-indeterminate-translate {
  282. 0% {
  283. transform: translateX(0);
  284. }
  285. 20% {
  286. animation-timing-function: cubic-bezier(0.5, 0, 0.701732, 0.495819);
  287. transform: translateX(0);
  288. }
  289. 59.15% {
  290. animation-timing-function: cubic-bezier(
  291. 0.302435,
  292. 0.381352,
  293. 0.55,
  294. 0.956352
  295. );
  296. $primary-half: custom-properties.create(
  297. --mdc-linear-progress-primary-half,
  298. 83.67142%
  299. );
  300. @include apply-translate_($primary-half);
  301. }
  302. 100% {
  303. $primary-full: custom-properties.create(
  304. --mdc-linear-progress-primary-full,
  305. 200.611057%
  306. );
  307. @include apply-translate_($primary-full);
  308. }
  309. }
  310. }
  311. @mixin primary-indeterminate-scale-keyframes_ {
  312. @keyframes mdc-linear-progress-primary-indeterminate-scale {
  313. 0% {
  314. transform: scaleX(0.08);
  315. }
  316. 36.65% {
  317. animation-timing-function: cubic-bezier(0.334731, 0.12482, 0.785844, 1);
  318. transform: scaleX(0.08);
  319. }
  320. 69.15% {
  321. animation-timing-function: cubic-bezier(0.06, 0.11, 0.6, 1);
  322. transform: scaleX(0.661479);
  323. }
  324. 100% {
  325. transform: scaleX(0.08);
  326. }
  327. }
  328. }
  329. @mixin secondary-indeterminate-translate-keyframes_ {
  330. @keyframes mdc-linear-progress-secondary-indeterminate-translate {
  331. 0% {
  332. animation-timing-function: cubic-bezier(0.15, 0, 0.515058, 0.409685);
  333. transform: translateX(0);
  334. }
  335. 25% {
  336. animation-timing-function: cubic-bezier(0.31033, 0.284058, 0.8, 0.733712);
  337. $secondary-quarter: custom-properties.create(
  338. --mdc-linear-progress-secondary-quarter,
  339. 37.651913%
  340. );
  341. @include apply-translate_($secondary-quarter);
  342. }
  343. 48.35% {
  344. animation-timing-function: cubic-bezier(0.4, 0.627035, 0.6, 0.902026);
  345. $secondary-half: custom-properties.create(
  346. --mdc-linear-progress-secondary-half,
  347. 84.386165%
  348. );
  349. @include apply-translate_($secondary-half);
  350. }
  351. 100% {
  352. $secondary-full: custom-properties.create(
  353. --mdc-linear-progress-secondary-full,
  354. 160.277782%
  355. );
  356. @include apply-translate_($secondary-full);
  357. }
  358. }
  359. }
  360. @mixin secondary-indeterminate-scale-keyframes_ {
  361. @keyframes mdc-linear-progress-secondary-indeterminate-scale {
  362. 0% {
  363. animation-timing-function: cubic-bezier(
  364. 0.205028,
  365. 0.057051,
  366. 0.57661,
  367. 0.453971
  368. );
  369. transform: scaleX(0.08);
  370. }
  371. 19.15% {
  372. animation-timing-function: cubic-bezier(
  373. 0.152313,
  374. 0.196432,
  375. 0.648374,
  376. 1.004315
  377. );
  378. transform: scaleX(0.457104);
  379. }
  380. 44.15% {
  381. animation-timing-function: cubic-bezier(
  382. 0.257759,
  383. -0.003163,
  384. 0.211762,
  385. 1.38179
  386. );
  387. transform: scaleX(0.72796);
  388. }
  389. 100% {
  390. transform: scaleX(0.08);
  391. }
  392. }
  393. }
  394. @mixin primary-indeterminate-translate-reverse-keyframes_ {
  395. @keyframes mdc-linear-progress-primary-indeterminate-translate-reverse {
  396. 0% {
  397. transform: translateX(0);
  398. }
  399. 20% {
  400. animation-timing-function: cubic-bezier(0.5, 0, 0.701732, 0.495819);
  401. transform: translateX(0);
  402. }
  403. 59.15% {
  404. animation-timing-function: cubic-bezier(
  405. 0.302435,
  406. 0.381352,
  407. 0.55,
  408. 0.956352
  409. );
  410. $primary-half: custom-properties.create(
  411. --mdc-linear-progress-primary-half-neg,
  412. -83.67142%
  413. );
  414. @include apply-translate_($primary-half);
  415. }
  416. 100% {
  417. $primary-full: custom-properties.create(
  418. --mdc-linear-progress-primary-full-neg,
  419. -200.611057%
  420. );
  421. @include apply-translate_($primary-full);
  422. }
  423. }
  424. }
  425. @mixin secondary-indeterminate-translate-reverse-keyframes_ {
  426. @keyframes mdc-linear-progress-secondary-indeterminate-translate-reverse {
  427. 0% {
  428. animation-timing-function: cubic-bezier(0.15, 0, 0.515058, 0.409685);
  429. transform: translateX(0);
  430. }
  431. 25% {
  432. animation-timing-function: cubic-bezier(0.31033, 0.284058, 0.8, 0.733712);
  433. $secondary-quarter: custom-properties.create(
  434. --mdc-linear-progress-secondary-quarter-neg,
  435. -37.651913%
  436. );
  437. @include apply-translate_($secondary-quarter);
  438. }
  439. 48.35% {
  440. animation-timing-function: cubic-bezier(0.4, 0.627035, 0.6, 0.902026);
  441. $secondary-half: custom-properties.create(
  442. --mdc-linear-progress-secondary-half-neg,
  443. -84.386165%
  444. );
  445. @include apply-translate_($secondary-half);
  446. }
  447. 100% {
  448. $secondary-full: custom-properties.create(
  449. --mdc-linear-progress-secondary-full-neg,
  450. -160.277782%
  451. );
  452. @include apply-translate_($secondary-full);
  453. }
  454. }
  455. }
  456. @mixin buffering-reverse-keyframes_ {
  457. @keyframes mdc-linear-progress-buffering-reverse {
  458. from {
  459. @include rtl.ignore-next-line();
  460. transform: translateX(-10px);
  461. }
  462. }
  463. }
  464. @mixin apply-translate_($value) {
  465. @include theme.property(
  466. transform,
  467. translateX(value),
  468. $replace: (value: $value),
  469. $gss: (noflip: true)
  470. );
  471. }