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

Size prop added to ImageInput component #1260

Merged
merged 34 commits into from
Nov 17, 2021
Merged

Conversation

giedoka
Copy link
Contributor

@giedoka giedoka commented Nov 9, 2021

Purpose

ImageInput has 2 sizes. They have different button size. In that case, ImageInput component needs to have buttonSize prop.

Zrzut ekranu 2021-11-15 o 12 36 17

Approach and changes

  • border radius docs updated
  • fix of border radius in Avatar (there was wrong value for the giga one)
  • buttonSize prop added to ImageInput

Definition of done

  • Development completed
  • Reviewers assigned
  • Unit and integration tests
  • Meets minimum browser support
  • Meets accessibility requirements

@giedoka giedoka requested a review from a team as a code owner November 9, 2021 09:45
@giedoka giedoka requested review from connor-baer and removed request for a team November 9, 2021 09:45
@changeset-bot
Copy link

changeset-bot bot commented Nov 9, 2021

🦋 Changeset detected

Latest commit: 1f5718a

The changes in this PR will be included in the next version bump.

This PR includes changesets to release 1 package
Name Type
@sumup/circuit-ui Minor

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

@vercel
Copy link

vercel bot commented Nov 9, 2021

This pull request is being automatically deployed with Vercel (learn more).
To see the status of your deployment, click below or on the icon next to each commit.

🔍 Inspect: https://vercel.com/sumup/oss-circuit-ui/GTChasDruHg1LMx9eeSSyezRfTif
✅ Preview: https://oss-circuit-ui-git-feature-image-input-size-sumup.vercel.app

@sumup-clark
Copy link

sumup-clark bot commented Nov 9, 2021

Hey @giedoka,
we are super excited that you are contributing! 🎉There's one more thing you need to do. Please accept our Contributor License Agreement. It helps you and us to collaborate on clear terms and focus on what we love most: code.

Thanks!

@codecov
Copy link

codecov bot commented Nov 9, 2021

Codecov Report

Merging #1260 (1f5718a) into main (96d0007) will increase coverage by 0.01%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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              
Impacted Files Coverage Δ
packages/circuit-ui/components/Avatar/Avatar.tsx 95.23% <100.00%> (+1.12%) ⬆️
...es/circuit-ui/components/ImageInput/ImageInput.tsx 86.45% <100.00%> (+0.74%) ⬆️

Copy link
Contributor

@robinmetral robinmetral 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 PR @giedoka! Added a few comments, mostly the last one is an important discussion we should have about the API for this change 🙂

docs/features/theme.stories.mdx Show resolved Hide resolved
.changeset/cool-pandas-fly.md Outdated Show resolved Hide resolved
.changeset/cool-pandas-fly.md Outdated Show resolved Hide resolved
packages/circuit-ui/components/Avatar/Avatar.tsx Outdated Show resolved Hide resolved
}: {
src?: string;
alt: string;
size: 'giga' | 'yotta';
Copy link
Contributor

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

Copy link
Contributor

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

Copy link
Member

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?

Copy link
Contributor

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 🙂

Copy link
Contributor Author

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>
giedoka and others added 2 commits November 10, 2021 09:40
Co-authored-by: Robin Métral <robin.metral@sumup.com>
Co-authored-by: Robin Métral <robin.metral@sumup.com>
Copy link
Contributor

@robinmetral robinmetral left a 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 🙏

Co-authored-by: Robin Métral <robin.metral@sumup.com>
giedoka and others added 2 commits November 17, 2021 14:37
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>
Copy link
Contributor

@robinmetral robinmetral left a 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>
@robinmetral robinmetral merged commit 40339fe into main Nov 17, 2021
@robinmetral robinmetral deleted the feature/image-input-size branch November 17, 2021 16:15
@github-actions github-actions bot mentioned this pull request Nov 17, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants