Skip to content
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

allow EuiImage to set custom width #3012

Merged
merged 26 commits into from
Mar 19, 2020
Merged

allow EuiImage to set custom width #3012

merged 26 commits into from
Mar 19, 2020

Conversation

anishagg17
Copy link
Contributor

@anishagg17 anishagg17 commented Mar 9, 2020

Summary

Fixes : #1554

allow EuiImage to set custom width by allowing size to accept number

Checklist

- [ ] Check against all themes for compatibility in both light and dark modes
- [ ] Checked in mobile

  • Checked in IE11 and Firefox
    - [ ] Props have proper autodocs
  • Added documentation examples
  • Added or updated jest tests
    - [ ] Checked for breaking changes and labeled appropriately
    - [ ] Checked for accessibility including keyboard-only and screenreader modes
  • A changelog entry exists and is marked appropriately

@kibanamachine
Copy link

Since this is a community submitted pull request, a Jenkins build has not been kicked off automatically. Can an Elastic organization member please verify the contents of this patch and then kick off a build manually?

Copy link
Contributor

@thompsongl thompsongl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @anishagg17

Can you update the PR summary to include a more full description? Like, what part of the issue this PR addresses, how it was addressed, and what is still left to do?

Also, please strikethrough (~~) any checklist items that don't apply so we have an accurate picture of work still left to be done.

Copy link
Contributor

@thompsongl thompsongl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the description and summary updates

This doesn't appear to match the description or solve the issue requirements, though. Specifically:

the size prop essentially means "width or height should be set to this, whichever is larger" in any cases when it is not set to original or fullWidth

allow EuiImage to set custom width by allowing size to accept number

With these changes, only height is directly set when giving the size prop a numeric value. A 2:1 horizontally oriented image, for instance, would be 100px wide when size={50}. This component would need to do an aspect ratio calculation to accomplish the requirement of "width or height should be set to this, whichever is larger" (or perhaps just also set max-width to the given size number)

@snide Am I reading your comments correctly?

@anishagg17
Copy link
Contributor Author

I will update it soon

@anishagg17
Copy link
Contributor Author

I have updated the functionality

@thompsongl
Copy link
Contributor

@anishagg17 I'm still a bit confused on the intention of this PR.
The last commit message says that height should be a consideration (greater of height or width gets size ,lesser is set to auto), but the description of the PR still only accounts for width.
And, functionally, only width is currently impacted (50px width regardless of aspect ratio):
Screen Shot 2020-03-16 at 10 50 41 AM

If you intend for this PR to only impact width, we can work with that. If your latest commit intended to restrict height based on aspect ratio, the functionality needs to be revisited.

@anishagg17
Copy link
Contributor Author

Let me recheck for it

@anishagg17
Copy link
Contributor Author

@thompsongl can you please recheck this now

Copy link
Contributor

@thompsongl thompsongl left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks, @anishagg17, this does restrict height now also.

Like I mentioned in an earlier comment, this can be done without any JS if we were to "perhaps just also set max-width to the given size number". Rather than use timeouts or ratio calculations, we could use the customStyle state to set minWidth and maxWdith to size when size is a number. CSS will correctly size the image with the same restrictions.

src/components/image/_image.scss Outdated Show resolved Hide resolved
src/components/image/_image.scss Outdated Show resolved Hide resolved
@anishagg17
Copy link
Contributor Author

Rather than use timeouts or ratio calculations, we could use the customStyle state to set minWidth and maxWdith to size when size is a number. CSS will correctly size the image with the same restrictions.

Should I update according to this??

@cchaos
Copy link
Contributor

cchaos commented Mar 17, 2020

Jenkins, test this

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_3012/

@thompsongl
Copy link
Contributor

Should I update according to this??

Yes, please. A style-only solution is preferable here to using React lifecycle methods and JS intervals to check DOM sizing attributes.

@anishagg17
Copy link
Contributor Author

anishagg17 commented Mar 18, 2020

