-
Notifications
You must be signed in to change notification settings - Fork 130
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
Size prop added to ImageInput component #1260
Conversation
🦋 Changeset detectedLatest commit: 1f5718a The changes in this PR will be included in the next version bump. This PR includes changesets to release 1 package
Not sure what this means? Click here to learn what changesets are. Click here if you're a maintainer who wants to add another changeset to this PR |
This pull request is being automatically deployed with Vercel (learn more). 🔍 Inspect: https://vercel.com/sumup/oss-circuit-ui/GTChasDruHg1LMx9eeSSyezRfTif |
Hey @giedoka, Thanks! |
Codecov Report
@@ Coverage Diff @@
## main #1260 +/- ##
==========================================
+ Coverage 92.03% 92.05% +0.01%
==========================================
Files 184 184
Lines 3630 3639 +9
Branches 1170 1171 +1
==========================================
+ Hits 3341 3350 +9
Misses 271 271
Partials 18 18
|
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.
Thanks for the PR @giedoka! Added a few comments, mostly the last one is an important discussion we should have about the API for this change 🙂
packages/circuit-ui/components/Avatar/__snapshots__/Avatar.spec.tsx.snap
Outdated
Show resolved
Hide resolved
packages/circuit-ui/components/ImageInput/ImageInput.stories.tsx
Outdated
Show resolved
Hide resolved
packages/circuit-ui/components/ImageInput/ImageInput.stories.tsx
Outdated
Show resolved
Hide resolved
}: { | ||
src?: string; | ||
alt: string; | ||
size: 'giga' | 'yotta'; |
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.
The size here should be optional, otherwise it would be a breaking change
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.
Actually I just got back into the stories and I realized something: we probably don't need this extra size
prop at all! Back then, we built the component that way to prevent tying the ImageInput
together with the Avatar
too much—basically you could use the ImageInput with any visual component that accepts an src
and alt text (although it's optimized for the Avatar).
So this means that we can get the small ImageInput like this in userland:
// this is an example from the stories
<ImageInput
label="Upload an image"
clearButtonLabel="Clear"
src={imageUrl}
onChange={onChange}
onClear={onClear}
invalid={!!error}
validationHint={error}
loadingLabel="Uploading"
// component={Avatar} 👈 instead of just passing the Avatar...
component={({ src, alt }) => <Avatar src={src} alt={alt} size="giga" />} // 👈 ...we pass it with the `size` prop
/>
So instead of forwarding the size to the underlying component, I think what we could do here is accept a new, optional buttonSize
prop, which could be either giga
or yotta
(or maybe it should be more aligned with the IconButton
component and be either kilo
(the existing small IconButton) or byte
(the new XS IconButton—name to confirm with GC).
That way the ImageInput stays decoupled from the Avatar, and developers choose which button size they want for their own use-case.
We would also add a new story for the ImageInput using an <Avatar size="giga" />
since that might be a fairly common use case.
cc @connor-baer, would love your thoughts here. Let me know if you need background on anything in this PR
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 agree that the ImageInput should remain independent of any particular image component. If multiple sizes of the ImageInput are needed, I would therefore keep the size of the ImageInput independent of the child component as well. In other words, we shouldn't pass the size to the child component.
I would keep the name of the size prop for the ImageInput generic. Right now, it only affects the button, but what if additional elements are added in the future that also need to adapt their size?
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 would keep the name of the size prop for the ImageInput generic. Right now, it only affects the button, but what if additional elements are added in the future that also need to adapt their size?
@giedoka we also forgot about this! That was a good point—the ImageInput's only built-in UI is the button, which means we can just rename buttonSize
into size
.
We could use the prop description to say that this changes the button size, so make it more intuitive for developers without requiring breaking changes in the future if the size
affects anything else 🙂
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.
Ahhh yes good point! I focused on adding new prop but not on its name... I'll change it
Co-authored-by: Robin Métral <robin.metral@sumup.com>
Co-authored-by: Robin Métral <robin.metral@sumup.com>
Co-authored-by: Robin Métral <robin.metral@sumup.com>
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.
Looks great! Final comments here (mostly nitpicks), thanks a lot for your patience 🙏
...t-ui/components/TopNavigation/components/ProfileMenu/__snapshots__/ProfileMenu.spec.tsx.snap
Show resolved
Hide resolved
Co-authored-by: Robin Métral <robin.metral@sumup.com>
Co-authored-by: Robin Métral <robin.metral@sumup.com>
Co-authored-by: Robin Métral <robin.metral@sumup.com>
Co-authored-by: Robin Métral <robin.metral@sumup.com>
…eature/image-input-size
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.
Yay! My last comment is a tiny wording thing for the size
prop description so I'm approving already 😅
I'll request a review from design on Chromatic in the meantime.
Thanks you so much for contributing this! 🎉
Co-authored-by: Robin Métral <robin.metral@sumup.com>
Purpose
ImageInput has 2 sizes. They have different button size. In that case, ImageInput component needs to have buttonSize prop.
Approach and changes
Definition of done