Skip to content
This repository was archived by the owner on Jan 13, 2025. It is now read-only.

Commit ef276aa

Browse files
EstebanG23copybara-github
authored andcommitted
refactor(snackbar): Separate static styles to separate mixin in MDC
PiperOrigin-RevId: 459537423
1 parent 826a3d8 commit ef276aa

File tree

6 files changed

+455
-354
lines changed

6 files changed

+455
-354
lines changed

packages/mdc-snackbar/_mixins.scss

Lines changed: 4 additions & 315 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
//
2-
// Copyright 2018 Google Inc.
2+
// Copyright 2022 Google Inc.
33
//
44
// Permission is hereby granted, free of charge, to any person obtaining a copy
55
// of this software and associated documentation files (the "Software"), to deal
@@ -20,317 +20,6 @@
2020
// THE SOFTWARE.
2121
//
2222

23-
@use '@material/feature-targeting/feature-targeting';
24-
@use '@material/animation/functions' as animation-functions;
25-
@use '@material/button/button-theme';
26-
@use '@material/icon-button/icon-button-theme';
27-
@use '@material/ripple/ripple-theme';
28-
@use '@material/rtl/rtl';
29-
@use '@material/dom/mixins' as dom-mixins;
30-
@use '@material/typography/typography';
31-
@use '@material/elevation/mixins' as elevation-mixins;
32-
@use '@material/shape/mixins' as shape-mixins;
33-
@use '@material/theme/theme';
34-
@use './variables';
35-
36-
@mixin core-styles($query: feature-targeting.all()) {
37-
$feat-structure: feature-targeting.create-target($query, structure);
38-
$feat-animation: feature-targeting.create-target($query, animation);
39-
40-
// postcss-bem-linter: define snackbar
41-
.mdc-snackbar {
42-
@include z-index(variables.$z-index, $query: $query);
43-
@include viewport-margin(variables.$viewport-margin-narrow, $query: $query);
44-
45-
@include feature-targeting.targets($feat-structure) {
46-
display: none;
47-
position: fixed;
48-
right: 0;
49-
bottom: 0;
50-
left: 0;
51-
align-items: center;
52-
justify-content: center;
53-
box-sizing: border-box;
54-
55-
// Ignore mouse events on the root layout element.
56-
pointer-events: none;
57-
58-
// For some reason, iOS Safari displays a tap highlight on the entire snackbar element.
59-
// Mobile Safari only supports `rgba` values for this property; named values like
60-
// `transparent` are ignored. From Apple's docs:
61-
// > This property obeys the alpha value, if specified.
62-
// > If you don’t specify an alpha value, Safari on iOS applies a default alpha value to the color.
63-
// > To disable tap highlighting, set the alpha value to 0 (invisible).
64-
// > If you set the alpha value to 1.0 (opaque), the element is not visible when tapped.
65-
// See https://github.com/ben-eb/postcss-colormin/issues/1
66-
-webkit-tap-highlight-color: rgba(0, 0, 0, 0);
67-
}
68-
}
69-
70-
@include fill-color(variables.$fill-color, $query: $query);
71-
@include label-ink-color(variables.$label-ink-color, $query: $query);
72-
@include min-width(variables.$min-width, $query: $query);
73-
@include max-width(variables.$max-width, $query: $query);
74-
@include elevation(variables.$elevation, $query: $query);
75-
@include shape-radius(variables.$shape-radius, $query: $query);
76-
77-
.mdc-snackbar--opening,
78-
.mdc-snackbar--open,
79-
.mdc-snackbar--closing {
80-
@include feature-targeting.targets($feat-structure) {
81-
display: flex;
82-
}
83-
}
84-
85-
.mdc-snackbar--open .mdc-snackbar__label,
86-
.mdc-snackbar--open .mdc-snackbar__actions {
87-
@include feature-targeting.targets($feat-structure) {
88-
visibility: visible;
89-
}
90-
}
91-
92-
.mdc-snackbar--leading {
93-
@include position-leading($query: $query);
94-
}
95-
96-
.mdc-snackbar--stacked {
97-
@include layout-stacked($query: $query);
98-
}
99-
100-
.mdc-snackbar__surface {
101-
// 1px border around the snackbar surface for high contrast mode.
102-
&::before {
103-
@include dom-mixins.transparent-border($query: $query);
104-
}
105-
106-
@include feature-targeting.targets($feat-structure) {
107-
@include rtl.reflexive-property(padding, 0, variables.$padding);
108-
109-
display: flex;
110-
align-items: center;
111-
justify-content: flex-start;
112-
box-sizing: border-box;
113-
transform: scale(0.8);
114-
opacity: 0;
115-
}
116-
117-
.mdc-snackbar--open & {
118-
@include feature-targeting.targets($feat-structure) {
119-
transform: scale(1);
120-
opacity: 1;
121-
pointer-events: auto; // Allow mouse events on surface element while snackbar is open
122-
}
123-
124-
@include feature-targeting.targets($feat-animation) {
125-
transition: animation-functions.enter(
126-
opacity,
127-
variables.$enter-duration
128-
),
129-
animation-functions.enter(transform, variables.$enter-duration);
130-
}
131-
}
132-
133-
.mdc-snackbar--closing & {
134-
@include feature-targeting.targets($feat-structure) {
135-
transform: scale(1);
136-
}
137-
138-
@include feature-targeting.targets($feat-animation) {
139-
transition: animation-functions.exit-permanent(
140-
opacity,
141-
variables.$exit-duration
142-
);
143-
}
144-
}
145-
}
146-
147-
.mdc-snackbar__label {
148-
@include typography.typography(variables.$label-type-scale, $query: $query);
149-
150-
@include feature-targeting.targets($feat-structure) {
151-
@include rtl.reflexive-property(padding, 16px, variables.$padding);
152-
153-
width: 100%;
154-
flex-grow: 1;
155-
box-sizing: border-box;
156-
margin: 0;
157-
visibility: hidden;
158-
159-
// 14px top/bottom padding needed to make the height 48px.
160-
padding-top: 14px;
161-
padding-bottom: 14px;
162-
}
163-
}
164-
165-
// Used to prevent visual jank when announcing label text to screen readers.
166-
// See the `announce()` function in util.js for details.
167-
.mdc-snackbar__label::before {
168-
@include feature-targeting.targets($feat-structure) {
169-
display: inline;
170-
content: attr(data-mdc-snackbar-label-text);
171-
}
172-
}
173-
174-
.mdc-snackbar__actions {
175-
@include feature-targeting.targets($feat-structure) {
176-
display: flex;
177-
flex-shrink: 0;
178-
align-items: center;
179-
box-sizing: border-box;
180-
visibility: hidden;
181-
}
182-
}
183-
184-
.mdc-snackbar__action {
185-
@include button-theme.ink-color(
186-
variables.$action-ink-color,
187-
$query: $query
188-
);
189-
@include ripple-theme.states(
190-
variables.$action-ink-color,
191-
$ripple-target: button-theme.$ripple-target,
192-
$query: $query
193-
);
194-
}
195-
196-
.mdc-snackbar__dismiss {
197-
@include icon-button-theme.ink-color(
198-
variables.$dismiss-ink-color,
199-
$query: $query
200-
);
201-
}
202-
203-
// Two selectors are needed to increase specificity above `.material-icons`.
204-
// stylelint-disable-next-line selector-class-pattern
205-
.mdc-snackbar__dismiss.mdc-snackbar__dismiss {
206-
@include icon-button-theme.size(
207-
variables.$dismiss-button-size,
208-
$query: $query
209-
);
210-
@include feature-targeting.targets($feat-structure) {
211-
font-size: variables.$dismiss-icon-size;
212-
}
213-
}
214-
215-
.mdc-snackbar__action + .mdc-snackbar__dismiss {
216-
@include feature-targeting.targets($feat-structure) {
217-
@include rtl.reflexive-property(margin, variables.$padding, 0);
218-
}
219-
}
220-
// postcss-bem-linter: end
221-
}
222-
223-
@mixin fill-color($color, $query: feature-targeting.all()) {
224-
$feat-color: feature-targeting.create-target($query, color);
225-
226-
.mdc-snackbar__surface {
227-
@include feature-targeting.targets($feat-color) {
228-
@include theme.property(background-color, $color);
229-
}
230-
}
231-
}
232-
233-
@mixin label-ink-color($color, $query: feature-targeting.all()) {
234-
$feat-color: feature-targeting.create-target($query, color);
235-
236-
.mdc-snackbar__label {
237-
@include feature-targeting.targets($feat-color) {
238-
@include theme.property(color, $color);
239-
}
240-
}
241-
}
242-
243-
@mixin shape-radius(
244-
$radius,
245-
$rtl-reflexive: false,
246-
$query: feature-targeting.all()
247-
) {
248-
.mdc-snackbar__surface {
249-
@include shape-mixins.radius($radius, $rtl-reflexive, $query: $query);
250-
}
251-
}
252-
253-
@mixin min-width(
254-
$min-width,
255-
$mobile-breakpoint: variables.$mobile-breakpoint,
256-
$query: feature-targeting.all()
257-
) {
258-
$feat-structure: feature-targeting.create-target($query, structure);
259-
260-
.mdc-snackbar__surface {
261-
@include feature-targeting.targets($feat-structure) {
262-
min-width: $min-width;
263-
264-
// The first media query ensures that snackbars are always 100% width on mobile devices, as required by the spec.
265-
// The second media query prevents snackbars from being wider than the viewport for large min-width values.
266-
@media (max-width: $mobile-breakpoint), (max-width: $min-width) {
267-
min-width: 100%;
268-
}
269-
}
270-
}
271-
}
272-
273-
@mixin max-width($max-width, $query: feature-targeting.all()) {
274-
$feat-structure: feature-targeting.create-target($query, structure);
275-
276-
.mdc-snackbar__surface {
277-
@include feature-targeting.targets($feat-structure) {
278-
max-width: $max-width;
279-
}
280-
}
281-
}
282-
283-
@mixin elevation($z-index, $query: feature-targeting.all()) {
284-
.mdc-snackbar__surface {
285-
@include elevation-mixins.elevation($z-index, $query: $query);
286-
}
287-
}
288-
289-
@mixin viewport-margin($margin, $query: feature-targeting.all()) {
290-
$feat-structure: feature-targeting.create-target($query, structure);
291-
292-
@include feature-targeting.targets($feat-structure) {
293-
margin: $margin;
294-
}
295-
}
296-
297-
@mixin z-index($z-index, $query: feature-targeting.all()) {
298-
$feat-structure: feature-targeting.create-target($query, structure);
299-
300-
@include feature-targeting.targets($feat-structure) {
301-
z-index: $z-index;
302-
}
303-
}
304-
305-
@mixin position-leading($query: feature-targeting.all()) {
306-
$feat-structure: feature-targeting.create-target($query, structure);
307-
308-
@include feature-targeting.targets($feat-structure) {
309-
justify-content: flex-start;
310-
}
311-
}
312-
313-
@mixin layout-stacked($query: feature-targeting.all()) {
314-
$feat-structure: feature-targeting.create-target($query, structure);
315-
316-
.mdc-snackbar__label {
317-
@include feature-targeting.targets($feat-structure) {
318-
@include rtl.reflexive-property(padding, 16px, 8px);
319-
padding-bottom: 12px;
320-
}
321-
}
322-
323-
.mdc-snackbar__surface {
324-
@include feature-targeting.targets($feat-structure) {
325-
flex-direction: column;
326-
align-items: flex-start;
327-
}
328-
}
329-
330-
.mdc-snackbar__actions {
331-
@include feature-targeting.targets($feat-structure) {
332-
align-self: flex-end;
333-
margin-bottom: variables.$padding;
334-
}
335-
}
336-
}
23+
/// @deprecated Import './snackbar' or './snackbar-theme' instead.
24+
@forward './snackbar' show core-styles;
25+
@forward './snackbar-theme' show fill-color, label-ink-color, shape-radius, min-width, max-width, elevation, viewport-margin, z-index, position-leading, layout-stacked;

0 commit comments

Comments
 (0)