Skip to content

Commit

Permalink
Merge pull request #10 from prezly/feature/dev-11075-prezlycontent-re…
Browse files Browse the repository at this point in the history
…nderer-reactjs-use-srcset-to-properly-size

Use explicit width for `srcSet` generation, allow generating srcSets without retina support
  • Loading branch information
riffbyte authored Jul 6, 2023
2 parents 0e730b8 + 91956b2 commit fd61bf7
Showing 1 changed file with 7 additions and 6 deletions.
13 changes: 7 additions & 6 deletions src/lib/UploadcareImage.ts
Original file line number Diff line number Diff line change
Expand Up @@ -232,14 +232,15 @@ export class UploadcareImage {
};

public srcSet = (width: number): string => {
if (this.width < width * 2) {
return '';
}

const doubleWidth = width * 2;
const src1x = this.resize(width).cdnUrl;
const src2x = this.resize(width * 2).cdnUrl;
const src2x = this.resize(doubleWidth).cdnUrl;

if (this.width < doubleWidth) {
return `${src1x} ${width}w`;
}

return `${src1x} 1x, ${src2x} 2x`;
return `${src1x} ${width}w, ${src2x} ${doubleWidth}w`;
};

public toPrezlyStoragePayload = (): UploadedImage => ({
Expand Down

0 comments on commit fd61bf7

Please sign in to comment.