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

[EuiImage] Allow src as well #4611

Merged
merged 6 commits into from
Mar 6, 2021
Merged

[EuiImage] Allow src as well #4611

merged 6 commits into from
Mar 6, 2021

Conversation

cchaos
Copy link
Contributor

@cchaos cchaos commented Mar 4, 2021

This url prop for EuiImage has tripped me up many times. I constantly try to use the typical HTML src attribute and it takes me several minutes and docs lookup to find my mistake.

This PR just creates an exclusive union that requires either url or src but since they can also conflict if not using TS, it defaults to src since this feels more standard and aligns to the final <img> tag.

Checklist

  • [ ] Check against all themes for compatibility in both light and dark modes
  • [ ] Checked in mobile
  • Checked in Chrome, Safari, Edge, and Firefox
  • Props have proper autodocs and playground toggles
  • Updated documentation
  • Checked Code Sandbox works for the any docs 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

Comment on lines +74 to +84
type _EuiImageSrcOrUrl = ExclusiveUnion<
{
/**
* Requires either `src` or `url` but defaults to using `src` if both are provided
*/
src: string;
},
{
url: string;
}
>;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

🤔 Somehow though this doesn't show up as either being required in the props table. Is that a problem? TS will complain at least.

Screen Shot 2021-03-04 at 15 37 11 PM

Copy link
Contributor

Choose a reason for hiding this comment

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

It's difficult to "project" types into a flattened system like the props tables or the component's propTypes. In this case, you want to allow src or url but not both, and it doesn't make sense to mark both as required as that's equally invalid. I played around with this a little to see if I could trick it to show src as required, but couldn't. We could modify the generated docgen when showing it on the page, however:

src-docs/src/views/image/image_example.js
EuiImage.__docgenInfo.props.src.required = true;

Copy link
Contributor Author

Choose a reason for hiding this comment

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

Oooh I like that idea, and it worked well. Thanks!

Copy link
Contributor Author

Choose a reason for hiding this comment

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

image

@kibanamachine
Copy link

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

Copy link
Contributor

@snide snide left a comment

Choose a reason for hiding this comment

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

I'm good with the functionality and premise of this change. I'll leave the doc / TS issue to one of the engineers.

Copy link
Contributor

@chandlerprall chandlerprall left a comment

Choose a reason for hiding this comment

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

Changes LGTM; pulled & tested locally; verified that src or url is required by TS, and omitting or including both results in errors.

@cchaos
Copy link
Contributor Author

cchaos commented Mar 6, 2021

Jenkins, test this

@kibanamachine
Copy link

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

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.

4 participants