|
1 | | -@use '@material/snackbar/snackbar' as mdc-snackbar; |
2 | | -@use '@material/snackbar/snackbar-theme' as mdc-snackbar-theme; |
3 | | -@use '@material/theme/custom-properties' as mdc-custom-properties; |
| 1 | +@use '@angular/cdk'; |
4 | 2 | @use '../core/tokens/m2/mdc/snack-bar' as tokens-mdc-snack-bar; |
5 | 3 | @use '../core/tokens/m2/mat/snack-bar' as tokens-mat-snack-bar; |
6 | 4 | @use '../core/tokens/m2/mat/text-button' as tokens-mat-text-button; |
7 | 5 | @use '../core/tokens/token-utils'; |
8 | | -@use '../core/mdc-helpers/mdc-helpers'; |
9 | | - |
10 | | -@mixin _container-min-width { |
11 | | - $min-width: mdc-snackbar-theme.$min-width; |
12 | | - $mobile-breakpoint: mdc-snackbar-theme.$mobile-breakpoint; |
13 | | - |
14 | | - // The styles weren't included in `static-styles` so we need to add them ourselves. |
15 | | - @include mdc-snackbar-theme.min-width( |
16 | | - $min-width: $min-width, |
17 | | - $mobile-breakpoint: $mobile-breakpoint, |
18 | | - $query: mdc-helpers.$mdc-base-styles-query |
19 | | - ); |
20 | | - |
21 | | - // The MDC `min-width` mixin has a similar breakpoint that sets `min-width: 100%` on the surface |
22 | | - // element to make it span the entire viewport, however it ends up collapsing because the |
23 | | - // container is `width: auto`. This query ensures that the surface will span the whole viewport. |
24 | | - @media (max-width: $mobile-breakpoint), (max-width: $min-width) { |
| 6 | +@use '../core/style/elevation'; |
| 7 | + |
| 8 | +$_side-padding: 8px; |
| 9 | + |
| 10 | +.mat-mdc-snack-bar-container { |
| 11 | + display: flex; |
| 12 | + align-items: center; |
| 13 | + justify-content: center; |
| 14 | + box-sizing: border-box; |
| 15 | + -webkit-tap-highlight-color: rgba(0, 0, 0, 0); |
| 16 | + margin: 8px; |
| 17 | + |
| 18 | + .mat-mdc-snack-bar-handset & { |
25 | 19 | width: 100vw; |
26 | 20 | } |
27 | 21 | } |
28 | 22 |
|
29 | | -@include mdc-custom-properties.configure($emit-fallback-values: false, $emit-fallback-vars: false) { |
30 | | - // Include the styles without the animations since we |
31 | | - // reuse the same animation as the non-MDC version. |
32 | | - @include mdc-snackbar.static-styles($query: mdc-helpers.$mdc-base-styles-without-animation-query); |
33 | | - |
34 | | - .mat-mdc-snack-bar-container { |
35 | | - @include _container-min-width; |
36 | | - @include mdc-snackbar-theme.max-width( |
37 | | - mdc-snackbar-theme.$max-width, |
38 | | - $query: mdc-helpers.$mdc-base-styles-query |
39 | | - ); |
40 | | - @include mdc-snackbar-theme.viewport-margin( |
41 | | - mdc-snackbar-theme.$viewport-margin-narrow, |
42 | | - $query: mdc-helpers.$mdc-base-styles-query |
43 | | - ); |
44 | | - |
45 | | - // MDC has the `container-elevation` which sounds like it should work, but it ends up applying |
46 | | - // the shadow on the outer container instead of the `.mdc-snackbar__surface` which causes |
47 | | - // a white background behind the rounded corners, because the `border-radius` is on the |
48 | | - // surface element. |
49 | | - @include mdc-snackbar-theme.elevation(mdc-snackbar-theme.$elevation); |
50 | | - @include mdc-snackbar-theme.theme-styles(tokens-mdc-snack-bar.get-token-slots()); |
51 | | - |
52 | | - // MDC sets the position as fixed and sets the container on the bottom center of the page (or |
53 | | - // otherwise can be set to be "leading"). Our overlay handles a more advanced configuration |
54 | | - // of positions, so we'll defer logic there. |
55 | | - position: static; |
56 | | - |
57 | | - // The `mat-mdc-button` and `:not(:disabled)` here are redundant, but we need them to increase |
58 | | - // the specificity over the button styles that may bleed in from the rest of the app. |
59 | | - .mat-mdc-button.mat-mdc-snack-bar-action:not(:disabled) { |
60 | | - // MDC's `action-label-text-color` should be able to do this, but the button theme has a |
61 | | - // higher specificity so it ends up overriding it. Define our own variable that we can |
62 | | - // use to control the color instead. |
63 | | - @include token-utils.use-tokens( |
64 | | - tokens-mat-snack-bar.$prefix, |
65 | | - tokens-mat-snack-bar.get-token-slots() |
66 | | - ) { |
67 | | - @include token-utils.create-token-slot(color, button-color); |
68 | | - } |
69 | | - |
70 | | - // Darken the ripples in the button so they're visible against the dark background. |
71 | | - @include token-utils.create-token-values(tokens-mat-text-button.$prefix, ( |
72 | | - state-layer-color: currentColor, |
73 | | - ripple-color: currentColor, |
74 | | - )); |
75 | | - |
76 | | - .mat-ripple-element { |
77 | | - opacity: 0.1; |
78 | | - } |
| 23 | +.mat-mdc-snackbar-surface { |
| 24 | + @include elevation.elevation(6); |
| 25 | + display: flex; |
| 26 | + align-items: center; |
| 27 | + justify-content: flex-start; |
| 28 | + box-sizing: border-box; |
| 29 | + padding-left: 0; |
| 30 | + padding-right: $_side-padding; |
| 31 | + |
| 32 | + [dir='rtl'] & { |
| 33 | + padding-right: 0; |
| 34 | + padding-left: $_side-padding; |
| 35 | + } |
| 36 | + |
| 37 | + .mat-mdc-snack-bar-container & { |
| 38 | + min-width: 344px; |
| 39 | + max-width: 672px; |
| 40 | + } |
| 41 | + |
| 42 | + // Ensures that the snack bar stretches to full width in handset mode. |
| 43 | + .mat-mdc-snack-bar-handset & { |
| 44 | + width: 100%; |
| 45 | + min-width: 0; |
| 46 | + } |
| 47 | + |
| 48 | + @include cdk.high-contrast(active, off) { |
| 49 | + outline: solid 1px; |
| 50 | + } |
| 51 | + |
| 52 | + @include token-utils.use-tokens( |
| 53 | + tokens-mdc-snack-bar.$prefix, |
| 54 | + tokens-mdc-snack-bar.get-token-slots() |
| 55 | + ) { |
| 56 | + .mat-mdc-snack-bar-container & { |
| 57 | + @include token-utils.create-token-slot(color, supporting-text-color); |
| 58 | + @include token-utils.create-token-slot(border-radius, container-shape); |
| 59 | + @include token-utils.create-token-slot(background-color, container-color); |
79 | 60 | } |
| 61 | + } |
| 62 | +} |
| 63 | + |
| 64 | +.mdc-snackbar__label { |
| 65 | + width: 100%; |
| 66 | + flex-grow: 1; |
| 67 | + box-sizing: border-box; |
| 68 | + margin: 0; |
| 69 | + padding: 14px $_side-padding 14px 16px; |
80 | 70 |
|
81 | | - // MDC uses this pseudo element to work around an issue with their live announcer, but it |
82 | | - // can cause additional space for long snack bar messages (see #26685). Since we don't use |
83 | | - // MDC's announcer, we can hide the element. |
84 | | - .mdc-snackbar__label::before { |
85 | | - display: none; |
| 71 | + [dir='rtl'] & { |
| 72 | + padding-left: $_side-padding; |
| 73 | + padding-right: 16px; |
| 74 | + } |
| 75 | + |
| 76 | + @include token-utils.use-tokens( |
| 77 | + tokens-mdc-snack-bar.$prefix, |
| 78 | + tokens-mdc-snack-bar.get-token-slots() |
| 79 | + ) { |
| 80 | + .mat-mdc-snack-bar-container & { |
| 81 | + @include token-utils.create-token-slot(font-family, supporting-text-font); |
| 82 | + @include token-utils.create-token-slot(font-size, supporting-text-size); |
| 83 | + @include token-utils.create-token-slot(font-weight, supporting-text-weight); |
| 84 | + @include token-utils.create-token-slot(line-height, supporting-text-line-height); |
86 | 85 | } |
87 | 86 | } |
88 | 87 | } |
89 | 88 |
|
| 89 | +.mat-mdc-snack-bar-actions { |
| 90 | + display: flex; |
| 91 | + flex-shrink: 0; |
| 92 | + align-items: center; |
| 93 | + box-sizing: border-box; |
| 94 | +} |
| 95 | + |
90 | 96 | // These elements need to have full width using flex layout. |
91 | 97 | .mat-mdc-snack-bar-handset, |
92 | 98 | .mat-mdc-snack-bar-container, |
|
96 | 102 | flex: 1 1 auto; |
97 | 103 | } |
98 | 104 |
|
99 | | -// Ensures that the snack bar stretches to full width in handset mode. |
100 | | -.mat-mdc-snack-bar-handset .mdc-snackbar__surface { |
101 | | - width: 100%; |
| 105 | +// The `mat-mdc-button` and `:not(:disabled)` here are redundant, but we need them to increase |
| 106 | +// the specificity over the button styles that may bleed in from the rest of the app. |
| 107 | +.mat-mdc-snack-bar-container .mat-mdc-button.mat-mdc-snack-bar-action:not(:disabled) { |
| 108 | + // MDC's `action-label-text-color` should be able to do this, but the button theme has a |
| 109 | + // higher specificity so it ends up overriding it. Define our own variable that we can |
| 110 | + // use to control the color instead. |
| 111 | + @include token-utils.use-tokens( |
| 112 | + tokens-mat-snack-bar.$prefix, |
| 113 | + tokens-mat-snack-bar.get-token-slots() |
| 114 | + ) { |
| 115 | + @include token-utils.create-token-slot(color, button-color); |
| 116 | + } |
| 117 | + |
| 118 | + // Darken the ripples in the button so they're visible against the dark background. |
| 119 | + @include token-utils.create-token-values(tokens-mat-text-button.$prefix, ( |
| 120 | + state-layer-color: currentColor, |
| 121 | + ripple-color: currentColor, |
| 122 | + )); |
| 123 | + |
| 124 | + .mat-ripple-element { |
| 125 | + opacity: 0.1; |
| 126 | + } |
102 | 127 | } |
0 commit comments