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

[Avatar] Add avatar component #1210

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open

Conversation

acomanescu
Copy link

This PR adds the Avatar component. I wasn't able to run the tests due to some Mocha run errors that happen even when I run the tests on a fresh clone.

@mui-bot
Copy link

mui-bot commented Dec 21, 2024

Netlify deploy preview

https://deploy-preview-1210--base-ui.netlify.app/

Generated by 🚫 dangerJS against e2dd254

@mnajdova
Copy link
Member

Hey @acomanescu thanks for the contribution. We will be working soon on the roadmap for Base UI, where we will share the next components we have in the pipeline. As of now, the Avatar component is not planned, but please keep an eye on the GH Roadmap/issues if you want to contribute with something else.

If you are interested in Base UI introducing an Avatar component, please create an issue for it.

Thank you!

@acomanescu
Copy link
Author

Hi @mnajdova, thank you for your response. I am closing this PR.

@acomanescu acomanescu closed this Dec 24, 2024
@zannager zannager added the component: avatar This is the name of the generic UI component, not the React module! label Dec 27, 2024
@colmtuite
Copy link
Contributor

I've created an issue for Avatar and added it to the current cycle. I'll reopen this PR and take a look soon. Thanks @acomanescu!

@colmtuite colmtuite reopened this Jan 20, 2025
@github-actions github-actions bot added the PR: out-of-date The pull request has merge conflicts and can't be merged label Jan 20, 2025
Copy link
Member

@mnajdova mnajdova 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, I left some initial feedback. I will let Colm review the docs demo

Comment on lines +59 to +62
/**
* Time in milliseconds to wait before showing the fallback.
*/
delayMs: PropTypes.number,
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
/**
* Time in milliseconds to wait before showing the fallback.
*/
delayMs: PropTypes.number,
/**
* How long to wait before showing the fallback. Specified in milliseconds.
*/
delay: PropTypes.number,

To be consistent with the other components.

const { className, render, delayMs, ...otherProps } = props;

const context = useAvatarRootContext();
const [canRender, setCanRender] = React.useState(delayMs === undefined);
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
const [canRender, setCanRender] = React.useState(delayMs === undefined);
const [delayPassed, setDelayPassed] = React.useState(delayMs === undefined);

extraProps: otherProps,
});

return canRender && context.imageLoadingStatus !== 'loaded' ? renderElement() : null;
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
return canRender && context.imageLoadingStatus !== 'loaded' ? renderElement() : null;
const canRender = delayPassed && context.imageLoadingStatus !== 'loaded' ;
return canRender ? renderElement() : null;

To improve readability a bit.


export default function ExampleAvatar() {
return (
<Avatar.Root className={styles.Root}>
Copy link
Member

Choose a reason for hiding this comment

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

We can extend the hero demo so also show an Avatar with initials only, something like:

<Avatar.Root>
  MN
</Avatar.Root>

Copy link
Member

Choose a reason for hiding this comment

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

Also, I would make the avatars a bit smaller :)

describeConformance(<Avatar.Root />, () => ({
render,
refInstanceof: window.HTMLSpanElement,
}));
Copy link
Member

Choose a reason for hiding this comment

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

Let's add more tests to make sure the fallback behavior is working as expected.

@colmtuite
Copy link
Contributor

@acomanescu Good work 🙏

  • Let's use a different image. I don't have a preference, just something different.
  • Let's go with 48px width + height.
  • On Root, inline-flex would be better than flex, since it's usually an inline component.
  • Root will need user-select: none for when there is text content inside.
  • Root will need vertical-align: middle to easier accommodate alignment with other inline components and fix x-browser rendering issues with img.
  • I see you're using alphabetical order for properties (which is admirable), but we don't follow that convention currently. Instead, we group properties by association. So flex properties should go together, dimensions/size properties should go together etc.
  • Rather than the hard-coded background-color value, use var(--color-gray-100) instead.
  • Rather than the hard-coded color value, use var(--color-gray-900) instead.
  • Fallback will need a font-size. 16px should be good (but use rem). It will also need line-height: 1;
  • All px values should be converted to rem.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
component: avatar This is the name of the generic UI component, not the React module! PR: out-of-date The pull request has merge conflicts and can't be merged
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants