diff --git a/demos/image-list.html b/demos/image-list.html index e6aee34200d..0ff2f60b0ce 100644 --- a/demos/image-list.html +++ b/demos/image-list.html @@ -304,6 +304,132 @@

Standard Image List

+ +

Masonry Image List

+
+
+
+ +
+
+
+
+
+ +
+
+
+ +
+
+
+
+
+ +
+
+
+ +
+
+
+
+
+ +
+
+ @@ -327,6 +453,7 @@

Standard Image List

}); var standardImageListEl = document.getElementById('standard-image-list'); + var masonryImageListEl = document.getElementById('masonry-image-list'); document.getElementById('standard-label-below').addEventListener('change', function() { standardImageListEl.classList[this.checked ? 'remove' : 'add']('mdc-image-list--with-text-protection'); @@ -342,6 +469,21 @@

Standard Image List

standardImageListEl.classList[this.checked ? 'remove' : 'add']('mdc-image-list--with-text-protection'); standardImageListEl.classList[this.checked ? 'add' : 'remove']('hide-supporting'); }); + + document.getElementById('masonry-label-below').addEventListener('change', function() { + masonryImageListEl.classList[this.checked ? 'remove' : 'add']('mdc-image-list--with-text-protection'); + masonryImageListEl.classList[this.checked ? 'remove' : 'add']('hide-supporting'); + }); + + document.getElementById('masonry-label-protected').addEventListener('change', function() { + masonryImageListEl.classList[this.checked ? 'add' : 'remove']('mdc-image-list--with-text-protection'); + masonryImageListEl.classList[this.checked ? 'remove' : 'add']('hide-supporting'); + }); + + document.getElementById('masonry-label-none').addEventListener('change', function() { + masonryImageListEl.classList[this.checked ? 'remove' : 'add']('mdc-image-list--with-text-protection'); + masonryImageListEl.classList[this.checked ? 'add' : 'remove']('hide-supporting'); + }); }); diff --git a/demos/image-list.scss b/demos/image-list.scss index dc9e7b583a3..d9516b4e8dd 100644 --- a/demos/image-list.scss +++ b/demos/image-list.scss @@ -37,6 +37,11 @@ max-width: 1000px; } +.mdc-image-list.masonry-image-list { + @include mdc-image-list-masonry-columns(5); + max-width: 1000px; +} + .hide-supporting .mdc-image-list__supporting { display: none; } @@ -49,4 +54,8 @@ .mdc-image-list.standard-image-list { @include mdc-image-list-standard-columns(3); } + + .mdc-image-list.masonry-image-list { + @include mdc-image-list-masonry-columns(3); + } } diff --git a/packages/mdc-image-list/README.md b/packages/mdc-image-list/README.md index b7d909cea16..77d43d55cda 100644 --- a/packages/mdc-image-list/README.md +++ b/packages/mdc-image-list/README.md @@ -71,6 +71,38 @@ columns should be displayed per line: Images in a Standard Image list are constrained to 1:1 aspect ratio by default; this can be overridden using the `mdc-image-list-aspect` mixin documented below. +## Variants + +### Masonry Image List + +The Masonry Image List variant presents images vertically arranged into several columns, using +[CSS Columns](https://developer.mozilla.org/en-US/docs/Web/CSS/CSS_Columns). In this layout, images may be any +combination of aspect ratios. + +```html + +``` + +> **Note:** Masonry Image List items _do not_ include the `mdc-image-list__image-aspect-container` element, since +images in the list are not expected to be locked to a common aspect ratio. + +This would be combined with an invocation of the `mdc-image-list-masonry-columns` mixin, to establish how many columns +should be displayed: + +```scss +.my-masonry-image-list { + @include mdc-image-list-masonry-columns(5); +} +``` + ## Style Customization ### CSS Classes @@ -78,6 +110,7 @@ Images in a Standard Image list are constrained to 1:1 aspect ratio by default; CSS Class | Description --- | --- `mdc-image-list` | Mandatory. Indicates the root Image List element. +`mdc-image-list--masonry` | Optional. Indicates that this Image List should use the Masonry variant. `mdc-image-list--with-text-protection` | Optional. Indicates that supporting content should be positioned in a scrim overlaying each image (instead of positioned separately under each image). `mdc-image-list__item` | Mandatory. Indicates each item in an Image List. `mdc-image-list__image-aspect-container` | Optional. Parent of each item's image element, responsible for constraining aspect ratio. This element may be omitted entirely if images are already sized to the correct aspect ratio. @@ -92,12 +125,16 @@ Mixin | Description `mdc-image-list-aspect($width-height-ratio)` | Styles the aspect container elements within an Image List to conform to the given ratio, where 1 is 1:1, greater than 1 is wider, and less than 1 is taller. `mdc-image-list-corner-radius($radius)` | Styles the image and supporting content elements within an Image List to have rounded corners with the given radius. `mdc-image-list-standard-columns($column-count, $gutter-size)` | Styles a Standard Image List to display the given number of columns. `$gutter-size` is optional and overrides the default amount of space between items. +`mdc-image-list-masonry-columns($column-count, $gutter-size)` | Styles a Masonry Image List to display the given number of columns. `$gutter-size` is optional and overrides the default amount of space between items. + +> **Note:** Only one of the `mdc-image-list-...-columns` mixins should be used for any given Image List. +> Use the mixin appropriate to the variant being used. ### Additional Information #### Constraining width -The `mdc-image-list-standard-columns` mixin will grow and shrink items based on the Image List's overall width. Depending on +The `mdc-image-list-...-columns` mixins will grow and shrink items based on the Image List's overall width. Depending on placement, this could be directly related to the viewport width, and images could become exceedingly large compared to their actual rendered size. This can be restricted by using any of `min-width`, `width`, or `max-width` on the Image List: @@ -131,6 +168,8 @@ needs to be changed are styles: #### Using div in place of img to enforce aspect ratio +> **Note:** This advice is not applicable to Masonry Image List, where images do not share a common aspect ratio. + Images in an Image List typically use the `img` element. However, if your assets don't have the same aspect ratio as specified for list items, they will become distorted. In these cases, you can use a `div` element in place of `img`, and set the `background-image` of each. diff --git a/packages/mdc-image-list/_mixins.scss b/packages/mdc-image-list/_mixins.scss index c9ff2b9c691..d22598687c6 100644 --- a/packages/mdc-image-list/_mixins.scss +++ b/packages/mdc-image-list/_mixins.scss @@ -41,3 +41,14 @@ margin: $gutter-size / 2; } } + +// Masonry Image List + +@mixin mdc-image-list-masonry-columns($column-count, $gutter-size: $mdc-image-list-masonry-gutter-size) { + column-count: $column-count; + column-gap: $gutter-size; + + .mdc-image-list__item { + margin-bottom: $gutter-size; + } +} diff --git a/packages/mdc-image-list/_variables.scss b/packages/mdc-image-list/_variables.scss index 1b3b50ba789..3a2e1e6743a 100644 --- a/packages/mdc-image-list/_variables.scss +++ b/packages/mdc-image-list/_variables.scss @@ -13,6 +13,7 @@ // limitations under the License. $mdc-image-list-standard-gutter-size: 4px; +$mdc-image-list-masonry-gutter-size: 16px; $mdc-image-list-icon-size: 24px; $mdc-image-list-text-protection-background-color: rgba(0, 0, 0, .6); $mdc-image-list-text-protection-height: 48px; diff --git a/packages/mdc-image-list/mdc-image-list.scss b/packages/mdc-image-list/mdc-image-list.scss index d74e89b9d00..89ee7ea6eea 100644 --- a/packages/mdc-image-list/mdc-image-list.scss +++ b/packages/mdc-image-list/mdc-image-list.scss @@ -85,3 +85,18 @@ background: $mdc-image-list-text-protection-background-color; color: #fff; } + +// Masonry Image List, using CSS columns (i.e. renders down then across) + +.mdc-image-list--masonry { + display: block; // Override flex + + .mdc-image-list__item { + break-inside: avoid-column; + } + + .mdc-image-list__image { + display: block; + height: auto; + } +}