Skip to content

Commit

Permalink
feat: add image atom, blur images with missing alt tags (#281)
Browse files Browse the repository at this point in the history
Resolves #230.
  • Loading branch information
Ned Zimmerman committed Mar 26, 2020
1 parent 225b6c5 commit 2e89f54
Show file tree
Hide file tree
Showing 6 changed files with 68 additions and 4 deletions.
11 changes: 11 additions & 0 deletions src/assets/styles/components/_image.scss
Original file line number Diff line number Diff line change
@@ -0,0 +1,11 @@
img {
border-style: none;
display: block;
height: auto;
max-width: 100%;
vertical-align: middle;
}

img:not([alt]) {
filter: blur(rem(10));
}
1 change: 1 addition & 0 deletions src/assets/styles/pinecone.scss
Original file line number Diff line number Diff line change
Expand Up @@ -17,6 +17,7 @@
@import "components/divider";
@import "components/button";
@import "components/icons";
@import "components/image";
@import "components/input";
@import "components/link";
@import "components/link-list";
Expand Down
27 changes: 27 additions & 0 deletions src/components/atoms/image/image.config.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,27 @@
module.exports = {
title: 'Image',
status: 'wip',
order: 11,
context: {
src: '/images/person.jpg',
width: 367,
height: 250,
alt: 'Photograph of Trebor Scholz',
role: false
},
variants: [
{
name: 'Decorative',
context: {
alt: '',
role: 'presentation'
}
},
{
name: 'Missing Alternative Text',
context: {
alt: false
}
}
]
};
10 changes: 10 additions & 0 deletions src/components/atoms/image/image.njk
Original file line number Diff line number Diff line change
@@ -0,0 +1,10 @@
{% set altAttribute = false %}
{% if alt !== false %}
{% set altAttribute = 'alt="' + alt + '"' %}
{% endif %}
{% set roleAttribute = false %}
{% if role !== false %}
{% set roleAttribute = 'role="' + role + '"' %}
{% endif %}

<img {{ roleAttribute | safe if roleAttribute else '' }} src="{{ src }}" width="{{ width }}" height="{{ height }}" {{ altAttribute | safe if altAttribute else '' }} />
21 changes: 18 additions & 3 deletions src/components/molecules/card/card.config.js
Original file line number Diff line number Diff line change
Expand Up @@ -79,7 +79,12 @@ module.exports = {
title: 'Who Owns the World?',
date: 'Nov 12, 2019',
href: 'blog',
image: '/images/blog.jpg'
image: {
src: '/images/blog.jpg',
width: 367,
height: 165,
alt: 'Photograph of Cataki workers'
}
}
},
{
Expand All @@ -92,7 +97,12 @@ module.exports = {
title: 'SEWA Federation',
locality: 'Gujarat, India',
href: 'story',
image: '/images/story.jpg'
image: {
src: '/images/story.jpg',
width: 367,
height: 165,
alt: 'Photograph of SEWA workers'
}
}
},
{
Expand All @@ -104,7 +114,12 @@ module.exports = {
title: 'Trebor Scholz',
description: 'Founding Director, Institute for the Cooperative Digital Economy',
href: 'person',
image: '/images/person.jpg'
image: {
src: '/images/person.jpg',
width: '',
height: '',
alt: 'Photograph of Trebor Scholz',
}
}
},
{
Expand Down
2 changes: 1 addition & 1 deletion src/components/molecules/card/card.njk
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,7 @@
<article class="card{% if modifier %} card--{{ modifier }}{% endif %}">
{% if image %}
<figure class="card__image">
<img src="{{ image }}" alt="Image for this {{ modifier }}."/>
{% render '@image', image, true %}
</figure>
{% endif %}
<header>
Expand Down

0 comments on commit 2e89f54

Please sign in to comment.