_mixins.scss 11 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412
  1. //
  2. // Copyright 2018 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. // stylelint-disable selector-class-pattern --
  23. // Selector '.mdc-*' should only be used in this project.
  24. @use '@material/feature-targeting/feature-targeting';
  25. @use '@material/focus-ring/focus-ring';
  26. @use '@material/ripple/ripple';
  27. @use '@material/ripple/ripple-theme';
  28. @use '@material/theme/theme';
  29. @use '@material/typography/typography';
  30. @use '@material/rtl/rtl';
  31. @use '@material/tab-indicator/mixins' as tab-indicator-mixins;
  32. @use './variables';
  33. // Public mixins
  34. @mixin core-styles($query: feature-targeting.all()) {
  35. @include without-ripple($query);
  36. @include ripple($query);
  37. }
  38. @mixin static-styles($query: feature-targeting.all()) {
  39. $feat-structure: feature-targeting.create-target($query, structure);
  40. $feat-animation: feature-targeting.create-target($query, animation);
  41. .mdc-tab {
  42. @include min-width(variables.$min-width, $query);
  43. @include horizontal-padding(variables.$horizontal-padding, $query);
  44. @include feature-targeting.targets($feat-structure) {
  45. display: flex;
  46. flex: 1 0 auto;
  47. justify-content: center;
  48. box-sizing: border-box;
  49. // Explicitly setting margin to 0 is to override safari default margin for button elements.
  50. margin: 0;
  51. padding-top: 0;
  52. padding-bottom: 0;
  53. border: none;
  54. outline: none;
  55. text-align: center;
  56. white-space: nowrap;
  57. cursor: pointer;
  58. -webkit-appearance: none;
  59. z-index: 1;
  60. // Firefox still draws a dotted border around focused buttons unless specifically overridden.
  61. &::-moz-focus-inner {
  62. padding: 0;
  63. border: 0;
  64. }
  65. &[hidden] {
  66. display: none;
  67. }
  68. }
  69. }
  70. .mdc-tab--min-width {
  71. @include feature-targeting.targets($feat-structure) {
  72. flex: 0 1 auto;
  73. }
  74. }
  75. .mdc-tab__content {
  76. @include feature-targeting.targets($feat-structure) {
  77. display: flex;
  78. align-items: center;
  79. justify-content: center;
  80. height: inherit;
  81. pointer-events: none;
  82. }
  83. }
  84. .mdc-tab__text-label {
  85. @include feature-targeting.targets($feat-animation) {
  86. transition: 150ms color linear;
  87. }
  88. @include feature-targeting.targets($feat-structure) {
  89. display: inline-block;
  90. // Setting line-height here overrides the line-height from the typography
  91. // mixin above. The line-height needs to be overridden so that the spacing
  92. // between the text label and the icon as well as the text label and the
  93. // bottom of the tab remain the same.
  94. line-height: 1;
  95. z-index: 2;
  96. }
  97. }
  98. .mdc-tab__icon {
  99. @include feature-targeting.targets($feat-animation) {
  100. transition: 150ms color linear;
  101. }
  102. @include feature-targeting.targets($feat-structure) {
  103. z-index: 2;
  104. }
  105. }
  106. .mdc-tab--stacked {
  107. @include stacked_($query);
  108. }
  109. .mdc-tab--active {
  110. .mdc-tab__text-label,
  111. .mdc-tab__icon {
  112. @include feature-targeting.targets($feat-animation) {
  113. transition-delay: 100ms;
  114. }
  115. }
  116. }
  117. .mdc-tab:not(.mdc-tab--stacked) .mdc-tab__icon + .mdc-tab__text-label {
  118. @include feature-targeting.targets($feat-structure) {
  119. @include rtl.reflexive-box(padding, left, 8px);
  120. }
  121. }
  122. }
  123. // This API is intended for use by frameworks that may want to separate the ripple-related styles
  124. // from the other tah styles. It is recommended that most users use `mdc-tab-core-styles` instead.
  125. @mixin without-ripple($query: feature-targeting.all()) {
  126. $feat-structure: feature-targeting.create-target($query, structure);
  127. $feat-animation: feature-targeting.create-target($query, animation);
  128. // postcss-bem-linter: define tab
  129. .mdc-tab {
  130. @include base_($query);
  131. }
  132. .mdc-tab__content {
  133. @include content_($query);
  134. }
  135. .mdc-tab__icon {
  136. @include feature-targeting.targets($feat-structure) {
  137. width: variables.$icon-size;
  138. height: variables.$icon-size;
  139. font-size: variables.$icon-size;
  140. }
  141. }
  142. .mdc-tab--active {
  143. @include active_($query);
  144. }
  145. .mdc-tab {
  146. @include feature-targeting.targets($feat-structure) {
  147. background: none;
  148. }
  149. }
  150. @include static-styles($query: $query);
  151. // postcss-bem-linter: end
  152. }
  153. // This API is intended for use by frameworks that may want to separate the ripple-related styles
  154. // from the other tah styles. It is recommended that most users use `mdc-tab-core-styles` instead.
  155. @mixin ripple($query: feature-targeting.all()) {
  156. @include ripple.common($query); // COPYBARA_COMMENT_THIS_LINE
  157. @include ripple_($query);
  158. }
  159. @mixin horizontal-padding($padding, $query: feature-targeting.all()) {
  160. $feat-structure: feature-targeting.create-target($query, structure);
  161. @include feature-targeting.targets($feat-structure) {
  162. padding-right: $padding;
  163. padding-left: $padding;
  164. }
  165. }
  166. @mixin text-label-color($color, $query: feature-targeting.all()) {
  167. $feat-color: feature-targeting.create-target($query, color);
  168. .mdc-tab__text-label {
  169. @include feature-targeting.targets($feat-color) {
  170. @include theme.property(color, $color);
  171. }
  172. }
  173. }
  174. @mixin icon-color($color, $query: feature-targeting.all()) {
  175. $feat-color: feature-targeting.create-target($query, color);
  176. .mdc-tab__icon {
  177. @include feature-targeting.targets($feat-color) {
  178. @include theme.property(color, $color);
  179. fill: currentColor;
  180. }
  181. }
  182. }
  183. @mixin states-color($color, $query: feature-targeting.all()) {
  184. @include ripple-theme.states(
  185. $color,
  186. $query: $query,
  187. $ripple-target: variables.$ripple-target
  188. );
  189. }
  190. @mixin ink-color($color, $query: feature-targeting.all()) {
  191. @include icon-color($color, $query);
  192. @include states-color($color, $query);
  193. @include text-label-color($color, $query);
  194. }
  195. @mixin active-text-label-color($color, $query: feature-targeting.all()) {
  196. &.mdc-tab--active {
  197. @include text-label-color($color, $query);
  198. }
  199. }
  200. @mixin active-icon-color($color, $query: feature-targeting.all()) {
  201. &.mdc-tab--active {
  202. @include icon-color($color, $query);
  203. }
  204. }
  205. @mixin active-states-color($color, $query: feature-targeting.all()) {
  206. &.mdc-tab--active {
  207. @include states-color($color, $query);
  208. }
  209. }
  210. @mixin parent-positioning($query: feature-targeting.all()) {
  211. $feat-structure: feature-targeting.create-target($query, structure);
  212. @include feature-targeting.targets($feat-structure) {
  213. position: relative;
  214. }
  215. }
  216. @mixin fixed-width($width, $query: feature-targeting.all()) {
  217. $feat-structure: feature-targeting.create-target($query, structure);
  218. @include feature-targeting.targets($feat-structure) {
  219. flex: 0 1 $width;
  220. }
  221. }
  222. ///
  223. /// Sets tab height
  224. ///
  225. /// @param {Number} $height Height value in `px`.
  226. ///
  227. @mixin height($height, $query: feature-targeting.all()) {
  228. $feat-structure: feature-targeting.create-target($query, structure);
  229. @include feature-targeting.targets($feat-structure) {
  230. height: $height;
  231. }
  232. }
  233. ///
  234. /// Sets tab text transform
  235. ///
  236. /// @param {String} $transform The text-transform property to apply.
  237. ///
  238. @mixin text-transform($transform, $query: feature-targeting.all()) {
  239. $feat-structure: feature-targeting.create-target($query, structure);
  240. @include feature-targeting.targets($feat-structure) {
  241. text-transform: $transform;
  242. }
  243. }
  244. ///
  245. /// Sets tab min-width.
  246. ///
  247. /// @param {Number} $min-width Minimum width value in `px`.
  248. ///
  249. @mixin min-width($min-width, $query: feature-targeting.all()) {
  250. $feat-structure: feature-targeting.create-target($query, structure);
  251. @include feature-targeting.targets($feat-structure) {
  252. min-width: $min-width;
  253. }
  254. }
  255. //
  256. // Private
  257. //
  258. @mixin base_($query: feature-targeting.all()) {
  259. $feat-structure: feature-targeting.create-target($query, structure);
  260. @include typography.typography(button, $query);
  261. @include text-label-color(variables.$text-label-color-default, $query);
  262. @include icon-color(variables.$icon-color-default, $query);
  263. @include tab-indicator-mixins.surface($query);
  264. @include ripple-theme.focus() {
  265. &.mdc-tab--active .mdc-tab__focus-ring {
  266. @include focus-ring.focus-ring(
  267. $query: $query,
  268. $ring-radius: 10px,
  269. $container-outer-padding-vertical: -6px,
  270. $container-outer-padding-horizontal: -4px
  271. );
  272. @include feature-targeting.targets($feat-structure) {
  273. margin-top: -2px;
  274. // Set z-index to +1 above the .mdc-tab
  275. z-index: 2;
  276. }
  277. }
  278. .mdc-tab__focus-ring {
  279. @include focus-ring.focus-ring(
  280. $query: $query,
  281. $ring-radius: 10px,
  282. $container-outer-padding-vertical: -4px,
  283. $container-outer-padding-horizontal: -4px
  284. );
  285. @include feature-targeting.targets($feat-structure) {
  286. // Set z-index to +1 above the .mdc-tab
  287. z-index: 2;
  288. }
  289. }
  290. }
  291. }
  292. @mixin ripple_($query: feature-targeting.all()) {
  293. $feat-structure: feature-targeting.create-target($query, structure);
  294. .mdc-tab {
  295. @include ripple.surface(
  296. $query,
  297. $ripple-target: variables.$ripple-target,
  298. $include-will-change: false
  299. );
  300. @include ripple.radius-bounded(
  301. $query: $query,
  302. $ripple-target: variables.$ripple-target
  303. );
  304. @include ripple-theme.states(
  305. $color: primary,
  306. $query: $query,
  307. $ripple-target: variables.$ripple-target
  308. );
  309. }
  310. #{variables.$ripple-target} {
  311. @include feature-targeting.targets($feat-structure) {
  312. position: absolute;
  313. top: 0;
  314. left: 0;
  315. width: 100%;
  316. height: 100%;
  317. overflow: hidden;
  318. // TODO(b/151931961): Remove the following line once resolved
  319. will-change: transform, opacity;
  320. }
  321. }
  322. }
  323. @mixin content_($query: feature-targeting.all()) {
  324. $feat-structure: feature-targeting.create-target($query, structure);
  325. @include tab-indicator-mixins.surface($query);
  326. }
  327. @mixin stacked_($query: feature-targeting.all()) {
  328. $feat-structure: feature-targeting.create-target($query, structure);
  329. @include feature-targeting.targets($feat-structure) {
  330. .mdc-tab__content {
  331. flex-direction: column;
  332. align-items: center;
  333. justify-content: center;
  334. }
  335. .mdc-tab__text-label {
  336. padding-top: 6px;
  337. padding-bottom: 4px;
  338. }
  339. }
  340. }
  341. @mixin active_($query: feature-targeting.all()) {
  342. $feat-animation: feature-targeting.create-target($query, animation);
  343. @include text-label-color(variables.$text-label-color-active, $query);
  344. @include icon-color(variables.$icon-color-active, $query);
  345. }