_variables.scss 9.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210
  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:math';
  23. @use 'sass:color';
  24. @use '@material/density/variables' as density-variables;
  25. @use '@material/floating-label/variables' as floating-label-variables;
  26. @use '@material/notched-outline/variables' as notched-outline-variables;
  27. @use '@material/theme/custom-properties';
  28. @use '@material/theme/theme-color';
  29. ///
  30. /// Returns outlined text field floating label position for given height.
  31. ///
  32. /// @todo Instead of adjusting `$positionY` with label box height that might change based on floating label font size
  33. /// wrap label in a child element to apply `transitionY(-50%)` to automatically offset based on box height.
  34. ///
  35. @function get-outlined-label-position-y($text-field-height) {
  36. $offset: math.div(notched-outline-variables.$label-box-height, 2);
  37. // If $text-field-height is not a primitive value, but a custom property or a custom property map,
  38. // we cannot compute the label Y position at compilation time.
  39. // We will have to defer it to the browser, using calc().
  40. @if custom-properties.is-custom-prop($text-field-height) {
  41. $text-field-height: custom-properties.get-declaration-value(
  42. $text-field-height
  43. );
  44. @return calc($offset + $text-field-height / 2); // Evaluated in the browser.
  45. }
  46. @if custom-properties.is-custom-prop-string($text-field-height) {
  47. @return calc($offset + $text-field-height / 2); // Evaluated in the browser.
  48. }
  49. @return $offset + math.div($text-field-height, 2); // Evaluated statically.
  50. }
  51. $error: error !default;
  52. $disabled-border: rgba(theme-color.prop-value(on-surface), 0.06) !default;
  53. $disabled-icon: rgba(theme-color.prop-value(on-surface), 0.3) !default;
  54. $bottom-line-hover: rgba(theme-color.prop-value(on-surface), 0.87) !default;
  55. $bottom-line-idle: rgba(theme-color.prop-value(on-surface), 0.42) !default;
  56. $label: rgba(theme-color.prop-value(on-surface), 0.6) !default;
  57. $ink-color: rgba(theme-color.prop-value(on-surface), 0.87) !default;
  58. $helper-text-color: rgba(theme-color.prop-value(on-surface), 0.6) !default;
  59. $icon-color: rgba(theme-color.prop-value(on-surface), 0.54) !default;
  60. $focused-label-color: rgba(theme-color.prop-value(primary), 0.87) !default;
  61. $placeholder-ink-color: rgba(theme-color.prop-value(on-surface), 0.54) !default;
  62. $affix-color: rgba(theme-color.prop-value(on-surface), 0.6) !default;
  63. $disabled-label-color: rgba(theme-color.prop-value(on-surface), 0.38) !default;
  64. $disabled-ink-color: rgba(theme-color.prop-value(on-surface), 0.38) !default;
  65. $disabled-placeholder-ink-color: rgba(
  66. theme-color.prop-value(on-surface),
  67. 0.38
  68. ) !default;
  69. $disabled-helper-text-color: rgba(
  70. theme-color.prop-value(on-surface),
  71. 0.38
  72. ) !default;
  73. $disabled-affix-color: rgba(theme-color.prop-value(on-surface), 0.38) !default;
  74. $background: color.mix(
  75. theme-color.prop-value(on-surface),
  76. theme-color.prop-value(surface),
  77. 4%
  78. ) !default;
  79. $disabled-background: color.mix(
  80. theme-color.prop-value(on-surface),
  81. theme-color.prop-value(surface),
  82. 2%
  83. ) !default;
  84. $secondary-text: rgba(theme-color.prop-value(on-surface), 0.6) !default;
  85. $outlined-idle-border: rgba(theme-color.prop-value(on-surface), 0.38) !default;
  86. $outlined-disabled-border: rgba(
  87. theme-color.prop-value(on-surface),
  88. 0.06
  89. ) !default;
  90. $outlined-hover-border: rgba(theme-color.prop-value(on-surface), 0.87) !default;
  91. $textarea-border: rgba(theme-color.prop-value(on-surface), 0.73) !default;
  92. $textarea-background: rgba(theme-color.prop-value(surface), 1) !default;
  93. $textarea-disabled-border-color: rgba(
  94. theme-color.prop-value(on-surface),
  95. 0.26
  96. ) !default;
  97. // cannot be transparent because multiline textarea input
  98. // will make text unreadable
  99. $textarea-disabled-background: rgba(249, 249, 249, 1) !default;
  100. $ripple-target: '.mdc-text-field__ripple';
  101. $outlined-stroke-width: 2px !default;
  102. $height: 56px !default;
  103. $minimum-height: 36px !default;
  104. $minimum-height-for-filled-label: 52px !default;
  105. $maximum-height: $height !default;
  106. $padding-horizontal: 16px !default;
  107. $density-scale: density-variables.$default-scale !default;
  108. $density-config: (
  109. height: (
  110. default: $height,
  111. maximum: $maximum-height,
  112. minimum: $minimum-height,
  113. ),
  114. ) !default;
  115. $shape-radius: small !default;
  116. $label-position-y: floating-label-variables.$position-y !default;
  117. $label-offset: 16px !default;
  118. // TODO(b/154350788): Remove this variable, it's not used internally but it is
  119. // externally in Angular
  120. /// @deprecated this variable will be removed in the future.
  121. /// Use get-outlined-label-position-y($height) instead
  122. $outlined-label-position-y: get-outlined-label-position-y($height) !default;
  123. $outlined-with-leading-icon-label-position-x: 32px !default;
  124. $textarea-outlined-label-position-y: 24.75px !default; // visually ~4dp from top to baseline
  125. $textarea-filled-label-position-y: 10.25px !default; // visually ~20dp from top to label baseline
  126. $helper-line-padding: 16px !default;
  127. $filled-baseline-top: 40px !default;
  128. $input-height: 28px !default;
  129. $textarea-label-top: 19px !default; // visually ~32dp from top to label baseline
  130. $textarea-outlined-label-top: $textarea-label-top -
  131. notched-outline-variables.$border-width !default;
  132. $textarea-line-height: 1.5rem !default; // 24dp from baseline to baseline
  133. $textarea-input-handle-margin: 1px !default;
  134. // Outlined textarea's first line should be placed at the same position as
  135. // outlined textfield, and should look identical if it is 1 row. Since textfield
  136. // is centered and font metrics vary for where the baseline is, the best way to
  137. // ensure textarea and textfield align is with padding. At 56px height with a
  138. // 24px line-height, a centered textfield has 16px of top and bottom padding.
  139. // Textarea should use this to position itself.
  140. $textarea-outlined-input-margin-top: 16px !default;
  141. $textarea-outlined-input-margin-bottom: 16px !default;
  142. $textarea-outlined-density-config: (
  143. margin-top: (
  144. default: $textarea-outlined-input-margin-top,
  145. maximum: $textarea-outlined-input-margin-top,
  146. minimum: $textarea-outlined-input-margin-top - 8,
  147. ),
  148. margin-bottom: (
  149. default: $textarea-outlined-input-margin-bottom,
  150. maximum: $textarea-outlined-input-margin-bottom,
  151. minimum: $textarea-outlined-input-margin-bottom - 8,
  152. ),
  153. ) !default; // remove 1/2 of scale to -4 for minimum
  154. $textarea-outlined-label-density-config: (
  155. top: (
  156. default: $textarea-outlined-label-top,
  157. maximum: $textarea-outlined-label-top,
  158. minimum: $textarea-outlined-label-top - 8,
  159. ),
  160. ) !default; // remove 1/2 of scale to -4 for minimum
  161. $textarea-filled-input-margin-top: 23px !default; // visually ~40dp from top to baseline
  162. $textarea-filled-input-margin-bottom: 9px !default; // visually ~16dp from baseline to bottom
  163. $textarea-filled-density-config: (
  164. margin-bottom: (
  165. default: $textarea-filled-input-margin-bottom,
  166. maximum: $textarea-filled-input-margin-bottom,
  167. minimum: $textarea-filled-input-margin-bottom - 4,
  168. ),
  169. ) !default; // scale to -1 for minimum
  170. $textarea-filled-label-density-config: (
  171. top: (
  172. default: $textarea-label-top,
  173. maximum: $textarea-label-top,
  174. minimum: $textarea-label-top - 2,
  175. ),
  176. ) !default; // remove 1/2 of scale to -1 for minimm
  177. $textarea-filled-no-label-input-margin-top: 16px !default; // see above explanation for outlined textarea margin
  178. $textarea-filled-no-label-input-margin-bottom: 16px !default; // see above explanation for outlined textarea margin
  179. $textarea-filled-no-label-density-config: (
  180. margin-top: (
  181. default: $textarea-filled-no-label-input-margin-top,
  182. maximum: $textarea-filled-no-label-input-margin-top,
  183. minimum: $textarea-filled-no-label-input-margin-top - 8,
  184. ),
  185. margin-bottom: (
  186. default: $textarea-filled-no-label-input-margin-bottom,
  187. maximum: $textarea-filled-no-label-input-margin-bottom,
  188. minimum: $textarea-filled-no-label-input-margin-bottom - 8,
  189. ),
  190. ) !default; // remove 1/2 of scale to -4 for minimum
  191. $textarea-internal-counter-input-margin-bottom: 2px !default; // visually ~20dp from baseline to counter baseline
  192. $textarea-internal-counter-baseline-bottom: 16px !default;
  193. // Note that the scale factor is an eyeballed approximation of what's shown in the mocks.
  194. $prefix-padding: 2px !default;
  195. $prefix-end-aligned-padding: 12px !default;
  196. $suffix-padding: 12px !default;
  197. $suffix-end-aligned-padding: 2px !default;