_dialog-theme.scss 9.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271
  1. //
  2. // Copyright 2021 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. // Internal styling for Dialog MDC component-
  25. @use 'sass:map';
  26. @use 'sass:meta';
  27. @use '@material/elevation/elevation-theme';
  28. @use '@material/shape/shape';
  29. @use '@material/theme/keys';
  30. @use '@material/theme/theme';
  31. @use '@material/tokens/resolvers';
  32. @use '@material/button/button-text-theme';
  33. $light-theme: (
  34. container-color: null,
  35. container-elevation: null,
  36. container-shadow-color: null,
  37. container-shape: null,
  38. with-divider-divider-color: null,
  39. with-divider-divider-height: null,
  40. with-icon-icon-size: null,
  41. with-icon-icon-color: null,
  42. subhead-font: null,
  43. subhead-line-height: null,
  44. subhead-size: null,
  45. subhead-weight: null,
  46. subhead-tracking: null,
  47. subhead-color: null,
  48. supporting-text-font: null,
  49. supporting-text-line-height: null,
  50. supporting-text-size: null,
  51. supporting-text-weight: null,
  52. supporting-text-tracking: null,
  53. supporting-text-color: null,
  54. action-label-text-font: null,
  55. action-label-text-line-height: null,
  56. action-label-text-size: null,
  57. action-label-text-weight: null,
  58. action-label-text-tracking: null,
  59. action-label-text-color: null,
  60. action-hover-state-layer-color: null,
  61. action-hover-state-layer-opacity: null,
  62. action-hover-label-text-color: null,
  63. action-focus-state-layer-color: null,
  64. action-focus-state-layer-opacity: null,
  65. action-focus-label-text-color: null,
  66. action-pressed-state-layer-color: null,
  67. action-pressed-state-layer-opacity: null,
  68. action-pressed-label-text-color: null,
  69. // TODO(b/229523517): add headline token support to dialog
  70. headline-color: null,
  71. headline-font: null,
  72. headline-line-height: null,
  73. headline-size: null,
  74. headline-tracking: null,
  75. headline-weight: null,
  76. z-index: null,
  77. );
  78. $custom-property-prefix: 'dialog';
  79. @mixin theme($theme, $resolvers: resolvers.$material) {
  80. // TODO(b/251881053): Replace with `validate-theme`.
  81. @include theme.validate-theme-styles($light-theme, $theme);
  82. $theme: _resolve-elevation($theme, map.get($resolvers, elevation));
  83. @include keys.declare-custom-properties(
  84. $theme,
  85. $prefix: $custom-property-prefix
  86. );
  87. }
  88. @mixin theme-styles($theme, $resolvers: resolvers.$material) {
  89. @include theme.validate-theme-styles($light-theme, $theme);
  90. $theme: keys.create-theme-properties(
  91. $theme,
  92. $prefix: $custom-property-prefix
  93. );
  94. @include _container-color(map.get($theme, container-color));
  95. @include _container-elevation(
  96. map.get($resolvers, elevation),
  97. map.get($theme, container-elevation),
  98. map.get($theme, container-shadow-color)
  99. );
  100. @include container-shape(map.get($theme, container-shape));
  101. @include _divider-color(map.get($theme, with-divider-divider-color));
  102. @include _divider-height(map.get($theme, with-divider-divider-height));
  103. @include _icon-size(map.get($theme, with-icon-icon-size));
  104. @include _icon-color(map.get($theme, with-icon-icon-color));
  105. @include subhead-typography(
  106. (
  107. font: map.get($theme, subhead-font),
  108. line-height: map.get($theme, subhead-line-height),
  109. size: map.get($theme, subhead-size),
  110. weight: map.get($theme, subhead-weight),
  111. tracking: map.get($theme, subhead-tracking),
  112. )
  113. );
  114. @include _subhead-color(map.get($theme, subhead-color));
  115. @include _supporting-text-typography(
  116. (
  117. font: map.get($theme, supporting-text-font),
  118. line-height: map.get($theme, supporting-text-line-height),
  119. size: map.get($theme, supporting-text-size),
  120. weight: map.get($theme, supporting-text-weight),
  121. tracking: map.get($theme, supporting-text-tracking),
  122. )
  123. );
  124. @include _supporting-text-color(map.get($theme, supporting-text-color));
  125. @include _z-index(map.get($theme, z-index));
  126. .mdc-dialog__actions .mdc-button {
  127. @include button-text-theme.theme-styles-internal(
  128. (
  129. focus-label-text-color: map.get($theme, action-focus-label-text-color),
  130. focus-state-layer-color: map.get($theme, action-focus-state-layer-color),
  131. focus-state-layer-opacity:
  132. map.get($theme, action-focus-state-layer-opacity),
  133. hover-label-text-color: map.get($theme, action-hover-text-color),
  134. hover-state-layer-color: map.get($theme, action-hover-state-layer-color),
  135. hover-state-layer-opacity:
  136. map.get($theme, action-hover-state-layer-opacity),
  137. label-text-color: map.get($theme, action-label-text-color),
  138. label-text-font: map.get($theme, action-label-text-font),
  139. label-text-size: map.get($theme, action-label-text-size),
  140. label-text-tracking: map.get($theme, action-label-text-tracking),
  141. label-text-weight: map.get($theme, action-label-text-weight),
  142. pressed-label-text-color:
  143. map.get($theme, action-pressed-label-text-color),
  144. pressed-state-layer-color:
  145. map.get($theme, action-pressed-state-layer-color),
  146. pressed-state-layer-opacity:
  147. map.get($theme, action-pressed-state-layer-opacity),
  148. )
  149. );
  150. }
  151. }
  152. @mixin _container-color($color) {
  153. .mdc-dialog__surface {
  154. @include theme.property(background-color, $color);
  155. }
  156. }
  157. @mixin _container-elevation($elevation-resolver, $elevation, $shadow-color) {
  158. .mdc-dialog__surface {
  159. @include elevation-theme.with-resolver(
  160. $elevation-resolver,
  161. $elevation: $elevation,
  162. $shadow-color: $shadow-color
  163. );
  164. }
  165. }
  166. @mixin container-shape($radius) {
  167. .mdc-dialog__surface {
  168. @include shape.radius($radius);
  169. }
  170. }
  171. @mixin _divider-color($color) {
  172. &.mdc-dialog--scrollable .mdc-dialog__title,
  173. &.mdc-dialog--scrollable .mdc-dialog__actions,
  174. &.mdc-dialog--scrollable.mdc-dialog-scroll-divider-footer
  175. .mdc-dialog__actions {
  176. @include theme.property(border-color, $color);
  177. }
  178. &.mdc-dialog--scrollable .mdc-dialog__title {
  179. @include theme.property(border-bottom-color, $color);
  180. }
  181. }
  182. @mixin _divider-height($height) {
  183. .mdc-dialog__actions {
  184. @include theme.property(border-top-width, $height);
  185. }
  186. &.mdc-dialog--scrollable .mdc-dialog__title {
  187. @include theme.property(border-bottom-width, $height);
  188. }
  189. }
  190. @mixin _icon-size($size) {
  191. .mdc-dialog__title-icon {
  192. @include theme.property(height, $size);
  193. @include theme.property(width, $size);
  194. @include theme.property(font-size, $size);
  195. }
  196. }
  197. @mixin _icon-color($color) {
  198. .mdc-dialog__title-icon {
  199. @include theme.property(color, $color);
  200. }
  201. }
  202. @mixin subhead-typography($typography) {
  203. .mdc-dialog__title {
  204. @include theme.property(font-family, map.get($typography, font));
  205. @include theme.property(line-height, map.get($typography, line-height));
  206. @include theme.property(font-size, map.get($typography, size));
  207. @include theme.property(font-weight, map.get($typography, weight));
  208. @include theme.property(letter-spacing, map.get($typography, tracking));
  209. }
  210. }
  211. @mixin _subhead-color($color) {
  212. .mdc-dialog__title {
  213. @include theme.property(color, $color);
  214. }
  215. }
  216. @mixin _supporting-text-typography($typography) {
  217. .mdc-dialog__content {
  218. @include theme.property(font-family, map.get($typography, font));
  219. @include theme.property(line-height, map.get($typography, line-height));
  220. @include theme.property(font-size, map.get($typography, size));
  221. @include theme.property(font-weight, map.get($typography, weight));
  222. @include theme.property(letter-spacing, map.get($typography, tracking));
  223. }
  224. }
  225. @mixin _supporting-text-color($color) {
  226. .mdc-dialog__content {
  227. @include theme.property(color, $color);
  228. }
  229. }
  230. @mixin _z-index($z-index) {
  231. &.mdc-dialog {
  232. @include theme.property(z-index, $z-index);
  233. }
  234. }
  235. @function _resolve-elevation($theme, $elevation-resolver) {
  236. @if map.get($theme, container-elevation) and
  237. map.get($theme, container-shadow-color)
  238. {
  239. $resolved-value: meta.call(
  240. $elevation-resolver,
  241. $elevation: map.get($theme, container-elevation),
  242. $shadow-color: map.get($theme, container-shadow-color)
  243. );
  244. $theme: map.set($theme, container-elevation, $resolved-value);
  245. }
  246. @return $theme;
  247. }