-
Notifications
You must be signed in to change notification settings - Fork 841
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
Conversation
type _EuiImageSrcOrUrl = ExclusiveUnion< | ||
{ | ||
/** | ||
* Requires either `src` or `url` but defaults to using `src` if both are provided | ||
*/ | ||
src: string; | ||
}, | ||
{ | ||
url: string; | ||
} | ||
>; |
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.
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.
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;
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.
Oooh I like that idea, and it worked well. Thanks!
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.
Preview documentation changes for this PR: https://eui.elastic.co/pr_4611/ |
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'm good with the functionality and premise of this change. I'll leave the doc / TS issue to one of the engineers.
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.
Changes LGTM; pulled & tested locally; verified that src or url is required by TS, and omitting or including both results in errors.
Jenkins, test this |
Preview documentation changes for this PR: https://eui.elastic.co/pr_4611/ |
This
url
prop for EuiImage has tripped me up many times. I constantly try to use the typical HTMLsrc
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
orsrc
but since they can also conflict if not using TS, it defaults tosrc
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 for breaking changes and labeled appropriately[ ] Checked for accessibility including keyboard-only and screenreader modes