Skip to content

Commit

Permalink
Add cover option to image container component
Browse files Browse the repository at this point in the history
  • Loading branch information
bartaz committed Jun 28, 2024
1 parent ff047c5 commit 08c3551
Show file tree
Hide file tree
Showing 5 changed files with 31 additions and 0 deletions.
4 changes: 4 additions & 0 deletions releases.yml
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,10 @@
url: /docs/patterns/links#anchor-link
status: New
notes: We've introduced a new class <code>.p-link--anchor-heading</code> to style anchor links in headings.
- component: Image container / Cover
url: /docs/patterns/images#cover-image
status: New
notes: We've added a new cover variant to the image container component via <code>is-cover</code> class to support having images cover the container with predefined aspect ratio.
- version: 4.13.0
features:
- component: Image container
Expand Down
8 changes: 8 additions & 0 deletions scss/_patterns_image.scss
Original file line number Diff line number Diff line change
Expand Up @@ -42,6 +42,14 @@
max-height: 100%;
object-fit: contain;
}

&.is-cover {
.p-image-container__image {
height: 100%;
object-fit: cover;
width: 100%;
}
}
}

.p-image-container--16-9 {
Expand Down
1 change: 1 addition & 0 deletions templates/docs/examples/patterns/image/combined.html
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
<section>{% include 'docs/examples/patterns/image/shadowed.html' %}</section>
<section>{% include 'docs/examples/patterns/image/spacing.html' %}</section>
<section>{% include 'docs/examples/patterns/image/container/highlighted.html' %}</section>
<section>{% include 'docs/examples/patterns/image/container/cover.html' %}</section>
<section>{% include 'docs/examples/patterns/image/container/aspect-ratio/all.html' %}</section>
{% endwith %}
{% endblock %}
10 changes: 10 additions & 0 deletions templates/docs/examples/patterns/image/container/cover.html
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% extends "_layouts/examples.html" %}
{% block title %}Image Container / Cover{% endblock %}

{% block standalone_css %}patterns_image{% endblock %}

{% block content %}
<div class="p-image-container--16-9 is-cover">
<img class="p-image-container__image" src="https://assets.ubuntu.com/v1/44095efb-photo-1580536793208-117fdb20ffc1%20(1).jpeg" alt="" width="1000">
</div>
{% endblock %}
8 changes: 8 additions & 0 deletions templates/docs/patterns/images.md
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,14 @@ See the [class references section](#class-reference) for more information on the
View example of image container with 16/9 aspect ratio
</a></div>

## Cover image

Cover images are used to fill the entire container, cropping the image if necessary. This can be combined with the aspect ratio modifier to crop the image to a specific aspect ratio.

<div class="embedded-example"><a href="/docs/examples/patterns/image/container/cover" class="js-example">
View example of cover image
</a></div>

## Image with border

<div class="p-notification--caution">
Expand Down

0 comments on commit 08c3551

Please sign in to comment.