I tried your solution but it does not maintain the aspect ratio 100x800 image would turn to 50x400

Screenshot 2020-03-18 at 3 53 51 PM

also when i apply same to height then the output is 50x50 it should be 50x40

@anishagg17
Copy link
Contributor Author

now i have used

 customStyle = {
        maxWidth: size,
        maxHeight: size,
        minWidth: 0,
        minHeight: 0,
        width: 'auto',
        height: 'auto',
      };

this fixes it correctly

@cchaos
Copy link
Contributor

cchaos commented Mar 18, 2020

@anishagg17 This one got kind of complicated and the docs needed good explanations so I pushed you a PR. anishagg17#3 As mentioned in the summary it:

  • Moved props docs to comments in component file
  • Accounting for style prop is passed by consumer
  • Removed extraneous style properties
  • Updating docs size section

cchaos and others added 2 commits March 18, 2020 19:06
- Moved props docs to comments in component file
- Accounting for `style` prop is passed by consumer
- Removed extraneous style properties
- Updating docs size section
@anishagg17
Copy link
Contributor Author

@cchaos

maxWidth: size,
maxHeight: size,
width: 'auto',
height: 'auto',

Last 2 properties are required to maintain the aspect ratio otherwise a size x size image is rendered

@cchaos
Copy link
Contributor

cchaos commented Mar 18, 2020

Ahh it only happens when the height is greater than the width. This actually brings up a greater question... Should we be increasing the size of the images to fit the "size" given?

@snide, Just curious on your thoughts here....

Currently, all the enum sizes (s, m, l, etc...) will force the image to grow to fit that specified width. However, in the current configuration when a number is provided, this is maximum width/height. So if they supply a smaller image than the number provided, it does not grow to fit.

I can't really see a benefit of making the image grow to fit the size if the image isn't already atleast that size. This will cause blurry images.

@cchaos
Copy link
Contributor

cchaos commented Mar 18, 2020

Jenkins test this

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_3012/

@snide
Copy link
Contributor

snide commented Mar 18, 2020

I can't really see a benefit of making the image grow to fit the size if the image isn't already atleast that size. This will cause blurry images.

I agree.

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've thought about it some more and I think we should just keep the behavior as it is where the sized (s, m, l, etc) images would grow to fit the determined size, but the custom values behave as a maximum and wont grow the image.

The only way I could find to make the latter actually grow the image proportionally is to use object-fill but then it doesn't work with the shadow we have on the figure and just gets very messy. So for now, I think this works. I just have some text changes now based on all that.

CHANGELOG.md Outdated Show resolved Hide resolved
src-docs/src/views/image/image_example.js Outdated Show resolved Hide resolved
src-docs/src/views/image/image_example.js Outdated Show resolved Hide resolved
src/components/image/image.tsx Outdated Show resolved Hide resolved
src/components/image/image.tsx Outdated Show resolved Hide resolved
@cchaos
Copy link
Contributor

cchaos commented Mar 18, 2020

I agree.

Haha, thanks @snide. I think we'll leave it for now and circle back but at least the custom sizing won't increase the image size.

@cchaos
Copy link
Contributor

cchaos commented Mar 19, 2020

Jenkins, test this

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_3012/

@cchaos
Copy link
Contributor

cchaos commented Mar 19, 2020

There's a prettier error most likely due to the accepting of changes in Github.

11:40:31 /app/src-docs/src/views/image/image_example.js
11:40:31   109:75  error  Insert `⏎·········`  prettier/prettier
11:40:31 
11:40:31 ✖ 1 problem (1 error, 0 warnings)
11:40:31   1 error and 0 warnings potentially fixable with the `--fix` option.

@cchaos
Copy link
Contributor

cchaos commented Mar 19, 2020

Jenkins, test this

@kibanamachine
Copy link

Preview documentation changes for this PR: https://eui.elastic.co/pr_3012/

Copy link
Contributor

@cchaos cchaos left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Looks good to me. Thanks!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Add height restriction option for EuiImage
5 participants