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

Commit a0b2db2

Browse files
EstebanG23copybara-github
authored andcommitted
feat(banner): Add mobile-stacked variant support to banner.
PiperOrigin-RevId: 340543964
1 parent fc8b045 commit a0b2db2

File tree

3 files changed

+53
-15
lines changed

3 files changed

+53
-15
lines changed

packages/mdc-banner/README.md

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,25 @@ Banners may have one or two low-emphasis text buttons.
172172
</div>
173173
```
174174

175+
176+
#### Mobile Stacked
177+
178+
On mobile view, banners with long text should have their action(s) be positioned _below_ the text instead of alongside it. This can be accomplished by adding the `mdc-banner--mobile-stacked` modifier class to the root element:
179+
180+
```html
181+
<div class="mdc-banner mdc-banner--mobile-stacked">
182+
...
183+
</div>
184+
```
185+
186+
Alternatively, you can call the `mobile-stacked` mixin from Sass:
187+
188+
```scss
189+
.my-banner {
190+
@include banner.mobile-stacked;
191+
}
192+
```
193+
175194
## API
176195

177196
### Sass mixins

packages/mdc-banner/_banner-theme.scss

Lines changed: 29 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@
2121
//
2222

2323
@use '@material/feature-targeting/feature-targeting';
24+
@use '@material/rtl/mixins' as rtl-mixins;
2425
@use '@material/shape/mixins' as shape-mixins;
2526
@use '@material/theme/theme';
2627
@use '@material/theme/theme-color';
@@ -187,6 +188,34 @@ $z-index: 1;
187188
}
188189
}
189190

191+
///
192+
/// Sets the banner content to centered instead of leading.
193+
///
194+
@mixin mobile-stacked($query: feature-targeting.all()) {
195+
$feat-structure: feature-targeting.create-target($query, structure);
196+
197+
@include feature-targeting.targets($feat-structure) {
198+
@media (max-width: $mobile-breakpoint) {
199+
.mdc-banner__content {
200+
flex-wrap: wrap;
201+
}
202+
203+
.mdc-banner__graphic {
204+
margin-bottom: 12px;
205+
}
206+
207+
.mdc-banner__text {
208+
@include rtl-mixins.reflexive-property(margin, 16px, 8px);
209+
padding-bottom: 4px;
210+
}
211+
212+
.mdc-banner__actions {
213+
margin-left: auto;
214+
}
215+
}
216+
}
217+
}
218+
190219
// Sets the z-index of the banner.
191220
// @param {Number} $z-index
192221
@mixin z-index($z-index, $query: feature-targeting.all()) {

packages/mdc-banner/_banner.scss

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -75,22 +75,8 @@ $_exit-duration: 250ms;
7575
right: 0;
7676
}
7777

78-
.mdc-banner__content {
79-
flex-wrap: wrap;
80-
}
81-
82-
.mdc-banner__graphic {
83-
margin-bottom: 12px;
84-
}
85-
8678
.mdc-banner__text {
87-
margin-left: 16px;
88-
margin-right: 8px;
89-
padding-bottom: 4px;
90-
}
91-
92-
.mdc-banner__actions {
93-
margin-left: auto;
79+
@include rtl-mixins.reflexive-property(margin, 16px, 36px);
9480
}
9581
}
9682

@@ -103,6 +89,10 @@ $_exit-duration: 250ms;
10389
position: relative;
10490
width: 100%;
10591
}
92+
93+
&.mdc-banner--mobile-stacked {
94+
@include banner-theme.mobile-stacked($query: $query);
95+
}
10696
}
10797

10898
.mdc-banner--opening,

0 commit comments

Comments
 (0)