_mixins.scss 15 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523
  1. //
  2. // Copyright 2017 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 'sass:math';
  25. @use 'sass:list';
  26. @use 'sass:meta';
  27. @use '@material/feature-targeting/feature-targeting';
  28. @use '@material/animation/functions' as functions2;
  29. @use '@material/animation/variables' as animation-variables;
  30. @use '@material/rtl/rtl';
  31. @use '@material/typography/typography';
  32. @use '@material/theme/theme';
  33. @use '@material/theme/theme-color';
  34. @use '@material/list/mixins' as list-mixins;
  35. @use '@material/ripple/ripple-theme';
  36. @use '@material/shape/mixins' as shape-mixins;
  37. @use '@material/elevation/mixins' as elevation-mixins;
  38. @use './variables';
  39. //
  40. // Public
  41. //
  42. @mixin core-styles($query: feature-targeting.all()) {
  43. $feat-structure: feature-targeting.create-target($query, structure);
  44. $feat-animation: feature-targeting.create-target($query, animation);
  45. // postcss-bem-linter: define drawer
  46. .mdc-drawer {
  47. @include title-ink-color(variables.$title-ink-color, $query: $query);
  48. @include subtitle-ink-color(variables.$subtitle-ink-color, $query: $query);
  49. @include border-color(variables.$divider-color, $query: $query);
  50. @include surface-fill-color(variables.$surface-fill-color, $query: $query);
  51. @include item-icon-ink-color(
  52. variables.$item-inactive-ink-color,
  53. $query: $query
  54. );
  55. @include item-text-ink-color(
  56. variables.$item-inactive-ink-color,
  57. $query: $query
  58. );
  59. @include item-activated-icon-ink-color(
  60. variables.$item-activated-ink-color,
  61. $query: $query
  62. );
  63. @include item-activated-text-ink-color(
  64. variables.$item-activated-ink-color,
  65. $query: $query
  66. );
  67. @include shape-radius(variables.$shape-radius, $query: $query);
  68. @include item-shape-radius(variables.$item-shape-radius, $query: $query);
  69. @include z-index(variables.$z-index, $query: $query);
  70. @include width(variables.$width, $query: $query);
  71. @include feature-targeting.targets($feat-structure) {
  72. display: flex;
  73. flex-direction: column;
  74. flex-shrink: 0;
  75. box-sizing: border-box;
  76. height: 100%;
  77. @include rtl.ignore-next-line();
  78. border-right-width: 1px;
  79. @include rtl.ignore-next-line();
  80. border-right-style: solid;
  81. overflow: hidden;
  82. @include rtl.rtl {
  83. @include rtl.ignore-next-line();
  84. border-right-width: 0;
  85. @include rtl.ignore-next-line();
  86. border-left-width: 1px;
  87. @include rtl.ignore-next-line();
  88. border-right-style: none;
  89. @include rtl.ignore-next-line();
  90. border-left-style: solid;
  91. }
  92. }
  93. @include feature-targeting.targets($feat-animation) {
  94. transition-property: transform;
  95. transition-timing-function: animation-variables.$standard-curve-timing-function;
  96. }
  97. @include list-item_($query);
  98. }
  99. .mdc-drawer--animate {
  100. @include feature-targeting.targets($feat-structure) {
  101. transform: translateX(-100%);
  102. @include rtl.rtl {
  103. transform: translateX(100%);
  104. }
  105. }
  106. }
  107. .mdc-drawer--opening {
  108. @include feature-targeting.targets($feat-structure) {
  109. transform: translateX(0);
  110. // Required to level the specificity with animate class.
  111. @include rtl.rtl {
  112. transform: translateX(0);
  113. }
  114. }
  115. @include feature-targeting.targets($feat-animation) {
  116. transition-duration: variables.$animation-enter;
  117. }
  118. }
  119. .mdc-drawer--closing {
  120. @include feature-targeting.targets($feat-structure) {
  121. transform: translateX(-100%);
  122. @include rtl.rtl {
  123. transform: translateX(100%);
  124. }
  125. }
  126. @include feature-targeting.targets($feat-animation) {
  127. transition-duration: variables.$animation-exit;
  128. }
  129. }
  130. .mdc-drawer__header {
  131. @include feature-targeting.targets($feat-structure) {
  132. flex-shrink: 0;
  133. box-sizing: border-box;
  134. min-height: 64px; // same as $mdc-top-app-bar-row-height
  135. padding: 0 variables.$surface-padding 4px;
  136. }
  137. }
  138. .mdc-drawer__title {
  139. @include typography.typography(headline6, $query: $query);
  140. @include typography.text-baseline(
  141. $top: 36px,
  142. $bottom: 20px,
  143. $query: $query
  144. );
  145. }
  146. .mdc-drawer__subtitle {
  147. @include typography.typography(body2, $query: $query);
  148. @include typography.text-baseline($top: 20px, $query: $query);
  149. @include feature-targeting.targets($feat-structure) {
  150. margin-bottom: 0;
  151. }
  152. }
  153. .mdc-drawer__content {
  154. @include feature-targeting.targets($feat-structure) {
  155. height: 100%;
  156. overflow-y: auto;
  157. -webkit-overflow-scrolling: touch;
  158. }
  159. }
  160. // postcss-bem-linter: end
  161. }
  162. @mixin dismissible-core-styles($query: feature-targeting.all()) {
  163. $feat-structure: feature-targeting.create-target($query, structure);
  164. .mdc-drawer--dismissible {
  165. @include feature-targeting.targets($feat-structure) {
  166. @include rtl.reflexive-position(left, 0);
  167. display: none;
  168. position: absolute;
  169. &.mdc-drawer--open {
  170. display: flex;
  171. }
  172. }
  173. }
  174. .mdc-drawer-app-content {
  175. @include feature-targeting.targets($feat-structure) {
  176. @include rtl.reflexive-box(margin, left, 0);
  177. position: relative;
  178. }
  179. }
  180. }
  181. @mixin modal-core-styles($query: feature-targeting.all()) {
  182. $feat-structure: feature-targeting.create-target($query, structure);
  183. $feat-animation: feature-targeting.create-target($query, animation);
  184. .mdc-drawer--modal {
  185. @include scrim-fill-color(variables.$modal-scrim-color, $query: $query);
  186. @include elevation-mixins.elevation(
  187. variables.$modal-elevation,
  188. $query: $query
  189. );
  190. @include feature-targeting.targets($feat-structure) {
  191. @include rtl.reflexive-position(left, 0);
  192. display: none;
  193. position: fixed;
  194. }
  195. &.mdc-drawer--open {
  196. @include feature-targeting.targets($feat-structure) {
  197. display: flex;
  198. }
  199. }
  200. }
  201. .mdc-drawer-scrim {
  202. @include feature-targeting.targets($feat-structure) {
  203. display: none;
  204. position: fixed;
  205. top: 0;
  206. left: 0;
  207. width: 100%;
  208. height: 100%;
  209. z-index: variables.$z-index - 1;
  210. }
  211. @include feature-targeting.targets($feat-animation) {
  212. transition-property: opacity;
  213. transition-timing-function: animation-variables.$standard-curve-timing-function;
  214. }
  215. .mdc-drawer--open + & {
  216. @include feature-targeting.targets($feat-structure) {
  217. display: block;
  218. }
  219. }
  220. .mdc-drawer--animate + & {
  221. @include feature-targeting.targets($feat-structure) {
  222. opacity: 0;
  223. }
  224. }
  225. .mdc-drawer--opening + & {
  226. @include feature-targeting.targets($feat-animation) {
  227. transition-duration: variables.$animation-enter;
  228. }
  229. @include feature-targeting.targets($feat-structure) {
  230. opacity: 1;
  231. }
  232. }
  233. .mdc-drawer--closing + & {
  234. @include feature-targeting.targets($feat-animation) {
  235. transition-duration: variables.$animation-exit;
  236. }
  237. @include feature-targeting.targets($feat-structure) {
  238. opacity: 0;
  239. }
  240. }
  241. }
  242. }
  243. @mixin activated-overlay-color($color, $query: feature-targeting.all()) {
  244. :not(.mdc-deprecated-list--non-interactive) > .mdc-deprecated-list-item {
  245. @include ripple-theme.states-activated($color, $query: $query);
  246. }
  247. }
  248. @mixin border-color($color, $query: feature-targeting.all()) {
  249. $feat-color: feature-targeting.create-target($query, color);
  250. $value: rgba(theme-color.prop-value($color), variables.$divider-opacity);
  251. @include feature-targeting.targets($feat-color) {
  252. @include theme.property(border-color, $value);
  253. }
  254. }
  255. @mixin item-shape-radius(
  256. $radius,
  257. $rtl-reflexive: true,
  258. $query: feature-targeting.all()
  259. ) {
  260. @include list-mixins.deprecated-single-line-shape-radius(
  261. $radius,
  262. $rtl-reflexive,
  263. $query: $query
  264. );
  265. }
  266. @mixin shape-radius($radius, $query: feature-targeting.all()) {
  267. // Check type since $radius may be a custom property Map
  268. $is-list: meta.type-of($radius) == 'list';
  269. @if $is-list and list.length($radius) > 2 {
  270. @error "Invalid radius: '#{$radius}' component doesn't allow customizing all corners";
  271. } @else if $is-list and list.length($radius) == 2 {
  272. $radius: 0 list.nth($radius, 1) list.nth($radius, 2) 0;
  273. } @else {
  274. $radius: 0 $radius $radius 0;
  275. }
  276. @include shape-mixins.radius($radius, $rtl-reflexive: true, $query: $query);
  277. }
  278. @mixin divider-color($color, $query: feature-targeting.all()) {
  279. $value: rgba(theme-color.prop-value($color), variables.$divider-opacity);
  280. @include list-mixins.deprecated-divider-color($value, $query: $query);
  281. }
  282. @mixin title-ink-color($color, $query: feature-targeting.all()) {
  283. $feat-color: feature-targeting.create-target($query, color);
  284. $value: rgba(theme-color.prop-value($color), variables.$title-ink-opacity);
  285. .mdc-drawer__title {
  286. @include feature-targeting.targets($feat-color) {
  287. @include theme.property(color, $value);
  288. }
  289. }
  290. }
  291. @mixin subtitle-ink-color($color, $query: feature-targeting.all()) {
  292. $feat-color: feature-targeting.create-target($query, color);
  293. $value: rgba(theme-color.prop-value($color), variables.$subtitle-ink-opacity);
  294. @include list-mixins.deprecated-group-subheader-ink-color(
  295. $value,
  296. $query: $query
  297. );
  298. .mdc-drawer__subtitle {
  299. @include feature-targeting.targets($feat-color) {
  300. @include theme.property(color, $value);
  301. }
  302. }
  303. }
  304. @mixin fill-color-accessible($color, $query: feature-targeting.all()) {
  305. $accessibleColor: theme-color.accessible-ink-color($color);
  306. @include title-ink-color($accessibleColor, $query: $query);
  307. @include subtitle-ink-color($accessibleColor, $query: $query);
  308. @include item-text-ink-color($accessibleColor, $query: $query);
  309. @include item-icon-ink-color($accessibleColor, $query: $query);
  310. @include surface-fill-color($color, $query: $query);
  311. }
  312. @mixin item-icon-ink-color($color, $query: feature-targeting.all()) {
  313. $value: rgba(
  314. theme-color.prop-value($color),
  315. variables.$item-inactive-icon-ink-opacity
  316. );
  317. @include list-mixins.deprecated-item-graphic-ink-color(
  318. $value,
  319. $query: $query
  320. );
  321. }
  322. @mixin item-activated-icon-ink-color($color, $query: feature-targeting.all()) {
  323. $value: rgba(
  324. theme-color.prop-value($color),
  325. variables.$item-active-icon-ink-opacity
  326. );
  327. .mdc-deprecated-list-item--activated {
  328. @include list-mixins.deprecated-item-graphic-ink-color(
  329. $value,
  330. $query: $query
  331. );
  332. }
  333. }
  334. @mixin item-activated-text-ink-color($color, $query: feature-targeting.all()) {
  335. $value: rgba(
  336. theme-color.prop-value($color),
  337. variables.$item-active-text-ink-opacity
  338. );
  339. .mdc-deprecated-list-item--activated {
  340. @include list-mixins.deprecated-item-primary-text-ink-color(
  341. $value,
  342. $query: $query
  343. );
  344. }
  345. }
  346. @mixin item-text-ink-color($color, $query: feature-targeting.all()) {
  347. $value: rgba(
  348. theme-color.prop-value($color),
  349. variables.$item-inactive-text-ink-opacity
  350. );
  351. .mdc-deprecated-list-item {
  352. @include list-mixins.deprecated-item-primary-text-ink-color(
  353. $value,
  354. $query: $query
  355. );
  356. }
  357. }
  358. @mixin surface-fill-color($color, $query: feature-targeting.all()) {
  359. $feat-color: feature-targeting.create-target($query, color);
  360. @include feature-targeting.targets($feat-color) {
  361. @include theme.property(background-color, $color);
  362. }
  363. }
  364. @mixin scrim-fill-color($color, $query: feature-targeting.all()) {
  365. $feat-color: feature-targeting.create-target($query, color);
  366. $value: rgba(theme-color.prop-value($color), variables.$modal-scrim-opacity);
  367. + .mdc-drawer-scrim {
  368. @include feature-targeting.targets($feat-color) {
  369. @include theme.property(background-color, $value);
  370. }
  371. }
  372. }
  373. @mixin z-index($value, $query: feature-targeting.all()) {
  374. $feat-structure: feature-targeting.create-target($query, structure);
  375. @include feature-targeting.targets($feat-structure) {
  376. z-index: $value;
  377. }
  378. }
  379. @mixin width($width, $query: feature-targeting.all()) {
  380. $feat-structure: feature-targeting.create-target($query, structure);
  381. @include feature-targeting.targets($feat-structure) {
  382. @include theme.property(width, $width);
  383. }
  384. &.mdc-drawer--open:not(.mdc-drawer--closing) + .mdc-drawer-app-content {
  385. @include feature-targeting.targets($feat-structure) {
  386. @include rtl.reflexive-box(margin, left, $width);
  387. }
  388. }
  389. }
  390. //
  391. // Private
  392. //
  393. @mixin list-item_($query: feature-targeting.all()) {
  394. $feat-structure: feature-targeting.create-target($query, structure);
  395. // postcss-bem-linter: ignore
  396. .mdc-deprecated-list-item {
  397. @include typography.typography(subtitle2, $query: $query);
  398. @include feature-targeting.targets($feat-structure) {
  399. height: calc(48px - 2 * #{variables.$list-item-spacing});
  400. // To accomodate margin conflict.
  401. margin: (variables.$list-item-spacing * 2) 8px;
  402. padding: 0 math.div(variables.$surface-padding, 2);
  403. }
  404. }
  405. // postcss-bem-linter: ignore
  406. .mdc-deprecated-list-item:nth-child(1) {
  407. @include feature-targeting.targets($feat-structure) {
  408. margin-top: 2px;
  409. }
  410. }
  411. // postcss-bem-linter: ignore
  412. .mdc-deprecated-list-item:nth-last-child(1) {
  413. @include feature-targeting.targets($feat-structure) {
  414. margin-bottom: 0;
  415. }
  416. }
  417. // postcss-bem-linter: ignore
  418. .mdc-deprecated-list-group__subheader {
  419. @include typography.typography(body2, $query: $query);
  420. @include typography.text-baseline($top: 24px, $query: $query);
  421. @include feature-targeting.targets($feat-structure) {
  422. margin: 0;
  423. padding: 0 variables.$surface-padding;
  424. }
  425. }
  426. // postcss-bem-linter: ignore
  427. .mdc-deprecated-list-divider {
  428. @include feature-targeting.targets($feat-structure) {
  429. margin: 3px 0 4px;
  430. }
  431. }
  432. // Prevents list item children from being included in the click target.
  433. // postcss-bem-linter: ignore
  434. .mdc-deprecated-list-item__text,
  435. .mdc-deprecated-list-item__graphic {
  436. @include feature-targeting.targets($feat-structure) {
  437. pointer-events: none;
  438. }
  439. }
  440. }