-
Notifications
You must be signed in to change notification settings - Fork 64
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
feat: reduce props API surface area #162
Conversation
- roll auto, crop, entropy, faces, fit props into imgixParams - renamed customParams to imgixParams - faces default has been changed to false - old props have been supported until v9 through the use of a HOC
09a1e78
to
20b94f7
Compare
export default class ReactImgix extends Component { | ||
const defaultImgixParams = { | ||
auto: ["format"], | ||
fit: "crop" |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If we're removing the fit=faces
default, we need to also remove the fit=crop
default. If it's left on, all images will crop to center instead of resizing as expected.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This should be noted as a breaking change as well, since people will need to re-add it in their imgixParams
(née customParams
) if they're intentionally using other crop modes.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
As discussed offline, fit=crop
works intuitively for developers, but it needs to be called out in the README somewhere.
src/react-imgix.js
Outdated
disableSrcSet: PropTypes.bool, | ||
onMounted: PropTypes.func, | ||
sizes: PropTypes.string, | ||
src: PropTypes.string.isRequired, | ||
type: PropTypes.oneOf(validTypes), | ||
width: PropTypes.number, | ||
height: PropTypes.number, | ||
disableLibraryParam: PropTypes.bool | ||
defaultHeight: PropTypes.number, | ||
defaultWidth: PropTypes.number, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think defaultWidth
and defaultHeight
aren't supposed to be here. Weren't they removed in #159?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My bad, they were removed. Those pesky merge commits!
src/react-imgix.js
Outdated
if (params.crop) crop = params.crop; | ||
|
||
let fit = false; | ||
if (entropy || faces) fit = "crop"; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I think we should just go all-in on auto-setting here: if the user provides any kind of crop
value, we should automatically set fit=crop
(otherwise crop=
is always ignored by the painter).
if (!!crop) fit = "crop";
Usually I would object to this kind of "magic" but I can't think of a downside in this case.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This sounds like a great idea.
src/react-imgix.js
Outdated
...this.props.imgixParams | ||
}; | ||
|
||
const { faces, entropy } = params; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I feel a little bit uneasy about encouraging users to put "non-standard" parameters into the imgixParams
object. I have no problem putting "helper" options into the parent this.props
object, but if we're going to explicitly call this a map of "imgix params" then I feel like we should require users to pass in crop: 'faces'
instead of faces: true
.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I had actually forgotten that faces
wasn't a top level imgix parameter. I agree with you, I feel uneasy about it as well. I'll remove faces
in favour of using crop: 'faces'
directly.
src/react-imgix.js
Outdated
children, | ||
component, | ||
customParams, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
imgixParams
should be added to this.props
here, no?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think so -- this is not setting the prop types for the component, this is destructuring props into local variables to make it easier to use in the render
method. imgixParams
is not used anywhere in render, only in ReactImgix.buildSrcs()
DEPRECATED_PROPS.forEach(deprecatedProp => { | ||
warning( | ||
!(deprecatedProp in props), | ||
`The prop '${deprecatedProp}' has been deprecated and will be removed in v9. Please update the usage to <Imgix imgixParams={{${deprecatedProp}: value}} />` |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Following my above comment about not encouraging users to pass in { imgixProps: { entropy: true } }
, this warning will need to be updated.
Hey @jayeb, I think I've addressed all the issues discussed - could you please give this another review? |
…#163) BREAKING CHANGES: - picture and source types have been changed to components. ## Description **NB: This is currently a stacked PR. I will change the base to `version-8` when #162 is resolved. The last commit in the PR moved some stuff around, it may help to view [this diff](https://github.com/imgix/react-imgix/pull/163/files/0b88acb3f646691ef1df80b207b5e09935df54f5) first to see the feature changes.** This PR builds on the changes described in #144. Having the picture and source behaviour work using a `type` prop was causing `<Imgix />` to have mixed responsibilities. This was causing pecularities, such as needing to pass a `src` to a `<Imgix type='picture' />` even though it wasn't used. ### TODO - [x] Update Upgrade Guide - [x] Change imgProps to be htmlAttributes as discussed offline with @jayeb ~- [ ] Add prop fall-through behaviour to `<Picture />`~ ### New Feature - [x] If this is a big feature with breaking changes, consider [opening an issue][issues] to discuss first. This is completely up to you, but please keep in mind that your PR might not be accepted. - [x] Run unit tests to ensure all existing tests are still passing - [x] Add new passing unit tests to cover the code introduced by your PR - [x] Update the readme - [x] Add some [steps](#steps-to-test) so we can test your cool new feature! - [x] The PR title is in the [conventional commit](#conventional-commit-spec) format: e.g. `feat(<area>): added new way to do this cool thing #issue-number` - [x] Add your info to the [contributors](#packagejson-contributors) array in package.json! ## Steps to Test Review the changes to the tests.
* version-8: docs: add link to fluid example and fix some links docs: add example about fitting to the size of the container docs: add ref information feat: refactor picture and source behaviour into different components (#163) feat: reduce props API surface area (#162) feat: implement responsiveness with srcSet and sizes (#159) fix: warn the user when no <img> passed as a child to <picture> fixes #90 (#151) # Conflicts: # README.md
BREAKING CHANGE: faces is no longer set by default.
Deprecations (supported until v9):
imgixParams
)imgixParams
)Description
This PR consolidates some imgix props into the
imgixParams
object, which makes the props API smaller and easier to understand. There should be no issues with excessive re-rendering as the object is checked shallowly to see if the object's values have changed. I decided to deprecate the old props rather than remove them to ease the transition to the new API. Any use of the old props will now trigger a warning, and we will remove the old props in v9.In the past this library has set the
faces
imgix parameter by default. The new behaviour is to not set this parameter so that it should be less confusing for new-comers.Also, I'm looking for good taglines/features about this library, so if you, reader, have any ideas, please let me know.
Ref #144
TODO
imgProps
tohtmlAttributes
after deciding thatimgProps
andimgixParam
are too similarNew Feature
feat(<area>): added new way to do this cool thing #issue-number
Steps to Test
Review changes to unit tests.