_snackbar.scss 7.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242
  1. //
  2. // Copyright 2022 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/animation/functions' as animation-functions;
  25. @use '@material/button/button-theme';
  26. @use '@material/dom/mixins' as dom-mixins;
  27. @use '@material/feature-targeting/feature-targeting';
  28. @use '@material/icon-button/icon-button-theme';
  29. @use '@material/ripple/ripple-theme';
  30. @use '@material/rtl/rtl';
  31. @use '@material/typography/typography';
  32. @use './snackbar-theme';
  33. @mixin core-styles($query: feature-targeting.all()) {
  34. $feat-structure: feature-targeting.create-target($query, structure);
  35. @include snackbar-theme.fill-color(
  36. snackbar-theme.$fill-color,
  37. $query: $query
  38. );
  39. @include snackbar-theme.label-ink-color(
  40. snackbar-theme.$label-ink-color,
  41. $query: $query
  42. );
  43. @include snackbar-theme.min-width(snackbar-theme.$min-width, $query: $query);
  44. @include snackbar-theme.max-width(snackbar-theme.$max-width, $query: $query);
  45. @include snackbar-theme.elevation(snackbar-theme.$elevation, $query: $query);
  46. @include snackbar-theme.shape-radius(
  47. snackbar-theme.$shape-radius,
  48. $query: $query
  49. );
  50. @include static-styles($query);
  51. .mdc-snackbar {
  52. @include snackbar-theme.z-index(snackbar-theme.$z-index, $query: $query);
  53. @include snackbar-theme.viewport-margin(
  54. snackbar-theme.$viewport-margin-narrow,
  55. $query: $query
  56. );
  57. }
  58. .mdc-snackbar--stacked {
  59. @include snackbar-theme.layout-stacked($query: $query);
  60. }
  61. .mdc-snackbar--leading {
  62. @include snackbar-theme.position-leading($query: $query);
  63. }
  64. .mdc-snackbar__label {
  65. @include typography.typography(
  66. snackbar-theme.$label-type-scale,
  67. $query: $query
  68. );
  69. }
  70. .mdc-snackbar__action {
  71. @include button-theme.ink-color(
  72. snackbar-theme.$action-ink-color,
  73. $query: $query
  74. );
  75. @include ripple-theme.states(
  76. snackbar-theme.$action-ink-color,
  77. $ripple-target: button-theme.$ripple-target,
  78. $query: $query
  79. );
  80. }
  81. .mdc-snackbar__dismiss {
  82. @include icon-button-theme.ink-color(
  83. snackbar-theme.$dismiss-ink-color,
  84. $query: $query
  85. );
  86. }
  87. // Two selectors are needed to increase specificity above `.material-icons`.
  88. .mdc-snackbar__dismiss.mdc-snackbar__dismiss {
  89. @include icon-button-theme.size(
  90. snackbar-theme.$dismiss-button-size,
  91. $query: $query
  92. );
  93. @include feature-targeting.targets($feat-structure) {
  94. font-size: snackbar-theme.$dismiss-icon-size;
  95. }
  96. }
  97. }
  98. @mixin static-styles($query: feature-targeting.all()) {
  99. $feat-structure: feature-targeting.create-target($query, structure);
  100. $feat-animation: feature-targeting.create-target($query, animation);
  101. .mdc-snackbar {
  102. @include feature-targeting.targets($feat-structure) {
  103. display: none;
  104. position: fixed;
  105. right: 0;
  106. bottom: 0;
  107. left: 0;
  108. align-items: center;
  109. justify-content: center;
  110. box-sizing: border-box;
  111. // Ignore mouse events on the root layout element.
  112. pointer-events: none;
  113. // For some reason, iOS Safari displays a tap highlight on the entire snackbar element.
  114. // Mobile Safari only supports `rgba` values for this property; named values like
  115. // `transparent` are ignored. From Apple's docs:
  116. // > This property obeys the alpha value, if specified.
  117. // > If you don’t specify an alpha value, Safari on iOS applies a default alpha value to the color.
  118. // > To disable tap highlighting, set the alpha value to 0 (invisible).
  119. // > If you set the alpha value to 1.0 (opaque), the element is not visible when tapped.
  120. // See https://github.com/ben-eb/postcss-colormin/issues/1
  121. -webkit-tap-highlight-color: rgba(0, 0, 0, 0);
  122. }
  123. }
  124. .mdc-snackbar--opening,
  125. .mdc-snackbar--open,
  126. .mdc-snackbar--closing {
  127. @include feature-targeting.targets($feat-structure) {
  128. display: flex;
  129. }
  130. }
  131. .mdc-snackbar--open .mdc-snackbar__label,
  132. .mdc-snackbar--open .mdc-snackbar__actions {
  133. @include feature-targeting.targets($feat-structure) {
  134. visibility: visible;
  135. }
  136. }
  137. .mdc-snackbar__surface {
  138. // 1px border around the snackbar surface for high contrast mode.
  139. &::before {
  140. @include dom-mixins.transparent-border($query: $query);
  141. }
  142. @include feature-targeting.targets($feat-structure) {
  143. @include rtl.reflexive-property(padding, 0, snackbar-theme.$padding);
  144. display: flex;
  145. align-items: center;
  146. justify-content: flex-start;
  147. box-sizing: border-box;
  148. transform: scale(0.8);
  149. opacity: 0;
  150. }
  151. .mdc-snackbar--open & {
  152. @include feature-targeting.targets($feat-structure) {
  153. transform: scale(1);
  154. opacity: 1;
  155. pointer-events: auto; // Allow mouse events on surface element while snackbar is open
  156. }
  157. @include feature-targeting.targets($feat-animation) {
  158. transition: animation-functions.enter(
  159. opacity,
  160. snackbar-theme.$enter-duration
  161. ),
  162. animation-functions.enter(transform, snackbar-theme.$enter-duration);
  163. }
  164. }
  165. .mdc-snackbar--closing & {
  166. @include feature-targeting.targets($feat-structure) {
  167. transform: scale(1);
  168. }
  169. @include feature-targeting.targets($feat-animation) {
  170. transition: animation-functions.exit-permanent(
  171. opacity,
  172. snackbar-theme.$exit-duration
  173. );
  174. }
  175. }
  176. }
  177. .mdc-snackbar__label {
  178. @include feature-targeting.targets($feat-structure) {
  179. @include rtl.reflexive-property(padding, 16px, snackbar-theme.$padding);
  180. width: 100%;
  181. flex-grow: 1;
  182. box-sizing: border-box;
  183. margin: 0;
  184. visibility: hidden;
  185. // 14px top/bottom padding needed to make the height 48px.
  186. padding-top: 14px;
  187. padding-bottom: 14px;
  188. }
  189. }
  190. // Used to prevent visual jank when announcing label text to screen readers.
  191. // See the `announce()` function in util.js for details.
  192. .mdc-snackbar__label::before {
  193. @include feature-targeting.targets($feat-structure) {
  194. display: inline;
  195. content: attr(data-mdc-snackbar-label-text);
  196. }
  197. }
  198. .mdc-snackbar__actions {
  199. @include feature-targeting.targets($feat-structure) {
  200. display: flex;
  201. flex-shrink: 0;
  202. align-items: center;
  203. box-sizing: border-box;
  204. visibility: hidden;
  205. }
  206. }
  207. .mdc-snackbar__action + .mdc-snackbar__dismiss {
  208. @include feature-targeting.targets($feat-structure) {
  209. @include rtl.reflexive-property(margin, snackbar-theme.$padding, 0);
  210. }
  211. }
  212. }