Skip to content

Commit 4fef318

Browse files
committed
refactor!: change auto to thumbnails for consistency
1 parent 57db3e5 commit 4fef318

File tree

4 files changed

+17
-20
lines changed

4 files changed

+17
-20
lines changed

DOCUMENTATION.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -446,15 +446,15 @@ Displays an image field, image manipulation can be performed through the `imgixP
446446
447447
{% image document.data.image, { widths: "defaults" } %}
448448
449-
{% image document.data.imageWithResponsiveViews, { widths: "auto" } %}
449+
{% image document.data.imageWithResponsiveViews, { widths: "thumbnails" } %}
450450
451451
{% image document.data.image, { widths: [500, 1000, 1500] } %}
452452
453453
{% image document.data.image, { pixelDensities: "defaults" } %}
454454
455455
{% image document.data.image, { pixelDensities: [3, 4] } %}
456456
457-
{% image document.data.image, { imgixParams: { sat: 100 }, widths: "auto", class: "block p-5", loading: "lazy" } %}
457+
{% image document.data.image, { imgixParams: { sat: 100 }, widths: "thumbnails", class: "block p-5", loading: "lazy" } %}
458458
```
459459

460460
Renders to:

src/shortcodes.ts

Lines changed: 5 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -164,7 +164,7 @@ export const image = (
164164
| NonNullable<
165165
Parameters<typeof prismicH.asImageWidthSrcSet>[1]
166166
>["widths"]
167-
| "auto"
167+
| "thumbnails"
168168
| "defaults";
169169
pixelDensities?:
170170
| NonNullable<
@@ -205,20 +205,10 @@ export const image = (
205205
);
206206
}
207207

208-
if (widths === "auto") {
209-
return prismicH.asImageWidthSrcSet(imageField, imgixParams);
210-
} else {
211-
// Remove potential thumbnails when using manual widths
212-
const { url, dimensions, alt, copyright } = imageField;
213-
214-
return prismicH.asImageWidthSrcSet(
215-
{ url, dimensions, alt, copyright },
216-
{
217-
...imgixParams,
218-
widths: widths === "defaults" ? widthSrcSetDefaults : widths,
219-
},
220-
);
221-
}
208+
return prismicH.asImageWidthSrcSet(imageField, {
209+
...imgixParams,
210+
widths: widths === "defaults" ? widthSrcSetDefaults : widths,
211+
});
222212
} else if (pixelDensities) {
223213
return prismicH.asImagePixelDensitySrcSet(imageField, {
224214
...imgixParams,

src/types.ts

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -104,7 +104,7 @@ export type PrismicPluginOptionsBase = {
104104
*
105105
* @remarks
106106
* Consider configuring image widths within your content type definition and
107-
* using `widths="auto"` instead to give content writers the ability to crop
107+
* using `widths="thumbnails"` instead to give content writers the ability to crop
108108
* images in the editor.
109109
* @defaultValue `@prismicio/helpers` defaults
110110
*/

test/shortcodes-image.test.ts

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -24,6 +24,13 @@ test("returns a valid image tag with an accessible default alt value", (t) => {
2424
);
2525
});
2626

27+
test("renders image field with provided alt value", (t) => {
28+
t.is(
29+
image()({ ...imageField, alt: "foo" }, { alt: "bar" }),
30+
'<img alt="bar" src="https://example.com/" />',
31+
);
32+
});
33+
2734
test("returns a valid image tag with class", (t) => {
2835
t.is(
2936
image()(imageField, "foo"),
@@ -52,7 +59,7 @@ test("returns a valid image tag with width-based `srcset`", (t) => {
5259
);
5360
});
5461

55-
test("returns a valid image tag with auto width-based `srcset`", (t) => {
62+
test("returns a valid image tag with thumbnails width-based `srcset`", (t) => {
5663
t.is(
5764
image()(
5865
{
@@ -65,7 +72,7 @@ test("returns a valid image tag with auto width-based `srcset`", (t) => {
6572
},
6673
},
6774
} as ImageField<"foo">,
68-
{ imgixParams: { sat: 100 }, widths: "auto" },
75+
{ imgixParams: { sat: 100 }, widths: "thumbnails" },
6976
),
7077
'<img alt="foo" src="https://example.com/?sat=100" srcset="https://example.com/?sat=100&width=10 10w, https://example.com/?sat=100&width=100 100w" />',
7178
);

0 commit comments

Comments
 (0)