_tab-bar-theme.scss 8.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252
  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. @use 'sass:map';
  23. @use '@material/elevation/elevation-theme';
  24. @use '@material/tab/tab-theme';
  25. @use '@material/theme/map-ext';
  26. @use '@material/tab-indicator/tab-indicator-theme';
  27. @use '@material/theme/theme-color';
  28. @use '@material/typography/typography';
  29. @use '@material/tokens/resolvers';
  30. @use '@material/theme/theme';
  31. @use '@material/theme/keys';
  32. @use '@material/theme/validate';
  33. // stylelint-disable selector-class-pattern --
  34. // Selector '.mdc-*' should only be used in this project.
  35. $custom-property-prefix: 'tab-bar';
  36. // Complete tokens set for primary tabs component
  37. // tab bar should validate all tokens as it is the entry point
  38. $primary-navigation-tabs-light-theme: (
  39. active-focus-state-layer-color: theme-color.$primary,
  40. active-focus-state-layer-opacity: 0.12,
  41. active-hover-state-layer-color: theme-color.$primary,
  42. active-hover-state-layer-opacity: 0.04,
  43. active-indicator-color: theme-color.$primary,
  44. active-indicator-height: 3px,
  45. active-indicator-shape: (
  46. 3px,
  47. 3px,
  48. 0,
  49. 0,
  50. ),
  51. active-pressed-state-layer-color: theme-color.$primary,
  52. active-pressed-state-layer-opacity: 0.1,
  53. container-color: theme-color.$surface,
  54. container-elevation: elevation-theme.get-elevation(0),
  55. container-height: 48px,
  56. container-shape: 0,
  57. divider-color: null,
  58. divider-height: null,
  59. inactive-focus-state-layer-color: theme-color.$on-surface,
  60. inactive-focus-state-layer-opacity: 0.12,
  61. inactive-hover-state-layer-color: theme-color.$on-surface,
  62. inactive-hover-state-layer-opacity: 0.04,
  63. inactive-pressed-state-layer-color: theme-color.$on-surface,
  64. inactive-pressed-state-layer-opacity: 0.1,
  65. with-icon-active-focus-icon-color: theme-color.$primary,
  66. with-icon-active-hover-icon-color: theme-color.$primary,
  67. with-icon-active-icon-color: theme-color.$primary,
  68. with-icon-active-pressed-icon-color: theme-color.$primary,
  69. with-icon-and-label-text-container-height: 64px,
  70. with-icon-icon-size: 24px,
  71. with-icon-inactive-focus-icon-color: theme-color.$on-surface,
  72. with-icon-inactive-hover-icon-color: theme-color.$on-surface,
  73. with-icon-inactive-icon-color: theme-color.$on-surface,
  74. with-icon-inactive-pressed-icon-color: theme-color.$on-surface,
  75. with-label-text-active-focus-label-text-color: theme-color.$primary,
  76. with-label-text-active-hover-label-text-color: theme-color.$primary,
  77. with-label-text-active-label-text-color: theme-color.$primary,
  78. with-label-text-active-pressed-label-text-color: theme-color.$primary,
  79. with-label-text-inactive-focus-label-text-color: theme-color.$on-surface,
  80. with-label-text-inactive-hover-label-text-color: theme-color.$on-surface,
  81. with-label-text-inactive-label-text-color: theme-color.$on-surface,
  82. with-label-text-inactive-pressed-label-text-color: theme-color.$on-surface,
  83. with-label-text-label-text-font-family: typography.get-font(subhead2),
  84. with-label-text-label-text-font-size: typography.get-size(subhead2),
  85. with-label-text-label-text-letter-spacing: typography.get-tracking(subhead2),
  86. with-label-text-label-text-font: typography.get-font(subhead2),
  87. with-label-text-label-text-size: typography.get-size(subhead2),
  88. with-label-text-label-text-tracking: typography.get-tracking(subhead2),
  89. with-label-text-label-text-line-height: typography.get-line-height(subhead2),
  90. with-label-text-label-text-weight: typography.get-weight(subhead2),
  91. );
  92. // Complete tokens set for secondary tabs component
  93. // tab bar should validate all tokens as it is the entry point
  94. $secondary-navigation-tabs-light-theme: (
  95. active-indicator-color: null,
  96. active-indicator-height: null,
  97. active-label-text-color: null,
  98. container-color: null,
  99. container-elevation: null,
  100. container-height: null,
  101. container-shadow-color: null,
  102. container-shape: null,
  103. divider-color: null,
  104. divider-height: null,
  105. focus-label-text-color: null,
  106. focus-state-layer-color: null,
  107. focus-state-layer-opacity: null,
  108. hover-label-text-color: null,
  109. hover-state-layer-color: null,
  110. hover-state-layer-opacity: null,
  111. inactive-label-text-color: null,
  112. label-text-font-family: null,
  113. label-text-font-size: null,
  114. label-text-letter-spacing: null,
  115. label-text-font: null,
  116. label-text-size: null,
  117. label-text-tracking: null,
  118. label-text-line-height: null,
  119. label-text-weight: null,
  120. pressed-label-text-color: null,
  121. pressed-state-layer-color: null,
  122. pressed-state-layer-opacity: null,
  123. with-icon-active-icon-color: null,
  124. with-icon-focus-icon-color: null,
  125. with-icon-hover-icon-color: null,
  126. with-icon-inactive-icon-color: null,
  127. with-icon-pressed-icon-color: null,
  128. with-icon-icon-size: null,
  129. );
  130. // Tab bar related tokens to create custom properties
  131. $light-theme: (
  132. divider-color: null,
  133. divider-height: null,
  134. );
  135. @mixin primary-navigation-tab-theme($theme, $resolvers: resolvers.$material) {
  136. $theme: validate.theme($primary-navigation-tabs-light-theme, $theme);
  137. $tab-bar-theme: map-ext.pick($theme, map.keys($light-theme)...);
  138. @include keys.declare-custom-properties(
  139. $tab-bar-theme,
  140. $prefix: $custom-property-prefix
  141. );
  142. @include tab-theme.primary-navigation-tab-theme(
  143. map-ext.pick($theme, map.keys(tab-theme.$primary-light-theme)...),
  144. $resolvers
  145. );
  146. @include tab-indicator-theme.theme(
  147. map-ext.pick($theme, map.keys(tab-indicator-theme.$light-theme)...)
  148. );
  149. }
  150. @mixin secondary-navigation-tab-theme($theme, $resolvers: resolvers.$material) {
  151. $theme: validate.theme($secondary-navigation-tabs-light-theme, $theme);
  152. $tab-bar-theme: map-ext.pick($theme, map.keys($light-theme)...);
  153. @include keys.declare-custom-properties(
  154. $tab-bar-theme,
  155. $prefix: $custom-property-prefix
  156. );
  157. @include tab-theme.secondary-navigation-tab-theme(
  158. map-ext.pick($theme, map.keys(tab-theme.$secondary-light-theme)...),
  159. $resolvers
  160. );
  161. @include tab-indicator-theme.theme(
  162. map-ext.pick($theme, map.keys(tab-indicator-theme.$light-theme)...)
  163. );
  164. }
  165. @mixin primary-navigation-tab-theme-styles(
  166. $theme,
  167. $resolvers: resolvers.$material
  168. ) {
  169. // TODO(b/251881053): Use theme-styles mixin from validate module
  170. // when all customers are migrated
  171. @include theme.validate-theme-styles(
  172. $primary-navigation-tabs-light-theme,
  173. $theme
  174. );
  175. $tab-bar-theme: map-ext.pick($theme, map.keys($light-theme)...);
  176. $tab-bar-theme: keys.create-theme-properties(
  177. $tab-bar-theme,
  178. $prefix: $custom-property-prefix
  179. );
  180. &.mdc-tab-bar {
  181. @include _divider-color(map.get($tab-bar-theme, divider-color));
  182. @include _divider-height(map.get($tab-bar-theme, divider-height));
  183. }
  184. .mdc-tab {
  185. @include tab-theme.primary-navigation-tab-theme-styles(
  186. map-ext.pick($theme, map.keys(tab-theme.$primary-light-theme)...),
  187. $resolvers
  188. );
  189. }
  190. .mdc-tab-indicator {
  191. @include tab-indicator-theme.theme-styles(
  192. map-ext.pick($theme, map.keys(tab-indicator-theme.$light-theme)...)
  193. );
  194. }
  195. }
  196. @mixin secondary-navigation-tab-theme-styles(
  197. $theme,
  198. $resolvers: resolvers.$material
  199. ) {
  200. // TODO(b/251881053): Use theme-styles mixin from validate module
  201. // when all customers are migrated
  202. @include theme.validate-theme-styles(
  203. $secondary-navigation-tabs-light-theme,
  204. $theme
  205. );
  206. $tab-bar-theme: map-ext.pick($theme, map.keys($light-theme)...);
  207. $tab-bar-theme: keys.create-theme-properties(
  208. $tab-bar-theme,
  209. $prefix: $custom-property-prefix
  210. );
  211. &.mdc-tab-bar {
  212. @include _divider-color(map.get($tab-bar-theme, divider-color));
  213. @include _divider-height(map.get($tab-bar-theme, divider-height));
  214. }
  215. .mdc-tab {
  216. @include tab-theme.secondary-navigation-tab-theme-styles(
  217. map-ext.pick($theme, map.keys(tab-theme.$secondary-light-theme)...),
  218. $resolvers
  219. );
  220. }
  221. .mdc-tab-indicator {
  222. @include tab-indicator-theme.theme-styles(
  223. map-ext.pick($theme, map.keys(tab-indicator-theme.$light-theme)...)
  224. );
  225. }
  226. }
  227. @mixin _divider-color($color) {
  228. @include theme.property('border-bottom-color', $color);
  229. }
  230. @mixin _divider-height($height) {
  231. @include theme.property('border-bottom-width', $height);
  232. }