Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
[Files] Simplify image component implementation and usage (#145347)
## Summary While working on the Image Embeddable I've struggle with using the image component, especially making the blur hash part work as I wanted. The main problems were caused by a custom container around the image which had custom styling - I had to properly style it separately to fit my use-case. The other problem was the BlurHash as since it was implemented as a separate image with custom positioning, I couldn't easily position it exactly the same as I positioned the original image. To make Image component easier to use I suggest the following changes. I also wanted to make the component thinner. - Use a single <img> tag for the underlying image - both for the src and for blurhash. This way we can be sure the image and the placeholder are always position in the same way. To make it work we first set src=blurhash, and then when it is ready we set a real source. The trick here is that the browser loads the new src without removing the previous image. - The downside is that we lost the logic with `blurDelayExpired`. This isn't great, but I think we can live with that considering the simplicity of the new approach. I also reduced the blur box size so that it calculates a bit more faster, as it would have to do this for every image now. - Also, to solve all the edge cases, I had to make the blurred image the same size as the original image by stretching it back to the original size. The problem is that I had to make that part of the code async #145347 (comment) - The image partially implemented some features from `EuiImage` (like predefined set of sizes). Instead of keeping the partial implementation with some code copy paste, I simply suggest we use `EuiImage` underneath. This make our image a tiny wrapper around `EuiImage` which also supports blurhash. - Added a storybook that tests custom sizing with css. - We discussed with @jloleysens that maybe we don't needs custom viewport visibility logic and just use a native browser attribute. The browsers which don't support it will simply load the image eagerly (only Safari atm). I think the native approach is fine here and we should remove the custom code to reduce bug surface.
- Loading branch information