Skip to content

Commit f30b21e

Browse files
authored
refactor: always include dimensions on images (#1405)
* refactor: always include dimensions on images * chore: corrected that filename * chore: we should advocate for including dimensions as well * chore: we should advocate for including dimensions as well * chore: we should advocate for including dimensions as well * chore: added missing dimensions
1 parent 76ccc8c commit f30b21e

30 files changed

+125
-57
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
<p align="center">
2-
<img src='/patternlab.png' width="300" alt="Pattern Lab Logo" style="max-width: 100%;" />
2+
<img src='/patternlab.png' width="300" height="166" alt="Pattern Lab Logo" style="max-width: 100%;" />
33
</p>
44

55
# Pattern Lab

packages/docs/src/docs/data-json-mustache.md

Lines changed: 15 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -17,10 +17,10 @@ sitemapPriority: '0.8'
1717
At its core JSON is a simple key-value store. This means that any piece of data in JSON has a key and a value. The key is the name of an attribute and the value is what should be shown when that attribute is referenced. Here's a simple example:
1818

1919
```javascript
20-
"src": "../../images/fpo-avatar.png"
20+
"src": "../../images/fpo_avatar.png"
2121
```
2222

23-
In this case the key is `src` and the value is `../../images/fpo-avatar.png`. Let's look at how we might reference this data in a pattern template. Mustache variables are denoted by the double-curly braces (or mustaches).
23+
In this case the key is `src` and the value is `../../images/fpo_avatar.png`. Let's look at how we might reference this data in a pattern template. Mustache variables are denoted by the double-curly braces (or mustaches).
2424

2525
```html
2626
<img src="{% raw %}{{ src }}{% endraw %}" alt="Avatar" />
@@ -29,7 +29,7 @@ In this case the key is `src` and the value is `../../images/fpo-avatar.png`. Le
2929
The Mustache variable is `{% raw %}{{ src }}{% endraw %}`. Note that `src` matches the name of the key in our JSON example. When the Node version of Pattern Lab compile this template the end result will be:
3030

3131
```html
32-
<img src="../../images/fpo-avatar.png" alt="Avatar" />
32+
<img src="../../images/fpo_avatar.png" alt="Avatar" />
3333
```
3434

3535
Note that `{% raw %}{{ src }}{% endraw %}` was replaced by the value for `src` found in our JSON example.
@@ -40,28 +40,34 @@ We may want our JSON file to be a little more organized and our Mustache variabl
4040

4141
```javascript
4242
"square": {
43-
"src": "../../images/fpo-square.png",
44-
"alt": "Square"
43+
"src": "../../images/fpo_square.png",
44+
"alt": "Square",
45+
"width": "600",
46+
"height": "600"
4547
},
4648
"avatar": {
47-
"src": "../../images/fpo-avatar.png",
48-
"alt": "Avatar"
49+
"src": "../../images/fpo_avatar.png",
50+
"alt": "Avatar",
51+
"width": "300",
52+
"height": "300"
4953
}
5054
```
5155

52-
Note how their are attributes ( `src`, `alt` ) nested within a larger container ( `square` ). Also note how the attributes are separated by commas. If we wanted to use the attributes for the square image in our pattern we'd write:
56+
Note how their are attributes ( `src`, `alt`, `width`, `height` ) nested within a larger container ( `square` ). Also note how the attributes are separated by commas. If we wanted to use the attributes for the square image in our pattern we'd write:
5357

5458
```html
5559
<img
5660
src="{% raw %}{{ square.src }}{% endraw %}"
5761
alt="{% raw %}{{ square.alt }}{% endraw %}"
62+
width="{% raw %}{{ square.width }}{% endraw %}"
63+
height="{% raw %}{{ square.height }}{% endraw %}"
5864
/>
5965
```
6066

6167
This would compile to:
6268

6369
```html
64-
<img src="../../images/fpo-square.png" alt="Square" />
70+
<img src="../../images/fpo_square.png" alt="Square" width="600" height="600" />
6571
```
6672

6773
This nesting makes it easier to read how the attributes are organized in our patterns. The default `data.json` file has several examples of this type of nesting of attributes.

packages/starterkit-handlebars-demo/dist/_data/blocks.json

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,8 @@
11
{
22
"stackedBlockMedia": {
3-
"src": "https://via.placeholder.com/600x400"
3+
"src": "https://via.placeholder.com/600x400",
4+
"width": "600",
5+
"height": "400"
46
},
57
"stripeField": true,
68
"cartPrice": {
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
{
22
"src" : "https://via.placeholder.com/1200x800",
33
"alt": "landscape image",
4-
"logoImg" : "../../images/logo.png"
4+
"logoImg" : "../../images/logo.png",
5+
"width": "1200",
6+
"height": "800"
57
}

packages/starterkit-handlebars-demo/dist/_data/lists.json

Lines changed: 18 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,9 @@
55
"url": "#",
66
"stackedBlockMedia": {
77
"src": "https://via.placeholder.com/600x400",
8-
"alt": "placeholder image"
8+
"alt": "placeholder image",
9+
"width": "600",
10+
"height": "400"
911
},
1012
"headline": "Heading ipsum dolor sit (39 characters)",
1113
"excerpt": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam",
@@ -16,7 +18,9 @@
1618
"url": "#",
1719
"stackedBlockMedia": {
1820
"src": "https://via.placeholder.com/600x400",
19-
"alt": "placeholder image"
21+
"alt": "placeholder image",
22+
"width": "600",
23+
"height": "400"
2024
},
2125
"headline": "Heading ipsum dolor sit (39 characters)",
2226
"excerpt": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam",
@@ -27,7 +31,9 @@
2731
"url": "#",
2832
"stackedBlockMedia": {
2933
"src": "https://via.placeholder.com/600x400",
30-
"alt": "placeholder image"
34+
"alt": "placeholder image",
35+
"width": "600",
36+
"height": "400"
3137
},
3238
"headline": "Heading ipsum dolor sit (39 characters)",
3339
"excerpt": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam",
@@ -38,7 +44,9 @@
3844
"url": "#",
3945
"stackedBlockMedia": {
4046
"src": "https://via.placeholder.com/600x400",
41-
"alt": "placeholder image"
47+
"alt": "placeholder image",
48+
"width": "600",
49+
"height": "400"
4250
},
4351
"headline": "Heading ipsum dolor sit (39 characters)",
4452
"excerpt": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam",
@@ -49,7 +57,9 @@
4957
"url": "#",
5058
"stackedBlockMedia": {
5159
"src": "https://via.placeholder.com/600x400",
52-
"alt": "placeholder image"
60+
"alt": "placeholder image",
61+
"width": "600",
62+
"height": "400"
5363
},
5464
"headline": "Heading ipsum dolor sit (39 characters)",
5565
"excerpt": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam",
@@ -60,7 +70,9 @@
6070
"url": "#",
6171
"stackedBlockMedia": {
6272
"src": "https://via.placeholder.com/600x400",
63-
"alt": "placeholder image"
73+
"alt": "placeholder image",
74+
"width": "600",
75+
"height": "400"
6476
},
6577
"headline": "Heading ipsum dolor sit (39 characters)",
6678
"excerpt": "Lorem ipsum dolor sit amet, consectetur adipisicing elit, sed do eiusmod tempor incididunt ut labore et dolore magna aliqua. Ut enim ad minim veniam",
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<img src="{{ src }}" alt="{{ alt }}" class="{{ styleModifier }}" />
1+
<img src="{{ src }}" alt="{{ alt }}" width="{{ width }}" height="{{ height }}" class="{{ styleModifier }}" />
Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
<img src="{{ src }}" alt="{{ alt }}" class="c-stacked-block__img" />
1+
<img src="{{ src }}" alt="{{ alt }}" width="{{ width }}" height="{{ height }}" class="c-stacked-block__img" />
Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,5 @@
11
{
2-
"src": "https://via.placeholder.com/600x400"
2+
"src": "https://via.placeholder.com/600x400",
3+
"width": "600",
4+
"height": "400"
35
}

packages/starterkit-handlebars-demo/dist/_patterns/molecules/blocks/hero.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<div class="c-hero">
22

3-
<img src="{{ src }}" alt="{{ alt }}" class="c-hero__img" />
3+
<img src="{{ src }}" alt="{{ alt }}" width="{{ width }}" height="{{ height }}" class="c-hero__img" />
44
<div class="c-hero__body">
55
<h2 class="c-hero__headline">{{ heading }}</h2>
66
</div>

packages/starterkit-handlebars-demo/dist/_patterns/molecules/blocks/promo-block.hbs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
{{#with promoBlockLink }}
1515
<a href="{{ url }}" class="c-promo-block__link">
1616
{{/ with }}
17-
<img src="{{ src }}" alt="{{ alt }}" class="c-promo-block__img" />
17+
<img src="{{ src }}" alt="{{ alt }}" width="{{ width }}" height="{{ height }}" class="c-promo-block__img" />
1818
{{#if promoBlockLink }}
1919
</a>
2020
{{/ if }}

0 commit comments

Comments
 (0)