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

Add Avatar and ImageInput components #922

Merged
merged 36 commits into from
Jun 3, 2021
Merged

Add Avatar and ImageInput components #922

merged 36 commits into from
Jun 3, 2021

Conversation

robinmetral
Copy link
Contributor

@robinmetral robinmetral commented May 6, 2021

Addresses #722 (partly).

Purpose

Introduces the Avatar and ImageInput components.

The Avatar component is a visual element with two variant and two sizes, used to display either identity (e.g. profile image) or object (e.g. product image) avatars.

Screenshot 2021-05-31 at 11 19 15

The ImageInput receives a visual element (with drop-in support for the Avatar) and adds file input logic as well as state-specific styles.

Screenshot 2021-05-31 at 11 19 37

Screenshot 2021-05-31 at 11 19 44

Approach and changes

High-level, the Avatar is a purely presentational element, while the ImageInput handles state-specific styles (hover, active, invalid) as well as file input logic. The actual uploading of an image should be handled in each application via an onChange callback passed to the ImageInput.

Refer to the Storybook for further implementation and usage guidelines, and to the threads below for more details and discussion on the implementation.

Note: some things have been left out of this PR's scope and will be addressed in later versions (primarily for versioning reasons):

  • Integration with the Popover (depends on Popover component #153)
  • Dropzone support
  • Disabled state styles
  • Switch from pseudo-elements to CSS brightness() for styling component states (when we drop IE support)
    • This will also make the ImageInput compatible with other image shapes, like the Avatar's object variant
  • Use Add icon from @sumup/icons (major)
  • Use border-radius values from @sumup/design-tokens (major)

Definition of done

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

@changeset-bot
Copy link

changeset-bot bot commented May 6, 2021

🦋 Changeset detected

Latest commit: eb3121e

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 May 6, 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/5ZiBd1WtwfG7FmWJS2sxwhKqGswd
✅ Preview: https://oss-circuit-ui-git-image-input-sumup.vercel.app

@sumup-clark
Copy link

sumup-clark bot commented May 6, 2021

Hey @robinmetral,
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 May 6, 2021

Codecov Report

Merging #922 (eb3121e) into main (7caa435) will increase coverage by 0.13%.
The diff coverage is 96.51%.

Impacted file tree graph

@@            Coverage Diff             @@
##             main     #922      +/-   ##
==========================================
+ Coverage   91.85%   91.99%   +0.13%     
==========================================
  Files         161      163       +2     
  Lines        2923     3009      +86     
  Branches      759      784      +25     
==========================================
+ Hits         2685     2768      +83     
- Misses        209      212       +3     
  Partials       29       29              
Impacted Files Coverage Δ
packages/circuit-ui/components/Avatar/Avatar.tsx 95.00% <95.00%> (ø)
...es/circuit-ui/components/ImageInput/ImageInput.tsx 96.96% <96.96%> (ø)

Robin Metral added 2 commits May 28, 2021 18:13
- the border-radius of the zetta size was increased to 12px, the value will be moves to design tokens and used in the next Circuit major version
- a bug on Chrome where uploading the same image twice would not fire onChange the second time was fixed by clearing the DOM input element on click
- the AvatarInput was adapted to accept any component as a visual element, the Avatar or something else. A new story "Custom Component" was added to document it. I will add tests for it and rename AvatarInput back to ImageInput in follow-up commits
Since the last commit, it accepts any visual element, although it is still optimized for the Avatar component. This will enable teams to use the ImageInput for use cases beyond an avatar upload.
@robinmetral robinmetral changed the title Add Avatar and AvatarInput components Add Avatar and ImageInput components May 28, 2021
Robin Metral added 5 commits May 31, 2021 10:16
This is to ensure that the button still stands out well even with invalid styles (from a design feedback)
- This makes the component's implementation cleaner
- It makes the tests cleaner because there's only one matching label that we can query with getByLabelText
- This commit also adds missing prop descriptions
Copy link
Member

@connor-baer connor-baer 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 a perfectionist 🙈

.changeset/sharp-mugs-marry.md Outdated Show resolved Hide resolved
packages/circuit-ui/components/Avatar/Avatar.docs.mdx Outdated Show resolved Hide resolved
packages/circuit-ui/components/Avatar/Avatar.docs.mdx Outdated Show resolved Hide resolved
- **Do** use the right variant for your use case (see _Variants_ below).
- **Do** use the [ImageInput component](Forms/ImageInput) with the `component={Avatar}` prop to allow users to upload an avatar (note: the ImageInput only supports `variant="object"` for now).

## Accessibility
Copy link
Member

Choose a reason for hiding this comment

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

Thanks for adding a dedicated Accessibility section! 🙌🏻

Some feedback: I would flip the order of the recommendations: adding alt text should be the default, omitting it the exception. It's better to have duplicate content than missing content.

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I reworded it to put more focus on when the alt text was necessary.

Do you think we should make alt a required prop and remove the "" default? In that case developers will need to explicitly pass "" if their images are presentational.

Copy link
Member

Choose a reason for hiding this comment

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

I think that's a good idea. It forces developers to make a conscious decision.

packages/circuit-ui/components/Avatar/Avatar.tsx Outdated Show resolved Hide resolved
@robinmetral
Copy link
Contributor Author

@connor-baer I addressed your comments (thank you! 🙌), let me know what you think about the last two open questions (I believe):

  • possibly making alt a required prop in the Avatar to enforce a11y (I think it will most often be presentational, at least in our current use cases, so I'm not sure about this).
  • the ImageInput not supporting border-radii rounder than 12px: I've updated the docs a bit to make this clearer, but it's still a strange behavior and I'd love to find a solution soon. But maybe we can merge this first and add support for rounded images as a follow-up improvement in a minor.

The ImageInput also exposes it as part of the custom component's signature, but it defaults to  in that case.

Accessibility docs were also updated and an extra usage example with a custom component was added to the ImageInput stories.
@robinmetral robinmetral merged commit feb6b32 into main Jun 3, 2021
@robinmetral robinmetral deleted the image-input branch June 3, 2021 18:38
@github-actions github-actions bot mentioned this pull request Jun 3, 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.

2 participants