_menu.scss 6.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201
  1. //
  2. // Copyright 2023 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 '@material/dom/dom';
  26. @use '@material/elevation/mixins' as elevation-mixins;
  27. @use '@material/feature-targeting/feature-targeting';
  28. @use '@material/ripple/ripple-theme';
  29. @use '@material/rtl/rtl';
  30. @use '@material/list/mixins' as list-mixins;
  31. @use '@material/list/variables' as list-variables;
  32. @use '@material/ripple/ripple';
  33. @use '@material/theme/theme';
  34. @use '@material/theme/custom-properties';
  35. @use './menu-custom-properties';
  36. @use './variables';
  37. @use '@material/menu-surface/menusurface-theme';
  38. /// @deprecated Use static-styles() instead.
  39. @mixin core-styles($query: feature-targeting.all()) {
  40. @include static-styles($query);
  41. }
  42. @mixin static-styles($query: feature-targeting.all()) {
  43. $feat-color: feature-targeting.create-target($query, color);
  44. $feat-structure: feature-targeting.create-target($query, structure);
  45. @include ripple.common($query); // COPYBARA_COMMENT_THIS_LINE
  46. // prettier-ignore
  47. @include elevation-mixins.overlay-common($query); // COPYBARA_COMMENT_THIS_LINE
  48. // Customize the menu-surface and contained list to match the mdc-menu styles.
  49. .mdc-menu {
  50. @include list-mixins.deprecated-item-meta-ink-color(
  51. variables.$ink-color,
  52. $query
  53. );
  54. @include list-mixins.deprecated-item-graphic-ink-color(
  55. variables.$ink-color,
  56. $query
  57. );
  58. @include min-width(variables.$min-width, $query: $query);
  59. @include open-item-opacity(variables.$open-item-opacity, $query: $query);
  60. // Include mdc-deprecated-list selector to ensure list-inside-menu overrides default list styles
  61. .mdc-deprecated-list {
  62. @include list-mixins.deprecated-item-primary-text-ink-color(
  63. variables.$ink-color,
  64. $query
  65. );
  66. }
  67. .mdc-deprecated-list,
  68. .mdc-list {
  69. @include elevation-mixins.overlay-surface-position($query: $query);
  70. @include elevation-mixins.overlay-dimensions(100%, $query: $query);
  71. &::before {
  72. @include dom.transparent-border($query: $query);
  73. }
  74. }
  75. .mdc-deprecated-list-divider {
  76. @include feature-targeting.targets($feat-structure) {
  77. margin: 8px 0;
  78. }
  79. }
  80. .mdc-deprecated-list-item {
  81. @include feature-targeting.targets($feat-structure) {
  82. user-select: none;
  83. }
  84. }
  85. .mdc-deprecated-list-item--disabled {
  86. @include feature-targeting.targets($feat-structure) {
  87. cursor: auto;
  88. }
  89. }
  90. a.mdc-deprecated-list-item .mdc-deprecated-list-item__text,
  91. a.mdc-deprecated-list-item .mdc-deprecated-list-item__graphic {
  92. @include feature-targeting.targets($feat-structure) {
  93. pointer-events: none;
  94. }
  95. }
  96. }
  97. // postcss-bem-linter: define menu
  98. .mdc-menu__selection-group {
  99. @include feature-targeting.targets($feat-structure) {
  100. padding: 0;
  101. fill: currentColor;
  102. }
  103. .mdc-deprecated-list-item {
  104. @include feature-targeting.targets($feat-structure) {
  105. @include rtl.reflexive-property(
  106. padding,
  107. 56px,
  108. list-variables.$deprecated-side-padding
  109. );
  110. }
  111. }
  112. .mdc-menu__selection-group-icon {
  113. @include feature-targeting.targets($feat-structure) {
  114. @include rtl.reflexive-position(left, 16px);
  115. visibility: hidden;
  116. position: absolute;
  117. // IE11 requires the icon to be vertically centered due to its absolute positioning
  118. top: 50%;
  119. transform: translateY(-50%);
  120. // This is an instant transition with a delay that ensures the checkmark
  121. // appears when menu is closed. Visibility property was used on purpose to
  122. // indicate that there is no actual transition, but instant shift from start
  123. // to end state with a delay.
  124. transition-property: visibility;
  125. transition-delay: menusurface-theme.$fade-out-duration;
  126. }
  127. }
  128. }
  129. // postcss-bem-linter: end
  130. .mdc-menu-item--selected .mdc-menu__selection-group-icon {
  131. @include feature-targeting.targets($feat-structure) {
  132. display: inline;
  133. visibility: visible;
  134. }
  135. }
  136. }
  137. @mixin open-item-opacity($opacity, $query: feature-targeting.all()) {
  138. $feat-color: feature-targeting.create-target($query, color);
  139. .mdc-menu-item--submenu-open {
  140. @include ripple-theme.states-background-selector(
  141. list-variables.$deprecated-ripple-target
  142. ) {
  143. @include feature-targeting.targets($feat-color) {
  144. opacity: $opacity;
  145. }
  146. }
  147. @include ripple-theme.states-background-selector(
  148. list-variables.$deprecated-temporary-ripple-target
  149. ) {
  150. @include feature-targeting.targets($feat-color) {
  151. opacity: $opacity;
  152. }
  153. }
  154. }
  155. }
  156. @mixin width($width, $query: feature-targeting.all()) {
  157. $feat-structure: feature-targeting.create-target($query, structure);
  158. @include feature-targeting.targets($feat-structure) {
  159. @if math.is-unitless($width) {
  160. width: $width * variables.$width-base;
  161. } @else {
  162. width: $width;
  163. }
  164. }
  165. }
  166. /// Sets the min-width of the menu.
  167. /// @param {Number} $min-width - the desired min-width.
  168. @mixin min-width($min-width, $query: feature-targeting.all()) {
  169. $feat-structure: feature-targeting.create-target($query, structure);
  170. @include feature-targeting.targets($feat-structure) {
  171. $min-width-custom-property: custom-properties.create(
  172. menu-custom-properties.$min-width,
  173. $min-width
  174. );
  175. @include theme.property(min-width, $min-width-custom-property);
  176. }
  177. }