_outlined-text-field-theme.scss 7.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248
  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/notched-outline/mixins' as notched-outline-mixins;
  27. @use '@material/theme/custom-properties';
  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: 'outlined-text-field';
  35. $_light-theme: (
  36. caret-color: null,
  37. container-height: null,
  38. container-shape: null,
  39. disabled-input-text-color: null,
  40. disabled-input-text-opacity: null,
  41. disabled-label-text-color: null,
  42. disabled-label-text-opacity: null,
  43. disabled-leading-icon-color: null,
  44. disabled-leading-icon-opacity: null,
  45. disabled-outline-color: null,
  46. disabled-outline-opacity: null,
  47. disabled-outline-width: null,
  48. disabled-supporting-text-color: null,
  49. disabled-supporting-text-opacity: null,
  50. disabled-trailing-icon-color: null,
  51. disabled-trailing-icon-opacity: null,
  52. error-caret-color: null,
  53. error-focus-caret-color: null,
  54. error-focus-input-text-color: null,
  55. error-focus-label-text-color: null,
  56. error-focus-leading-icon-color: null,
  57. error-focus-outline-color: null,
  58. error-focus-supporting-text-color: null,
  59. error-focus-trailing-icon-color: null,
  60. error-hover-caret-color: null,
  61. error-hover-input-text-color: null,
  62. error-hover-label-text-color: null,
  63. error-hover-leading-icon-color: null,
  64. error-hover-outline-color: null,
  65. error-hover-supporting-text-color: null,
  66. error-hover-trailing-icon-color: null,
  67. error-input-text-color: null,
  68. error-label-text-color: null,
  69. error-leading-icon-color: null,
  70. error-outline-color: null,
  71. error-supporting-text-color: null,
  72. error-trailing-icon-color: null,
  73. focus-caret-color: null,
  74. focus-input-text-color: null,
  75. focus-label-text-color: null,
  76. focus-leading-icon-color: null,
  77. focus-outline-color: null,
  78. focus-outline-width: null,
  79. focus-supporting-text-color: null,
  80. focus-trailing-icon-color: null,
  81. hover-caret-color: null,
  82. hover-input-text-color: null,
  83. hover-label-text-color: null,
  84. hover-leading-icon-color: null,
  85. hover-outline-color: null,
  86. hover-outline-width: null,
  87. hover-supporting-text-color: null,
  88. hover-trailing-icon-color: null,
  89. input-text-color: null,
  90. input-text-font: null,
  91. input-text-line-height: null,
  92. input-text-placeholder-color: null,
  93. input-text-prefix-color: null,
  94. input-text-size: null,
  95. input-text-suffix-color: null,
  96. input-text-tracking: null,
  97. input-text-type: null,
  98. input-text-weight: null,
  99. label-text-color: null,
  100. label-text-font: null,
  101. label-text-line-height: null,
  102. label-text-populated-line-height: null,
  103. label-text-populated-size: null,
  104. label-text-size: null,
  105. label-text-tracking: null,
  106. label-text-type: null,
  107. label-text-weight: null,
  108. leading-icon-color: null,
  109. leading-icon-size: null,
  110. outline-color: null,
  111. outline-width: null,
  112. supporting-text-color: null,
  113. supporting-text-font: null,
  114. supporting-text-line-height: null,
  115. supporting-text-size: null,
  116. supporting-text-tracking: null,
  117. supporting-text-type: null,
  118. supporting-text-weight: null,
  119. trailing-icon-color: null,
  120. trailing-icon-size: null,
  121. );
  122. @mixin theme($theme) {
  123. $theme: validate.theme($_light-theme, $theme);
  124. @include keys.declare-custom-properties(
  125. $theme,
  126. $prefix: $custom-property-prefix
  127. );
  128. }
  129. @mixin theme-styles($theme, $resolvers: resolvers.$material) {
  130. $theme: validate.theme-styles($_light-theme, $theme, false);
  131. $theme: keys.create-theme-properties(
  132. $theme,
  133. $prefix: $custom-property-prefix
  134. );
  135. @include text-field-theme.theme-styles($theme, $resolvers: $resolvers);
  136. &:not(.mdc-text-field--textarea) {
  137. $container-height: map.get($theme, container-height);
  138. @if $container-height {
  139. $container-height-value: if(
  140. custom-properties.is-custom-prop($container-height),
  141. custom-properties.get-declaration-value($container-height),
  142. $container-height
  143. );
  144. $keyframe-suffix: if(
  145. custom-properties.is-custom-prop($container-height),
  146. 'text-field-outlined-#{custom-properties.get-fallback($container-height)}',
  147. 'text-field-outlined-#{$container-height}'
  148. );
  149. @include mixins.outlined-height($container-height-value, $keyframe-suffix);
  150. &.mdc-text-field--with-leading-icon {
  151. $with-leading-icon-keyframe-suffix: if(
  152. custom-properties.is-custom-prop($container-height),
  153. 'text-field-outlined-with-leading-icon-#{custom-properties.get-fallback($container-height)}',
  154. 'text-field-outlined-with-leading-icon-#{$container-height}'
  155. );
  156. @include mixins.outlined-with-leading-icon-height($container-height-value, $with-leading-icon-keyframe-suffix);
  157. }
  158. }
  159. }
  160. @if map.get($theme, container-shape) {
  161. @include mixins.outline-shape-radius(map.get($theme, container-shape));
  162. }
  163. @include _outline-color(
  164. (
  165. default: map.get($theme, outline-color),
  166. hover: map.get($theme, hover-outline-color),
  167. focus: map.get($theme, focus-outline-color),
  168. disabled: map.get($theme, disabled-outline-color),
  169. )
  170. );
  171. @include _error-outline-color(
  172. (
  173. default: map.get($theme, error-outline-color),
  174. hover: map.get($theme, error-hover-outline-color),
  175. focus: map.get($theme, error-focus-outline-color),
  176. )
  177. );
  178. @include _outline-width(
  179. (
  180. default: map.get($theme, outline-width),
  181. hover: map.get($theme, hover-outline-width),
  182. focus: map.get($theme, focus-outline-width),
  183. )
  184. );
  185. }
  186. @mixin _outline-color($colors) {
  187. @include text-field-theme.if-enabled {
  188. @include _set-outline-color(map.get($colors, default));
  189. @include text-field-theme.if-hovered {
  190. .mdc-notched-outline {
  191. @include _set-outline-color(map.get($colors, hover));
  192. }
  193. }
  194. @include text-field-theme.if-focused {
  195. @include _set-outline-color(map.get($colors, focus));
  196. }
  197. }
  198. @include text-field-theme.if-disabled {
  199. @include _set-outline-color(map.get($colors, disabled));
  200. }
  201. }
  202. @mixin _set-outline-color($color) {
  203. @include notched-outline-mixins.color($color);
  204. }
  205. @mixin _error-outline-color($color) {
  206. &.mdc-text-field--invalid {
  207. @include _outline-color($color);
  208. }
  209. }
  210. @mixin _outline-width($width) {
  211. @include text-field-theme.if-enabled {
  212. @include _set-outline-width(map.get($width, default));
  213. @include text-field-theme.if-hovered {
  214. @include _set-outline-width(map.get($width, hover));
  215. }
  216. @include text-field-theme.if-focused {
  217. @include _set-outline-width(map.get($width, focus));
  218. }
  219. }
  220. }
  221. @mixin _set-outline-width($width) {
  222. .mdc-notched-outline {
  223. @include notched-outline-mixins.stroke-width($width);
  224. }
  225. }