UNPKG

6.74 kBSCSSView Raw
1// Copyright 2018 Google Inc.
2//
3// Permission is hereby granted, free of charge, to any person obtaining a copy
4// of this software and associated documentation files (the "Software"), to deal
5// in the Software without restriction, including without limitation the rights
6// to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
7// copies of the Software, and to permit persons to whom the Software is
8// furnished to do so, subject to the following conditions:
9//
10// The above copyright notice and this permission notice shall be included in
11// all copies or substantial portions of the Software.
12//
13// THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
14// IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
15// FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
16// AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
17// LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
18// OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
19// THE SOFTWARE.
20
21@use 'sass:math';
22@use '@material/feature-targeting/feature-targeting';
23@use '@material/shape/mixins' as shape-mixins;
24@use '@material/shape/functions' as shape-functions;
25@use '@material/theme/theme';
26@use '@material/typography/typography';
27@use './variables';
28
29@mixin core-styles($query: feature-targeting.all()) {
30 $feat-color: feature-targeting.create-target($query, color);
31 $feat-structure: feature-targeting.create-target($query, structure);
32
33 // postcss-bem-linter: define image-list
34 .mdc-image-list {
35 @include feature-targeting.targets($feat-structure) {
36 display: flex;
37 flex-wrap: wrap;
38 // Margin and padding are set to override default user agent styles for lists, and also to center the Image List
39 margin: 0 auto;
40 padding: 0;
41 }
42 }
43
44 .mdc-image-list__item,
45 .mdc-image-list__image-aspect-container {
46 @include feature-targeting.targets($feat-structure) {
47 // Supports absolute positioning of protected supporting content for item, and image for image-aspect-container
48 position: relative;
49 box-sizing: border-box;
50 }
51 }
52
53 .mdc-image-list__item {
54 @include feature-targeting.targets($feat-structure) {
55 list-style-type: none;
56 }
57 }
58
59 .mdc-image-list__image {
60 @include feature-targeting.targets($feat-structure) {
61 width: 100%;
62 }
63 }
64
65 // Descendant selector allows image-aspect-container to be optional in DOM structure
66 .mdc-image-list__image-aspect-container .mdc-image-list__image {
67 @include feature-targeting.targets($feat-structure) {
68 position: absolute;
69 top: 0;
70 right: 0;
71 bottom: 0;
72 left: 0;
73 height: 100%;
74 // Background styles to support div instead of img
75 background-repeat: no-repeat;
76 background-position: center;
77 background-size: cover;
78 }
79 }
80
81 @include aspect(1, $query: $query);
82 @include shape-radius(variables.$shape-radius, $query: $query);
83
84 .mdc-image-list__supporting {
85 @include feature-targeting.targets($feat-color) {
86 @include theme.property(color, text-primary-on-background);
87 }
88
89 @include feature-targeting.targets($feat-structure) {
90 display: flex;
91 align-items: center;
92 justify-content: space-between;
93 box-sizing: border-box;
94 padding: 8px 0;
95 line-height: variables.$icon-size;
96 }
97 }
98
99 .mdc-image-list__label {
100 @include typography.typography(subtitle1, $query: $query);
101 @include typography.overflow-ellipsis($query: $query);
102 }
103
104 // Modifier for labels/icons with text protection, overlaying images.
105
106 .mdc-image-list--with-text-protection .mdc-image-list__supporting {
107 @include feature-targeting.targets($feat-structure) {
108 position: absolute;
109 bottom: 0;
110 width: 100%;
111 height: variables.$text-protection-height;
112 padding: 0 variables.$text-protection-horizontal-padding;
113 }
114
115 @include feature-targeting.targets($feat-color) {
116 background: variables.$text-protection-background-color;
117 color: #fff;
118 }
119 }
120
121 // Masonry Image List, using CSS columns (i.e. renders down then across)
122
123 .mdc-image-list--masonry {
124 @include feature-targeting.targets($feat-structure) {
125 display: block; // Override flex
126 }
127
128 .mdc-image-list__item {
129 @include feature-targeting.targets($feat-structure) {
130 break-inside: avoid-column;
131 }
132 }
133
134 .mdc-image-list__image {
135 @include feature-targeting.targets($feat-structure) {
136 display: block;
137 height: auto;
138 }
139 }
140 }
141 // postcss-bem-linter: end
142}
143
144@mixin aspect($width-height-ratio, $query: feature-targeting.all()) {
145 $feat-structure: feature-targeting.create-target($query, structure);
146
147 .mdc-image-list__image-aspect-container {
148 @include feature-targeting.targets($feat-structure) {
149 padding-bottom: calc(100% / #{$width-height-ratio});
150 }
151 }
152}
153
154@mixin shape-radius(
155 $radius,
156 $rtl-reflexive: false,
157 $query: feature-targeting.all()
158) {
159 .mdc-image-list__image {
160 @include shape-mixins.radius($radius, $rtl-reflexive, $query: $query);
161 }
162
163 $selector: if(
164 &,
165 '&.mdc-image-list--with-text-protection',
166 '.mdc-image-list--with-text-protection'
167 );
168
169 #{$selector} .mdc-image-list__supporting {
170 $masked-radius: shape-functions.mask-radius($radius, 0 0 1 1);
171
172 @include shape-mixins.radius(
173 $masked-radius,
174 $rtl-reflexive,
175 $query: $query
176 );
177 }
178}
179
180// Standard Image List
181
182@mixin standard-columns(
183 $column-count,
184 $gutter-size: variables.$standard-gutter-size,
185 $query: feature-targeting.all()
186) {
187 $feat-structure: feature-targeting.create-target($query, structure);
188
189 // This uses margin rather than padding to facilitate properly positioning the supporting content element when
190 // --with-text-protection is used.
191 .mdc-image-list__item {
192 @include feature-targeting.targets($feat-structure) {
193 // Subtract extra fraction from each item's width to ensure correct wrapping in IE/Edge which round differently
194 width: calc(
195 100% / #{$column-count} - #{$gutter-size + math.div(1, $column-count)}
196 );
197 margin: math.div($gutter-size, 2);
198 }
199 }
200}
201
202// Masonry Image List
203
204@mixin masonry-columns(
205 $column-count,
206 $gutter-size: variables.$masonry-gutter-size,
207 $query: feature-targeting.all()
208) {
209 $feat-structure: feature-targeting.create-target($query, structure);
210
211 @include feature-targeting.targets($feat-structure) {
212 column-count: $column-count;
213 column-gap: $gutter-size;
214 }
215
216 .mdc-image-list__item {
217 @include feature-targeting.targets($feat-structure) {
218 margin-bottom: $gutter-size;
219 }
220 }
221}