_filled-text-field-theme.scss 8.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277
  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. // Selector '.mdc-*' should only be used in this project.
  23. // stylelint-disable selector-class-pattern --
  24. // NOTE: this is the implementation of the aforementioned classes.
  25. @use 'sass:map';
  26. @use '@material/line-ripple/mixins' as line-ripple-mixins;
  27. @use '@material/ripple/ripple-theme';
  28. @use '@material/theme/keys';
  29. @use '@material/theme/theme';
  30. @use '@material/theme/validate';
  31. @use '@material/tokens/resolvers';
  32. @use './text-field-theme';
  33. @use './mixins';
  34. $_custom-property-prefix: 'filled-text-field';
  35. $_light-theme: (
  36. active-indicator-color: null,
  37. active-indicator-height: null,
  38. caret-color: null,
  39. container-color: null,
  40. container-height: null,
  41. container-shape: null,
  42. disabled-active-indicator-color: null,
  43. disabled-active-indicator-height: null,
  44. disabled-active-indicator-opacity: null,
  45. disabled-container-color: null,
  46. disabled-container-opacity: null,
  47. disabled-input-text-color: null,
  48. disabled-input-text-opacity: null,
  49. disabled-label-text-color: null,
  50. disabled-label-text-opacity: null,
  51. disabled-leading-icon-color: null,
  52. disabled-leading-icon-opacity: null,
  53. disabled-supporting-text-color: null,
  54. disabled-supporting-text-opacity: null,
  55. disabled-trailing-icon-color: null,
  56. disabled-trailing-icon-opacity: null,
  57. error-active-indicator-color: null,
  58. error-caret-color: null,
  59. error-focus-active-indicator-color: null,
  60. error-focus-caret-color: null,
  61. error-focus-input-text-color: null,
  62. error-focus-label-text-color: null,
  63. error-focus-leading-icon-color: null,
  64. error-focus-supporting-text-color: null,
  65. error-focus-trailing-icon-color: null,
  66. error-hover-active-indicator-color: null,
  67. error-hover-caret-color: null,
  68. error-hover-input-text-color: null,
  69. error-hover-label-text-color: null,
  70. error-hover-leading-icon-color: null,
  71. error-hover-state-layer-color: null,
  72. error-hover-state-layer-opacity: null,
  73. error-hover-supporting-text-color: null,
  74. error-hover-trailing-icon-color: null,
  75. error-input-text-color: null,
  76. error-label-text-color: null,
  77. error-leading-icon-color: null,
  78. error-supporting-text-color: null,
  79. error-trailing-icon-color: null,
  80. focus-active-indicator-color: null,
  81. focus-active-indicator-height: null,
  82. focus-caret-color: null,
  83. focus-input-text-color: null,
  84. focus-label-text-color: null,
  85. focus-leading-icon-color: null,
  86. focus-supporting-text-color: null,
  87. focus-trailing-icon-color: null,
  88. hover-active-indicator-color: null,
  89. hover-active-indicator-height: null,
  90. hover-caret-color: null,
  91. hover-input-text-color: null,
  92. hover-label-text-color: null,
  93. hover-leading-icon-color: null,
  94. hover-state-layer-color: null,
  95. hover-state-layer-opacity: null,
  96. hover-supporting-text-color: null,
  97. hover-trailing-icon-color: null,
  98. input-text-color: null,
  99. input-text-font: null,
  100. input-text-line-height: null,
  101. input-text-placeholder-color: null,
  102. input-text-prefix-color: null,
  103. input-text-size: null,
  104. input-text-suffix-color: null,
  105. input-text-tracking: null,
  106. input-text-type: null,
  107. input-text-weight: null,
  108. label-text-color: null,
  109. label-text-font: null,
  110. label-text-line-height: null,
  111. label-text-populated-line-height: null,
  112. label-text-populated-size: null,
  113. label-text-size: null,
  114. label-text-tracking: null,
  115. label-text-type: null,
  116. label-text-weight: null,
  117. leading-icon-color: null,
  118. leading-icon-size: null,
  119. supporting-text-color: null,
  120. supporting-text-font: null,
  121. supporting-text-line-height: null,
  122. supporting-text-size: null,
  123. supporting-text-tracking: null,
  124. supporting-text-weight: null,
  125. trailing-icon-color: null,
  126. trailing-icon-size: null,
  127. );
  128. @mixin theme($theme) {
  129. $theme: validate.theme($_light-theme, $theme);
  130. @include keys.declare-custom-properties(
  131. $theme,
  132. $prefix: $_custom-property-prefix
  133. );
  134. }
  135. @mixin theme-styles($theme, $resolvers: resolvers.$material) {
  136. $theme: validate.theme-styles($_light-theme, $theme, false);
  137. $theme: keys.create-theme-properties(
  138. $theme,
  139. $prefix: $_custom-property-prefix
  140. );
  141. @include text-field-theme.theme-styles($theme, $resolvers: $resolvers);
  142. &:not(.mdc-text-field--textarea) {
  143. @if map.get($theme, container-height) {
  144. @include mixins.height(map.get($theme, container-height));
  145. }
  146. }
  147. @if map.get($theme, container-shape) {
  148. @include mixins.shape-radius(map.get($theme, container-shape));
  149. }
  150. @include _container-color(
  151. (
  152. default: map.get($theme, container-color),
  153. disabled: map.get($theme, disabled-container-color),
  154. )
  155. );
  156. @include _active-indicator-color(
  157. (
  158. default: map.get($theme, active-indicator-color),
  159. hover: map.get($theme, hover-active-indicator-color),
  160. focus: map.get($theme, focus-active-indicator-color),
  161. disabled: map.get($theme, disabled-active-indicator-color),
  162. )
  163. );
  164. @include _error-active-indicator-color(
  165. (
  166. default: map.get($theme, error-active-indicator-color),
  167. hover: map.get($theme, error-hover-active-indicator-color),
  168. focus: map.get($theme, error-focus-active-indicator-color),
  169. )
  170. );
  171. @include _active-indicator-height(map.get($theme, active-indicator-height));
  172. @include _focus-active-indicator-height(
  173. map.get($theme, focus-active-indicator-height)
  174. );
  175. @include _hover-state-layer(
  176. (
  177. error-hover-state-layer-color:
  178. map.get($theme, error-hover-state-layer-color),
  179. error-hover-state-layer-opacity:
  180. map.get($theme, error-hover-state-layer-opacity),
  181. hover-state-layer-color: map.get($theme, hover-state-layer-color),
  182. hover-state-layer-opacity: map.get($theme, hover-state-layer-opacity),
  183. )
  184. );
  185. }
  186. @mixin _container-color($colors) {
  187. @include text-field-theme.if-enabled {
  188. @include _set-container-color(map.get($colors, default));
  189. }
  190. @include text-field-theme.if-disabled {
  191. @include _set-container-color(map.get($colors, disabled));
  192. }
  193. }
  194. @mixin _set-container-color($color) {
  195. @include theme.property(background-color, $color);
  196. }
  197. @mixin _active-indicator-color($colors) {
  198. @include text-field-theme.if-enabled {
  199. @include _set-active-indicator-color(map.get($colors, default));
  200. @include text-field-theme.if-hovered {
  201. @include _set-active-indicator-color(map.get($colors, hover));
  202. }
  203. @include _focused-line-ripple-color(map.get($colors, focus));
  204. }
  205. @include text-field-theme.if-disabled {
  206. @include _set-active-indicator-color(map.get($colors, disabled));
  207. }
  208. }
  209. @mixin _set-active-indicator-color($color) {
  210. .mdc-line-ripple {
  211. @include line-ripple-mixins.inactive-color($color);
  212. }
  213. }
  214. @mixin _focused-line-ripple-color($color) {
  215. .mdc-line-ripple {
  216. @include line-ripple-mixins.active-color($color);
  217. }
  218. }
  219. @mixin _error-active-indicator-color($colors) {
  220. &.mdc-text-field--invalid {
  221. @include _active-indicator-color($colors);
  222. }
  223. }
  224. @mixin _active-indicator-height($height) {
  225. .mdc-line-ripple {
  226. @include line-ripple-mixins.height($height);
  227. }
  228. }
  229. @mixin _focus-active-indicator-height($height) {
  230. .mdc-line-ripple {
  231. @include line-ripple-mixins.active-height($height);
  232. }
  233. }
  234. @mixin _hover-state-layer($colors) {
  235. @include ripple-theme.theme-styles(
  236. (
  237. hover-state-layer-color: map.get($colors, hover-state-layer-color),
  238. hover-state-layer-opacity: map.get($colors, hover-state-layer-opacity),
  239. ),
  240. $ripple-target: '.mdc-text-field__ripple'
  241. );
  242. &.mdc-text-field--invalid {
  243. @include ripple-theme.theme-styles(
  244. (
  245. hover-state-layer-color: map.get($colors, error-hover-state-layer-color),
  246. hover-state-layer-opacity:
  247. map.get($colors, error-hover-state-layer-opacity),
  248. ),
  249. $ripple-target: '.mdc-text-field__ripple'
  250. );
  251. }
  252. }