Skip to content

Commit

Permalink
fix: remove default fit parameter (#484)
Browse files Browse the repository at this point in the history
  • Loading branch information
sherwinski authored Oct 30, 2019
1 parent d036132 commit fbe8082
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 22 deletions.
8 changes: 3 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -76,11 +76,11 @@ This will generate HTML similar to the following:

```html
<img
src="https://assets.imgix.net/examples/pione.jpg?auto=format&amp;crop=faces&amp;fit=crop&amp;ixlib=react-7.2.0"
src="https://assets.imgix.net/examples/pione.jpg?auto=format&amp;crop=faces&amp;ixlib=react-7.2.0"
sizes="100vw"
srcset="
https://assets.imgix.net/examples/pione.jpg?auto=format&amp;crop=faces&amp;fit=crop&amp;ixlib=react-7.2.0&amp;w=100 100w,
https://assets.imgix.net/examples/pione.jpg?auto=format&amp;crop=faces&amp;fit=crop&amp;ixlib=react-7.2.0&amp;w=200 200w,
https://assets.imgix.net/examples/pione.jpg?auto=format&amp;crop=faces&amp;ixlib=react-7.2.0&amp;w=100 100w,
https://assets.imgix.net/examples/pione.jpg?auto=format&amp;crop=faces&amp;ixlib=react-7.2.0&amp;w=200 200w,
...
"
/>
Expand All @@ -100,8 +100,6 @@ import Imgix from "react-imgix";
/>;
```

NB: Since this library sets [`fit`](https://docs.imgix.com/apis/url/size/fit) to `crop` by default, when just a width or height is set, the image will resize and maintain aspect ratio. When both are set, the image will be cropped to that size, maintaining pixel aspect ratio (i.e. edges are clipped in order to not stretch the photo). If this isn't desired, set `fit` to be another value (e.g. `clip`)

[![Edit xp0348lv0z](https://codesandbox.io/static/img/play-codesandbox.svg)](https://codesandbox.io/s/charming-keller-kjnsq)

#### Server-side rendering
Expand Down
10 changes: 2 additions & 8 deletions src/react-imgix.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@ const NODE_ENV = process.env.NODE_ENV;
const buildKey = idx => `react-imgix-${idx}`;

const defaultImgixParams = {
auto: ["format"],
fit: "crop"
auto: ["format"]
};

const defaultAttributeMap = {
Expand Down Expand Up @@ -170,12 +169,7 @@ function buildSrc({
*/
function imgixParams(props) {
const params = Object.assign({}, defaultImgixParams, props.imgixParams);

let fit = false;
if (params.crop != null) fit = "crop";
if (params.fit) fit = params.fit;

return Object.assign({}, params, { fit });
return Object.assign({}, params);
}

/**
Expand Down
10 changes: 1 addition & 9 deletions test/unit/react-imgix.test.jsx
Original file line number Diff line number Diff line change
Expand Up @@ -456,16 +456,8 @@ describe("When using the component", () => {
it("the rendered element should contain the class name provided", () => {
expect(sut.props().className).toContain(className);
});
it("the crop param should alter the crop and fit query parameters correctly", () => {
sut = shallow(
<Imgix src={src} sizes="100vw" imgixParams={{ crop: "faces,entropy" }} />
);

expectSrcsToContain(sut, "crop=faces%2Centropy");
expectSrcsToContain(sut, "fit=crop");
});
it("the fit param should alter the fit query pararmeter correctly", () => {
expectSrcsToContain(sut, "fit=crop");
expectSrcsTo(sut, expect.not.stringContaining("fit=crop"));
});
it("the keys of custom url parameters should be url encoded", () => {
const helloWorldKey = "hello world";
Expand Down

0 comments on commit fbe8082

Please sign in to comment.