-
Notifications
You must be signed in to change notification settings - Fork 17
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Support fixed and responsive layouts
This accumulates a few (breaking) changes: * will add the CSS for responsive (fluid) image layout (the default) * when passing `@width` and/or `@height` arguments, it will opt into fixed layout (closes #117) * in fixed layout, it will pick the (fallback) `src` attribute based on the fixed width, pick `srcset` sources for that given width and pixel densities of `1x` and `2x`, and `width` and `height` with the appropriate fixed values (if one is missing, it will be computed based on the image's aspect ratio) * in responsive layout, `width` and `height` attributes are rendered even though the *actual* size is responsive, to let the browser know the correct vertical size (even before the image has been loaded), to reduce [Cumulative Layout Shift](https://web.dev/cls/) (Closes #88) * some (breaking) related changes in the service's API, removing `getImageBySize()`, renaming `getImageDataBySize()` to `getImageMetaBySize()` and introducing `getImageMetaByWidth()`
- Loading branch information
1 parent
89aa535
commit a889521
Showing
9 changed files
with
476 additions
and
306 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,24 @@ | ||
import { inject as service } from '@ember/service'; | ||
import { htmlSafe } from '@ember/string'; | ||
import Helper from '@ember/component/helper'; | ||
import ResponsiveImageService from 'ember-responsive-image/services/responsive-image'; | ||
|
||
/** | ||
* @class responsiveImageResolve | ||
* @namespace Helpers | ||
* @extends Ember.Helper | ||
* @public | ||
*/ | ||
export default class ResponsiveImageResolve extends Helper { | ||
@service | ||
responsiveImage!: ResponsiveImageService; | ||
|
||
compute( | ||
[image, size]: [string, number | undefined] /*, hash*/ | ||
): ReturnType<typeof htmlSafe> | undefined { | ||
const responsive = this.responsiveImage.getImageMetaBySize(image, size) | ||
?.image; | ||
|
||
return responsive ? htmlSafe(responsive) : undefined; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,4 @@ | ||
.eri-responsive { | ||
width: 100%; | ||
height: auto; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1 +1,9 @@ | ||
<h2>Fixed</h2> | ||
|
||
<ResponsiveImage @width={{200}} @image="assets/images/test.png"/> | ||
|
||
<h2>Responsive</h2> | ||
|
||
<ResponsiveImage @image="assets/images/test.png"/> | ||
|
||
|
Oops, something went wrong.