Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

@material/image-list

Package Overview
Dependencies
Maintainers
15
Versions
1659
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

@material/image-list

The Material Components for the web image list component

  • 14.0.0
  • latest
  • Source
  • npm
  • Socket score

Version published
Weekly downloads
771K
increased by2.52%
Maintainers
15
Weekly downloads
 
Created
Source

Image List

MDC Image List provides a RTL-aware Material Design image list component. An Image List consists of several items, each containing an image and optionally supporting content (i.e. a text label).

Design & API Documentation

  • Material Design guidelines: Image list
  • Demo

Installation

npm install @material/image-list

Basic Usage

HTML Structure

The HTML structure for a Standard Image List is as follows:

<ul class="mdc-image-list my-image-list">
  <li class="mdc-image-list__item">
    <div class="mdc-image-list__image-aspect-container">
      <img class="mdc-image-list__image" src="...">
    </div>
    <div class="mdc-image-list__supporting">
      <span class="mdc-image-list__label">Text label</span>
    </div>
  </li>
  ...
</ul>

Styles

@use "@material/image-list/mdc-image-list";

The HTML structure above would be combined with an invocation of the standard-columns mixin, to establish how many columns should be displayed per line:

@use "@material/image-list";

.my-image-list {
  @include image-list.standard-columns(5);
}

Images in a Standard Image list are constrained to 1:1 aspect ratio by default; this can be overridden using the aspect mixin documented below.

Variants

Masonry Image List

The Masonry Image List variant presents images vertically arranged into several columns, using CSS Columns. In this layout, images may be any combination of aspect ratios.

<ul class="mdc-image-list mdc-image-list--masonry my-masonry-image-list">
  <li class="mdc-image-list__item">
    <img class="mdc-image-list__image" src="...">
    <div class="mdc-image-list__supporting">
      <span class="mdc-image-list__label">Text label</span>
    </div>
  </li>
  ...
</ul>

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:

.my-masonry-image-list {
  @include image-list.masonry-columns(5);
}

Style Customization

CSS Classes

CSS ClassDescription
mdc-image-listMandatory. Indicates the root Image List element.
mdc-image-list--masonryOptional. Indicates that this Image List should use the Masonry variant.
mdc-image-list--with-text-protectionOptional. Indicates that supporting content should be positioned in a scrim overlaying each image (instead of positioned separately under each image).
mdc-image-list__itemMandatory. Indicates each item in an Image List.
mdc-image-list__image-aspect-containerOptional. 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.
mdc-image-list__imageMandatory. Indicates the image element in each item.
mdc-image-list__supportingOptional. Indicates the area within each item containing the supporting text label, if the Image List contains text labels.
mdc-image-list__labelOptional. Indicates the text label in each item, if the Image List contains text labels.

Sass Mixins

MixinDescription
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.
shape-radius($radius, $rtl-reflexive)Sets the rounded shape to image list item with given radius size. Set $rtl-reflexive to true to flip radius values in RTL context, defaults to false.
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.
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 *-columns mixins should be used for any given Image List. Use the mixin appropriate to the variant being used.

Additional Information

Constraining width

The *-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:

@use "@material/image-list";

.my-image-list {
  @include image-list.standard-columns(5);

  max-width: 960px;
}

Note: Remember that any specified width will apply to the entire list, so be sure to account for the gutters as well.

Changing number of columns across breakpoints

Presenting a different number of columns for different viewport sizes is straightforward, since the only thing that needs to be changed are styles:

.my-image-list {
  @include image-list.standard-columns(5);
}

@media (max-width: 599px) {
  .my-image-list {
    @include image-list.standard-columns(3);
  }
}
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.

Note: Ensuring your images are appropriately-sized prior to serving them to browsers is the most efficient and ideal approach to using MDC Image List. The div alternative is provided as a convenience. If you use this alternative, make sure to also include the mdc-image-list__image-aspect-container element around each item's image.

Keywords

FAQs

Package last updated on 28 Apr 2022

Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc