_floating-label-theme.scss 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200
  1. //
  2. // Copyright 2018 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:meta';
  25. @use '@material/animation/variables' as animation-variables;
  26. @use '@material/feature-targeting/feature-targeting';
  27. @use '@material/rtl/rtl';
  28. @use '@material/theme/theme';
  29. @use '@material/theme/theme-color';
  30. @use '@material/typography/typography';
  31. ///
  32. /// Y-axis position of label when it is afloat.
  33. /// 100% of the length of label and additional 6% for scaledown.
  34. ///
  35. $position-y: 106% !default;
  36. $transition-duration: 150ms !default;
  37. $float-scale: 0.75 !default;
  38. @mixin theme-styles($query: feature-targeting.all()) {
  39. $feat-structure: feature-targeting.create-target($query, structure);
  40. $feat-animation: feature-targeting.create-target($query, animation);
  41. // postcss-bem-linter: define floating-label
  42. .mdc-floating-label {
  43. @include typography.typography(
  44. subtitle1,
  45. $exclude-props: (line-height),
  46. $query: $query
  47. );
  48. @include feature-targeting.targets($feat-animation) {
  49. transition: transform $transition-duration
  50. animation-variables.$standard-curve-timing-function,
  51. color $transition-duration
  52. animation-variables.$standard-curve-timing-function;
  53. }
  54. }
  55. @at-root {
  56. @include float-position($position-y, $query: $query);
  57. @include shake-animation(standard, $query: $query);
  58. }
  59. @include shake-keyframes(standard, $position-y, $query: $query);
  60. }
  61. @mixin ink-color($color, $query: feature-targeting.all()) {
  62. $feat-color: feature-targeting.create-target($query, color);
  63. @include feature-targeting.targets($feat-color) {
  64. @include theme.property(color, $color);
  65. }
  66. }
  67. // Used for textarea in case of scrolling
  68. @mixin fill-color($color, $query: feature-targeting.all()) {
  69. $feat-color: feature-targeting.create-target($query, color);
  70. @include feature-targeting.targets($feat-color) {
  71. @include theme.property(background-color, $color);
  72. }
  73. }
  74. @mixin shake-keyframes(
  75. $modifier,
  76. $positionY,
  77. $positionX: 0%,
  78. $scale: $float-scale,
  79. $query: feature-targeting.all()
  80. ) {
  81. $feat-animation: feature-targeting.create-target($query, animation);
  82. @include feature-targeting.targets($feat-animation) {
  83. @keyframes mdc-floating-label-shake-float-above-#{$modifier} {
  84. 0% {
  85. @include rtl.ignore-next-line();
  86. transform: translateX(calc(0% - #{$positionX}))
  87. translateY(calc(0% - #{$positionY})) scale(#{$scale});
  88. }
  89. 33% {
  90. animation-timing-function: cubic-bezier(0.5, 0, 0.701732, 0.495819);
  91. @include rtl.ignore-next-line();
  92. transform: translateX(calc(4% - #{$positionX}))
  93. translateY(calc(0% - #{$positionY})) scale(#{$scale});
  94. }
  95. 66% {
  96. animation-timing-function: cubic-bezier(
  97. 0.302435,
  98. 0.381352,
  99. 0.55,
  100. 0.956352
  101. );
  102. @include rtl.ignore-next-line();
  103. transform: translateX(calc(-4% - #{$positionX}))
  104. translateY(calc(0% - #{$positionY})) scale(#{$scale});
  105. }
  106. 100% {
  107. @include rtl.ignore-next-line();
  108. transform: translateX(calc(0% - #{$positionX}))
  109. translateY(calc(0% - #{$positionY})) scale(#{$scale});
  110. }
  111. }
  112. }
  113. }
  114. @mixin float-position(
  115. $positionY,
  116. $positionX: 0%,
  117. $scale: $float-scale,
  118. $query: feature-targeting.all()
  119. ) {
  120. $feat-structure: feature-targeting.create-target($query, structure);
  121. $translateY: if(
  122. meta.type-of($positionY) == 'calculation',
  123. calc(-1 * $positionY),
  124. -1 * $positionY
  125. );
  126. .mdc-floating-label--float-above {
  127. @include feature-targeting.targets($feat-structure) {
  128. @if $positionX > 0 or $positionX < 0 {
  129. @include rtl.ignore-next-line();
  130. transform: translateY($translateY)
  131. translateX(-1 * $positionX)
  132. scale($scale);
  133. @include rtl.rtl {
  134. @include rtl.ignore-next-line();
  135. transform: translateY($translateY) translateX($positionX)
  136. scale($scale);
  137. }
  138. } @else {
  139. transform: translateY($translateY) scale($scale);
  140. }
  141. }
  142. }
  143. }
  144. @mixin shake-animation($modifier, $query: feature-targeting.all()) {
  145. $feat-animation: feature-targeting.create-target($query, animation);
  146. .mdc-floating-label--shake {
  147. @include feature-targeting.targets($feat-animation) {
  148. animation: mdc-floating-label-shake-float-above-#{$modifier} 250ms 1;
  149. }
  150. }
  151. }
  152. @mixin max-width($max-width, $query: feature-targeting.all()) {
  153. $feat-structure: feature-targeting.create-target($query, structure);
  154. @include feature-targeting.targets($feat-structure) {
  155. max-width: $max-width;
  156. }
  157. }
  158. ///
  159. /// Sets the CSS transition for the floating animation.
  160. ///
  161. /// @param {Number} $duration-ms - Duration (in ms) of the animation.
  162. /// @param {String} $timing-function - Optionally overrides the default animation timing function.
  163. ///
  164. @mixin float-transition(
  165. $duration-ms,
  166. $timing-function: animation-variables.$standard-curve-timing-function,
  167. $query: feature-targeting.all()
  168. ) {
  169. $feat-animation: feature-targeting.create-target($query, animation);
  170. @include feature-targeting.targets($feat-animation) {
  171. transition: color $duration-ms $timing-function,
  172. transform $duration-ms $timing-function;
  173. }
  174. }